CMS 3D CMS Logo

TreeSplitter.cc
Go to the documentation of this file.
1 #ifndef TREESPLITTER_CC
2 #define TREESPLITTER_CC
3 
4 #include "TreeSplitter.h"
5 
7  treeFileName_( iConfig.getParameter<std::string>("InputFileName") ),
8  outputFileName_( iConfig.getParameter<std::string>("OutputFileName") ),
9  maxEvents_( iConfig.getParameter<int32_t>("MaxEvents") ),
10  subSampleFirstEvent_( iConfig.getParameter<uint32_t>("SubSampleFirstEvent") ),
11  subSampleMaxEvents_( iConfig.getParameter<uint32_t>("SubSampleMaxEvents") )
12 {
13 }
14 
16 {
17 }
18 
20 {
21  std::cout << "Reading muon pairs from Root Tree in " << treeFileName_ << std::endl;
22  RootTreeHandler rootTreeHandler;
23 
24  typedef std::vector<std::pair<lorentzVector,lorentzVector> > MuonPairVector;
25  // MuonPairVector savedPair;
26  std::vector<MuonPair> savedPair;
27  rootTreeHandler.readTree(maxEvents_, treeFileName_, &savedPair, 0);
28  // rootTreeHandler.readTree(maxEvents, inputRootTreeFileName_, &savedPair, &(MuScleFitUtils::genPair));
29 
30  // Loop on all the pairs
31  std::vector<MuonPair> newSavedPair;
32  // MuonPairVector newSavedPair;
33  unsigned int i = 0;
34  // MuonPairVector::iterator it = savedPair.begin();
35  std::vector<MuonPair>::iterator it = savedPair.begin();
36  std::cout << "Starting loop on " << savedPair.size() << " muons" << std::endl;
37  uint32_t lastEvent = subSampleFirstEvent_ + subSampleMaxEvents_;
38  for( ; it != savedPair.end(); ++it, ++i ) {
39  // Save only events in the selected range
40  if( i >= subSampleFirstEvent_ && i < lastEvent ) {
41  newSavedPair.push_back(*it);
42  }
43  }
44  rootTreeHandler.writeTree(outputFileName_, &newSavedPair, 0);
45 }
46 
47 //define this as a plug-in
49 
50 #endif
uint32_t subSampleFirstEvent_
Definition: TreeSplitter.h:41
TreeSplitter(const edm::ParameterSet &)
Definition: TreeSplitter.cc:6
void readTree(const int maxEvents, const TString &fileName, MuonPairVector *savedPair, const int muonType, std::vector< std::pair< unsigned int, unsigned long long > > *evtRun, MuonPairVector *genPair=nullptr)
void writeTree(const TString &fileName, const std::vector< MuonPair > *savedPair, const int muonType=0, const std::vector< GenMuonPair > *genPair=nullptr, const bool saveAll=false)
TString treeFileName_
Definition: TreeSplitter.h:38
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TString outputFileName_
Definition: TreeSplitter.h:39
~TreeSplitter() override
Definition: TreeSplitter.cc:15
std::vector< std::pair< lorentzVector, lorentzVector > > MuonPairVector
void endJob() override
Definition: TreeSplitter.cc:19
uint32_t subSampleMaxEvents_
Definition: TreeSplitter.h:42
int32_t maxEvents_
Definition: TreeSplitter.h:40