TH2F to TProfile

Hi everyone:

Here is a piece of code.
TH2F* f2 = new TH2F(“hello”,“hhelo”,100,-4,4,11,0,1.1);
Float_t px, py, pz;
for ( Int_t i=0; i<25000; i++) {
gRandom->Rannor(px,py);
pz = pxpx + pypy + 5;

      if (pz > 5.5){
         f2->Fill(px,1);
         hprof->Fill(px,1);
        continue;
       }

   hprof->Fill(px,0);
   f2->Fill(px,0) ;

}
TProfile* fp = f2->ProfileX();

I wonder why the plot of fp is different from hprof, especially the value of y-axial.




Hi,

the reason of your discrepancy is due to numerical rounding of 1.0 wich is exactly at the bin edge of the y axis of your 2D histogram.
Just create your 2D histogram as

H2F* f2 = new TH2F(“hello”,“hhelo”,100,-4,4,11,-0.05,1.05);

and the 2 profile’s will be identical

Lorenzo

Yes, it works! Thanks for your help.