00001 #include "Validation/RecoParticleFlow/interface/PFTester.h"
00002
00003
00004
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "FWCore/ServiceRegistry/interface/Service.h"
00007
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "DataFormats/Common/interface/Handle.h"
00010 #include "FWCore/Framework/interface/ESHandle.h"
00011
00012
00013 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00014 #include "DataFormats/METReco/interface/GenMET.h"
00015 #include "DataFormats/METReco/interface/GenMETCollection.h"
00016 #include "DataFormats/METReco/interface/CaloMET.h"
00017 #include "DataFormats/METReco/interface/CaloMETCollection.h"
00018
00019 #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
00020 #include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
00021 #include "DataFormats/ParticleFlowReco/interface/PFRecTrack.h"
00022 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00023 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00024 #include "DataFormats/Common/interface/RefToBase.h"
00025
00026 #include <vector>
00027 #include <ostream>
00028 #include <fstream>
00029 #include <iostream>
00030 #include <algorithm>
00031 #include <cmath>
00032 #include <memory>
00033
00034 using namespace edm;
00035 using namespace std;
00036 using namespace reco;
00037
00038
00039 PFTester::PFTester(const edm::ParameterSet& iConfig)
00040 {
00041
00042 inputPFlowLabel_ = iConfig.getParameter<std::string>("InputPFlowLabel");
00043 outputFile_ = iConfig.getUntrackedParameter<std::string>("OutputFile");
00044
00045 if (outputFile_.size() > 0)
00046 edm::LogInfo("OutputInfo") << " ParticleFLow Task histograms will be saved to '" << outputFile_.c_str() << "'";
00047 else edm::LogInfo("OutputInfo") << " ParticleFlow Task histograms will NOT be saved";
00048
00049 }
00050
00051 PFTester::~PFTester() { }
00052
00053 void PFTester::beginJob(const edm::EventSetup& iSetup)
00054 {
00055
00056
00057 dbe_ = edm::Service<DQMStore>().operator->();
00058
00059 if (dbe_) {
00060
00061 dbe_->setCurrentFolder("PFTask/PFCandidates");
00062
00063 me["CandidateEt"] = dbe_->book1D("CandidateEt","CandidateEt",1000,0,1000);
00064 me["CandidateEta"] = dbe_->book1D("CandidateEta","CandidateEta",200,-5,5);
00065 me["CandidatePhi"] = dbe_->book1D("CandidatePhi","CandidatePhi",200,-M_PI,M_PI);
00066 me["CandidateCharge"] = dbe_->book1D("CandidateCharge","CandidateCharge",5,-2,2);
00067 me["PFCandidateType"] = dbe_->book1D("PFCandidateType","PFCandidateType",10,0,10);
00068
00069 dbe_->setCurrentFolder("PFTask/PFBlocks");
00070
00071 me["NumElements"] = dbe_->book1D("NumElements","NumElements",25,0,25);
00072 me["NumTrackElements"] = dbe_->book1D("NumTrackElements","NumTrackElements",5,0,5);
00073 me["NumPS1Elements"] = dbe_->book1D("NumPS1Elements","NumPS1Elements",5,0,5);
00074 me["NumPS2Elements"] = dbe_->book1D("NumPS2Elements","NumPS2Elements",5,0,5);
00075 me["NumECALElements"] = dbe_->book1D("NumECALElements","NumECALElements",5,0,5);
00076 me["NumHCALElements"] = dbe_->book1D("NumHCALElements","NumHCALElements",5,0,5);
00077 me["NumMuonElements"] = dbe_->book1D("NumMuonElements","NumMuonElements",5,0,5);
00078
00079 dbe_->setCurrentFolder("PFTask/PFTracks");
00080
00081 me["TrackCharge"] = dbe_->book1D("TrackCharge","TrackCharge",5,-2,2);
00082 me["TrackNumPoints"] = dbe_->book1D("TrackNumPoints","TrackNumPoints",100,0,100);
00083 me["TrackNumMeasurements"] = dbe_->book1D("TrackNumMeasurements","TrackNumMeasurements",100,0,100);
00084 me["TrackImpactParameter"] = dbe_->book1D("TrackImpactParameter","TrackImpactParameter",1000,0,1);
00085
00086 dbe_->setCurrentFolder("PFTask/PFClusters");
00087
00088 }
00089
00090 }
00091
00092 void PFTester::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00093 {
00094
00095
00096 const PFCandidateCollection *pflow_candidates;
00097
00098
00099
00100
00101
00102 {
00103
00104
00105 Handle<PFCandidateCollection> pflow_hnd;
00106 iEvent.getByLabel(inputPFlowLabel_, pflow_hnd);
00107 pflow_candidates = pflow_hnd.product();
00108
00109 }
00110
00111 if (!pflow_candidates) {
00112
00113 edm::LogInfo("OutputInfo") << " failed to retrieve data required by ParticleFlow Task";
00114 edm::LogInfo("OutputInfo") << " ParticleFlow Task cannot continue...!";
00115 return;
00116
00117 }
00118
00119
00120
00121
00122
00123
00124 PFCandidateCollection::const_iterator pf;
00125 for (pf = pflow_candidates->begin(); pf != pflow_candidates->end(); pf++) {
00126
00127 const PFCandidate *particle = &(*pf);
00128
00129
00130 me["CandidateEt"]->Fill(particle->et());
00131 me["CandidateEta"]->Fill(particle->eta());
00132 me["CandidatePhi"]->Fill(particle->phi());
00133 me["CandidateCharge"]->Fill(particle->charge());
00134 me["CandidatePdgId"]->Fill(particle->pdgId());
00135
00136
00137 me["PFCandidateType"]->Fill(particle->particleId());
00138
00139
00140
00141
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 void PFTester::endJob()
00211 {
00212
00213
00214 if (outputFile_.size() > 0 && dbe_)
00215 dbe_->save(outputFile_);
00216
00217 }