int a=0; //int subdet=37; int subdet=45; int xhn=-99; void DrawVerticalLine(Double_t x) { TLine l; l.SetLineColor(kRed); l.SetLineStyle(1); l.SetLineWidth(1.); Double_t lm = gPad->GetLeftMargin(); Double_t rm = 1.-gPad->GetRightMargin(); Double_t tm = 1.-gPad->GetTopMargin(); Double_t bm = gPad->GetBottomMargin(); Double_t xndc = (rm-lm)*((x-gPad->GetUxmin())/(gPad->GetUxmax()-gPad->GetUxmin()))+lm; l.DrawLineNDC(xndc,bm,xndc,tm); } void caloprof() { TFile *fin = TFile::Open("C:/si-calo-sep18/si-500628-trasl.root"); fin->ls (); TFile *fin2 = TFile::Open("C:/si-calo-sep18/si-500596-trasl.root"); fin2->ls (); TH1F *hx37ele = (TH1F *)fin->Get("hx37"); if (hx37ele == 0) { printf("Error getting an histogram from the file electrons!\n"); return; } TH1F *hx37muon = (TH1F *)fin2->Get("hx37"); if (hx37muon == 0) { printf("Error getting an histogram from the file muons!\n"); return; } TGaxis::SetMaxDigits(3); if (fin == 0 || fin2 ==0 ) { printf("Error: cannot open the file!\n"); } else { TTree *t=0; TTree *t2=0; fin->GetObject("lemma",t); fin2->GetObject("lemma",t2); TCanvas *c01 = new TCanvas("c01","canvas",1280,1024); c01->SetLogy(); TH2F *henepos = new TH2F("henepos", "", 100, 0., 0.,100, 0.,0.); TString varexp = TString::Format("Calo_EnDep[%d] : hx37 >> henepos", a); TString selection = TString::Format("subdet==%d", subdet); t->Draw(varexp, selection,"goff"); TProfile *hprof = henepos->ProfileX(); hprof->SetLineColor(kBlue); hprof->SetMarkerColor(kBlue); hprof->SetMarkerStyle(8); hprof->GetXaxis()->SetTitle("x-position (cm)"); hprof->GetYaxis()->SetTitle("Energy (ADC counts)"); hprof->GetXaxis()->SetLabelFont(43); hprof->GetXaxis()->SetLabelSize(30); hprof->GetYaxis()->SetLabelFont(43); hprof->GetYaxis()->SetLabelSize(30); hprof->GetXaxis()->SetTitleFont(43); hprof->GetXaxis()->SetTitleSize(30); hprof->GetYaxis()->SetTitleFont(43); hprof->GetYaxis()->SetTitleSize(30); hprof->Draw(); hprof->SetStats(0); gPad->Update(); // make sure it's really (re)drawn TH2F *henepos2 = new TH2F("henepos2", "", 100, 0., 0.,100, 0.,0.); TString varexp2 = TString::Format("Calo_EnDep[%d] : xh >> henepos2", a); t2->Draw(varexp2, selection, "goff"); TProfile *hprof2 = henepos2->ProfileX(); hprof2->SetLineColor(kGreen); hprof2->SetMarkerColor(kGreen); hprof2->SetMarkerStyle(8); hprof2->Draw("SAME "); DrawVerticalLine(9.); DrawVerticalLine(12.); TLegend* leg = new TLegend(0.15, 0.75, .25, .85); leg->SetHeader("Legend"); leg->SetNColumns(1); leg->AddEntry(hprof, "Electrons", "l"); leg->AddEntry(hprof2, "Muons", "l"); leg->Draw(); c01->Print("C:/simulazione/Tprofile.pdf"); } }