32 #include <type_traits>
45 bool trackSelected(
unsigned char mask,
unsigned char qual) {
return mask & 1 << qual; }
54 ignoremissingtkcollection_(
pset.getUntrackedParameter<
bool>(
"ignoremissingtrackcollection",
false)),
55 useAssociators_(
pset.getParameter<
bool>(
"UseAssociators")),
56 calculateDrSingleCollection_(
pset.getUntrackedParameter<
bool>(
"calculateDrSingleCollection")),
57 doPlotsOnlyForTruePV_(
pset.getUntrackedParameter<
bool>(
"doPlotsOnlyForTruePV")),
58 doSummaryPlots_(
pset.getUntrackedParameter<
bool>(
"doSummaryPlots")),
59 doSimPlots_(
pset.getUntrackedParameter<
bool>(
"doSimPlots")),
60 doSimTrackPlots_(
pset.getUntrackedParameter<
bool>(
"doSimTrackPlots")),
61 doRecoTrackPlots_(
pset.getUntrackedParameter<
bool>(
"doRecoTrackPlots")),
62 dodEdxPlots_(
pset.getUntrackedParameter<
bool>(
"dodEdxPlots")),
63 doPVAssociationPlots_(
pset.getUntrackedParameter<
bool>(
"doPVAssociationPlots")),
64 doSeedPlots_(
pset.getUntrackedParameter<
bool>(
"doSeedPlots")),
65 doMVAPlots_(
pset.getUntrackedParameter<
bool>(
"doMVAPlots")),
66 simPVMaxZ_(
pset.getUntrackedParameter<double>(
"simPVMaxZ")) {
78 if (
pset.getParameter<
bool>(
"label_tp_effic_refvector")) {
81 label_tp_effic = consumes<TrackingParticleCollection>(label_tp_effic_tag);
83 if (
pset.getParameter<
bool>(
"label_tp_fake_refvector")) {
86 label_tp_fake = consumes<TrackingParticleCollection>(label_tp_fake_tag);
89 for (
const auto&
tag :
pset.getParameter<std::vector<edm::InputTag>>(
"sim")) {
94 pset.getParameter<std::vector<edm::InputTag>>(
"doResolutionPlotsForLabels");
96 for (
auto& itag :
label) {
105 std::sort(
begin(labelTmp),
end(labelTmp));
110 throw cms::Exception(
"Configuration") <<
"Duplicate InputTag in labels: " <<
l;
126 consumes<edm::ValueMap<unsigned int>>(
pset.getParameter<
edm::InputTag>(
"label_tp_npixellayers"));
128 consumes<edm::ValueMap<unsigned int>>(
pset.getParameter<
edm::InputTag>(
"label_tp_nstripstereolayers"));
139 consumes<reco::VertexToTrackingVertexAssociator>(
pset.getUntrackedParameter<
edm::InputTag>(
"vertexAssociator"));
145 for (
size_t iIter = 0; iIter <
labelToken.size(); ++iIter) {
148 if (mvaPSet.exists(
labels.module)) {
150 mvaPSet.getUntrackedParameter<std::vector<std::string>>(
labels.module), [&](
const std::string&
tag) {
151 return std::make_tuple(consumes<MVACollection>(edm::InputTag(tag,
"MVAValues")),
152 consumes<QualityMaskCollection>(edm::InputTag(tag,
"QualityMasks")));
159 pset.getParameter<
double>(
"ptMaxTP"),
160 pset.getParameter<
double>(
"minRapidityTP"),
161 pset.getParameter<
double>(
"maxRapidityTP"),
162 pset.getParameter<
double>(
"tipTP"),
163 pset.getParameter<
double>(
"lipTP"),
164 pset.getParameter<
int>(
"minHitTP"),
165 pset.getParameter<
bool>(
"signalOnlyTP"),
166 pset.getParameter<
bool>(
"intimeOnlyTP"),
167 pset.getParameter<
bool>(
"chargedOnlyTP"),
168 pset.getParameter<
bool>(
"stableOnlyTP"),
169 pset.getParameter<std::vector<int>>(
"pdgIdTP"),
170 pset.getParameter<
bool>(
"invertRapidityCutTP"));
173 pset.getParameter<
double>(
"minRapidityTP"),
174 pset.getParameter<
double>(
"maxRapidityTP"),
175 pset.getParameter<
double>(
"tipTP"),
176 pset.getParameter<
double>(
"lipTP"),
177 pset.getParameter<
int>(
"minHitTP"),
178 pset.getParameter<
bool>(
"chargedOnlyTP"),
179 pset.getParameter<std::vector<int>>(
"pdgIdTP"));
200 _simHitTpMapTag = mayConsume<SimHitTPAssociationProducer::SimHitTPAssociationList>(
205 consumes<edm::View<reco::Track>>(
pset.getParameter<
edm::InputTag>(
"trackCollectionForDrCalculation"));
231 const auto minColl = -0.5;
232 const auto maxColl =
label.size() - 0.5;
233 const auto nintColl =
label.size();
236 for (
size_t i = 0;
i <
label.size(); ++
i) {
239 me->disableAlphanumeric();
254 for (
unsigned int ww = 0; ww <
associators.size(); ww++) {
262 binLabels(ibook.
book1D(
"num_assoc(simToReco)_coll",
263 "N of associated (simToReco) tracks vs track collection",
268 ibook.
book1D(
"num_simul_coll",
"N of simulated tracks vs track collection", nintColl, minColl, maxColl)));
272 ibook.
book1D(
"num_reco_coll",
"N of reco track vs track collection", nintColl, minColl, maxColl)));
274 binLabels(ibook.
book1D(
"num_assoc(recoToSim)_coll",
275 "N of associated (recoToSim) tracks vs track collection",
280 binLabels(ibook.
book1D(
"num_duplicate_coll",
281 "N of associated (recoToSim) looper tracks vs track collection",
286 binLabels(ibook.
book1D(
"num_pileup_coll",
287 "N of associated (recoToSim) pileup tracks vs track collection",
294 for (
unsigned int www = 0; www <
label.size(); www++) {
298 if (!
algo.process().empty())
300 if (!
algo.label().empty())
302 if (!
algo.instance().empty())
353 if (eff.
id() != fake.
id()) {
355 <<
"Efficiency and fake TrackingParticle (refs) point to different collections (eff " << eff.
id() <<
" fake "
357 <<
"). This is not supported. Efficiency TP set must be the same or a subset of the fake TP set.";
363 for (
const auto& ref : fake) {
364 fakeKeys.
insert(ref.key());
367 for (
const auto& ref : eff) {
368 if (!fakeKeys.
has(ref.key())) {
369 throw cms::Exception(
"Configuration") <<
"Efficiency TrackingParticle " << ref.key()
370 <<
" is not found from the set of fake TPs. This is not supported. The "
371 "efficiency TP set must be the same or a subset of the fake TP set.";
379 for (
const auto& simV : *htv) {
380 if (simV.eventId().bunchCrossing() != 0)
382 if (simV.eventId().event() != 0)
384 return &(simV.position());
398 auto pvPtr = hvertex->refAt(0);
399 if (pvPtr->isFake() || pvPtr->ndof() < 0)
402 auto pvFound = v_r2s.find(pvPtr);
403 if (pvFound == v_r2s.end())
406 for (
const auto& vertexRefQuality : pvFound->val) {
409 return &(pvPtr->position());
423 std::vector<std::tuple<TrackingParticle::Vector, TrackingParticle::Point>>& momVert_tPCeff,
424 std::vector<size_t>& selected_tPCeff)
const {
425 selected_tPCeff.reserve(tPCeff.
size());
426 momVert_tPCeff.reserve(tPCeff.
size());
429 for (
size_t j = 0;
j < tPCeff.
size(); ++
j) {
436 histograms.histoProducerAlgo, momentum,
vertex, tpr->eventId().bunchCrossing());
438 if (tpr->eventId().bunchCrossing() == 0)
442 selected_tPCeff.push_back(
j);
443 momVert_tPCeff.emplace_back(momentum,
vertex);
448 for (
auto const& tpr : tPCeff) {
457 histograms.histoProducerAlgo,
tp.momentum(),
tp.vertex(),
tp.eventId().bunchCrossing());
459 if (
tp.eventId().bunchCrossing() == 0)
463 selected_tPCeff.push_back(
j);
466 momVert_tPCeff.emplace_back(momentum,
vertex);
477 const std::vector<size_t>& selected_tPCeff,
481 float etaL[tPCeff.
size()], phiL[tPCeff.
size()];
482 size_t n_selTP_dr = 0;
483 for (
size_t iTP : selected_tPCeff) {
485 auto const& tp2 = *(tPCeff[iTP]);
486 auto&&
p = tp2.momentum();
487 etaL[iTP] = etaFromXYZ(
p.x(),
p.y(),
p.z());
488 phiL[iTP] = atan2f(
p.y(),
p.x());
490 for (
size_t iTP1 : selected_tPCeff) {
491 auto const&
tp = *(tPCeff[iTP1]);
496 float eta = etaL[iTP1];
497 float phi = phiL[iTP1];
498 for (
size_t iTP2 : selected_tPCeff) {
507 if (
cores !=
nullptr) {
508 for (
unsigned int ji = 0; ji <
cores->size(); ji++) {
510 double jet_eta =
jet.eta();
511 double jet_phi =
jet.phi();
513 if (dR_jet_tmp < dR_jet)
531 float etaL[trackCollectionDr.
size()];
532 float phiL[trackCollectionDr.
size()];
533 bool validL[trackCollectionDr.
size()];
534 for (
auto const& track2 : trackCollectionDr) {
535 auto&&
p = track2.momentum();
536 etaL[
i] = etaFromXYZ(
p.x(),
p.y(),
p.z());
537 phiL[
i] = atan2f(
p.y(),
p.x());
546 auto&&
p =
track.momentum();
547 float eta = etaFromXYZ(
p.x(),
p.y(),
p.z());
548 float phi = atan2f(
p.y(),
p.x());
556 if (
cores !=
nullptr) {
557 for (
unsigned int ji = 0; ji <
cores->size(); ji++) {
559 double jet_eta =
jet.eta();
560 double jet_phi =
jet.phi();
562 if (dR_jet_tmp < dR_jet)
580 using namespace reco;
582 LogDebug(
"TrackValidator") <<
"\n===================================================="
584 <<
"Analyzing new event"
586 <<
"====================================================\n"
592 auto parametersDefinerTP = parametersDefinerTPHandle->
clone();
610 if (!tp_effic_refvector) {
612 for (
size_t i = 0,
size = TPCollectionHeff->size();
i <
size; ++
i) {
615 tmpTPeffPtr = &tmpTPeff;
618 tmpTPeffPtr = TPCollectionHeffRefVector.
product();
623 for (
size_t i = 0,
size = TPCollectionHfake->size();
i <
size; ++
i) {
626 tmpTPfakePtr = &tmpTPfake;
630 tmpTPfakePtr = TPCollectionHfakeRefVector.
product();
636 ensureEffIsSubsetOfFake(tPCeff, tPCfake);
642 parametersDefinerTP->initEvent(simHitsTPAssoc);
651 if (!theSimPVPosition)
669 thePVposition =
nullptr;
673 event.getByToken(
bsSrc, recoBeamSpotHandle);
680 for (
unsigned int puinfo_ite = 0; puinfo_ite < (*puinfoH).size(); ++puinfo_ite) {
681 if ((*puinfoH)[puinfo_ite].getBunchCrossing() == 0) {
682 puinfo = (*puinfoH)[puinfo_ite];
690 const auto& nLayers_tPCeff = *tpNLayersH;
693 const auto& nPixelLayers_tPCeff = *tpNLayersH;
696 const auto& nStripMonoAndStereoLayers_tPCeff = *tpNLayersH;
716 std::vector<size_t> selected_tPCeff;
717 std::vector<std::tuple<TrackingParticle::Vector, TrackingParticle::Point>> momVert_tPCeff;
728 if (
cores.isValid()) {
729 coresVector =
cores.product();
734 size_t n_selTP_dr =
tpDR(tPCeff, selected_tPCeff, dR_tPCeff, dR_tPCeff_jet, coresVector);
744 std::vector<const edm::ValueMap<reco::DeDxData>*> v_dEdx;
750 v_dEdx.push_back(dEdx1Handle.
product());
751 v_dEdx.push_back(dEdx2Handle.
product());
754 std::vector<const MVACollection*> mvaCollections;
755 std::vector<const QualityMaskCollection*> qualityMaskCollections;
756 std::vector<float> mvaValues;
759 for (
unsigned int ww = 0; ww <
associators.size(); ww++) {
767 simRecCollPFull = simtorecoCollectionH.
product();
771 recSimCollP = recotosimCollectionH.
product();
777 recSimCollP = &recSimCollL;
780 for (
unsigned int www = 0; www <
label.size();
805 LogTrace(
"TrackValidator") <<
"Calling associateRecoToSim method"
808 recSimCollP = &recSimCollL;
809 LogTrace(
"TrackValidator") <<
"Calling associateSimToReco method"
818 simRecCollP = &simRecCollL;
825 simRecCollP = &simRecCollL;
836 event.getByToken(std::get<0>(tokenTpl), hmva);
837 event.getByToken(std::get<1>(tokenTpl), hqual);
839 mvaCollections.push_back(hmva.
product());
840 qualityMaskCollections.push_back(hqual.
product());
843 <<
"Inconsistency in track collection and MVA sizes. Track collection " << www <<
" has "
844 <<
trackCollection.size() <<
" tracks, whereas the MVA " << (mvaCollections.size() - 1)
845 <<
" for it has " << mvaCollections.back()->size() <<
" entries. Double-check your configuration.";
849 <<
"Inconsistency in track collection and quality mask sizes. Track collection " << www <<
" has "
850 <<
trackCollection.size() <<
" tracks, whereas the quality mask " << (qualityMaskCollections.size() - 1)
851 <<
" for it has " << qualityMaskCollections.back()->size()
852 <<
" entries. Double-check your configuration.";
863 LogTrace(
"TrackValidator") <<
"\n# of TrackingParticles: " << tPCeff.
size() <<
"\n";
868 for (
size_t i = 0;
i < selected_tPCeff.size(); ++
i) {
869 size_t iTP = selected_tPCeff[
i];
873 auto const& momVert = momVert_tPCeff[
i];
881 double dR = dR_tPCeff[iTP];
882 double dR_jet = dR_tPCeff_jet[iTP];
887 momentumTP =
tp.momentum();
888 vertexTP =
tp.vertex();
895 if (theSimPVPosition) {
902 momentumTP = std::get<TrackingParticle::Vector>(momVert);
903 vertexTP = std::get<TrackingParticle::Point>(momVert);
923 const reco::Track* matchedSecondTrackPointer =
nullptr;
924 unsigned int selectsLoose = mvaCollections.size();
925 unsigned int selectsHP = mvaCollections.size();
926 if (simRecColl.
find(tpr) != simRecColl.
end()) {
927 auto const&
rt = simRecColl[tpr];
931 matchedTrackPointer =
rt.begin()->first.get();
932 if (
rt.size() >= 2) {
933 matchedSecondTrackPointer = (
rt.begin() + 1)->
first.get();
935 LogTrace(
"TrackValidator") <<
"TrackingParticle #" << st <<
" with pt=" <<
sqrt(momentumTP.perp2())
936 <<
" associated with quality:" <<
rt.begin()->second <<
"\n";
945 for (
size_t imva = 0; imva < mvaCollections.size(); ++imva) {
946 const auto&
mva = *(mvaCollections[imva]);
947 const auto& qual = *(qualityMaskCollections[imva]);
949 auto iMatch =
rt.begin();
950 float maxMva =
mva[iMatch->first.key()];
951 for (; iMatch !=
rt.end(); ++iMatch) {
952 auto itrk = iMatch->first.key();
960 mvaValues.push_back(maxMva);
965 LogTrace(
"TrackValidator") <<
"TrackingParticle #" << st <<
" with pt,eta,phi: " <<
sqrt(momentumTP.perp2())
966 <<
" , " << momentumTP.eta() <<
" , " << momentumTP.phi() <<
" , "
967 <<
" NOT associated to any reco::Track"
971 int nSimHits =
tp.numberOfTrackerHits();
972 int nSimLayers = nLayers_tPCeff[tpr];
973 int nSimPixelLayers = nPixelLayers_tPCeff[tpr];
974 int nSimStripMonoAndStereoLayers = nStripMonoAndStereoLayers_tPCeff[tpr];
987 nSimStripMonoAndStereoLayers,
1000 if (matchedTrackPointer && matchedSecondTrackPointer) {
1002 histograms.histoProducerAlgo,
w, *matchedTrackPointer, *matchedSecondTrackPointer);
1008 if (matchedTrackPointer) {
1021 LogTrace(
"TrackValidator") <<
"\n# of reco::Tracks with " <<
label[www].process() <<
":" <<
label[www].label()
1027 int seed_fit_failed = 0;
1028 size_t n_selTrack_dr = 0;
1047 bool isSigSimMatched(
false);
1048 bool isSimMatched(
false);
1049 bool isChargeMatched(
true);
1050 int numAssocRecoTracks = 0;
1052 double sharedFraction = 0.;
1055 isSimMatched = tpFound != recSimColl.
end();
1057 const auto&
tp = tpFound->val;
1058 nSimHits =
tp[0].first->numberOfTrackerHits();
1059 sharedFraction =
tp[0].second;
1061 isChargeMatched =
false;
1062 if (simRecColl.
find(
tp[0].first) != simRecColl.
end())
1063 numAssocRecoTracks = simRecColl[
tp[0].
first].
size();
1065 for (
unsigned int tp_ite = 0; tp_ite <
tp.size(); ++tp_ite) {
1068 isSigSimMatched =
true;
1073 LogTrace(
"TrackValidator") <<
"reco::Track #" << rT <<
" with pt=" <<
track->pt()
1074 <<
" associated with quality:" <<
tp.begin()->second <<
"\n";
1076 LogTrace(
"TrackValidator") <<
"reco::Track #" << rT <<
" with pt=" <<
track->pt()
1077 <<
" NOT associated to any TrackingParticle"
1084 unsigned int selectsLoose = mvaCollections.size();
1085 unsigned int selectsHP = mvaCollections.size();
1087 for (
size_t imva = 0; imva < mvaCollections.size(); ++imva) {
1088 const auto&
mva = *(mvaCollections[imva]);
1089 const auto& qual = *(qualityMaskCollections[imva]);
1090 mvaValues.push_back(
mva[
i]);
1093 selectsLoose = imva;
1099 double dR = dR_trk[
i];
1100 double dR_jet = dR_trk_jet[
i];
1126 if (numAssocRecoTracks > 1) {
1129 if (!isSigSimMatched) {
1164 int chargeTP = tpr->charge();
1167 histograms.histoProducerAlgo,
w, momentumTP, vertexTP, chargeTP, *
track,
bs.position());
1175 mvaCollections.clear();
1176 qualityMaskCollections.clear();
1185 LogTrace(
"TrackValidator") <<
"Collection " << www <<
"\n"
1186 <<
"Total Simulated (selected): " << n_selTP_dr <<
"\n"
1187 <<
"Total Reconstructed (selected): " << n_selTrack_dr <<
"\n"
1188 <<
"Total Reconstructed: " << rT <<
"\n"
1189 <<
"Total Associated (recoToSim): " << at <<
"\n"
1190 <<
"Total Fakes: " << rT - at <<
"\n";