87 #include "HepPDT/ParticleID.hh"
95 #include <unordered_set>
96 #include <unordered_map>
111 using TrackingParticleRefKeyToIndex = std::unordered_map<reco::RecoToSimCollection::index_type, size_t>;
112 using TrackingVertexRefKeyToIndex = TrackingParticleRefKeyToIndex;
113 using SimHitFullKey = std::pair<TrackPSimHitRef::key_type, edm::ProductID>;
114 using SimHitRefKeyToIndex = std::map<SimHitFullKey, size_t>;
115 using TrackingParticleRefKeyToCount = TrackingParticleRefKeyToIndex;
132 return "UNKNOWN TRACKER HIT TYPE";
136 struct ProductIDSetPrinter {
137 ProductIDSetPrinter(
const std::set<edm::ProductID>& set) : set_(set) {}
139 void print(std::ostream& os)
const {
140 for (
const auto&
item : set_) {
145 const std::set<edm::ProductID>& set_;
147 std::ostream&
operator<<(std::ostream& os,
const ProductIDSetPrinter&
o) {
151 template <
typename T>
152 struct ProductIDMapPrinter {
153 ProductIDMapPrinter(
const std::map<edm::ProductID, T>&
map) : map_(
map) {}
155 void print(std::ostream& os)
const {
156 for (
const auto&
item : map_) {
157 os <<
item.first <<
" ";
161 const std::map<edm::ProductID, T>& map_;
163 template <
typename T>
164 auto make_ProductIDMapPrinter(
const std::map<edm::ProductID, T>&
map) {
165 return ProductIDMapPrinter<T>(
map);
167 template <
typename T>
168 std::ostream&
operator<<(std::ostream& os,
const ProductIDMapPrinter<T>&
o) {
173 template <
typename T>
174 struct VectorPrinter {
175 VectorPrinter(
const std::vector<T>& vec) : vec_(vec) {}
177 void print(std::ostream& os)
const {
178 for (
const auto&
item : vec_) {
183 const std::vector<T>& vec_;
185 template <
typename T>
186 auto make_VectorPrinter(
const std::vector<T>& vec) {
187 return VectorPrinter<T>(vec);
189 template <
typename T>
190 std::ostream&
operator<<(std::ostream& os,
const VectorPrinter<T>&
o) {
195 void checkProductID(
const std::set<edm::ProductID>& set,
const edm::ProductID&
id,
const char*
name) {
196 if (set.find(
id) == set.end())
198 <<
"Got " <<
name <<
" with a hit with ProductID " <<
id
199 <<
" which does not match to the set of ProductID's for the hits: " << ProductIDSetPrinter(set)
200 <<
". Usually this is caused by a wrong hit collection in the configuration.";
203 template <
typename SimLink,
typename Func>
206 if (
link.channel() == channel) {
213 template <
typename... Args>
214 void call_nop(Args&&...
args) {}
216 template <
typename...
Types>
223 unsigned int operator[](
size_t i)
const {
return std::get<0>(content_)[
i]; }
225 template <
typename... Args>
226 void book(Args&&...
args) {
227 impl([&](
auto& vec) { vec.book(std::forward<Args>(
args)...); });
230 template <
typename... Args>
231 void push_back(Args&&...
args) {
232 impl([&](
auto& vec) { vec.push_back(std::forward<Args>(
args)...); });
235 template <
typename... Args>
236 void resize(Args&&...
args) {
237 impl([&](
auto& vec) { vec.resize(std::forward<Args>(
args)...); });
240 template <
typename... Args>
241 void set(Args&&...
args) {
242 impl([&](
auto& vec) { vec.set(std::forward<Args>(
args)...); });
246 impl([&](
auto& vec) { vec.clear(); });
251 template <
typename F>
253 impl2(std::index_sequence_for<Types...>{}, std::forward<F>(
func));
261 template <std::size_t... Is,
typename F>
262 void impl2(std::index_sequence<Is...>,
F&&
func) {
263 call_nop((
func(std::get<Is>(content_)), 0)...);
266 std::tuple<
Types...> content_;
269 std::map<unsigned int, double> chargeFraction(
const SiPixelCluster& cluster,
272 std::map<unsigned int, double> simTrackIdToAdc;
274 auto idetset = digiSimLink.
find(detId);
275 if (idetset == digiSimLink.
end())
276 return simTrackIdToAdc;
280 for (
int iPix = 0; iPix != cluster.
size(); ++iPix) {
284 forEachMatchedSimLink(*idetset, channel, [&](
const PixelDigiSimLink& simLink) {
290 for (
auto& pair : simTrackIdToAdc) {
294 pair.second /= adcSum;
297 return simTrackIdToAdc;
300 std::map<unsigned int, double> chargeFraction(
const SiStripCluster& cluster,
303 std::map<unsigned int, double> simTrackIdToAdc;
305 auto idetset = digiSimLink.
find(detId);
306 if (idetset == digiSimLink.
end())
307 return simTrackIdToAdc;
319 for (
const auto& pair : simTrackIdToAdc) {
320 simTrackIdToAdc[pair.first] = (adcSum != 0. ? pair.second / adcSum : 0.);
323 return simTrackIdToAdc;
329 std::map<unsigned int, double> simTrackIdToAdc;
330 throw cms::Exception(
"LogicError") <<
"Not possible to use StripDigiSimLink with Phase2TrackerCluster1D! ";
331 return simTrackIdToAdc;
339 std::map<unsigned int, double> simTrackIdToAdc;
340 return simTrackIdToAdc;
343 struct TrackTPMatch {
345 int countClusters = 0;
350 const TrackingParticleRefKeyToIndex& tpKeyToIndex) {
356 std::vector<OmniClusterRef>
clusters =
359 std::unordered_map<int, Count>
count;
360 for (
size_t iCluster = 0,
end =
clusters.size(); iCluster <
end; ++iCluster) {
361 const auto& clusterRef =
clusters[iCluster];
364 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
365 const auto tpKey = ip->second.key();
366 if (tpKeyToIndex.find(tpKey) == tpKeyToIndex.end())
369 auto& elem =
count[tpKey];
371 elem.innermostHit =
std::min(elem.innermostHit, iCluster);
380 for (
auto& keyCount :
count) {
381 if (keyCount.second.clusters > bestCount ||
382 (keyCount.second.clusters == bestCount && keyCount.second.innermostHit < bestInnermostHit)) {
383 best.key = keyCount.first;
384 best.countClusters = bestCount = keyCount.second.clusters;
385 bestInnermostHit = keyCount.second.innermostHit;
389 LogTrace(
"TrackingNtuple") <<
"findBestMatchingTrackingParticle key " << best.key;
394 TrackTPMatch findMatchingTrackingParticleFromFirstHit(
const reco::Track&
track,
396 const TrackingParticleRefKeyToIndex& tpKeyToIndex) {
399 std::vector<OmniClusterRef>
clusters =
405 auto operateCluster = [&](
const auto& clusterRef,
const auto&
func) {
407 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
408 const auto tpKey = ip->second.key();
409 if (tpKeyToIndex.find(tpKey) == tpKeyToIndex.end())
415 std::vector<unsigned int>
418 operateCluster(*iCluster, [&](
unsigned int tpKey) { validTPs.push_back(tpKey); });
419 if (validTPs.empty()) {
423 ++best.countClusters;
425 std::vector<bool> foundTPs(validTPs.size(),
false);
426 for (
auto iEnd =
clusters.end(); iCluster != iEnd; ++iCluster) {
427 const auto& clusterRef = *iCluster;
430 operateCluster(clusterRef, [&](
unsigned int tpKey) {
432 if (
found != cend(validTPs)) {
438 auto iTP = validTPs.size();
442 if (!foundTPs[iTP]) {
443 validTPs.erase(validTPs.begin() + iTP);
444 foundTPs.erase(foundTPs.begin() + iTP);
447 if (!validTPs.empty()) {
451 best.key = validTPs[0];
457 ++best.countClusters;
461 return best.countClusters >= 3 ? best : TrackTPMatch();
502 if (
i.tpKey ==
j.tpKey) {
504 return i.detId <
j.detId;
506 return i.tof <
j.tof;
508 return i.tpKey <
j.tpKey;
514 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
519 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
520 std::set<edm::ProductID>& hitProductIds);
524 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
529 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
530 std::set<edm::ProductID>& hitProductIds);
535 std::vector<std::pair<int, int>>& monoStereoClusterList);
540 std::vector<std::pair<int, int>>& monoStereoClusterList);
544 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
549 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
550 std::set<edm::ProductID>& hitProductIds);
554 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
561 std::vector<std::pair<int, int>>& monoStereoClusterList,
562 const std::set<edm::ProductID>& hitProductIds,
563 std::map<edm::ProductID, size_t>& seedToCollIndex);
567 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
568 const TrackingParticleRefKeyToCount& tpKeyToClusterCount,
576 const std::set<edm::ProductID>& hitProductIds,
577 const std::map<edm::ProductID, size_t>& seedToCollIndex,
578 const std::vector<const MVACollection*>& mvaColls,
579 const std::vector<const QualityMaskCollection*>& qualColls);
582 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
585 SimHitRefKeyToIndex& simHitRefKeyToIndex,
586 std::vector<TPHitIndex>& tpHitList);
593 const TrackingVertexRefKeyToIndex& tvKeyToIndex,
595 const std::vector<TPHitIndex>& tpHitList,
596 const TrackingParticleRefKeyToCount& tpKeyToClusterCount);
600 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
601 const unsigned int seedOffset);
606 const TrackingParticleRefKeyToIndex& tpKeyToIndex);
616 template <
typename SimLink>
622 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
625 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
635 std::vector<edm::EDGetTokenT<edm::View<reco::Track>>>
seedTokens_;
670 #define BOOK(name) tree->Branch((prefix + "_" + #name).c_str(), &name);
686 detId.push_back(
id.rawId());
687 subdet.push_back(
id.subdetId());
691 unsigned short s = 0;
692 switch (
id.subdetId()) {
733 std::vector<unsigned short>
side;
777 const auto parsed =
parse(tTopo,
id);
778 order.push_back(parsed.order);
779 ring.push_back(parsed.ring);
780 rod.push_back(parsed.rod);
790 const auto parsed =
parse(tTopo,
id);
811 switch (
id.subdetId()) {
826 std::vector<unsigned short>
ring;
827 std::vector<unsigned short>
rod;
843 const auto parsed =
parse(tTopo,
id);
844 string.push_back(parsed.string);
848 isGlued.push_back(parsed.glued);
860 const auto parsed =
parse(tTopo,
id);
861 string[
index] = parsed.string;
880 unsigned int string = 0;
885 switch (
id.subdetId()) {
936 using DetIdPixel = CombineDetId<DetIdCommon, DetIdPixelOnly>;
937 using DetIdStrip = CombineDetId<DetIdCommon, DetIdOTCommon, DetIdStripOnly>;
938 using DetIdPhase2OT = CombineDetId<DetIdCommon, DetIdOTCommon, DetIdPhase2OTOnly>;
939 using DetIdAll = CombineDetId<DetIdCommon, DetIdPixelOnly, DetIdOTCommon, DetIdStripOnly>;
940 using DetIdAllPhase2 = CombineDetId<DetIdCommon, DetIdPixelOnly, DetIdOTCommon, DetIdPhase2OTOnly>;
1271 iConfig.getUntrackedParameter<
edm::
InputTag>(
"simHitTPMap"))),
1273 iConfig.getUntrackedParameter<
edm::
InputTag>(
"trackAssociator"))),
1275 iConfig.getUntrackedParameter<
edm::
InputTag>(
"pixelDigiSimLink"))),
1277 iConfig.getUntrackedParameter<
edm::
InputTag>(
"stripDigiSimLink"))),
1279 iConfig.getUntrackedParameter<
edm::
InputTag>(
"phase2OTSimLink"))),
1280 includeStripHits_(!iConfig.getUntrackedParameter<
edm::
InputTag>(
"stripDigiSimLink").
label().
empty()),
1281 includePhase2OTHits_(!iConfig.getUntrackedParameter<
edm::
InputTag>(
"phase2OTSimLink").
label().
empty()),
1285 stripRphiRecHitToken_(
1287 stripStereoRecHitToken_(
1290 iConfig.getUntrackedParameter<
edm::
InputTag>(
"stripMatchedRecHits"))),
1292 iConfig.getUntrackedParameter<
edm::
InputTag>(
"phase2OTRecHits"))),
1294 trackingVertexToken_(
1296 tpNLayersToken_(consumes<
edm::ValueMap<unsigned
int>>(
1297 iConfig.getUntrackedParameter<
edm::
InputTag>(
"trackingParticleNlayers"))),
1298 tpNPixelLayersToken_(consumes<
edm::ValueMap<unsigned
int>>(
1299 iConfig.getUntrackedParameter<
edm::
InputTag>(
"trackingParticleNpixellayers"))),
1300 tpNStripStereoLayersToken_(consumes<
edm::ValueMap<unsigned
int>>(
1301 iConfig.getUntrackedParameter<
edm::
InputTag>(
"trackingParticleNstripstereolayers"))),
1302 includeSeeds_(iConfig.getUntrackedParameter<
bool>(
"includeSeeds")),
1303 includeAllHits_(iConfig.getUntrackedParameter<
bool>(
"includeAllHits")),
1304 includeMVA_(iConfig.getUntrackedParameter<
bool>(
"includeMVA")),
1305 includeTrackingParticles_(iConfig.getUntrackedParameter<
bool>(
"includeTrackingParticles")) {
1309 [&](
const edm::InputTag&
tag) { return consumes<edm::View<reco::Track>>(tag); });
1312 [&](
const edm::InputTag&
tag) { return consumes<std::vector<SeedStopInfo>>(tag); });
1322 <<
"Both stripDigiSimLink and phase2OTSimLink are set, please set only either one (this information is used "
1323 "to infer if you're running phase0/1 or phase2 detector)";
1327 <<
"Neither stripDigiSimLink or phase2OTSimLink are set, please set either one.";
1344 return std::make_tuple(consumes<MVACollection>(edm::InputTag(tag,
"MVAValues")),
1345 consumes<QualityMaskCollection>(edm::InputTag(tag,
"QualityMasks")));
1351 t = fs->
make<TTree>(
"tree",
"tree");
1399 t->Branch((
"trk_mva" + std::to_string(
i + 1)).c_str(), &(
trk_mvas[
i]));
1404 t->Branch(
"trk_q", &
trk_q);
1469 t->Branch(
"sim_q", &
sim_q);
1502 t->Branch(
"pix_x", &
pix_x);
1503 t->Branch(
"pix_y", &
pix_y);
1504 t->Branch(
"pix_z", &
pix_z);
1527 t->Branch(
"str_x", &
str_x);
1528 t->Branch(
"str_y", &
str_y);
1529 t->Branch(
"str_z", &
str_z);
1546 t->Branch(
"glu_x", &
glu_x);
1547 t->Branch(
"glu_y", &
glu_y);
1548 t->Branch(
"glu_z", &
glu_z);
1570 t->Branch(
"ph2_x", &
ph2_x);
1571 t->Branch(
"ph2_y", &
ph2_y);
1572 t->Branch(
"ph2_z", &
ph2_z);
1609 t->Branch(
"bsp_x", &
bsp_x,
"bsp_x/F");
1610 t->Branch(
"bsp_y", &
bsp_y,
"bsp_y/F");
1611 t->Branch(
"bsp_z", &
bsp_z,
"bsp_z/F");
1612 t->Branch(
"bsp_sigmax", &
bsp_sigmax,
"bsp_sigmax/F");
1613 t->Branch(
"bsp_sigmay", &
bsp_sigmay,
"bsp_sigmay/F");
1614 t->Branch(
"bsp_sigmaz", &
bsp_sigmaz,
"bsp_sigmaz/F");
1638 t->Branch(
"see_q", &
see_q);
1668 t->Branch(
"vtx_x", &
vtx_x);
1669 t->Branch(
"vtx_y", &
vtx_y);
1670 t->Branch(
"vtx_z", &
vtx_z);
1992 using namespace edm;
1993 using namespace reco;
1994 using namespace std;
2005 LogDebug(
"TrackingNtuple") <<
"Analyzing new event";
2020 for (
size_t i = 0,
size = TPCollectionH->size();
i <
size; ++
i) {
2026 tmpTPptr = TPCollectionHRefVector.
product();
2031 TrackingParticleRefKeyToIndex tpKeyToIndex;
2032 for (
size_t i = 0;
i < tpCollection.
size(); ++
i) {
2033 tpKeyToIndex[tpCollection[
i].key()] =
i;
2043 TrackingVertexRefKeyToIndex tvKeyToIndex;
2044 for (
size_t i = 0;
i < tvs.size(); ++
i) {
2046 if (
v.eventId().bunchCrossing() != 0)
2048 tvKeyToIndex[
i] = tvRefs.
size();
2060 TrackingParticleRefKeyToCount tpKeyToClusterCount;
2061 for (
const auto& clusterTP : clusterToTPMap) {
2062 tpKeyToClusterCount[clusterTP.second.key()] += 1;
2066 SimHitRefKeyToIndex simHitRefKeyToIndex;
2069 std::vector<TPHitIndex> tpHitList;
2073 std::set<edm::ProductID> hitProductIds;
2074 std::map<edm::ProductID, size_t> seedCollToOffset;
2083 const auto& pixelDigiSimLinks = *pixelDigiSimLinksHandle;
2099 vector<pair<int, int>> monoStereoClusterList;
2103 fillSimHits(
tracker, tpKeyToIndex, *simHitsTPAssoc, tTopo, simHitRefKeyToIndex, tpHitList);
2114 simHitRefKeyToIndex,
2119 LogDebug(
"TrackingNtuple") <<
"foundStripSimLink";
2120 const auto& stripDigiSimLinks = *stripDigiSimLinksHandle;
2128 simHitRefKeyToIndex,
2136 LogDebug(
"TrackingNtuple") <<
"foundPhase2OTSimLinks";
2137 const auto& phase2OTSimLinks = *siphase2OTSimLinksHandle;
2145 simHitRefKeyToIndex,
2161 monoStereoClusterList,
2175 std::vector<const MVACollection*> mvaColls;
2176 std::vector<const QualityMaskCollection*> qualColls;
2182 iEvent.getByToken(std::get<0>(tokenTpl), hmva);
2183 iEvent.getByToken(std::get<1>(tokenTpl), hqual);
2185 mvaColls.push_back(hmva.
product());
2186 qualColls.push_back(hqual.
product());
2187 if (mvaColls.back()->size() !=
tracks.size()) {
2189 <<
"Inconsistency in track collection and MVA sizes. Track collection has " <<
tracks.size()
2190 <<
" tracks, whereas the MVA " << (mvaColls.size() - 1) <<
" has " << mvaColls.back()->size()
2191 <<
" entries. Double-check your configuration.";
2193 if (qualColls.back()->size() !=
tracks.size()) {
2195 <<
"Inconsistency in track collection and quality mask sizes. Track collection has " <<
tracks.size()
2196 <<
" tracks, whereas the quality mask " << (qualColls.size() - 1) <<
" has " << qualColls.back()->size()
2197 <<
" entries. Double-check your configuration.";
2208 tpKeyToClusterCount,
2225 iEvent, iSetup, trackRefs,
bs, tpCollection, tvKeyToIndex, associatorByHits, tpHitList, tpKeyToClusterCount);
2246 template <
typename SimLink>
2258 template <
typename SimLink>
2265 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2268 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
2272 std::map<unsigned int, double> simTrackIdToChargeFraction;
2276 simTrackIdToChargeFraction = chargeFraction(GetCluster<SimLink>::call(cluster), hitId,
digiSimLinks);
2281 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
2285 const auto event = trackingParticle->eventId().event();
2286 const auto bx = trackingParticle->eventId().bunchCrossing();
2291 ret.type = static_cast<HitSimType>(
std::min(static_cast<int>(
ret.type), static_cast<int>(
type)));
2294 auto tpIndex = tpKeyToIndex.find(trackingParticle.
key());
2295 if (tpIndex == tpKeyToIndex.end())
2299 std::pair<TrackingParticleRef, TrackPSimHitRef> simHitTPpairWithDummyTP(trackingParticle,
TrackPSimHitRef());
2301 auto range = std::equal_range(simHitsTPAssoc.begin(),
2302 simHitsTPAssoc.end(),
2303 simHitTPpairWithDummyTP,
2305 bool foundSimHit =
false;
2306 bool foundElectron =
false;
2307 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
2312 if (
std::abs(TPhit->particleType()) == 11 &&
std::abs(trackingParticle->pdgId()) != 11) {
2313 foundElectron =
true;
2318 auto simHitKey = TPhit.
key();
2319 auto simHitID = TPhit.
id();
2321 auto simHitIndex = simHitRefKeyToIndex.at(std::make_pair(simHitKey, simHitID));
2322 ret.matchingSimHit.push_back(simHitIndex);
2324 double chargeFraction = 0.;
2325 for (
const SimTrack& simtrk : trackingParticle->g4Tracks()) {
2326 auto found = simTrackIdToChargeFraction.find(simtrk.trackId());
2327 if (
found != simTrackIdToChargeFraction.end()) {
2328 chargeFraction +=
found->second;
2331 ret.chargeFraction.push_back(chargeFraction);
2334 ret.bunchCrossing.push_back(
bx);
2338 simhit_hitType[simHitIndex].push_back(static_cast<int>(hitType));
2348 <<
"Did not find SimHit for reco hit DetId " << hitId.
rawId() <<
" for TP " << trackingParticle.
key()
2349 <<
" bx:event " <<
bx <<
":" <<
event <<
".\nFound SimHits from detectors ";
2350 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
2353 ex << dId.
rawId() <<
" ";
2355 if (trackingParticle->eventId().event() != 0) {
2356 ex <<
"\nSince this is a TrackingParticle from pileup, check that you're running the pileup mixing in "
2368 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2371 SimHitRefKeyToIndex& simHitRefKeyToIndex,
2372 std::vector<TPHitIndex>& tpHitList) {
2373 for (
const auto&
assoc : simHitsTPAssoc) {
2374 auto tpKey =
assoc.first.key();
2378 auto found = tpKeyToIndex.find(tpKey);
2379 if (
found == tpKeyToIndex.end())
2381 const auto tpIndex =
found->second;
2384 const auto& simhit = *(
assoc.second);
2385 auto detId =
DetId(simhit.detUnitId());
2397 auto simHitKey = std::make_pair(
assoc.second.key(),
assoc.second.id());
2399 if (simHitRefKeyToIndex.find(simHitKey) != simHitRefKeyToIndex.end()) {
2400 for (
const auto& assoc2 : simHitsTPAssoc) {
2401 if (std::make_pair(assoc2.second.key(), assoc2.second.id()) == simHitKey) {
2403 auto range1 = std::equal_range(simHitsTPAssoc.begin(),
2404 simHitsTPAssoc.end(),
2407 auto range2 = std::equal_range(simHitsTPAssoc.begin(),
2408 simHitsTPAssoc.end(),
2412 LogTrace(
"TrackingNtuple") <<
"Earlier TP " << assoc2.first.key() <<
" SimTrack Ids";
2413 for (
const auto&
simTrack : assoc2.first->g4Tracks()) {
2415 <<
simTrack.eventId().bunchCrossing() <<
":" <<
simTrack.eventId().event();
2417 for (
auto iHit = range2.first; iHit != range2.second; ++iHit) {
2418 LogTrace(
"TrackingNtuple") <<
" SimHit " << iHit->second.key() <<
" " << iHit->second.id() <<
" tof "
2419 << iHit->second->tof() <<
" trackId " << iHit->second->trackId() <<
" BX:event "
2420 << iHit->second->eventId().bunchCrossing() <<
":"
2421 << iHit->second->eventId().event();
2423 LogTrace(
"TrackingNtuple") <<
"Current TP " <<
assoc.first.key() <<
" SimTrack Ids";
2426 <<
simTrack.eventId().bunchCrossing() <<
":" <<
simTrack.eventId().event();
2428 for (
auto iHit = range1.first; iHit != range1.second; ++iHit) {
2429 LogTrace(
"TrackingNtuple") <<
" SimHit " << iHit->second.key() <<
" " << iHit->second.id() <<
" tof "
2430 << iHit->second->tof() <<
" trackId " << iHit->second->trackId() <<
" BX:event "
2431 << iHit->second->eventId().bunchCrossing() <<
":"
2432 << iHit->second->eventId().event();
2437 <<
"Got second time the SimHit " << simHitKey.first <<
" of " << simHitKey.second
2438 <<
", first time with TrackingParticle " << assoc2.first.key() <<
", now with " << tpKey;
2441 throw cms::Exception(
"LogicError") <<
"Got second time the SimHit " << simHitKey.first <<
" of "
2442 << simHitKey.second <<
", now with TrackingParticle " << tpKey
2443 <<
", but I didn't find the first occurrance!";
2446 auto det =
tracker.idToDetUnit(detId);
2448 throw cms::Exception(
"LogicError") <<
"Did not find a det unit for DetId " << simhit.detUnitId()
2449 <<
" from tracker geometry";
2451 const auto pos = det->surface().toGlobal(simhit.localPosition());
2452 const float tof = simhit.timeOfFlight();
2454 const auto simHitIndex =
simhit_x.size();
2455 simHitRefKeyToIndex[simHitKey] = simHitIndex;
2475 tpHitList.emplace_back(tpKey, simHitIndex, tof, simhit.detUnitId());
2481 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2486 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
2487 std::set<edm::ProductID>& hitProductIds) {
2490 for (
auto it = pixelHits->
begin(); it != pixelHits->
end(); it++) {
2491 const DetId hitId = it->detId();
2492 for (
auto hit = it->begin();
hit != it->end();
hit++) {
2495 hitProductIds.insert(
hit->cluster().
id());
2497 const int key =
hit->cluster().key();
2498 const int lay = tTopo.
layer(hitId);
2504 pix_x.push_back(ttrh->globalPosition().x());
2505 pix_y.push_back(ttrh->globalPosition().y());
2506 pix_z.push_back(ttrh->globalPosition().z());
2507 pix_xx.push_back(ttrh->globalPositionError().cxx());
2508 pix_xy.push_back(ttrh->globalPositionError().cyx());
2509 pix_yy.push_back(ttrh->globalPositionError().cyy());
2510 pix_yz.push_back(ttrh->globalPositionError().czy());
2511 pix_zz.push_back(ttrh->globalPositionError().czz());
2512 pix_zx.push_back(ttrh->globalPositionError().czx());
2513 pix_radL.push_back(ttrh->surface()->mediumProperties().radLen());
2514 pix_bbxi.push_back(ttrh->surface()->mediumProperties().xi());
2516 LogTrace(
"TrackingNtuple") <<
"pixHit cluster=" <<
key <<
" subdId=" << hitId.
subdetId() <<
" lay=" << lay
2517 <<
" rawId=" << hitId.
rawId() <<
" pos =" << ttrh->globalPosition();
2527 simHitRefKeyToIndex,
2535 LogTrace(
"TrackingNtuple") <<
" firstMatchingSimHit=" << simHitIdx <<
" simHitPos="
2541 <<
" event=" << simHitData.
event[0];
2550 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2555 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
2556 std::set<edm::ProductID>& hitProductIds) {
2570 str_x.resize(totalStripHits);
2571 str_y.resize(totalStripHits);
2572 str_z.resize(totalStripHits);
2573 str_xx.resize(totalStripHits);
2574 str_xy.resize(totalStripHits);
2575 str_yy.resize(totalStripHits);
2576 str_yz.resize(totalStripHits);
2577 str_zz.resize(totalStripHits);
2578 str_zx.resize(totalStripHits);
2583 for (
const auto& detset :
hits) {
2584 const DetId hitId = detset.detId();
2585 for (
const auto&
hit : detset) {
2588 hitProductIds.insert(
hit.cluster().
id());
2590 const int key =
hit.cluster().key();
2591 const int lay = tTopo.
layer(hitId);
2594 str_x[
key] = ttrh->globalPosition().x();
2595 str_y[
key] = ttrh->globalPosition().y();
2596 str_z[
key] = ttrh->globalPosition().z();
2597 str_xx[
key] = ttrh->globalPositionError().cxx();
2598 str_xy[
key] = ttrh->globalPositionError().cyx();
2599 str_yy[
key] = ttrh->globalPositionError().cyy();
2600 str_yz[
key] = ttrh->globalPositionError().czy();
2601 str_zz[
key] = ttrh->globalPositionError().czz();
2602 str_zx[
key] = ttrh->globalPositionError().czx();
2603 str_radL[
key] = ttrh->surface()->mediumProperties().radLen();
2604 str_bbxi[
key] = ttrh->surface()->mediumProperties().xi();
2606 <<
" rawId=" << hitId.
rawId() <<
" pos =" << ttrh->globalPosition();
2617 simHitRefKeyToIndex,
2625 LogTrace(
"TrackingNtuple") <<
" firstMatchingSimHit=" << simHitIdx <<
" simHitPos="
2633 <<
" event=" << simHitData.
event[0];
2640 fill(*rphiHits,
"stripRPhiHit");
2641 fill(*stereoHits,
"stripStereoHit");
2647 std::vector<std::pair<int, int>>& monoStereoClusterList) {
2649 const auto hitId =
hit.geographicalId();
2650 const int lay = tTopo.
layer(hitId);
2651 monoStereoClusterList.emplace_back(
hit.monoHit().cluster().key(),
hit.stereoHit().cluster().key());
2657 glu_x.push_back(ttrh->globalPosition().x());
2658 glu_y.push_back(ttrh->globalPosition().y());
2659 glu_z.push_back(ttrh->globalPosition().z());
2660 glu_xx.push_back(ttrh->globalPositionError().cxx());
2661 glu_xy.push_back(ttrh->globalPositionError().cyx());
2662 glu_yy.push_back(ttrh->globalPositionError().cyy());
2663 glu_yz.push_back(ttrh->globalPositionError().czy());
2664 glu_zz.push_back(ttrh->globalPositionError().czz());
2665 glu_zx.push_back(ttrh->globalPositionError().czx());
2666 glu_radL.push_back(ttrh->surface()->mediumProperties().radLen());
2667 glu_bbxi.push_back(ttrh->surface()->mediumProperties().xi());
2668 LogTrace(
"TrackingNtuple") <<
"stripMatchedHit"
2669 <<
" cluster0=" <<
hit.stereoHit().cluster().key()
2670 <<
" cluster1=" <<
hit.monoHit().cluster().key() <<
" subdId=" << hitId.subdetId()
2671 <<
" lay=" << lay <<
" rawId=" << hitId.rawId() <<
" pos =" << ttrh->globalPosition();
2678 std::vector<std::pair<int, int>>& monoStereoClusterList) {
2681 for (
auto it = matchedHits->
begin(); it != matchedHits->
end(); it++) {
2682 for (
auto hit = it->begin();
hit != it->end();
hit++) {
2690 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2695 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
2696 std::set<edm::ProductID>& hitProductIds) {
2699 for (
auto it = phase2OTHits->
begin(); it != phase2OTHits->
end(); it++) {
2700 const DetId hitId = it->detId();
2701 for (
auto hit = it->begin();
hit != it->end();
hit++) {
2704 hitProductIds.insert(
hit->cluster().
id());
2706 const int key =
hit->cluster().key();
2707 const int lay = tTopo.
layer(hitId);
2713 ph2_x.push_back(ttrh->globalPosition().x());
2714 ph2_y.push_back(ttrh->globalPosition().y());
2715 ph2_z.push_back(ttrh->globalPosition().z());
2716 ph2_xx.push_back(ttrh->globalPositionError().cxx());
2717 ph2_xy.push_back(ttrh->globalPositionError().cyx());
2718 ph2_yy.push_back(ttrh->globalPositionError().cyy());
2719 ph2_yz.push_back(ttrh->globalPositionError().czy());
2720 ph2_zz.push_back(ttrh->globalPositionError().czz());
2721 ph2_zx.push_back(ttrh->globalPositionError().czx());
2722 ph2_radL.push_back(ttrh->surface()->mediumProperties().radLen());
2723 ph2_bbxi.push_back(ttrh->surface()->mediumProperties().xi());
2725 LogTrace(
"TrackingNtuple") <<
"phase2 OT cluster=" <<
key <<
" subdId=" << hitId.
subdetId() <<
" lay=" << lay
2726 <<
" rawId=" << hitId.
rawId() <<
" pos =" << ttrh->globalPosition();
2737 simHitRefKeyToIndex,
2744 LogTrace(
"TrackingNtuple") <<
" firstMatchingSimHit=" << simHitIdx <<
" simHitPos="
2750 <<
" event=" << simHitData.
event[0];
2759 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2766 std::vector<std::pair<int, int>>& monoStereoClusterList,
2767 const std::set<edm::ProductID>& hitProductIds,
2768 std::map<edm::ProductID, size_t>& seedCollToOffset) {
2770 for (
size_t iColl = 0; iColl <
seedTokens_.size(); ++iColl) {
2774 iEvent.getByToken(seedToken, seedTracksHandle);
2785 iEvent.getByToken(seedStopInfoToken, seedStopInfoHandle);
2786 const auto& seedStopInfos = *seedStopInfoHandle;
2787 if (
seedTracks.size() != seedStopInfos.size()) {
2792 <<
" seed stopping infos for collections " <<
labels.module <<
", "
2806 label.ReplaceAll(
"seedTracks",
"");
2807 label.ReplaceAll(
"Seeds",
"");
2808 label.ReplaceAll(
"muonSeeded",
"muonSeededStep");
2813 auto inserted = seedCollToOffset.emplace(
id,
offset);
2814 if (!inserted.second)
2816 <<
"Trying to add seeds with ProductID " <<
id <<
" for a second time from collection " <<
labels.module
2817 <<
", seed algo " <<
label <<
". Typically this is caused by a configuration problem.";
2821 <<
" ProductID " <<
id;
2823 for (
size_t iSeed = 0; iSeed < seedTrackRefs.
size(); ++iSeed) {
2824 const auto& seedTrackRef = seedTrackRefs[iSeed];
2825 const auto& seedTrack = *seedTrackRef;
2826 const auto& seedRef = seedTrack.seedRef();
2827 const auto&
seed = *seedRef;
2829 const auto seedStopInfo = seedStopInfos[iSeed];
2831 if (seedRef.id() !=
id)
2833 <<
"All tracks in 'TracksFromSeeds' collection should point to seeds in the same collection. Now the "
2834 "element 0 had ProductID "
2835 <<
id <<
" while the element " << seedTrackRef.key() <<
" had " << seedTrackRef.id()
2836 <<
". The source collection is " <<
labels.module <<
".";
2838 std::vector<int> tpIdx;
2839 std::vector<float> sharedFraction;
2840 auto foundTPs = recSimColl.
find(seedTrackRef);
2841 if (foundTPs != recSimColl.
end()) {
2842 for (
const auto& tpQuality : foundTPs->val) {
2843 tpIdx.push_back(tpKeyToIndex.at(tpQuality.first.key()));
2844 sharedFraction.push_back(tpQuality.second);
2849 const int nHits = seedTrack.numberOfValidHits();
2851 seedTrack.recHitsBegin(),
2852 seedTrack.recHitsEnd());
2854 const auto bestKeyCount = findBestMatchingTrackingParticle(seedTrack, clusterToTPMap, tpKeyToIndex);
2855 const float bestShareFrac =
2856 nClusters > 0 ? static_cast<float>(bestKeyCount.countClusters) / static_cast<float>(
nClusters) : 0;
2858 const auto bestFirstHitKeyCount =
2859 findMatchingTrackingParticleFromFirstHit(seedTrack, clusterToTPMap, tpKeyToIndex);
2860 const float bestFirstHitShareFrac =
2861 nClusters > 0 ? static_cast<float>(bestFirstHitKeyCount.countClusters) / static_cast<float>(
nClusters) : 0;
2864 const int charge = seedTrack.charge();
2865 const float pt = seedFitOk ? seedTrack.pt() : 0;
2866 const float eta = seedFitOk ? seedTrack.eta() : 0;
2867 const float phi = seedFitOk ? seedTrack.phi() : 0;
2869 const auto seedIndex =
see_fitok.size();
2873 see_px.push_back(seedFitOk ? seedTrack.px() : 0);
2874 see_py.push_back(seedFitOk ? seedTrack.py() : 0);
2875 see_pz.push_back(seedFitOk ? seedTrack.pz() : 0);
2882 see_dxy.push_back(seedFitOk ? seedTrack.dxy(
bs.position()) : 0);
2883 see_dz.push_back(seedFitOk ? seedTrack.dz(
bs.position()) : 0);
2884 see_ptErr.push_back(seedFitOk ? seedTrack.ptError() : 0);
2885 see_etaErr.push_back(seedFitOk ? seedTrack.etaError() : 0);
2886 see_phiErr.push_back(seedFitOk ? seedTrack.phiError() : 0);
2887 see_dxyErr.push_back(seedFitOk ? seedTrack.dxyError() : 0);
2888 see_dzErr.push_back(seedFitOk ? seedTrack.dzError() : 0);
2891 see_nCands.push_back(seedStopInfo.candidatesPerSeed());
2893 const auto&
state = seedTrack.seedRef()->startingState();
2894 const auto&
pos =
state.parameters().position();
2895 const auto& mom =
state.parameters().momentum();
2907 see_bestSimTrkIdx.push_back(bestKeyCount.key >= 0 ? tpKeyToIndex.at(bestKeyCount.key) : -1);
2909 bestFirstHitKeyCount.key >= 0 ? tpKeyToIndex.at(bestFirstHitKeyCount.key) : -1);
2928 std::vector<int> hitIdx;
2929 std::vector<int> hitType;
2931 for (
auto const&
hit :
seed.recHits()) {
2933 int subid =
recHit->geographicalId().subdetId();
2939 checkProductID(hitProductIds, clusterRef.id(),
"seed");
2942 hitIdx.push_back(clusterKey);
2955 std::vector<std::pair<int, int>>::iterator
pos =
2956 find(monoStereoClusterList.begin(), monoStereoClusterList.end(), std::make_pair(monoIdx, stereoIdx));
2957 size_t gluedIndex = -1;
2958 if (
pos != monoStereoClusterList.end()) {
2965 gluedIndex =
addStripMatchedHit(*matchedHit, theTTRHBuilder, tTopo, monoStereoClusterList);
2970 hitIdx.push_back(gluedIndex);
2975 unsigned int clusterKey;
2976 if (clusterRef.isPhase2()) {
2979 clusterKey = clusterRef.cluster_strip().key();
2983 checkProductID(hitProductIds, clusterRef.id(),
"seed");
2984 if (clusterRef.isPhase2()) {
2991 hitIdx.push_back(clusterKey);
2992 if (clusterRef.isPhase2()) {
2999 LogTrace(
"TrackingNtuple") <<
" not pixel and not Strip detector";
3014 std::vector<GlobalPoint>
gp(2);
3015 std::vector<GlobalError> ge(2);
3016 gp[0] = recHit0->globalPosition();
3017 ge[0] = recHit0->globalPositionError();
3018 gp[1] = recHit1->globalPosition();
3019 ge[1] = recHit1->globalPositionError();
3021 <<
"seed " << seedTrackRef.key() <<
" pt=" <<
pt <<
" eta=" <<
eta <<
" phi=" <<
phi <<
" q=" <<
charge
3022 <<
" - PAIR - ids: " << recHit0->geographicalId().rawId() <<
" " << recHit1->geographicalId().rawId()
3023 <<
" hitpos: " <<
gp[0] <<
" " <<
gp[1] <<
" trans0: "
3024 << (recHit0->transientHits().size() > 1 ? recHit0->transientHits()[0]->globalPosition()
3027 << (recHit0->transientHits().size() > 1 ? recHit0->transientHits()[1]->globalPosition()
3030 << (recHit1->transientHits().size() > 1 ? recHit1->transientHits()[0]->globalPosition()
3033 << (recHit1->transientHits().size() > 1 ? recHit1->transientHits()[1]->globalPosition()
3035 <<
" eta,phi: " <<
gp[0].
eta() <<
"," <<
gp[0].phi();
3036 }
else if (
nHits == 3) {
3043 gp[0] = recHit0->globalPosition();
3044 ge[0] = recHit0->globalPositionError();
3045 int subid0 = recHit0->geographicalId().subdetId();
3048 gp[1] = recHit1->globalPosition();
3049 ge[1] = recHit1->globalPositionError();
3050 int subid1 = recHit1->geographicalId().subdetId();
3053 gp[2] = recHit2->globalPosition();
3054 ge[2] = recHit2->globalPositionError();
3055 int subid2 = recHit2->geographicalId().subdetId();
3059 float seed_chi2 = rzLine.
chi2();
3063 <<
"seed " << seedTrackRef.key() <<
" pt=" <<
pt <<
" eta=" <<
eta <<
" phi=" <<
phi <<
" q=" <<
charge
3064 <<
" - TRIPLET - ids: " << recHit0->geographicalId().rawId() <<
" " << recHit1->geographicalId().rawId()
3065 <<
" " << recHit2->geographicalId().rawId() <<
" hitpos: " <<
gp[0] <<
" " <<
gp[1] <<
" " <<
gp[2]
3067 << (recHit0->transientHits().size() > 1 ? recHit0->transientHits()[0]->globalPosition()
3070 << (recHit0->transientHits().size() > 1 ? recHit0->transientHits()[1]->globalPosition()
3073 << (recHit1->transientHits().size() > 1 ? recHit1->transientHits()[0]->globalPosition()
3076 << (recHit1->transientHits().size() > 1 ? recHit1->transientHits()[1]->globalPosition()
3079 << (recHit2->transientHits().size() > 1 ? recHit2->transientHits()[0]->globalPosition()
3082 << (recHit2->transientHits().size() > 1 ? recHit2->transientHits()[1]->globalPosition()
3085 << recHit2->localPosition()
3087 <<
" eta,phi: " <<
gp[0].eta() <<
"," <<
gp[0].phi() <<
" pt,chi2: " << seed_pt <<
"," << seed_chi2;
3099 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
3100 const TrackingParticleRefKeyToCount& tpKeyToClusterCount,
3108 const std::set<edm::ProductID>& hitProductIds,
3109 const std::map<edm::ProductID, size_t>& seedCollToOffset,
3110 const std::vector<const MVACollection*>& mvaColls,
3111 const std::vector<const QualityMaskCollection*>& qualColls) {
3115 LogTrace(
"TrackingNtuple") <<
"NEW TRACK LABEL: " <<
labels.module;
3117 auto pvPosition =
vertices[0].position();
3119 for (
size_t iTrack = 0; iTrack <
tracks.size(); ++iTrack) {
3120 const auto& itTrack =
tracks[iTrack];
3121 int charge = itTrack->charge();
3122 float pt = itTrack->pt();
3123 float eta = itTrack->eta();
3124 const double lambda = itTrack->lambda();
3125 float chi2 = itTrack->normalizedChi2();
3126 float ndof = itTrack->ndof();
3127 float phi = itTrack->phi();
3128 int nHits = itTrack->numberOfValidHits();
3131 const auto& tkParam = itTrack->parameters();
3132 auto tkCov = itTrack->covariance();
3137 bool isSimMatched =
false;
3138 std::vector<int> tpIdx;
3139 std::vector<float> sharedFraction;
3140 std::vector<float> tpChi2;
3141 auto foundTPs = recSimColl.
find(itTrack);
3142 if (foundTPs != recSimColl.
end()) {
3143 if (!foundTPs->val.empty()) {
3144 nSimHits = foundTPs->val[0].first->numberOfTrackerHits();
3145 isSimMatched =
true;
3147 for (
const auto& tpQuality : foundTPs->val) {
3148 tpIdx.push_back(tpKeyToIndex.at(tpQuality.first.key()));
3149 sharedFraction.push_back(tpQuality.second);
3156 itTrack->recHitsBegin(),
3157 itTrack->recHitsEnd());
3160 const auto bestKeyCount = findBestMatchingTrackingParticle(*itTrack, clusterToTPMap, tpKeyToIndex);
3161 const float bestShareFrac = static_cast<float>(bestKeyCount.countClusters) / static_cast<float>(
nClusters);
3162 float bestShareFracSimDenom = 0;
3163 float bestShareFracSimClusterDenom = 0;
3164 float bestChi2 = -1;
3165 if (bestKeyCount.key >= 0) {
3166 bestShareFracSimDenom =
3167 static_cast<float>(bestKeyCount.countClusters) /
3168 static_cast<float>(tpCollection[tpKeyToIndex.at(bestKeyCount.key)]->numberOfTrackerHits());
3169 bestShareFracSimClusterDenom =
3170 static_cast<float>(bestKeyCount.countClusters) / static_cast<float>(tpKeyToClusterCount.at(bestKeyCount.key));
3172 tkParam, tkCov, *(tpCollection[tpKeyToIndex.at(bestKeyCount.key)]), mf,
bs);
3175 const auto bestFirstHitKeyCount = findMatchingTrackingParticleFromFirstHit(*itTrack, clusterToTPMap, tpKeyToIndex);
3176 const float bestFirstHitShareFrac =
3177 static_cast<float>(bestFirstHitKeyCount.countClusters) / static_cast<float>(
nClusters);
3178 float bestFirstHitShareFracSimDenom = 0;
3179 float bestFirstHitShareFracSimClusterDenom = 0;
3180 float bestFirstHitChi2 = -1;
3181 if (bestFirstHitKeyCount.key >= 0) {
3182 bestFirstHitShareFracSimDenom =
3183 static_cast<float>(bestFirstHitKeyCount.countClusters) /
3184 static_cast<float>(tpCollection[tpKeyToIndex.at(bestFirstHitKeyCount.key)]->numberOfTrackerHits());
3185 bestFirstHitShareFracSimClusterDenom = static_cast<float>(bestFirstHitKeyCount.countClusters) /
3186 static_cast<float>(tpKeyToClusterCount.at(bestFirstHitKeyCount.key));
3188 tkParam, tkCov, *(tpCollection[tpKeyToIndex.at(bestFirstHitKeyCount.key)]), mf,
bs);
3191 float chi2_1Dmod =
chi2;
3192 int count1dhits = 0;
3193 for (
auto iHit = itTrack->recHitsBegin(), iEnd = itTrack->recHitsEnd(); iHit != iEnd; ++iHit) {
3198 if (count1dhits > 0) {
3199 chi2_1Dmod = (
chi2 + count1dhits) / (
ndof + count1dhits);
3204 trk_px.push_back(itTrack->px());
3205 trk_py.push_back(itTrack->py());
3206 trk_pz.push_back(itTrack->pz());
3211 trk_inner_pt.push_back(itTrack->innerMomentum().rho());
3215 trk_outer_pt.push_back(itTrack->outerMomentum().rho());
3220 trk_dxy.push_back(itTrack->dxy(
bs.position()));
3221 trk_dz.push_back(itTrack->dz(
bs.position()));
3222 trk_dxyPV.push_back(itTrack->dxy(pvPosition));
3223 trk_dzPV.push_back(itTrack->dz(pvPosition));
3226 trk_ptErr.push_back(itTrack->ptError());
3231 trk_dzErr.push_back(itTrack->dzError());
3250 trk_n3DLay.push_back(
hp.numberOfValidStripLayersWithMonoAndStereo() +
hp.pixelLayersWithMeasurement());
3253 trk_algo.push_back(itTrack->algo());
3260 trk_mvas[
i].push_back((*(mvaColls[
i]))[iTrack]);
3265 auto offset = seedCollToOffset.find(itTrack->seedRef().id());
3266 if (
offset == seedCollToOffset.end()) {
3270 << itTrack->seedRef().id()
3271 <<
", but that seed collection is not given as an input. The following collections were given as an input "
3272 << make_ProductIDMapPrinter(seedCollToOffset);
3275 const auto seedIndex =
offset->second + itTrack->seedRef().key();
3278 throw cms::Exception(
"LogicError") <<
"Track index has already been set for seed " << seedIndex <<
" to "
3279 <<
see_trkIdx[seedIndex] <<
"; was trying to set it to " << iTrack;
3288 trk_bestSimTrkIdx.push_back(bestKeyCount.key >= 0 ? tpKeyToIndex.at(bestKeyCount.key) : -1);
3303 LogTrace(
"TrackingNtuple") <<
"Track #" << itTrack.key() <<
" with q=" <<
charge <<
", pT=" <<
pt
3304 <<
" GeV, eta: " <<
eta <<
", phi: " <<
phi <<
", chi2=" <<
chi2 <<
", Nhits=" <<
nHits
3305 <<
", algo=" << itTrack->algoName(itTrack->algo()).c_str()
3307 <<
" seed#=" << itTrack->seedRef().key() <<
" simMatch=" << isSimMatched
3308 <<
" nSimHits=" << nSimHits
3309 <<
" sharedFraction=" << (sharedFraction.empty() ? -1 : sharedFraction[0])
3310 <<
" tpIdx=" << (tpIdx.empty() ? -1 : tpIdx[0]);
3311 std::vector<int> hitIdx;
3312 std::vector<int> hitType;
3314 for (
auto i = itTrack->recHitsBegin();
i != itTrack->recHitsEnd();
i++) {
3316 DetId hitId =
hit->geographicalId();
3324 if (
hit->isValid()) {
3328 unsigned int clusterKey;
3329 if (clusterRef.isPixel()) {
3331 }
else if (clusterRef.isPhase2()) {
3332 clusterKey = clusterRef.cluster_phase2OT().key();
3334 clusterKey = clusterRef.cluster_strip().key();
3337 LogTrace(
"TrackingNtuple") <<
" id: " << hitId.
rawId() <<
" - globalPos =" <<
hit->globalPosition()
3338 <<
" cluster=" << clusterKey <<
" clusterRef ID=" << clusterRef.
id()
3339 <<
" eta,phi: " <<
hit->globalPosition().eta() <<
"," <<
hit->globalPosition().phi();
3341 checkProductID(hitProductIds, clusterRef.id(),
"track");
3342 if (clusterRef.isPixel()) {
3344 }
else if (clusterRef.isPhase2()) {
3351 hitIdx.push_back(clusterKey);
3352 if (clusterRef.isPixel()) {
3354 }
else if (clusterRef.isPhase2()) {
3360 LogTrace(
"TrackingNtuple") <<
" - invalid hit";
3384 const TrackingVertexRefKeyToIndex& tvKeyToIndex,
3386 const std::vector<TPHitIndex>& tpHitList,
3387 const TrackingParticleRefKeyToCount& tpKeyToClusterCount) {
3393 const auto& nLayers_tPCeff = *tpNLayersH;
3396 const auto& nPixelLayers_tPCeff = *tpNLayersH;
3399 const auto& nStripMonoAndStereoLayers_tPCeff = *tpNLayersH;
3404 LogTrace(
"TrackingNtuple") <<
"tracking particle pt=" <<
tp->pt() <<
" eta=" <<
tp->eta() <<
" phi=" <<
tp->phi();
3405 bool isRecoMatched =
false;
3406 std::vector<int> tkIdx;
3407 std::vector<float> sharedFraction;
3408 auto foundTracks = simRecColl.
find(
tp);
3409 if (foundTracks != simRecColl.
end()) {
3410 isRecoMatched =
true;
3418 for (
const auto& genRef :
tp->genParticles()) {
3419 if (genRef.isNonnull())
3423 bool isFromBHadron =
false;
3428 for (
const auto& particle : recoGenParticleTrail) {
3431 isFromBHadron =
true;
3437 LogTrace(
"TrackingNtuple") <<
"matched to tracks = " << make_VectorPrinter(tkIdx)
3438 <<
" isRecoMatched=" << isRecoMatched;
3449 sim_q.push_back(
tp->charge());
3453 std::vector<int> decayIdx;
3454 for (
const auto&
v :
tp->decayVertices())
3455 decayIdx.push_back(tvKeyToIndex.at(
v.key()));
3463 const double lambdaSim =
M_PI / 2 - momentum.theta();
3472 std::vector<int> hitIdx;
3473 int nPixel = 0, nStrip = 0;
3475 for (
auto ip = rangeHit.first; ip != rangeHit.second; ++ip) {
3479 LogTrace(
"TrackingNtuple") <<
"simhit=" << ip->simHitIdx <<
" type=" << static_cast<int>(
type);
3480 hitIdx.push_back(ip->simHitIdx);
3483 throw cms::Exception(
"LogicError") <<
"Encountered SimHit for TP " <<
tp.key() <<
" with DetId "
3484 << detid.rawId() <<
" whose det() is not Tracker but " << detid.det();
3486 const auto subdet = detid.subdetId();
3499 throw cms::Exception(
"LogicError") <<
"Encountered SimHit for TP " <<
tp.key() <<
" with DetId "
3500 << detid.rawId() <<
" whose subdet is not recognized, is " << subdet;
3507 const auto nSimLayers = nLayers_tPCeff[
tp];
3508 const auto nSimPixelLayers = nPixelLayers_tPCeff[
tp];
3509 const auto nSimStripMonoAndStereoLayers = nStripMonoAndStereoLayers_tPCeff[
tp];
3512 sim_n3DLay.push_back(nSimPixelLayers + nSimStripMonoAndStereoLayers);
3515 auto found = tpKeyToClusterCount.find(
tp.key());
3525 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
3526 const unsigned int seedOffset) {
3530 for (
const auto& keyVal : simRecColl) {
3531 const auto& tpRef = keyVal.key;
3532 auto found = tpKeyToIndex.find(tpRef.key());
3533 if (
found == tpKeyToIndex.end())
3534 throw cms::Exception(
"Assert") << __FILE__ <<
":" << __LINE__ <<
" fillTrackingParticlesForSeeds: tpRef.key() "
3535 << tpRef.key() <<
" not found from tpKeyToIndex. tpKeyToIndex size "
3536 << tpKeyToIndex.size();
3537 const auto tpIndex =
found->second;
3538 for (
const auto& pair : keyVal.val) {
3539 const auto& seedRef = pair.first->seedRef();
3540 sim_seedIdx[tpIndex].push_back(seedOffset + seedRef.key());
3547 for (
size_t iVertex = 0,
size =
vertices.size(); iVertex <
size; ++iVertex) {
3560 std::vector<int> trkIdx;
3561 for (
auto iTrack =
vertex.tracks_begin(); iTrack !=
vertex.tracks_end(); ++iTrack) {
3563 if (iTrack->id() !=
tracks.id())
3566 trkIdx.push_back(iTrack->key());
3569 throw cms::Exception(
"LogicError") <<
"Vertex index has already been set for track " << iTrack->key() <<
" to "
3570 <<
trk_vtxIdx[iTrack->key()] <<
"; was trying to set it to " << iVertex;
3579 const TrackingParticleRefKeyToIndex& tpKeyToIndex) {
3580 int current_event = -1;
3581 for (
const auto& ref : trackingVertices) {
3583 if (
v.eventId().event() != current_event) {
3585 current_event =
v.eventId().event();
3590 if (!
v.g4Vertices().empty()) {
3591 processType =
v.g4Vertices()[0].processType();
3603 for (
const auto& tpRef : tps) {
3604 auto found = tpKeyToIndex.find(tpRef.key());
3605 if (
found != tpKeyToIndex.end()) {
3611 std::vector<int> sourceIdx;
3612 std::vector<int> daughterIdx;
3613 fill(
v.sourceTracks(), sourceIdx);
3614 fill(
v.daughterTracks(), daughterIdx);
3626 desc.addUntracked<std::vector<edm::InputTag>>(
3628 std::vector<edm::InputTag>{
edm::InputTag(
"seedTracksinitialStepSeeds"),
3638 desc.addUntracked<std::vector<edm::InputTag>>(
3640 std::vector<edm::InputTag>{
edm::InputTag(
"initialStepTrackCandidates"),
3651 desc.addUntracked<std::vector<std::string>>(
"trackMVAs", std::vector<std::string>{{
"generalTracks"}});
3653 desc.addUntracked<
bool>(
"trackingParticlesRef",
false);
3669 edm::InputTag(
"trackingParticleNumberOfLayersProducer",
"trackerLayers"));
3671 edm::InputTag(
"trackingParticleNumberOfLayersProducer",
"pixelLayers"));
3673 edm::InputTag(
"trackingParticleNumberOfLayersProducer",
"stripStereoLayers"));
3675 desc.addUntracked<
std::string>(
"parametersDefiner",
"LhcParametersDefinerForTP");
3676 desc.addUntracked<
bool>(
"includeSeeds",
false);
3677 desc.addUntracked<
bool>(
"includeAllHits",
false);
3678 desc.addUntracked<
bool>(
"includeMVA",
true);
3679 desc.addUntracked<
bool>(
"includeTrackingParticles",
true);
3680 descriptions.
add(
"trackingNtuple",
desc);