CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
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 }
T getUntrackedParameter(std::string const &, T const &) const
dqm::legacy::MonitorElement MonitorElement
Definition: PFTester.cc:37
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: PFTester.cc:109
void endJob() override
Definition: PFTester.cc:218
std::map< std::string, MonitorElement * > me
Definition: PFTester.cc:49
int pdgId() const final
PDG identifier.
int iEvent
Definition: GenABIO.cc:224
#define M_PI
Log< level::Info, false > LogInfo
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
T const * product() const
Definition: Handle.h:70
dqm::legacy::DQMStore DQMStore
Definition: PFTester.cc:36
void beginJob() override
Definition: PFTester.cc:75
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< reco::PFCandidateCollection > inputPFlowLabel_tok_
Definition: PFTester.cc:53
std::string outputFile_
Definition: PFTester.cc:52
~PFTester() override
Definition: PFTester.cc:73
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
double et() const final
transverse energy
virtual ParticleType particleId() const
Definition: PFCandidate.h:392
double phi() const final
momentum azimuthal angle
PFTester(const edm::ParameterSet &)
Definition: PFTester.cc:63
int charge() const final
electric charge
DQMStore * dbe_
Definition: PFTester.cc:48
double eta() const final
momentum pseudorapidity