#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" void calo() { int ifile=500427; //Root File number name. To change each time int a=8; //First subdetector name to analyze. To change each time //int b=13; // Second subdetector name to analyze. To change each time int b; int csig=2;//Sigma const if (a==8 || a==9 || a==6 ){ char timenamesuba[200]= "scint"; //First subdetector tipology name for time plot. char timeenergynamesuba[200]= "scintillator"; //First subdetector tipology name for energy plot. } else if (a==0 || a==1 || a==2 || a==3 || a==4 || a==5) { char timenamesuba[200]= "lead"; //First subdetector tipology name for time plot. char timeenergynamesuba[200]= "Lead"; //First subdetector tipology name for energy plot. } else if (a==12 || a==13 || a==14 || a==15 ){ char timenamesuba[200]= "horsa"; //First subdetector tipology name for time plot. char timeenergynamesuba[200]= "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 ){ char timenamesuba[200]= "versa"; //First subdetector tipology name for time plot. char timeenergynamesuba[200]= "Versa"; //First subdetector tipology name for energy plot. } for (b=0;b<=23;++b){ if (b==8 || b==9 || b==6 ){ char timenamesubb[200]= "scint"; //Second subdetector tipology name for time plot. char timeenergynamesubb[200]= "scintillator"; //Second subdetector tipology name for energy plot. } else if (b==0 || b==1 || b==2 || b==3 || b==4 || b==5) { char timenamesubb[200]= "lead"; //Second subdetector tipology name for time plot. char timeenergynamesubb[200]= "Lead"; //Second subdetector tipology name for energy plot. } else if (b==12 || b==13 || b==14 || b==15 ){ char timenamesubb[200]= "horsa"; //Second subdetector tipology name for time plot. char timeenergynamesubb[200]= "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 ){ char timenamesubb[200]= "versa"; //Second subdetector tipology name for time plot. char timeenergynamesubb[200]= "Versa"; //Second subdetector tipology name for energy plot. } else if (b==7 ){ char timenamesubb[200]= "NONE"; //Second subdetector tipology name for time plot. char timeenergynamesubb[200]= "NONE"; //Second subdetector tipology name for energy plot. } char dirin[200]="D:/ago18_e_45GeV_target/";//Directory where there is the input root file char dirout[200]="D:/";//Main Directory where to save the output files char htempname[200]="#DeltaTime"; char htempabname[200]="Time"; char heneabname[200]="Energy"; float n=3; int c_YTitleSize=25; int c_YTitleFont=43; int c_YTitleOffset=1.55; int c_YLabelFont=43; int c_YLabelSize=20; int c_XTitleSize=25; int c_XTitleFont=43; int c_XTitleOffset=1; int c_XLabelFont=43; int c_XLabelSize=20; int c1_YTitleSize=25; int c1_YTitleFont=43; int c1_YTitleOffset=1.55; int c1_YLabelFont=43; int c1_YLabelSize=20; int c1_XTitleSize=25; int c1_XTitleFont=43; int c1_XTitleOffset=1; int c1_XLabelFont=43; int c1_XLabelSize=20; //int c1_XSetRangem=0; //int c1_XSetRangeM=100; int c2_YTitleSize=25; int c2_YTitleFont=43; int c2_YTitleOffset=1.55; int c2_YLabelFont=43; int c2_YLabelSize=20; int c2_XTitleSize=25; int c2_XTitleFont=43; int c2_XTitleOffset=1; int c2_XLabelFont=43; int c2_XLabelSize=20; int c2_XSetRangem=0; int c2_XSetRangeM=150; float p0; float p1; float p2; float heneabfillcolor=0.35; float htimeabfillcolor=0.35; float hdeltatimeabfillcolor=0.35; 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); TString outfolder=TString::Format("%stestbeam/si-%d/sub_%d-%d/",dirout,ifile, a, b); TString myfilein = TString::Format("%ssi-%d.root",dirin,ifile); TString myplotdeltatimeout = TString::Format("%ssi-%d_deltatime%d-%d.pdf",outfolder.Data(),ifile,a,b); TString myplottimeout = TString::Format("%ssi-%d_time%d-%d.pdf",outfolder.Data(),ifile,a,b); TString myploteneout = TString::Format("%ssi-%d_ene%d-%d.pdf",outfolder.Data(),ifile,a,b); TString mydatavalueouta = TString::Format("%ssi-%d_CaloTime_%d.txt",outfolder.Data(),ifile,a); TString mydatavalueoutb = TString::Format("%ssi-%d_CaloTime_%d.txt",outfolder.Data(),ifile,b); TString mydatavalueoutab = TString::Format("%ssi-%d_CaloTime_%d-%d.txt",outfolder.Data(),ifile,a,b); TString canvtitle = TString::Format("si-%d",ifile); TString cdname = TString::Format("si-%d: Time_{%s}_{%d}-Time_{%s}_{%d}", ifile,timenamesuba,a,timenamesubb,b); TString cdenenamea = TString::Format("si-%d: Energy_{%s}_{%d}", ifile,timeenergynamesuba,a); TString cdenenameb = TString::Format("si-%d: Energy_{%s}_{%d}", ifile,timeenergynamesubb,b); TString cdtempnamea = TString::Format("si-%d: Time_{%s}_{%d}", ifile,timeenergynamesuba,a); TString cdtempnameb = TString::Format("si-%d: Time_{%s}_{%d}", ifile,timeenergynamesubb,b); char fobject[200]= "lemma"; char cdenename[200]= "Energy"; char cddeltatimeXname[200]= "#DeltaTime (ns)"; char cddeltatimeYname[200]= "# Counts"; char cdtempXnameab[200]= "Time (ns)"; char cdtempYnameab[200]= "# Counts"; char cdeneXnameab[200]= "Energy (ADC counts)"; char cdeneYnameab[200]= "# Counts"; TFile *f = TFile::Open(myfilein); f->ls (); TGaxis::SetMaxDigits(n); if (f == 0) { printf("Error: cannot open the file!\n"); //return; } else { TTree *t=0; f->GetObject(fobject,t); TCanvas *c = new TCanvas("c",canvtitle,1280,1024); gStyle->SetOptFit(); t->SetLineColor(kBlue); t->Draw(Form("Calo_Time[%d]-Calo_Time[%d]",a,b)); t->GetHistogram()->SetTitle(cdname); lemma->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"); htemp->Fit("gaus"); p0 = gaus->GetParameter(0); p1 = gaus->GetParameter(1); p2 = gaus->GetParameter(2); 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 c->Update(); TLegend* leg = new TLegend(0.15, 0.7, .25, .75); leg->SetNColumns(1); leg->AddEntry(htemp, "Data", "l"); leg->AddEntry(gaus, "Fit", "l"); leg->Draw(); c->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); gPad->Update(); c->Print(myplotdeltatimeout); delete c; TCanvas *c1 = new TCanvas("c1",canvtitle,1280,1024); c1->Divide (2,1); c1->cd(1); t->SetLineColor(kBlue); t->Draw(Form("Calo_Time[%d]",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); //htempa->GetXaxis()->SetRangeUser(c1_XSetRangem,c1_XSetRangeM); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legtempa = new TLegend(0.65, 0.7, .75, .75); 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]",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); //htempb->GetXaxis()->SetRangeUser(c1_XSetRangem,c1_XSetRangeM); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legtempb = new TLegend(0.65, 0.7, .75, .75); 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); t->Draw( TString::Format("Calo_EnDep[%d]", a), TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f)", a, b, p1, csig, p2) ); 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); henea->GetXaxis()->SetRangeUser(c2_XSetRangem,c2_XSetRangeM); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TLegend* legenea = new TLegend(0.65, 0.7, .75, .75); 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); t->Draw( TString::Format("Calo_EnDep[%d]", b), TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f)", a, b, p1, csig, p2) ); 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); heneb->GetXaxis()->SetRangeUser(c2_XSetRangem,c2_XSetRangeM); gPad->Modified(); gPad->Update(); TLegend* legeneb = new TLegend(0.65, 0.7, .75, .75); 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; gROOT->ProcessLine("gROOT->SetBatch(kFALSE)"); } } //exit(); }