CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <vector>
28 #include <ostream>
29 #include <fstream>
30 #include <iostream>
31 #include <algorithm>
32 #include <cmath>
33 #include <memory>
34 
35 using namespace edm;
36 using namespace std;
37 using namespace reco;
38 
39 
41 {
42 
43  inputPFlowLabel_ = iConfig.getParameter<std::string>("InputPFlowLabel");
44  outputFile_ = iConfig.getUntrackedParameter<std::string>("OutputFile");
45 
46  if (outputFile_.size() > 0)
47  edm::LogInfo("OutputInfo") << " ParticleFLow Task histograms will be saved to '" << outputFile_.c_str() << "'";
48  else edm::LogInfo("OutputInfo") << " ParticleFlow Task histograms will NOT be saved";
49 
50 }
51 
53 
54 void
56 {
57 
58  // get ahold of back-end interface
60 
61  if (dbe_) {
62 
63  dbe_->setCurrentFolder("PFTask/PFCandidates");
64 
65  me["CandidateEt"] = dbe_->book1D("CandidateEt","CandidateEt",1000,0,1000);
66  me["CandidateEta"] = dbe_->book1D("CandidateEta","CandidateEta",200,-5,5);
67  me["CandidatePhi"] = dbe_->book1D("CandidatePhi","CandidatePhi",200,-M_PI,M_PI);
68  me["CandidateCharge"] = dbe_->book1D("CandidateCharge","CandidateCharge",5,-2,2);
69  me["PFCandidateType"] = dbe_->book1D("PFCandidateType","PFCandidateType",10,0,10);
70 
71  dbe_->setCurrentFolder("PFTask/PFBlocks");
72 
73  me["NumElements"] = dbe_->book1D("NumElements","NumElements",25,0,25);
74  me["NumTrackElements"] = dbe_->book1D("NumTrackElements","NumTrackElements",5,0,5);
75  me["NumPS1Elements"] = dbe_->book1D("NumPS1Elements","NumPS1Elements",5,0,5);
76  me["NumPS2Elements"] = dbe_->book1D("NumPS2Elements","NumPS2Elements",5,0,5);
77  me["NumECALElements"] = dbe_->book1D("NumECALElements","NumECALElements",5,0,5);
78  me["NumHCALElements"] = dbe_->book1D("NumHCALElements","NumHCALElements",5,0,5);
79  me["NumMuonElements"] = dbe_->book1D("NumMuonElements","NumMuonElements",5,0,5);
80 
81  dbe_->setCurrentFolder("PFTask/PFTracks");
82 
83  me["TrackCharge"] = dbe_->book1D("TrackCharge","TrackCharge",5,-2,2);
84  me["TrackNumPoints"] = dbe_->book1D("TrackNumPoints","TrackNumPoints",100,0,100);
85  me["TrackNumMeasurements"] = dbe_->book1D("TrackNumMeasurements","TrackNumMeasurements",100,0,100);
86  me["TrackImpactParameter"] = dbe_->book1D("TrackImpactParameter","TrackImpactParameter",1000,0,1);
87 
88  dbe_->setCurrentFolder("PFTask/PFClusters");
89 
90  }
91 
92 }
93 
94 void
96  const edm::EventSetup& iSetup)
97 {
98 
99  // Data to Retrieve from the Event
100  const PFCandidateCollection *pflow_candidates;
101 
102  // ==========================================================
103  // Retrieve!
104  // ==========================================================
105 
106  {
107 
108  // Get Particle Flow Candidates
110  iEvent.getByLabel(inputPFlowLabel_, pflow_hnd);
111  pflow_candidates = pflow_hnd.product();
112 
113  }
114 
115  if (!pflow_candidates) {
116 
117  edm::LogInfo("OutputInfo") << " failed to retrieve data required by ParticleFlow Task";
118  edm::LogInfo("OutputInfo") << " ParticleFlow Task cannot continue...!";
119  return;
120 
121  }
122 
123  // ==========================================================
124  // Analyze!
125  // ==========================================================
126 
127  // Loop Over Particle Flow Candidates
128  PFCandidateCollection::const_iterator pf;
129  for (pf = pflow_candidates->begin(); pf != pflow_candidates->end(); pf++) {
130 
131  const PFCandidate *particle = &(*pf);
132 
133  // Fill Histograms for Candidate Methods
134  me["CandidateEt"]->Fill(particle->et());
135  me["CandidateEta"]->Fill(particle->eta());
136  me["CandidatePhi"]->Fill(particle->phi());
137  me["CandidateCharge"]->Fill(particle->charge());
138  me["CandidatePdgId"]->Fill(particle->pdgId());
139 
140  // Fill Histograms for PFCandidate Specific Methods
141  me["PFCandidateType"]->Fill(particle->particleId());
142  // particle->elementsInBlocks();
143 
144  // Get the PFBlock and Elements
145  // JW: Returns vector of blocks now ,TO BE FIXED ----
146  /*PFBlock block = *(particle->block());
147  OwnVector<PFBlockElement> elements = block.elements();
148  int numElements = elements.size();
149  int numTrackElements = 0;
150  int numPS1Elements = 0;
151  int numPS2Elements = 0;
152  int numECALElements = 0;
153  int numHCALElements = 0;
154  int numMuonElements = 0;
155 
156  // Loop over Elements in Block
157  OwnVector<PFBlockElement>::const_iterator element;
158  for (element = elements.begin(); element != elements.end(); element++) {
159 
160  int element_type = element->type();
161  // Element is a Tracker Track
162  if (element_type == PFBlockElement::TRACK) {
163 
164  // Get General Information about the Track
165  PFRecTrack track = *(element->trackRefPF());
166  me["TrackCharge"]->Fill(track.charge());
167  me["TrackNumPoints"]->Fill(track.nTrajectoryPoints());
168  me["TrackNumMeasurements"]->Fill(track.nTrajectoryMeasurements());
169 
170  // Loop Over Points in the Track
171  vector<PFTrajectoryPoint> points = track.trajectoryPoints();
172  vector<PFTrajectoryPoint>::iterator point;
173  for (point = points.begin(); point != points.end(); point++) {
174  int point_layer = point->layer();
175  double x = point->positionXYZ().x();
176  double y = point->positionXYZ().y();
177  double z = point->positionXYZ().z();
178  //switch (point_layer) {
179  //case PFTrajectoryPoint::ClosestApproach:
180  // Fill the Track's D0
181  if (point_layer == PFTrajectoryPoint::ClosestApproach) {
182  me["TrackImpactParameter"]->Fill(sqrt(x*x + y*y + z*z));
183  }
184  }
185  numTrackElements++;
186  }
187 
188  // Element is an ECAL Cluster
189  else if (element_type == PFBlockElement::ECAL) {
190  numECALElements++;
191  }
192  // Element is a HCAL Cluster
193  else if (element_type == PFBlockElement::HCAL) {
194  numHCALElements++;
195  }
196  // Element is a Muon Track
197  else if (element_type == PFBlockElement::MUON) {
198  numMuonElements++;
199  }
200  // Fill the Respective Elements Sizes
201  me["NumElements"]->Fill(numElements);
202  me["NumTrackElements"]->Fill(numTrackElements);
203  me["NumPS1Elements"]->Fill(numPS1Elements);
204  me["NumPS2Elements"]->Fill(numPS2Elements);
205  me["NumECALElements"]->Fill(numECALElements);
206  me["NumHCALElements"]->Fill(numHCALElements);
207  me["NumMuonElements"]->Fill(numMuonElements);
208  } ---------------------------------------------- */
209 
210  }
211 
212 }
213 
215 {
216 
217  // Store the DAQ Histograms
218  if (outputFile_.size() > 0 && dbe_)
219  dbe_->save(outputFile_);
220 
221 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual int pdgId() const
PDG identifier.
virtual void beginJob()
Definition: PFTester.cc:55
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
virtual double et() const
transverse energy
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2113
virtual double eta() const
momentum pseudorapidity
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: PFTester.cc:95
int iEvent
Definition: GenABIO.cc:243
virtual void endJob()
Definition: PFTester.cc:214
virtual int charge() const
electric charge
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
DQMStore * dbe_
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
#define M_PI
Definition: BFit3D.cc:3
T const * product() const
Definition: Handle.h:74
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:33
virtual ~PFTester()
Definition: PFTester.cc:52
virtual ParticleType particleId() const
Definition: PFCandidate.h:324
PFTester(const edm::ParameterSet &)
Definition: PFTester.cc:40
virtual double phi() const
momentum azimuthal angle
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429