CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
TrackingParticleNumberOfLayers Class Reference

#include <TrackingParticleNumberOfLayers.h>

Public Types

enum  { nTrackerLayers = 0, nPixelLayers = 1, nStripMonoAndStereoLayers = 2 }
 

Public Member Functions

std::tuple< std::unique_ptr< edm::ValueMap< unsigned int > >, std::unique_ptr< edm::ValueMap< unsigned int > >, std::unique_ptr< edm::ValueMap< unsigned int > > > calculate (const edm::Handle< TrackingParticleCollection > &tps, const edm::EventSetup &iSetup) const
 
 TrackingParticleNumberOfLayers (const edm::Event &iEvent, const std::vector< edm::EDGetTokenT< std::vector< PSimHit >>> &simHitTokens)
 

Private Attributes

std::vector< std::pair< unsigned int, const PSimHit * > > trackIdToHitPtr_
 

Detailed Description

This class calculates the number of tracker layers, pixel layers, and strip mono+stereo layers "crossed" by TrackingParticle.

The numbers of pixel and strip mono+stereo layers are not available from TrackingParticle itself, so they are calculated here in a standalone way in order to not to modify the TP dataformat (for now). The number of tracker layers is available in TP, but its calculation in TrackingTruthAccumulator gives wrong results (too many layers) for loopers, so also it is calculated here on the same go.

The PSimHits are needed for the calculation, so, in practice, in events with pileup the numbers of layers can be calculated only for TPs from the signal event (i.e. not for pileup TPs). Fortunately this is exactly what is sufficient for MultiTrackValidator.

Eventually we should move to use HitPattern as in reco::TrackBase (more information in a compact format), and consider adding it to the TrackingParticle itself.

In principle we could utilize the TP->SimHit map produced in SimHitTPAssociationProducer instead of doing the association here again, but

Definition at line 44 of file TrackingParticleNumberOfLayers.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
nTrackerLayers 
nPixelLayers 
nStripMonoAndStereoLayers 

Definition at line 49 of file TrackingParticleNumberOfLayers.h.

Constructor & Destructor Documentation

◆ TrackingParticleNumberOfLayers()

TrackingParticleNumberOfLayers::TrackingParticleNumberOfLayers ( const edm::Event iEvent,
const std::vector< edm::EDGetTokenT< std::vector< PSimHit >>> &  simHitTokens 
)

Definition at line 31 of file TrackingParticleNumberOfLayers.cc.

32  {
33  // A multimap linking SimTrack::trackId() to a pointer to PSimHit
34  // Similar to TrackingTruthAccumulator
35  for (const auto &simHitToken : simHitTokens) {
37  iEvent.getByToken(simHitToken, hsimhits);
38  trackIdToHitPtr_.reserve(trackIdToHitPtr_.size() + hsimhits->size());
39  for (const auto &simHit : *hsimhits) {
40  trackIdToHitPtr_.emplace_back(simHit.trackId(), &simHit);
41  }
42  }
43  std::stable_sort(trackIdToHitPtr_.begin(), trackIdToHitPtr_.end(), trackIdHitPairLessSort);
44 }

References iEvent, rpcPointValidation_cfi::simHit, SiPixelPhase1TrackingParticleV_cfi::simHitToken, and trackIdToHitPtr_.

Member Function Documentation

◆ calculate()

std::tuple< std::unique_ptr< edm::ValueMap< unsigned int > >, std::unique_ptr< edm::ValueMap< unsigned int > >, std::unique_ptr< edm::ValueMap< unsigned int > > > TrackingParticleNumberOfLayers::calculate ( const edm::Handle< TrackingParticleCollection > &  tps,
const edm::EventSetup iSetup 
) const

Definition at line 49 of file TrackingParticleNumberOfLayers.cc.

