File indexing completed on 2024-04-06 12:30:49
0001 #include "SimMuon/Neutron/src/RootChamberReader.h"
0002 #include "SimMuon/Neutron/src/RootSimHit.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "TClonesArray.h"
0005 using namespace std;
0006
0007 RootChamberReader::RootChamberReader() : theTree(nullptr), theHits(nullptr), thePosition(0), theSize(0) {}
0008
0009 RootChamberReader::RootChamberReader(TFile *file, const std::string &treeName)
0010 : theTree((TTree *)file->Get(treeName.c_str())),
0011 theHits(new TClonesArray("RootSimHit")),
0012 thePosition(-1),
0013 theSize(0) {
0014 if (theTree != nullptr) {
0015 theTree->SetBranchAddress("Hits", &theHits);
0016 theSize = theTree->GetEntries();
0017 }
0018 }
0019
0020 RootChamberReader::~RootChamberReader() {
0021
0022
0023 }
0024
0025 void RootChamberReader::read(edm::PSimHitContainer &hits) {
0026
0027 if (theTree != nullptr && theSize != 0) {
0028 ++thePosition;
0029
0030 if (thePosition >= theSize)
0031 thePosition = 0;
0032 theTree->GetEntry(thePosition);
0033
0034 TIter next(theHits);
0035 RootSimHit *rootHit;
0036 while ((rootHit = (RootSimHit *)next())) {
0037 hits.push_back(rootHit->get());
0038 }
0039 LogTrace("Neutrons") << "Event " << thePosition << " OF " << theSize << " has " << hits.size() << " hits ";
0040 }
0041 }