00001 #include "SimMuon/Neutron/src/RootChamberReader.h" 00002 #include "SimMuon/Neutron/src/RootSimHit.h" 00003 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00004 #include "TClonesArray.h" 00005 using namespace std; 00006 00007 RootChamberReader::RootChamberReader() 00008 : theTree(0), 00009 theHits(0), 00010 thePosition(0), 00011 theSize(0) 00012 { 00013 } 00014 00015 00016 RootChamberReader::RootChamberReader(TFile * file, const std::string & treeName) 00017 : theTree( (TTree *) file->Get(treeName.c_str()) ), 00018 theHits(new TClonesArray("RootSimHit")), 00019 thePosition(-1), 00020 theSize(0) 00021 { 00022 if(theTree != 0) 00023 { 00024 theTree->SetBranchAddress("Hits", &theHits); 00025 theSize = theTree->GetEntries(); 00026 } 00027 } 00028 00029 00030 RootChamberReader::~RootChamberReader() 00031 { 00032 // delete theHits; 00033 // delete theTree; 00034 } 00035 00036 00037 void RootChamberReader::read(edm::PSimHitContainer & hits) 00038 { 00039 // if there's no tree, make no events 00040 if(theTree != 0 && theSize != 0) 00041 { 00042 ++thePosition; 00043 // start again from the beginning, if needed 00044 if(thePosition >= theSize) thePosition = 0; 00045 theTree->GetEntry(thePosition); 00046 00047 TIter next(theHits); 00048 RootSimHit * rootHit; 00049 while( (rootHit = (RootSimHit *) next()) ) 00050 { 00051 hits.push_back(rootHit->get()); 00052 } 00053 LogTrace("Neutrons") << "Event " << thePosition << " OF " << theSize 00054 << " has " << hits.size() << " hits "; 00055 } 00056 } 00057 00058