CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/MuonAnalysis/MomentumScaleCalibration/plugins/TreeSplitter.cc

Go to the documentation of this file.
00001 #ifndef TREESPLITTER_CC
00002 #define TREESPLITTER_CC
00003 
00004 #include "TreeSplitter.h"
00005 
00006 TreeSplitter::TreeSplitter(const edm::ParameterSet& iConfig) :
00007   treeFileName_( iConfig.getParameter<std::string>("InputFileName") ),
00008   outputFileName_( iConfig.getParameter<std::string>("OutputFileName") ),
00009   maxEvents_( iConfig.getParameter<int32_t>("MaxEvents") ),
00010   subSampleFirstEvent_( iConfig.getParameter<uint32_t>("SubSampleFirstEvent") ),
00011   subSampleMaxEvents_( iConfig.getParameter<uint32_t>("SubSampleMaxEvents") )
00012 {
00013 }
00014 
00015 TreeSplitter::~TreeSplitter()
00016 {
00017 }
00018 
00019 void TreeSplitter::endJob()
00020 {
00021   std::cout << "Reading muon pairs from Root Tree in " << treeFileName_ << std::endl;
00022   RootTreeHandler rootTreeHandler;
00023 
00024   typedef std::vector<std::pair<lorentzVector,lorentzVector> > MuonPairVector;
00025   // MuonPairVector savedPair;
00026   std::vector<MuonPair> savedPair;
00027   rootTreeHandler.readTree(maxEvents_, treeFileName_, &savedPair, 0);
00028   // rootTreeHandler.readTree(maxEvents, inputRootTreeFileName_, &savedPair, &(MuScleFitUtils::genPair));
00029 
00030   // Loop on all the pairs
00031   std::vector<MuonPair> newSavedPair;
00032   // MuonPairVector newSavedPair;
00033   unsigned int i = 0;
00034   // MuonPairVector::iterator it = savedPair.begin();
00035   std::vector<MuonPair>::iterator it = savedPair.begin();
00036   std::cout << "Starting loop on " << savedPair.size() << " muons" << std::endl;
00037   uint32_t lastEvent = subSampleFirstEvent_ + subSampleMaxEvents_;
00038   for( ; it != savedPair.end(); ++it, ++i ) {
00039     // Save only events in the selected range
00040     if( i >= subSampleFirstEvent_ && i < lastEvent ) {
00041       newSavedPair.push_back(*it);
00042     }
00043   }
00044   rootTreeHandler.writeTree(outputFileName_, &newSavedPair, 0);
00045 }
00046 
00047 //define this as a plug-in
00048 DEFINE_FWK_MODULE(TreeSplitter);
00049 
00050 #endif