Should I use a TH2 or a TProfile?

Hello, I am trying to expand on the results of this publication, in short, I have a bunch particles from which I get 2 values, p and delta, I want to plot this two variables together in very specific ranges, then I want the average of each bin (|p|), then I want to add all the averages in the same range of delta but different ranges of p (S|p|), and finally I want to put those results in a TH2 histogram of delta and S|p|.

The thing is, I’m not sure if I can Fill a TProfile directly, since I need to specify the ranges of both X and Y, and no constructor of TProfile seems to allow that, there is no:

TProfile::TProfile ( const char * name, const char * title, Int_t nbins, const Double_t*xbins, Double_tybins, Option_t * option = “” )

So I created a TH2D, filled it, it looks good, but I’m not sure how to get the averages I need, so I decided to convert my TH2D into a TProfile…

TProfile* profile_pTdelta = TH2::ProfileY("hist_pTdelta",1, 9);

but I get a weird compilation error In function ‘int main()’: error: cannot call member function ‘TProfile* TH2::ProfileY(const char*, Int_t, Int_t, const Option_t*) const’ without object
make: *** [myjets] Error 1

And I get the same if I put a “new” after the equal sign.

I asked a teacher and he told to not even bother, that the error bars are too big when using TProfile.
I read that there is a way to change the default error from RMS/sqrt(N) to RMS… but that’s in the constructor, which I’m not using.

My teacher suggested me to create a histogram for each interval of delta, get the mean of those, and then add them up… it would be a mess that I could hide in a function, but I want to be sure there’s no easier way before going that way.

So I finally decided to ask for help, I need another perspective.

Here is how I’m currently declaring the TH2D:

double delta_edges[] = { 0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.5, 1.6, 1.8, 3.6 };
double pT_edges[]    = { 0.5, 1, 2, 4, 8, 300 };
TH2D*  hist_pTdelta  = new TH2D("hist_pTdelta", "The momentum of particles in each Delta Ring", 5, pT_edges, 10, delta_edges );

and here is how I’m using it (I’m using also a library called FastJet, that’s were PesudoJet comes from):

  for (int n = 0; n <= event.size(); ++n)
      PseudoJet particle = event[n];
      delta = sqrt(pow(particle.eta()-axis.eta(),2)+pow(particle.phi()-axis.phi(),2));
      if (delta>3.6 || particle.perp()>300) continue;
      pTll = -particle.perp()*cos( particle.phi()-axis.phi() );
      hist_pTdelta->Fill(pTll,delta); //we fill the histogram in the same order that we declared it, first pT and then delta

Thanks a lot

for proper use of TProfile consult its doc, e.g.
and look at $ROOTSYS/tutorials/hsimple.C

Another possibilty:
TH2F *h2 = new TH2F(…
TProfile *pry = h2->ProfileY(); // all args have defaults

If the result is suited for your purpose
ithat is up to you to judge.


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