#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" #include "TCut.h" #include "TPaletteAxis.h" #include "TLatex.h" #include "TText.h" #include "TLine.h" #include "TProfile.h" int a=0; int subdet=37; int xhn=-99; void DrawVerticalLine(Double_t x) { TLine l; 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.root"); // TFile *fin = TFile::Open("C:/si-calo-sep18/si-500596.root"); fin->ls (); TFile *fin2 = TFile::Open("C:/si-calo-sep18/si-500596.root"); fin2->ls (); TGaxis::SetMaxDigits(3); if (fin == 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); TH2F *henepos = new TH2F("henepos", "", 500, 0., 0.,500, 0.,0.); TString varexp = TString::Format("Calo_EnDep[%d] : xh >> henepos", a); TString selection = TString::Format("subdet==%d && xh>%d", subdet, xhn); t->Draw(varexp, selection); gPad->Modified(); TProfile *hprof = henepos->ProfileX(); henepos->SetTitle("Released energy"); hprof->SetLineColor(kBlue); henepos->GetXaxis()->SetTitle("x-position (cm)"); henepos->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("SAME"); henepos->SetStats(0); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TH2F *henepos2 = new TH2F("henepos2", "", 500, 0., 0.,500, 0.,0.); TString varexp2 = TString::Format("Calo_EnDep[%d] : xh >> henepos2", a); t2->Draw(varexp2, selection,"SAME"); TProfile *hprof2 = henepos2->ProfileY(); hprof2->SetLineColor(kGreen); hprof2->Draw("SAME"); gPad->Modified(); float threshold = 9; auto lnThreshold = new TLine(threshold,0, threshold,gPad->GetUymax()); lnThreshold->SetLineColor(kRed); lnThreshold->SetLineStyle(10); lnThreshold->SetLineWidth(2.); // maybe lnThreshold->Draw(); // DrawVerticalLine(2.); gPad->Modified(); c01->Update(); float threshold2 = 12; auto lnThreshold2 = new TLine(threshold2, 0, threshold2,gPad->GetUymax()); lnThreshold2->SetLineColor(kRed); lnThreshold2->SetLineStyle(10); lnThreshold2->SetLineWidth(2.); // maybe lnThreshold2->Draw(); // DrawVerticalLine(2.); c01->SetLogy(); gPad->Modified(); TLegend* leg = new TLegend(0.15, 0.8, .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"); } }