I am using the EventLoop package and I am trying to fill a TTree with a particle’s kinematic variables for the particles of each event. I have declared a variable for the number of particles and a vector in the corresponding .h file:
and then I clear the vector at the end of the event. By doing so, the “particle” number should be the same with the size of the vector for the pt.
The code compiles and runs fine. However, when I use the MakeClass command to read the TTree and I print its components, the size of the pt vector is 0 for a small fraction of events, while it works fine for the others. Are there any ideas about what is causing this problem?
Do you also reset the value of ‘particle’ to zero?
However, when I use the MakeClass command to read the TTree and I print its components, the size of the pt vector is 0 for a small fraction of events, while it works fine for the others.
MakeClass is not very good at reading vector. It is however surprising that it works for some entries and not others. Try adding
The problem probably does not have to do with MakeClass because when I open the .root file with root -l myfile.root and draw the pt branch directly from the TTree with:
tree->Draw("pt");
the histogram has less entries than expected. In particular, the sum of the particles is 548 and the entries for the pt are 516. I have also tried to change my vector to a pointer but I got exactly the same result.
Ok. There is a problem in the producing/writing code then. I am unable to guess from the little you shown so far (which looks okay). Can you provide a running example writing on of your files so that we can help you debug it?
You were right about it. The problem was deeper than I first thought. For some reason, when I went back to the beginning to the object selection I noticed that if I run:
so that the size of each vector is the number of tracks in that event. Then in the execute() function I have to initialize the vector components before I can fill them:
for(int i=0; i<1000; i++)
{
tpt[i]=0;
}
And then fill them:
for( auto track : *Tracks ) {
if(tNtracks >= 1000) continue;
++tNtracks;
tpt[tNtracks-1] = track->pt(); //or whatever value you want to fill it with
}