Integrating

void rough() {

gStyle->SetOptStat(0);

auto f = new TFile(“run_11_r0.root”);

auto TreeMaster = (TTree*) f->Get(“TreeMaster”);

TH1D* h[4];
for (int i=0; i<=4; i++) {
h[i] = new TH1D(Form(“h%i”,i+1), Form(“Cristal = %i”,i),10000 ,0,1500);
h[i]->SetLineColor(i+2);

}

TreeMaster->Draw(“0.0899152 + 0.224355 * (Energy + (0.5-(rand())/2147483647.))>> h1”,“Cristal==0”,“goff”);
TreeMaster->Draw(“0.109294 + 0.228245 * (Energy + (0.5-(rand())/2147483647.)) >> h2”,“Cristal==1”,“goff”);
TreeMaster->Draw(“0.206293 + 0.23034 * (Energy + (0.5-(rand())/2147483647.)) >> h3”,“Cristal==2”,“goff”);
TreeMaster->Draw(“0.00227491 + 0.229786 * (Energy + (0.5-(rand())/2147483647.)) >> h4”,“Cristal==3”,“goff”);

h[0]->SetBit(TH1::kNoTitle,kTRUE);

h[0]->Draw();
h[1]->Draw(“same”);
h[2]->Draw(“same”);
h[3]->Draw(“same”);

float a = h[0]->Integral(118,127);
printf(“Result”,a);

gPad->BuildLegend();
}
image

I am trying to get the integral for certain peaks but it is not working. Can you please show the right way of getting an integral?


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


double a = h[0]->Integral(h[0]->FindFixBin(118.), h[0]->FindFixBin(127.));

1 Like

Thanks for the help. I am trying to print it out but getting an error. Can you also please let me know how I can display it?

printf("Result = %g\n", a);

1 Like
printf("a = %g\n",a);
1 Like

Thanks.

Thanks.