32 #include <type_traits>
45 bool trackSelected(
unsigned char mask,
unsigned char qual) {
return mask & 1 << qual; }
56 ignoremissingtkcollection_(
pset.getUntrackedParameter<
bool>(
"ignoremissingtrackcollection",
false)),
57 useAssociators_(
pset.getParameter<
bool>(
"UseAssociators")),
58 calculateDrSingleCollection_(
pset.getUntrackedParameter<
bool>(
"calculateDrSingleCollection")),
59 doPlotsOnlyForTruePV_(
pset.getUntrackedParameter<
bool>(
"doPlotsOnlyForTruePV")),
60 doSummaryPlots_(
pset.getUntrackedParameter<
bool>(
"doSummaryPlots")),
61 doSimPlots_(
pset.getUntrackedParameter<
bool>(
"doSimPlots")),
62 doSimTrackPlots_(
pset.getUntrackedParameter<
bool>(
"doSimTrackPlots")),
63 doRecoTrackPlots_(
pset.getUntrackedParameter<
bool>(
"doRecoTrackPlots")),
64 dodEdxPlots_(
pset.getUntrackedParameter<
bool>(
"dodEdxPlots")),
65 doPVAssociationPlots_(
pset.getUntrackedParameter<
bool>(
"doPVAssociationPlots")),
66 doSeedPlots_(
pset.getUntrackedParameter<
bool>(
"doSeedPlots")),
67 doMVAPlots_(
pset.getUntrackedParameter<
bool>(
"doMVAPlots")),
68 simPVMaxZ_(
pset.getUntrackedParameter<double>(
"simPVMaxZ")) {
80 if (
pset.getParameter<
bool>(
"label_tp_effic_refvector")) {
83 label_tp_effic = consumes<TrackingParticleCollection>(label_tp_effic_tag);
85 if (
pset.getParameter<
bool>(
"label_tp_fake_refvector")) {
88 label_tp_fake = consumes<TrackingParticleCollection>(label_tp_fake_tag);
91 for (
const auto&
tag :
pset.getParameter<std::vector<edm::InputTag>>(
"sim")) {
96 pset.getParameter<std::vector<edm::InputTag>>(
"doResolutionPlotsForLabels");
98 for (
auto& itag :
label) {
112 throw cms::Exception(
"Configuration") <<
"Duplicate InputTag in labels: " <<
l;
128 consumes<edm::ValueMap<unsigned int>>(
pset.getParameter<
edm::InputTag>(
"label_tp_npixellayers"));
130 consumes<edm::ValueMap<unsigned int>>(
pset.getParameter<
edm::InputTag>(
"label_tp_nstripstereolayers"));
141 consumes<reco::VertexToTrackingVertexAssociator>(
pset.getUntrackedParameter<
edm::InputTag>(
"vertexAssociator"));
147 for (
size_t iIter = 0; iIter <
labelToken.size(); ++iIter) {
150 if (mvaPSet.exists(
labels.module)) {
152 mvaPSet.getUntrackedParameter<std::vector<std::string>>(
labels.module), [&](
const std::string&
tag) {
153 return std::make_tuple(consumes<MVACollection>(edm::InputTag(tag,
"MVAValues")),
154 consumes<QualityMaskCollection>(edm::InputTag(tag,
"QualityMasks")));
161 pset.getParameter<
double>(
"ptMaxTP"),
162 pset.getParameter<
double>(
"minRapidityTP"),
163 pset.getParameter<
double>(
"maxRapidityTP"),
164 pset.getParameter<
double>(
"tipTP"),
165 pset.getParameter<
double>(
"lipTP"),
166 pset.getParameter<
int>(
"minHitTP"),
167 pset.getParameter<
bool>(
"signalOnlyTP"),
168 pset.getParameter<
bool>(
"intimeOnlyTP"),
169 pset.getParameter<
bool>(
"chargedOnlyTP"),
170 pset.getParameter<
bool>(
"stableOnlyTP"),
171 pset.getParameter<std::vector<int>>(
"pdgIdTP"),
172 pset.getParameter<
bool>(
"invertRapidityCutTP"));
175 pset.getParameter<
double>(
"minRapidityTP"),
176 pset.getParameter<
double>(
"maxRapidityTP"),
177 pset.getParameter<
double>(
"tipTP"),
178 pset.getParameter<
double>(
"lipTP"),
179 pset.getParameter<
int>(
"minHitTP"),
180 pset.getParameter<
bool>(
"chargedOnlyTP"),
181 pset.getParameter<std::vector<int>>(
"pdgIdTP"));
202 _simHitTpMapTag = mayConsume<SimHitTPAssociationProducer::SimHitTPAssociationList>(
207 consumes<edm::View<reco::Track>>(
pset.getParameter<
edm::InputTag>(
"trackCollectionForDrCalculation"));
233 const auto minColl = -0.5;
234 const auto maxColl =
label.size() - 0.5;
235 const auto nintColl =
label.size();
238 for (
size_t i = 0;
i <
label.size(); ++
i) {
241 me->disableAlphanumeric();
256 for (
unsigned int ww = 0; ww <
associators.size(); ww++) {
264 binLabels(ibook.
book1D(
"num_assoc(simToReco)_coll",
265 "N of associated (simToReco) tracks vs track collection",
270 ibook.
book1D(
"num_simul_coll",
"N of simulated tracks vs track collection", nintColl, minColl, maxColl)));
274 ibook.
book1D(
"num_reco_coll",
"N of reco track vs track collection", nintColl, minColl, maxColl)));
276 binLabels(ibook.
book1D(
"num_assoc(recoToSim)_coll",
277 "N of associated (recoToSim) tracks vs track collection",
282 binLabels(ibook.
book1D(
"num_duplicate_coll",
283 "N of associated (recoToSim) looper tracks vs track collection",
288 binLabels(ibook.
book1D(
"num_pileup_coll",
289 "N of associated (recoToSim) pileup tracks vs track collection",
296 for (
unsigned int www = 0; www <
label.size(); www++) {
300 if (!
algo.process().empty())
302 if (!
algo.label().empty())
304 if (!
algo.instance().empty())
355 if (eff.
id() !=
fake.id()) {
357 <<
"Efficiency and fake TrackingParticle (refs) point to different collections (eff " << eff.
id() <<
" fake "
359 <<
"). This is not supported. Efficiency TP set must be the same or a subset of the fake TP set.";
365 for (
const auto& ref :
fake) {
366 fakeKeys.
insert(ref.key());
369 for (
const auto& ref : eff) {
370 if (!fakeKeys.
has(ref.key())) {
371 throw cms::Exception(
"Configuration") <<
"Efficiency TrackingParticle " << ref.key()
372 <<
" is not found from the set of fake TPs. This is not supported. The "
373 "efficiency TP set must be the same or a subset of the fake TP set.";
381 for (
const auto& simV : *htv) {
382 if (simV.eventId().bunchCrossing() != 0)
384 if (simV.eventId().event() != 0)
386 return &(simV.position());
400 auto pvPtr = hvertex->refAt(0);
401 if (pvPtr->isFake() || pvPtr->ndof() < 0)
404 auto pvFound = v_r2s.find(pvPtr);
405 if (pvFound == v_r2s.end())
408 for (
const auto& vertexRefQuality : pvFound->val) {
411 return &(pvPtr->position());
425 std::vector<std::tuple<TrackingParticle::Vector, TrackingParticle::Point>>& momVert_tPCeff,
426 std::vector<size_t>& selected_tPCeff)
const {
427 selected_tPCeff.reserve(tPCeff.
size());
428 momVert_tPCeff.reserve(tPCeff.
size());
431 for (
size_t j = 0;
j < tPCeff.
size(); ++
j) {
438 histograms.histoProducerAlgo, momentum,
vertex, tpr->eventId().bunchCrossing());
440 if (tpr->eventId().bunchCrossing() == 0)
444 selected_tPCeff.push_back(
j);
445 momVert_tPCeff.emplace_back(momentum,
vertex);
450 for (
auto const& tpr : tPCeff) {
459 histograms.histoProducerAlgo,
tp.momentum(),
tp.vertex(),
tp.eventId().bunchCrossing());
461 if (
tp.eventId().bunchCrossing() == 0)
465 selected_tPCeff.push_back(
j);
468 momVert_tPCeff.emplace_back(momentum,
vertex);
479 const std::vector<size_t>& selected_tPCeff,
483 float etaL[tPCeff.
size()], phiL[tPCeff.
size()];
484 size_t n_selTP_dr = 0;
485 for (
size_t iTP : selected_tPCeff) {
487 auto const& tp2 = *(tPCeff[iTP]);
488 auto&&
p = tp2.momentum();
489 etaL[iTP] = etaFromXYZ(
p.x(),
p.y(),
p.z());
490 phiL[iTP] = atan2f(
p.y(),
p.x());
492 for (
size_t iTP1 : selected_tPCeff) {
493 auto const&
tp = *(tPCeff[iTP1]);
498 float eta = etaL[iTP1];
499 float phi = phiL[iTP1];
500 for (
size_t iTP2 : selected_tPCeff) {
509 if (
cores !=
nullptr) {
510 for (
unsigned int ji = 0; ji <
cores->size(); ji++) {
512 double jet_eta =
jet.eta();
513 double jet_phi =
jet.phi();
515 if (dR_jet_tmp < dR_jet)
533 float etaL[trackCollectionDr.
size()];
534 float phiL[trackCollectionDr.
size()];
535 bool validL[trackCollectionDr.
size()];
536 for (
auto const& track2 : trackCollectionDr) {
537 auto&&
p = track2.momentum();
538 etaL[
i] = etaFromXYZ(
p.x(),
p.y(),
p.z());
539 phiL[
i] = atan2f(
p.y(),
p.x());
548 auto&&
p =
track.momentum();
549 float eta = etaFromXYZ(
p.x(),
p.y(),
p.z());
550 float phi = atan2f(
p.y(),
p.x());
558 if (
cores !=
nullptr) {
559 for (
unsigned int ji = 0; ji <
cores->size(); ji++) {
561 double jet_eta =
jet.eta();
562 double jet_phi =
jet.phi();
564 if (dR_jet_tmp < dR_jet)
582 using namespace reco;
584 LogDebug(
"TrackValidator") <<
"\n===================================================="
586 <<
"Analyzing new event"
588 <<
"====================================================\n"
593 auto parametersDefinerTP = parametersDefinerTPHandle->clone();
609 if (!tp_effic_refvector) {
611 for (
size_t i = 0,
size = TPCollectionHeff->size();
i <
size; ++
i) {
614 tmpTPeffPtr = &tmpTPeff;
617 tmpTPeffPtr = TPCollectionHeffRefVector.
product();
622 for (
size_t i = 0,
size = TPCollectionHfake->size();
i <
size; ++
i) {
625 tmpTPfakePtr = &tmpTPfake;
629 tmpTPfakePtr = TPCollectionHfakeRefVector.
product();
635 ensureEffIsSubsetOfFake(tPCeff, tPCfake);
641 parametersDefinerTP->initEvent(simHitsTPAssoc);
650 if (!theSimPVPosition)
668 thePVposition =
nullptr;
672 event.getByToken(
bsSrc, recoBeamSpotHandle);
679 for (
unsigned int puinfo_ite = 0; puinfo_ite < (*puinfoH).size(); ++puinfo_ite) {
680 if ((*puinfoH)[puinfo_ite].getBunchCrossing() == 0) {
681 puinfo = (*puinfoH)[puinfo_ite];
689 const auto& nLayers_tPCeff = *tpNLayersH;
692 const auto& nPixelLayers_tPCeff = *tpNLayersH;
695 const auto& nStripMonoAndStereoLayers_tPCeff = *tpNLayersH;
715 std::vector<size_t> selected_tPCeff;
716 std::vector<std::tuple<TrackingParticle::Vector, TrackingParticle::Point>> momVert_tPCeff;
727 if (
cores.isValid()) {
728 coresVector =
cores.product();
733 size_t n_selTP_dr =
tpDR(tPCeff, selected_tPCeff, dR_tPCeff, dR_tPCeff_jet, coresVector);
743 std::vector<const edm::ValueMap<reco::DeDxData>*> v_dEdx;
749 v_dEdx.push_back(dEdx1Handle.
product());
750 v_dEdx.push_back(dEdx2Handle.
product());
753 std::vector<const MVACollection*> mvaCollections;
754 std::vector<const QualityMaskCollection*> qualityMaskCollections;
755 std::vector<float> mvaValues;
758 for (
unsigned int ww = 0; ww <
associators.size(); ww++) {
766 simRecCollPFull = simtorecoCollectionH.
product();
770 recSimCollP = recotosimCollectionH.
product();
776 recSimCollP = &recSimCollL;
779 for (
unsigned int www = 0; www <
label.size();
804 LogTrace(
"TrackValidator") <<
"Calling associateRecoToSim method"
807 recSimCollP = &recSimCollL;
808 LogTrace(
"TrackValidator") <<
"Calling associateSimToReco method"
817 simRecCollP = &simRecCollL;
824 simRecCollP = &simRecCollL;
835 event.getByToken(std::get<0>(tokenTpl), hmva);
836 event.getByToken(std::get<1>(tokenTpl), hqual);
838 mvaCollections.push_back(hmva.
product());
839 qualityMaskCollections.push_back(hqual.
product());
842 <<
"Inconsistency in track collection and MVA sizes. Track collection " << www <<
" has "
843 <<
trackCollection.size() <<
" tracks, whereas the MVA " << (mvaCollections.size() - 1)
844 <<
" for it has " << mvaCollections.back()->size() <<
" entries. Double-check your configuration.";
848 <<
"Inconsistency in track collection and quality mask sizes. Track collection " << www <<
" has "
849 <<
trackCollection.size() <<
" tracks, whereas the quality mask " << (qualityMaskCollections.size() - 1)
850 <<
" for it has " << qualityMaskCollections.back()->size()
851 <<
" entries. Double-check your configuration.";
862 LogTrace(
"TrackValidator") <<
"\n# of TrackingParticles: " << tPCeff.
size() <<
"\n";
867 for (
size_t i = 0;
i < selected_tPCeff.size(); ++
i) {
868 size_t iTP = selected_tPCeff[
i];
872 auto const& momVert = momVert_tPCeff[
i];
880 double dR = dR_tPCeff[iTP];
881 double dR_jet = dR_tPCeff_jet[iTP];
886 momentumTP =
tp.momentum();
887 vertexTP =
tp.vertex();
894 if (theSimPVPosition) {
901 momentumTP = std::get<TrackingParticle::Vector>(momVert);
902 vertexTP = std::get<TrackingParticle::Point>(momVert);
922 const reco::Track* matchedSecondTrackPointer =
nullptr;
923 unsigned int selectsLoose = mvaCollections.size();
924 unsigned int selectsHP = mvaCollections.size();
925 if (simRecColl.
find(tpr) != simRecColl.
end()) {
926 auto const&
rt = simRecColl[tpr];
930 matchedTrackPointer =
rt.begin()->first.get();
931 if (
rt.size() >= 2) {
932 matchedSecondTrackPointer = (
rt.begin() + 1)->
first.get();
934 LogTrace(
"TrackValidator") <<
"TrackingParticle #" << st <<
" with pt=" <<
sqrt(momentumTP.perp2())
935 <<
" associated with quality:" <<
rt.begin()->second <<
"\n";
944 for (
size_t imva = 0; imva < mvaCollections.size(); ++imva) {
945 const auto&
mva = *(mvaCollections[imva]);
946 const auto& qual = *(qualityMaskCollections[imva]);
948 auto iMatch =
rt.begin();
949 float maxMva =
mva[iMatch->first.key()];
950 for (; iMatch !=
rt.end(); ++iMatch) {
951 auto itrk = iMatch->first.key();
959 mvaValues.push_back(maxMva);
964 LogTrace(
"TrackValidator") <<
"TrackingParticle #" << st <<
" with pt,eta,phi: " <<
sqrt(momentumTP.perp2())
965 <<
" , " << momentumTP.eta() <<
" , " << momentumTP.phi() <<
" , "
966 <<
" NOT associated to any reco::Track"
970 int nSimHits =
tp.numberOfTrackerHits();
971 int nSimLayers = nLayers_tPCeff[tpr];
972 int nSimPixelLayers = nPixelLayers_tPCeff[tpr];
973 int nSimStripMonoAndStereoLayers = nStripMonoAndStereoLayers_tPCeff[tpr];
986 nSimStripMonoAndStereoLayers,
999 if (matchedTrackPointer && matchedSecondTrackPointer) {
1001 histograms.histoProducerAlgo,
w, *matchedTrackPointer, *matchedSecondTrackPointer);
1007 if (matchedTrackPointer) {
1020 LogTrace(
"TrackValidator") <<
"\n# of reco::Tracks with " <<
label[www].process() <<
":" <<
label[www].label()
1026 int seed_fit_failed = 0;
1027 size_t n_selTrack_dr = 0;
1046 bool isSigSimMatched(
false);
1047 bool isSimMatched(
false);
1048 bool isChargeMatched(
true);
1049 int numAssocRecoTracks = 0;
1051 double sharedFraction = 0.;
1054 isSimMatched = tpFound != recSimColl.
end();
1056 const auto&
tp = tpFound->val;
1057 nSimHits =
tp[0].first->numberOfTrackerHits();
1058 sharedFraction =
tp[0].second;
1060 isChargeMatched =
false;
1061 if (simRecColl.
find(
tp[0].first) != simRecColl.
end())
1062 numAssocRecoTracks = simRecColl[
tp[0].
first].
size();
1064 for (
unsigned int tp_ite = 0; tp_ite <
tp.size(); ++tp_ite) {
1067 isSigSimMatched =
true;
1072 LogTrace(
"TrackValidator") <<
"reco::Track #" << rT <<
" with pt=" <<
track->pt()
1073 <<
" associated with quality:" <<
tp.begin()->second <<
"\n";
1075 LogTrace(
"TrackValidator") <<
"reco::Track #" << rT <<
" with pt=" <<
track->pt()
1076 <<
" NOT associated to any TrackingParticle"
1083 unsigned int selectsLoose = mvaCollections.size();
1084 unsigned int selectsHP = mvaCollections.size();
1086 for (
size_t imva = 0; imva < mvaCollections.size(); ++imva) {
1087 const auto&
mva = *(mvaCollections[imva]);
1088 const auto& qual = *(qualityMaskCollections[imva]);
1089 mvaValues.push_back(
mva[
i]);
1092 selectsLoose = imva;
1098 double dR = dR_trk[
i];
1099 double dR_jet = dR_trk_jet[
i];
1125 if (numAssocRecoTracks > 1) {
1128 if (!isSigSimMatched) {
1163 int chargeTP = tpr->charge();
1166 histograms.histoProducerAlgo,
w, momentumTP, vertexTP, chargeTP, *
track,
bs.position());
1174 mvaCollections.clear();
1175 qualityMaskCollections.clear();
1184 LogTrace(
"TrackValidator") <<
"Collection " << www <<
"\n"
1185 <<
"Total Simulated (selected): " << n_selTP_dr <<
"\n"
1186 <<
"Total Reconstructed (selected): " << n_selTrack_dr <<
"\n"
1187 <<
"Total Reconstructed: " << rT <<
"\n"
1188 <<
"Total Associated (recoToSim): " << at <<
"\n"
1189 <<
"Total Fakes: " << rT - at <<
"\n";