How do I find all the entries for particular organID in ntuple?

Hello,

My Ntuple has OrganID and Edep as two variables. Below is the some part of the result of ntuple->Scan()

  • Row * organID * edep *

  •    0 *         0 * 47388.926 *
    
  •    1 *         1 * 72410.647 *
    
  •    2 *         3 * 527.36354 *
    
  •    3 *         4 * 36178.279 *
    
  •    4 *         6 * 0.2632020 *
    
  •    5 *         7 * 9860.5481 *
    
  •    6 *         8 * 302542.39 *
    
  •    7 *         9 * 62766.762 *
    
  •    8 *        12 * 10204.895 *
    
  •    9 *        13 * 0.2821026 *
    

.
.
<other values in between till row number 31>
.

  •   32 *         0 * 49589.595 *
    
  •   33 *         1 * 71012.100 *
    
  •   34 *         3 * 547.18643 *
    
  •   35 *         4 * 36951.942 *
    
  •   36 *         6 * 0.5847544 *
    
  •   37 *         7 * 10640.369 *
    
  •   38 *         8 * 302008.29 *
    
  •   39 *         9 * 62758.523 *
    
  •   40 *        12 * 10518.896 *
    
  •   41 *        13 * 0.4693063 *
    
  •   42 *        14 * 28.497480 *
    
  •   43 *        15 * 3.7103971 *
    
  •   44 *        16 * 79167.327 *
    
  •   45 *        17 * 1765.4321 *
    
  •   46 *        19 * 36838.414 *
    
  •   47 *        20 * 591.20726 *
    
  •   48 *        21 * 37632.491 *
    
  •   49 *        23 * 0.4601577 *
    

I want to find all the entries for particular OrganID.
example: for OrganID 6, it should return following rows:

  • Row * organID * edep *

  •    4 *         6 * 0.2632020 *
    
  •   36 *         6 * 0.5847544 *
    

My goal is to find all the rows for specific organID and sum them all.

Any help in this regard would be highly appreciated.

Thanks,
Piyush

ntuple->Scan("*", “organID == 6”);

Thanks. it worked. Also, is there’s any way to dump this output in a variable? I basically want to take the sum of “edep” of this returned scan result.

The value integral on the resulting plot should print out the sum of edeps:

ntuple -> Draw("edep", "organID == 6")```

Thanks Adam! However, this would generate a figure. Is there’s any way to get the sum and not generating the figure?

There is no compact solution for that. You will have to loop on the entries in the TTree:

int organID;
float edep;
ntuple -> SetBranchAddress("organID", &organID);
ntuple -> SetBranchAddress("edep", &edep);
int sum = 0;
for(Long64_t entryIndex = 0; entryIndex < ntuple -> GetEntries() ++entryIndex) 
{
    ntuple -> GetEntry(entryIndex);
    if(organID == 6) sum += edep;
}
std::cout << "The sum is: " << sum << std::endl;

Great! Thank you very much :slight_smile:

1 Like

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