Home | News | Documentation | Download

Access histogram function


#1

Dear experts,
I what to access histograms function after a Fit and plot all the fit on the same canvas. I used (1), but it does not find the function. You can see the complete code here (2). Do you see something wrong in the procedure?
Regards

(1)

  i=0;
  for (auto &station : vstation){ 
    for (auto &layer : vlayer){
   
      name = station+"_"+layer;
      cout<<"\nSiT layer: "<<name<<endl;

      canvas->cd(i+1);

      h_meanhitVersusPileup[i]->Fit("fpol", "R");

      TF1 *h_fit = (TF1*) h_meanhitVersusPileup[i]->GetFunction("fpol");

	h_fit->SetLineColor(i);
	canvas->cd(17);
	h_fit->Draw("same");
      }

      i++;
    }
  }

(2)
http://calpas.web.cern.ch/calpas/sit_pileup.C


#2

Dear experts,
any idea?
Regards


#3

The full example you posted via its URL uses data we do not have. Can you post a self contained example we can run and showing what is your problem ? What do you mean by “it does not find the function” ? I do not see any problem with the standard hex histogram stored in hsimple.root:

root [0] hpx->Fit("gaus")
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
 FCN=63.6385 FROM MIGRAD    STATUS=CONVERGED      54 CALLS          55 TOTAL
                     EDM=6.235e-10    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  Constant     8.00108e+02   6.20101e+00   1.98916e-02  -6.18780e-06
   2  Mean        -3.86196e-03   6.30762e-03   2.47615e-05   1.13881e-03
   3  Sigma        9.94740e-01   4.45485e-03   4.77918e-06  -2.46080e-02
(TFitResultPtr) <nullptr TFitResult>

root [1] hpx->GetListOfFunctions()->ls()
OBJ: TList	TList	Doubly linked list : 0
 OBJ: TPaveStats	stats  	X1= 2.800000 Y1=718.495291 X2=4.800000 Y2=888.805322
 OBJ: TF1	gaus	gaus : 0 at: 0x7fa48cc50030

root [2] auto f = hpx->GetFunction("gaus");
root [3] f->Draw()
root [4] 

#4

Dear Couet,
can you please parse these 2 files (*) in the input file vector?
Regards

(*)
http://calpas.web.cern.ch/calpas/user.calpas.13392746.CombinedMonitoring._000001.root
http://calpas.web.cern.ch/calpas/user.calpas.13392746.CombinedMonitoring._000002.root


#5

simply add a protection in case the fit is empty (see the warnings):

      if (h_fit) {
         h_fit->SetLineColor(i);
         canvas->cd(17);
         h_fit->Draw("same");
      }

#6

Dear Couet,
even with the protection it does not work.
Regards


#7

What do you mean ? what do you get ? for rme it works


#8

Dear Couet,

yes you are right, it’s working. But I want to have all the fits on the same pad number 17 as you can see at line 129 of (*). Why it does not draw them there?
Regards

(*)
http://calpas.web.cern.ch/calpas/sit_pileup.C


#9

Because you draw all the fits with option same and pad 17 limits are never defined in that case. Before the loop do:

  canvas->cd(17)->DrawFrame(10.,0.,70.,15.);

#10

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