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())
356 if (eff.
id() !=
fake.id()) {
358 <<
"Efficiency and fake TrackingParticle (refs) point to different collections (eff " << eff.
id() <<
" fake "
360 <<
"). This is not supported. Efficiency TP set must be the same or a subset of the fake TP set.";
366 for (
const auto& ref :
fake) {
367 fakeKeys.
insert(ref.key());
370 for (
const auto& ref : eff) {
371 if (!fakeKeys.
has(ref.key())) {
372 throw cms::Exception(
"Configuration") <<
"Efficiency TrackingParticle " << ref.key()
373 <<
" is not found from the set of fake TPs. This is not supported. The "
374 "efficiency TP set must be the same or a subset of the fake TP set.";
383 for (
const auto& simV : *htv) {
384 if (simV.eventId().bunchCrossing() != 0)
386 if (simV.eventId().event() != 0)
388 return &(simV.position());
402 auto pvPtr = hvertex->refAt(0);
403 if (pvPtr->isFake() || pvPtr->ndof() < 0)
406 auto pvFound = v_r2s.find(pvPtr);
407 if (pvFound == v_r2s.end())
410 for (
const auto& vertexRefQuality : pvFound->val) {
413 return &(pvPtr->position());
427 std::vector<std::tuple<TrackingParticle::Vector, TrackingParticle::Point>>& momVert_tPCeff,
428 std::vector<size_t>& selected_tPCeff)
const {
429 selected_tPCeff.reserve(tPCeff.
size());
430 momVert_tPCeff.reserve(tPCeff.
size());
433 for (
size_t j = 0;
j < tPCeff.
size(); ++
j) {
441 histograms.histoProducerAlgo, momentum,
vertex, tpr->eventId().bunchCrossing());
443 if (tpr->eventId().bunchCrossing() == 0)
447 selected_tPCeff.push_back(
j);
448 momVert_tPCeff.emplace_back(momentum,
vertex);
453 for (
auto const& tpr : tPCeff) {
462 histograms.histoProducerAlgo,
tp.momentum(),
tp.vertex(),
tp.eventId().bunchCrossing());
464 if (
tp.eventId().bunchCrossing() == 0)
468 selected_tPCeff.push_back(
j);
480 const std::vector<size_t>& selected_tPCeff,
484 float etaL[tPCeff.
size()], phiL[tPCeff.
size()];
485 size_t n_selTP_dr = 0;
486 for (
size_t iTP : selected_tPCeff) {
488 auto const& tp2 = *(tPCeff[iTP]);
489 auto&&
p = tp2.momentum();
490 etaL[iTP] = etaFromXYZ(
p.x(),
p.y(),
p.z());
491 phiL[iTP] = atan2f(
p.y(),
p.x());
493 for (
size_t iTP1 : selected_tPCeff) {
494 auto const&
tp = *(tPCeff[iTP1]);
499 float eta = etaL[iTP1];
500 float phi = phiL[iTP1];
501 for (
size_t iTP2 : selected_tPCeff) {
510 if (
cores !=
nullptr) {
511 for (
unsigned int ji = 0; ji <
cores->size(); ji++) {
513 double jet_eta =
jet.eta();
514 double jet_phi =
jet.phi();
516 if (dR_jet_tmp < dR_jet)
534 float etaL[trackCollectionDr.
size()];
535 float phiL[trackCollectionDr.
size()];
536 bool validL[trackCollectionDr.
size()];
537 for (
auto const& track2 : trackCollectionDr) {
538 auto&&
p = track2.momentum();
539 etaL[
i] = etaFromXYZ(
p.x(),
p.y(),
p.z());
540 phiL[
i] = atan2f(
p.y(),
p.x());
549 auto&&
p =
track.momentum();
550 float eta = etaFromXYZ(
p.x(),
p.y(),
p.z());
551 float phi = atan2f(
p.y(),
p.x());
559 if (
cores !=
nullptr) {
560 for (
unsigned int ji = 0; ji <
cores->size(); ji++) {
562 double jet_eta =
jet.eta();
563 double jet_phi =
jet.phi();
565 if (dR_jet_tmp < dR_jet)
583 using namespace reco;
585 LogDebug(
"TrackValidator") <<
"\n===================================================="
587 <<
"Analyzing new event"
589 <<
"====================================================\n"
594 auto parametersDefinerTP = parametersDefinerTPHandle->clone();
610 if (!tp_effic_refvector) {
612 tmpTPeff.
reserve(TPCollectionHeff->size());
613 for (
size_t i = 0,
size = TPCollectionHeff->size();
i <
size; ++
i) {
616 tmpTPeffPtr = &tmpTPeff;
619 tmpTPeffPtr = TPCollectionHeffRefVector.
product();
624 tmpTPfake.
reserve(TPCollectionHfake->size());
625 for (
size_t i = 0,
size = TPCollectionHfake->size();
i <
size; ++
i) {
628 tmpTPfakePtr = &tmpTPfake;
632 tmpTPfakePtr = TPCollectionHfakeRefVector.
product();
639 ensureEffIsSubsetOfFake(tPCeff, tPCfake);
646 parametersDefinerTP->initEvent(simHitsTPAssoc);
655 if (!theSimPVPosition)
673 thePVposition =
nullptr;
677 event.getByToken(
bsSrc, recoBeamSpotHandle);
684 for (
unsigned int puinfo_ite = 0; puinfo_ite < (*puinfoH).size(); ++puinfo_ite) {
685 if ((*puinfoH)[puinfo_ite].getBunchCrossing() == 0) {
686 puinfo = (*puinfoH)[puinfo_ite];
694 const auto& nLayers_tPCeff = *tpNLayersH;
697 const auto& nPixelLayers_tPCeff = *tpNLayersH;
700 const auto& nStripMonoAndStereoLayers_tPCeff = *tpNLayersH;
720 std::vector<size_t> selected_tPCeff;
721 std::vector<std::tuple<TrackingParticle::Vector, TrackingParticle::Point>> momVert_tPCeff;
732 if (
cores.isValid()) {
733 coresVector =
cores.product();
738 size_t n_selTP_dr =
tpDR(tPCeff, selected_tPCeff, dR_tPCeff, dR_tPCeff_jet, coresVector);
748 std::vector<const edm::ValueMap<reco::DeDxData>*> v_dEdx;
754 v_dEdx.push_back(dEdx1Handle.
product());
755 v_dEdx.push_back(dEdx2Handle.
product());
758 std::vector<const MVACollection*> mvaCollections;
759 std::vector<const QualityMaskCollection*> qualityMaskCollections;
760 std::vector<float> mvaValues;
763 for (
unsigned int ww = 0; ww <
associators.size(); ww++) {
771 simRecCollPFull = simtorecoCollectionH.
product();
775 recSimCollP = recotosimCollectionH.
product();
781 recSimCollP = &recSimCollL;
784 for (
unsigned int www = 0; www <
label.size();
810 LogTrace(
"TrackValidator") <<
"Calling associateRecoToSim method"
813 recSimCollP = &recSimCollL;
814 LogTrace(
"TrackValidator") <<
"Calling associateSimToReco method"
823 simRecCollP = &simRecCollL;
830 simRecCollP = &simRecCollL;
841 event.getByToken(std::get<0>(tokenTpl), hmva);
842 event.getByToken(std::get<1>(tokenTpl), hqual);
844 mvaCollections.push_back(hmva.
product());
845 qualityMaskCollections.push_back(hqual.
product());
848 <<
"Inconsistency in track collection and MVA sizes. Track collection " << www <<
" has "
849 <<
trackCollection.size() <<
" tracks, whereas the MVA " << (mvaCollections.size() - 1)
850 <<
" for it has " << mvaCollections.back()->size() <<
" entries. Double-check your configuration.";
854 <<
"Inconsistency in track collection and quality mask sizes. Track collection " << www <<
" has "
855 <<
trackCollection.size() <<
" tracks, whereas the quality mask " << (qualityMaskCollections.size() - 1)
856 <<
" for it has " << qualityMaskCollections.back()->size()
857 <<
" entries. Double-check your configuration.";
868 LogTrace(
"TrackValidator") <<
"\n# of TrackingParticles: " << tPCeff.
size() <<
"\n";
873 for (
size_t i = 0;
i < selected_tPCeff.size(); ++
i) {
874 size_t iTP = selected_tPCeff[
i];
878 auto const& momVert = momVert_tPCeff[
i];
886 double dR = dR_tPCeff[iTP];
887 double dR_jet = dR_tPCeff_jet[iTP];
892 momentumTP =
tp.momentum();
893 vertexTP =
tp.vertex();
900 if (theSimPVPosition) {
907 momentumTP = std::get<TrackingParticle::Vector>(momVert);
908 vertexTP = std::get<TrackingParticle::Point>(momVert);
928 const reco::Track* matchedSecondTrackPointer =
nullptr;
929 unsigned int selectsLoose = mvaCollections.size();
930 unsigned int selectsHP = mvaCollections.size();
931 if (simRecColl.
find(tpr) != simRecColl.
end()) {
932 auto const&
rt = simRecColl[tpr];
936 matchedTrackPointer =
rt.begin()->first.get();
937 if (
rt.size() >= 2) {
938 matchedSecondTrackPointer = (
rt.begin() + 1)->
first.get();
940 LogTrace(
"TrackValidator") <<
"TrackingParticle #" << st <<
" with pt=" <<
sqrt(momentumTP.perp2())
941 <<
" associated with quality:" <<
rt.begin()->second <<
"\n";
950 for (
size_t imva = 0; imva < mvaCollections.size(); ++imva) {
951 const auto&
mva = *(mvaCollections[imva]);
952 const auto& qual = *(qualityMaskCollections[imva]);
954 auto iMatch =
rt.begin();
955 float maxMva =
mva[iMatch->first.key()];
956 for (; iMatch !=
rt.end(); ++iMatch) {
957 auto itrk = iMatch->first.key();
965 mvaValues.push_back(maxMva);
970 LogTrace(
"TrackValidator") <<
"TrackingParticle #" << st <<
" with pt,eta,phi: " <<
sqrt(momentumTP.perp2())
971 <<
" , " << momentumTP.eta() <<
" , " << momentumTP.phi() <<
" , "
972 <<
" NOT associated to any reco::Track"
976 int nSimHits =
tp.numberOfTrackerHits();
977 int nSimLayers = nLayers_tPCeff[tpr];
978 int nSimPixelLayers = nPixelLayers_tPCeff[tpr];
979 int nSimStripMonoAndStereoLayers = nStripMonoAndStereoLayers_tPCeff[tpr];
992 nSimStripMonoAndStereoLayers,
1005 if (matchedTrackPointer && matchedSecondTrackPointer) {
1007 histograms.histoProducerAlgo,
w, *matchedTrackPointer, *matchedSecondTrackPointer);
1013 if (matchedTrackPointer) {
1026 LogTrace(
"TrackValidator") <<
"\n# of reco::Tracks with " <<
label[www].process() <<
":" <<
label[www].label()
1032 int seed_fit_failed = 0;
1033 size_t n_selTrack_dr = 0;
1055 bool isSigSimMatched(
false);
1056 bool isSimMatched(
false);
1057 bool isChargeMatched(
true);
1058 int numAssocRecoTracks = 0;
1060 double sharedFraction = 0.;
1063 isSimMatched = tpFound != recSimColl.
end();
1065 const auto&
tp = tpFound->val;
1066 nSimHits =
tp[0].first->numberOfTrackerHits();
1067 sharedFraction =
tp[0].second;
1069 isChargeMatched =
false;
1070 if (simRecColl.
find(
tp[0].first) != simRecColl.
end())
1071 numAssocRecoTracks = simRecColl[
tp[0].
first].
size();
1073 for (
unsigned int tp_ite = 0; tp_ite <
tp.size(); ++tp_ite) {
1076 isSigSimMatched =
true;
1081 LogTrace(
"TrackValidator") <<
"reco::Track #" << rT <<
" with pt=" <<
track->pt()
1082 <<
" associated with quality:" <<
tp.begin()->second <<
"\n";
1084 LogTrace(
"TrackValidator") <<
"reco::Track #" << rT <<
" with pt=" <<
track->pt()
1085 <<
" NOT associated to any TrackingParticle"
1092 unsigned int selectsLoose = mvaCollections.size();
1093 unsigned int selectsHP = mvaCollections.size();
1095 for (
size_t imva = 0; imva < mvaCollections.size(); ++imva) {
1096 const auto&
mva = *(mvaCollections[imva]);
1097 const auto& qual = *(qualityMaskCollections[imva]);
1098 mvaValues.push_back(
mva[
i]);
1101 selectsLoose = imva;
1107 double dR = dR_trk[
i];
1108 double dR_jet = dR_trk_jet[
i];
1134 if (numAssocRecoTracks > 1) {
1137 if (!isSigSimMatched) {
1172 int chargeTP = tpr->charge();
1175 histograms.histoProducerAlgo,
w, momentumTP, vertexTP, chargeTP, *
track,
bs.position());
1183 mvaCollections.clear();
1184 qualityMaskCollections.clear();
1193 LogTrace(
"TrackValidator") <<
"Collection " << www <<
"\n"
1194 <<
"Total Simulated (selected): " << n_selTP_dr <<
"\n"
1195 <<
"Total Reconstructed (selected): " << n_selTrack_dr <<
"\n"
1196 <<
"Total Reconstructed: " << rT <<
"\n"
1197 <<
"Total Associated (recoToSim): " << at <<
"\n"
1198 <<
"Total Fakes: " << rT - at <<
"\n";