CMS 3D CMS Logo

TreeSplitter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TreeSplitter
4 // Class: TreeSplitter
5 //
13 //
14 // Original Author: Marco De Mattia
15 // Created: Thu Sep 11 12:16:00 CEST 2008
16 //
17 
24 
26 public:
27  explicit TreeSplitter(const edm::ParameterSet&);
28  ~TreeSplitter() override;
29 
30 private:
31  void analyze(const edm::Event&, const edm::EventSetup&) override{};
32  void endJob() override;
33 
34  TString treeFileName_;
35  TString outputFileName_;
36  int32_t maxEvents_;
39 };
40 
42  : treeFileName_(iConfig.getParameter<std::string>("InputFileName")),
43  outputFileName_(iConfig.getParameter<std::string>("OutputFileName")),
44  maxEvents_(iConfig.getParameter<int32_t>("MaxEvents")),
45  subSampleFirstEvent_(iConfig.getParameter<uint32_t>("SubSampleFirstEvent")),
46  subSampleMaxEvents_(iConfig.getParameter<uint32_t>("SubSampleMaxEvents")) {}
47 
49 
51  std::cout << "Reading muon pairs from Root Tree in " << treeFileName_ << std::endl;
52  RootTreeHandler rootTreeHandler;
53 
54  typedef std::vector<std::pair<lorentzVector, lorentzVector> > MuonPairVector;
55  // MuonPairVector savedPair;
56  std::vector<MuonPair> savedPair;
57  rootTreeHandler.readTree(maxEvents_, treeFileName_, &savedPair, 0);
58  // rootTreeHandler.readTree(maxEvents, inputRootTreeFileName_, &savedPair, &(MuScleFitUtils::genPair));
59 
60  // Loop on all the pairs
61  std::vector<MuonPair> newSavedPair;
62  // MuonPairVector newSavedPair;
63  unsigned int i = 0;
64  // MuonPairVector::iterator it = savedPair.begin();
65  std::vector<MuonPair>::iterator it = savedPair.begin();
66  std::cout << "Starting loop on " << savedPair.size() << " muons" << std::endl;
68  for (; it != savedPair.end(); ++it, ++i) {
69  // Save only events in the selected range
70  if (i >= subSampleFirstEvent_ && i < lastEvent) {
71  newSavedPair.push_back(*it);
72  }
73  }
74  rootTreeHandler.writeTree(outputFileName_, &newSavedPair, 0);
75 }
76 
77 //define this as a plug-in
uint32_t subSampleFirstEvent_
Definition: TreeSplitter.cc:37
TreeSplitter(const edm::ParameterSet &)
Definition: TreeSplitter.cc:41
#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.cc:34
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: TreeSplitter.cc:31
TString outputFileName_
Definition: TreeSplitter.cc:35
~TreeSplitter() override
Definition: TreeSplitter.cc:48
void endJob() override
Definition: TreeSplitter.cc:50
uint32_t subSampleMaxEvents_
Definition: TreeSplitter.cc:38
std::vector< std::pair< lorentzVector, lorentzVector > > MuonPairVector
int32_t maxEvents_
Definition: TreeSplitter.cc:36