Hi,
I am trying to access the MC information (in o2sim_Kine.root) of reconstructed tracks (for example in in o2trac_ist.root as I am looking at tracks reconstructed in the ITS) using the outputs of an o2 simulation (o2sim suite).
I have found the o2::steer::MCKinematicsReader class that should, if I understand correctly, allow me to find the MC track (in o2sim_Kine.root) associated with the reconstructed track (in o2trac_its.root) by using labels, and calling the function .getTrack().
I have tried to use the .getTrack(int trackID, int event ID, int sourceID) variation of the function, but I can’t get my code to work: it breaks after iterating over 1 to 5 or 6 tracks, then breaks with a segmentation violation when I use MCKinematicsReader reader.getTrack()
I attached the whole code to this post, but here is a summary of what I am doing in it:
//initialise MCKinematicsReader
o2::steer::MCKinematicsReader reader("/thepathtothecorrectfolder/collisioncontext.root");
//loop over the tracks
for (int itrack = 0; itrack<nTracks; itrack++){
//get the trackID, eventID and sourceID of the track
//assuming good declaration of mMCTruthArray and link to the o2trac_its.root file (see full code)
int trackID = mMCTruthArray.getElement(itrack).getTrackID();
int eventID = mMCTruthArray.getElement(itrack).getEventID();
int sourceID = mMCTruthArray.getElement(itrack).getSourceID();
//get the track associated to those labels
o2::MCTrack const* mctrack = reader.getTrack(trackID, eventID, sourceID); -->this is where the break happens when it happens
if (!mctrack){
Printf(" no track found");
pdgCode = 0;
continue;
}
long int pdgCode = mctrack->GetPdgCode();
}
If I run the built executable several times in a row, the break doesn’t happen always at the same iteration over the tracks: if most of the times it breaks at itrack=0, it sometimes goes up to itrack=6, and returns for the pdgCode 0,1 or 32767 which is apparently the range of the int type: -32768 to 32767. When changing pdgCode from int to long int, I still sometimes get 32767.
The error message I get once it breaks is:
*** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[<unknown binary>] (no debug info)
[/Users/stf4795/alice/sw/BUILD/O2-latest/O2/stage/bin/o2-trimITSTrackTree-AIMERIC_files] main /Users/stf4795/alice/sw/SOURCES/O2/v1.2.0/0/AIMERIC_files/src/trim_ITS_track_tree.cxx:152
[/usr/lib/system/libdyld.dylib] start (no debug info)
[<unknown binary>] (no debug info)
Am I using the MCKinematicsReader incorrectly? I’ve found examples in the github but they all show how to use it with the digits files instead of the reconstructed tracks files.
Best wishes,
Aimeric
trim_ITS_track_tree.cxx (6.1 KB)