Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-19 23:36:10

0001 // -*- C++ -*-
0002 //
0003 // Package:    TreeSplitter
0004 // Class:      TreeSplitter
0005 //
0006 /**\class TreeSplitter TreeSplitter.cc MuonAnalysis/MomentumScaleCalibration/plugins/TreeSplitter.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Marco De Mattia
0015 //         Created:  Thu Sep 11 12:16:00 CEST 2008
0016 //
0017 
0018 #include "FWCore/Framework/interface/MakerMacros.h"
0019 #include "FWCore/Framework/interface/Frameworkfwd.h"
0020 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include <MuonAnalysis/MomentumScaleCalibration/interface/RootTreeHandler.h>
0024 
0025 class TreeSplitter : public edm::one::EDAnalyzer<> {
0026 public:
0027   explicit TreeSplitter(const edm::ParameterSet&);
0028   ~TreeSplitter() override;
0029 
0030 private:
0031   void analyze(const edm::Event&, const edm::EventSetup&) override{};
0032   void endJob() override;
0033 
0034   TString treeFileName_;
0035   TString outputFileName_;
0036   int32_t maxEvents_;
0037   uint32_t subSampleFirstEvent_;
0038   uint32_t subSampleMaxEvents_;
0039 };
0040 
0041 TreeSplitter::TreeSplitter(const edm::ParameterSet& iConfig)
0042     : treeFileName_(iConfig.getParameter<std::string>("InputFileName")),
0043       outputFileName_(iConfig.getParameter<std::string>("OutputFileName")),
0044       maxEvents_(iConfig.getParameter<int32_t>("MaxEvents")),
0045       subSampleFirstEvent_(iConfig.getParameter<uint32_t>("SubSampleFirstEvent")),
0046       subSampleMaxEvents_(iConfig.getParameter<uint32_t>("SubSampleMaxEvents")) {}
0047 
0048 TreeSplitter::~TreeSplitter() {}
0049 
0050 void TreeSplitter::endJob() {
0051   std::cout << "Reading muon pairs from Root Tree in " << treeFileName_ << std::endl;
0052   RootTreeHandler rootTreeHandler;
0053 
0054   typedef std::vector<std::pair<lorentzVector, lorentzVector> > MuonPairVector;
0055   // MuonPairVector savedPair;
0056   std::vector<MuonPair> savedPair;
0057   rootTreeHandler.readTree(maxEvents_, treeFileName_, &savedPair, 0);
0058   // rootTreeHandler.readTree(maxEvents, inputRootTreeFileName_, &savedPair, &(MuScleFitUtils::genPair));
0059 
0060   // Loop on all the pairs
0061   std::vector<MuonPair> newSavedPair;
0062   // MuonPairVector newSavedPair;
0063   unsigned int i = 0;
0064   // MuonPairVector::iterator it = savedPair.begin();
0065   std::vector<MuonPair>::iterator it = savedPair.begin();
0066   std::cout << "Starting loop on " << savedPair.size() << " muons" << std::endl;
0067   uint32_t lastEvent = subSampleFirstEvent_ + subSampleMaxEvents_;
0068   for (; it != savedPair.end(); ++it, ++i) {
0069     // Save only events in the selected range
0070     if (i >= subSampleFirstEvent_ && i < lastEvent) {
0071       newSavedPair.push_back(*it);
0072     }
0073   }
0074   rootTreeHandler.writeTree(outputFileName_, &newSavedPair, 0);
0075 }
0076 
0077 //define this as a plug-in
0078 DEFINE_FWK_MODULE(TreeSplitter);