Tprofile plotting

Hello, I’ve these ROOT files

I need a Tprofile of the “Calo_EnDep[0]” and “xh” from both the root file. The macro works for one Tprofile…

but when I try to merge the two plots on a single canvas I get this… you see…:

  1. It looks like it is plotting also the scatter plot;
  2. The Tprofile regarding of the muons (Green line) doesn’t work (I just see a green line)

Thank you

caloprof.cpp (3.8 KB)

It looks like it could be a problem of scales. Did you draw the 2 separately and check the x and y scales/ranges? If they are very different you can end up with something looking like what you showed.

Hello @dastudillo …yes the scales are differents, that’s because I setted the logy to merge the plots…anyway

  1. Here the plot regarding of the electrons

  1. Here the plot regarding of the electrons setting logy (in this plot I also have the problem regarding of the Tlines that don’t cover all the canvas but stop when they cross the data)

  1. Here the plot regarding of muons

  1. Here the plot regarding of the electrons setting logy (also in this plot I also have the problem regarding of the Tlines that don’t cover all the canvas but stop when they cross the data)

You see…wehn I plot 2 canvas, I just get the Tprofile (not the scatter plot) …moreover, muons releas energy untill 100 ADC…so I shouldn’t have the green line in the plot when I merge the two hystograms

Search for "goff" in the TTree::Draw method description.

Do not mix “ProfileX” and “ProfileY” in the same plot unless you really mean it.

hello @Wile_E_Coyote

if I set “goff option”

  1. I can’t write the canvas and axes titles…
  2. I can’t remove the statbox
  3. I still get the Tline problem
  4. I get only the muon plot

This was a typo-bug… I need ProfileX for the both…

caloprof.cpp (4.0 KB)

Hello @Wile_E_Coyote I finally could get the two Tprofile into a same TCanvas.

Unfortunately, I’ve the last problem, i.e. the Tline doesn’t cover all the pad… do you know how to fix it?
Or @couet maybe you know it, because I’m using the Drawline function found in one your reply to a topic.

Here the macro

caloprof.cpp (3.8 KB)
Thank you

Your DrawVerticalLine function will do.

Hello @Wile_E_Coyote yes, I can get the line, bit I can’t modify it (I mean setting the color and the style)…i just can get a thin line

int a=0;
int subdet=37;
int xhn=-99;

void DrawVerticalLine(Double_t x)
{
   TLine l;
   l.SetLineColor(kRed);
   l.SetLineStyle(10);
   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("si-500628.root");
   //TFile *fin = TFile::Open("C:/si-calo-sep18/si-500596.root");
   fin->ls ();
   TFile *fin2 = TFile::Open("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);
      c01->SetLogy();

      TH2F *henepos = new TH2F("henepos", "", 100, 0., 0.,100, 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,"goff");

      TProfile *hprof = henepos->ProfileX();
      hprof->SetLineColor(kBlue);
      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->Draw("SAME ");

      DrawVerticalLine(8.);
      DrawVerticalLine(12.);

      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("Tprofile.pdf");
   }
}

Thank you @couet! it works!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.