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 
SiPixelPhase1TrackingParticleV.h
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
SiPixelPhase1TrackingParticleV::PHI
Definition: SiPixelPhase1TrackingParticleV.h:29
SiPixelPhase1TrackingParticleV::MASS
Definition: SiPixelPhase1TrackingParticleV.h:23
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
edm::Handle::product
T const * product() const
Definition: Handle.h:70
SiPixelPhase1TrackingParticleV_cfi.simHitToken
simHitToken
Definition: SiPixelPhase1TrackingParticleV_cfi.py:122
ESHandle.h
edm
HLT enums.
Definition: AlignableModifier.h:19
PSimHitContainer.h
SiPixelPhase1TrackingParticleV::vec_TrackingParticle_Token_
edm::EDGetTokenT< TrackingParticleCollection > vec_TrackingParticle_Token_
Definition: SiPixelPhase1TrackingParticleV.h:43
SiPixelPhase1TrackingParticleV::CHARGE
Definition: SiPixelPhase1TrackingParticleV.h:24
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
HistogramManagerHolder::histo
std::vector< HistogramManager > histo
Definition: SiPixelPhase1Base.h:37
edm::Handle< TrackingParticleCollection >
SiPixelPhase1TrackingParticleV::TIP
Definition: SiPixelPhase1TrackingParticleV.h:34
SiPixelPhase1TrackingParticleV::ETA
Definition: SiPixelPhase1TrackingParticleV.h:30
SiPixelPhase1Base
Definition: SiPixelPhase1Base.h:46
SiPixelPhase1TrackingParticleV::PT
Definition: SiPixelPhase1TrackingParticleV.h:28
DetId
Definition: DetId.h:17
MakerMacros.h
SiPixelPhase1TrackingParticleV::SiPixelPhase1TrackingParticleV
SiPixelPhase1TrackingParticleV(const edm::ParameterSet &conf)
Definition: SiPixelPhase1TrackingParticleV.cc:45
PSimHit.h
SiPixelPhase1TrackingParticleV::VTY
Definition: SiPixelPhase1TrackingParticleV.h:32
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
SiPixelPhase1TrackingParticleV::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: SiPixelPhase1TrackingParticleV.cc:53
rpcPointValidation_cfi.simHit
simHit
Definition: rpcPointValidation_cfi.py:24
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
SiPixelPhase1TrackingParticleV::simHitTokens_
std::vector< edm::EDGetTokenT< std::vector< PSimHit > > > simHitTokens_
Definition: SiPixelPhase1TrackingParticleV.h:44
SiPixelPhase1TrackingParticleV::LIP
Definition: SiPixelPhase1TrackingParticleV.h:35
b
double b
Definition: hdecay.h:118
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
SiPixelPhase1TrackingParticleV::MATCHED
Definition: SiPixelPhase1TrackingParticleV.h:27
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
SiPixelPhase1TrackingParticleV::ID
Definition: SiPixelPhase1TrackingParticleV.h:25
muonSimHitMatcherPSet.simTrack
simTrack
Definition: muonSimHitMatcherPSet.py:4
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
SiPixelPhase1TrackingParticleV::VYZ
Definition: SiPixelPhase1TrackingParticleV.h:33
SiPixelPhase1TrackingParticleV::NHITS
Definition: SiPixelPhase1TrackingParticleV.h:26
isFinite.h
SimTrack
Definition: SimTrack.h:6
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
DetIdAssociator.h
LocalPoint.h
TrackingParticleCollection
std::vector< TrackingParticle > TrackingParticleCollection
Definition: TrackingParticleFwd.h:8
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::isFinite
constexpr bool isFinite(T x)
SiPixelPhase1TrackingParticleV
Definition: SiPixelPhase1TrackingParticleV.h:21
PSimHit
Definition: PSimHit.h:15
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
SiPixelPhase1TrackingParticleV::VTX
Definition: SiPixelPhase1TrackingParticleV.h:31