File indexing completed on 2024-09-07 04:37:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
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
0056 std::vector<MuonPair> savedPair;
0057 rootTreeHandler.readTree(maxEvents_, treeFileName_, &savedPair, 0);
0058
0059
0060
0061 std::vector<MuonPair> newSavedPair;
0062
0063 unsigned int i = 0;
0064
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
0070 if (i >= subSampleFirstEvent_ && i < lastEvent) {
0071 newSavedPair.push_back(*it);
0072 }
0073 }
0074 rootTreeHandler.writeTree(outputFileName_, &newSavedPair, 0);
0075 }
0076
0077
0078 DEFINE_FWK_MODULE(TreeSplitter);