CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
14 
16  std::cout << "Reading muon pairs from Root Tree in " << treeFileName_ << std::endl;
17  RootTreeHandler rootTreeHandler;
18 
19  typedef std::vector<std::pair<lorentzVector, lorentzVector> > MuonPairVector;
20  // MuonPairVector savedPair;
21  std::vector<MuonPair> savedPair;
22  rootTreeHandler.readTree(maxEvents_, treeFileName_, &savedPair, 0);
23  // rootTreeHandler.readTree(maxEvents, inputRootTreeFileName_, &savedPair, &(MuScleFitUtils::genPair));
24 
25  // Loop on all the pairs
26  std::vector<MuonPair> newSavedPair;
27  // MuonPairVector newSavedPair;
28  unsigned int i = 0;
29  // MuonPairVector::iterator it = savedPair.begin();
30  std::vector<MuonPair>::iterator it = savedPair.begin();
31  std::cout << "Starting loop on " << savedPair.size() << " muons" << std::endl;
32  uint32_t lastEvent = subSampleFirstEvent_ + subSampleMaxEvents_;
33  for (; it != savedPair.end(); ++it, ++i) {
34  // Save only events in the selected range
35  if (i >= subSampleFirstEvent_ && i < lastEvent) {
36  newSavedPair.push_back(*it);
37  }
38  }
39  rootTreeHandler.writeTree(outputFileName_, &newSavedPair, 0);
40 }
41 
42 //define this as a plug-in
44 
45 #endif
uint32_t subSampleFirstEvent_
Definition: TreeSplitter.h:40
TreeSplitter(const edm::ParameterSet &)
Definition: TreeSplitter.cc:6
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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:37
TString outputFileName_
Definition: TreeSplitter.h:38
~TreeSplitter() override
Definition: TreeSplitter.cc:13
void endJob() override
Definition: TreeSplitter.cc:15
uint32_t subSampleMaxEvents_
Definition: TreeSplitter.h:41
std::vector< std::pair< lorentzVector, lorentzVector > > MuonPairVector
tuple cout
Definition: gather_cfg.py:144
int32_t maxEvents_
Definition: TreeSplitter.h:39