CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackingTruthProducer.cc
Go to the documentation of this file.
1 
11 
14 
18 
20 
25 
27  pSimHitSelector_(config), pixelPSimHitSelector_(config), trackerPSimHitSelector_(config), muonPSimHitSelector_(config)
28 {
29  // Initialize global parameters
30  dataLabels_ = config.getParameter<std::vector<std::string> >("HepMCDataLabels");
31  useMultipleHepMCLabels_ = config.getParameter<bool>("useMultipleHepMCLabels");
32 
33  distanceCut_ = config.getParameter<double>("vertexDistanceCut");
34  volumeRadius_ = config.getParameter<double>("volumeRadius");
35  volumeZ_ = config.getParameter<double>("volumeZ");
36  mergedBremsstrahlung_ = config.getParameter<bool>("mergedBremsstrahlung");
37  removeDeadModules_ = config.getParameter<bool>("removeDeadModules");
38  simHitLabel_ = config.getParameter<std::string>("simHitLabel");
39 
40  // Initialize selection for building TrackingParticles
41  if ( config.exists("select") )
42  {
43  edm::ParameterSet param = config.getParameter<edm::ParameterSet>("select");
45  param.getParameter<double>("ptMinTP"),
46  param.getParameter<double>("minRapidityTP"),
47  param.getParameter<double>("maxRapidityTP"),
48  param.getParameter<double>("tipTP"),
49  param.getParameter<double>("lipTP"),
50  param.getParameter<int>("minHitTP"),
51  param.getParameter<bool>("signalOnlyTP"),
52  param.getParameter<bool>("chargedOnlyTP"),
53  param.getParameter<std::vector<int> >("pdgIdTP")
54  );
55  selectorFlag_ = true;
56  }
57  else
58  selectorFlag_ = false;
59 
60  MessageCategory_ = "TrackingTruthProducer";
61 
62  edm::LogInfo (MessageCategory_) << "Setting up TrackingTruthProducer";
63  edm::LogInfo (MessageCategory_) << "Vertex distance cut set to " << distanceCut_ << " mm";
64  edm::LogInfo (MessageCategory_) << "Volume radius set to " << volumeRadius_ << " mm";
65  edm::LogInfo (MessageCategory_) << "Volume Z set to " << volumeZ_ << " mm";
66 
67  if (useMultipleHepMCLabels_) edm::LogInfo (MessageCategory_) << "Collecting generator information from pileup.";
68  if (mergedBremsstrahlung_) edm::LogInfo (MessageCategory_) << "Merging electrom bremsstralung";
69  if (removeDeadModules_) edm::LogInfo (MessageCategory_) << "Removing psimhit from dead modules";
70 
71  if (!mergedBremsstrahlung_)
72  {
73  produces<TrackingVertexCollection>();
74  produces<TrackingParticleCollection>();
75  }
76  else
77  {
78  produces<TrackingVertexCollection>();
79  produces<TrackingParticleCollection>();
80  produces<TrackingVertexCollection>("MergedTrackTruth");
81  produces<TrackingParticleCollection>("MergedTrackTruth");
82  }
83 }
84 
85 
87 {
88  // Clean the list of hepmc products
89  hepMCProducts_.clear();
90 
91  // Collect all the HepMCProducts
93 
94  for (std::vector<std::string>::const_iterator source = dataLabels_.begin(); source != dataLabels_.end(); ++source)
95  {
96  if ( event.getByLabel(*source, hepMCHandle) )
97  {
98  hepMCProducts_.push_back(hepMCHandle);
99  edm::LogInfo (MessageCategory_) << "Using HepMC source " << *source;
100  if (!useMultipleHepMCLabels_) break;
101  }
102  }
103 
104  if ( hepMCProducts_.empty() )
105  {
106  edm::LogWarning (MessageCategory_) << "No HepMC source found";
107  return;
108  }
109  else if (hepMCProducts_.size() > 1 || useMultipleHepMCLabels_)
110  {
111  edm::LogInfo (MessageCategory_) << "You are using more than one HepMC source.";
112  edm::LogInfo (MessageCategory_) << "If the labels are not in the same order as the events in the crossing frame (i.e. signal, pileup(s) ) ";
113  edm::LogInfo (MessageCategory_) << "or there are fewer labels than events in the crossing frame";
114  edm::LogInfo (MessageCategory_) << MessageCategory_ << " may try to access data in the wrong HepMCProduct and crash.";
115  }
116 
117  // Collect all the simtracks from the crossing frame
119  event.getByLabel("mix", simHitLabel_, cfSimTracks);
120 
121  // Create a mix collection from one simtrack collection
122  simTracks_ = std::auto_ptr<MixCollection<SimTrack> >( new MixCollection<SimTrack>(cfSimTracks.product()) );
123 
124  // Collect all the simvertex from the crossing frame
125  edm::Handle<CrossingFrame<SimVertex> > cfSimVertexes;
126  event.getByLabel("mix", simHitLabel_, cfSimVertexes);
127 
128  // Create a mix collection from one simvertex collection
129  simVertexes_ = std::auto_ptr<MixCollection<SimVertex> >( new MixCollection<SimVertex>(cfSimVertexes.product()) );
130 
131  // Create collections of things we will put in event
132  trackingParticles_ = std::auto_ptr<TrackingParticleCollection>( new TrackingParticleCollection );
133  trackingVertexes_ = std::auto_ptr<TrackingVertexCollection>( new TrackingVertexCollection );
134 
135  // Get references before put so we can cross reference
136  refTrackingParticles_ = event.getRefBeforePut<TrackingParticleCollection>();
137  refTrackingVertexes_ = event.getRefBeforePut<TrackingVertexCollection>();
138 
139  // Create a list of psimhits
140  if (removeDeadModules_)
141  {
142  pSimHits_.clear();
143  pixelPSimHitSelector_.select(pSimHits_, event, setup);
145  muonPSimHitSelector_.select(pSimHits_, event, setup);
146  }
147  else
148  {
149  pSimHits_.clear();
150  pSimHitSelector_.select(pSimHits_, event, setup);
151  }
152 
153  // Create a multimap between trackId and hit indices
155 
156  // Create a map between trackId and track index
158 
159  // Create a map between vertexId and vertex index
161 
163 
165  {
166  // Create collections of things we will put in event,
167  mergedTrackingParticles_ = std::auto_ptr<TrackingParticleCollection>( new TrackingParticleCollection );
168  mergedTrackingVertexes_ = std::auto_ptr<TrackingVertexCollection>( new TrackingVertexCollection );
169 
170  // Get references before put so we can cross reference
171  refMergedTrackingParticles_ = event.getRefBeforePut<TrackingParticleCollection>("MergedTrackTruth");
172  refMergedTrackingVertexes_ = event.getRefBeforePut<TrackingVertexCollection>("MergedTrackTruth");
173 
174  // Merged brem electrons
176 
177  // Put TrackingParticles and TrackingVertices in event
178  event.put(mergedTrackingParticles_, "MergedTrackTruth");
179  event.put(mergedTrackingVertexes_, "MergedTrackTruth");
180  event.put(trackingParticles_);
181  event.put(trackingVertexes_);
182  }
183  else
184  {
185  // Put TrackingParticles and TrackingVertices in event
186  event.put(trackingParticles_);
187  event.put(trackingVertexes_);
188  }
189 }
190 
191 
193  std::vector<PSimHit> const & pSimHits,
194  EncodedTruthIdToIndexes & association
195 )
196 {
197  // Clear the association map
198  association.clear();
199 
200  // Create a association from simtracks to overall index in the mix collection
201  for (std::size_t i = 0; i < pSimHits.size(); ++i)
202  {
203  EncodedTruthIdToIndexes::key_type objectId = EncodedTruthIdToIndexes::key_type(pSimHits[i].eventId(), pSimHits[i].trackId());
204  association.insert( std::make_pair(objectId, i) );
205  }
206 }
207 
208 
210  std::auto_ptr<MixCollection<SimTrack> > const & mixCollection,
211  EncodedTruthIdToIndex & association
212 )
213 {
214  int index = 0;
215  // Clear the association map
216  association.clear();
217  // Create a association from simtracks to overall index in the mix collection
218  for (MixCollection<SimTrack>::MixItr iterator = mixCollection->begin(); iterator != mixCollection->end(); ++iterator, ++index)
219  {
220  EncodedTruthId objectId = EncodedTruthId(iterator->eventId(), iterator->trackId());
221  association.insert( std::make_pair(objectId, index) );
222  }
223 }
224 
225 
227  std::auto_ptr<MixCollection<SimVertex> > const & mixCollection,
228  EncodedTruthIdToIndex & association
229 )
230 {
231  int index = 0;
232 
233  // Solution to the problem of not having vertexId
234  bool useVertexId = true;
235  EncodedEventIdToIndex vertexId;
236  EncodedEventId oldEventId;
237  unsigned int oldVertexId = 0;
238 
239  // Loop for finding repeated vertexId (vertexId problem hack)
240  for (MixCollection<SimVertex>::MixItr iterator = mixCollection->begin(); iterator != mixCollection->end(); ++iterator, ++index)
241  {
242  if (!index || iterator->eventId() != oldEventId)
243  {
244  oldEventId = iterator->eventId();
245  oldVertexId = iterator->vertexId();
246  continue;
247  }
248 
249  if ( iterator->vertexId() == oldVertexId )
250  {
251  edm::LogWarning(MessageCategory_) << "Multiple vertexId found, no using vertexId.";
252  useVertexId = false;
253  break;
254  }
255  }
256 
257  // Reset the index
258  index = 0;
259 
260  // Clear the association map
261  association.clear();
262 
263  // Create a association from simvertexes to overall index in the mix collection
264  for (MixCollection<SimVertex>::MixItr iterator = mixCollection->begin(); iterator != mixCollection->end(); ++iterator, ++index)
265  {
266  EncodedTruthId objectId;
267  if (useVertexId)
268  objectId = EncodedTruthId(iterator->eventId(), iterator->vertexId());
269  else
270  objectId = EncodedTruthId(iterator->eventId(), vertexId[iterator->eventId()]++);
271  association.insert( std::make_pair(objectId, index) );
272  }
273 }
274 
275 
277 {
278  unsigned int index = 0;
279 
280  std::set<unsigned int> excludedTV, excludedTP;
281 
282  // Merge Bremsstrahlung vertexes
283  for (TrackingVertexCollection::iterator iVC = trackingVertexes_->begin(); iVC != trackingVertexes_->end(); ++iVC, ++index)
284  {
285  // Check Bremsstrahlung vertex
287  {
288  // Get a pointer to the source track (A Ref<> cannot be use with a product!)
289  TrackingParticle * track = &trackingParticles_->at(iVC->sourceTracks_begin()->key());
290  // Get a Ref<> to the source track
291  TrackingParticleRef trackRef = *iVC->sourceTracks_begin();
292  // Pointer to electron daughter
293  TrackingParticle * daughter = 0;
294  // Ref<> to electron daughter
295  TrackingParticleRef daughterRef;
296 
297  // Select the electron daughter and redirect the photon
298  for (TrackingVertex::tp_iterator idaughter = iVC->daughterTracks_begin(); idaughter != iVC->daughterTracks_end(); ++idaughter)
299  {
300  TrackingParticle * pointer = &trackingParticles_->at(idaughter->key());
301  if ( std::abs( pointer->pdgId() ) == 11 )
302  {
303  // Set pointer to the electron daughter
304  daughter = pointer;
305  // Set Ref<> to the electron daughter
306  daughterRef = *idaughter;
307  }
308  else if ( pointer->pdgId() == 22 )
309  {
310  // Delete the photon original parent vertex
311  pointer->clearParentVertex();
312  // Set the new parent vertex to the vertex of the source track
313  pointer->setParentVertex( track->parentVertex() );
314  // Get a non-const pointer to the parent vertex
315  TrackingVertex * vertex = &trackingVertexes_->at( track->parentVertex().key() );
316  // Add the photon to the doughter list of the parent vertex
317  vertex->addDaughterTrack( *idaughter );
318  }
319  }
320 
321  // Add the electron segments from the electron daughter
322  // track must not be the same particle as daughter
323  // if (track != daughter)
324  for (TrackingParticle::g4t_iterator isegment = daughter->g4Track_begin(); isegment != daughter->g4Track_end(); ++isegment)
325  track->addG4Track(*isegment);
326 
327  // Copy all the simhits to the new track
328  for (std::vector<PSimHit>::const_iterator ihit = daughter->pSimHit_begin(); ihit != daughter->pSimHit_end(); ++ihit)
329  track->addPSimHit(*ihit);
330 
331  // Make a copy of the decay vertexes of the track
332  TrackingVertexRefVector decayVertices( track->decayVertices() );
333 
334  // Clear the decay vertex list
335  track->clearDecayVertices();
336 
337  // Add the remaining vertexes
338  for (TrackingVertexRefVector::const_iterator idecay = decayVertices.begin(); idecay != decayVertices.end(); ++idecay)
339  if ( (*idecay).key() != index ) track->addDecayVertex(*idecay);
340 
341  // Redirect all the decay source vertexes to those in the electron daughter
342  for (TrackingParticle::tv_iterator idecay = daughter->decayVertices_begin(); idecay != daughter->decayVertices_end(); ++idecay)
343  {
344  // Add the vertexes to the decay list of the source particles
345  track->addDecayVertex(*idecay);
346  // Get a reference to decay vertex
347  TrackingVertex * vertex = &trackingVertexes_->at( idecay->key() );
348  // Copy all the source tracks from of the decay vertex
349  TrackingParticleRefVector sources( vertex->sourceTracks() );
350  // Clear the source track references
351  vertex->clearParentTracks();
352  // Add the new source tracks by excluding the one with the segment merged
353  for (TrackingVertex::tp_iterator isource = sources.begin(); isource != sources.end(); ++isource)
354  if (*isource != daughterRef)
355  vertex->addParentTrack(*isource);
356  // Add the track reference to the list of sources
357  vertex->addParentTrack(trackRef);
358  }
359 
360  // Adding the vertex to the exlusion list
361  excludedTV.insert(index);
362 
363  // Adding the electron segment tp into the exlusion list
364  excludedTP.insert( daughterRef.key() );
365  }
366  }
367 
368  edm::LogInfo(MessageCategory_) << "Generating the merged collection." << std::endl;
369 
370  // Reserved the same amount of memory for the merged collections
372  mergedTrackingVertexes_->reserve(trackingVertexes_->size());
373 
374  index = 0;
375  std::map<unsigned int, unsigned int> vertexMap;
376 
377  // Copy non-excluded vertices discarding parent & child tracks
378  for (TrackingVertexCollection::const_iterator iVC = trackingVertexes_->begin(); iVC != trackingVertexes_->end(); ++iVC, ++index)
379  {
380  if ( excludedTV.find(index) != excludedTV.end() ) continue;
381  // Save the new location of the non excluded vertexes (take in consideration those were removed)
382  vertexMap.insert( std::make_pair(index, mergedTrackingVertexes_->size()) );
383  // Copy those vertexes are not excluded
384  TrackingVertex newVertex = (*iVC);
385  newVertex.clearDaughterTracks();
386  newVertex.clearParentTracks();
387  mergedTrackingVertexes_->push_back(newVertex);
388  }
389 
390  index = 0;
391 
392  // Copy and cross reference the non-excluded tp to the merged collection
393  for (TrackingParticleCollection::const_iterator iTP = trackingParticles_->begin(); iTP != trackingParticles_->end(); ++iTP, ++index)
394  {
395  if ( excludedTP.find(index) != excludedTP.end() ) continue;
396 
397  TrackingVertexRef sourceV = iTP->parentVertex();
398  TrackingVertexRefVector decayVs = iTP->decayVertices();
399  TrackingParticle newTrack = *iTP;
400 
401  newTrack.clearParentVertex();
402  newTrack.clearDecayVertices();
403 
404  // Set vertex indices for new vertex product and track references in those vertices
405 
406  // Index of parent vertex in vertex container
407  unsigned int parentIndex = vertexMap[sourceV.key()];
408  // Index of this track in track container
409  unsigned int tIndex = mergedTrackingParticles_->size();
410 
411  // Add vertex to track
413  // Add track to vertex
414  (mergedTrackingVertexes_->at(parentIndex)).addDaughterTrack(TrackingParticleRef(refMergedTrackingParticles_, tIndex));
415 
416  for (TrackingVertexRefVector::const_iterator iDecayV = decayVs.begin(); iDecayV != decayVs.end(); ++iDecayV)
417  {
418  // Index of decay vertex in vertex container
419  unsigned int daughterIndex = vertexMap[iDecayV->key()];
420  // Add vertex to track
421  newTrack.addDecayVertex( TrackingVertexRef(refMergedTrackingVertexes_, daughterIndex) );
422  // Add track to vertex
423  (mergedTrackingVertexes_->at(daughterIndex)).addParentTrack( TrackingParticleRef(refMergedTrackingParticles_, tIndex) );
424  }
425 
426  mergedTrackingParticles_->push_back(newTrack);
427  }
428 }
429 
430 
432  TrackingVertex const & vertex,
433  std::auto_ptr<TrackingParticleCollection> & tPC
434 )
435 {
437 
438  // Check for the basic parent conditions
439  if ( parents.size() != 1)
440  return false;
441 
442  // Check for the parent particle is a |electron| (electron or positron)
443  if ( std::abs( tPC->at(parents.begin()->key()).pdgId() ) != 11 )
444  return false;
445 
446  int nElectrons = 0;
447  int nPhotons = 0;
448  int nOthers = 0;
449 
450  // Loop over the daughter particles and counts the number of |electrons|, photons or others
451  for ( TrackingVertex::tp_iterator it = vertex.daughterTracks_begin(); it != vertex.daughterTracks_end(); ++it )
452  {
453  // Stronger rejection for looping particles
454  if ( parents[0] == *it )
455  return false;
456 
457  if ( std::abs( tPC->at(it->key()).pdgId() ) == 11 )
458  nElectrons++;
459  else if ( tPC->at(it->key()).pdgId() == 22 )
460  nPhotons++;
461  else
462  nOthers++;
463  }
464 
465  // Condition to be a Bremsstrahlung Vertex
466  if (nElectrons == 1 && nPhotons >= 0 && nOthers == 0)
467  return true;
468 
469  return false;
470 }
471 
472 
474 {
475  // Reset the event counter (use for define vertexId)
476  eventIdCounter_.clear();
477 
478  // Define a container of vetoed traks
479  std::map<int,std::size_t> vetoedTracks;
480 
481  // Define map between parent simtrack and tv indexes
482  std::map<int,std::size_t> vetoedSimVertexes;
483 
484  for (int simTrackIndex = 0; simTrackIndex != simTracks_->size(); ++simTrackIndex)
485  {
486  // Check if the simTrack is excluded (includes non traceable and recovered by history)
487  if ( vetoedTracks.find(simTrackIndex) != vetoedTracks.end() ) continue;
488 
489  SimTrack const & simTrack = simTracks_->getObject(simTrackIndex);
490 
491  TrackingParticle trackingParticle;
492 
493  // Set a bare tp (only with the psimhit) with a given simtrack
494  // the function return true if it is tracable
495  if ( setTrackingParticle(simTrack, trackingParticle) )
496  {
497  // Follows the path upward recovering the history of the particle
498  SimTrack const * currentSimTrack = & simTrack;
499 
500  // Initial condition for the tp and tv indexes
501  int trackingParticleIndex = -1;
502  int trackingVertexIndex = -1;
503 
504  do
505  {
506  // Set a new tracking particle for the current simtrack
507  // and add it to the list of parent tracks of previous vertex
508  if (trackingParticleIndex >= 0)
509  {
510  setTrackingParticle(*currentSimTrack, trackingParticle);
511 
512  // Set the tp index to its new value
513  trackingParticleIndex = trackingParticles_->size();
514  // Push the tp in to the collection
515  trackingParticles_->push_back(trackingParticle);
516 
517  // Add the previous track to the list of decay vertexes of the new tp
518  trackingParticles_->at(trackingParticleIndex).addDecayVertex(
519  TrackingVertexRef(refTrackingVertexes_, trackingVertexIndex)
520  );
521 
522  // Add the new tp to the list of parent tracks of the previous tv
523  trackingVertexes_->at(trackingVertexIndex).addParentTrack(
524  TrackingParticleRef(refTrackingParticles_, trackingParticleIndex)
525  );
526  }
527  else
528  {
529  // Set the tp index to its new value
530  trackingParticleIndex = trackingParticles_->size();
531  // Push the tp in to the collection
532  trackingParticles_->push_back(trackingParticle);
533  // Vetoed the simTrack
534  vetoedTracks.insert( std::make_pair(simTrackIndex, trackingParticleIndex) );
535  }
536 
537  // Verify if the parent simVertex has a simTrack or if the source is a vetoSimVertex
538  if (currentSimTrack->noVertex()) break;
539 
540  // Get the simTrack parent index (it is implicit should be in the same event as current)
541  unsigned int parentSimVertexIndex = vertexIdToIndex_[
543  currentSimTrack->eventId(),
544  currentSimTrack->vertIndex()
545  )
546  ];
547  // Create a new tv
548  TrackingVertex trackingVertex;
549  // Get the parent simVertex associated to the current simTrack
550  SimVertex const * parentSimVertex = & simVertexes_->getObject(parentSimVertexIndex);
551 
552  bool vetoSimVertex = vetoedSimVertexes.find(parentSimVertexIndex) != vetoedSimVertexes.end();
553 
554  // Check for a already visited parent simTrack
555  if ( !vetoSimVertex )
556  {
557  // Set the tv by using simvertex
558  trackingVertexIndex = setTrackingVertex(*parentSimVertex, trackingVertex);
559 
560  // Check if a new vertex needs to be created
561  if (trackingVertexIndex < 0)
562  {
563  // Set the tv index ot its new value
564  trackingVertexIndex = trackingVertexes_->size();
565  // Push the new tv in to the collection
566  trackingVertexes_->push_back(trackingVertex);
567  }
568  else
569  {
570  // Get the postion and time of the vertex
571  const LorentzVector & position = trackingVertexes_->at(trackingVertexIndex).position();
572  Vector xyz = Vector(position.x(), position.y(), position.z());
573  double t = position.t();
574  // Set the vertex postion of the tp to the closest vertex
575  trackingParticles_->at(trackingParticleIndex).setVertex(xyz, t);
576  }
577 
578  vetoedSimVertexes.insert( std::make_pair(parentSimVertexIndex, trackingVertexIndex) );
579  }
580  else
581  trackingVertexIndex = vetoedSimVertexes[parentSimVertexIndex];
582 
583  // Set the newly created tv as parent vertex
584  trackingParticles_->at(trackingParticleIndex).setParentVertex(
585  TrackingVertexRef(refTrackingVertexes_, trackingVertexIndex)
586  );
587 
588  // Add the newly created tp to the tv daughter list
589  trackingVertexes_->at(trackingVertexIndex).addDaughterTrack(
590  TrackingParticleRef(refTrackingParticles_, trackingParticleIndex)
591  );
592 
593  // Verify if the parent simVertex has a simTrack or if the source is a vetoSimVertex
594  if (parentSimVertex->noParent() || vetoSimVertex) break;
595 
596  // Get the next simTrack index (it is implicit should be in the same event as current).
597  unsigned int nextSimTrackIndex = trackIdToIndex_[
599  currentSimTrack->eventId(),
600  parentSimVertex->parentIndex()
601  )
602  ];
603 
604  // Check if the next track exist
605  if ( vetoedTracks.find(nextSimTrackIndex) != vetoedTracks.end() )
606  {
607  // Add to the newly created tv the existent next simtrack in to parent list.
608  trackingVertexes_->at(trackingVertexIndex).addParentTrack(
609  TrackingParticleRef(refTrackingParticles_, vetoedTracks[nextSimTrackIndex])
610  );
611  // Add the vertex to list of decay vertexes of the new tp
612  trackingParticles_->at(vetoedTracks[nextSimTrackIndex]).addDecayVertex(
613  TrackingVertexRef(refTrackingVertexes_, trackingVertexIndex)
614  );
615  break;
616  }
617 
618  // Vetoed the next simTrack
619  vetoedTracks.insert( std::make_pair(nextSimTrackIndex, trackingParticleIndex) );
620 
621  // Set the current simTrack as the next simTrack
622  currentSimTrack = & simTracks_->getObject(nextSimTrackIndex);
623  }
624  while (!currentSimTrack->noVertex());
625  }
626  }
627 }
628 
629 
631  SimTrack const & simTrack,
632  TrackingParticle & trackingParticle
633 )
634 {
635  // Get the eventid associated to the track
636  EncodedEventId trackEventId = simTrack.eventId();
637  // Get the simtrack id
638  EncodedTruthId simTrackId = EncodedTruthId( trackEventId, simTrack.trackId() );
639 
640  // Location of the parent vertex
642  // If not parent then location is (0,0,0,0)
643  if (simTrack.noVertex())
644  position = LorentzVector(0, 0, 0, 0);
645  else
646  position = simVertexes_->getObject(simTrack.vertIndex()). position();
647 
648  // Define the default status and pdgid
649  int status = -99;
650  int pdgId = simTrack.type();
651 
652  int genParticleIndex = simTrack.genpartIndex();
653  bool signalEvent = (trackEventId.event() == 0 && trackEventId.bunchCrossing() == 0);
654 
655  // In the case of a existing generated particle and track
656  // event is signal redefine status a pdgId
657 
659 
660  if (genParticleIndex >= 0 && (signalEvent || useMultipleHepMCLabels_) )
661  {
662  // Get the generated particle
663  hepmc = (useMultipleHepMCLabels_) ? hepMCProducts_.at(trackEventId.rawId()) : hepmc = hepMCProducts_.at(0);
664 
665  const HepMC::GenParticle * genParticle = hepmc->GetEvent()->barcode_to_particle(genParticleIndex);
666 
667  if (genParticle)
668  {
669  status = genParticle->status();
670  pdgId = genParticle->pdg_id();
671  }
672  }
673 
674  // Create a tp from the simtrack
675  trackingParticle = TrackingParticle(
676  (char) simTrack.charge(),
677  simTrack.momentum(),
678  Vector(position.x(), position.y(), position.z()),
679  position.t(),
680  pdgId,
681  status,
682  trackEventId
683  );
684 
685  bool init = true;
686 
687  int processType = 0;
688  int particleType = 0;
689 
690  // Counting the TP hits using the layers (as in ORCA).
691  // Does seem to find less hits. maybe b/c layer is a number now, not a pointer
692  int totalSimHits = 0;
693  int oldLayer = 0;
694  int newLayer = 0;
695  int oldDetector = 0;
696  int newDetector = 0;
697 
698  // Loop over the associated hits per track
699  for (
700  EncodedTruthIdToIndexes::const_iterator iEntry = trackIdToHits_.lower_bound(simTrackId);
701  iEntry != trackIdToHits_.upper_bound(simTrackId);
702  ++iEntry
703  )
704  {
705  // Get a constant reference to the simhit
706  PSimHit const & pSimHit = pSimHits_.at(iEntry->second);
707 
708  // Initial condition for consistent simhit selection
709  if (init)
710  {
711  processType = pSimHit.processType();
712  particleType = pSimHit.particleType();
713  init = false;
714  }
715 
716  // Check for delta and interaction products discards
717  if (processType == pSimHit.processType() && particleType == pSimHit.particleType() && pdgId == pSimHit.particleType() )
718  {
719  trackingParticle.addPSimHit(pSimHit);
720 
721  unsigned int detectorIdIndex = pSimHit.detUnitId();
722  DetId detectorId = DetId(detectorIdIndex);
723  oldLayer = newLayer;
724  oldDetector = newDetector;
725  newLayer = LayerFromDetid(detectorIdIndex);
726  newDetector = detectorId.subdetId();
727 
728  // Count hits using layers for glued detectors
729  // newlayer !=0 excludes Muon layers set to 0 by LayerFromDetid
730  if ( ( oldLayer != newLayer || (oldLayer==newLayer && oldDetector!=newDetector ) ) && newLayer != 0 ) totalSimHits++;
731  }
732  }
733 
734  // Set the number of matched simhits
735  trackingParticle.setMatchedHit(totalSimHits);
736 
737  // Add the simtrack associated to the tp
738  trackingParticle.addG4Track(simTrack);
739 
740  // Add the generator information
741  if ( genParticleIndex >= 0 && (signalEvent || useMultipleHepMCLabels_) )
742  trackingParticle.addGenParticle( GenParticleRef(hepmc, genParticleIndex) );
743 
744  if (selectorFlag_) return selector_(trackingParticle);
745 
746  return true;
747 }
748 
749 
751  SimVertex const & simVertex,
752  TrackingVertex & trackingVertex
753 )
754 {
755  LorentzVector const & position = simVertex.position();
756 
757  // Look for close by vertexes
758  for (std::size_t trackingVertexIndex = 0; trackingVertexIndex < trackingVertexes_->size(); ++trackingVertexIndex)
759  {
760  // Calculate the distance
761  double distance = (position - trackingVertexes_->at(trackingVertexIndex).position()).P();
762  // If the distance is under a given cut return the trackingVertex index (vertex merging)
763  if (distance <= distanceCut_)
764  {
765  // Add simvertex to the pre existent tv
766  trackingVertexes_->at(trackingVertexIndex).addG4Vertex(simVertex);
767  // return tv index
768  return trackingVertexIndex;
769  }
770  }
771 
772  // Get the event if from the simvertex
773  EncodedEventId simVertexEventId = simVertex.eventId();
774 
775  // Initialize the event counter
776  if (eventIdCounter_.find(simVertexEventId) == eventIdCounter_.end())
777  eventIdCounter_[simVertexEventId] = 0;
778 
779  // Get the simVertex id
780  EncodedTruthId simVertexId = EncodedTruthId(simVertexEventId, eventIdCounter_[simVertexEventId]);
781 
782  // Calculate if the vertex is in the tracker volume (it needs to be review for other detectors)
783  bool inVolume = (position.Pt() < volumeRadius_ && std::abs(position.z()) < volumeZ_); // In or out of Tracker
784 
785  // Initialize the new vertex
786  trackingVertex = TrackingVertex(position, inVolume, simVertexId);
787 
788  // Find the the closest GenVertexes to the created tv
789  addCloseGenVertexes(trackingVertex);
790 
791  // Add the g4 vertex to the tv
792  trackingVertex.addG4Vertex(simVertex);
793 
794  // Initialize the event counter
795  eventIdCounter_[simVertexEventId]++;
796 
797  return -1;
798 }
799 
800 
802 {
803  // Get the generated particle
805  const HepMC::GenEvent * genEvent = hepmc->GetEvent();
806 
807  // Get the postion of the tv
808  Vector tvPosition(trackingVertex.position().x(), trackingVertex.position().y(), trackingVertex.position().z());
809 
810  // Find HepMC vertices, put them in a close TrackingVertex (this could conceivably add the same GenVertex to multiple TrackingVertices)
811  for (
812  HepMC::GenEvent::vertex_const_iterator iGenVertex = genEvent->vertices_begin();
813  iGenVertex != genEvent->vertices_end();
814  ++iGenVertex
815  )
816  {
817  // Get the position of the genVertex
818  HepMC::ThreeVector rawPosition = (*iGenVertex)->position();
819 
820  // Convert to cm
821  Vector genPosition(rawPosition.x()/10.0, rawPosition.y()/10.0, rawPosition.z()/10.0);
822 
823  // Calculate the dis
824  double distance = sqrt( (tvPosition - genPosition).mag2() );
825 
826  if (distance <= distanceCut_)
827  trackingVertex.addGenVertex( GenVertexRef(hepmc, (*iGenVertex)->barcode()) );
828  }
829 }
830 
831 
833 {
834  DetId detId = DetId(detid);
835 
836  if ( detId.det() != DetId::Tracker ) return 0;
837 
838  int layerNumber=0;
839  unsigned int subdetId = static_cast<unsigned int>(detId.subdetId());
840 
841  if ( subdetId == StripSubdetector::TIB)
842  {
843  TIBDetId tibid(detId.rawId());
844  layerNumber = tibid.layer();
845  }
846  else if ( subdetId == StripSubdetector::TOB )
847  {
848  TOBDetId tobid(detId.rawId());
849  layerNumber = tobid.layer();
850  }
851  else if ( subdetId == StripSubdetector::TID)
852  {
853  TIDDetId tidid(detId.rawId());
854  layerNumber = tidid.wheel();
855  }
856  else if ( subdetId == StripSubdetector::TEC )
857  {
858  TECDetId tecid(detId.rawId());
859  layerNumber = tecid.wheel();
860  }
861  else if ( subdetId == PixelSubdetector::PixelBarrel )
862  {
863  PXBDetId pxbid(detId.rawId());
864  layerNumber = pxbid.layer();
865  }
866  else if ( subdetId == PixelSubdetector::PixelEndcap )
867  {
868  PXFDetId pxfid(detId.rawId());
869  layerNumber = pxfid.disk();
870  }
871  else
872  edm::LogVerbatim("TrackingTruthProducer") << "Unknown subdetid: " << subdetId;
873 
874  return layerNumber;
875 }
876 
std::auto_ptr< TrackingVertexCollection > trackingVertexes_
T getParameter(std::string const &) const
tp_iterator daughterTracks_begin() const
int i
Definition: DBlmapReader.cc:9
const TrackingParticleRefVector & sourceTracks() const
tv_iterator decayVertices_end() const
EncodedEventId eventId() const
Definition: CoreSimTrack.h:46
std::auto_ptr< TrackingParticleCollection > trackingParticles_
int event() const
get the contents of the subdetector field (should be protected?)
TPRegexp parents
Definition: eve_filter.cc:24
tv_iterator decayVertices_begin() const
void produce(edm::Event &, const edm::EventSetup &)
unsigned int layer() const
layer id
Definition: TOBDetId.h:39
TrackingParticleRefProd refMergedTrackingParticles_
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:15
std::auto_ptr< MixCollection< SimTrack > > simTracks_
std::auto_ptr< TrackingVertexCollection > mergedTrackingVertexes_
MuonPSimHitSelector muonPSimHitSelector_
std::auto_ptr< TrackingParticleCollection > mergedTrackingParticles_
PixelPSimHitSelector pixelPSimHitSelector_
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:28
EncodedEventIdToIndex eventIdCounter_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
g4t_iterator g4Track_begin() const
int pdgId() const
PDG id, signal source, crossing number.
int LayerFromDetid(const unsigned int &)
std::multimap< EncodedTruthId, unsigned int > EncodedTruthIdToIndexes
unsigned int layerNumber(align::ID)
Layer number increases with rho from 1 to 8.
Definition: TIBNameSpace.h:85
TrackingParticleRefProd refTrackingParticles_
int init
Definition: HydjetWrapper.h:63
const std::vector< PSimHit >::const_iterator pSimHit_begin() const
bool exists(std::string const &parameterName) const
checks if a parameter exists
#define abs(x)
Definition: mlp_lapack.h:159
void addDaughterTrack(const TrackingParticleRef &)
const std::vector< PSimHit >::const_iterator pSimHit_end() const
EncodedTruthIdToIndexes trackIdToHits_
#define P
TrackerPSimHitSelector trackerPSimHitSelector_
TrackingParticleSelector selector_
void clearDaughterTracks()
edm::Ref< edm::HepMCProduct, HepMC::GenParticle > GenParticleRef
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:242
void addParentTrack(const TrackingParticleRef &)
float charge() const
charge
Definition: CoreSimTrack.cc:3
void setMatchedHit(const int &)
TrackingVertexRefProd refMergedTrackingVertexes_
bool isBremsstrahlungVertex(TrackingVertex const &vertex, std::auto_ptr< TrackingParticleCollection > &tPC)
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
math::XYZTLorentzVector LorentzVector
Definition: HLTMuonBPAG.h:55
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:237
unsigned int layer() const
layer id
Definition: PXBDetId.h:35
EncodedTruthIdToIndex trackIdToIndex_
void addG4Vertex(const SimVertex &)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
SingleObjectSelector< TrackingParticleCollection,::TrackingParticleSelector > TrackingParticleSelector
TrackingVertexRefProd refTrackingVertexes_
int parentIndex() const
Definition: SimVertex.h:33
virtual void select(PSimHitCollection &, edm::Event const &, edm::EventSetup const &) const
Pre-process event information.
void associator(std::vector< PSimHit > const &, EncodedTruthIdToIndexes &)
void addPSimHit(const PSimHit &)
std::auto_ptr< MixCollection< SimVertex > > simVertexes_
T sqrt(T t)
Definition: SSEVec.h:28
int bunchCrossing() const
get the detector field from this detid
void addCloseGenVertexes(TrackingVertex &)
void addDecayVertex(const TrackingVertexRef &)
int genpartIndex() const
index of the corresponding Generator particle in the Event container (-1 if no Genpart) ...
Definition: SimTrack.h:33
TrackingTruthProducer(const edm::ParameterSet &)
bool noVertex() const
Definition: SimTrack.h:30
tuple genEvent
Definition: MCTruth.py:33
const math::XYZTLorentzVectorD & position() const
Definition: CoreSimVertex.h:26
uint32_t rawId() const
get the raw id
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
tp_iterator daughterTracks_end() const
const TrackingVertexRef & parentVertex() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
unsigned int disk() const
disk id
Definition: PXFDetId.h:43
PSimHitSelector::PSimHitCollection pSimHits_
std::vector< edm::Handle< edm::HepMCProduct > > hepMCProducts_
std::vector< SimTrack >::const_iterator g4t_iterator
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
Definition: SimTrack.h:29
edm::Ref< TrackingVertexCollection > TrackingVertexRef
Definition: DetId.h:20
edm::Ref< edm::HepMCProduct, HepMC::GenVertex > GenVertexRef
unsigned int trackId() const
Definition: CoreSimTrack.h:49
PSimHitSelector pSimHitSelector_
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
void clearParentTracks()
std::vector< TrackingVertex > TrackingVertexCollection
key_type key() const
Accessor for product key.
Definition: Ref.h:264
std::vector< std::string > dataLabels_
int setTrackingVertex(SimVertex const &, TrackingVertex &)
T const * product() const
Definition: Handle.h:74
unsigned int wheel() const
wheel id
Definition: TECDetId.h:52
unsigned short processType() const
Definition: PSimHit.h:118
unsigned int layer() const
layer id
Definition: TIBDetId.h:41
void addGenVertex(const GenVertexRef &)
const EncodedEventId & eventId() const
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:40
int particleType() const
Definition: PSimHit.h:85
void addGenParticle(const GenParticleRef &)
EncodedEventId eventId() const
Definition: CoreSimVertex.h:30
const math::XYZTLorentzVectorD & momentum() const
particle info...
Definition: CoreSimTrack.h:36
virtual void select(PSimHitCollection &, edm::Event const &, edm::EventSetup const &) const
Pre-process event information.
tuple config
Definition: cmsDriver.py:17
void addG4Track(const SimTrack &)
virtual void select(PSimHitCollection &, edm::Event const &, edm::EventSetup const &) const
Select the psimhit add them to a PSimHitCollection.
bool noParent() const
Definition: SimVertex.h:34
std::vector< TrackingParticle > TrackingParticleCollection
tuple status
Definition: ntuplemaker.py:245
virtual void select(PSimHitCollection &, edm::Event const &, edm::EventSetup const &) const
Pre-process event information.
bool setTrackingParticle(SimTrack const &, TrackingParticle &)
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
g4t_iterator g4Track_end() const
const TrackingVertexRefVector & decayVertices() const
void setParentVertex(const TrackingVertexRef &)
edm::Ref< TrackingParticleCollection > TrackingParticleRef
unsigned int detUnitId() const
Definition: PSimHit.h:93
math::PtEtaPhiELorentzVectorF LorentzVector
unsigned int wheel() const
wheel id
Definition: TIDDetId.h:50
std::map< EncodedEventId, unsigned int > EncodedEventIdToIndex
std::map< EncodedTruthId, unsigned int > EncodedTruthIdToIndex
EncodedTruthIdToIndex vertexIdToIndex_
const LorentzVector & position() const