File indexing completed on 2024-04-06 12:23:22
0001 #include <TH1F.h>
0002 #include <TROOT.h>
0003 #include <TFile.h>
0004 #include <TSystem.h>
0005
0006 #include "DataFormats/FWLite/interface/Event.h"
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "FWCore/FWLite/interface/FWLiteEnabler.h"
0009
0010 #include "DataFormats/FWLite/interface/InputSource.h"
0011 #include "DataFormats/FWLite/interface/OutputFiles.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/ParameterSetReader/interface/ParameterSetReader.h"
0014
0015 #include "TStopwatch.h"
0016 #include "PhysicsTools/FWLite/interface/WSelector.h"
0017 #include "PhysicsTools/FWLite/interface/TFileService.h"
0018
0019
0020 int main(int argc, char* argv[]) {
0021
0022
0023 using reco::Muon;
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 gSystem->Load("libFWCoreFWLite");
0035 FWLiteEnabler::enable();
0036
0037 if (argc < 2) {
0038 std::cout << "Usage : " << argv[0] << " [parameters.py]" << std::endl;
0039 return 0;
0040 }
0041
0042 if (!edm::readPSetsFrom(argv[1])->existsAs<edm::ParameterSet>("process")) {
0043 std::cout << " ERROR: ParametersSet 'process' is missing in your configuration file" << std::endl;
0044 exit(0);
0045 }
0046
0047 const edm::ParameterSet& process = edm::readPSetsFrom(argv[1])->getParameter<edm::ParameterSet>("process");
0048 fwlite::InputSource inputHandler_(process);
0049 fwlite::OutputFiles outputHandler_(process);
0050
0051
0052 edm::ParameterSet selection = process.getParameter<edm::ParameterSet>("selection");
0053 WSelector wSelector(selection);
0054 pat::strbitset wSelectorReturns = wSelector.getBitTemplate();
0055
0056
0057 fwlite::TFileService fs = fwlite::TFileService(outputHandler_.file());
0058 TFileDirectory theDir = fs.mkdir("analyzeBasicPat");
0059 TH1F* muonPt_ = theDir.make<TH1F>("muonPt", "pt", 100, 0., 300.);
0060 TH1F* muonEta_ = theDir.make<TH1F>("muonEta", "eta", 100, -3., 3.);
0061 TH1F* muonPhi_ = theDir.make<TH1F>("muonPhi", "phi", 100, -5., 5.);
0062
0063
0064 TStopwatch timer;
0065 timer.Start();
0066
0067
0068 int ievt = 0;
0069 unsigned int nEventsAnalyzed = 0;
0070 int maxEvents_(inputHandler_.maxEvents());
0071 for (unsigned int iFile = 0; iFile < inputHandler_.files().size(); ++iFile) {
0072
0073 TFile* inFile = TFile::Open(inputHandler_.files()[iFile].c_str());
0074 if (inFile) {
0075
0076
0077
0078
0079
0080
0081
0082
0083 fwlite::Event ev(inFile);
0084 for (ev.toBegin(); !ev.atEnd(); ++ev, ++ievt) {
0085 edm::EventBase const& event = ev;
0086
0087 if (maxEvents_ > 0 ? ievt + 1 > maxEvents_ : false)
0088 break;
0089
0090 if (inputHandler_.reportAfter() != 0 ? (ievt > 0 && ievt % inputHandler_.reportAfter() == 0) : false)
0091 std::cout << " processing event: " << ievt << std::endl;
0092
0093 if (wSelector(event, wSelectorReturns)) {
0094 pat::Muon const& wMuon = wSelector.wMuon();
0095 muonPt_->Fill(wMuon.pt());
0096 muonEta_->Fill(wMuon.eta());
0097 muonPhi_->Fill(wMuon.phi());
0098 }
0099 ++nEventsAnalyzed;
0100 }
0101
0102 inFile->Close();
0103 }
0104
0105
0106 if (maxEvents_ > 0 ? ievt + 1 > maxEvents_ : false)
0107 break;
0108 }
0109
0110 timer.Stop();
0111
0112
0113 wSelector.print(std::cout);
0114
0115
0116 double rtime = timer.RealTime();
0117 double ctime = timer.CpuTime();
0118
0119 printf("Analyzed events: %d \n", nEventsAnalyzed);
0120 printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime);
0121 printf("%4.2f events / RealTime second .\n", (double)nEventsAnalyzed / rtime);
0122 printf("%4.2f events / CpuTime second .\n", (double)nEventsAnalyzed / ctime);
0123 return 0;
0124 }