CMS 3D CMS Logo

SiPixelPhase1TrackingParticleV.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelPhase1TrackingParticleV
4 // Class: SiPixelPhase1TrackingParticleV
5 //
6 
7 // Original Author: Marcel Schneider
8 // Additional Authors: Alexander Morton - modifying code for validation use
9 
12 
15 
18 
21 
22 class TrackAssociatorByHits;
23 
24 namespace {
25  bool trackIdHitPairLess(const std::pair<unsigned int, const PSimHit *> &a,
26  const std::pair<unsigned int, const PSimHit *> &b) {
27  return a.first < b.first;
28  }
29 
30  bool trackIdHitPairLessSort(const std::pair<unsigned int, const PSimHit *> &a,
31  const std::pair<unsigned int, const PSimHit *> &b) {
32  if (a.first == b.first) {
33  const auto atof = edm::isFinite(a.second->timeOfFlight())
34  ? a.second->timeOfFlight()
35  : std::numeric_limits<decltype(a.second->timeOfFlight())>::max();
36  const auto btof = edm::isFinite(b.second->timeOfFlight())
37  ? b.second->timeOfFlight()
38  : std::numeric_limits<decltype(b.second->timeOfFlight())>::max();
39  return atof < btof;
40  }
41  return a.first < b.first;
42  }
43 } // namespace
44 
46  : SiPixelPhase1Base(iConfig),
47  vec_TrackingParticle_Token_(consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("src"))) {
48  for (const auto &tag : iConfig.getParameter<std::vector<edm::InputTag>>("simHitToken")) {
49  simHitTokens_.push_back(consumes<std::vector<PSimHit>>(tag));
50  }
51 }
52 
54  edm::Handle<TrackingParticleCollection> TruthTrackContainer;
55  iEvent.getByToken(vec_TrackingParticle_Token_, TruthTrackContainer);
56  const TrackingParticleCollection *tPC = TruthTrackContainer.product();
57  std::vector<std::pair<unsigned int, const PSimHit *>> trackIdToHitPtr;
58 
59  // A multimap linking SimTrack::trackId() to a pointer to PSimHit
60  // Similar to TrackingTruthAccumulator
61  for (const auto &simHitToken : simHitTokens_) {
63  iEvent.getByToken(simHitToken, hsimhits);
64  trackIdToHitPtr.reserve(trackIdToHitPtr.size() + hsimhits->size());
65  for (const auto &simHit : *hsimhits) {
66  trackIdToHitPtr.emplace_back(simHit.trackId(), &simHit);
67  }
68  }
69  std::stable_sort(trackIdToHitPtr.begin(), trackIdToHitPtr.end(), trackIdHitPairLessSort);
70 
71  // Loop over TrackingParticle's
72  for (TrackingParticleCollection::const_iterator t = tPC->begin(); t != tPC->end(); ++t) {
73  // histo manager requires a det ID, use first tracker hit
74 
75  bool isBpixtrack = false, isFpixtrack = false;
76  DetId id;
77 
78  for (const SimTrack &simTrack : t->g4Tracks()) {
79  // Logic is from TrackingTruthAccumulator
80  auto range = std::equal_range(trackIdToHitPtr.begin(),
81  trackIdToHitPtr.end(),
82  std::pair<unsigned int, const PSimHit *>(simTrack.trackId(), nullptr),
83  trackIdHitPairLess);
84  if (range.first == range.second)
85  continue;
86 
87  auto iHitPtr = range.first;
88  for (; iHitPtr != range.second; ++iHitPtr) {
89  const PSimHit &simHit = *(iHitPtr->second);
90  if (simHit.eventId() != t->eventId())
91  continue;
92  id = DetId(simHit.detUnitId());
93 
94  // check we are in pixel
95  uint32_t subdetid = (id.subdetId());
96  if (subdetid == PixelSubdetector::PixelBarrel)
97  isBpixtrack = true;
98  if (subdetid == PixelSubdetector::PixelEndcap)
99  isFpixtrack = true;
100  if (subdetid != PixelSubdetector::PixelBarrel && subdetid != PixelSubdetector::PixelEndcap)
101  continue;
102  }
103  }
104 
105  if (isBpixtrack || isFpixtrack) {
106  histo[MASS].fill(t->mass(), id, &iEvent);
107  histo[CHARGE].fill(t->charge(), id, &iEvent);
108  histo[ID].fill(t->pdgId(), id, &iEvent);
109  histo[NHITS].fill(t->numberOfTrackerHits(), id, &iEvent);
110  histo[MATCHED].fill(t->numberOfTrackerLayers(), id, &iEvent);
111  histo[PT].fill(sqrt(t->momentum().perp2()), id, &iEvent);
112  histo[PHI].fill(t->momentum().Phi(), id, &iEvent);
113  histo[ETA].fill(t->momentum().eta(), id, &iEvent);
114  histo[VTX].fill(t->vx(), id, &iEvent);
115  histo[VTY].fill(t->vy(), id, &iEvent);
116  histo[VYZ].fill(t->vz(), id, &iEvent);
117  histo[TIP].fill(sqrt(t->vertex().perp2()), id, &iEvent);
118  histo[LIP].fill(t->vz(), id, &iEvent);
119  }
120  }
121 }
122 
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
T const * product() const
Definition: Handle.h:70
constexpr bool isFinite(T x)
int iEvent
Definition: GenABIO.cc:224
T sqrt(T t)
Definition: SSEVec.h:19
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< TrackingParticleCollection > vec_TrackingParticle_Token_
Definition: DetId.h:17
double b
Definition: hdecay.h:118
std::vector< HistogramManager > histo
HLT enums.
double a
Definition: hdecay.h:119
void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< TrackingParticle > TrackingParticleCollection
SiPixelPhase1TrackingParticleV(const edm::ParameterSet &conf)
std::vector< edm::EDGetTokenT< std::vector< PSimHit > > > simHitTokens_