#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=500274; //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 a; //TO USE FOR FILES WITHOUT THE TARGET int b; char timeenergynamesuba[200]; int csig=2; //Sigma const for (a=0;a<=23;++a){ //TO USE FOR FILES WITHOUT THE TARGET if (a==8 || a==9 || a==6 ){ char timenamesuba[200]= "scint"; //First subdetector tipology name for time plot. strcpy(timeenergynamesuba, "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. strcpy(timeenergynamesuba, "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. strcpy(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 ){ char timenamesuba[200]= "versa"; //First subdetector tipology name for time plot. strcpy(timeenergynamesuba, "Versa"); //First subdetector tipology name for energy plot. } /* -------------------------------------SECTION FOR FILES WITH THE TARGET----------------------*/ //char dirin[200]="D:/ago18_e_45GeV_target/";//Directory where there is the input root file // TO USE FOR FILES WITH THE TARGET char dirin[200]="./";//Directory where there is the input root file // TO USE FOR FILES WITHOUT THE TARGET char dirout[200]="./";//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; double 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; double 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; double 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); // TO USE FOR FILES WITH TARGET gSystem->mkdir(TString::Format("%stestbeam/si-%d/sub_%d/",dirout,ifile, a), kTRUE); // TO USE FOR FILES WITHOUT TARGET //TString outfolder=TString::Format("%stestbeam/si-%d/sub_%d-%d/",dirout,ifile, a, b); // TO USE FOR FILES WITH TARGET TString outfolder=TString::Format("%stestbeam/si-%d/sub_%d/",dirout,ifile, a); // TO USE FOR FILES WITHOUT TARGET 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); // TO USE FOR FILES WHIT TARGET TString myploteneout = TString::Format("%ssi-%d_ene%d.pdf",outfolder.Data(),ifile,a); // TO USE FOR FILES WITHOUT TARGET 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); // TO USE FOR FILES WITH TARGET TString cdenenamea = TString::Format("si-%d: Energy_{%s}_{%d}", ifile,timeenergynamesuba,a); //TString cdenenameb = TString::Format("si-%d: Energy_{%s}_{%d}", ifile,timeenergynamesubb,b); // TO USE FOR FILES WITH TARGET TString cdtempnamea = TString::Format("si-%d: Time_{%s}_{%d}", ifile,timeenergynamesuba,a); //TString cdtempnameb = TString::Format("si-%d: Time_{%s}_{%d}", ifile,timeenergynamesubb,b); // TO USE FOR FILES WITH TARGET 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"); } else { TTree *t=0; f->GetObject(fobject,t); gStyle->SetOptFit(); TCanvas *c3 = new TCanvas("c3",canvtitle,1280,1024); t->SetLineColor(kBlue); t->Draw( TString::Format("Calo_EnDep[%d]", a)); 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(); c3->Print(myploteneout); delete c3; } } }