I had a problem when i integrate histogram

Hi experts.
I had a problem when i integrate histogram.
Below code is what i used.

void Asymmetry()
{
  TChain *ch = new TChain("ntp");
  char filename[300];
  for (int i=1; i<=459; i++){
  TString datadir = "/data/COSINE/WORK/islee/NaI037/data/MRGD/";
  sprintf(filename,"mrgd6_M000950.root.%.3d",i);
  ch->Add(datadir+filename);
  }

  TCanvas *Asy = new TCanvas("Asymmetry","Asymmetry",800,600);

  TString asymmetry = "((pmt41.qc5-pmt42.qc5)/(pmt41.qc5+pmt42.qc5))";
  TString multiple = "(BCsIAll.Energy>50) &&";
 
  TString E_12 = "(crystal4.energy*9.3143e-5>1 && crystal4.energy*9.3143e-5<2)";
  gROOT->cd();

  TH1F *asy = new TH1F("asy","asy",50,-1,1);

  ch->Draw("(pmt41.qc5-pmt42.qc5)/(pmt41.qc5+pmt42.qc5)>>asy", multiple + E_12);
  
  Int_t L_Ent = asy->Integral(-0.5,0);
  Int_t R_Ent = asy->Integral(0,0.5);

  std::cout << "L = " << L_Ent << "R = " << R_Ent <<endl;

  TFile o("Asymmetry12.root","RECREATE");
  ch->Write();

}

I wanna compare the sum of left side and right side with zero as the center.
But it shows like below.

In file included from input_line_9:1:
/home/a9mon/NaI037/Asymmetry.C:29:32: warning: implicit conversion from ‘double’ to
‘Int_t’ (aka ‘int’) changes value from 0.5 to 0 [-Wliteral-conversion]
Int_t L_Ent = asy->Integral(-0.5,0);
~~~ ^~~
/home/a9mon/NaI037/Asymmetry.C:30:33: warning: implicit conversion from ‘double’ to
‘Int_t’ (aka ‘int’) changes value from 0.5 to 0 [-Wliteral-conversion]
Int_t R_Ent = asy->Integral(0,0.5);
~~~ ^~~
L = 0R = 0

What is the problem?


Please read tips for efficient and successful posting and posting code

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


Hi,

TH1::Integral() is supposed to take bin numbers as inputs, not axis values. So instead of

do the following:

  Int_t L_Ent = asy->Integral(asy->FindFixBin(-0.5), asy->FindFixBin(0));
  Int_t R_Ent = asy->Integral(asy->FindFixBin(0), asy->FindFixBin(0.5));

Thanks for help!!

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