//Objective of this code is to loop over the reconstructed tracks of o2trac_its.root and get the pdgcode of the associated particles, then create a tree with this information. void TestITS(){ //**************************** Kinematics and MC information File ***********************************// // Open the .root data file with MC information std::unique_ptr mcFile(TFile::Open(("o2sim_Kine.root "))); if (!mcFile || mcFile->IsZombie()) { std::cerr << "Failed to open input Kine file " << ("o2sim_Kine.root"); return; } // Open the tree std::unique_ptr mcTree((TTree*)mcFile->FindObjectAny("o2sim")); if (!mcTree) { std::cerr << "Failed to get o2sim tree"; return; } // init the reader from the context o2::steer::MCKinematicsReader reader("collisioncontext.root"); // Create the pointers for the relevant branches of the input tree std::vector* mcTracksArray = nullptr; mcTree->SetBranchAddress("MCTrack", &mcTracksArray); //**************************** Input File ***********************************// // Open the .root data file with tracks std::unique_ptr trackFile(TFile::Open(("o2trac_its.root "))); if (!trackFile || trackFile->IsZombie()) { std::cerr << "Failed to open input digits file " << ("o2trac_its.root"); return; } // Open the tree std::unique_ptr trackTree((TTree*)trackFile->FindObjectAny("o2sim")); if (!trackTree) { std::cerr << "Failed to get o2sim tree"; return; } // Create the pointers for the relevant branches of the input tree std::vector* itsTracksArray = nullptr; trackTree->SetBranchAddress("ITSTrack", &itsTracksArray); std::vector* mcTruthArrayPtr = nullptr; trackTree->SetBranchAddress("ITSTrackMCTruth", &mcTruthArrayPtr); //**************************** Output File ***********************************// // Create new .root file to store the DCA info std::unique_ptr trimmedfile(new TFile("trimmed_ITSTracks.root", "RECREATE")); if (!trimmedfile || trimmedfile->IsZombie()) { std::cerr << "Failed to open file " << ("trimmed_ITSTracks.root"); return; } // Create Tree for output file std::unique_ptr fTreeTrimmed(new TTree("trimmed_Tree", "")); // Initialise Tree parameters and create tree and tree branches (//check https://github.com/AliceO2Group/AliceO2/blob/aa579dea7c83b35d30b38b22bdce1822392ccf72/Framework/Core/test/test_Root2ArrowTable.cxx) int trackID = -1; int eventID = -1; int sourceID = -1; long int pdgCode; fTreeTrimmed->Branch("trackID", &trackID, "trackID/I" ); fTreeTrimmed->Branch("pdgCode", &pdgCode, "pdgCode/I" ); //********************************** Loop over the tracks of o2trac_its.root ********************************************// //get or set the magnetic field, needed for the DCAFitter float MagField = 5; // can't find it in any o2sim.root file trackTree->GetEntry(0); // loop over all the tracks int nTracks = itsTracksArray->size(); std::cerr << "We have " << nTracks << " tracks "; std::cerr << "We have " << mcTruthArrayPtr->size() << " labels "; for (int itrack = 0; itrackat(itrack); //get the trackID, eventID and sourceID of the track auto& mctruth = *mcTruthArrayPtr; auto& label = mctruth[itrack]; trackID = label.getTrackID(); eventID = label.getEventID(); sourceID = label.getSourceID(); Printf(" trackID = %i",trackID); Printf(" eventID = %i",eventID); Printf(" sourceID = %i",sourceID); //get the track associated to those labels o2::MCTrack const* mctrack = reader.getTrack(label); if (!mctrack){ Printf(" no track found"); pdgCode = 0; continue; } pdgCode = mctrack->GetPdgCode(); //returns 0,1 or 32767 which is apparently the range of the int type: -32768 to 32767 ; didn't change when using long int -> is it a coincidence? Printf(" pdgCode %li", pdgCode); // add track to tree with: trackID, pdgCode (will eventually have more, but right now is not what is causing issues) fTreeTrimmed->Fill(); } fTreeTrimmed->Write(); //trimmedfile->Close(); }