50  {
51  // Retrieve tracker topology from geometry
53  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
54  const TrackerTopology &tTopo = *tTopoHandle;
55 
56  const TrackingParticleCollection &tps = *htps;
57  std::vector<unsigned int> valuesLayers(tps.size(), 0);
58  std::vector<unsigned int> valuesPixelLayers(tps.size(), 0);
59  std::vector<unsigned int> valuesStripMonoAndStereoLayers(tps.size(), 0);
60  for (size_t iTP = 0; iTP < tps.size(); ++iTP) {
61  const TrackingParticle &tp = tps[iTP];
62  const auto pdgId = tp.pdgId();
63 
64  // I would prefer a better way...
65  constexpr unsigned int maxSubdet = static_cast<unsigned>(StripSubdetector::TEC) + 1;
66  constexpr unsigned int maxLayer = 0xF + 1; // as in HitPattern.h
67  bool hasHit[maxSubdet][maxLayer];
68  bool hasPixel[maxSubdet][maxLayer];
69  bool hasMono[maxSubdet][maxLayer];
70  bool hasStereo[maxSubdet][maxLayer];
71  memset(hasHit, 0, sizeof(hasHit));
72  memset(hasPixel, 0, sizeof(hasPixel));
73  memset(hasMono, 0, sizeof(hasMono));
74  memset(hasStereo, 0, sizeof(hasStereo));
75 
76  for (const SimTrack &simTrack : tp.g4Tracks()) {
77  // Logic is from TrackingTruthAccumulator
78  auto range = std::equal_range(trackIdToHitPtr_.begin(),
79  trackIdToHitPtr_.end(),
80  std::pair<unsigned int, const PSimHit *>(simTrack.trackId(), nullptr),
81  trackIdHitPairLess);
82  if (range.first == range.second)
83  continue;
84 
85  auto iHitPtr = range.first;
86  for (; iHitPtr != range.second; ++iHitPtr) {
87  // prevent simhits with particleType != pdgId from being the "first hit"
88  if (iHitPtr->second->particleType() == pdgId)
89  break;
90  }
91  if (iHitPtr == range.second) // no simhits with particleType == pdgId
92  continue;
93  int processType = iHitPtr->second->processType();
94  int particleType = iHitPtr->second->particleType();
95 
96  for (; iHitPtr != range.second; ++iHitPtr) {
97  const PSimHit &simHit = *(iHitPtr->second);
98  if (simHit.eventId() != tp.eventId())
99  continue;
100  DetId newDetector = DetId(simHit.detUnitId());
101 
102  // Check for delta and interaction products discards
103  if (processType == simHit.processType() && particleType == simHit.particleType() &&
104  pdgId == simHit.particleType()) {
105  // The logic of this piece follows HitPattern
106  bool isPixel = false;
107  bool isStripStereo = false;
108  bool isStripMono = false;
109 
110  switch (newDetector.subdetId()) {
113  isPixel = true;
114  break;
116  isStripMono = tTopo.tibIsRPhi(newDetector);
117  isStripStereo = tTopo.tibIsStereo(newDetector);
118  break;
120  isStripMono = tTopo.tidIsRPhi(newDetector);
121  isStripStereo = tTopo.tidIsStereo(newDetector);
122  break;
124  isStripMono = tTopo.tobIsRPhi(newDetector);
125  isStripStereo = tTopo.tobIsStereo(newDetector);
126  break;
128  isStripMono = tTopo.tecIsRPhi(newDetector);
129  isStripStereo = tTopo.tecIsStereo(newDetector);
130  break;
131  }
132 
133  const auto subdet = newDetector.subdetId();
134  const auto layer = tTopo.layer(newDetector);
135 
136  hasHit[subdet][layer] = true;
137  if (isPixel)
138  hasPixel[subdet][layer] = isPixel;
139  else if (isStripMono)
140  hasMono[subdet][layer] = isStripMono;
141  else if (isStripStereo)
142  hasStereo[subdet][layer] = isStripStereo;
143  }
144  }
145  }
146 
147  unsigned int nLayers = 0;
148  unsigned int nPixelLayers = 0;
149  unsigned int nStripMonoAndStereoLayers = 0;
150  for (unsigned int i = 0; i < maxSubdet; ++i) {
151  for (unsigned int j = 0; j < maxLayer; ++j) {
152  nLayers += hasHit[i][j];
153  nPixelLayers += hasPixel[i][j];
154  nStripMonoAndStereoLayers += (hasMono[i][j] && hasStereo[i][j]);
155  }
156  }
157 
158  valuesLayers[iTP] = nLayers;
159  valuesPixelLayers[iTP] = nPixelLayers;
160  valuesStripMonoAndStereoLayers[iTP] = nStripMonoAndStereoLayers;
161  }
162 
163  auto ret0 = std::make_unique<edm::ValueMap<unsigned int>>();
164  {
166  filler.insert(htps, valuesLayers.begin(), valuesLayers.end());
167  filler.fill();
168  }
169  auto ret1 = std::make_unique<edm::ValueMap<unsigned int>>();
170  {
172  filler.insert(htps, valuesPixelLayers.begin(), valuesPixelLayers.end());
173  filler.fill();
174  }
175  auto ret2 = std::make_unique<edm::ValueMap<unsigned int>>();
176  {
178  filler.insert(htps, valuesStripMonoAndStereoLayers.begin(), valuesStripMonoAndStereoLayers.end());
179  filler.fill();
180  }
181 
182  return std::make_tuple(std::move(ret0), std::move(ret1), std::move(ret2));
183 }

