File indexing completed on 2023-03-17 11:28:41
0001
0002
0003
0004 #include "DQMServices/Core/interface/DQMStore.h"
0005 #include "DataFormats/Common/interface/Handle.h"
0006 #include "DataFormats/Common/interface/RefToBase.h"
0007 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0008 #include "DataFormats/METReco/interface/CaloMET.h"
0009 #include "DataFormats/METReco/interface/CaloMETCollection.h"
0010 #include "DataFormats/METReco/interface/GenMET.h"
0011 #include "DataFormats/METReco/interface/GenMETCollection.h"
0012 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0013 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0014 #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
0015 #include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
0016 #include "DataFormats/ParticleFlowReco/interface/PFRecTrack.h"
0017 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0018 #include "FWCore/Framework/interface/ESHandle.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 #include "FWCore/ServiceRegistry/interface/Service.h"
0023
0024 #include <algorithm>
0025 #include <cmath>
0026 #include <fstream>
0027 #include <iostream>
0028 #include <map>
0029 #include <memory>
0030 #include <ostream>
0031 #include <string>
0032 #include <vector>
0033
0034 class PFTester : public edm::one::EDAnalyzer<> {
0035 public:
0036 typedef dqm::legacy::DQMStore DQMStore;
0037 typedef dqm::legacy::MonitorElement MonitorElement;
0038
0039 explicit PFTester(const edm::ParameterSet &);
0040 ~PFTester() override;
0041
0042 void analyze(const edm::Event &, const edm::EventSetup &) override;
0043 void beginJob() override;
0044 void endJob() override;
0045
0046 private:
0047
0048 DQMStore *dbe_;
0049 std::map<std::string, MonitorElement *> me;
0050
0051
0052 std::string outputFile_;
0053 edm::EDGetTokenT<reco::PFCandidateCollection> inputPFlowLabel_tok_;
0054 };
0055
0056 #include "FWCore/Framework/interface/MakerMacros.h"
0057 DEFINE_FWK_MODULE(PFTester);
0058
0059 using namespace edm;
0060 using namespace std;
0061 using namespace reco;
0062
0063 PFTester::PFTester(const edm::ParameterSet &iConfig) {
0064 inputPFlowLabel_tok_ = consumes<reco::PFCandidateCollection>(iConfig.getParameter<std::string>("InputPFlowLabel"));
0065 outputFile_ = iConfig.getUntrackedParameter<std::string>("OutputFile");
0066
0067 if (!outputFile_.empty())
0068 edm::LogInfo("OutputInfo") << " ParticleFLow Task histograms will be saved to '" << outputFile_.c_str() << "'";
0069 else
0070 edm::LogInfo("OutputInfo") << " ParticleFlow Task histograms will NOT be saved";
0071 }
0072
0073 PFTester::~PFTester() {}
0074
0075 void PFTester::beginJob() {
0076
0077 dbe_ = edm::Service<DQMStore>().operator->();
0078
0079 if (dbe_) {
0080 dbe_->setCurrentFolder("PFTask/PFCandidates");
0081
0082 me["CandidateEt"] = dbe_->book1D("CandidateEt", "CandidateEt", 1000, 0, 1000);
0083 me["CandidateEta"] = dbe_->book1D("CandidateEta", "CandidateEta", 200, -5, 5);
0084 me["CandidatePhi"] = dbe_->book1D("CandidatePhi", "CandidatePhi", 200, -M_PI, M_PI);
0085 me["CandidateCharge"] = dbe_->book1D("CandidateCharge", "CandidateCharge", 5, -2, 2);
0086 me["PFCandidateType"] = dbe_->book1D("PFCandidateType", "PFCandidateType", 10, 0, 10);
0087
0088 dbe_->setCurrentFolder("PFTask/PFBlocks");
0089
0090 me["NumElements"] = dbe_->book1D("NumElements", "NumElements", 25, 0, 25);
0091 me["NumTrackElements"] = dbe_->book1D("NumTrackElements", "NumTrackElements", 5, 0, 5);
0092 me["NumPS1Elements"] = dbe_->book1D("NumPS1Elements", "NumPS1Elements", 5, 0, 5);
0093 me["NumPS2Elements"] = dbe_->book1D("NumPS2Elements", "NumPS2Elements", 5, 0, 5);
0094 me["NumECALElements"] = dbe_->book1D("NumECALElements", "NumECALElements", 5, 0, 5);
0095 me["NumHCALElements"] = dbe_->book1D("NumHCALElements", "NumHCALElements", 5, 0, 5);
0096 me["NumMuonElements"] = dbe_->book1D("NumMuonElements", "NumMuonElements", 5, 0, 5);
0097
0098 dbe_->setCurrentFolder("PFTask/PFTracks");
0099
0100 me["TrackCharge"] = dbe_->book1D("TrackCharge", "TrackCharge", 5, -2, 2);
0101 me["TrackNumPoints"] = dbe_->book1D("TrackNumPoints", "TrackNumPoints", 100, 0, 100);
0102 me["TrackNumMeasurements"] = dbe_->book1D("TrackNumMeasurements", "TrackNumMeasurements", 100, 0, 100);
0103 me["TrackImpactParameter"] = dbe_->book1D("TrackImpactParameter", "TrackImpactParameter", 1000, 0, 1);
0104
0105 dbe_->setCurrentFolder("PFTask/PFClusters");
0106 }
0107 }
0108
0109 void PFTester::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0110
0111 const PFCandidateCollection *pflow_candidates;
0112
0113
0114
0115
0116
0117 {
0118
0119 Handle<PFCandidateCollection> pflow_hnd;
0120 iEvent.getByToken(inputPFlowLabel_tok_, pflow_hnd);
0121 pflow_candidates = pflow_hnd.product();
0122 }
0123
0124 if (!pflow_candidates) {
0125 edm::LogInfo("OutputInfo") << " failed to retrieve data required by ParticleFlow Task";
0126 edm::LogInfo("OutputInfo") << " ParticleFlow Task cannot continue...!";
0127 return;
0128 }
0129
0130
0131
0132
0133
0134
0135 PFCandidateCollection::const_iterator pf;
0136 for (pf = pflow_candidates->begin(); pf != pflow_candidates->end(); pf++) {
0137 const PFCandidate *particle = &(*pf);
0138
0139
0140 me["CandidateEt"]->Fill(particle->et());
0141 me["CandidateEta"]->Fill(particle->eta());
0142 me["CandidatePhi"]->Fill(particle->phi());
0143 me["CandidateCharge"]->Fill(particle->charge());
0144 me["CandidatePdgId"]->Fill(particle->pdgId());
0145
0146
0147 me["PFCandidateType"]->Fill(particle->particleId());
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215 }
0216 }
0217
0218 void PFTester::endJob() {
0219
0220 if (!outputFile_.empty() && dbe_)
0221 dbe_->save(outputFile_);
0222 }