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 "DataFormats/MuonReco/interface/Muon.h"
0016 #include "DataFormats/PatCandidates/interface/Muon.h"
0017 #include "PhysicsTools/FWLite/interface/TFileService.h"
0018
0019 int main(int argc, char* argv[]) {
0020
0021
0022 using reco::Muon;
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 gSystem->Load("libFWCoreFWLite");
0034 FWLiteEnabler::enable();
0035
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 const edm::ParameterSet& ana = process.getParameter<edm::ParameterSet>("muonAnalyzer");
0053 edm::InputTag muons_(ana.getParameter<edm::InputTag>("muons"));
0054
0055
0056 fwlite::TFileService fs = fwlite::TFileService(outputHandler_.file());
0057 TFileDirectory dir = fs.mkdir("analyzeBasicPat");
0058 TH1F* muonPt_ = dir.make<TH1F>("muonPt", "pt", 100, 0., 300.);
0059 TH1F* muonEta_ = dir.make<TH1F>("muonEta", "eta", 100, -3., 3.);
0060 TH1F* muonPhi_ = dir.make<TH1F>("muonPhi", "phi", 100, -5., 5.);
0061 TH1F* mumuMass_ = dir.make<TH1F>("mumuMass", "mass", 90, 30., 120.);
0062
0063
0064 int ievt = 0;
0065 int maxEvents_(inputHandler_.maxEvents());
0066 for (unsigned int iFile = 0; iFile < inputHandler_.files().size(); ++iFile) {
0067
0068 TFile* inFile = TFile::Open(inputHandler_.files()[iFile].c_str());
0069 if (inFile) {
0070
0071
0072
0073
0074
0075
0076
0077
0078 fwlite::Event ev(inFile);
0079 for (ev.toBegin(); !ev.atEnd(); ++ev, ++ievt) {
0080 edm::EventBase const& event = ev;
0081
0082 if (maxEvents_ > 0 ? ievt + 1 > maxEvents_ : false)
0083 break;
0084
0085 if (inputHandler_.reportAfter() != 0 ? (ievt > 0 && ievt % inputHandler_.reportAfter() == 0) : false)
0086 std::cout << " processing event: " << ievt << std::endl;
0087
0088
0089 edm::Handle<std::vector<Muon> > muons;
0090 event.getByLabel(muons_, muons);
0091
0092
0093 for (std::vector<Muon>::const_iterator mu1 = muons->begin(); mu1 != muons->end(); ++mu1) {
0094 muonPt_->Fill(mu1->pt());
0095 muonEta_->Fill(mu1->eta());
0096 muonPhi_->Fill(mu1->phi());
0097 if (mu1->pt() > 20 && fabs(mu1->eta()) < 2.1) {
0098 for (std::vector<Muon>::const_iterator mu2 = muons->begin(); mu2 != muons->end(); ++mu2) {
0099 if (mu2 > mu1) {
0100 if (mu1->charge() * mu2->charge() < 0) {
0101 if (mu2->pt() > 20 && fabs(mu2->eta()) < 2.1) {
0102 mumuMass_->Fill((mu1->p4() + mu2->p4()).mass());
0103 }
0104 }
0105 }
0106 }
0107 }
0108 }
0109 }
0110
0111 inFile->Close();
0112 }
0113
0114
0115 if (maxEvents_ > 0 ? ievt + 1 > maxEvents_ : false)
0116 break;
0117 }
0118 return 0;
0119 }