CMS 3D CMS Logo

PFTester.cc
Go to the documentation of this file.
1 // author: Mike Schmitt, University of Florida
2 // first version 11/7/2007
3 
23 
24 #include <algorithm>
25 #include <cmath>
26 #include <fstream>
27 #include <iostream>
28 #include <map>
29 #include <memory>
30 #include <ostream>
31 #include <string>
32 #include <vector>
33 
34 class PFTester : public edm::EDAnalyzer {
35 public:
38 
39  explicit PFTester(const edm::ParameterSet &);
40  ~PFTester() override;
41 
42  void analyze(const edm::Event &, const edm::EventSetup &) override;
43  void beginJob() override;
44  void endJob() override;
45 
46 private:
47  // DAQ Tools
49  std::map<std::string, MonitorElement *> me;
50 
51  // Inputs from Configuration File
54 };
55 
58 
59 using namespace edm;
60 using namespace std;
61 using namespace reco;
62 
64  inputPFlowLabel_tok_ = consumes<reco::PFCandidateCollection>(iConfig.getParameter<std::string>("InputPFlowLabel"));
65  outputFile_ = iConfig.getUntrackedParameter<std::string>("OutputFile");
66 
67  if (!outputFile_.empty())
68  edm::LogInfo("OutputInfo") << " ParticleFLow Task histograms will be saved to '" << outputFile_.c_str() << "'";
69  else
70  edm::LogInfo("OutputInfo") << " ParticleFlow Task histograms will NOT be saved";
71 }
72 
74 
76  // get ahold of back-end interface
77  dbe_ = edm::Service<DQMStore>().operator->();
78 
79  if (dbe_) {
80  dbe_->setCurrentFolder("PFTask/PFCandidates");
81 
82  me["CandidateEt"] = dbe_->book1D("CandidateEt", "CandidateEt", 1000, 0, 1000);
83  me["CandidateEta"] = dbe_->book1D("CandidateEta", "CandidateEta", 200, -5, 5);
84  me["CandidatePhi"] = dbe_->book1D("CandidatePhi", "CandidatePhi", 200, -M_PI, M_PI);
85  me["CandidateCharge"] = dbe_->book1D("CandidateCharge", "CandidateCharge", 5, -2, 2);
86  me["PFCandidateType"] = dbe_->book1D("PFCandidateType", "PFCandidateType", 10, 0, 10);
87 
88  dbe_->setCurrentFolder("PFTask/PFBlocks");
89 
90  me["NumElements"] = dbe_->book1D("NumElements", "NumElements", 25, 0, 25);
91  me["NumTrackElements"] = dbe_->book1D("NumTrackElements", "NumTrackElements", 5, 0, 5);
92  me["NumPS1Elements"] = dbe_->book1D("NumPS1Elements", "NumPS1Elements", 5, 0, 5);
93  me["NumPS2Elements"] = dbe_->book1D("NumPS2Elements", "NumPS2Elements", 5, 0, 5);
94  me["NumECALElements"] = dbe_->book1D("NumECALElements", "NumECALElements", 5, 0, 5);
95  me["NumHCALElements"] = dbe_->book1D("NumHCALElements", "NumHCALElements", 5, 0, 5);
96  me["NumMuonElements"] = dbe_->book1D("NumMuonElements", "NumMuonElements", 5, 0, 5);
97 
98  dbe_->setCurrentFolder("PFTask/PFTracks");
99 
100  me["TrackCharge"] = dbe_->book1D("TrackCharge", "TrackCharge", 5, -2, 2);
101  me["TrackNumPoints"] = dbe_->book1D("TrackNumPoints", "TrackNumPoints", 100, 0, 100);
102  me["TrackNumMeasurements"] = dbe_->book1D("TrackNumMeasurements", "TrackNumMeasurements", 100, 0, 100);
103  me["TrackImpactParameter"] = dbe_->book1D("TrackImpactParameter", "TrackImpactParameter", 1000, 0, 1);
104 
105  dbe_->setCurrentFolder("PFTask/PFClusters");
106  }
107 }
108 
109 void PFTester::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
110  // Data to Retrieve from the Event
111  const PFCandidateCollection *pflow_candidates;
112 
113  // ==========================================================
114  // Retrieve!
115  // ==========================================================
116 
117  {
118  // Get Particle Flow Candidates
120  iEvent.getByToken(inputPFlowLabel_tok_, pflow_hnd);
121  pflow_candidates = pflow_hnd.product();
122  }
123 
124  if (!pflow_candidates) {
125  edm::LogInfo("OutputInfo") << " failed to retrieve data required by ParticleFlow Task";
126  edm::LogInfo("OutputInfo") << " ParticleFlow Task cannot continue...!";
127  return;
128  }
129 
130  // ==========================================================
131  // Analyze!
132  // ==========================================================
133 
134  // Loop Over Particle Flow Candidates
135  PFCandidateCollection::const_iterator pf;
136  for (pf = pflow_candidates->begin(); pf != pflow_candidates->end(); pf++) {
137  const PFCandidate *particle = &(*pf);
138 
139  // Fill Histograms for Candidate Methods
140  me["CandidateEt"]->Fill(particle->et());
141  me["CandidateEta"]->Fill(particle->eta());
142  me["CandidatePhi"]->Fill(particle->phi());
143  me["CandidateCharge"]->Fill(particle->charge());
144  me["CandidatePdgId"]->Fill(particle->pdgId());
145 
146  // Fill Histograms for PFCandidate Specific Methods
147  me["PFCandidateType"]->Fill(particle->particleId());
148  // particle->elementsInBlocks();
149 
150  // Get the PFBlock and Elements
151  // JW: Returns vector of blocks now ,TO BE FIXED ----
152  /*PFBlock block = *(particle->block());
153  OwnVector<PFBlockElement> elements = block.elements();
154  int numElements = elements.size();
155  int numTrackElements = 0;
156  int numPS1Elements = 0;
157  int numPS2Elements = 0;
158  int numECALElements = 0;
159  int numHCALElements = 0;
160  int numMuonElements = 0;
161 
162  // Loop over Elements in Block
163  OwnVector<PFBlockElement>::const_iterator element;
164  for (element = elements.begin(); element != elements.end(); element++) {
165 
166  int element_type = element->type();
167  // Element is a Tracker Track
168  if (element_type == PFBlockElement::TRACK) {
169 
170  // Get General Information about the Track
171  PFRecTrack track = *(element->trackRefPF());
172  me["TrackCharge"]->Fill(track.charge());
173  me["TrackNumPoints"]->Fill(track.nTrajectoryPoints());
174  me["TrackNumMeasurements"]->Fill(track.nTrajectoryMeasurements());
175 
176  // Loop Over Points in the Track
177  vector<PFTrajectoryPoint> points = track.trajectoryPoints();
178  vector<PFTrajectoryPoint>::iterator point;
179  for (point = points.begin(); point != points.end(); point++) {
180  int point_layer = point->layer();
181  double x = point->positionXYZ().x();
182  double y = point->positionXYZ().y();
183  double z = point->positionXYZ().z();
184  //switch (point_layer) {
185  //case PFTrajectoryPoint::ClosestApproach:
186  // Fill the Track's D0
187  if (point_layer == PFTrajectoryPoint::ClosestApproach) {
188  me["TrackImpactParameter"]->Fill(sqrt(x*x + y*y + z*z));
189  }
190  }
191  numTrackElements++;
192  }
193 
194  // Element is an ECAL Cluster
195  else if (element_type == PFBlockElement::ECAL) {
196  numECALElements++;
197  }
198  // Element is a HCAL Cluster
199  else if (element_type == PFBlockElement::HCAL) {
200  numHCALElements++;
201  }
202  // Element is a Muon Track
203  else if (element_type == PFBlockElement::MUON) {
204  numMuonElements++;
205  }
206  // Fill the Respective Elements Sizes
207  me["NumElements"]->Fill(numElements);
208  me["NumTrackElements"]->Fill(numTrackElements);
209  me["NumPS1Elements"]->Fill(numPS1Elements);
210  me["NumPS2Elements"]->Fill(numPS2Elements);
211  me["NumECALElements"]->Fill(numECALElements);
212  me["NumHCALElements"]->Fill(numHCALElements);
213  me["NumMuonElements"]->Fill(numMuonElements);
214  } ---------------------------------------------- */
215  }
216 }
217 
219  // Store the DAQ Histograms
220  if (!outputFile_.empty() && dbe_)
221  dbe_->save(outputFile_);
222 }
Handle.h
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ESHandle.h
PFCandidate.h
GenMETCollection.h
edm::EDGetTokenT< reco::PFCandidateCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
DQMStore.h
dqm::legacy::MonitorElement
Definition: MonitorElement.h:462
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
EDAnalyzer.h
PFTester::~PFTester
~PFTester() override
Definition: PFTester.cc:73
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
PFTester::DQMStore
dqm::legacy::DQMStore DQMStore
Definition: PFTester.cc:36
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
CaloMETCollection.h
GenParticle.h
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
dqm::legacy::DQMStore
Definition: DQMStore.h:728
CaloMET.h
Service.h
PFBlockElement.h
dqm::implementation::DQMStore::setCurrentFolder
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:569
dbe_
dqm::legacy::DQMStore * dbe_
Definition: PFJetBenchmarkAnalyzer.cc:77
dqm::implementation::DQMStore::save
DQM_DEPRECATED void save(std::string const &filename, std::string const &path="")
Definition: DQMStore.cc:784
RefToBase.h
PFTester::outputFile_
std::string outputFile_
Definition: PFTester.cc:52
GenMET.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
reco::PFCandidate::particleId
virtual ParticleType particleId() const
Definition: PFCandidate.h:367
PFTester::inputPFlowLabel_tok_
edm::EDGetTokenT< reco::PFCandidateCollection > inputPFlowLabel_tok_
Definition: PFTester.cc:53
reco::LeafCandidate::pdgId
int pdgId() const final
PDG identifier.
Definition: LeafCandidate.h:176
PFTester::me
std::map< std::string, MonitorElement * > me
Definition: PFTester.cc:49
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
PFTester
Definition: PFTester.cc:34
reco::LeafCandidate::charge
int charge() const final
electric charge
Definition: LeafCandidate.h:106
edm::EventSetup
Definition: EventSetup.h:58
PFRecTrack.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PFTester::beginJob
void beginJob() override
Definition: PFTester.cc:75
PFBlock.h
reco::LeafCandidate::et
double et() const final
transverse energy
Definition: LeafCandidate.h:127
PFTester::PFTester
PFTester(const edm::ParameterSet &)
Definition: PFTester.cc:63
std
Definition: JetResolutionObject.h:76
reco::LeafCandidate::phi
double phi() const final
momentum azimuthal angle
Definition: LeafCandidate.h:148
PFTester::dbe_
DQMStore * dbe_
Definition: PFTester.cc:48
packedPFCandidateRefMixer_cfi.pf
pf
Definition: packedPFCandidateRefMixer_cfi.py:4
reco::PFCandidateCollection
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
Definition: PFCandidateFwd.h:12
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
ParameterSet.h
PFTester::endJob
void endJob() override
Definition: PFTester.cc:218
PFTester::MonitorElement
dqm::legacy::MonitorElement MonitorElement
Definition: PFTester.cc:37
hlt_dqm_clientPB-live_cfg.me
me
Definition: hlt_dqm_clientPB-live_cfg.py:61
edm::Event
Definition: Event.h:73
edm::Log
Definition: MessageLogger.h:70
PFCandidateFwd.h
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
PFTester::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: PFTester.cc:109