References trigObjTnPSource_cfi::filler, edm::EventSetup::get(), get, mps_fire::i, fastTrackerRecHitType::isPixel(), dqmiolumiharvest::j, phase1PixelTopology::layer, TrackerTopology::layer(), eostools::move(), MuonTCMETValueMapProducer_cff::nLayers, nPixelLayers, nStripMonoAndStereoLayers, PbPb_ZMuSkimMuonDPG_cff::particleType, EgammaValidation_cff::pdgId, PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, FastTimerService_cff::range, rpcPointValidation_cfi::simHit, cscDigiValidation_cfi::simTrack, DetId::subdetId(), StripSubdetector::TEC, TrackerTopology::tecIsRPhi(), TrackerTopology::tecIsStereo(), StripSubdetector::TIB, TrackerTopology::tibIsRPhi(), TrackerTopology::tibIsStereo(), StripSubdetector::TID, TrackerTopology::tidIsRPhi(), TrackerTopology::tidIsStereo(), StripSubdetector::TOB, TrackerTopology::tobIsRPhi(), TrackerTopology::tobIsStereo(), cmsswSequenceInfo::tp, and trackIdToHitPtr_.

Member Data Documentation

◆ trackIdToHitPtr_

std::vector<std::pair<unsigned int, const PSimHit *> > TrackingParticleNumberOfLayers::trackIdToHitPtr_
private

Definition at line 57 of file TrackingParticleNumberOfLayers.h.

Referenced by calculate(), and TrackingParticleNumberOfLayers().

FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
cscDigiValidation_cfi.simTrack
simTrack
Definition: cscDigiValidation_cfi.py:29
mps_fire.i
i
Definition: mps_fire.py:428
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
SiPixelPhase1TrackingParticleV_cfi.simHitToken
simHitToken
Definition: SiPixelPhase1TrackingParticleV_cfi.py:122
TrackerTopology::tobIsStereo
bool tobIsStereo(const DetId &id) const
Definition: TrackerTopology.h:264
TrackerTopology
Definition: TrackerTopology.h:16
TrackerTopology::tidIsRPhi
bool tidIsRPhi(const DetId &id) const
Definition: TrackerTopology.h:272
TrackerTopology::tecIsStereo
bool tecIsStereo(const DetId &id) const
Definition: TrackerTopology.h:265
TrackerTopology::layer
unsigned int layer(const DetId &id) const
Definition: TrackerTopology.cc:47
edm::Handle
Definition: AssociativeIterator.h:50
TrackingParticleNumberOfLayers::nPixelLayers
Definition: TrackingParticleNumberOfLayers.h:49
TrackerTopology::tobIsRPhi
bool tobIsRPhi(const DetId &id) const
Definition: TrackerTopology.h:269
TrackerTopology::tidIsStereo
bool tidIsStereo(const DetId &id) const
Definition: TrackerTopology.h:267
DetId
Definition: DetId.h:17
TrackerTopology::tecIsRPhi
bool tecIsRPhi(const DetId &id) const
Definition: TrackerTopology.h:270
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
rpcPointValidation_cfi.simHit
simHit
Definition: rpcPointValidation_cfi.py:24
TrackingParticle
Monte Carlo truth information used for tracking validation.
Definition: TrackingParticle.h:29
edm::ESHandle< TrackerTopology >
TrackerTopology::tibIsStereo
bool tibIsStereo(const DetId &id) const
Definition: TrackerTopology.h:266
StripSubdetector::TIB
static constexpr auto TIB
Definition: StripSubdetector.h:16
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
MuonTCMETValueMapProducer_cff.nLayers
nLayers
Definition: MuonTCMETValueMapProducer_cff.py:38
fastTrackerRecHitType::isPixel
bool isPixel(HitType hitType)
Definition: FastTrackerRecHit.h:37
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
iEvent
int iEvent
Definition: GenABIO.cc:224
EgammaValidation_cff.pdgId
pdgId
Definition: EgammaValidation_cff.py:117
TrackingParticleNumberOfLayers::nStripMonoAndStereoLayers
Definition: TrackingParticleNumberOfLayers.h:49
get
#define get
TrackingParticleNumberOfLayers::nTrackerLayers
Definition: TrackingParticleNumberOfLayers.h:49
eostools.move
def move(src, dest)
Definition: eostools.py:511
StripSubdetector::TEC
static constexpr auto TEC
Definition: StripSubdetector.h:19
SimTrack
Definition: SimTrack.h:9
TrackingParticleNumberOfLayers::trackIdToHitPtr_
std::vector< std::pair< unsigned int, const PSimHit * > > trackIdToHitPtr_
Definition: TrackingParticleNumberOfLayers.h:57
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
TrackingParticleCollection
std::vector< TrackingParticle > TrackingParticleCollection
Definition: TrackingParticleFwd.h:9
edm::helper::Filler
Definition: ValueMap.h:22
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
PSimHit
Definition: PSimHit.h:15
PbPb_ZMuSkimMuonDPG_cff.particleType
particleType
Definition: PbPb_ZMuSkimMuonDPG_cff.py:27
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
TrackerTopology::tibIsRPhi
bool tibIsRPhi(const DetId &id) const
Definition: TrackerTopology.h:271
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17