How to make transverse momentum intervals and how to do a certain operation in the transverse momentum intervals?

Hello all, I’m new to root and basically stuck in a code algorithm because my knowledge in C is very minimum to non-existent.
here is the code that looping on all events and tracks of the event

for(int ipart=0;ipart<p.Ntracks;ipart++)
    {
      //CALCULATE A VARIABLE AND FILL IT INTO A HISTOGRAM
      
      double pt = sqrt(p.px[ipart]*p.px[ipart]+p.py[ipart]*p.py[ipart])*1.1;
      double phi0 = atan2(p.py[ipart],p.px[ipart]);
      double phiRP = phi0-p.ReactionPlane;
      if(phiRP<-M_PI) phiRP += 2*M_PI;
      if(phiRP>M_PI) phiRP -= 2*M_PI;
      if(phiRP<-M_PI/2) phiRP += M_PI;
      if(phiRP>M_PI/2) phiRP -= M_PI;
      ptdist->Fill(pt);
      phidist->Fill(phiRP);
    }

double pt = sqrt(p.px[ipart]*p.px[ipart]+p.py[ipart]*p.py[ipart])*1.1; calculates the transverse momentum
while double phiRP = phi0-p.ReactionPlane; flow angle.
The objective is I need do this phiRP (phi angle) code for tracks in various pT transverse momentum intervals, say: 2-300, 3-400, MeV/c, etc. After this I need to fill result into an angle distribution, separate for each pT.
The question is how to implement this? I tried like ptdist[nPART] intervals but it gives me error. So since my knowledge in C is non-existence compared to my python knowledge, I need help?

ROOT Version: 6.26.02
Platform: wsl
Compiler: emacs___

Hi @Highenergyman ,
and welcome to the ROOT forum! Please see Posting code? Read this first! for tips on code formatting on the forum.

You tagged the post as #rdataframe , so I would like to make sure, how does the rest of the code look like? How are you reading the input data?

We can help with ROOT and a bit of C++ but if you have to write a lot of C or C++ code you might want to start by getting familiar with the language.

About your actual question, I don’t see any logic in your code snippet that selects only the tracks that belong to a certain pt interval. Maybe the simplest way to do it is with a 2-dimensional histogram filled with phiRP in one dimension and with pt in the other, so you get a different “slice” of phiRP distribution for different slices in pt?

TH2D h("h", "h", nPtBins, minPt, maxPt, nPhiRPBins, phiRPmin, phiRPmax);
h.Fill(pt, phiRP);

Cheers,
Enrico

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