Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:28

0001 #include <Track.h>
0002 #include <GFRaveVertex.h>
0003 
0004 #include <TDatabasePDG.h>
0005 #include <TEveManager.h>
0006 #include <TGeoManager.h>
0007 #include <TRandom.h>
0008 #include <TVector3.h>
0009 #include <vector>
0010 
0011 #include <TROOT.h>
0012 #include <TClonesArray.h>
0013 #include <TFile.h>
0014 #include <TTree.h>
0015 
0016 #include <iostream>
0017 
0018 
0019 int main() {
0020 
0021   genfit::Track tr; // pull in genfit libraries
0022 
0023   //genfit::Track* aTrackPtr(nullptr);
0024   genfit::GFRaveVertex* aVertexPtr(nullptr);
0025 
0026   TFile* trackFile = TFile::Open("tracks.root", "READ");
0027   if (!trackFile) {
0028     std::cerr << "Couldn't open 'tracks.root'." << std::endl;
0029     return -1;
0030   }
0031   TTree* tree = (TTree*)trackFile->Get("tree");
0032   if (!tree) {
0033     std::cerr << "Couldn't find tree 'tree' in file 'tracks.root'." << std::endl;
0034     return -1;
0035   }
0036   TClonesArray* trackArray = new TClonesArray("genfit::Track");
0037   tree->SetBranchAddress("trackBranch", &trackArray);
0038 
0039   tree->Print();
0040 
0041   TClonesArray* vertexArray = new TClonesArray("genfit::GFRaveVertex");
0042   tree->SetBranchAddress("vertexBranch", &vertexArray);
0043 
0044 
0045   for (Long_t i = 0; i < tree->GetEntries(); ++i) {
0046     tree->GetEntry(i);
0047 
0048     std::cout << "trackArray nr of entries: " << trackArray->GetEntries() << "\n";
0049 
0050     for (Long_t j = 0; j < trackArray->GetEntriesFast(); ++j) {
0051       std::cout << "track uniqueID: " << static_cast<genfit::Track*>(trackArray->At(j))->GetUniqueID() <<
0052           " (" << static_cast<genfit::Track*>(trackArray->At(j))->GetUniqueID() - 16777216 << ")\n";
0053     }
0054 
0055     for (Long_t j = 0; j < vertexArray->GetEntriesFast(); ++j) {
0056 
0057       aVertexPtr = (genfit::GFRaveVertex*)(vertexArray->At(j));
0058       //aVertexPtr->Print();
0059 
0060       for (unsigned int k=0; k<aVertexPtr->getNTracks(); ++k) {
0061         std::cout << "track parameters uniqueID: " << aVertexPtr->getParameters(k)->GetUniqueID() << "\n";
0062       }
0063 
0064       // when the track branch from the tracks.root file is loaded, the TRefs to the tracks
0065       // in the GFRaveTrackParameters are again pointing to them.
0066       for (unsigned int k = 0; k<aVertexPtr->getNTracks(); ++k) {
0067         if (aVertexPtr->getParameters(k)->hasTrack()) {
0068           std::cout << "track parameters have track \n";
0069         }
0070         else {
0071           std::cout << "track parameters have NO track <--------------------------------- \n";
0072         }
0073       }
0074 
0075     }
0076 
0077   }
0078 
0079 
0080 }
0081 
0082