CMS 3D CMS Logo

TrackHistoryAnalyzer.cc
Go to the documentation of this file.
1 /*
2  * TrackHistoryAnalyzer.C
3  *
4  * Created by Victor Eduardo Bazterra on 5/31/07.
5  *
6  */
7 
8 // system include files
9 #include <iostream>
10 #include <memory>
11 #include <string>
12 #include <sstream>
13 #include <vector>
14 
15 // user include files
16 
19 
27 
30 
31 //
32 // class decleration
33 //
34 
36 {
37 public:
38 
39  explicit TrackHistoryAnalyzer(const edm::ParameterSet&);
41 
42 private:
43 
44  virtual void beginRun(const edm::Run&, const edm::EventSetup&);
45  virtual void beginJob() override ;
46  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
47 
48  // Member data
49 
51 
52  std::size_t totalTracks_;
53 
55 
56  std::string particleString(int) const;
57 
59 
63  ) const;
64 
66  HepMC::GenVertex::particles_in_const_iterator,
67  HepMC::GenVertex::particles_in_const_iterator,
68  HepMC::GenVertex::particles_out_const_iterator,
69  HepMC::GenVertex::particles_out_const_iterator
70  ) const;
71 };
72 
73 
75 {
76  trackProducer_ = config.getUntrackedParameter<edm::InputTag> ( "trackProducer" );
77  consumes<edm::View<reco::Track>>(trackProducer_);
78 }
79 
80 
82 
83 
85 {
86  // Track collection
88  event.getByLabel(trackProducer_, trackCollection);
89 
90  // Set the classifier for a new event
91  classifier_.newEvent(event, setup);
92 
93  // Get a constant reference to the track history associated to the classifier
94  TrackHistory const & tracer = classifier_.history();
95 
96  // Loop over the track collection.
97  for (std::size_t index = 0; index < trackCollection->size(); index++)
98  {
99  std::cout << std::endl << "History for track #" << index << " : " << std::endl;
100 
101  // Classify the track and detect for fakes
103  {
104  // Get the list of TrackingParticles associated to
105  TrackHistory::SimParticleTrail simParticles(tracer.simParticleTrail());
106 
107  // Loop over all simParticles
108  for (std::size_t hindex=0; hindex<simParticles.size(); hindex++)
109  {
110  std::cout << " simParticles [" << hindex << "] : "
111  << particleString(simParticles[hindex]->pdgId())
112  << std::endl;
113  }
114 
115  // Get the list of TrackingVertexes associated to
116  TrackHistory::SimVertexTrail simVertexes(tracer.simVertexTrail());
117 
118  // Loop over all simVertexes
119  if ( !simVertexes.empty() )
120  {
121  for (std::size_t hindex=0; hindex<simVertexes.size(); hindex++)
122  {
123  std::cout << " simVertex [" << hindex << "] : "
124  << vertexString(
125  simVertexes[hindex]->sourceTracks(),
126  simVertexes[hindex]->daughterTracks()
127  )
128  << std::endl;
129  }
130  }
131  else
132  std::cout << " simVertex no found" << std::endl;
133 
134  // Get the list of GenParticles associated to
136 
137  // Loop over all genParticles
138  for (std::size_t hindex=0; hindex<genParticles.size(); hindex++)
139  {
140  std::cout << " genParticles [" << hindex << "] : "
141  << particleString(genParticles[hindex]->pdg_id())
142  << std::endl;
143  }
144 
145  // Get the list of TrackingVertexes associated to
146  TrackHistory::GenVertexTrail genVertexes(tracer.genVertexTrail());
147 
148  // Loop over all simVertexes
149  if ( !genVertexes.empty() )
150  {
151  for (std::size_t hindex=0; hindex<genVertexes.size(); hindex++)
152  {
153  std::cout << " genVertex [" << hindex << "] : "
154  << vertexString(
155  genVertexes[hindex]->particles_in_const_begin(),
156  genVertexes[hindex]->particles_in_const_end(),
157  genVertexes[hindex]->particles_out_const_begin(),
158  genVertexes[hindex]->particles_out_const_end()
159  )
160  << std::endl;
161  }
162  }
163  else
164  std::cout << " genVertex no found" << std::endl;
165  }
166  else
167  std::cout << " fake track" << std::endl;
168 
169  std::cout << " track categories : " << classifier_;
170  std::cout << std::endl;
171  }
172 }
173 
174 
175 void
177 {
178  // Get the particles table.
179  setup.getData( pdt_ );
180 }
181 
182 void
184 {
185  totalTracks_ = 0;
186 }
187 
188 
190 {
191  ParticleData const * pid;
192 
193  std::ostringstream vDescription;
194 
196 
197  if (particleType.isValid())
198  {
199  pid = pdt_->particle(particleType);
200  if (pid)
201  vDescription << pid->name();
202  else
203  vDescription << pdgId;
204  }
205  else
206  vDescription << pdgId;
207 
208  return vDescription.str();
209 }
210 
211 
215 ) const
216 {
217  ParticleData const * pid;
218 
219  std::ostringstream vDescription;
220 
221  for (std::size_t j = 0; j < in.size(); j++)
222  {
223  if (!j) vDescription << "(";
224 
226 
227  if (particleType.isValid())
228  {
229  pid = pdt_->particle(particleType);
230  if (pid)
231  vDescription << pid->name();
232  else
233  vDescription << in[j]->pdgId();
234  }
235  else
236  vDescription << in[j]->pdgId();
237 
238  if (j == in.size() - 1) vDescription << ")";
239  else vDescription << ",";
240  }
241 
242  vDescription << "->";
243 
244  for (std::size_t j = 0; j < out.size(); j++)
245  {
246  if (!j) vDescription << "(";
247 
249 
250  if (particleType.isValid())
251  {
252  pid = pdt_->particle(particleType);
253  if (pid)
254  vDescription << pid->name();
255  else
256  vDescription << out[j]->pdgId();
257  }
258  else
259  vDescription << out[j]->pdgId();
260 
261  if (j == out.size() - 1) vDescription << ")";
262  else vDescription << ",";
263  }
264 
265  return vDescription.str();
266 }
267 
268 
270  HepMC::GenVertex::particles_in_const_iterator in_begin,
271  HepMC::GenVertex::particles_in_const_iterator in_end,
272  HepMC::GenVertex::particles_out_const_iterator out_begin,
273  HepMC::GenVertex::particles_out_const_iterator out_end
274 ) const
275 {
276  ParticleData const * pid;
277 
278  std::ostringstream vDescription;
279 
280  std::size_t j = 0;
281 
282  HepMC::GenVertex::particles_in_const_iterator in, itmp;
283 
284  for (in = in_begin; in != in_end; in++, j++)
285  {
286  if (!j) vDescription << "(";
287 
288  HepPDT::ParticleID particleType((*in)->pdg_id());
289 
290  if (particleType.isValid())
291  {
292  pid = pdt_->particle(particleType);
293  if (pid)
294  vDescription << pid->name();
295  else
296  vDescription << (*in)->pdg_id();
297  }
298  else
299  vDescription << (*in)->pdg_id();
300 
301  itmp = in;
302 
303  if (++itmp == in_end) vDescription << ")";
304  else vDescription << ",";
305  }
306 
307  vDescription << "->";
308  j = 0;
309 
310  HepMC::GenVertex::particles_out_const_iterator out, otmp;
311 
312  for (out = out_begin; out != out_end; out++, j++)
313  {
314  if (!j) vDescription << "(";
315 
316  HepPDT::ParticleID particleType((*out)->pdg_id());
317 
318  if (particleType.isValid())
319  {
320  pid = pdt_->particle(particleType);
321  if (pid)
322  vDescription << pid->name();
323  else
324  vDescription << (*out)->pdg_id();
325  }
326  else
327  vDescription << (*out)->pdg_id();
328 
329  otmp = out;
330 
331  if (++otmp == out_end) vDescription << ")";
332  else vDescription << ",";
333  }
334 
335  return vDescription.str();
336 }
337 
338 
T getUntrackedParameter(std::string const &, T const &) const
std::string vertexString(const TrackingParticleRefVector &, const TrackingParticleRefVector &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
SimVertexTrail const & simVertexTrail() const
Return all the simulated vertices in the history.
Definition: HistoryBase.h:59
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
std::string particleString(int) const
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
virtual void beginJob() override
TrackHistory const & history() const
Returns a reference to the track history used in the classification.
Definition: config.py:1
void getData(T &iHolder) const
Definition: EventSetup.h:78
std::vector< const HepMC::GenParticle * > GenParticleTrail
HepMC::GenParticle trail type.
Definition: HistoryBase.h:18
TrackClassifier const & evaluate(reco::TrackBaseRef const &)
Classify the RecoTrack in categories.
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
TrackHistoryAnalyzer(const edm::ParameterSet &)
This class traces the simulated and generated history of a given track.
Definition: TrackHistory.h:17
std::vector< const HepMC::GenVertex * > GenVertexTrail
GenVertex trail type.
Definition: HistoryBase.h:27
void newEvent(edm::Event const &, edm::EventSetup const &)
Pre-process event information (for accessing reconstraction information)
HepPDT::ParticleData ParticleData
bool is(Category category) const
Returns track flag for a given category.
Get track history and classify it in function of their .
SimParticleTrail const & simParticleTrail() const
Return all the simulated particle in the history.
Definition: HistoryBase.h:65
edm::ESHandle< ParticleDataTable > pdt_
size_type size() const
Size of the RefVector.
Definition: RefVector.h:107
GenVertexTrail const & genVertexTrail() const
Return all generated vertex in the history.
Definition: HistoryBase.h:71
std::vector< TrackingVertexRef > SimVertexTrail
SimVertex trail type.
Definition: HistoryBase.h:36
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
GenParticleTrail const & genParticleTrail() const
Return all generated particle (HepMC::GenParticle) in the history.
Definition: HistoryBase.h:77
Definition: event.py:1
Definition: Run.h:42
std::vector< TrackingParticleRef > SimParticleTrail
SimParticle trail type.
Definition: HistoryBase.h:33