CMS 3D CMS Logo

RootChamberReader.cc
Go to the documentation of this file.
4 #include "TClonesArray.h"
5 using namespace std;
6 
7 RootChamberReader::RootChamberReader() : theTree(nullptr), theHits(nullptr), thePosition(0), theSize(0) {}
8 
10  : theTree((TTree *)file->Get(treeName.c_str())),
11  theHits(new TClonesArray("RootSimHit")),
12  thePosition(-1),
13  theSize(0) {
14  if (theTree != nullptr) {
15  theTree->SetBranchAddress("Hits", &theHits);
16  theSize = theTree->GetEntries();
17  }
18 }
19 
21  // delete theHits;
22  // delete theTree;
23 }
24 
26  // if there's no tree, make no events
27  if (theTree != nullptr && theSize != 0) {
28  ++thePosition;
29  // start again from the beginning, if needed
30  if (thePosition >= theSize)
31  thePosition = 0;
32  theTree->GetEntry(thePosition);
33 
34  TIter next(theHits);
35  RootSimHit *rootHit;
36  while ((rootHit = (RootSimHit *)next())) {
37  hits.push_back(rootHit->get());
38  }
39  LogTrace("Neutrons") << "Event " << thePosition << " OF " << theSize << " has " << hits.size() << " hits ";
40  }
41 }
PSimHit get() const
Definition: RootSimHit.cc:21
TClonesArray * theHits
#define nullptr
void read(edm::PSimHitContainer &hits)
RootChamberReader()
default ctor, for STL
#define LogTrace(id)
~RootChamberReader()
writes the tree, and deletes everything
std::vector< PSimHit > PSimHitContainer