00001 #include "Validation/RecoParticleFlow/plugins/PFTester.h"
00002
00003
00004
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008
00009 #include "FWCore/Framework/interface/Event.h"
00010 #include "DataFormats/Common/interface/Handle.h"
00011 #include "FWCore/Framework/interface/ESHandle.h"
00012
00013
00014 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00015 #include "DataFormats/METReco/interface/GenMET.h"
00016 #include "DataFormats/METReco/interface/GenMETCollection.h"
00017 #include "DataFormats/METReco/interface/CaloMET.h"
00018 #include "DataFormats/METReco/interface/CaloMETCollection.h"
00019
00020 #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
00021 #include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
00022 #include "DataFormats/ParticleFlowReco/interface/PFRecTrack.h"
00023 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00024 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00025 #include "DataFormats/Common/interface/RefToBase.h"
00026
00027 #include <vector>
00028 #include <ostream>
00029 #include <fstream>
00030 #include <iostream>
00031 #include <algorithm>
00032 #include <cmath>
00033 #include <memory>
00034
00035 using namespace edm;
00036 using namespace std;
00037 using namespace reco;
00038
00039
00040 PFTester::PFTester(const edm::ParameterSet& iConfig)
00041 {
00042
00043 inputPFlowLabel_ = iConfig.getParameter<std::string>("InputPFlowLabel");
00044 outputFile_ = iConfig.getUntrackedParameter<std::string>("OutputFile");
00045
00046 if (outputFile_.size() > 0)
00047 edm::LogInfo("OutputInfo") << " ParticleFLow Task histograms will be saved to '" << outputFile_.c_str() << "'";
00048 else edm::LogInfo("OutputInfo") << " ParticleFlow Task histograms will NOT be saved";
00049
00050 }
00051
00052 PFTester::~PFTester() { }
00053
00054 void
00055 PFTester::beginJob()
00056 {
00057
00058
00059 dbe_ = edm::Service<DQMStore>().operator->();
00060
00061 if (dbe_) {
00062
00063 dbe_->setCurrentFolder("PFTask/PFCandidates");
00064
00065 me["CandidateEt"] = dbe_->book1D("CandidateEt","CandidateEt",1000,0,1000);
00066 me["CandidateEta"] = dbe_->book1D("CandidateEta","CandidateEta",200,-5,5);
00067 me["CandidatePhi"] = dbe_->book1D("CandidatePhi","CandidatePhi",200,-M_PI,M_PI);
00068 me["CandidateCharge"] = dbe_->book1D("CandidateCharge","CandidateCharge",5,-2,2);
00069 me["PFCandidateType"] = dbe_->book1D("PFCandidateType","PFCandidateType",10,0,10);
00070
00071 dbe_->setCurrentFolder("PFTask/PFBlocks");
00072
00073 me["NumElements"] = dbe_->book1D("NumElements","NumElements",25,0,25);
00074 me["NumTrackElements"] = dbe_->book1D("NumTrackElements","NumTrackElements",5,0,5);
00075 me["NumPS1Elements"] = dbe_->book1D("NumPS1Elements","NumPS1Elements",5,0,5);
00076 me["NumPS2Elements"] = dbe_->book1D("NumPS2Elements","NumPS2Elements",5,0,5);
00077 me["NumECALElements"] = dbe_->book1D("NumECALElements","NumECALElements",5,0,5);
00078 me["NumHCALElements"] = dbe_->book1D("NumHCALElements","NumHCALElements",5,0,5);
00079 me["NumMuonElements"] = dbe_->book1D("NumMuonElements","NumMuonElements",5,0,5);
00080
00081 dbe_->setCurrentFolder("PFTask/PFTracks");
00082
00083 me["TrackCharge"] = dbe_->book1D("TrackCharge","TrackCharge",5,-2,2);
00084 me["TrackNumPoints"] = dbe_->book1D("TrackNumPoints","TrackNumPoints",100,0,100);
00085 me["TrackNumMeasurements"] = dbe_->book1D("TrackNumMeasurements","TrackNumMeasurements",100,0,100);
00086 me["TrackImpactParameter"] = dbe_->book1D("TrackImpactParameter","TrackImpactParameter",1000,0,1);
00087
00088 dbe_->setCurrentFolder("PFTask/PFClusters");
00089
00090 }
00091
00092 }
00093
00094 void
00095 PFTester::analyze(const edm::Event& iEvent,
00096 const edm::EventSetup& iSetup)
00097 {
00098
00099
00100 const PFCandidateCollection *pflow_candidates;
00101
00102
00103
00104
00105
00106 {
00107
00108
00109 Handle<PFCandidateCollection> pflow_hnd;
00110 iEvent.getByLabel(inputPFlowLabel_, pflow_hnd);
00111 pflow_candidates = pflow_hnd.product();
00112
00113 }
00114
00115 if (!pflow_candidates) {
00116
00117 edm::LogInfo("OutputInfo") << " failed to retrieve data required by ParticleFlow Task";
00118 edm::LogInfo("OutputInfo") << " ParticleFlow Task cannot continue...!";
00119 return;
00120
00121 }
00122
00123
00124
00125
00126
00127
00128 PFCandidateCollection::const_iterator pf;
00129 for (pf = pflow_candidates->begin(); pf != pflow_candidates->end(); pf++) {
00130
00131 const PFCandidate *particle = &(*pf);
00132
00133
00134 me["CandidateEt"]->Fill(particle->et());
00135 me["CandidateEta"]->Fill(particle->eta());
00136 me["CandidatePhi"]->Fill(particle->phi());
00137 me["CandidateCharge"]->Fill(particle->charge());
00138 me["CandidatePdgId"]->Fill(particle->pdgId());
00139
00140
00141 me["PFCandidateType"]->Fill(particle->particleId());
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 }
00211
00212 }
00213
00214 void PFTester::endJob()
00215 {
00216
00217
00218 if (outputFile_.size() > 0 && dbe_)
00219 dbe_->save(outputFile_);
00220
00221 }