CMS 3D CMS Logo

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