89 #include "HepPDT/ParticleID.hh"
97 #include <unordered_set>
98 #include <unordered_map>
113 using TrackingParticleRefKeyToIndex = std::unordered_map<reco::RecoToSimCollection::index_type, size_t>;
114 using TrackingVertexRefKeyToIndex = TrackingParticleRefKeyToIndex;
115 using SimHitFullKey = std::pair<TrackPSimHitRef::key_type, edm::ProductID>;
116 using SimHitRefKeyToIndex = std::map<SimHitFullKey, size_t>;
117 using TrackingParticleRefKeyToCount = TrackingParticleRefKeyToIndex;
134 return "UNKNOWN TRACKER HIT TYPE";
138 struct ProductIDSetPrinter {
139 ProductIDSetPrinter(
const std::set<edm::ProductID>& set) : set_(set) {}
141 void print(std::ostream& os)
const {
142 for (
const auto&
item : set_) {
147 const std::set<edm::ProductID>& set_;
149 std::ostream&
operator<<(std::ostream& os,
const ProductIDSetPrinter&
o) {
153 template <
typename T>
154 struct ProductIDMapPrinter {
155 ProductIDMapPrinter(
const std::map<edm::ProductID, T>&
map) : map_(
map) {}
157 void print(std::ostream& os)
const {
158 for (
const auto&
item : map_) {
159 os <<
item.first <<
" ";
163 const std::map<edm::ProductID, T>& map_;
165 template <
typename T>
166 auto make_ProductIDMapPrinter(
const std::map<edm::ProductID, T>&
map) {
167 return ProductIDMapPrinter<T>(
map);
169 template <
typename T>
170 std::ostream&
operator<<(std::ostream& os,
const ProductIDMapPrinter<T>&
o) {
175 template <
typename T>
176 struct VectorPrinter {
177 VectorPrinter(
const std::vector<T>& vec) : vec_(vec) {}
179 void print(std::ostream& os)
const {
180 for (
const auto&
item : vec_) {
185 const std::vector<T>& vec_;
187 template <
typename T>
188 auto make_VectorPrinter(
const std::vector<T>& vec) {
189 return VectorPrinter<T>(vec);
191 template <
typename T>
192 std::ostream&
operator<<(std::ostream& os,
const VectorPrinter<T>&
o) {
197 void checkProductID(
const std::set<edm::ProductID>& set,
const edm::ProductID&
id,
const char*
name) {
198 if (set.find(
id) == set.end())
200 <<
"Got " <<
name <<
" with a hit with ProductID " <<
id
201 <<
" which does not match to the set of ProductID's for the hits: " << ProductIDSetPrinter(set)
202 <<
". Usually this is caused by a wrong hit collection in the configuration.";
205 template <
typename SimLink,
typename Func>
208 if (
link.channel() == channel) {
215 template <
typename... Args>
216 void call_nop(Args&&...
args) {}
218 template <
typename...
Types>
225 unsigned int operator[](
size_t i)
const {
return std::get<0>(content_)[
i]; }
227 template <
typename... Args>
228 void book(Args&&...
args) {
229 impl([&](
auto& vec) { vec.book(std::forward<Args>(
args)...); });
232 template <
typename... Args>
233 void push_back(Args&&...
args) {
234 impl([&](
auto& vec) { vec.push_back(std::forward<Args>(
args)...); });
237 template <
typename... Args>
238 void resize(Args&&...
args) {
239 impl([&](
auto& vec) { vec.resize(std::forward<Args>(
args)...); });
242 template <
typename... Args>
243 void set(Args&&...
args) {
244 impl([&](
auto& vec) { vec.set(std::forward<Args>(
args)...); });
248 impl([&](
auto& vec) { vec.clear(); });
253 template <
typename F>
255 impl2(std::index_sequence_for<Types...>{}, std::forward<F>(
func));
263 template <std::size_t... Is,
typename F>
264 void impl2(std::index_sequence<Is...>,
F&&
func) {
265 call_nop((
func(std::get<Is>(content_)), 0)...);
268 std::tuple<
Types...> content_;
271 std::map<unsigned int, double> chargeFraction(
const SiPixelCluster& cluster,
274 std::map<unsigned int, double> simTrackIdToAdc;
276 auto idetset = digiSimLink.
find(detId);
277 if (idetset == digiSimLink.
end())
278 return simTrackIdToAdc;
282 for (
int iPix = 0; iPix != cluster.
size(); ++iPix) {
286 forEachMatchedSimLink(*idetset, channel, [&](
const PixelDigiSimLink& simLink) {
292 for (
auto& pair : simTrackIdToAdc) {
296 pair.second /= adcSum;
299 return simTrackIdToAdc;
302 std::map<unsigned int, double> chargeFraction(
const SiStripCluster& cluster,
305 std::map<unsigned int, double> simTrackIdToAdc;
307 auto idetset = digiSimLink.
find(detId);
308 if (idetset == digiSimLink.
end())
309 return simTrackIdToAdc;
321 for (
const auto& pair : simTrackIdToAdc) {
322 simTrackIdToAdc[pair.first] = (adcSum != 0. ? pair.second / adcSum : 0.);
325 return simTrackIdToAdc;
331 std::map<unsigned int, double> simTrackIdToAdc;
332 throw cms::Exception(
"LogicError") <<
"Not possible to use StripDigiSimLink with Phase2TrackerCluster1D! ";
333 return simTrackIdToAdc;
341 std::map<unsigned int, double> simTrackIdToAdc;
342 return simTrackIdToAdc;
345 struct TrackTPMatch {
347 int countClusters = 0;
352 const TrackingParticleRefKeyToIndex& tpKeyToIndex) {
358 std::vector<OmniClusterRef>
clusters =
361 std::unordered_map<int, Count>
count;
362 for (
size_t iCluster = 0,
end =
clusters.size(); iCluster <
end; ++iCluster) {
363 const auto& clusterRef =
clusters[iCluster];
366 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
367 const auto tpKey = ip->second.key();
368 if (tpKeyToIndex.find(tpKey) == tpKeyToIndex.end())
371 auto& elem =
count[tpKey];
373 elem.innermostHit =
std::min(elem.innermostHit, iCluster);
382 for (
auto& keyCount :
count) {
383 if (keyCount.second.clusters > bestCount ||
384 (keyCount.second.clusters == bestCount && keyCount.second.innermostHit < bestInnermostHit)) {
385 best.key = keyCount.first;
386 best.countClusters = bestCount = keyCount.second.clusters;
387 bestInnermostHit = keyCount.second.innermostHit;
391 LogTrace(
"TrackingNtuple") <<
"findBestMatchingTrackingParticle key " << best.key;
396 TrackTPMatch findMatchingTrackingParticleFromFirstHit(
const reco::Track&
track,
398 const TrackingParticleRefKeyToIndex& tpKeyToIndex) {
401 std::vector<OmniClusterRef>
clusters =
407 auto operateCluster = [&](
const auto& clusterRef,
const auto&
func) {
409 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
410 const auto tpKey = ip->second.key();
411 if (tpKeyToIndex.find(tpKey) == tpKeyToIndex.end())
417 std::vector<unsigned int>
420 operateCluster(*iCluster, [&](
unsigned int tpKey) { validTPs.push_back(tpKey); });
421 if (validTPs.empty()) {
425 ++best.countClusters;
427 std::vector<bool> foundTPs(validTPs.size(),
false);
428 for (
auto iEnd =
clusters.end(); iCluster != iEnd; ++iCluster) {
429 const auto& clusterRef = *iCluster;
432 operateCluster(clusterRef, [&](
unsigned int tpKey) {
434 if (
found != cend(validTPs)) {
440 auto iTP = validTPs.size();
444 if (!foundTPs[iTP]) {
445 validTPs.erase(validTPs.begin() + iTP);
446 foundTPs.erase(foundTPs.begin() + iTP);
449 if (!validTPs.empty()) {
453 best.key = validTPs[0];
459 ++best.countClusters;
463 return best.countClusters >= 3 ? best : TrackTPMatch();
507 if (
i.tpKey ==
j.tpKey) {
509 return i.detId <
j.detId;
511 return i.tof <
j.tof;
513 return i.tpKey <
j.tpKey;
519 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
524 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
525 std::set<edm::ProductID>& hitProductIds);
529 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
534 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
535 std::set<edm::ProductID>& hitProductIds);
540 std::vector<std::pair<int, int>>& monoStereoClusterList);
545 const std::vector<std::pair<uint64_t, StripMaskContainer const*>>& stripMasks,
546 std::vector<std::pair<int, int>>& monoStereoClusterList);
550 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
555 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
556 std::set<edm::ProductID>& hitProductIds);
560 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
567 std::vector<std::pair<int, int>>& monoStereoClusterList,
568 const std::set<edm::ProductID>& hitProductIds,
569 std::map<edm::ProductID, size_t>& seedToCollIndex);
573 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
574 const TrackingParticleRefKeyToCount& tpKeyToClusterCount,
582 const std::set<edm::ProductID>& hitProductIds,
583 const std::map<edm::ProductID, size_t>& seedToCollIndex,
584 const std::vector<const MVACollection*>& mvaColls,
585 const std::vector<const QualityMaskCollection*>& qualColls);
588 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
591 SimHitRefKeyToIndex& simHitRefKeyToIndex,
592 std::vector<TPHitIndex>& tpHitList);
599 const TrackingVertexRefKeyToIndex& tvKeyToIndex,
601 const std::vector<TPHitIndex>& tpHitList,
602 const TrackingParticleRefKeyToCount& tpKeyToClusterCount);
606 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
607 const unsigned int seedOffset);
612 const TrackingParticleRefKeyToIndex& tpKeyToIndex);
623 template <
typename SimLink>
629 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
632 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
642 std::vector<edm::EDGetTokenT<edm::View<reco::Track>>>
seedTokens_;
688 #define BOOK(name) tree->Branch((prefix + "_" + #name).c_str(), &name);
704 detId.push_back(
id.rawId());
705 subdet.push_back(
id.subdetId());
709 unsigned short s = 0;
710 switch (
id.subdetId()) {
751 std::vector<unsigned short>
side;
795 const auto parsed =
parse(tTopo,
id);
796 order.push_back(parsed.order);
797 ring.push_back(parsed.ring);
798 rod.push_back(parsed.rod);
808 const auto parsed =
parse(tTopo,
id);
829 switch (
id.subdetId()) {
844 std::vector<unsigned short>
ring;
845 std::vector<unsigned short>
rod;
861 const auto parsed =
parse(tTopo,
id);
862 string.push_back(parsed.string);
866 isGlued.push_back(parsed.glued);
878 const auto parsed =
parse(tTopo,
id);
879 string[
index] = parsed.string;
898 unsigned int string = 0;
903 switch (
id.subdetId()) {
954 using DetIdPixel = CombineDetId<DetIdCommon, DetIdPixelOnly>;
955 using DetIdStrip = CombineDetId<DetIdCommon, DetIdOTCommon, DetIdStripOnly>;
956 using DetIdPhase2OT = CombineDetId<DetIdCommon, DetIdOTCommon, DetIdPhase2OTOnly>;
957 using DetIdAll = CombineDetId<DetIdCommon, DetIdPixelOnly, DetIdOTCommon, DetIdStripOnly>;
958 using DetIdAllPhase2 = CombineDetId<DetIdCommon, DetIdPixelOnly, DetIdOTCommon, DetIdPhase2OTOnly>;
1313 iConfig.getUntrackedParameter<
edm::
InputTag>(
"simHitTPMap"))),
1315 iConfig.getUntrackedParameter<
edm::
InputTag>(
"trackAssociator"))),
1317 iConfig.getUntrackedParameter<
edm::
InputTag>(
"pixelDigiSimLink"))),
1319 iConfig.getUntrackedParameter<
edm::
InputTag>(
"stripDigiSimLink"))),
1321 iConfig.getUntrackedParameter<
edm::
InputTag>(
"phase2OTSimLink"))),
1322 includeStripHits_(!iConfig.getUntrackedParameter<
edm::
InputTag>(
"stripDigiSimLink").
label().
empty()),
1323 includePhase2OTHits_(!iConfig.getUntrackedParameter<
edm::
InputTag>(
"phase2OTSimLink").
label().
empty()),
1327 stripRphiRecHitToken_(
1329 stripStereoRecHitToken_(
1332 iConfig.getUntrackedParameter<
edm::
InputTag>(
"stripMatchedRecHits"))),
1334 iConfig.getUntrackedParameter<
edm::
InputTag>(
"phase2OTRecHits"))),
1336 trackingVertexToken_(
1338 tpNLayersToken_(consumes<
edm::ValueMap<unsigned
int>>(
1339 iConfig.getUntrackedParameter<
edm::
InputTag>(
"trackingParticleNlayers"))),
1340 tpNPixelLayersToken_(consumes<
edm::ValueMap<unsigned
int>>(
1341 iConfig.getUntrackedParameter<
edm::
InputTag>(
"trackingParticleNpixellayers"))),
1342 tpNStripStereoLayersToken_(consumes<
edm::ValueMap<unsigned
int>>(
1343 iConfig.getUntrackedParameter<
edm::
InputTag>(
"trackingParticleNstripstereolayers"))),
1344 includeSeeds_(iConfig.getUntrackedParameter<
bool>(
"includeSeeds")),
1345 addSeedCurvCov_(iConfig.getUntrackedParameter<
bool>(
"addSeedCurvCov")),
1346 includeAllHits_(iConfig.getUntrackedParameter<
bool>(
"includeAllHits")),
1347 includeMVA_(iConfig.getUntrackedParameter<
bool>(
"includeMVA")),
1348 includeTrackingParticles_(iConfig.getUntrackedParameter<
bool>(
"includeTrackingParticles")),
1349 includeOOT_(iConfig.getUntrackedParameter<
bool>(
"includeOOT")),
1350 keepEleSimHits_(iConfig.getUntrackedParameter<
bool>(
"keepEleSimHits")),
1351 saveSimHitsP3_(iConfig.getUntrackedParameter<
bool>(
"saveSimHitsP3")),
1352 simHitBySignificance_(iConfig.getUntrackedParameter<
bool>(
"simHitBySignificance")) {
1356 [&](
const edm::InputTag&
tag) { return consumes<edm::View<reco::Track>>(tag); });
1359 [&](
const edm::InputTag&
tag) { return consumes<std::vector<SeedStopInfo>>(tag); });
1369 <<
"Both stripDigiSimLink and phase2OTSimLink are set, please set only either one (this information is used "
1370 "to infer if you're running phase0/1 or phase2 detector)";
1374 <<
"Neither stripDigiSimLink or phase2OTSimLink are set, please set either one.";
1380 for (
auto const& mask : maskVPset) {
1381 auto index = mask.getUntrackedParameter<
unsigned int>(
"index");
1384 consumes<PixelMaskContainer>(mask.getUntrackedParameter<
edm::InputTag>(
"src")));
1387 index, consumes<StripMaskContainer>(mask.getUntrackedParameter<
edm::InputTag>(
"src")));
1404 return std::make_tuple(consumes<MVACollection>(edm::InputTag(tag,
"MVAValues")),
1405 consumes<QualityMaskCollection>(edm::InputTag(tag,
"QualityMasks")));
1411 t = fs->
make<TTree>(
"tree",
"tree");
1459 t->Branch((
"trk_mva" + std::to_string(
i + 1)).c_str(), &(
trk_mvas[
i]));
1464 t->Branch(
"trk_q", &
trk_q);
1529 t->Branch(
"sim_q", &
sim_q);
1565 t->Branch(
"pix_x", &
pix_x);
1566 t->Branch(
"pix_y", &
pix_y);
1567 t->Branch(
"pix_z", &
pix_z);
1595 t->Branch(
"str_x", &
str_x);
1596 t->Branch(
"str_y", &
str_y);
1597 t->Branch(
"str_z", &
str_z);
1617 t->Branch(
"glu_x", &
glu_x);
1618 t->Branch(
"glu_y", &
glu_y);
1619 t->Branch(
"glu_z", &
glu_z);
1649 t->Branch(
"ph2_x", &
ph2_x);
1650 t->Branch(
"ph2_y", &
ph2_y);
1651 t->Branch(
"ph2_z", &
ph2_z);
1693 t->Branch(
"bsp_x", &
bsp_x,
"bsp_x/F");
1694 t->Branch(
"bsp_y", &
bsp_y,
"bsp_y/F");
1695 t->Branch(
"bsp_z", &
bsp_z,
"bsp_z/F");
1696 t->Branch(
"bsp_sigmax", &
bsp_sigmax,
"bsp_sigmax/F");
1697 t->Branch(
"bsp_sigmay", &
bsp_sigmay,
"bsp_sigmay/F");
1698 t->Branch(
"bsp_sigmaz", &
bsp_sigmaz,
"bsp_sigmaz/F");
1731 t->Branch(
"see_q", &
see_q);
1761 t->Branch(
"vtx_x", &
vtx_x);
1762 t->Branch(
"vtx_y", &
vtx_y);
1763 t->Branch(
"vtx_z", &
vtx_z);
2109 using namespace edm;
2110 using namespace reco;
2111 using namespace std;
2122 LogDebug(
"TrackingNtuple") <<
"Analyzing new event";
2137 for (
size_t i = 0,
size = TPCollectionH->size();
i <
size; ++
i) {
2143 tmpTPptr = TPCollectionHRefVector.
product();
2148 TrackingParticleRefKeyToIndex tpKeyToIndex;
2149 for (
size_t i = 0;
i < tpCollection.
size(); ++
i) {
2150 tpKeyToIndex[tpCollection[
i].key()] =
i;
2160 TrackingVertexRefKeyToIndex tvKeyToIndex;
2161 for (
size_t i = 0;
i < tvs.size(); ++
i) {
2165 tvKeyToIndex[
i] = tvRefs.
size();
2177 TrackingParticleRefKeyToCount tpKeyToClusterCount;
2178 for (
const auto& clusterTP : clusterToTPMap) {
2179 tpKeyToClusterCount[clusterTP.second.key()] += 1;
2183 SimHitRefKeyToIndex simHitRefKeyToIndex;
2186 std::vector<TPHitIndex> tpHitList;
2190 std::set<edm::ProductID> hitProductIds;
2191 std::map<edm::ProductID, size_t> seedCollToOffset;
2200 const auto& pixelDigiSimLinks = *pixelDigiSimLinksHandle;
2216 vector<pair<int, int>> monoStereoClusterList;
2220 fillSimHits(
tracker, tpKeyToIndex, *simHitsTPAssoc, tTopo, simHitRefKeyToIndex, tpHitList);
2231 simHitRefKeyToIndex,
2236 LogDebug(
"TrackingNtuple") <<
"foundStripSimLink";
2237 const auto& stripDigiSimLinks = *stripDigiSimLinksHandle;
2245 simHitRefKeyToIndex,
2253 LogDebug(
"TrackingNtuple") <<
"foundPhase2OTSimLinks";
2254 const auto& phase2OTSimLinks = *siphase2OTSimLinksHandle;
2262 simHitRefKeyToIndex,
2278 monoStereoClusterList,
2292 std::vector<const MVACollection*> mvaColls;
2293 std::vector<const QualityMaskCollection*> qualColls;
2299 iEvent.getByToken(std::get<0>(tokenTpl), hmva);
2300 iEvent.getByToken(std::get<1>(tokenTpl), hqual);
2302 mvaColls.push_back(hmva.
product());
2303 qualColls.push_back(hqual.
product());
2304 if (mvaColls.back()->size() !=
tracks.size()) {
2306 <<
"Inconsistency in track collection and MVA sizes. Track collection has " <<
tracks.size()
2307 <<
" tracks, whereas the MVA " << (mvaColls.size() - 1) <<
" has " << mvaColls.back()->size()
2308 <<
" entries. Double-check your configuration.";
2310 if (qualColls.back()->size() !=
tracks.size()) {
2312 <<
"Inconsistency in track collection and quality mask sizes. Track collection has " <<
tracks.size()
2313 <<
" tracks, whereas the quality mask " << (qualColls.size() - 1) <<
" has " << qualColls.back()->size()
2314 <<
" entries. Double-check your configuration.";
2325 tpKeyToClusterCount,
2342 iEvent, iSetup, trackRefs,
bs, tpCollection, tvKeyToIndex, associatorByHits, tpHitList, tpKeyToClusterCount);
2363 template <
typename SimLink>
2375 template <
typename SimLink>
2382 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2385 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
2389 std::map<unsigned int, double> simTrackIdToChargeFraction;
2393 simTrackIdToChargeFraction = chargeFraction(GetCluster<SimLink>::call(cluster), hitId,
digiSimLinks);
2395 float h_x = 0, h_y = 0;
2396 float h_xx = 0, h_xy = 0, h_yy = 0;
2398 h_x = ttrh->localPosition().x();
2399 h_y = ttrh->localPosition().y();
2400 h_xx = ttrh->localPositionError().xx();
2401 h_xy = ttrh->localPositionError().xy();
2402 h_yy = ttrh->localPositionError().yy();
2408 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
2412 const auto event = trackingParticle->eventId().event();
2413 const auto bx = trackingParticle->eventId().bunchCrossing();
2419 ret.type = static_cast<HitSimType>(
std::min(static_cast<int>(
ret.type), static_cast<int>(
type)));
2422 auto tpIndex = tpKeyToIndex.find(trackingParticle.
key());
2423 if (tpIndex == tpKeyToIndex.end())
2427 std::pair<TrackingParticleRef, TrackPSimHitRef> simHitTPpairWithDummyTP(trackingParticle,
TrackPSimHitRef());
2429 auto range = std::equal_range(simHitsTPAssoc.begin(),
2430 simHitsTPAssoc.end(),
2431 simHitTPpairWithDummyTP,
2433 bool foundSimHit =
false;
2434 bool foundElectron =
false;
2435 int foundElectrons = 0;
2436 int foundNonElectrons = 0;
2437 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
2442 if (
std::abs(TPhit->particleType()) == 11 &&
std::abs(trackingParticle->pdgId()) != 11) {
2445 foundNonElectrons++;
2455 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
2460 if (
std::abs(TPhit->particleType()) == 11 &&
std::abs(trackingParticle->pdgId()) != 11) {
2461 foundElectron =
true;
2466 float sx = TPhit->localPosition().x();
2467 float sy = TPhit->localPosition().y();
2468 float dx =
sx - h_x;
2469 float dy =
sy - h_y;
2470 float sig = (
dx *
dx * h_yy - 2 *
dx *
dy * h_xy +
dy *
dy * h_xx) / (h_xx * h_yy - h_xy * h_xy);
2475 simHitKey = TPhit.
key();
2476 simHitID = TPhit.
id();
2481 auto simHitIndex = simHitRefKeyToIndex.at(std::make_pair(simHitKey, simHitID));
2482 ret.matchingSimHit.push_back(simHitIndex);
2484 double chargeFraction = 0.;
2485 for (
const SimTrack& simtrk : trackingParticle->g4Tracks()) {
2486 auto found = simTrackIdToChargeFraction.find(simtrk.trackId());
2487 if (
found != simTrackIdToChargeFraction.end()) {
2488 chargeFraction +=
found->second;
2492 ret.chargeFraction.push_back(chargeFraction);
2495 ret.bunchCrossing.push_back(
bx);
2499 simhit_hitType[simHitIndex].push_back(static_cast<int>(hitType));
2502 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
2507 if (
std::abs(TPhit->particleType()) == 11 &&
std::abs(trackingParticle->pdgId()) != 11) {
2508 foundElectron =
true;
2511 if (foundNonElectrons > 0)
2516 auto simHitKey = TPhit.
key();
2517 auto simHitID = TPhit.
id();
2519 auto simHitIndex = simHitRefKeyToIndex.at(std::make_pair(simHitKey, simHitID));
2520 ret.matchingSimHit.push_back(simHitIndex);
2522 double chargeFraction = 0.;
2523 for (
const SimTrack& simtrk : trackingParticle->g4Tracks()) {
2524 auto found = simTrackIdToChargeFraction.find(simtrk.trackId());
2525 if (
found != simTrackIdToChargeFraction.end()) {
2526 chargeFraction +=
found->second;
2530 ret.chargeFraction.push_back(chargeFraction);
2533 ret.bunchCrossing.push_back(
bx);
2537 simhit_hitType[simHitIndex].push_back(static_cast<int>(hitType));
2548 <<
"Did not find SimHit for reco hit DetId " << hitId.
rawId() <<
" for TP " << trackingParticle.
key()
2549 <<
" bx:event " <<
bx <<
":" <<
event <<
" PDGid " << trackingParticle->pdgId() <<
" q "
2550 << trackingParticle->charge() <<
" p4 " << trackingParticle->p4() <<
" nG4 "
2551 << trackingParticle->g4Tracks().size() <<
".\nFound SimHits from detectors ";
2552 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
2555 ex << dId.
rawId() <<
" ";
2557 if (trackingParticle->eventId().event() != 0) {
2558 ex <<
"\nSince this is a TrackingParticle from pileup, check that you're running the pileup mixing in "
2570 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2573 SimHitRefKeyToIndex& simHitRefKeyToIndex,
2574 std::vector<TPHitIndex>& tpHitList) {
2575 for (
const auto&
assoc : simHitsTPAssoc) {
2576 auto tpKey =
assoc.first.key();
2580 auto found = tpKeyToIndex.find(tpKey);
2581 if (
found == tpKeyToIndex.end())
2583 const auto tpIndex =
found->second;
2586 const auto& simhit = *(
assoc.second);
2587 auto detId =
DetId(simhit.detUnitId());
2599 auto simHitKey = std::make_pair(
assoc.second.key(),
assoc.second.id());
2601 if (simHitRefKeyToIndex.find(simHitKey) != simHitRefKeyToIndex.end()) {
2602 for (
const auto& assoc2 : simHitsTPAssoc) {
2603 if (std::make_pair(assoc2.second.key(), assoc2.second.id()) == simHitKey) {
2605 auto range1 = std::equal_range(simHitsTPAssoc.begin(),
2606 simHitsTPAssoc.end(),
2609 auto range2 = std::equal_range(simHitsTPAssoc.begin(),
2610 simHitsTPAssoc.end(),
2614 LogTrace(
"TrackingNtuple") <<
"Earlier TP " << assoc2.first.key() <<
" SimTrack Ids";
2615 for (
const auto&
simTrack : assoc2.first->g4Tracks()) {
2617 <<
simTrack.eventId().bunchCrossing() <<
":" <<
simTrack.eventId().event();
2619 for (
auto iHit = range2.first; iHit != range2.second; ++iHit) {
2620 LogTrace(
"TrackingNtuple") <<
" SimHit " << iHit->second.key() <<
" " << iHit->second.id() <<
" tof "
2621 << iHit->second->tof() <<
" trackId " << iHit->second->trackId() <<
" BX:event "
2622 << iHit->second->eventId().bunchCrossing() <<
":"
2623 << iHit->second->eventId().event();
2625 LogTrace(
"TrackingNtuple") <<
"Current TP " <<
assoc.first.key() <<
" SimTrack Ids";
2628 <<
simTrack.eventId().bunchCrossing() <<
":" <<
simTrack.eventId().event();
2630 for (
auto iHit = range1.first; iHit != range1.second; ++iHit) {
2631 LogTrace(
"TrackingNtuple") <<
" SimHit " << iHit->second.key() <<
" " << iHit->second.id() <<
" tof "
2632 << iHit->second->tof() <<
" trackId " << iHit->second->trackId() <<
" BX:event "
2633 << iHit->second->eventId().bunchCrossing() <<
":"
2634 << iHit->second->eventId().event();
2639 <<
"Got second time the SimHit " << simHitKey.first <<
" of " << simHitKey.second
2640 <<
", first time with TrackingParticle " << assoc2.first.key() <<
", now with " << tpKey;
2643 throw cms::Exception(
"LogicError") <<
"Got second time the SimHit " << simHitKey.first <<
" of "
2644 << simHitKey.second <<
", now with TrackingParticle " << tpKey
2645 <<
", but I didn't find the first occurrance!";
2648 auto det =
tracker.idToDetUnit(detId);
2650 throw cms::Exception(
"LogicError") <<
"Did not find a det unit for DetId " << simhit.detUnitId()
2651 <<
" from tracker geometry";
2653 const auto pos = det->surface().toGlobal(simhit.localPosition());
2654 const float tof = simhit.timeOfFlight();
2656 const auto simHitIndex =
simhit_x.size();
2657 simHitRefKeyToIndex[simHitKey] = simHitIndex;
2667 const auto mom = det->surface().toGlobal(simhit.momentumAtEntry());
2683 tpHitList.emplace_back(tpKey, simHitIndex, tof, simhit.detUnitId());
2689 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2694 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
2695 std::set<edm::ProductID>& hitProductIds) {
2696 std::vector<std::pair<uint64_t, PixelMaskContainer const*>> pixelMasks;
2700 iEvent.getByToken(itoken.second, aH);
2701 pixelMasks.emplace_back(1 << itoken.first, aH.
product());
2703 auto pixUsedMask = [&pixelMasks](
size_t key) {
2705 for (
auto const&
m : pixelMasks) {
2706 if (
m.second->mask(
key))
2715 const DetId hitId = it->detId();
2716 for (
auto hit = it->begin();
hit != it->end();
hit++) {
2719 hitProductIds.insert(
hit->cluster().
id());
2721 const int key =
hit->cluster().key();
2722 const int lay = tTopo.
layer(hitId);
2728 pix_x.push_back(ttrh->globalPosition().x());
2729 pix_y.push_back(ttrh->globalPosition().y());
2730 pix_z.push_back(ttrh->globalPosition().z());
2731 pix_xx.push_back(ttrh->globalPositionError().cxx());
2732 pix_xy.push_back(ttrh->globalPositionError().cyx());
2733 pix_yy.push_back(ttrh->globalPositionError().cyy());
2734 pix_yz.push_back(ttrh->globalPositionError().czy());
2735 pix_zz.push_back(ttrh->globalPositionError().czz());
2736 pix_zx.push_back(ttrh->globalPositionError().czx());
2737 pix_radL.push_back(ttrh->surface()->mediumProperties().radLen());
2738 pix_bbxi.push_back(ttrh->surface()->mediumProperties().xi());
2743 LogTrace(
"TrackingNtuple") <<
"pixHit cluster=" <<
key <<
" subdId=" << hitId.
subdetId() <<
" lay=" << lay
2744 <<
" rawId=" << hitId.
rawId() <<
" pos =" << ttrh->globalPosition();
2754 simHitRefKeyToIndex,
2763 LogTrace(
"TrackingNtuple") <<
" firstMatchingSimHit=" << simHitIdx <<
" simHitPos="
2769 <<
" event=" << simHitData.
event[0];
2778 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2783 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
2784 std::set<edm::ProductID>& hitProductIds) {
2785 std::vector<std::pair<uint64_t, StripMaskContainer const*>> stripMasks;
2789 iEvent.getByToken(itoken.second, aH);
2790 stripMasks.emplace_back(1 << itoken.first, aH.
product());
2792 auto strUsedMask = [&stripMasks](
size_t key) {
2794 for (
auto const&
m : stripMasks) {
2795 if (
m.second->mask(
key))
2814 str_x.resize(totalStripHits);
2815 str_y.resize(totalStripHits);
2816 str_z.resize(totalStripHits);
2817 str_xx.resize(totalStripHits);
2818 str_xy.resize(totalStripHits);
2819 str_yy.resize(totalStripHits);
2820 str_yz.resize(totalStripHits);
2821 str_zz.resize(totalStripHits);
2822 str_zx.resize(totalStripHits);
2832 for (
const auto& detset :
hits) {
2833 const DetId hitId = detset.detId();
2834 for (
const auto&
hit : detset) {
2837 hitProductIds.insert(
hit.cluster().
id());
2839 const int key =
hit.cluster().key();
2840 const int lay = tTopo.
layer(hitId);
2843 str_x[
key] = ttrh->globalPosition().x();
2844 str_y[
key] = ttrh->globalPosition().y();
2845 str_z[
key] = ttrh->globalPosition().z();
2846 str_xx[
key] = ttrh->globalPositionError().cxx();
2847 str_xy[
key] = ttrh->globalPositionError().cyx();
2848 str_yy[
key] = ttrh->globalPositionError().cyy();
2849 str_yz[
key] = ttrh->globalPositionError().czy();
2850 str_zz[
key] = ttrh->globalPositionError().czz();
2851 str_zx[
key] = ttrh->globalPositionError().czx();
2852 str_radL[
key] = ttrh->surface()->mediumProperties().radLen();
2853 str_bbxi[
key] = ttrh->surface()->mediumProperties().xi();
2858 <<
" rawId=" << hitId.
rawId() <<
" pos =" << ttrh->globalPosition();
2869 simHitRefKeyToIndex,
2878 LogTrace(
"TrackingNtuple") <<
" firstMatchingSimHit=" << simHitIdx <<
" simHitPos="
2886 <<
" event=" << simHitData.
event[0];
2893 fill(*rphiHits,
"stripRPhiHit");
2894 fill(*stereoHits,
"stripStereoHit");
2900 const std::vector<std::pair<uint64_t, StripMaskContainer const*>>& stripMasks,
2901 std::vector<std::pair<int, int>>& monoStereoClusterList) {
2902 auto strUsedMask = [&stripMasks](
size_t key) {
2904 for (
auto const&
m : stripMasks) {
2905 if (
m.second->mask(
key))
2912 const auto hitId =
hit.geographicalId();
2913 const int lay = tTopo.
layer(hitId);
2914 monoStereoClusterList.emplace_back(
hit.monoHit().cluster().key(),
hit.stereoHit().cluster().key());
2920 glu_x.push_back(ttrh->globalPosition().x());
2921 glu_y.push_back(ttrh->globalPosition().y());
2922 glu_z.push_back(ttrh->globalPosition().z());
2923 glu_xx.push_back(ttrh->globalPositionError().cxx());
2924 glu_xy.push_back(ttrh->globalPositionError().cyx());
2925 glu_yy.push_back(ttrh->globalPositionError().cyy());
2926 glu_yz.push_back(ttrh->globalPositionError().czy());
2927 glu_zz.push_back(ttrh->globalPositionError().czz());
2928 glu_zx.push_back(ttrh->globalPositionError().czx());
2929 glu_radL.push_back(ttrh->surface()->mediumProperties().radLen());
2930 glu_bbxi.push_back(ttrh->surface()->mediumProperties().xi());
2936 LogTrace(
"TrackingNtuple") <<
"stripMatchedHit"
2937 <<
" cluster0=" <<
hit.stereoHit().cluster().key()
2938 <<
" cluster1=" <<
hit.monoHit().cluster().key() <<
" subdId=" << hitId.subdetId()
2939 <<
" lay=" << lay <<
" rawId=" << hitId.rawId() <<
" pos =" << ttrh->globalPosition();
2946 std::vector<std::pair<int, int>>& monoStereoClusterList) {
2947 std::vector<std::pair<uint64_t, StripMaskContainer const*>> stripMasks;
2951 iEvent.getByToken(itoken.second, aH);
2952 stripMasks.emplace_back(1 << itoken.first, aH.
product());
2957 for (
auto it = matchedHits->
begin(); it != matchedHits->
end(); it++) {
2958 for (
auto hit = it->begin();
hit != it->end();
hit++) {
2966 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
2971 const SimHitRefKeyToIndex& simHitRefKeyToIndex,
2972 std::set<edm::ProductID>& hitProductIds) {
2975 for (
auto it = phase2OTHits->
begin(); it != phase2OTHits->
end(); it++) {
2976 const DetId hitId = it->detId();
2977 for (
auto hit = it->begin();
hit != it->end();
hit++) {
2980 hitProductIds.insert(
hit->cluster().
id());
2982 const int key =
hit->cluster().key();
2983 const int lay = tTopo.
layer(hitId);
2989 ph2_x.push_back(ttrh->globalPosition().x());
2990 ph2_y.push_back(ttrh->globalPosition().y());
2991 ph2_z.push_back(ttrh->globalPosition().z());
2992 ph2_xx.push_back(ttrh->globalPositionError().cxx());
2993 ph2_xy.push_back(ttrh->globalPositionError().cyx());
2994 ph2_yy.push_back(ttrh->globalPositionError().cyy());
2995 ph2_yz.push_back(ttrh->globalPositionError().czy());
2996 ph2_zz.push_back(ttrh->globalPositionError().czz());
2997 ph2_zx.push_back(ttrh->globalPositionError().czx());
2998 ph2_radL.push_back(ttrh->surface()->mediumProperties().radLen());
2999 ph2_bbxi.push_back(ttrh->surface()->mediumProperties().xi());
3001 LogTrace(
"TrackingNtuple") <<
"phase2 OT cluster=" <<
key <<
" subdId=" << hitId.
subdetId() <<
" lay=" << lay
3002 <<
" rawId=" << hitId.
rawId() <<
" pos =" << ttrh->globalPosition();
3013 simHitRefKeyToIndex,
3021 LogTrace(
"TrackingNtuple") <<
" firstMatchingSimHit=" << simHitIdx <<
" simHitPos="
3027 <<
" event=" << simHitData.
event[0];
3036 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
3043 std::vector<std::pair<int, int>>& monoStereoClusterList,
3044 const std::set<edm::ProductID>& hitProductIds,
3045 std::map<edm::ProductID, size_t>& seedCollToOffset) {
3047 for (
size_t iColl = 0; iColl <
seedTokens_.size(); ++iColl) {
3051 iEvent.getByToken(seedToken, seedTracksHandle);
3062 iEvent.getByToken(seedStopInfoToken, seedStopInfoHandle);
3063 const auto& seedStopInfos = *seedStopInfoHandle;
3064 if (
seedTracks.size() != seedStopInfos.size()) {
3069 <<
" seed stopping infos for collections " <<
labels.module <<
", "
3073 std::vector<std::pair<uint64_t, StripMaskContainer const*>> stripMasks;
3077 iEvent.getByToken(itoken.second, aH);
3078 stripMasks.emplace_back(1 << itoken.first, aH.
product());
3091 label.ReplaceAll(
"seedTracks",
"");
3092 label.ReplaceAll(
"Seeds",
"");
3093 label.ReplaceAll(
"muonSeeded",
"muonSeededStep");
3095 label.ReplaceAll(
"FromPixelTracks",
"");
3096 label.ReplaceAll(
"PFLowPixel",
"");
3097 label.ReplaceAll(
"hltDoubletRecovery",
"pixelPairStep");
3102 auto inserted = seedCollToOffset.emplace(
id,
offset);
3103 if (!inserted.second)
3105 <<
"Trying to add seeds with ProductID " <<
id <<
" for a second time from collection " <<
labels.module
3106 <<
", seed algo " <<
label <<
". Typically this is caused by a configuration problem.";
3110 <<
" ProductID " <<
id;
3112 for (
size_t iSeed = 0; iSeed < seedTrackRefs.
size(); ++iSeed) {
3113 const auto& seedTrackRef = seedTrackRefs[iSeed];
3114 const auto& seedTrack = *seedTrackRef;
3115 const auto& seedRef = seedTrack.seedRef();
3116 const auto&
seed = *seedRef;
3118 const auto seedStopInfo = seedStopInfos[iSeed];
3120 if (seedRef.id() !=
id)
3122 <<
"All tracks in 'TracksFromSeeds' collection should point to seeds in the same collection. Now the "
3123 "element 0 had ProductID "
3124 <<
id <<
" while the element " << seedTrackRef.key() <<
" had " << seedTrackRef.id()
3125 <<
". The source collection is " <<
labels.module <<
".";
3127 std::vector<int> tpIdx;
3128 std::vector<float> sharedFraction;
3129 auto foundTPs = recSimColl.
find(seedTrackRef);
3130 if (foundTPs != recSimColl.
end()) {
3131 for (
const auto& tpQuality : foundTPs->val) {
3132 tpIdx.push_back(tpKeyToIndex.at(tpQuality.first.key()));
3133 sharedFraction.push_back(tpQuality.second);
3138 const int nHits = seedTrack.numberOfValidHits();
3140 seedTrack.recHitsBegin(),
3141 seedTrack.recHitsEnd());
3143 const auto bestKeyCount = findBestMatchingTrackingParticle(seedTrack, clusterToTPMap, tpKeyToIndex);
3144 const float bestShareFrac =
3145 nClusters > 0 ? static_cast<float>(bestKeyCount.countClusters) / static_cast<float>(
nClusters) : 0;
3147 const auto bestFirstHitKeyCount =
3148 findMatchingTrackingParticleFromFirstHit(seedTrack, clusterToTPMap, tpKeyToIndex);
3149 const float bestFirstHitShareFrac =
3150 nClusters > 0 ? static_cast<float>(bestFirstHitKeyCount.countClusters) / static_cast<float>(
nClusters) : 0;
3153 const int charge = seedTrack.charge();
3154 const float pt = seedFitOk ? seedTrack.pt() : 0;
3155 const float eta = seedFitOk ? seedTrack.eta() : 0;
3156 const float phi = seedFitOk ? seedTrack.phi() : 0;
3158 const auto seedIndex =
see_fitok.size();
3162 see_px.push_back(seedFitOk ? seedTrack.px() : 0);
3163 see_py.push_back(seedFitOk ? seedTrack.py() : 0);
3164 see_pz.push_back(seedFitOk ? seedTrack.pz() : 0);
3171 see_dxy.push_back(seedFitOk ? seedTrack.dxy(
bs.position()) : 0);
3172 see_dz.push_back(seedFitOk ? seedTrack.dz(
bs.position()) : 0);
3173 see_ptErr.push_back(seedFitOk ? seedTrack.ptError() : 0);
3174 see_etaErr.push_back(seedFitOk ? seedTrack.etaError() : 0);
3175 see_phiErr.push_back(seedFitOk ? seedTrack.phiError() : 0);
3176 see_dxyErr.push_back(seedFitOk ? seedTrack.dxyError() : 0);
3177 see_dzErr.push_back(seedFitOk ? seedTrack.dzError() : 0);
3180 see_nCands.push_back(seedStopInfo.candidatesPerSeed());
3182 const auto&
state = seedTrack.seedRef()->startingState();
3183 const auto&
pos =
state.parameters().position();
3184 const auto& mom =
state.parameters().momentum();
3205 std::vector<float> cov(15);
3206 auto covP = cov.begin();
3207 for (
auto const val : stateCcov)
3216 see_bestSimTrkIdx.push_back(bestKeyCount.key >= 0 ? tpKeyToIndex.at(bestKeyCount.key) : -1);
3218 bestFirstHitKeyCount.key >= 0 ? tpKeyToIndex.at(bestFirstHitKeyCount.key) : -1);
3237 std::vector<int> hitIdx;
3238 std::vector<int> hitType;
3240 for (
auto const&
hit :
seed.recHits()) {
3242 int subid =
recHit->geographicalId().subdetId();
3248 checkProductID(hitProductIds, clusterRef.id(),
"seed");
3251 hitIdx.push_back(clusterKey);
3264 std::vector<std::pair<int, int>>::iterator
pos =
3265 find(monoStereoClusterList.begin(), monoStereoClusterList.end(), std::make_pair(monoIdx, stereoIdx));
3266 size_t gluedIndex = -1;
3267 if (
pos != monoStereoClusterList.end()) {
3274 gluedIndex =
addStripMatchedHit(*matchedHit, theTTRHBuilder, tTopo, stripMasks, monoStereoClusterList);
3279 hitIdx.push_back(gluedIndex);
3284 unsigned int clusterKey;
3285 if (clusterRef.isPhase2()) {
3288 clusterKey = clusterRef.cluster_strip().key();
3292 checkProductID(hitProductIds, clusterRef.id(),
"seed");
3293 if (clusterRef.isPhase2()) {
3300 hitIdx.push_back(clusterKey);
3301 if (clusterRef.isPhase2()) {
3308 LogTrace(
"TrackingNtuple") <<
" not pixel and not Strip detector";
3323 std::vector<GlobalPoint>
gp(2);
3324 std::vector<GlobalError> ge(2);
3325 gp[0] = recHit0->globalPosition();
3326 ge[0] = recHit0->globalPositionError();
3327 gp[1] = recHit1->globalPosition();
3328 ge[1] = recHit1->globalPositionError();
3330 <<
"seed " << seedTrackRef.key() <<
" pt=" <<
pt <<
" eta=" <<
eta <<
" phi=" <<
phi <<
" q=" <<
charge
3331 <<
" - PAIR - ids: " << recHit0->geographicalId().rawId() <<
" " << recHit1->geographicalId().rawId()
3332 <<
" hitpos: " <<
gp[0] <<
" " <<
gp[1] <<
" trans0: "
3333 << (recHit0->transientHits().size() > 1 ? recHit0->transientHits()[0]->globalPosition()
3336 << (recHit0->transientHits().size() > 1 ? recHit0->transientHits()[1]->globalPosition()
3339 << (recHit1->transientHits().size() > 1 ? recHit1->transientHits()[0]->globalPosition()
3342 << (recHit1->transientHits().size() > 1 ? recHit1->transientHits()[1]->globalPosition()
3344 <<
" eta,phi: " <<
gp[0].
eta() <<
"," <<
gp[0].phi();
3345 }
else if (
nHits == 3) {
3352 gp[0] = recHit0->globalPosition();
3353 ge[0] = recHit0->globalPositionError();
3354 int subid0 = recHit0->geographicalId().subdetId();
3357 gp[1] = recHit1->globalPosition();
3358 ge[1] = recHit1->globalPositionError();
3359 int subid1 = recHit1->geographicalId().subdetId();
3362 gp[2] = recHit2->globalPosition();
3363 ge[2] = recHit2->globalPositionError();
3364 int subid2 = recHit2->geographicalId().subdetId();
3368 float seed_chi2 = rzLine.
chi2();
3372 <<
"seed " << seedTrackRef.key() <<
" pt=" <<
pt <<
" eta=" <<
eta <<
" phi=" <<
phi <<
" q=" <<
charge
3373 <<
" - TRIPLET - ids: " << recHit0->geographicalId().rawId() <<
" " << recHit1->geographicalId().rawId()
3374 <<
" " << recHit2->geographicalId().rawId() <<
" hitpos: " <<
gp[0] <<
" " <<
gp[1] <<
" " <<
gp[2]
3376 << (recHit0->transientHits().size() > 1 ? recHit0->transientHits()[0]->globalPosition()
3379 << (recHit0->transientHits().size() > 1 ? recHit0->transientHits()[1]->globalPosition()
3382 << (recHit1->transientHits().size() > 1 ? recHit1->transientHits()[0]->globalPosition()
3385 << (recHit1->transientHits().size() > 1 ? recHit1->transientHits()[1]->globalPosition()
3388 << (recHit2->transientHits().size() > 1 ? recHit2->transientHits()[0]->globalPosition()
3391 << (recHit2->transientHits().size() > 1 ? recHit2->transientHits()[1]->globalPosition()
3394 << recHit2->localPosition()
3396 <<
" eta,phi: " <<
gp[0].eta() <<
"," <<
gp[0].phi() <<
" pt,chi2: " << seed_pt <<
"," << seed_chi2;
3408 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
3409 const TrackingParticleRefKeyToCount& tpKeyToClusterCount,
3417 const std::set<edm::ProductID>& hitProductIds,
3418 const std::map<edm::ProductID, size_t>& seedCollToOffset,
3419 const std::vector<const MVACollection*>& mvaColls,
3420 const std::vector<const QualityMaskCollection*>& qualColls) {
3424 LogTrace(
"TrackingNtuple") <<
"NEW TRACK LABEL: " <<
labels.module;
3426 auto pvPosition =
vertices[0].position();
3428 for (
size_t iTrack = 0; iTrack <
tracks.size(); ++iTrack) {
3429 const auto& itTrack =
tracks[iTrack];
3430 int charge = itTrack->charge();
3431 float pt = itTrack->pt();
3432 float eta = itTrack->eta();
3433 const double lambda = itTrack->lambda();
3434 float chi2 = itTrack->normalizedChi2();
3435 float ndof = itTrack->ndof();
3436 float phi = itTrack->phi();
3437 int nHits = itTrack->numberOfValidHits();
3440 const auto& tkParam = itTrack->parameters();
3441 auto tkCov = itTrack->covariance();
3446 bool isSimMatched =
false;
3447 std::vector<int> tpIdx;
3448 std::vector<float> sharedFraction;
3449 std::vector<float> tpChi2;
3450 auto foundTPs = recSimColl.
find(itTrack);
3451 if (foundTPs != recSimColl.
end()) {
3452 if (!foundTPs->val.empty()) {
3453 nSimHits = foundTPs->val[0].first->numberOfTrackerHits();
3454 isSimMatched =
true;
3456 for (
const auto& tpQuality : foundTPs->val) {
3457 tpIdx.push_back(tpKeyToIndex.at(tpQuality.first.key()));
3458 sharedFraction.push_back(tpQuality.second);
3465 itTrack->recHitsBegin(),
3466 itTrack->recHitsEnd());
3469 const auto bestKeyCount = findBestMatchingTrackingParticle(*itTrack, clusterToTPMap, tpKeyToIndex);
3470 const float bestShareFrac = static_cast<float>(bestKeyCount.countClusters) / static_cast<float>(
nClusters);
3471 float bestShareFracSimDenom = 0;
3472 float bestShareFracSimClusterDenom = 0;
3473 float bestChi2 = -1;
3474 if (bestKeyCount.key >= 0) {
3475 bestShareFracSimDenom =
3476 static_cast<float>(bestKeyCount.countClusters) /
3477 static_cast<float>(tpCollection[tpKeyToIndex.at(bestKeyCount.key)]->numberOfTrackerHits());
3478 bestShareFracSimClusterDenom =
3479 static_cast<float>(bestKeyCount.countClusters) / static_cast<float>(tpKeyToClusterCount.at(bestKeyCount.key));
3481 tkParam, tkCov, *(tpCollection[tpKeyToIndex.at(bestKeyCount.key)]), mf,
bs);
3484 const auto bestFirstHitKeyCount = findMatchingTrackingParticleFromFirstHit(*itTrack, clusterToTPMap, tpKeyToIndex);
3485 const float bestFirstHitShareFrac =
3486 static_cast<float>(bestFirstHitKeyCount.countClusters) / static_cast<float>(
nClusters);
3487 float bestFirstHitShareFracSimDenom = 0;
3488 float bestFirstHitShareFracSimClusterDenom = 0;
3489 float bestFirstHitChi2 = -1;
3490 if (bestFirstHitKeyCount.key >= 0) {
3491 bestFirstHitShareFracSimDenom =
3492 static_cast<float>(bestFirstHitKeyCount.countClusters) /
3493 static_cast<float>(tpCollection[tpKeyToIndex.at(bestFirstHitKeyCount.key)]->numberOfTrackerHits());
3494 bestFirstHitShareFracSimClusterDenom = static_cast<float>(bestFirstHitKeyCount.countClusters) /
3495 static_cast<float>(tpKeyToClusterCount.at(bestFirstHitKeyCount.key));
3497 tkParam, tkCov, *(tpCollection[tpKeyToIndex.at(bestFirstHitKeyCount.key)]), mf,
bs);
3500 float chi2_1Dmod =
chi2;
3501 int count1dhits = 0;
3502 for (
auto iHit = itTrack->recHitsBegin(), iEnd = itTrack->recHitsEnd(); iHit != iEnd; ++iHit) {
3507 if (count1dhits > 0) {
3508 chi2_1Dmod = (
chi2 + count1dhits) / (
ndof + count1dhits);
3513 trk_px.push_back(itTrack->px());
3514 trk_py.push_back(itTrack->py());
3515 trk_pz.push_back(itTrack->pz());
3520 trk_inner_pt.push_back(itTrack->innerMomentum().rho());
3524 trk_outer_pt.push_back(itTrack->outerMomentum().rho());
3529 trk_dxy.push_back(itTrack->dxy(
bs.position()));
3530 trk_dz.push_back(itTrack->dz(
bs.position()));
3531 trk_dxyPV.push_back(itTrack->dxy(pvPosition));
3532 trk_dzPV.push_back(itTrack->dz(pvPosition));
3535 trk_ptErr.push_back(itTrack->ptError());
3540 trk_dzErr.push_back(itTrack->dzError());
3559 trk_n3DLay.push_back(
hp.numberOfValidStripLayersWithMonoAndStereo() +
hp.pixelLayersWithMeasurement());
3562 trk_algo.push_back(itTrack->algo());
3569 trk_mvas[
i].push_back((*(mvaColls[
i]))[iTrack]);
3574 auto offset = seedCollToOffset.find(itTrack->seedRef().id());
3575 if (
offset == seedCollToOffset.end()) {
3579 << itTrack->seedRef().id()
3580 <<
", but that seed collection is not given as an input. The following collections were given as an input "
3581 << make_ProductIDMapPrinter(seedCollToOffset);
3584 const auto seedIndex =
offset->second + itTrack->seedRef().key();
3587 throw cms::Exception(
"LogicError") <<
"Track index has already been set for seed " << seedIndex <<
" to "
3588 <<
see_trkIdx[seedIndex] <<
"; was trying to set it to " << iTrack;
3597 trk_bestSimTrkIdx.push_back(bestKeyCount.key >= 0 ? tpKeyToIndex.at(bestKeyCount.key) : -1);
3612 LogTrace(
"TrackingNtuple") <<
"Track #" << itTrack.key() <<
" with q=" <<
charge <<
", pT=" <<
pt
3613 <<
" GeV, eta: " <<
eta <<
", phi: " <<
phi <<
", chi2=" <<
chi2 <<
", Nhits=" <<
nHits
3614 <<
", algo=" << itTrack->algoName(itTrack->algo()).c_str()
3616 <<
" seed#=" << itTrack->seedRef().key() <<
" simMatch=" << isSimMatched
3617 <<
" nSimHits=" << nSimHits
3618 <<
" sharedFraction=" << (sharedFraction.empty() ? -1 : sharedFraction[0])
3619 <<
" tpIdx=" << (tpIdx.empty() ? -1 : tpIdx[0]);
3620 std::vector<int> hitIdx;
3621 std::vector<int> hitType;
3623 for (
auto i = itTrack->recHitsBegin();
i != itTrack->recHitsEnd();
i++) {
3625 DetId hitId =
hit->geographicalId();
3633 if (
hit->isValid()) {
3637 unsigned int clusterKey;
3638 if (clusterRef.isPixel()) {
3640 }
else if (clusterRef.isPhase2()) {
3641 clusterKey = clusterRef.cluster_phase2OT().key();
3643 clusterKey = clusterRef.cluster_strip().key();
3646 LogTrace(
"TrackingNtuple") <<
" id: " << hitId.
rawId() <<
" - globalPos =" <<
hit->globalPosition()
3647 <<
" cluster=" << clusterKey <<
" clusterRef ID=" << clusterRef.
id()
3648 <<
" eta,phi: " <<
hit->globalPosition().eta() <<
"," <<
hit->globalPosition().phi();
3650 checkProductID(hitProductIds, clusterRef.id(),
"track");
3651 if (clusterRef.isPixel()) {
3653 }
else if (clusterRef.isPhase2()) {
3660 hitIdx.push_back(clusterKey);
3661 if (clusterRef.isPixel()) {
3663 }
else if (clusterRef.isPhase2()) {
3669 LogTrace(
"TrackingNtuple") <<
" - invalid hit";
3693 const TrackingVertexRefKeyToIndex& tvKeyToIndex,
3695 const std::vector<TPHitIndex>& tpHitList,
3696 const TrackingParticleRefKeyToCount& tpKeyToClusterCount) {
3702 const auto& nLayers_tPCeff = *tpNLayersH;
3705 const auto& nPixelLayers_tPCeff = *tpNLayersH;
3708 const auto& nStripMonoAndStereoLayers_tPCeff = *tpNLayersH;
3713 LogTrace(
"TrackingNtuple") <<
"tracking particle pt=" <<
tp->pt() <<
" eta=" <<
tp->eta() <<
" phi=" <<
tp->phi();
3714 bool isRecoMatched =
false;
3715 std::vector<int> tkIdx;
3716 std::vector<float> sharedFraction;
3717 auto foundTracks = simRecColl.
find(
tp);
3718 if (foundTracks != simRecColl.
end()) {
3719 isRecoMatched =
true;
3727 for (
const auto& genRef :
tp->genParticles()) {
3728 if (genRef.isNonnull())
3732 bool isFromBHadron =
false;
3737 for (
const auto& particle : recoGenParticleTrail) {
3740 isFromBHadron =
true;
3746 LogTrace(
"TrackingNtuple") <<
"matched to tracks = " << make_VectorPrinter(tkIdx)
3747 <<
" isRecoMatched=" << isRecoMatched;
3758 sim_q.push_back(
tp->charge());
3762 std::vector<int> decayIdx;
3763 for (
const auto&
v :
tp->decayVertices())
3764 decayIdx.push_back(tvKeyToIndex.at(
v.key()));
3772 const double lambdaSim =
M_PI / 2 - momentum.theta();
3781 std::vector<int> hitIdx;
3782 int nPixel = 0, nStrip = 0;
3784 for (
auto ip = rangeHit.first; ip != rangeHit.second; ++ip) {
3788 LogTrace(
"TrackingNtuple") <<
"simhit=" << ip->simHitIdx <<
" type=" << static_cast<int>(
type);
3789 hitIdx.push_back(ip->simHitIdx);
3792 throw cms::Exception(
"LogicError") <<
"Encountered SimHit for TP " <<
tp.key() <<
" with DetId "
3793 << detid.rawId() <<
" whose det() is not Tracker but " << detid.det();
3795 const auto subdet = detid.subdetId();
3808 throw cms::Exception(
"LogicError") <<
"Encountered SimHit for TP " <<
tp.key() <<
" with DetId "
3809 << detid.rawId() <<
" whose subdet is not recognized, is " << subdet;
3816 const auto nSimLayers = nLayers_tPCeff[
tp];
3817 const auto nSimPixelLayers = nPixelLayers_tPCeff[
tp];
3818 const auto nSimStripMonoAndStereoLayers = nStripMonoAndStereoLayers_tPCeff[
tp];
3821 sim_n3DLay.push_back(nSimPixelLayers + nSimStripMonoAndStereoLayers);
3824 auto found = tpKeyToClusterCount.find(
tp.key());
3834 const TrackingParticleRefKeyToIndex& tpKeyToIndex,
3835 const unsigned int seedOffset) {
3839 for (
const auto& keyVal : simRecColl) {
3840 const auto& tpRef = keyVal.key;
3841 auto found = tpKeyToIndex.find(tpRef.key());
3842 if (
found == tpKeyToIndex.end())
3843 throw cms::Exception(
"Assert") << __FILE__ <<
":" << __LINE__ <<
" fillTrackingParticlesForSeeds: tpRef.key() "
3844 << tpRef.key() <<
" not found from tpKeyToIndex. tpKeyToIndex size "
3845 << tpKeyToIndex.size();
3846 const auto tpIndex =
found->second;
3847 for (
const auto& pair : keyVal.val) {
3848 const auto& seedRef = pair.first->seedRef();
3849 sim_seedIdx[tpIndex].push_back(seedOffset + seedRef.key());
3856 for (
size_t iVertex = 0,
size =
vertices.size(); iVertex <
size; ++iVertex) {
3869 std::vector<int> trkIdx;
3870 for (
auto iTrack =
vertex.tracks_begin(); iTrack !=
vertex.tracks_end(); ++iTrack) {
3872 if (iTrack->id() !=
tracks.id())
3875 trkIdx.push_back(iTrack->key());
3878 throw cms::Exception(
"LogicError") <<
"Vertex index has already been set for track " << iTrack->key() <<
" to "
3879 <<
trk_vtxIdx[iTrack->key()] <<
"; was trying to set it to " << iVertex;
3888 const TrackingParticleRefKeyToIndex& tpKeyToIndex) {
3889 int current_event = -1;
3890 for (
const auto& ref : trackingVertices) {
3892 if (
v.eventId().event() != current_event) {
3894 current_event =
v.eventId().event();
3899 if (!
v.g4Vertices().empty()) {
3900 processType =
v.g4Vertices()[0].processType();
3912 for (
const auto& tpRef : tps) {
3913 auto found = tpKeyToIndex.find(tpRef.key());
3914 if (
found != tpKeyToIndex.end()) {
3920 std::vector<int> sourceIdx;
3921 std::vector<int> daughterIdx;
3922 fill(
v.sourceTracks(), sourceIdx);
3923 fill(
v.daughterTracks(), daughterIdx);
3935 desc.addUntracked<std::vector<edm::InputTag>>(
3937 std::vector<edm::InputTag>{
edm::InputTag(
"seedTracksinitialStepSeeds"),
3947 desc.addUntracked<std::vector<edm::InputTag>>(
3949 std::vector<edm::InputTag>{
edm::InputTag(
"initialStepTrackCandidates"),
3960 desc.addUntracked<std::vector<std::string>>(
"trackMVAs", std::vector<std::string>{{
"generalTracks"}});
3965 std::vector<edm::ParameterSet> cMasks;
3970 cMasks.push_back(ps);
3981 desc.addVPSetUntracked(
"clusterMasks", cMaskDesc, cMasks);
3984 desc.addUntracked<
bool>(
"trackingParticlesRef",
false);
4000 edm::InputTag(
"trackingParticleNumberOfLayersProducer",
"trackerLayers"));
4002 edm::InputTag(
"trackingParticleNumberOfLayersProducer",
"pixelLayers"));
4004 edm::InputTag(
"trackingParticleNumberOfLayersProducer",
"stripStereoLayers"));
4006 desc.addUntracked<
std::string>(
"parametersDefiner",
"LhcParametersDefinerForTP");
4007 desc.addUntracked<
bool>(
"includeSeeds",
false);
4008 desc.addUntracked<
bool>(
"addSeedCurvCov",
false);
4009 desc.addUntracked<
bool>(
"includeAllHits",
false);
4010 desc.addUntracked<
bool>(
"includeMVA",
true);
4011 desc.addUntracked<
bool>(
"includeTrackingParticles",
true);
4012 desc.addUntracked<
bool>(
"includeOOT",
false);
4013 desc.addUntracked<
bool>(
"keepEleSimHits",
false);
4014 desc.addUntracked<
bool>(
"saveSimHitsP3",
false);
4015 desc.addUntracked<
bool>(
"simHitBySignificance",
false);
4016 descriptions.
add(
"trackingNtuple",
desc);