#include "TFile.h" #include "TCanvas.h" #include "TStyle.h" #include "TH1.h" #include "TH2.h" #include "TH3.h" #include "TGaxis.h" #include "TRandom.h" #include "TLegend.h" #include "TPaveStats.h" #include "TGraph.h" #include "TSystem.h" #include "TTree.h" #include "TTreePlayer.h" #include "TF1.h" void calocal() { int ifile=500628; //Root File number name. To change each time /* int a=8; //First subdetector name to analyze. To change each time //TO USE FOR FILES WITH THE TARGET int b=3; //Second subdetector name to analyze. To change each time //TO USE FOR FILES WITH THE TARGET int c=5; //Third subdetector name to analyze. To change each time //TO USE FOR FILES WITH THE TARGET int d=4; //Fourth subdetector name to analyze. To change each time //TO USE FOR FILES WITH THE TARGET */ // /* int a=9; //First subdetector name to analyze. To change each time //TO USE FOR FILES WITH THE TARGET int b=2; //Second subdetector name to analyze. To change each time //TO USE FOR FILES WITH THE TARGET int c=0; //Third subdetector name to analyze. To change each time //TO USE FOR FILES WITH THE TARGET int d=1; //Fourth subdetector name to analyze. To change each time //TO USE FOR FILES WITH THE TARGE // */ int csig=3;//Sigma const int p1p2=2; //a,b int p13subp23sub=1; //a,c int p14subp24sub=2; //a,d int p13suballp23suball=p13subp23sub; //a,c int p14subp24suball=p14subp24sub; //a,d int p14subp24subsum=2; float p1; float p2; float p03sub; float p13sub; float p23sub; float p03suball; float p13suball; float p23suball; float p04sub; float p14sub; float p24sub; float p04suball; float p14suball; float p24suball; float p04subsum; float p14subsum; float p24subsum; char dirin[50];//Directory where there is the input root file char dirout[50];//Main Directory where to save the output files char htempname[50]; char htempabname[50]; char heneabname[50]; char fobject[50]; char cdenename[50]; char cddeltatimeXname[50]; char cddeltatimeYname[50]; char cdtempXnameab[50]; char cdtempYnameab[50]; char cdeneXnameab[50]; char cdeneYnameab[50]; char particletype[200]; char timenamesuba[50]; char timeenergynamesuba[50]; char timenamesubb[50]; char timeenergynamesubb[50]; char timenamesubc[50]; char timeenergynamesubc[50]; char timenamesubd[50]; char timeenergynamesubd[50]; char energyunit[50]; sprintf(dirin, "C:/si-calo-sep18/"); //TO USE FOR FILES WITH THE TARGET //sprintf(dirin, "D:/data_calib/"); //TO USE FOR FILES WITHOUT THE TARGET sprintf(dirout, "C:/grap"); sprintf(htempname, "#DeltaTime"); sprintf(htempabname, "Time"); sprintf(heneabname, "Energy"); sprintf(fobject, "lemma"); sprintf(cdenename, "Energy"); sprintf(cddeltatimeXname, "#DeltaTime (ns)"); sprintf(cddeltatimeYname, "# Counts"); sprintf(cdtempXnameab, "Time (ns)"); sprintf(cdtempYnameab, "# Counts"); sprintf(cdeneXnameab, "Energy (ADC counts)"); sprintf(cdeneYnameab, "# Counts/20ADC counts"); sprintf(particletype, "si-%d, e^{+}_{22GeV}:",ifile); sprintf(energyunit, "ADC counts"); if (a==8 || a==9 || a==6 || a==7 ) { sprintf(timenamesuba, "Scintillator"); //First subdetector tipology name for time plot. sprintf(timeenergynamesuba, "Scintillator"); //First subdetector tipology name for energy plot. } else if (a==0 || a==1 || a==2 || a==3 || a==4 || a==5) { sprintf(timenamesuba, "Lead"); //First subdetector tipology name for time plot. sprintf(timeenergynamesuba, "Lead"); //First subdetector tipology name for energy plot. } else if (a==12 || a==13 || a==14 || a==15 ) { sprintf(timenamesuba, "Horsa"); //First subdetector tipology name for time plot. sprintf(timeenergynamesuba, "Horsa"); //First subdetector tipology name for energy plot. } else if (a==16 || a==17 || a==18 || a==19 || a==10 || a==11 || a==20 || a==21 || a==22 || a==23 ) { sprintf(timenamesuba, "Versa"); //First subdetector tipology name for time plot. sprintf(timeenergynamesuba, "Versa"); //First subdetector tipology name for energy plot. } if (b==8 || b==9 || b==6 || b==7){ sprintf(timenamesubb, "Scintillator"); //Second subdetector tipology name for time plot. sprintf(timeenergynamesubb, "Scintillator"); //Second subdetector tipology name for energy plot. } else if (b==0 || b==1 || b==2 || b==3 || b==4 || b==5) { sprintf(timenamesubb, "Lead"); //Second subdetector tipology name for time plot. sprintf(timeenergynamesubb, "Lead"); //Second subdetector tipology name for energy plot. } else if (b==12 || b==13 || b==14 || b==15 ){ sprintf(timenamesubb, "Horsa"); //Second subdetector tipology name for time plot. sprintf(timeenergynamesubb, "Horsa"); //Second subdetector tipology name for energy plot. } else if (b==16 || b==17 || b==18 || b==19 || b==10 || b==11 || b==20 || b==21 || b==22 || b==23 ){ sprintf(timenamesubb, "Versa"); //Second subdetector tipology name for time plot. sprintf(timeenergynamesubb, "Versa"); //Second subdetector tipology name for energy plot. } if (c==8 || c==9 || c==6 || c==7){ sprintf(timenamesubc, "Scintillator"); //Third subdetector tipology name for time plot. sprintf(timeenergynamesubc, "Scintillator"); //Third subdetector tipology name for energy plot. } else if (c==0 || c==1 || c==2 || c==3 || c==4 || c==5) { sprintf(timenamesubc, "Lead"); //Third subdetector tipology name for time plot. sprintf(timeenergynamesubc, "Lead"); //Third subdetector tipology name for energy plot. } else if (c==12 || c==13 || c==14 || c==15 ){ sprintf(timenamesubc, "Horsa"); //Third subdetector tipology name for time plot. sprintf(timeenergynamesubc, "Horsa"); //Third subdetector tipology name for energy plot. } else if (c==16 || c==17 || c==18 || c==19 || c==10 || c==11 || c==20 || c==21 || c==22 || c==23 ){ sprintf(timenamesubc, "Versa"); //Third subdetector tipology name for time plot. sprintf(timeenergynamesubc, "Versa"); //Third subdetector tipology name for energy plot. } if (d==8 || d==9 || d==6 || d==7){ sprintf(timenamesubd, "Scintillator"); //Fourth subdetector tipology name for time plot. sprintf(timeenergynamesubd, "Scintillator"); //Fourth subdetector tipology name for energy plot. } else if (d==0 || d==1 || d==2 || d==3 || d==4 || d==5) { sprintf(timenamesubd, "Lead"); //Fourth subdetector tipology name for time plot. sprintf(timeenergynamesubd, "Lead"); //Fourth subdetector tipology name for energy plot. } else if (d==12 || d==13 || d==14 || d==15 ){ sprintf(timenamesubd, "Horsa"); //Fourth subdetector tipology name for time plot. sprintf(timeenergynamesubd, "Horsa"); //Fourth subdetector tipology name for energy plot. } else if (d==16 || d==17 || d==18 || d==19 || d==10 || d==11 || d==20 || d==21 || d==22 || d==23 ){ sprintf(timenamesubd, "Versa"); //Fourth subdetector tipology name for time plot. sprintf(timeenergynamesubd, "Versa"); //Fourth subdetector tipology name for energy plot. } int n=3; int c_YTitleSize=40; int c_YTitleFont=43; double c_YTitleOffset=1.3; int c_YLabelFont=43; int c_YLabelSize=40; int c_XTitleSize=40; int c_XTitleFont=43; int c_XTitleOffset=1; int c_XLabelFont=43; int c_XLabelSize=40; int c1_YTitleSize=30; int c1_YTitleFont=43; double c1_YTitleOffset=2; int c1_YLabelFont=43; int c1_YLabelSize=30; int c1_XTitleSize=30; int c1_XTitleFont=43; int c1_XTitleOffset=2; int c1_XLabelFont=43; int c1_XLabelSize=30; int c2_YTitleSize=30; int c2_YTitleFont=43; double c2_YTitleOffset=2; int c2_YLabelFont=43; int c2_YLabelSize=30; int c2_XTitleSize=30; int c2_XTitleFont=43; int c2_XTitleOffset=2; int c2_XLabelFont=43; int c2_XLabelSize=30; int c2_XSetRangem=0; int c2_XSetRangeMa=4000; int c2_XSetRangeMb=2000; float heneabfillcolor=0.35; float htimeabfillcolor=0.35; float hdeltatimeabfillcolor=0.35; TString myfilein = TString::Format("%ssi-%d.root",dirin,ifile); gSystem->mkdir(TString::Format("%stestbeam/", dirout), kTRUE); gSystem->mkdir(TString::Format("%stestbeam/si-%d/", dirout,ifile), kTRUE); gSystem->mkdir(TString::Format("%stestbeam/si-%d/sub_%d-%d/",dirout,ifile, a,b), kTRUE); // TO USE FOR FILES WITH TARGET gSystem->mkdir(TString::Format("%stestbeam/si-%d/sub_%d-%d/sub_%d",dirout,ifile, a,b,c),kTRUE); // TO USE FOR FILES WITH TARGET gSystem->mkdir(TString::Format("%stestbeam/si-%d/sub_%d-%d/sub_%d/sub_%d/",dirout,ifile, a,b,c,d),kTRUE); // TO USE FOR FILES WITH TARGET TString outfolder=TString::Format("%stestbeam/si-%d/sub_%d-%d/",dirout,ifile, a,b); // TO USE FOR FILES WITH TARGET TString outfolder3sub=TString::Format("%stestbeam/si-%d/sub_%d-%d/sub_%d/",dirout,ifile, a,b,c); // TO USE FOR FILES WITH TARGET TString outfolder4sub=TString::Format("%stestbeam/si-%d/sub_%d-%d/sub_%d/sub_%d/",dirout,ifile, a,b,c,d); // TO USE FOR FILES WITH TARGET TString myplotdeltatimeout = TString::Format("%ssi-%d_deltatime%d-%d.pdf",outfolder.Data(),ifile,a,b); // TO USE FOR FILES WITH TARGET TString myplotdeltatimeout3sub = TString::Format("%ssi-%d_deltatime%d-%d-%d.pdf",outfolder3sub.Data(),ifile,a,b,c); // TO USE FOR FILES WITH TARGET TString myplotdeltatimeout4sub = TString::Format("%ssi-%d_deltatime%d-%d-%d-%d.pdf",outfolder4sub.Data(),ifile,a,b,c,d); // TO USE FOR FILES WITH TARGET TString myplotdeltatimeout3suball = TString::Format("%ssi-%d_deltatime%d-%d.pdf",outfolder3sub.Data(),ifile,a,c); // TO USE FOR FILES WITH TARGET TString myplotdeltatimeout4suball = TString::Format("%ssi-%d_deltatime%d-%d.pdf",outfolder4sub.Data(),ifile,a,d); // TO USE FOR FILES WITH TARGET TString myplottimeout = TString::Format("%ssi-%d_time%d-%d.pdf",outfolder.Data(),ifile,a,b); // TO USE FOR FILES WITH TARGET TString myplottimeout3sub = TString::Format("%ssi-%d_time%d-%d-%d.pdf",outfolder3sub.Data(),ifile,a,b,c); // TO USE FOR FILES WITH TARGET TString myplottimeout4sub = TString::Format("%ssi-%d_time%d-%d-%d-%d.pdf",outfolder4sub.Data(),ifile,a,b,c,d); // TO USE FOR FILES WITH TARGET TString myploteneout = TString::Format("%ssi-%d_ene%d-%d.pdf",outfolder.Data(),ifile,a,b); // TO USE FOR FILES WHIT TARGET TString myploteneout3sub = TString::Format("%ssi-%d_ene%d-%d-%d.pdf",outfolder3sub.Data(),ifile,a,b,c); // TO USE FOR FILES WHIT TARGET TString myploteneout4sub = TString::Format("%ssi-%d_ene%d-%d-%d-%d.pdf",outfolder4sub.Data(),ifile,a,b,c,d); // TO USE FOR FILES WHIT TARGET TString myploteneout4subsum = TString::Format("%ssi-%d_ene_%d.pdf",outfolder4sub.Data(),ifile,c); // TO USE FOR FILES WHIT TARGET TString cdname = TString::Format("%s Time_{%s}_{%d}-Time_{%s}_{%d}", particletype,timenamesuba,a,timenamesubb,b); // TO USE FOR FILES WITH TARGET TString cdname3sub = TString::Format("%s Time_{%s}_{%d}-Time_{%s}_{%d}", particletype, timenamesuba,a,timenamesubc,c); // TO USE FOR FILES WITH TARGET METHOD 2 TString cdname4sub = TString::Format("%s Time_{%s}_{%d}-Time_{%s}_{%d}", particletype, timenamesuba,a,timenamesubd,d); // TO USE FOR FILES WITH TARGET METHOD 2 TString cdtempnamea = TString::Format("%s Time_{%s}_{%d}", particletype,timeenergynamesuba,a); TString cdtempnameb = TString::Format("%s Time_{%s}_{%d}",particletype, timeenergynamesubb,b); // TO USE FOR FILES WITH TARGET TString cdtempnamec = TString::Format("%s Time_{%s}_{%d}",particletype, timeenergynamesubc,c); // TO USE FOR FILES WITH TARGET TString cdtempnamed = TString::Format("%s Time_{%s}_{%d}",particletype, timeenergynamesubd,d); // TO USE FOR FILES WITH TARGET TString cdenenamea = TString::Format("%s Energy_{%s}_{%d}", particletype,timeenergynamesuba,a); TString cdenenameb = TString::Format("%s Energy_{%s}_{%d}", particletype,timeenergynamesubb,b); // TO USE FOR FILES WITH TARGET TString cdenenamec = TString::Format("%s Energy_{%s}_{%d}", particletype,timeenergynamesubc,c); // TO USE FOR FILES WITH TARGET TString cdenenamed = TString::Format("%s Energy_{%s}_{%d}", particletype,timeenergynamesubd,d); // TO USE FOR FILES WITH TARGET TString cdenenamesum = TString::Format("Released energy by 22GeV e^{+}", particletype,c); // TO USE FOR FILES WITH TARGET TString canvtitle = TString::Format("si-%d",ifile); TFile *fin = TFile::Open(myfilein); fin->ls (); TGaxis::SetMaxDigits(n); if (fin == 0) { printf("Error: cannot open the file!\n"); } else { TTree *t=0; fin->GetObject(fobject,t); TCanvas *c0 = new TCanvas("c0",canvtitle,1280,1024); gStyle->SetOptFit(); gStyle->SetOptStat(111110); t->SetLineColor(kBlue); t->Draw(Form("Calo_Time[%d]-Calo_Time[%d] >> htemp(1100, -550., 550.)", a, b)); t->GetHistogram()->SetTitle(cdname); t->SetScanField(0); /* ((TTreePlayer*)(t->GetPlayer()))->SetScanRedirect(true); ((TTreePlayer*)(t->GetPlayer()))->SetScanFileName(mydatavalueouta); t->Scan(Form("Calo_Time[%d]",a)); ((TTreePlayer*)(t->GetPlayer()))->SetScanRedirect(true); ((TTreePlayer*)(t->GetPlayer()))->SetScanFileName(mydatavalueoutb); t->Scan(Form("Calo_Time[%d]",b)); ((TTreePlayer*)(t->GetPlayer()))->SetScanRedirect(true); ((TTreePlayer*)(t->GetPlayer()))->SetScanFileName(mydatavalueoutab); t->Scan(Form("Calo_Time[%d]-Calo_Time[%d]",a,b)); */ TH1F *htemp = (TH1F*)gPad->GetPrimitive("htemp"); TF1 *g1 = new TF1 ("m1", "gaus", -150, -110); g1->SetLineColor(kYellow); TF1 *g2 = new TF1 ("m2", "gaus", -140, -100); g2->SetLineColor(kGreen); TF1 *f1 = new TF1("double_gaus", "gaus(0) + gaus(3)", -150, -100); f1->SetParNames("Constant 1", "Mean 1", "Sigma 1","Constant 2", "Mean 2", "Sigma 2"); f1->SetLineColor(kRed); htemp->Fit(g1, "R"); htemp->Fit(g2, "R"); Double_t par[6]; g1->GetParameters(&par[0]); g2->GetParameters(&par[3]); f1->SetParameters(par); htemp->Fit(f1, "R"); htemp->Draw("e1"); g1->Draw("SAME"); g2->Draw("SAME"); f1->Draw("SAME"); std::cout << g1->Mean(f1->GetXmin(), f1->GetXmax()) << std::endl; std::cout << TMath::Sqrt(g1->Variance(f1->GetXmin(), f1->GetXmax())) << std::endl; std::cout << g2->Mean(f1->GetXmin(), f1->GetXmax()) << std::endl; std::cout << TMath::Sqrt(g2->Variance(f1->GetXmin(), f1->GetXmax())) << std::endl; std::cout << f1->Mean(f1->GetXmin(), f1->GetXmax()) << std::endl; std::cout << TMath::Sqrt(f1->Variance(f1->GetXmin(), f1->GetXmax())) << std::endl; Double_t xmin = f1->GetXmin(); Double_t xmax = f1->GetXmax(); Double_t mean = f1->Mean(xmin, xmax); Double_t sigma = TMath::Sqrt(f1->Variance(xmin, xmax)); xmin = mean - 5.0 * sigma; xmax = mean + 5.0 * sigma; mean = f1->Mean(xmin, xmax); sigma = TMath::Sqrt(f1->Variance(xmin, xmax)); std::cout << "Mean = " << mean << std::endl; std::cout << "Sigma = " << sigma << std::endl; if (p1p2==1) { p1=f1->GetParameter(1); p2=f1->GetParameter(2); } else if (p1p2==2) { p1=f1->GetParameter(4); p2=f1->GetParameter(5); } htemp->GetXaxis()->SetTitle(cddeltatimeXname); htemp->GetYaxis()->SetTitle(cddeltatimeYname); htemp->GetYaxis()->SetTitleSize(c_YTitleSize); htemp->GetYaxis()->SetTitleFont(c_YTitleFont); htemp->GetYaxis()->SetTitleOffset(c_YTitleOffset); htemp->GetYaxis()->SetLabelFont(c_YLabelFont); htemp->GetYaxis()->SetLabelSize(c_YLabelSize); htemp->GetXaxis()->SetTitleSize(c_XTitleSize); htemp->GetXaxis()->SetTitleFont(c_XTitleFont); htemp->GetXaxis()->SetTitleOffset(c_XTitleOffset); htemp->GetXaxis()->SetLabelFont(c_XLabelFont); htemp->GetXaxis()->SetLabelSize(c_XLabelSize); htemp->SetFillColorAlpha(kBlue, hdeltatimeabfillcolor); htemp->Draw(); htemp->SetName(htempname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn c0->Update(); TLegend* leg = new TLegend(0.15, 0.7, .25, .75); leg->SetHeader("Legend"); leg->SetNColumns(1); leg->AddEntry(htemp, "Data", "l"); leg->AddEntry(f1, "Fit", "l"); //TO USE FOR 2 GAUSSIAN FIT leg->Draw(); c0->Update(); gPad->Modified(); gPad->Update(); TPaveStats *statsgdeltatime = (TPaveStats*)htemp->GetListOfFunctions()->FindObject("stats"); statsgdeltatime->SetTextColor(kBlue); statsgdeltatime->SetX1NDC(0.80); statsgdeltatime->SetX2NDC(0.98); statsgdeltatime->SetY1NDC(0.77); statsgdeltatime->SetY2NDC(0.92); statsgdeltatime->AddText(TString::Format("Mean = %g", p1)); statsgdeltatime->AddText(TString::Format("Sigma = %g", p2)); statsgdeltatime->DrawClone(); gPad->Update(); c0->Print(myplotdeltatimeout); delete c0; TCanvas *c1 = new TCanvas("c1",canvtitle,1280,1024); c1->Divide (2,1); c1->cd(1); t->SetLineColor(kBlue); t->Draw(Form("Calo_Time[%d] >> htemp(550., 0., 550.)",a)); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdtempnamea); TH1F *htempa = (TH1F*)gPad->GetPrimitive("htemp"); htempa->GetXaxis()->SetTitle(cdtempXnameab); htempa->GetYaxis()->SetTitle(cdtempYnameab); htempa->GetYaxis()->SetTitleSize(c1_YTitleSize); htempa->GetYaxis()->SetTitleFont(c1_YTitleFont); htempa->GetYaxis()->SetTitleOffset(c1_YTitleOffset); htempa->GetYaxis()->SetLabelFont(c1_YLabelFont); htempa->GetYaxis()->SetLabelSize(c1_YLabelSize); htempa->GetXaxis()->SetTitleSize(c1_XTitleSize); htempa->GetXaxis()->SetTitleFont(c1_XTitleFont); htempa->GetXaxis()->SetTitleOffset(c1_XTitleOffset); htempa->GetXaxis()->SetLabelFont(c1_XLabelFont); htempa->GetXaxis()->SetLabelSize(c1_XLabelSize); htempa->SetFillColorAlpha(kBlue, htimeabfillcolor); htempa->Draw(); htempa->SetName(htempabname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legtempa = new TLegend(0.65, 0.7, .75, .75); legtempa->SetHeader("Legend"); legtempa->SetNColumns(1); legtempa->AddEntry(htempa, "Data", "l"); legtempa->Draw(); gPad->Update(); TPaveStats *statsgtempa = (TPaveStats*)htempa->GetListOfFunctions()->FindObject("stats"); statsgtempa->SetTextColor(kBlue); statsgtempa->SetX1NDC(0.80); statsgtempa->SetX2NDC(0.98); statsgtempa->SetY1NDC(0.77); statsgtempa->SetY2NDC(0.92); gPad->Update(); c1->cd(2); t->SetLineColor(kBlue); t->Draw(Form("Calo_Time[%d] >> htemp(550., 0., 550.)",b)); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdtempnameb); TH1F *htempb = (TH1F*)gPad->GetPrimitive("htemp"); htempb->GetXaxis()->SetTitle(cdtempXnameab); htempb->GetYaxis()->SetTitle(cdtempYnameab); htempb->GetYaxis()->SetTitleSize(c1_YTitleSize); htempb->GetYaxis()->SetTitleFont(c1_YTitleFont); htempb->GetYaxis()->SetTitleOffset(c1_YTitleOffset); htempb->GetYaxis()->SetLabelFont(c1_YLabelFont); htempb->GetYaxis()->SetLabelSize(c1_YLabelSize); htempb->GetXaxis()->SetTitleSize(c1_XTitleSize); htempb->GetXaxis()->SetTitleFont(c1_XTitleFont); htempb->GetXaxis()->SetTitleOffset(c1_XTitleOffset); htempb->GetXaxis()->SetLabelFont(c1_XLabelFont); htempb->GetXaxis()->SetLabelSize(c1_XLabelSize); htempb->SetFillColorAlpha(kBlue, htimeabfillcolor); htempb->Draw(); htempb->SetName(htempabname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legtempb = new TLegend(0.65, 0.7, .75, .75); legtempb->SetHeader("Legend"); legtempb->SetNColumns(1); legtempb->AddEntry(htempb, "Data", "l"); legtempb->Draw(); gPad->Update(); TPaveStats *statsgtempb = (TPaveStats*)htempb->GetListOfFunctions()->FindObject("stats"); statsgtempb->SetTextColor(kBlue); statsgtempb->SetX1NDC(0.80); statsgtempb->SetX2NDC(0.98); statsgtempb->SetY1NDC(0.77); statsgtempb->SetY2NDC(0.92); gPad->Update(); c1->Print(myplottimeout); delete c1; TCanvas *c2 = new TCanvas("c2",canvtitle,1280,1024); c2->Divide (2,1); c2->cd(1); t->SetLineColor(kBlue); TCut cut = TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) ", a, b, p1, csig, p2).Data(); TString heneastring = TString::Format("Calo_EnDep[%d] >> htemp(7000., 0., 7000.)", a); t->Draw(heneastring, cut); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdenenamea); TH1F *henea = (TH1F*)gPad->GetPrimitive("htemp"); henea->GetXaxis()->SetTitle(cdeneXnameab); henea->GetYaxis()->SetTitle(cdeneYnameab); henea->GetYaxis()->SetTitleSize(c2_YTitleSize); henea->GetYaxis()->SetTitleFont(c2_YTitleFont); henea->GetYaxis()->SetTitleOffset(c2_YTitleOffset); henea->GetYaxis()->SetLabelFont(c2_YLabelFont); henea->GetYaxis()->SetLabelSize(c2_YLabelSize); henea->GetXaxis()->SetTitleSize(c2_XTitleSize); henea->GetXaxis()->SetTitleFont(c2_XTitleFont); henea->GetXaxis()->SetTitleOffset(c2_XTitleOffset); henea->GetXaxis()->SetLabelFont(c2_XLabelFont); henea->GetXaxis()->SetLabelSize(c2_XLabelSize); henea->SetFillColorAlpha(kBlue, heneabfillcolor); henea->Draw(); henea->SetName(heneabname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legenea = new TLegend(0.65, 0.7, .75, .75); legenea->SetHeader("Legend"); legenea->SetNColumns(1); legenea->AddEntry(henea, "Data", "l"); legenea->Draw(); gPad->Update(); TPaveStats *statsgenea = (TPaveStats*)henea->GetListOfFunctions()->FindObject("stats"); statsgenea->SetTextColor(kBlue); statsgenea->SetX1NDC(0.80); statsgenea->SetX2NDC(0.98); statsgenea->SetY1NDC(0.77); statsgenea->SetY2NDC(0.92); gPad->Update(); c2->cd(2); t->SetLineColor(kBlue); TString henebstring = TString::Format("Calo_EnDep[%d] >> htemp(7000., 0., 7000.)", b); t->Draw(henebstring, cut); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdenenameb); TH1F *heneb = (TH1F*)gPad->GetPrimitive("htemp"); heneb->GetXaxis()->SetTitle(cdeneXnameab); heneb->GetYaxis()->SetTitle(cdeneYnameab); heneb->GetYaxis()->SetTitleSize(c2_YTitleSize); heneb->GetYaxis()->SetTitleFont(c2_YTitleFont); heneb->GetYaxis()->SetTitleOffset(c2_YTitleOffset); heneb->GetYaxis()->SetLabelFont(c2_YLabelFont); heneb->GetYaxis()->SetLabelSize(c2_YLabelSize); heneb->GetXaxis()->SetTitleSize(c2_XTitleSize); heneb->GetXaxis()->SetTitleFont(c2_XTitleFont); heneb->GetXaxis()->SetTitleOffset(c2_XTitleOffset); heneb->GetXaxis()->SetLabelFont(c2_XLabelFont); heneb->GetXaxis()->SetLabelSize(c2_XLabelSize); heneb->SetFillColorAlpha(kBlue, heneabfillcolor); heneb->Draw(); heneb->SetName(heneabname); gPad->Modified(); gPad->Update(); TLegend* legeneb = new TLegend(0.65, 0.7, .75, .75); legeneb->SetHeader("Legend"); legeneb->SetNColumns(1); legeneb->AddEntry(heneb, "Data", "l"); legeneb->Draw(); gPad->Update(); TPaveStats *statsgeneb = (TPaveStats*)heneb->GetListOfFunctions()->FindObject("stats"); statsgeneb->SetTextColor(kBlue); statsgeneb->SetX1NDC(0.80); statsgeneb->SetX2NDC(0.98); statsgeneb->SetY1NDC(0.77); statsgeneb->SetY2NDC(0.92); gPad->Update(); c2->Print(myploteneout); delete c2; /*----------------------------------SECTION FOR 3 SUBDETECTORS COINCIDENCE METHOD 2----------------------------------*/ TCanvas *c11 = new TCanvas("c11",canvtitle,1280,1024); gStyle->SetOptFit(); t->SetLineColor(kBlue); t->Draw(Form("Calo_Time[%d]-Calo_Time[%d] >> htemp(1100., -550., 550.)", a, c)); t->GetHistogram()->SetTitle(cdname3sub); t->SetScanField(0); TH1F *htemp3suball = (TH1F*)gPad->GetPrimitive("htemp"); TF1 *g13suball = new TF1 ("m13suball", "gaus", -130, -110); g13suball->SetLineColor(kYellow); TF1 *g23suball = new TF1 ("m23suball", "gaus", -120, -100); g23suball->SetLineColor(kGreen); TF1 *f13suball = new TF1("double_gaus3suball", "gaus(0) + gaus(3)", -130, -100); f13suball->SetParNames("Constant 1", "Mean 1", "Sigma 1","Constant 2", "Mean 2", "Sigma 2"); f13suball->SetParLimits(5,0,5); f13suball->SetLineColor(kRed); htemp3suball->Fit(g13suball, "R"); htemp3suball->Fit(g23suball, "R"); Double_t par3suball[6]; g13suball->GetParameters(&par3suball[0]); g23suball->GetParameters(&par3suball[3]); f13suball->SetParameters(par3suball); htemp3suball->Fit(f13suball, "R"); htemp3suball->Draw("e1"); g13suball->Draw("SAME"); g23suball->Draw("SAME"); f13suball->Draw("SAME"); std::cout << g13suball->Mean(f13suball->GetXmin(), f13suball->GetXmax()) << std::endl; std::cout << TMath::Sqrt(g13suball->Variance(f13suball->GetXmin(), f13suball->GetXmax())) << std::endl; std::cout << g23suball->Mean(f13suball->GetXmin(), f13suball->GetXmax()) << std::endl; std::cout << TMath::Sqrt(g23suball->Variance(f13suball->GetXmin(), f13suball->GetXmax())) << std::endl; std::cout << f13suball->Mean(f13suball->GetXmin(), f13suball->GetXmax()) << std::endl; std::cout << TMath::Sqrt(f13suball->Variance(f13suball->GetXmin(), f13suball->GetXmax())) << std::endl; Double_t xmin3suball = f13suball->GetXmin(); Double_t xmax3suball = f13suball->GetXmax(); Double_t mean3suball = f13suball->Mean(xmin3suball, xmax3suball); Double_t sigma3suball = TMath::Sqrt(f13suball->Variance(xmin3suball, xmax3suball)); xmin3suball = mean3suball - 5.0 * sigma3suball; xmax3suball = mean3suball + 5.0 * sigma3suball; mean3suball = f13suball->Mean(xmin3suball, xmax3suball); sigma3suball = TMath::Sqrt(f13suball->Variance(xmin3suball, xmax3suball)); std::cout << "Mean = " << mean3suball << std::endl; std::cout << "Sigma = " << sigma3suball << std::endl; if (p13suballp23suball==1) { p13suball=f13suball->GetParameter(1); p23suball=f13suball->GetParameter(2); } else if (p13suballp23suball==2) { p13suball=f13suball->GetParameter(4); p23suball=f13suball->GetParameter(5); } htemp3suball->GetXaxis()->SetTitle(cddeltatimeXname); htemp3suball->GetYaxis()->SetTitle(cddeltatimeYname); htemp3suball->GetYaxis()->SetTitleSize(c_YTitleSize); htemp3suball->GetYaxis()->SetTitleFont(c_YTitleFont); htemp3suball->GetYaxis()->SetTitleOffset(c_YTitleOffset); htemp3suball->GetYaxis()->SetLabelFont(c_YLabelFont); htemp3suball->GetYaxis()->SetLabelSize(c_YLabelSize); htemp3suball->GetXaxis()->SetTitleSize(c_XTitleSize); htemp3suball->GetXaxis()->SetTitleFont(c_XTitleFont); htemp3suball->GetXaxis()->SetTitleOffset(c_XTitleOffset); htemp3suball->GetXaxis()->SetLabelFont(c_XLabelFont); htemp3suball->GetXaxis()->SetLabelSize(c_XLabelSize); htemp3suball->SetFillColorAlpha(kBlue, hdeltatimeabfillcolor); htemp3suball->Draw(); htemp3suball->SetName(htempname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn c11->Update(); TLegend* leg3suball = new TLegend(0.15, 0.7, .25, .75); leg3suball->SetHeader("Legend"); leg3suball->SetNColumns(1); leg3suball->AddEntry(htemp3suball, "Data", "l"); leg3suball->AddEntry(f13suball, "Fit", "l"); //TO USE FOR 2 GAUSSIAN FIT leg3suball->Draw(); c11->Update(); gPad->Modified(); gPad->Update(); TPaveStats *statsgdeltatime3suball = (TPaveStats*)htemp3suball->GetListOfFunctions()->FindObject("stats"); statsgdeltatime3suball->SetTextColor(kBlue); statsgdeltatime3suball->SetX1NDC(0.80); statsgdeltatime3suball->SetX2NDC(0.98); statsgdeltatime3suball->SetY1NDC(0.77); statsgdeltatime3suball->SetY2NDC(0.92); statsgdeltatime3suball->AddText(TString::Format("Mean = %g", p13suball)); statsgdeltatime3suball->AddText(TString::Format("Sigma = %g", p23suball)); statsgdeltatime3suball->DrawClone(); gPad->Update(); c11->Print(myplotdeltatimeout3suball); delete c11; TCanvas *c8 = new TCanvas("c8",canvtitle,1280,1024); gStyle->SetOptFit(); t->SetLineColor(kBlue); TString htemp3substring = TString::Format("Calo_Time[%d] - Calo_Time[%d] >> htemp(1100., -550., 550.)", a,c); t->Draw(htemp3substring, cut); t->GetHistogram()->SetTitle(cdname3sub); t->SetScanField(0); TH1F *htemp3sub = (TH1F*)gPad->GetPrimitive("htemp"); TF1 *g13sub = new TF1 ("m13sub", "gaus", -130, -110); g13sub->SetLineColor(kYellow); TF1 *g23sub = new TF1 ("m23sub", "gaus", -120, -100); g23sub->SetLineColor(kGreen); TF1 *f13sub = new TF1("double_gaus3sub", "gaus(0) + gaus(3)", -130,-100); f13sub->SetParNames("Constant 1", "Mean 1", "Sigma 1","Constant 2", "Mean 2", "Sigma 2"); f13sub->SetLineColor(kRed); htemp3sub->Fit(g13sub, "R"); htemp3sub->Fit(g23sub, "R"); Double_t par3sub[6]; g13sub->GetParameters(&par3sub[0]); g23sub->GetParameters(&par3sub[3]); f13sub->SetParameters(par3sub); htemp3sub->Fit(f13sub, "R"); htemp3sub->Draw("e1"); g13sub->Draw("SAME"); g23sub->Draw("SAME"); f13sub->Draw("SAME"); std::cout << g13sub->Mean(f13sub->GetXmin(), f13sub->GetXmax()) << std::endl; std::cout << TMath::Sqrt(g13sub->Variance(f13sub->GetXmin(), f13sub->GetXmax())) << std::endl; std::cout << g23sub->Mean(f13sub->GetXmin(), f13sub->GetXmax()) << std::endl; std::cout << TMath::Sqrt(g23sub->Variance(f13sub->GetXmin(), f13sub->GetXmax())) << std::endl; std::cout << f13sub->Mean(f13sub->GetXmin(), f13sub->GetXmax()) << std::endl; std::cout << TMath::Sqrt(f13sub->Variance(f13sub->GetXmin(), f13sub->GetXmax())) << std::endl; Double_t xmin3sub = f13sub->GetXmin(); Double_t xmax3sub = f13sub->GetXmax(); Double_t mean3sub = f13sub->Mean(xmin3sub, xmax3sub); Double_t sigma3sub = TMath::Sqrt(f13sub->Variance(xmin3sub, xmax3sub)); xmin3sub = mean3sub - 5.0 * sigma3sub; xmax3sub = mean3sub + 5.0 * sigma3sub; mean3sub = f13sub->Mean(xmin3sub, xmax3sub); sigma3sub = TMath::Sqrt(f13sub->Variance(xmin3sub, xmax3sub)); std::cout << "Mean = " << mean3sub << std::endl; std::cout << "Sigma = " << sigma3sub << std::endl; if (p13subp23sub==1) { p13sub=f13sub->GetParameter(1); p23sub=f13sub->GetParameter(2); } else if (p13subp23sub==2) { p13sub=f13sub->GetParameter(4); p23sub=f13sub->GetParameter(5); } htemp3sub->GetXaxis()->SetTitle(cddeltatimeXname); htemp3sub->GetYaxis()->SetTitle(cddeltatimeYname); htemp3sub->GetYaxis()->SetTitleSize(c_YTitleSize); htemp3sub->GetYaxis()->SetTitleFont(c_YTitleFont); htemp3sub->GetYaxis()->SetTitleOffset(c_YTitleOffset); htemp3sub->GetYaxis()->SetLabelFont(c_YLabelFont); htemp3sub->GetYaxis()->SetLabelSize(c_YLabelSize); htemp3sub->GetXaxis()->SetTitleSize(c_XTitleSize); htemp3sub->GetXaxis()->SetTitleFont(c_XTitleFont); htemp3sub->GetXaxis()->SetTitleOffset(c_XTitleOffset); htemp3sub->GetXaxis()->SetLabelFont(c_XLabelFont); htemp3sub->GetXaxis()->SetLabelSize(c_XLabelSize); htemp3sub->SetFillColorAlpha(kBlue, hdeltatimeabfillcolor); htemp3sub->Draw(); htemp3sub->SetName(htempname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn c8->Update(); TLegend* leg3sub = new TLegend(0.15, 0.7, .25, .75); leg3sub->SetHeader("Legend"); leg3sub->SetNColumns(1); leg3sub->AddEntry(htemp3sub, "Data", "l"); leg3sub->AddEntry(f13sub, "Fit", "l"); //TO USE FOR 2 GAUSSIAN FIT leg3sub->Draw(); c8->Update(); gPad->Modified(); gPad->Update(); TPaveStats *statsgdeltatime3sub = (TPaveStats*)htemp3sub->GetListOfFunctions()->FindObject("stats"); statsgdeltatime3sub->SetTextColor(kBlue); statsgdeltatime3sub->SetX1NDC(0.80); statsgdeltatime3sub->SetX2NDC(0.98); statsgdeltatime3sub->SetY1NDC(0.77); statsgdeltatime3sub->SetY2NDC(0.92); statsgdeltatime3sub->AddText(TString::Format("Mean = %g", p13sub)); statsgdeltatime3sub->AddText(TString::Format("Sigma = %g", p23sub)); statsgdeltatime3sub->DrawClone(); gPad->Update(); c8->Print(myplotdeltatimeout3sub); delete c8; TCanvas *c9 = new TCanvas("c9",canvtitle,1280,1024); c9->Divide (3,1); c9->cd(1); t->SetLineColor(kBlue); t->Draw(Form("Calo_Time[%d] >> htemp(550., 0., 550.)",a)); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdtempnamea); TH1F *htempa3sub = (TH1F*)gPad->GetPrimitive("htemp"); htempa3sub->GetXaxis()->SetTitle(cdtempXnameab); htempa3sub->GetYaxis()->SetTitle(cdtempYnameab); htempa3sub->GetYaxis()->SetTitleSize(c1_YTitleSize); htempa3sub->GetYaxis()->SetTitleFont(c1_YTitleFont); htempa3sub->GetYaxis()->SetTitleOffset(c1_YTitleOffset); htempa3sub->GetYaxis()->SetLabelFont(c1_YLabelFont); htempa3sub->GetYaxis()->SetLabelSize(c1_YLabelSize); htempa3sub->GetXaxis()->SetTitleSize(c1_XTitleSize); htempa3sub->GetXaxis()->SetTitleFont(c1_XTitleFont); htempa3sub->GetXaxis()->SetTitleOffset(c1_XTitleOffset); htempa3sub->GetXaxis()->SetLabelFont(c1_XLabelFont); htempa3sub->GetXaxis()->SetLabelSize(c1_XLabelSize); htempa3sub->SetFillColorAlpha(kBlue, htimeabfillcolor); htempa3sub->Draw(); htempa3sub->SetName(htempabname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legtempa3sub = new TLegend(0.65, 0.7, .75, .75); legtempa3sub->SetHeader("Legend"); legtempa3sub->SetNColumns(1); legtempa3sub->AddEntry(htempa3sub, "Data", "l"); legtempa3sub->Draw(); gPad->Update(); TPaveStats *statsgtempa3sub = (TPaveStats*)htempa3sub->GetListOfFunctions()->FindObject("stats"); statsgtempa3sub->SetTextColor(kBlue); statsgtempa3sub->SetX1NDC(0.80); statsgtempa3sub->SetX2NDC(0.98); statsgtempa3sub->SetY1NDC(0.77); statsgtempa3sub->SetY2NDC(0.92); gPad->Update(); c9->cd(2); t->SetLineColor(kBlue); t->Draw(Form("Calo_Time[%d] >> htemp(550., 0., 550.)",b)); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdtempnameb); TH1F *htempb3sub = (TH1F*)gPad->GetPrimitive("htemp"); htempb3sub->GetXaxis()->SetTitle(cdtempXnameab); htempb3sub->GetYaxis()->SetTitle(cdtempYnameab); htempb3sub->GetYaxis()->SetTitleSize(c1_YTitleSize); htempb3sub->GetYaxis()->SetTitleFont(c1_YTitleFont); htempb3sub->GetYaxis()->SetTitleOffset(c1_YTitleOffset); htempb3sub->GetYaxis()->SetLabelFont(c1_YLabelFont); htempb3sub->GetYaxis()->SetLabelSize(c1_YLabelSize); htempb3sub->GetXaxis()->SetTitleSize(c1_XTitleSize); htempb3sub->GetXaxis()->SetTitleFont(c1_XTitleFont); htempb3sub->GetXaxis()->SetTitleOffset(c1_XTitleOffset); htempb3sub->GetXaxis()->SetLabelFont(c1_XLabelFont); htempb3sub->GetXaxis()->SetLabelSize(c1_XLabelSize); htempb3sub->SetFillColorAlpha(kBlue, htimeabfillcolor); htempb3sub->Draw(); htempb3sub->SetName(htempabname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legtempb3sub = new TLegend(0.65, 0.7, .75, .75); legtempb3sub->SetHeader("Legend"); legtempb3sub->SetNColumns(1); legtempb3sub->AddEntry(htempb3sub, "Data", "l"); legtempb3sub->Draw(); gPad->Update(); TPaveStats *statsgtempb3sub = (TPaveStats*)htempb3sub->GetListOfFunctions()->FindObject("stats"); statsgtempb3sub->SetTextColor(kBlue); statsgtempb3sub->SetX1NDC(0.80); statsgtempb3sub->SetX2NDC(0.98); statsgtempb3sub->SetY1NDC(0.77); statsgtempb3sub->SetY2NDC(0.92); gPad->Update(); c9->cd(3); t->SetLineColor(kBlue); t->Draw(Form("Calo_Time[%d] >> htemp(550., 0., 550.)",c)); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdtempnamec); TH1F *htempc3sub = (TH1F*)gPad->GetPrimitive("htemp"); htempc3sub->GetXaxis()->SetTitle(cdtempXnameab); htempc3sub->GetYaxis()->SetTitle(cdtempYnameab); htempc3sub->GetYaxis()->SetTitleSize(c1_YTitleSize); htempc3sub->GetYaxis()->SetTitleFont(c1_YTitleFont); htempc3sub->GetYaxis()->SetTitleOffset(c1_YTitleOffset); htempc3sub->GetYaxis()->SetLabelFont(c1_YLabelFont); htempc3sub->GetYaxis()->SetLabelSize(c1_YLabelSize); htempc3sub->GetXaxis()->SetTitleSize(c1_XTitleSize); htempc3sub->GetXaxis()->SetTitleFont(c1_XTitleFont); htempc3sub->GetXaxis()->SetTitleOffset(c1_XTitleOffset); htempc3sub->GetXaxis()->SetLabelFont(c1_XLabelFont); htempc3sub->GetXaxis()->SetLabelSize(c1_XLabelSize); htempc3sub->SetFillColorAlpha(kBlue, htimeabfillcolor); htempc3sub->Draw(); htempc3sub->SetName(htempabname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legtempc3sub = new TLegend(0.65, 0.7, .75, .75); legtempc3sub->SetHeader("Legend"); legtempc3sub->SetNColumns(1); legtempc3sub->AddEntry(htempc3sub, "Data", "l"); legtempc3sub->Draw(); gPad->Update(); TPaveStats *statsgtempc3sub = (TPaveStats*)htempc3sub->GetListOfFunctions()->FindObject("stats"); statsgtempc3sub->SetTextColor(kBlue); statsgtempc3sub->SetX1NDC(0.80); statsgtempc3sub->SetX2NDC(0.98); statsgtempc3sub->SetY1NDC(0.77); statsgtempc3sub->SetY2NDC(0.92); gPad->Update(); c9->Print(myplottimeout3sub); delete c9; TCanvas *c10 = new TCanvas("c10",canvtitle,1280,1024); c10->Divide (3,1); c10->cd(1); t->SetLineColor(kBlue); TCut cut3sub = TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) ",a, c, p13sub, csig, p23sub).Data(); TString henea3substring = TString::Format("Calo_EnDep[%d] >> htemp(7000., 0., 7000.)", a); t->Draw(henea3substring, cut && cut3sub); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdenenamea); TH1F *henea3sub = (TH1F*)gPad->GetPrimitive("htemp"); henea3sub->GetXaxis()->SetTitle(cdeneXnameab); henea3sub->GetYaxis()->SetTitle(cdeneYnameab); henea3sub->GetYaxis()->SetTitleSize(c2_YTitleSize); henea3sub->GetYaxis()->SetTitleFont(c2_YTitleFont); henea3sub->GetYaxis()->SetTitleOffset(c2_YTitleOffset); henea3sub->GetYaxis()->SetLabelFont(c2_YLabelFont); henea3sub->GetYaxis()->SetLabelSize(c2_YLabelSize); henea3sub->GetXaxis()->SetTitleSize(c2_XTitleSize); henea3sub->GetXaxis()->SetTitleFont(c2_XTitleFont); henea3sub->GetXaxis()->SetTitleOffset(c2_XTitleOffset); henea3sub->GetXaxis()->SetLabelFont(c2_XLabelFont); henea3sub->GetXaxis()->SetLabelSize(c2_XLabelSize); henea3sub->SetFillColorAlpha(kBlue, heneabfillcolor); henea3sub->Draw(); henea3sub->SetName(heneabname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legenea3sub = new TLegend(0.65, 0.7, .75, .75); legenea3sub->SetHeader("Legend"); legenea3sub->SetNColumns(1); legenea3sub->AddEntry(henea3sub, "Data", "l"); legenea3sub->Draw(); gPad->Update(); TPaveStats *statsgenea3sub = (TPaveStats*)henea3sub->GetListOfFunctions()->FindObject("stats"); statsgenea3sub->SetTextColor(kBlue); statsgenea3sub->SetX1NDC(0.80); statsgenea3sub->SetX2NDC(0.98); statsgenea3sub->SetY1NDC(0.77); statsgenea3sub->SetY2NDC(0.92); gPad->Update(); c10->cd(2); t->SetLineColor(kBlue); TString heneb3substring = TString::Format("Calo_EnDep[%d] >> htemp(7000., 0., 7000.)", b); t->Draw(heneb3substring, cut && cut3sub); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdenenameb); TH1F *heneb3sub = (TH1F*)gPad->GetPrimitive("htemp"); heneb3sub->GetXaxis()->SetTitle(cdeneXnameab); heneb3sub->GetYaxis()->SetTitle(cdeneYnameab); heneb3sub->GetYaxis()->SetTitleSize(c2_YTitleSize); heneb3sub->GetYaxis()->SetTitleFont(c2_YTitleFont); heneb3sub->GetYaxis()->SetTitleOffset(c2_YTitleOffset); heneb3sub->GetYaxis()->SetLabelFont(c2_YLabelFont); heneb3sub->GetYaxis()->SetLabelSize(c2_YLabelSize); heneb3sub->GetXaxis()->SetTitleSize(c2_XTitleSize); heneb3sub->GetXaxis()->SetTitleFont(c2_XTitleFont); heneb3sub->GetXaxis()->SetTitleOffset(c2_XTitleOffset); heneb3sub->GetXaxis()->SetLabelFont(c2_XLabelFont); heneb3sub->GetXaxis()->SetLabelSize(c2_XLabelSize); heneb3sub->SetFillColorAlpha(kBlue, heneabfillcolor); heneb3sub->Draw(); heneb3sub->SetName(heneabname); gPad->Modified(); gPad->Update(); TLegend* legeneb3sub = new TLegend(0.65, 0.7, .75, .75); legeneb3sub->SetHeader("Legend"); legeneb3sub->SetNColumns(1); legeneb3sub->AddEntry(heneb3sub, "Data", "l"); legeneb3sub->Draw(); gPad->Update(); TPaveStats *statsgeneb3sub = (TPaveStats*)heneb3sub->GetListOfFunctions()->FindObject("stats"); statsgeneb3sub->SetTextColor(kBlue); statsgeneb3sub->SetX1NDC(0.80); statsgeneb3sub->SetX2NDC(0.98); statsgeneb3sub->SetY1NDC(0.77); statsgeneb3sub->SetY2NDC(0.92); gPad->Update(); c10->cd(3); t->SetLineColor(kBlue); TString henec3substring = TString::Format("Calo_EnDep[%d] >> htemp(7000., 0., 7000.)", c); t->Draw(henec3substring, cut && cut3sub); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdenenamec); TH1F *henec3sub = (TH1F*)gPad->GetPrimitive("htemp"); henec3sub->GetXaxis()->SetTitle(cdeneXnameab); henec3sub->GetYaxis()->SetTitle(cdeneYnameab); henec3sub->GetYaxis()->SetTitleSize(c2_YTitleSize); henec3sub->GetYaxis()->SetTitleFont(c2_YTitleFont); henec3sub->GetYaxis()->SetTitleOffset(c2_YTitleOffset); henec3sub->GetYaxis()->SetLabelFont(c2_YLabelFont); henec3sub->GetYaxis()->SetLabelSize(c2_YLabelSize); henec3sub->GetXaxis()->SetTitleSize(c2_XTitleSize); henec3sub->GetXaxis()->SetTitleFont(c2_XTitleFont); henec3sub->GetXaxis()->SetTitleOffset(c2_XTitleOffset); henec3sub->GetXaxis()->SetLabelFont(c2_XLabelFont); henec3sub->GetXaxis()->SetLabelSize(c2_XLabelSize); henec3sub->SetFillColorAlpha(kBlue, heneabfillcolor); henec3sub->Draw(); henec3sub->SetName(heneabname); gPad->Modified(); gPad->Update(); TLegend* legenec3sub = new TLegend(0.65, 0.7, .75, .75); legenec3sub->SetHeader("Legend"); legenec3sub->SetNColumns(1); legenec3sub->AddEntry(henec3sub, "Data", "l"); legenec3sub->Draw(); gPad->Update(); TPaveStats *statsgenec3sub = (TPaveStats*)henec3sub->GetListOfFunctions()->FindObject("stats"); statsgenec3sub->SetTextColor(kBlue); statsgenec3sub->SetX1NDC(0.80); statsgenec3sub->SetX2NDC(0.98); statsgenec3sub->SetY1NDC(0.77); statsgenec3sub->SetY2NDC(0.92); gPad->Update(); c10->Print(myploteneout3sub); delete c10; /*----------------------------------SECTION FOR 4 SUBDETECTORS COINCIDENCE ----------------------------------*/ TCanvas *c12= new TCanvas("c12",canvtitle,1280,1024); t->SetLineColor(kBlue); t->Draw(Form("Calo_Time[%d]-Calo_Time[%d] >> htemp(1100., -550., 550.)", a, d)); t->GetHistogram()->SetTitle(cdname4sub); t->SetScanField(0); TH1F *htemp4suball = (TH1F*)gPad->GetPrimitive("htemp"); TF1 *g14suball = new TF1 ("m14suball", "gaus", -150, -110); g14suball->SetLineColor(kYellow); TF1 *g24suball = new TF1 ("m24suball", "gaus", -140, -100); g24suball->SetLineColor(kGreen); TF1 *f14suball = new TF1("double_gaus4suball", "gaus(0) + gaus(3)", -150, -100); f14suball->SetParNames("Constant 1", "Mean 1", "Sigma 1","Constant 2", "Mean 2", "Sigma 2"); f14suball->SetLineColor(kRed); htemp4suball->Fit(g14suball, "R"); htemp4suball->Fit(g24suball, "R"); Double_t par4suball[6]; g14suball->GetParameters(&par4suball[0]); g24suball->GetParameters(&par4suball[3]); f14suball->SetParameters(par4suball); htemp4suball->Fit(f14suball, "R"); htemp4suball->Draw("e1"); g14suball->Draw("SAME"); g24suball->Draw("SAME"); f14suball->Draw("SAME"); std::cout << g14suball->Mean(f14suball->GetXmin(), f14suball->GetXmax()) << std::endl; std::cout << TMath::Sqrt(g14suball->Variance(f14suball->GetXmin(), f14suball->GetXmax())) << std::endl; std::cout << g24suball->Mean(f14suball->GetXmin(), f14suball->GetXmax()) << std::endl; std::cout << TMath::Sqrt(g23suball->Variance(f13suball->GetXmin(), f13suball->GetXmax())) << std::endl; std::cout << f14suball->Mean(f14suball->GetXmin(), f14suball->GetXmax()) << std::endl; std::cout << TMath::Sqrt(f14suball->Variance(f14suball->GetXmin(), f14suball->GetXmax())) << std::endl; Double_t xmin4suball = f14suball->GetXmin(); Double_t xmax4suball = f14suball->GetXmax(); Double_t mean4suball = f14suball->Mean(xmin4suball, xmax4suball); Double_t sigma4suball = TMath::Sqrt(f14suball->Variance(xmin4suball, xmax4suball)); xmin4suball = mean4suball - 5.0 * sigma4suball; xmax4suball = mean4suball + 5.0 * sigma4suball; mean4suball = f14suball->Mean(xmin4suball, xmax4suball); sigma4suball = TMath::Sqrt(f14suball->Variance(xmin4suball, xmax4suball)); std::cout << "Mean = " << mean4suball << std::endl; std::cout << "Sigma = " << sigma4suball << std::endl; if (p14subp24suball==1) { p14suball=f14suball->GetParameter(1); p24suball=f14suball->GetParameter(2); } else if (p14subp24suball==2) { p14suball=f14suball->GetParameter(4); p24suball=f14suball->GetParameter(5); } htemp4suball->GetXaxis()->SetTitle(cddeltatimeXname); htemp4suball->GetYaxis()->SetTitle(cddeltatimeYname); htemp4suball->GetYaxis()->SetTitleSize(c_YTitleSize); htemp4suball->GetYaxis()->SetTitleFont(c_YTitleFont); htemp4suball->GetYaxis()->SetTitleOffset(c_YTitleOffset); htemp4suball->GetYaxis()->SetLabelFont(c_YLabelFont); htemp4suball->GetYaxis()->SetLabelSize(c_YLabelSize); htemp4suball->GetXaxis()->SetTitleSize(c_XTitleSize); htemp4suball->GetXaxis()->SetTitleFont(c_XTitleFont); htemp4suball->GetXaxis()->SetTitleOffset(c_XTitleOffset); htemp4suball->GetXaxis()->SetLabelFont(c_XLabelFont); htemp4suball->GetXaxis()->SetLabelSize(c_XLabelSize); htemp4suball->SetFillColorAlpha(kBlue, hdeltatimeabfillcolor); htemp4suball->Draw(); htemp4suball->SetName(htempname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn c12->Update(); TLegend* leg4suball = new TLegend(0.15, 0.7, .25, .75); leg4suball->SetHeader("Legend"); leg4suball->SetNColumns(1); leg4suball->AddEntry(htemp4suball, "Data", "l"); leg4suball->AddEntry(f14suball, "Fit", "l"); //TO USE FOR 2 GAUSSIAN FIT leg4suball->Draw(); c12->Update(); gPad->Modified(); gPad->Update(); TPaveStats *statsgdeltatime4suball = (TPaveStats*)htemp4suball->GetListOfFunctions()->FindObject("stats"); statsgdeltatime4suball->SetTextColor(kBlue); statsgdeltatime4suball->SetX1NDC(0.80); statsgdeltatime4suball->SetX2NDC(0.98); statsgdeltatime4suball->SetY1NDC(0.77); statsgdeltatime4suball->SetY2NDC(0.92); statsgdeltatime4suball->AddText(TString::Format("Mean = %g", p14suball)); statsgdeltatime4suball->AddText(TString::Format("Sigma = %g", p24suball)); statsgdeltatime4suball->DrawClone(); gPad->Update(); c12->Print(myplotdeltatimeout4suball); delete c12; TCanvas *c13 = new TCanvas("c13",canvtitle,1280,1024); t->SetLineColor(kBlue); TString htemp4substring = TString::Format("Calo_Time[%d] - Calo_Time[%d] >> htemp(1100., -550., 550.)", a,d); t->Draw(htemp4substring, cut && cut3sub ); t->GetHistogram()->SetTitle(cdname4sub); t->SetScanField(0); TH1F *htemp4sub = (TH1F*)gPad->GetPrimitive("htemp"); TF1 *g14sub = new TF1 ("m14sub", "gaus", -150, -110); g14sub->SetLineColor(kYellow); TF1 *g24sub = new TF1 ("m24sub", "gaus", -140, -100); g24sub->SetLineColor(kGreen); TF1 *f14sub = new TF1("double_gaus4sub", "gaus(0) + gaus(3)", -150, -100); f14sub->SetParNames("Constant 1", "Mean 1", "Sigma 1","Constant 2", "Mean 2", "Sigma 2"); f14sub->SetParLimits(2,0,100); f14sub->SetLineColor(kRed); htemp4sub->Fit(g14sub, "R"); htemp4sub->Fit(g24sub, "R"); Double_t par4sub[6]; g14sub->GetParameters(&par4sub[0]); g24sub->GetParameters(&par4sub[3]); f14sub->SetParameters(par4sub); htemp4sub->Fit(f14sub, "R"); htemp4sub->Draw("e1"); g14sub->Draw("SAME"); g24sub->Draw("SAME"); f14sub->Draw("SAME"); std::cout << g14sub->Mean(f14sub->GetXmin(), f14sub->GetXmax()) << std::endl; std::cout << TMath::Sqrt(g14sub->Variance(f14sub->GetXmin(), f14sub->GetXmax())) << std::endl; std::cout << g24sub->Mean(f14sub->GetXmin(), f14sub->GetXmax()) << std::endl; std::cout << TMath::Sqrt(g24sub->Variance(f14sub->GetXmin(), f14sub->GetXmax())) << std::endl; std::cout << f13sub->Mean(f14sub->GetXmin(), f14sub->GetXmax()) << std::endl; std::cout << TMath::Sqrt(f14sub->Variance(f14sub->GetXmin(), f14sub->GetXmax())) << std::endl; Double_t xmin4sub = f14sub->GetXmin(); Double_t xmax4sub = f14sub->GetXmax(); Double_t mean4sub = f14sub->Mean(xmin4sub, xmax4sub); Double_t sigma4sub = TMath::Sqrt(f14sub->Variance(xmin4sub, xmax4sub)); xmin4sub = mean4sub - 5.0 * sigma4sub; xmax4sub = mean4sub + 5.0 * sigma4sub; mean4sub = f14sub->Mean(xmin4sub, xmax4sub); sigma4sub = TMath::Sqrt(f14sub->Variance(xmin4sub, xmax4sub)); std::cout << "Mean = " << mean4sub << std::endl; std::cout << "Sigma = " << sigma4sub << std::endl; if (p14subp24sub==1) { p14sub=f14sub->GetParameter(1); p24sub=f14sub->GetParameter(2); } else if (p14subp24sub==2) { p14sub=f14sub->GetParameter(4); p24sub=f14sub->GetParameter(5); } htemp4sub->GetXaxis()->SetTitle(cddeltatimeXname); htemp4sub->GetYaxis()->SetTitle(cddeltatimeYname); htemp4sub->GetYaxis()->SetTitleSize(c_YTitleSize); htemp4sub->GetYaxis()->SetTitleFont(c_YTitleFont); htemp4sub->GetYaxis()->SetTitleOffset(c_YTitleOffset); htemp4sub->GetYaxis()->SetLabelFont(c_YLabelFont); htemp4sub->GetYaxis()->SetLabelSize(c_YLabelSize); htemp4sub->GetXaxis()->SetTitleSize(c_XTitleSize); htemp4sub->GetXaxis()->SetTitleFont(c_XTitleFont); htemp4sub->GetXaxis()->SetTitleOffset(c_XTitleOffset); htemp4sub->GetXaxis()->SetLabelFont(c_XLabelFont); htemp4sub->GetXaxis()->SetLabelSize(c_XLabelSize); htemp4sub->SetFillColorAlpha(kBlue, hdeltatimeabfillcolor); htemp4sub->Draw(); htemp4sub->SetName(htempname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn c13->Update(); TLegend* leg4sub = new TLegend(0.15, 0.7, .25, .75); leg4sub->SetHeader("Legend"); leg4sub->SetNColumns(1); leg4sub->AddEntry(htemp4sub, "Data", "l"); leg4sub->AddEntry(f14sub, "Fit", "l"); //TO USE FOR 2 GAUSSIAN FIT leg4sub->Draw(); c13->Update(); gPad->Modified(); gPad->Update(); TPaveStats *statsgdeltatime4sub = (TPaveStats*)htemp4sub->GetListOfFunctions()->FindObject("stats"); statsgdeltatime4sub->SetTextColor(kBlue); statsgdeltatime4sub->SetX1NDC(0.80); statsgdeltatime4sub->SetX2NDC(0.98); statsgdeltatime4sub->SetY1NDC(0.77); statsgdeltatime4sub->SetY2NDC(0.92); statsgdeltatime4sub->AddText(TString::Format("Mean = %g", p14sub)); statsgdeltatime4sub->AddText(TString::Format("Sigma = %g", p24sub)); statsgdeltatime4sub->DrawClone(); gPad->Update(); c13->Print(myplotdeltatimeout4sub); delete c13; TCanvas *c14 = new TCanvas("c14",canvtitle,1280,1024); c14->Divide (2,2); c14->cd(1); t->SetLineColor(kBlue); t->Draw(Form("Calo_Time[%d] >> htemp(550., 0., 550.)",a)); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdtempnamea); TH1F *htempa4sub = (TH1F*)gPad->GetPrimitive("htemp"); htempa4sub->GetXaxis()->SetTitle(cdtempXnameab); htempa4sub->GetYaxis()->SetTitle(cdtempYnameab); htempa4sub->GetYaxis()->SetTitleSize(c1_YTitleSize); htempa4sub->GetYaxis()->SetTitleFont(c1_YTitleFont); htempa4sub->GetYaxis()->SetTitleOffset(c1_YTitleOffset); htempa4sub->GetYaxis()->SetLabelFont(c1_YLabelFont); htempa4sub->GetYaxis()->SetLabelSize(c1_YLabelSize); htempa4sub->GetXaxis()->SetTitleSize(c1_XTitleSize); htempa4sub->GetXaxis()->SetTitleFont(c1_XTitleFont); htempa4sub->GetXaxis()->SetTitleOffset(c1_XTitleOffset); htempa4sub->GetXaxis()->SetLabelFont(c1_XLabelFont); htempa4sub->GetXaxis()->SetLabelSize(c1_XLabelSize); htempa4sub->SetFillColorAlpha(kBlue, htimeabfillcolor); htempa4sub->Draw(); htempa4sub->SetName(htempabname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legtempa4sub = new TLegend(0.65, 0.7, .75, .75); legtempa4sub->SetHeader("Legend"); legtempa4sub->SetNColumns(1); legtempa4sub->AddEntry(htempa4sub, "Data", "l"); legtempa4sub->Draw(); gPad->Update(); TPaveStats *statsgtempa4sub = (TPaveStats*)htempa4sub->GetListOfFunctions()->FindObject("stats"); statsgtempa4sub->SetTextColor(kBlue); statsgtempa4sub->SetX1NDC(0.80); statsgtempa4sub->SetX2NDC(0.98); statsgtempa4sub->SetY1NDC(0.77); statsgtempa4sub->SetY2NDC(0.92); gPad->Update(); c14->cd(2); t->SetLineColor(kBlue); t->Draw(Form("Calo_Time[%d] >> htemp(550., 0., 550.)",b)); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdtempnameb); TH1F *htempb4sub = (TH1F*)gPad->GetPrimitive("htemp"); htempb4sub->GetXaxis()->SetTitle(cdtempXnameab); htempb4sub->GetYaxis()->SetTitle(cdtempYnameab); htempb4sub->GetYaxis()->SetTitleSize(c1_YTitleSize); htempb4sub->GetYaxis()->SetTitleFont(c1_YTitleFont); htempb4sub->GetYaxis()->SetTitleOffset(c1_YTitleOffset); htempb4sub->GetYaxis()->SetLabelFont(c1_YLabelFont); htempb4sub->GetYaxis()->SetLabelSize(c1_YLabelSize); htempb4sub->GetXaxis()->SetTitleSize(c1_XTitleSize); htempb4sub->GetXaxis()->SetTitleFont(c1_XTitleFont); htempb4sub->GetXaxis()->SetTitleOffset(c1_XTitleOffset); htempb4sub->GetXaxis()->SetLabelFont(c1_XLabelFont); htempb4sub->GetXaxis()->SetLabelSize(c1_XLabelSize); htempb4sub->SetFillColorAlpha(kBlue, htimeabfillcolor); htempb4sub->Draw(); htempb4sub->SetName(htempabname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legtempb4sub = new TLegend(0.65, 0.7, .75, .75); legtempb4sub->SetHeader("Legend"); legtempb4sub->SetNColumns(1); legtempb4sub->AddEntry(htempb4sub, "Data", "l"); legtempb4sub->Draw(); gPad->Update(); TPaveStats *statsgtempb4sub = (TPaveStats*)htempb4sub->GetListOfFunctions()->FindObject("stats"); statsgtempb4sub->SetTextColor(kBlue); statsgtempb4sub->SetX1NDC(0.80); statsgtempb4sub->SetX2NDC(0.98); statsgtempb4sub->SetY1NDC(0.77); statsgtempb4sub->SetY2NDC(0.92); gPad->Update(); c14->cd(3); t->SetLineColor(kBlue); t->Draw(Form("Calo_Time[%d] >> htemp(550., 0., 550.)",c)); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdtempnamec); TH1F *htempc4sub = (TH1F*)gPad->GetPrimitive("htemp"); htempc4sub->GetXaxis()->SetTitle(cdtempXnameab); htempc4sub->GetYaxis()->SetTitle(cdtempYnameab); htempc4sub->GetYaxis()->SetTitleSize(c1_YTitleSize); htempc4sub->GetYaxis()->SetTitleFont(c1_YTitleFont); htempc4sub->GetYaxis()->SetTitleOffset(c1_YTitleOffset); htempc4sub->GetYaxis()->SetLabelFont(c1_YLabelFont); htempc4sub->GetYaxis()->SetLabelSize(c1_YLabelSize); htempc4sub->GetXaxis()->SetTitleSize(c1_XTitleSize); htempc4sub->GetXaxis()->SetTitleFont(c1_XTitleFont); htempc4sub->GetXaxis()->SetTitleOffset(c1_XTitleOffset); htempc4sub->GetXaxis()->SetLabelFont(c1_XLabelFont); htempc4sub->GetXaxis()->SetLabelSize(c1_XLabelSize); htempc4sub->SetFillColorAlpha(kBlue, htimeabfillcolor); htempc4sub->Draw(); htempc4sub->SetName(htempabname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legtempc4sub = new TLegend(0.65, 0.7, .75, .75); legtempc4sub->SetHeader("Legend"); legtempc4sub->SetNColumns(1); legtempc4sub->AddEntry(htempc4sub, "Data", "l"); legtempc4sub->Draw(); gPad->Update(); TPaveStats *statsgtempc4sub = (TPaveStats*)htempc4sub->GetListOfFunctions()->FindObject("stats"); statsgtempc4sub->SetTextColor(kBlue); statsgtempc4sub->SetX1NDC(0.80); statsgtempc4sub->SetX2NDC(0.98); statsgtempc4sub->SetY1NDC(0.77); statsgtempc4sub->SetY2NDC(0.92); gPad->Update(); c14->cd(4); t->SetLineColor(kBlue); t->Draw(Form("Calo_Time[%d] >> htemp(550., 0., 550.)",d)); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdtempnamed); TH1F *htempd4sub = (TH1F*)gPad->GetPrimitive("htemp"); htempd4sub->GetXaxis()->SetTitle(cdtempXnameab); htempd4sub->GetYaxis()->SetTitle(cdtempYnameab); htempd4sub->GetYaxis()->SetTitleSize(c1_YTitleSize); htempd4sub->GetYaxis()->SetTitleFont(c1_YTitleFont); htempd4sub->GetYaxis()->SetTitleOffset(c1_YTitleOffset); htempd4sub->GetYaxis()->SetLabelFont(c1_YLabelFont); htempd4sub->GetYaxis()->SetLabelSize(c1_YLabelSize); htempd4sub->GetXaxis()->SetTitleSize(c1_XTitleSize); htempd4sub->GetXaxis()->SetTitleFont(c1_XTitleFont); htempd4sub->GetXaxis()->SetTitleOffset(c1_XTitleOffset); htempd4sub->GetXaxis()->SetLabelFont(c1_XLabelFont); htempd4sub->GetXaxis()->SetLabelSize(c1_XLabelSize); htempd4sub->SetFillColorAlpha(kBlue, htimeabfillcolor); htempd4sub->Draw(); htempd4sub->SetName(htempabname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legtempd4sub = new TLegend(0.65, 0.7, .75, .75); legtempd4sub->SetHeader("Legend"); legtempd4sub->SetNColumns(1); legtempd4sub->AddEntry(htempd4sub, "Data", "l"); legtempd4sub->Draw(); gPad->Update(); TPaveStats *statsgtempd4sub = (TPaveStats*)htempd4sub->GetListOfFunctions()->FindObject("stats"); statsgtempd4sub->SetTextColor(kBlue); statsgtempd4sub->SetX1NDC(0.80); statsgtempd4sub->SetX2NDC(0.98); statsgtempd4sub->SetY1NDC(0.77); statsgtempd4sub->SetY2NDC(0.92); gPad->Update(); c14->Print(myplottimeout4sub); delete c14; TCanvas *c15 = new TCanvas("c15",canvtitle,1280,1024); c15->Divide (2,2); c15->cd(1); t->SetLineColor(kBlue); TCut cut4sub = TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) ", a, d, p14sub, csig, p24sub).Data(); TString henea4substring = TString::Format("Calo_EnDep[%d] >> htemp(5000., 0., 5000.)", a); t->Draw(henea4substring, cut && cut3sub && cut4sub); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdenenamea); TH1F *henea4sub = (TH1F*)gPad->GetPrimitive("htemp"); henea4sub->GetXaxis()->SetTitle(cdeneXnameab); henea4sub->GetYaxis()->SetTitle(cdeneYnameab); henea4sub->GetYaxis()->SetTitleSize(c2_YTitleSize); henea4sub->GetYaxis()->SetTitleFont(c2_YTitleFont); henea4sub->GetYaxis()->SetTitleOffset(c2_YTitleOffset); henea4sub->GetYaxis()->SetLabelFont(c2_YLabelFont); henea4sub->GetYaxis()->SetLabelSize(c2_YLabelSize); henea4sub->GetXaxis()->SetTitleSize(c2_XTitleSize); henea4sub->GetXaxis()->SetTitleFont(c2_XTitleFont); henea4sub->GetXaxis()->SetTitleOffset(c2_XTitleOffset); henea4sub->GetXaxis()->SetLabelFont(c2_XLabelFont); henea4sub->GetXaxis()->SetLabelSize(c2_XLabelSize); henea4sub->SetFillColorAlpha(kBlue, heneabfillcolor); henea4sub->Draw(); henea4sub->SetName(heneabname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legenea4sub = new TLegend(0.65, 0.7, .75, .75); legenea4sub->SetHeader("Legend"); legenea4sub->SetNColumns(1); legenea4sub->AddEntry(henea4sub, "Data", "l"); legenea4sub->Draw(); gPad->Update(); TPaveStats *statsgenea4sub = (TPaveStats*)henea4sub->GetListOfFunctions()->FindObject("stats"); statsgenea4sub->SetTextColor(kBlue); statsgenea4sub->SetX1NDC(0.80); statsgenea4sub->SetX2NDC(0.98); statsgenea4sub->SetY1NDC(0.77); statsgenea4sub->SetY2NDC(0.92); gPad->Update(); c15->cd(2); t->SetLineColor(kBlue); TString heneb4substring = TString::Format("Calo_EnDep[%d] >> htemp(5000., 0., 5000.)", b); t->Draw(heneb4substring, cut && cut3sub && cut4sub); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdenenameb); TH1F *heneb4sub = (TH1F*)gPad->GetPrimitive("htemp"); heneb4sub->GetXaxis()->SetTitle(cdeneXnameab); heneb4sub->GetYaxis()->SetTitle(cdeneYnameab); heneb4sub->GetYaxis()->SetTitleSize(c2_YTitleSize); heneb4sub->GetYaxis()->SetTitleFont(c2_YTitleFont); heneb4sub->GetYaxis()->SetTitleOffset(c2_YTitleOffset); heneb4sub->GetYaxis()->SetLabelFont(c2_YLabelFont); heneb4sub->GetYaxis()->SetLabelSize(c2_YLabelSize); heneb4sub->GetXaxis()->SetTitleSize(c2_XTitleSize); heneb4sub->GetXaxis()->SetTitleFont(c2_XTitleFont); heneb4sub->GetXaxis()->SetTitleOffset(c2_XTitleOffset); heneb4sub->GetXaxis()->SetLabelFont(c2_XLabelFont); heneb4sub->GetXaxis()->SetLabelSize(c2_XLabelSize); heneb4sub->SetFillColorAlpha(kBlue, heneabfillcolor); heneb4sub->Draw(); heneb4sub->SetName(heneabname); gPad->Modified(); gPad->Update(); TLegend* legeneb4sub = new TLegend(0.65, 0.7, .75, .75); legeneb4sub->SetHeader("Legend"); legeneb4sub->SetNColumns(1); legeneb4sub->AddEntry(heneb4sub, "Data", "l"); legeneb4sub->Draw(); gPad->Update(); TPaveStats *statsgeneb4sub = (TPaveStats*)heneb4sub->GetListOfFunctions()->FindObject("stats"); statsgeneb4sub->SetTextColor(kBlue); statsgeneb4sub->SetX1NDC(0.80); statsgeneb4sub->SetX2NDC(0.98); statsgeneb4sub->SetY1NDC(0.77); statsgeneb4sub->SetY2NDC(0.92); gPad->Update(); c15->cd(3); t->SetLineColor(kBlue); TString henec4substring = TString::Format("Calo_EnDep[%d] >> htemp(5000., 0., 5000.)", c); t->Draw(henec4substring, cut && cut3sub && cut4sub); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdenenamec); TH1F *henec4sub = (TH1F*)gPad->GetPrimitive("htemp"); henec4sub->GetXaxis()->SetTitle(cdeneXnameab); henec4sub->GetYaxis()->SetTitle(cdeneYnameab); henec4sub->GetYaxis()->SetTitleSize(c2_YTitleSize); henec4sub->GetYaxis()->SetTitleFont(c2_YTitleFont); henec4sub->GetYaxis()->SetTitleOffset(c2_YTitleOffset); henec4sub->GetYaxis()->SetLabelFont(c2_YLabelFont); henec4sub->GetYaxis()->SetLabelSize(c2_YLabelSize); henec4sub->GetXaxis()->SetTitleSize(c2_XTitleSize); henec4sub->GetXaxis()->SetTitleFont(c2_XTitleFont); henec4sub->GetXaxis()->SetTitleOffset(c2_XTitleOffset); henec4sub->GetXaxis()->SetLabelFont(c2_XLabelFont); henec4sub->GetXaxis()->SetLabelSize(c2_XLabelSize); henec4sub->SetFillColorAlpha(kBlue, heneabfillcolor); henec4sub->Draw(); henec4sub->SetName(heneabname); gPad->Modified(); gPad->Update(); TLegend* legenec4sub = new TLegend(0.65, 0.7, .75, .75); legenec4sub->SetHeader("Legend"); legenec4sub->SetNColumns(1); legenec4sub->AddEntry(henec4sub, "Data", "l"); legenec4sub->Draw(); gPad->Update(); TPaveStats *statsgenec4sub = (TPaveStats*)henec4sub->GetListOfFunctions()->FindObject("stats"); statsgenec4sub->SetTextColor(kBlue); statsgenec4sub->SetX1NDC(0.80); statsgenec4sub->SetX2NDC(0.98); statsgenec4sub->SetY1NDC(0.77); statsgenec4sub->SetY2NDC(0.92); gPad->Update(); c15->cd(4); t->SetLineColor(kBlue); TString hened4substring = TString::Format("Calo_EnDep[%d] >> htemp(5000., 0., 5000.)", d); t->Draw(hened4substring, cut && cut3sub && cut4sub); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdenenamed); TH1F *hened4sub = (TH1F*)gPad->GetPrimitive("htemp"); hened4sub->GetXaxis()->SetTitle(cdeneXnameab); hened4sub->GetYaxis()->SetTitle(cdeneYnameab); hened4sub->GetYaxis()->SetTitleSize(c2_YTitleSize); hened4sub->GetYaxis()->SetTitleFont(c2_YTitleFont); hened4sub->GetYaxis()->SetTitleOffset(c2_YTitleOffset); hened4sub->GetYaxis()->SetLabelFont(c2_YLabelFont); hened4sub->GetYaxis()->SetLabelSize(c2_YLabelSize); hened4sub->GetXaxis()->SetTitleSize(c2_XTitleSize); hened4sub->GetXaxis()->SetTitleFont(c2_XTitleFont); hened4sub->GetXaxis()->SetTitleOffset(c2_XTitleOffset); hened4sub->GetXaxis()->SetLabelFont(c2_XLabelFont); hened4sub->GetXaxis()->SetLabelSize(c2_XLabelSize); hened4sub->SetFillColorAlpha(kBlue, heneabfillcolor); hened4sub->Draw(); hened4sub->SetName(heneabname); gPad->Modified(); gPad->Update(); TLegend* legened4sub = new TLegend(0.65, 0.7, .75, .75); legened4sub->SetHeader("Legend"); legened4sub->SetNColumns(1); legened4sub->AddEntry(hened4sub, "Data", "l"); legened4sub->Draw(); gPad->Update(); TPaveStats *statsgened4sub = (TPaveStats*)hened4sub->GetListOfFunctions()->FindObject("stats"); statsgened4sub->SetTextColor(kBlue); statsgened4sub->SetX1NDC(0.80); statsgened4sub->SetX2NDC(0.98); statsgened4sub->SetY1NDC(0.77); statsgened4sub->SetY2NDC(0.92); gPad->Update(); c15->Print(myploteneout4sub); delete c15; TCanvas *c19 = new TCanvas("c19",canvtitle,1280,1280); c19->cd(1); t->SetLineColor(kBlue); TString hene4substringsum = TString::Format("Calo_EnDep[%d] >> htemp(200., 0., 4000.)", c); t->Draw(hene4substringsum, cut && cut3sub && cut4sub); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn t->GetHistogram()->SetTitle(cdenenamesum); TH1F *hene4subsum = (TH1F*)gPad->GetPrimitive("htemp"); hene4subsum->SetStats(0); TF1 *g14subsum = new TF1 ("m14subsum", "gaus", 2000, 3000); g14subsum->SetLineColor(kYellow); TF1 *g24subsum = new TF1 ("m24subsum", "gaus", 3000, 5000); g24subsum->SetLineColor(kGreen); TF1 *f14subsum = new TF1("double_gaus4subsum", "gaus(0) + gaus(3)", 2000, 5000); f14subsum->SetParNames("Constant 1", "Mean 1", "Sigma 1","Constant 2", "Mean 2", "Sigma 2"); // f14subsum->SetParLimits(2,0,100); // f14subsum->SetParLimits(4,0,100); f14subsum->SetLineColor(kRed); hene4subsum->Fit(g14subsum, "R"); hene4subsum->Fit(g24subsum, "R"); Double_t par4subsum[6]; g14subsum->GetParameters(&par4subsum[0]); g24subsum->GetParameters(&par4subsum[3]); f14subsum->SetParameters(par4subsum); hene4subsum->Fit(f14subsum, "R"); gStyle->SetEndErrorSize(3); gStyle->SetErrorX(1.); hene4subsum->SetMarkerStyle(20); hene4subsum->Draw("E"); g14subsum->Draw("SAME"); g24subsum->Draw("SAME"); f14subsum->Draw("SAME"); std::cout << g14subsum->Mean(f14subsum->GetXmin(), f14subsum->GetXmax()) << std::endl; std::cout << TMath::Sqrt(g14subsum->Variance(f14subsum->GetXmin(), f14subsum->GetXmax())) << std::endl; std::cout << g24subsum->Mean(f14subsum->GetXmin(), f14subsum->GetXmax()) << std::endl; std::cout << TMath::Sqrt(g24subsum->Variance(f14subsum->GetXmin(), f14subsum->GetXmax())) << std::endl; std::cout << f14subsum->Mean(f14subsum->GetXmin(), f14subsum->GetXmax()) << std::endl; std::cout << TMath::Sqrt(f14subsum->Variance(f14subsum->GetXmin(), f14subsum->GetXmax())) << std::endl; Double_t xmin4subsum = f14subsum->GetXmin(); Double_t xmax4subsum = f14subsum->GetXmax(); Double_t mean4subsum = f14subsum->Mean(xmin4subsum, xmax4subsum); Double_t sigma4subsum = TMath::Sqrt(f14subsum->Variance(xmin4subsum, xmax4subsum)); xmin4subsum = mean4subsum - 5.0 * sigma4subsum; xmax4subsum = mean4subsum + 5.0 * sigma4subsum; mean4subsum = f14subsum->Mean(xmin4subsum, xmax4subsum); sigma4subsum = TMath::Sqrt(f14subsum->Variance(xmin4subsum, xmax4subsum)); std::cout << "Mean = " << mean4subsum << std::endl; std::cout << "Sigma = " << sigma4subsum << std::endl; if (p14subp24subsum==1) { p14subsum=f14subsum->GetParameter(1); p24subsum=f14subsum->GetParameter(2); } else if (p14subp24subsum==2) { p14subsum=f14subsum->GetParameter(4); p24subsum=f14subsum->GetParameter(5); } hene4subsum ->GetXaxis()->SetTitle(cdeneXnameab); hene4subsum ->GetYaxis()->SetTitle(cdeneYnameab); hene4subsum ->GetYaxis()->SetTitleSize(c_YTitleSize); hene4subsum ->GetYaxis()->SetTitleFont(c_YTitleFont); hene4subsum ->GetYaxis()->SetTitleOffset(c_YTitleOffset); hene4subsum ->GetYaxis()->SetLabelFont(c_YLabelFont); hene4subsum ->GetYaxis()->SetLabelSize(c_YLabelSize); hene4subsum ->GetXaxis()->SetTitleSize(c_XTitleSize); hene4subsum ->GetXaxis()->SetTitleFont(c_XTitleFont); hene4subsum ->GetXaxis()->SetTitleOffset(c_XTitleOffset); hene4subsum ->GetXaxis()->SetLabelFont(c_XLabelFont); hene4subsum ->GetXaxis()->SetLabelSize(c_XLabelSize); hene4subsum ->SetFillColorAlpha(kBlue, heneabfillcolor); hene4subsum ->Draw("E"); hene4subsum ->SetName(heneabname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legene4subsum = new TLegend(0.15, 0.85, .30, .75); legene4subsum ->SetHeader("Legend"); legene4subsum ->SetNColumns(1); legene4subsum ->AddEntry(hene4subsum , "Data", "l"); legene4subsum->AddEntry(f14subsum, "Fit", "l"); //TO USE FOR 2 GAUSSIAN FI legene4subsum ->Draw(); gPad->Update(); /*TPaveStats *statsgene4subsum = (TPaveStats*)hene4subsum ->GetListOfFunctions()->FindObject("stats"); statsgene4subsum ->SetTextColor(kBlue); statsgene4subsum ->SetX1NDC(0.75); statsgene4subsum ->SetX2NDC(0.98); statsgene4subsum ->SetY1NDC(0.62); statsgene4subsum ->SetY2NDC(0.92); statsgene4subsum->AddText(TString::Format("Mean = %g", p14subsum)); statsgene4subsum->AddText(TString::Format("Sigma = %g", p24subsum)); statsgene4subsum->DrawClone(); gPad->Update();*/ c19->Print(myploteneout4subsum); delete c19; } }