TH1F * MakeOnePSE(TH1F * sig, int nsig, TH1F * back, int nback){ //threw one data PSE and fill it TH1F * data = (TH1F*) sig ->Clone("data"); data->Reset(); data->FillRandom(sig,nsig); data->FillRandom(back,nback); return data; }//MakeOnePSE
vector<double> one_fit(bool do_fit) { TH1F* h = new TH1F("h","h", 20, -10, 10); h->FillRandom("gaus"); vector<double> ret; if (do_fit) { h->Fit("gaus",""); TF1* g = h->GetFunction("gaus"); h->Draw(); canvas->Modified(); canvas->Update(); for (int ind=0; ind < 3; ++ind) { ret.push_back(g->GetParameter(ind)); } } else { for (int ind=0; ind < 3; ++ind) { ret.push_back(0.0); } } ret.push_back(h->GetMean()); ret.push_back(h->GetRMS()); delete h; return ret; }
void fitcont() { //be sure default is Minuit since we will use gMinuit TVirtualFitter::SetDefaultFitter("Minuit"); TCanvas *c1 = new TCanvas("c1"); TH1F *h = new TH1F("h","My histogram",100,-3,3); h->FillRandom("gaus",6000); h->Fit("gaus"); c1->Update(); TCanvas *c2 = new TCanvas("c2","contours",10,10,600,800); c2->Divide(1,2); c2->cd(1); /*get first contour for parameter 1 versus parameter 2*/ TGraph *gr12 = (TGraph*)gMinuit->Contour(40,1,2); gr12->Draw("alp"); c2->cd(2); /*Get contour for parameter 0 versus parameter 2 for ERRDEF=2*/ gMinuit->SetErrorDef(4); //note 4 and not 2! TGraph *gr2 = (TGraph*)gMinuit->Contour(80,0,2); gr2->SetFillColor(42); gr2->Draw("alf"); /*Get contour for parameter 0 versus parameter 2 for ERRDEF=1*/ gMinuit->SetErrorDef(1); TGraph *gr1 = (TGraph*)gMinuit->Contour(80,0,2); gr1->SetFillColor(38); gr1->Draw("lf"); }
void transp() { //1. Try to find free indices for our custom colors. //We can use hard-coded indices like 1001, 1002, 1003, ... but //I prefer to find free indices in a ROOT's color table //to avoid possible conflicts with other tutorials. Int_t indices[2] = {}; if (ROOT::GLTutorials::FindFreeCustomColorIndices(indices) != 2) { Error("transp", "failed to create new custom colors"); return; } //2. Now that we have indices, create our custom colors. const Int_t redIndex = indices[0], greeIndex = indices[1]; new TColor(redIndex, 1., 0., 0., "red", 0.85); new TColor(greeIndex, 0., 1., 0., "green", 0.5); gStyle->SetCanvasPreferGL(kTRUE); TCanvas * const cnv = new TCanvas("trasnparency", "transparency demo", 600, 400); TH1F * hist = new TH1F("a5", "b5", 10, -2., 3.); TH1F * hist2 = new TH1F("c6", "d6", 10, -3., 3.); hist->FillRandom("landau", 100000); hist2->FillRandom("gaus", 100000); hist->SetFillColor(redIndex); hist2->SetFillColor(greeIndex); cnv->cd(); hist2->Draw(); hist->Draw("SAME"); }
void peaks(Int_t np=10) { npeaks = TMath::Abs(np); TH1F *h = new TH1F("h","test",500,0,1000); //generate n peaks at random Double_t par[3000]; par[0] = 0.8; par[1] = -0.6/1000; Int_t p; for (p=0;p<npeaks;p++) { par[3*p+2] = 1; par[3*p+3] = 10+gRandom->Rndm()*980; par[3*p+4] = 3+2*gRandom->Rndm(); } TF1 *f = new TF1("f",fpeaks,0,1000,2+3*npeaks); f->SetNpx(1000); f->SetParameters(par); TCanvas *c1 = new TCanvas("c1","c1",10,10,1000,900); c1->Divide(1,2); c1->cd(1); h->FillRandom("f",200000); h->Draw(); TH1F *h2 = (TH1F*)h->Clone("h2"); //Use TSpectrum to find the peak candidates TSpectrum *s = new TSpectrum(2*npeaks); Int_t nfound = s->Search(h,2,"",0.10); printf("Found %d candidate peaks to fit\n",nfound); //Estimate background using TSpectrum::Background TH1 *hb = s->Background(h,20,"same"); if (hb) c1->Update(); if (np <0) return; //estimate linear background using a fitting method c1->cd(2); TF1 *fline = new TF1("fline","pol1",0,1000); h->Fit("fline","qn"); //Loop on all found peaks. Eliminate peaks at the background level par[0] = fline->GetParameter(0); par[1] = fline->GetParameter(1); npeaks = 0; Double_t *xpeaks = s->GetPositionX(); for (p=0;p<nfound;p++) { Double_t xp = xpeaks[p]; Int_t bin = h->GetXaxis()->FindBin(xp); Double_t yp = h->GetBinContent(bin); if (yp-TMath::Sqrt(yp) < fline->Eval(xp)) continue; par[3*npeaks+2] = yp; par[3*npeaks+3] = xp; par[3*npeaks+4] = 3; npeaks++; } printf("Found %d useful peaks to fit\n",npeaks); printf("Now fitting: Be patient\n"); TF1 *fit = new TF1("fit",fpeaks,0,1000,2+3*npeaks); //we may have more than the default 25 parameters TVirtualFitter::Fitter(h2,10+3*npeaks); fit->SetParameters(par); fit->SetNpx(1000); h2->Fit("fit"); }
void rebin() { //create a fix bin histogram TH1F *h = new TH1F("h","test rebin",100,-3,3); Int_t nentries = 1000; h->FillRandom("gaus",nentries); Double_t xbins[1001]; Int_t k=0; TAxis *axis = h->GetXaxis(); for (Int_t i=1;i<=100;i++) { Int_t y = (Int_t)h->GetBinContent(i); if (y <=0) continue; Double_t dx = axis->GetBinWidth(i)/y; Double_t xmin = axis->GetBinLowEdge(i); for (Int_t j=0;j<y;j++) { xbins[k] = xmin +j*dx; k++; } } xbins[k] = axis->GetXmax(); //create a variable bin-width histogram out of fix bin histogram //new rebinned histogram should have about 10 entries per bin TH1F *hnew = new TH1F("hnew","rebinned",k,xbins); hnew->FillRandom("gaus",10*nentries); //rebin hnew keeping only 50% of the bins Double_t xbins2[501]; Int_t kk=0; for (Int_t j=0;j<k;j+=2) { xbins2[kk] = xbins[j]; kk++; } xbins2[kk] = xbins[k]; TH1F *hnew2 = (TH1F*)hnew->Rebin(kk,"hnew2",xbins2); //draw the 3 histograms TCanvas *c1 = new TCanvas("c1","c1",800,1000); c1->Divide(1,3); c1->cd(1); h->Draw(); c1->cd(2); hnew->Draw(); c1->cd(3); hnew2->Draw(); }
void exec3() { // Temporary work around the lack of automatic refresh of the list // when a script is reloaded. gROOT->GetListOfGlobalFunctions()->Delete(); TH1F *h = new TH1F("h","h",100,-3,3); h->FillRandom("gaus",1000); TCanvas *c1=new TCanvas("c1"); h->Draw(); c1->Update(); c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0, 0, "exec3event(Int_t,Int_t,Int_t,TObject*)"); }
void pad2png() { TCanvas *c = new TCanvas; TH1F *h = new TH1F("gaus", "gaus", 100, -5, 5); h->FillRandom("gaus", 10000); h->Draw(); gSystem->ProcessEvents(); TImage *img = TImage::Create(); img->FromPad(c); img->WriteImage("canvas.png"); }
void fill_local_ocdb() { AliceO2::CDB::Manager* cdb = AliceO2::CDB::Manager::Instance(); cdb->setDefaultStorage("local://O2CDB"); TH1F* h = 0; for (int run = 2000; run < 2100; run++) { cdb->setRun(run); h = new TH1F(Form("histo for %d run", run), "gauss", 100, -5, 5); h->FillRandom("gaus", 1000); AliceO2::CDB::ConditionId* id = new AliceO2::CDB::ConditionId("DET/Calib/Histo", run, run, 1, 0); AliceO2::CDB::ConditionMetaData* md = new AliceO2::CDB::ConditionMetaData(); cdb->putObject(h, *id, md); h = 0; } }
void exec3() { // Example of using signal/slot in TCanvas/TPad to get feedback // about processed events. Note that slots can be either functions // or class methods. Compare this with tutorials exec1.C and exec2.C. //Author: Ilka Antcheva // Temporary work around the lack of automatic refresh of the list // when a script is reloaded. gROOT->GetListOfGlobalFunctions()->Delete(); TH1F *h = new TH1F("h","h",100,-3,3); h->FillRandom("gaus",1000); TCanvas *c1=new TCanvas("c1"); h->Draw(); c1->Update(); c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0, 0, "exec3event(Int_t,Int_t,Int_t,TObject*)"); }
void lochanroot() { char name[10], title[20]; TObjArray Hlist(0); // create an array of Histograms TH1F* g; // create a pointer to a histogram // make and fill 15 histograms and add them to the object array for (Int_t i = 0; i < 15; i++) { sprintf(name,"lochan%d",i); sprintf(title,"histo number:%d",i); g = new TH1F(name,title,100,-4,4); Hlist.Add(g); //changed from -> to . g->FillRandom("gaus",1000); } // open a file and write the array to the file TFile f("lochan.root","recreate"); Hlist.Write(); //changed from -> to . f.Close(); }
void customContextMenu() { TH1F *h; TH1F *h2; TClassMenuItem *n; TList *l; // Create test histograms h = new TH1F("h","Schtroumpf",100,-4,4); h->FillRandom("gaus"); h->Draw(); h2 = new TH1F("h2","h2",1000,-4,4); h2->FillRandom("gaus",30000); // Retrieve menu list from TClass TClass *cl = h->IsA(); l = cl->GetMenuList(); // Add some items to the popup menus n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Test object, draw a second h","Draw",h2,"Option_t*"); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 4","poptest4",0,"const char*"); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 3","poptest3",0,""); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 2 bis","poptest2bis",0,"TObject*",2); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 2","poptest2",0,"int,int,TObject*",2); l->AddFirst(n); n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "test no 1","poptest1",0,"int,int"); l->AddFirst(n); }
/* * From here on, the code can also be used as a macro * Note though, that CINT may report errors where there are none in C++. E.g. this happens here where CINT says that f1 is out of scope ... ==>> put your code here (remember to update the name of you Macro in the lines above if you intend to comile the code) */ void ExampleMacro() { // Create a histogram, fill it with random gaussian numbers TH1F *h = new TH1F ("h", "example histogram", 100, -5.,5.); h->FillRandom("gaus",1000); // draw the histogram h->DrawClone(); /* - Create a new ROOT file for output - Note that this file may contain any kind of ROOT objects, histograms, pictures, graphics objects etc. - the new file is now becoming the current directory */ TFile *f1 = new TFile("ExampleMacro.root","RECREATE","ExampleMacro"); // write Histogram to current directory (i.e. the file just opened) h->Write(); // Close the file. // (You may inspect your histogram in the file using the TBrowser class) f1->Close(); }
void billtw(Int_t compress) { //write N histograms to a Tree timer.Start(); TFile f("billt.root","recreate","bill benchmark with trees",compress); TH1F *h = new TH1F("h","h",1000,-3,3); h->FillRandom("gaus",50000); TTree *T = new TTree("T","test bill"); T->Branch("event","TH1F",&h,64000,0); for (Int_t i=0;i<N;i++) { char name[20]; sprintf(name,"h%d",i); h->SetName(name); h->Fill(2*gRandom->Rndm()); T->Fill(); } T->Write(); delete T; timer.Stop(); printf("billtw%d : RT=%7.3f s, Cpu=%7.3f s, File size= %9d bytes, CX= %g\n",compress,timer.RealTime(),timer.CpuTime(), (Int_t)f.GetBytesWritten(),f.GetCompressionFactor()); }
void transp() { //1. Try to find free indices for our custom colors. //We can use hard-coded indices like 1001, 1002, 1003, ... but //I prefer to find free indices in a ROOT's color table //to avoid possible conflicts with other tutorials. Int_t indices[2] = {}; if (ROOT::CocoaTutorials::FindFreeCustomColorIndices(indices) != 2) { Error("transp", "failed to create new custom colors"); return; } //2. Now that we have indices, create our custom colors. const Int_t redIndex = indices[0], greeIndex = indices[1]; new TColor(redIndex, 1., 0., 0., "red", 0.85); new TColor(greeIndex, 0., 1., 0., "green", 0.5); //3. Test that back-end is TGCocoa. TCanvas * const cnv = new TCanvas("trasnparency", "transparency demo", 600, 400); //After we created a canvas, gVirtualX in principle should be initialized //and we can check its type: if (gVirtualX && !gVirtualX->InheritsFrom("TGCocoa")) { Warning("transp", "You can see the transparency ONLY in a pdf or png output (\"File\"->\"Save As\" ->...)\n" "To have transparency in a canvas graphics, you need MacOSX version with cocoa enabled"); } TH1F * hist = new TH1F("a5", "b5", 10, -2., 3.); TH1F * hist2 = new TH1F("c6", "d6", 10, -3., 3.); hist->FillRandom("landau", 100000); hist2->FillRandom("gaus", 100000); hist->SetFillColor(redIndex); hist2->SetFillColor(greeIndex); cnv->cd(); hist2->Draw(); hist->Draw("SAME"); }
void fitcont() { // Example illustrating how to draw the n-sigma contour of a Minuit fit. // To get the n-sigma contour the ERRDEF parameter in Minuit has to set // to n^2. The fcn function has to be set before the routine is called. // // WARNING!!! This test works only with TMinuit // // The TGraph object is created via the interpreter. The user must cast it // to a TGraph* // Author: Rene Brun //be sure default is Minuit since we will use gMinuit TVirtualFitter::SetDefaultFitter("Minuit"); TCanvas *c1 = new TCanvas("c1"); TH1F *h = new TH1F("h","My histogram",100,-3,3); h->FillRandom("gaus",6000); h->Fit("gaus"); c1->Update(); TCanvas *c2 = new TCanvas("c2","contours",10,10,600,800); c2->Divide(1,2); c2->cd(1); //get first contour for parameter 1 versus parameter 2 TGraph *gr12 = (TGraph*)gMinuit->Contour(40,1,2); gr12->Draw("alp"); c2->cd(2); //Get contour for parameter 0 versus parameter 2 for ERRDEF=2 gMinuit->SetErrorDef(4); //note 4 and not 2! TGraph *gr2 = (TGraph*)gMinuit->Contour(80,0,2); gr2->SetFillColor(42); gr2->Draw("alf"); //Get contour for parameter 0 versus parameter 2 for ERRDEF=1 gMinuit->SetErrorDef(1); TGraph *gr1 = (TGraph*)gMinuit->Contour(80,0,2); gr1->SetFillColor(38); gr1->Draw("lf"); }
void pad2png() { // Create a canvas and save as png. //Author: Valeriy Onuchin TCanvas *c = new TCanvas; TH1F *h = new TH1F("gaus", "gaus", 100, -5, 5); h->FillRandom("gaus", 10000); h->Draw(); gSystem->ProcessEvents(); TImage *img = TImage::Create(); //img->FromPad(c, 10, 10, 300, 200); img->FromPad(c); img->WriteImage("canvas.png"); delete h; delete c; delete img; }
void fitExclude() { //Create a source function TF1 *f1 = new TF1("f1","[0] +[1]*x +gaus(2)",0,5); f1->SetParameters(6,-1,5,3,0.2); // create and fill histogram according to the source function TH1F *h = new TH1F("h","background + signal",100,0,5); h->FillRandom("f1",2000); TF1 *fl = new TF1("fl",fline,0,5,2); fl->SetParameters(2,-1); //fit only the linear background excluding the signal area reject = kTRUE; h->Fit(fl,"0"); reject = kFALSE; //store 2 separate functions for visualization TF1 *fleft = new TF1("fleft",fline,0,2.5,2); fleft->SetParameters(fl->GetParameters()); h->GetListOfFunctions()->Add(fleft); gROOT->GetListOfFunctions()->Remove(fleft); TF1 *fright = new TF1("fright",fline,3.5,5,2); fright->SetParameters(fl->GetParameters()); h->GetListOfFunctions()->Add(fright); gROOT->GetListOfFunctions()->Remove(fright); h->Draw(); }
//___________________________________________________________________________ Double_t* IfitBin(TH1F* dataInput, TH1F* sigTemplate, TH1F* bkgTemplate, int fit_data=1) { cout << "Input files are " << dataInput->GetName() << "\t" << sigTemplate->GetName() << "\t" << bkgTemplate->GetName() << endl; TCanvas *c1 = new TCanvas("HF1", "Histos1", 0, 0, 600, 600); dataCollBin.clear(); sigCollBin.clear(); bkgCollBin.clear(); Double_t* fitted = new Double_t[8]; fitted[0] = fitted[1] = fitted[2] = fitted[3] = fitted[4] = fitted[5] = fitted[6] = fitted[7] = 0.0; TH1F *hsum = new TH1F(); float ntemplate = 1.; float sigfrac = 0.1; TH1F *hsum_norm = new TH1F(); TH1F *hdata; TH1F *hsig = (TH1F*)sigTemplate->Clone(); hsig->SetName("hsig"); hsig->Rebin(6); TH1F *hbkg = (TH1F*)bkgTemplate->Clone(); hbkg->SetName("hbkg"); hbkg->Rebin(6); float ndata=0; if ( fit_data>0 ) { hdata = (TH1F*)dataInput->Clone(); hdata -> SetName("hdata"); ndata = hdata->Integral(); }else { hsum = (TH1F*)hsig->Clone(); hsum->Add(hbkg,1); cout << "For histogram " << sigTemplate->GetName() << " and " << bkgTemplate->GetName() << " sum = " << hsum->Integral() << endl; if (hsum->Integral()>1.) ntemplate = hsum->Integral(); sigfrac = hsig->Integral()/ntemplate; hsum_norm = (TH1F*)hsum->Clone(); hsum_norm->Scale(1./hsum->Integral()); hdata = (TH1F*)hsum_norm->Clone(); hdata -> SetName("hdata"); ndata=ntemplate; hdata->FillRandom(hsum_norm, ndata); } if(ndata==0) { printf(" --- no events in the fit \n"); return fitted; } printf(" --------- before the fit ------------- \n"); printf("Nsig %2.3f, Nbg %2.3f, Ntemplate %3.3f \n", hsig->Integral(), hbkg->Integral(), ntemplate); // printf("Purity %2.3f, init size %4.3f, test sample size %4d\n", hsig->Integral()/hsum->Integral(), hsum->Integral(), ndata); printf(" -------------------------------------- \n"); hdata->Rebin(6); int nbins = hdata->GetNbinsX(); hsig->Scale(1./hsig->Integral()); hbkg->Scale(1./hbkg->Integral()); for (int ibin=1; ibin<=nbins; ibin++) { dataCollBin.push_back(hdata->GetBinContent(ibin)); sigCollBin.push_back(hsig->GetBinContent(ibin)); bkgCollBin.push_back(hbkg->GetBinContent(ibin)); } printf( " ----- Got %d, %d, %d events for fit ----- \n ", dataCollBin.size(), sigCollBin.size(), bkgCollBin.size() ); if ( dataCollBin.size() != sigCollBin.size() || sigCollBin.size()!=bkgCollBin.size() ) { printf(" error ... inconsistent hit collection size \n"); return fitted; } //-------------------------------------------------- //init parameters for fit Double_t vstart[10] = {1., 1.}; vstart[0] = sigfrac*ndata; vstart[1] = (1-sigfrac)*ndata; TMinuit *gMinuit = new TMinuit(NPARBIN); gMinuit->Command("SET STR 1"); gMinuit->SetFCN(fcnBin); Double_t arglist[10]; Int_t ierflg = 0; arglist[0] = 1; gMinuit->mnexcm("SET ERR", arglist ,1,ierflg); arglist[0] = 1; gMinuit->mnexcm("SET PRINT", arglist ,1,ierflg); Double_t step[] = { 0.1, 0.1,}; gMinuit->mnparm(0, "Signal yield" , vstart[0], step[0], 0., ndata*2. , ierflg); gMinuit->mnparm(1, "background yield" , vstart[1], step[1], 0., ndata*2. , ierflg); printf(" --------------------------------------------------------- \n"); printf(" Now ready for minimization step \n --------------------------------------------------------- \n"); arglist[0] = 2000; // number of iteration arglist[1] = 1.; gMinuit->mnexcm("MIGRAD", arglist ,2,ierflg); printf (" -------------------------------------------- \n"); printf("Finished. ierr = %d \n", ierflg); infoBin.clear(); infoBin_err.clear(); double para[NPARBIN+1],errpara[NPARBIN+1]; if ( ierflg == 0 ) { for(int j=0; j<=NPARBIN-1;j++) { gMinuit->GetParameter(j, para[j],errpara[j]); para[NPARBIN] = dataCollBin.size(); infoBin.push_back(para[j]); infoBin_err.push_back(errpara[j]); printf("Parameter (yeild) %d = %f +- %f\n",j,para[j],errpara[j]); } printf(" fitted yield %2.3f \n", (para[0]+para[1])/ndata ); infoBin.push_back(sigCollBin.size()); } else { printf(" *********** Fit failed! ************\n"); gMinuit->GetParameter(0, para[0],errpara[0]); gMinuit->GetParameter(1, para[1],errpara[1]); para[0]=0.; errpara[0]=0.; } // Print results Double_t amin,edm,errdef; Int_t nvpar,nparx,icstat; gMinuit->mnstat(amin,edm,errdef,nvpar,nparx,icstat); gMinuit->mnprin(1,amin); gMinuit->mnmatu(1); printf(" ========= happy ending !? =========================== \n"); printf("FCN = %3.3f \n", amin); double yerr[20]; for(int i=0;i<20;i++){ yerr[i] = 0.; } hsig->Scale(para[0]); hbkg->Scale(para[1]); TH1F *hfit = (TH1F*)hsig->Clone(); hfit->Add(hbkg); hsig->SetLineColor(1); hsig->SetFillColor(5); hsig->SetFillStyle(3001); hbkg->SetLineWidth(2); // plot c1->Draw(); //gPad->SetLogy(); hdata->SetLineColor(1); hdata->SetNdivisions(505,"XY"); hdata->SetXTitle("Iso_{ECAL}+Iso_{HCAL}+Iso_{TRK} (GeV)"); hdata->SetYTitle("Entries"); hdata->SetTitle(""); hdata->SetMarkerStyle(8); hdata->SetMinimum(0.); hdata->SetMaximum(hdata->GetMaximum()*1.5); hdata->Draw("p e"); hsig->Draw("hist same"); hbkg->SetMarkerStyle(0); hbkg->SetFillColor(8); hbkg->SetLineWidth(1); hbkg->SetFillStyle(3013); hbkg->SetError(yerr); hbkg->Draw("hist same"); hfit->SetMarkerStyle(0); hfit->SetLineColor(1); hfit->SetLineWidth(2); hfit->SetError(yerr); hfit->Draw("hist same"); double chi2ForThisBin=0; int nbinForThisBin=0; chi2NbinsHisto(hfit, hdata, chi2ForThisBin, nbinForThisBin); TPaveText *pavetex = new TPaveText(0.43, 0.87, 0.90, 0.92,"NDCBR"); pavetex->SetBorderSize(0); pavetex->SetFillColor(0); pavetex->SetFillStyle(0); pavetex->SetLineWidth(3); pavetex->SetTextAlign(12); pavetex->SetTextSize(0.03); pavetex->AddText(Form("#chi^{2}/NDF=%.1f/%d",chi2ForThisBin, nbinForThisBin)); pavetex->Draw(); char text[1000]; TLegend *tleg = new TLegend(0.43, 0.60, 0.90, 0.87); tleg->SetHeader(dataInput->GetTitle()); tleg->SetTextSize(0.03); tleg->SetFillColor(0); tleg->SetShadowColor(0); tleg->SetBorderSize(0); sprintf(text,"Data %5.1f events",hdata->Integral()); tleg->AddEntry(hdata,text,"pl"); sprintf(text,"Fitted %5.1f events",hfit->Integral()); tleg->AddEntry(hfit,text,"l"); sprintf(text,"SIG %5.1f #pm %5.1f events",para[0], errpara[0]); tleg->AddEntry(hsig,text,"f"); sprintf(text,"BKG %5.1f #pm %5.1f events",para[1], errpara[1]); tleg->AddEntry(hbkg,text,"f"); tleg->Draw(); gPad->RedrawAxis(); cout << dataInput->GetName() << endl; char fname[300]; sprintf(fname,"plots/Ifit_%s.eps",dataInput->GetName()); c1->SaveAs(fname); sprintf(fname,"plots/Ifit_%s.gif",dataInput->GetName()); c1->SaveAs(fname); printf("----- fit results with signal projection ----------- \n"); // ftemplate->Close(); int purityMaxBin = hsig->FindBin(5.0)-1; Double_t scale_signal = hsig->Integral(1,purityMaxBin)/hsig->Integral(); Double_t scale_background = hbkg->Integral(1,purityMaxBin)/hbkg->Integral(); fitted[0] = para[0]; fitted[1] = errpara[0]; fitted[2] = para[1]; fitted[3] = errpara[1]; // for integral up to 5 GeV fitted[4] = para[0]*scale_signal; fitted[5] = errpara[0]*scale_signal; fitted[6] = para[1]*scale_background; fitted[7] = errpara[1]*scale_background; return fitted; }
void compareCorrRCSpike(){ char tmp[1000]; setTDRStyle(); // settings for purity TGraphAsymmetryErrors Double_t fBinsPtMidPoint[nPtBin]={0}; Double_t fBinsPtError[nPtBin]={0}; for(int ipt=0; ipt < nPtBin; ipt++) { fBinsPtMidPoint[ipt] = 0.5*(fBinsPt[ipt+1]+fBinsPt[ipt]); fBinsPtError[ipt] = 0.5*(fBinsPt[ipt+1]-fBinsPt[ipt]); } TH1F* hTemplate_S[nEtaBin][nPtBin]; TH1F* hdata_S[nEtaBin][nPtBin]; std::string dataFile = "SBDataTemplate_131511_139239.root"; std::string templateFile = "spike_131511_139239.root"; TFile* inf_data = new TFile(dataFile.data()); TFile* inf_template = new TFile(templateFile.data()); char* dec[2] = {"EB","EE"}; for(int ieta=0; ieta<1; ieta++){ for(int ipt=0; ipt < nPtBin; ipt++){ // getting histograms from data root file sprintf(tmp,"h_%s_comb3Iso_sig_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << inf_data->GetName() << endl; hdata_S[ieta][ipt] = (TH1F*)inf_data->FindObjectAny(tmp); hdata_S[ieta][ipt]->SetName(Form("hdata_S_%d_%d",ieta,ipt)); hdata_S[ieta][ipt]->Rebin(REBINNINGS); // getting histogram for template root file sprintf(tmp,"h_EB_comb3Iso_EGdata_SIG"); cout << "looking for histogram " << tmp << " in file " << inf_template->GetName() << endl; hTemplate_S[ieta][ipt] = (TH1F*)inf_template->FindObjectAny(tmp); hTemplate_S[ieta][ipt]->SetName(Form("hTemplate_S_%d_%d",ieta,ipt)); hTemplate_S[ieta][ipt]->Rebin(REBINNINGS); } } TH1F* hfit_sig; TH1F* hfit_spike; TH1F* hsig = new TH1F("hsig","",120,-1,11); hsig->SetXTitle("Iso (GeV)"); hsig->SetYTitle("A.U."); hsig->GetYaxis()->SetDecimals(); hsig->SetYTitle("Iso (GeV)"); hsig->SetLineColor(2); TH1F* hspike = new TH1F("hspike","",120,-1,11); hspike->SetLineColor(4); TCanvas* c1 = new TCanvas("c1","",500,500); for(int ieta=0; ieta< 1; ieta++){ for(int ipt=0; ipt < nPtBin; ipt++){ hsig->Reset(); hspike->Reset(); // first obtain fit for the random cone corrected values hfit_sig = (TH1F*)hdata_S[ieta][ipt]->Clone(); hfit_sig -> SetName("hfit_sig"); hfit_sig -> Rebin(4); double sigPar[20] = {hfit_sig->GetMaximum(), 1., 0.5, 0.3, 1.,-.3,-1., 0.01, 0.5, 0.01, 1., 1.}; TF1 *fsig = new TF1("fsig", exp_conv, -1., 11., 12); fsig->SetParameters(sigPar); fsig->SetNpx(2500); fsig->SetLineColor(2); hfit_sig->Fit(fsig,"","",-1,5.0); c1->Print(Form("hfit_sig_pt%d.gif",(int)fBinsPt[ipt])); fsig->SetParameter(0,2); fsig->SetParameter(1,fsig->GetParameter(1)*8.39614e-01/6.83080e-01);//correction from RC fsig->SetParameter(2,4.83182e-01); fsig->SetParameter(3,fsig->GetParameter(3)*2.33769e-01/2.26323e-01); cout << "fsig Integral = " << fsig->Integral(-1,11) << endl; for(int i=0;i<4;i++) cout << "fsig par " << i << "= " << fsig->GetParameter(i) << endl; // second obtain fit for the spikes hfit_spike = (TH1F*)hTemplate_S[ieta][ipt]->Clone(); hfit_spike -> SetName("hfit_spike"); hfit_spike -> Rebin(4); TF1 *fspike = new TF1("fspike", exp_conv, -1., 11., 12); fspike->SetParameters(sigPar); fspike->SetParameter(0,hfit_spike->GetMaximum()); fspike->SetLineColor(4); fspike->SetNpx(2500); hfit_spike->Fit(fspike,"","",-1,5.0); c1->Print(Form("hfit_spike_pt%d.gif",(int)fBinsPt[ipt])); fspike->SetParameter(0,2.0); cout << "fspike Integral = " << fspike->Integral(-1,11) << endl; float scale = (float)fsig->Integral(-1,11)/(float)fspike->Integral(-1,11); fspike->SetParameter(0,2.0*scale); cout << "now fspike Integral = " << fspike->Integral(-1,11) << endl; for(int i=0;i<4;i++) cout << "fspike par " << i << "= " << fspike->GetParameter(i) << endl; hsig->FillRandom("fsig",10000); hspike->FillRandom("fspike",10000); cout << "KS test for sideband data and sideband MC = " << hsig->KolmogorovTest(hspike,"X") << endl; cout << "KS test 2 for sideband data and sideband MC = " << hsig->KolmogorovTest(hspike) << endl; hsig->Reset(); hsig->SetMaximum(1.2); hsig->Draw(); // hspike->Draw("same"); fsig->Draw("same"); fspike->Draw("same"); TLegend* leg = new TLegend(0.35,0.70,0.55,0.85); leg->SetHeader(Form("p_{T}[%d,%d]",(int)fBinsPt[ipt],(int)fBinsPt[ipt+1])); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetTextSize(0.04); leg->SetBorderSize(0); leg->AddEntry(fsig,"Random-cone-corrected MC","f"); leg->AddEntry(fspike,"Spike","f"); leg->Draw("same"); c1->Print(Form("CorrRCSpike_pt%d.eps",(int)fBinsPt[ipt])); c1->Print(Form("CorrRCSpike_pt%d.gif",(int)fBinsPt[ipt])); c1->Print(Form("CorrRCSpike_pt%d.C",(int)fBinsPt[ipt])); } } }
void quantiles() { // demo for quantiles // Authors: Rene Brun, Eddy Offermann const Int_t nq = 10000; const Int_t nshots = 10000; Double_t xq[nq]; // position where to compute the quantiles in [0,1] Double_t yq[nq]; // array to contain the quantiles for (Int_t i=0;i<nq;i++) xq[i] = Float_t(i+1)/nq; TGraph *gr70 = new TGraph(nshots); TGraph *gr90 = new TGraph(nshots); TGraph *gr98 = new TGraph(nshots); TH1F *h = new TH1F("h","demo quantiles",500,-4,4); for (Int_t shot=0;shot<nshots;shot++) { h->FillRandom("gaus",50); h->GetQuantiles(nq,yq,xq); gr70->SetPoint(shot,shot+1,yq[70]); gr90->SetPoint(shot,shot+1,yq[90]); gr98->SetPoint(shot,shot+1,yq[98]); } //show the original histogram in the top pad TCanvas *c1 = new TCanvas("c1","demo quantiles",10,10,600,900); c1->SetFillColor(41); c1->Divide(1,3); c1->cd(1); h->SetFillColor(38); h->Draw(); // show the final quantiles in the middle pad c1->cd(2); gPad->SetFrameFillColor(33); gPad->SetGrid(); TGraph *gr = new TGraph(nq,xq,yq); gr->SetTitle("final quantiles"); gr->SetMarkerStyle(21); gr->SetMarkerColor(kRed); gr->SetMarkerSize(0.3); gr->Draw("ap"); // show the evolution of some quantiles in the bottom pad c1->cd(3); gPad->SetFrameFillColor(17); gPad->DrawFrame(0,0,nshots+1,3.2); gPad->SetGrid(); gr98->SetMarkerStyle(22); gr98->SetMarkerColor(kRed); gr98->Draw("lp"); gr90->SetMarkerStyle(21); gr90->SetMarkerColor(kBlue); gr90->Draw("lp"); gr70->SetMarkerStyle(20); gr70->SetMarkerColor(kMagenta); gr70->Draw("lp"); // add a legend TLegend *legend = new TLegend(0.85,0.74,0.95,0.95); legend->SetTextFont(72); legend->SetTextSize(0.05); legend->AddEntry(gr98," q98","lp"); legend->AddEntry(gr90," q90","lp"); legend->AddEntry(gr70," q70","lp"); legend->Draw(); }
void fullPedestalAnalysis(string inputDIR, string outputDIR, string inputCablingMap, string outputFileName){ gROOT->ProcessLine("gErrorIgnoreLevel = 1"); // open the file and prepare the cluster tree, adding the other trees as frined --> memory consuming std::cout<<"##################################"<<std::endl; std::cout<<"###### fullPedestalAnalysis ######"<<std::endl; std::cout<<"##################################"<<std::endl; clock_t tStart = clock(); // prepare style and load macros setTDRStyle(); gROOT->SetBatch(kTRUE); system(("mkdir -p "+outputDIR).c_str()); ifstream file; std::cout<<"### Make input file list"<<std::endl; system(("find "+inputDIR+" -name \"*.root\" > file.temp").c_str()); std::ifstream infile; string line; vector<string> fileList; infile.open("file.temp",ifstream::in); if(infile.is_open()){ while(!infile.eof()){ getline(infile,line); if(line != "" and TString(line).Contains(".root") and line !="\n"){ fileList.push_back(line); } } } system("rm file.temp"); std::sort(fileList.begin(),fileList.end()); TFile* cablingFile = TFile::Open(inputCablingMap.c_str(),"READ"); cablingFile->cd(); TTree* readoutMap = (TTree*) cablingFile->FindObjectAny("readoutMap"); TTreeReader reader(readoutMap); TTreeReaderValue<uint32_t> detid (reader,"detid"); TTreeReaderValue<uint16_t> fecCrate (reader,"fecCrate"); TTreeReaderValue<uint16_t> fecSlot (reader,"fecSlot"); TTreeReaderValue<uint16_t> fecRing (reader,"fecRing"); TTreeReaderValue<uint16_t> ccuAdd (reader,"ccuAdd"); TTreeReaderValue<uint16_t> ccuChan (reader,"ccuChan"); TTreeReaderValue<uint16_t> lldChannel (reader,"lldChannel"); TTreeReaderValue<uint16_t> fedId (reader,"fedId"); TTreeReaderValue<uint16_t> fedCh (reader,"fedCh"); // output tree TFile* ouputTreeFile = new TFile((outputDIR+"/"+outputFileName).c_str(),"RECREATE"); ouputTreeFile->cd(); ouputTreeFile->SetCompressionLevel(0); TTree* outputTree = new TTree("pedestalFullNoise","pedestalFullNoise"); // branches uint32_t detid_,fedKey_; uint16_t fecCrate_,fecSlot_, fecRing_, ccuAdd_, ccuChan_, lldChannel_, fedId_, fedCh_, apvId_, stripId_; float noiseMean_,noiseRMS_, noiseSkewness_, noiseKurtosis_; float fitChi2_, fitChi2Probab_, fitStatus_; float fitGausMean_, fitGausSigma_, fitGausNormalization_; float fitGausMeanError_, fitGausSigmaError_, fitGausNormalizationError_; float noiseIntegral3Sigma_, noiseIntegral3SigmaFromFit_; float noiseIntegral4Sigma_, noiseIntegral4SigmaFromFit_; float noiseIntegral5Sigma_, noiseIntegral5SigmaFromFit_; float kSValue_, kSProbab_, jBValue_, jBProbab_, aDValue_, aDProbab_; vector<float> noiseDistribution_, noiseDistributionError_; float xMin_, xMax_, nBin_ ; outputTree->Branch("detid",&detid_,"detid/i"); outputTree->Branch("fedKey",&fedKey_,"fedKey/i"); outputTree->Branch("fecCrate",&fecCrate_,"fecCrate/s"); outputTree->Branch("fecSlot",&fecSlot_,"fecSlot/s"); outputTree->Branch("fecRing",&fecRing_,"fecRing/s"); outputTree->Branch("ccuAdd",&ccuAdd_,"ccuAdd/s"); outputTree->Branch("ccuChan",&ccuChan_,"ccuChan/s"); outputTree->Branch("lldChannel",&lldChannel_,"lldChannel/s"); outputTree->Branch("fedId",&fedId_,"fedId/s"); outputTree->Branch("fedCh",&fedCh_,"fedCh/s"); outputTree->Branch("apvId",&apvId_,"apvId/s"); outputTree->Branch("stripId",&stripId_,"stripId/s"); outputTree->Branch("noiseMean",&noiseMean_,"noiseMean/F"); outputTree->Branch("noiseRMS",&noiseRMS_,"noiseRMS/F"); outputTree->Branch("noiseSkewness",&noiseSkewness_,"noiseSkewness/F"); outputTree->Branch("noiseKurtosis",&noiseKurtosis_,"noiseKurtosis/F"); outputTree->Branch("fitGausNormalization",&fitGausNormalization_,"fitGausNormalization/F"); outputTree->Branch("fitGausMean",&fitGausMean_,"fitGausMean/F"); outputTree->Branch("fitGausSigma",&fitGausSigma_,"fitGausSigma/F"); outputTree->Branch("fitGausNormalizationError",&fitGausNormalizationError_,"fitGausNormalizationError/F"); outputTree->Branch("fitGausMeanError",&fitGausMeanError_,"fitGausMeanError/F"); outputTree->Branch("fitGausSigmaError",&fitGausSigmaError_,"fitGausSigmaError/F"); outputTree->Branch("fitChi2",&fitChi2_,"fitChi2/F"); outputTree->Branch("fitChi2Probab",&fitChi2Probab_,"fitChi2Probab/F"); outputTree->Branch("fitStatus",&fitStatus_,"fitStatus_F"); outputTree->Branch("noiseIntegral3Sigma",&noiseIntegral3Sigma_,"noiseIntegral3Sigma/F"); outputTree->Branch("noiseIntegral3SigmaFromFit",&noiseIntegral3SigmaFromFit_,"noiseIntegral3SigmaFromFit/F"); outputTree->Branch("noiseIntegral4Sigma",&noiseIntegral4Sigma_,"noiseIntegral4Sigma/F"); outputTree->Branch("noiseIntegral4SigmaFromFit",&noiseIntegral4SigmaFromFit_,"noiseIntegral4SigmaFromFit/F"); outputTree->Branch("noiseIntegral5Sigma",&noiseIntegral4Sigma_,"noiseIntegral5Sigma/F"); outputTree->Branch("noiseIntegral5SigmaFromFit",&noiseIntegral4SigmaFromFit_,"noiseIntegral5SigmaFromFit/F"); outputTree->Branch("kSValue",&kSValue_,"kSValue/F"); outputTree->Branch("jBValue",&jBValue_,"jBValue/F"); outputTree->Branch("aDValue",&aDValue_,"aDValue/F"); outputTree->Branch("kSProbab",&kSProbab_,"kSProbab/F"); outputTree->Branch("jBProbab",&jBProbab_,"jBProbab/F"); outputTree->Branch("aDProbab",&aDProbab_,"aDProbab/F"); outputTree->Branch("xMin",&xMin_,"xMin/F"); outputTree->Branch("xMax",&xMax_,"xMax/F"); outputTree->Branch("nBin",&nBin_,"nBin/F"); bool histoBranches = false; // Loop on the file list to extract each histogram 2D DQM histo with full noise distribution TH1F* histoNoiseStrip = NULL; TF1* fitFunc = NULL; TH1F* randomHisto = NULL; TFitResultPtr result; for(auto file : fileList){ cout<<"input file: "<<file<<endl; TFile* inputFile = TFile::Open(file.c_str(),"READ"); inputFile->cd(); // take into account that the DQM file structure for strips is always the same --> use cabling map to browse the histograms reader.SetEntry(0); TH2* histoNoise = NULL; long int iChannel = 0; int noFitResult = 0; while(reader.Next()){ cout.flush(); if(iChannel %10 == 0) cout<<"\r"<<"iChannel "<<100*double(iChannel)/(readoutMap->GetEntries()/reductionFactor)<<" % "; if(iChannel > double(readoutMap->GetEntries())/reductionFactor) break; iChannel++; TString objName; uint32_t fedKey = SiStripFedKey(*fedId,SiStripFedKey::feUnit(*fedCh),SiStripFedKey::feChan(*fedCh)).key(); std::stringstream stream; stream << std::hex << fedKey; string fedKeyStr = stream.str(); if(fedKeyStr.size() == 4) objName = Form("DQMData/SiStrip/ControlView/FecCrate%d/FecSlot%d/FecRing%d/CcuAddr%d/CcuChan%d/ExpertHisto_PedsFullNoise_FedKey0x0000%s_LldChannel%d_Noise2D",*fecCrate,*fecSlot,*fecRing,*ccuAdd,*ccuChan,fedKeyStr.c_str(),*lldChannel); else if(fedKeyStr.size() == 5) objName = Form("DQMData/SiStrip/ControlView/FecCrate%d/FecSlot%d/FecRing%d/CcuAddr%d/CcuChan%d/ExpertHisto_PedsFullNoise_FedKey0x000%s_LldChannel%d_Noise2D",*fecCrate,*fecSlot,*fecRing,*ccuAdd,*ccuChan,fedKeyStr.c_str(),*lldChannel); else cerr<<"hex number to short "<<fedKeyStr<<" --> please check "<<endl; inputFile->GetObject(objName.Data(),histoNoise); // extract single strip noise histogram --> loop on the y-axis uint16_t apvID = 0; uint16_t stripID = 0; if(histoNoiseStrip == 0 or histoNoiseStrip == NULL){ histoNoiseStrip = new TH1F ("histoNoiseStrip","",histoNoise->GetNbinsX(),histoNoise->GetXaxis()->GetXmin(),histoNoise->GetXaxis()->GetXmax()); histoNoiseStrip->Sumw2(); } for(int iBinY = 0; iBinY < histoNoise->GetNbinsY(); iBinY++){ histoNoiseStrip->Reset(); histoNoiseStrip->SetDirectory(0); // two multiplexed APV per line if(iBinY < histoNoise->GetNbinsY()/2) apvID = 1; else apvID = 2; // strip id stripID++; if(stripID > 128) stripID = 1; // loop on x-axis bin for(int iBinX = 0; iBinX < histoNoise->GetNbinsX(); iBinX++){ histoNoiseStrip->SetBinContent(iBinX+1,histoNoise->GetBinContent(iBinX+1,iBinY+1)); histoNoiseStrip->SetBinError(iBinX+1,histoNoise->GetBinError(iBinX+1,iBinY+1)); } // to initialize branches detid_ = 0; fedKey_ = 0; fecCrate_ = 0; fecSlot_ = 0; fecRing_ = 0; ccuAdd_ = 0; ccuChan_ = 0; lldChannel_ = 0; fedId_ = 0; fedCh_ = 0; apvId_ = 0; stripId_ = 0; noiseMean_ = 0.; noiseRMS_ = 0.; noiseSkewness_ = 0.; noiseKurtosis_ = 0.; fitGausMean_ = 0.; fitGausSigma_ = 0.;fitGausNormalization_ = 0.; fitGausMeanError_ = 0.; fitGausSigmaError_ = 0.;fitGausNormalizationError_ = 0.; fitChi2_ = 0.; fitChi2Probab_ = 0.; fitStatus_ = -1.; noiseIntegral3Sigma_ = 0.; noiseIntegral3SigmaFromFit_ = 0.; noiseIntegral4Sigma_ = 0.; noiseIntegral4SigmaFromFit_ = 0.; noiseIntegral5Sigma_ = 0.; noiseIntegral5SigmaFromFit_ = 0.; kSProbab_ = 0.; jBProbab_ = 0.; kSValue_ = 0.; jBValue_ = 0.; aDValue_= 0.; aDProbab_ = 0.; nBin_ = 0.; xMin_ = 0.; xMax_ = 0.; // basic info detid_ = *detid; fedKey_ = fedKey; fecCrate_ = *fecCrate; fecSlot_ = *fecSlot; fecRing_ = *fecRing; ccuAdd_ = *ccuAdd; ccuChan_ = *ccuChan; lldChannel_ = *lldChannel; fedId_ = *fedId; fedCh_ = *fedCh; apvId_ = apvID; stripId_ = stripID; // basic info of nioise distribution noiseMean_ = histoNoiseStrip->GetMean(); noiseRMS_ = histoNoiseStrip->GetRMS(); noiseSkewness_ = histoNoiseStrip->GetSkewness(); noiseKurtosis_ = histoNoiseStrip->GetKurtosis(); float integral = histoNoiseStrip->Integral(); noiseIntegral3Sigma_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+noiseRMS_*3),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-noiseRMS_*3)))/integral; noiseIntegral4Sigma_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+noiseRMS_*4),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-noiseRMS_*4)))/integral; noiseIntegral5Sigma_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+noiseRMS_*5),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-noiseRMS_*5)))/integral; // make a gaussian fit if(fitFunc == NULL or fitFunc == 0){ fitFunc = new TF1 ("fitFunc","gaus(0)",histoNoise->GetXaxis()->GetXmin(),histoNoise->GetXaxis()->GetXmax()); } fitFunc->SetRange(histoNoise->GetXaxis()->GetXmin(),histoNoise->GetXaxis()->GetXmax()); fitFunc->SetParameters(histoNoiseStrip->Integral(),noiseMean_,noiseRMS_); result = histoNoiseStrip->Fit(fitFunc,"QSR"); if(result.Get()){ fitStatus_ = result->Status(); fitGausNormalization_ = fitFunc->GetParameter(0); fitGausMean_ = fitFunc->GetParameter(1); fitGausSigma_ = fitFunc->GetParameter(2); fitGausNormalizationError_ = fitFunc->GetParError(0); fitGausMeanError_ = fitFunc->GetParError(1); fitGausSigmaError_ = fitFunc->GetParError(2); fitChi2_ = result->Chi2(); fitChi2Probab_ = result->Prob(); noiseIntegral3SigmaFromFit_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+fitGausSigma_*3),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-fitGausSigma_*3)))/histoNoiseStrip->Integral(); noiseIntegral4SigmaFromFit_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+fitGausSigma_*4),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-fitGausSigma_*4)))/histoNoiseStrip->Integral(); noiseIntegral5SigmaFromFit_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+fitGausSigma_*5),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-fitGausSigma_*5)))/histoNoiseStrip->Integral(); jBValue_ = (histoNoiseStrip->Integral()/6)*(noiseSkewness_*noiseSkewness_+(noiseKurtosis_*noiseKurtosis_)/4); jBProbab_ = ROOT::Math::chisquared_cdf_c(jBValue_,2); if(randomHisto == 0 or randomHisto == NULL) randomHisto = (TH1F*) histoNoiseStrip->Clone("randomHisto"); randomHisto->Reset(); randomHisto->SetDirectory(0); if(integral != 0){ if(generateRandomDistribution){ randomHisto->FillRandom("fitFunc",histoNoiseStrip->Integral()); kSValue_ = histoNoiseStrip->KolmogorovTest(randomHisto,"MN"); kSProbab_ = histoNoiseStrip->KolmogorovTest(randomHisto,"N"); aDValue_ = histoNoiseStrip->AndersonDarlingTest(randomHisto,"T"); aDProbab_ = histoNoiseStrip->AndersonDarlingTest(randomHisto); } else{ randomHisto->Add(fitFunc); kSValue_ = histoNoiseStrip->KolmogorovTest(randomHisto,"MN"); kSProbab_ = histoNoiseStrip->KolmogorovTest(randomHisto,"N"); // AD test ROOT::Fit::BinData data1; ROOT::Fit::BinData data2; ROOT::Fit::FillData(data1,histoNoiseStrip,0); data2.Initialize(randomHisto->GetNbinsX()+1,1); for(int ibin = 0; ibin < randomHisto->GetNbinsX(); ibin++){ if(histoNoiseStrip->GetBinContent(ibin+1) != 0 or randomHisto->GetBinContent(ibin+1) >= 1) data2.Add(randomHisto->GetBinCenter(ibin+1),randomHisto->GetBinContent(ibin+1),randomHisto->GetBinError(ibin+1)); } double probab; double value; ROOT::Math::GoFTest::AndersonDarling2SamplesTest(data1,data2,probab,value); aDValue_ = value; aDProbab_ = probab; } } } else noFitResult++; if(not histoBranches){ noiseDistribution_.clear(); noiseDistributionError_.clear(); outputTree->Branch("noiseDistribution","vector<float>",&noiseDistribution_); outputTree->Branch("noiseDistributionError","vector<float>",&noiseDistributionError_); histoBranches = true; } // set histogram noiseDistribution_.clear(); noiseDistributionError_.clear(); for(int iBin = 0; iBin < histoNoiseStrip->GetNbinsX(); iBin++){ noiseDistribution_.push_back(histoNoiseStrip->GetBinContent(iBin+1)); noiseDistributionError_.push_back(histoNoiseStrip->GetBinError(iBin+1)); } nBin_ = histoNoiseStrip->GetNbinsX(); xMin_ = histoNoise->GetXaxis()->GetBinLowEdge(1); xMax_ = histoNoise->GetXaxis()->GetBinLowEdge(histoNoise->GetNbinsX()+1); // fill all branches for each strip ouputTreeFile->cd(); outputTree->Fill(); } } inputFile->Close(); std::cout<<std::endl; cout<<"No fit results found for "<<100*double(noFitResult)/iChannel<<endl; } outputTree->BuildIndex("detid"); outputTree->Write(outputTree->GetName(),TObject::kOverwrite); ouputTreeFile->Close(); cablingFile->Close(); /* Do your stuff here */ cout<<"Time taken: "<<(double)(clock() - tStart)/CLOCKS_PER_SEC<<endl; }