CMS 3D CMS Logo

MultiTrackValidator.cc
Go to the documentation of this file.
3 
7 
25 
31 #include <type_traits>
32 
33 #include "TMath.h"
34 #include <TF1.h>
37 //#include <iostream>
38 
39 using namespace std;
40 using namespace edm;
41 
43 namespace {
44  bool trackSelected(unsigned char mask, unsigned char qual) { return mask & 1 << qual; }
45 
46 } // namespace
47 
49  : tTopoEsToken(esConsumes()),
50  parametersDefinerIsCosmic_(pset.getParameter<std::string>("parametersDefiner") == "CosmicParametersDefinerForTP"),
51  associators(pset.getUntrackedParameter<std::vector<edm::InputTag>>("associators")),
52  label(pset.getParameter<std::vector<edm::InputTag>>("label")),
53  ignoremissingtkcollection_(pset.getUntrackedParameter<bool>("ignoremissingtrackcollection", false)),
54  useAssociators_(pset.getParameter<bool>("UseAssociators")),
55  calculateDrSingleCollection_(pset.getUntrackedParameter<bool>("calculateDrSingleCollection")),
56  doPlotsOnlyForTruePV_(pset.getUntrackedParameter<bool>("doPlotsOnlyForTruePV")),
57  doSummaryPlots_(pset.getUntrackedParameter<bool>("doSummaryPlots")),
58  doSimPlots_(pset.getUntrackedParameter<bool>("doSimPlots")),
59  doSimTrackPlots_(pset.getUntrackedParameter<bool>("doSimTrackPlots")),
60  doRecoTrackPlots_(pset.getUntrackedParameter<bool>("doRecoTrackPlots")),
61  dodEdxPlots_(pset.getUntrackedParameter<bool>("dodEdxPlots")),
62  doPVAssociationPlots_(pset.getUntrackedParameter<bool>("doPVAssociationPlots")),
63  doSeedPlots_(pset.getUntrackedParameter<bool>("doSeedPlots")),
64  doMVAPlots_(pset.getUntrackedParameter<bool>("doMVAPlots")),
65  simPVMaxZ_(pset.getUntrackedParameter<double>("simPVMaxZ")) {
66  if (not(pset.getParameter<edm::InputTag>("cores").label().empty())) {
67  cores_ = consumes<edm::View<reco::Candidate>>(pset.getParameter<edm::InputTag>("cores"));
68  }
69  if (label.empty()) {
70  // Disable prefetching of everything if there are no track collections
71  return;
72  }
73 
74  const edm::InputTag& label_tp_effic_tag = pset.getParameter<edm::InputTag>("label_tp_effic");
75  const edm::InputTag& label_tp_fake_tag = pset.getParameter<edm::InputTag>("label_tp_fake");
76 
77  if (pset.getParameter<bool>("label_tp_effic_refvector")) {
78  label_tp_effic_refvector = consumes<TrackingParticleRefVector>(label_tp_effic_tag);
79  } else {
80  label_tp_effic = consumes<TrackingParticleCollection>(label_tp_effic_tag);
81  }
82  if (pset.getParameter<bool>("label_tp_fake_refvector")) {
83  label_tp_fake_refvector = consumes<TrackingParticleRefVector>(label_tp_fake_tag);
84  } else {
85  label_tp_fake = consumes<TrackingParticleCollection>(label_tp_fake_tag);
86  }
87  label_pileupinfo = consumes<std::vector<PileupSummaryInfo>>(pset.getParameter<edm::InputTag>("label_pileupinfo"));
88  for (const auto& tag : pset.getParameter<std::vector<edm::InputTag>>("sim")) {
89  simHitTokens_.push_back(consumes<std::vector<PSimHit>>(tag));
90  }
91 
92  std::vector<edm::InputTag> doResolutionPlotsForLabels =
93  pset.getParameter<std::vector<edm::InputTag>>("doResolutionPlotsForLabels");
94  doResolutionPlots_.reserve(label.size());
95  for (auto& itag : label) {
96  labelToken.push_back(consumes<edm::View<reco::Track>>(itag));
97  const bool doResol = doResolutionPlotsForLabels.empty() ||
100  doResolutionPlots_.push_back(doResol);
101  }
102  { // check for duplicates
103  auto labelTmp = edm::vector_transform(label, [&](const edm::InputTag& tag) { return tag.label(); });
104  std::sort(begin(labelTmp), end(labelTmp));
106  const std::string* prev = &empty;
107  for (const std::string& l : labelTmp) {
108  if (l == *prev) {
109  throw cms::Exception("Configuration") << "Duplicate InputTag in labels: " << l;
110  }
111  prev = &l;
112  }
113  }
114 
115  edm::InputTag beamSpotTag = pset.getParameter<edm::InputTag>("beamSpot");
116  bsSrc = consumes<reco::BeamSpot>(beamSpotTag);
117 
119  parametersDefinerTP_ = std::make_unique<CosmicParametersDefinerForTP>(consumesCollector());
120  } else {
121  parametersDefinerTP_ = std::make_unique<ParametersDefinerForTP>(beamSpotTag, consumesCollector());
122  }
123 
124  ParameterSet psetForHistoProducerAlgo = pset.getParameter<ParameterSet>("histoProducerAlgoBlock");
125  histoProducerAlgo_ = std::make_unique<MTVHistoProducerAlgoForTracker>(psetForHistoProducerAlgo, doSeedPlots_);
126 
127  dirName_ = pset.getParameter<std::string>("dirName");
128 
129  tpNLayersToken_ = consumes<edm::ValueMap<unsigned int>>(pset.getParameter<edm::InputTag>("label_tp_nlayers"));
131  consumes<edm::ValueMap<unsigned int>>(pset.getParameter<edm::InputTag>("label_tp_npixellayers"));
133  consumes<edm::ValueMap<unsigned int>>(pset.getParameter<edm::InputTag>("label_tp_nstripstereolayers"));
134 
135  if (dodEdxPlots_) {
136  m_dEdx1Tag = consumes<edm::ValueMap<reco::DeDxData>>(pset.getParameter<edm::InputTag>("dEdx1Tag"));
137  m_dEdx2Tag = consumes<edm::ValueMap<reco::DeDxData>>(pset.getParameter<edm::InputTag>("dEdx2Tag"));
138  }
139 
140  label_tv = consumes<TrackingVertexCollection>(pset.getParameter<edm::InputTag>("label_tv"));
142  recoVertexToken_ = consumes<edm::View<reco::Vertex>>(pset.getUntrackedParameter<edm::InputTag>("label_vertex"));
144  consumes<reco::VertexToTrackingVertexAssociator>(pset.getUntrackedParameter<edm::InputTag>("vertexAssociator"));
145  }
146 
147  if (doMVAPlots_) {
149  auto mvaPSet = pset.getUntrackedParameter<edm::ParameterSet>("mvaLabels");
150  for (size_t iIter = 0; iIter < labelToken.size(); ++iIter) {
153  if (mvaPSet.exists(labels.module)) {
155  mvaPSet.getUntrackedParameter<std::vector<std::string>>(labels.module), [&](const std::string& tag) {
156  return std::make_tuple(consumes<MVACollection>(edm::InputTag(tag, "MVAValues")),
157  consumes<QualityMaskCollection>(edm::InputTag(tag, "QualityMasks")));
158  });
159  }
160  }
161  }
162 
163  tpSelector = TrackingParticleSelector(pset.getParameter<double>("ptMinTP"),
164  pset.getParameter<double>("ptMaxTP"),
165  pset.getParameter<double>("minRapidityTP"),
166  pset.getParameter<double>("maxRapidityTP"),
167  pset.getParameter<double>("tipTP"),
168  pset.getParameter<double>("lipTP"),
169  pset.getParameter<int>("minHitTP"),
170  pset.getParameter<bool>("signalOnlyTP"),
171  pset.getParameter<bool>("intimeOnlyTP"),
172  pset.getParameter<bool>("chargedOnlyTP"),
173  pset.getParameter<bool>("stableOnlyTP"),
174  pset.getParameter<std::vector<int>>("pdgIdTP"),
175  pset.getParameter<bool>("invertRapidityCutTP"));
176 
177  cosmictpSelector = CosmicTrackingParticleSelector(pset.getParameter<double>("ptMinTP"),
178  pset.getParameter<double>("minRapidityTP"),
179  pset.getParameter<double>("maxRapidityTP"),
180  pset.getParameter<double>("tipTP"),
181  pset.getParameter<double>("lipTP"),
182  pset.getParameter<int>("minHitTP"),
183  pset.getParameter<bool>("chargedOnlyTP"),
184  pset.getParameter<std::vector<int>>("pdgIdTP"));
185 
186  ParameterSet psetVsPhi = psetForHistoProducerAlgo.getParameter<ParameterSet>("TpSelectorForEfficiencyVsPhi");
187  dRtpSelector = TrackingParticleSelector(psetVsPhi.getParameter<double>("ptMin"),
188  psetVsPhi.getParameter<double>("ptMax"),
189  psetVsPhi.getParameter<double>("minRapidity"),
190  psetVsPhi.getParameter<double>("maxRapidity"),
191  psetVsPhi.getParameter<double>("tip"),
192  psetVsPhi.getParameter<double>("lip"),
193  psetVsPhi.getParameter<int>("minHit"),
194  psetVsPhi.getParameter<bool>("signalOnly"),
195  psetVsPhi.getParameter<bool>("intimeOnly"),
196  psetVsPhi.getParameter<bool>("chargedOnly"),
197  psetVsPhi.getParameter<bool>("stableOnly"),
198  psetVsPhi.getParameter<std::vector<int>>("pdgId"),
199  psetVsPhi.getParameter<bool>("invertRapidityCut"));
200 
202 
203  useGsf = pset.getParameter<bool>("useGsf");
204 
205  _simHitTpMapTag = mayConsume<SimHitTPAssociationProducer::SimHitTPAssociationList>(
206  pset.getParameter<edm::InputTag>("simHitTpMapTag"));
207 
210  consumes<edm::View<reco::Track>>(pset.getParameter<edm::InputTag>("trackCollectionForDrCalculation"));
211  }
212 
213  if (useAssociators_) {
214  for (auto const& src : associators) {
215  associatorTokens.push_back(consumes<reco::TrackToTrackingParticleAssociator>(src));
216  }
217  } else {
218  for (auto const& src : associators) {
219  associatormapStRs.push_back(consumes<reco::SimToRecoCollection>(src));
220  associatormapRtSs.push_back(consumes<reco::RecoToSimCollection>(src));
221  }
222  }
223 }
224 
226 
228  edm::Run const&,
229  edm::EventSetup const& setup,
230  Histograms& histograms) const {
231  if (label.empty()) {
232  // Disable histogram booking if there are no track collections
233  return;
234  }
235 
236  const auto minColl = -0.5;
237  const auto maxColl = label.size() - 0.5;
238  const auto nintColl = label.size();
239 
240  auto binLabels = [&](dqm::reco::MonitorElement* me) {
241  for (size_t i = 0; i < label.size(); ++i) {
242  me->setBinLabel(i + 1, label[i].label());
243  }
244  me->disableAlphanumeric();
245  return me;
246  };
247 
248  //Booking histograms concerning with simulated tracks
249  if (doSimPlots_) {
250  ibook.cd();
251  ibook.setCurrentFolder(dirName_ + "simulation");
252 
253  histoProducerAlgo_->bookSimHistos(ibook, histograms.histoProducerAlgo);
254 
255  ibook.cd();
256  ibook.setCurrentFolder(dirName_);
257  }
258 
259  for (unsigned int ww = 0; ww < associators.size(); ww++) {
260  ibook.cd();
261  // FIXME: these need to be moved to a subdirectory whose name depends on the associator
262  ibook.setCurrentFolder(dirName_);
263 
264  if (doSummaryPlots_) {
265  if (doSimTrackPlots_) {
266  histograms.h_assoc_coll.push_back(
267  binLabels(ibook.book1D("num_assoc(simToReco)_coll",
268  "N of associated (simToReco) tracks vs track collection",
269  nintColl,
270  minColl,
271  maxColl)));
272  histograms.h_simul_coll.push_back(binLabels(
273  ibook.book1D("num_simul_coll", "N of simulated tracks vs track collection", nintColl, minColl, maxColl)));
274  }
275  if (doRecoTrackPlots_) {
276  histograms.h_reco_coll.push_back(binLabels(
277  ibook.book1D("num_reco_coll", "N of reco track vs track collection", nintColl, minColl, maxColl)));
278  histograms.h_assoc2_coll.push_back(
279  binLabels(ibook.book1D("num_assoc(recoToSim)_coll",
280  "N of associated (recoToSim) tracks vs track collection",
281  nintColl,
282  minColl,
283  maxColl)));
284  histograms.h_looper_coll.push_back(
285  binLabels(ibook.book1D("num_duplicate_coll",
286  "N of associated (recoToSim) looper tracks vs track collection",
287  nintColl,
288  minColl,
289  maxColl)));
290  histograms.h_pileup_coll.push_back(
291  binLabels(ibook.book1D("num_pileup_coll",
292  "N of associated (recoToSim) pileup tracks vs track collection",
293  nintColl,
294  minColl,
295  maxColl)));
296  }
297  }
298 
299  for (unsigned int www = 0; www < label.size(); www++) {
300  ibook.cd();
301  InputTag algo = label[www];
302  string dirName = dirName_;
303  if (!algo.process().empty())
304  dirName += algo.process() + "_";
305  if (!algo.label().empty())
306  dirName += algo.label() + "_";
307  if (!algo.instance().empty())
308  dirName += algo.instance() + "_";
309  if (dirName.find("Tracks") < dirName.length()) {
310  dirName.replace(dirName.find("Tracks"), 6, "");
311  }
312  string assoc = associators[ww].label();
313  if (assoc.find("Track") < assoc.length()) {
314  assoc.replace(assoc.find("Track"), 5, "");
315  }
316  dirName += assoc;
317  std::replace(dirName.begin(), dirName.end(), ':', '_');
318 
319  ibook.setCurrentFolder(dirName);
320 
321  const bool doResolutionPlots = doResolutionPlots_[www];
322 
323  if (doSimTrackPlots_) {
324  histoProducerAlgo_->bookSimTrackHistos(ibook, histograms.histoProducerAlgo, doResolutionPlots);
326  histoProducerAlgo_->bookSimTrackPVAssociationHistos(ibook, histograms.histoProducerAlgo);
327  }
328 
329  //Booking histograms concerning with reconstructed tracks
330  if (doRecoTrackPlots_) {
331  histoProducerAlgo_->bookRecoHistos(ibook, histograms.histoProducerAlgo, doResolutionPlots);
332  if (dodEdxPlots_)
333  histoProducerAlgo_->bookRecodEdxHistos(ibook, histograms.histoProducerAlgo);
335  histoProducerAlgo_->bookRecoPVAssociationHistos(ibook, histograms.histoProducerAlgo);
336  if (doMVAPlots_)
337  histoProducerAlgo_->bookMVAHistos(
338  ibook, histograms.histoProducerAlgo, mvaQualityCollectionTokens_[www].size());
339  }
340 
341  if (doSeedPlots_) {
342  histoProducerAlgo_->bookSeedHistos(ibook, histograms.histoProducerAlgo);
343  }
344  } //end loop www
345  } // end loop ww
346 }
347 
348 #ifdef EDM_ML_DEBUG
349 namespace {
350  void ensureEffIsSubsetOfFake(const TrackingParticleRefVector& eff, const TrackingParticleRefVector& fake) {
351  // If efficiency RefVector is empty, don't check the product ids
352  // as it will be 0:0 for empty. This covers also the case where
353  // both are empty. The case of fake being empty and eff not is an
354  // error.
355  if (eff.empty())
356  return;
357 
358  // First ensure product ids
359  if (eff.id() != fake.id()) {
360  throw cms::Exception("Configuration")
361  << "Efficiency and fake TrackingParticle (refs) point to different collections (eff " << eff.id() << " fake "
362  << fake.id()
363  << "). This is not supported. Efficiency TP set must be the same or a subset of the fake TP set.";
364  }
365 
366  // Same technique as in associationMapFilterValues
367  edm::IndexSet fakeKeys;
368  fakeKeys.reserve(fake.size());
369  for (const auto& ref : fake) {
370  fakeKeys.insert(ref.key());
371  }
372 
373  for (const auto& ref : eff) {
374  if (!fakeKeys.has(ref.key())) {
375  throw cms::Exception("Configuration") << "Efficiency TrackingParticle " << ref.key()
376  << " is not found from the set of fake TPs. This is not supported. The "
377  "efficiency TP set must be the same or a subset of the fake TP set.";
378  }
379  }
380  }
381 } // namespace
382 #endif
383 
385  const edm::Handle<TrackingVertexCollection>& htv) const {
386  for (const auto& simV : *htv) {
387  if (simV.eventId().bunchCrossing() != 0)
388  continue; // remove OOTPU
389  if (simV.eventId().event() != 0)
390  continue; // pick the PV of hard scatter
391  return &(simV.position());
392  }
393  return nullptr;
394 }
395 
397  const edm::Event& event, const edm::Handle<TrackingVertexCollection>& htv) const {
399  event.getByToken(recoVertexToken_, hvertex);
400 
402  event.getByToken(vertexAssociatorToken_, hvassociator);
403 
404  auto v_r2s = hvassociator->associateRecoToSim(hvertex, htv);
405  auto pvPtr = hvertex->refAt(0);
406  if (pvPtr->isFake() || pvPtr->ndof() < 0) // skip junk vertices
407  return nullptr;
408 
409  auto pvFound = v_r2s.find(pvPtr);
410  if (pvFound == v_r2s.end())
411  return nullptr;
412 
413  for (const auto& vertexRefQuality : pvFound->val) {
414  const TrackingVertex& tv = *(vertexRefQuality.first);
415  if (tv.eventId().event() == 0 && tv.eventId().bunchCrossing() == 0) {
416  return &(pvPtr->position());
417  }
418  }
419 
420  return nullptr;
421 }
422 
424  const Histograms& histograms,
425  const TrackingParticleRefVector& tPCeff,
426  const edm::Event& event,
427  const edm::EventSetup& setup,
428  const reco::BeamSpot& bs,
429  std::vector<std::tuple<TrackingParticle::Vector, TrackingParticle::Point>>& momVert_tPCeff,
430  std::vector<size_t>& selected_tPCeff) const {
431  selected_tPCeff.reserve(tPCeff.size());
432  momVert_tPCeff.reserve(tPCeff.size());
433  int nIntimeTPs = 0;
435  for (size_t j = 0; j < tPCeff.size(); ++j) {
436  const TrackingParticleRef& tpr = tPCeff[j];
437 
438  auto const& rec = parametersDefinerTP_->momentumAndVertex(event, setup, tpr);
439  TrackingParticle::Vector const& momentum = std::get<0>(rec);
440  TrackingParticle::Point const& vertex = std::get<1>(rec);
441  if (doSimPlots_) {
442  histoProducerAlgo_->fill_generic_simTrack_histos(
443  histograms.histoProducerAlgo, momentum, vertex, tpr->eventId().bunchCrossing());
444  }
445  if (tpr->eventId().bunchCrossing() == 0)
446  ++nIntimeTPs;
447 
448  if (cosmictpSelector(tpr, &bs, event, setup)) {
449  selected_tPCeff.push_back(j);
450  momVert_tPCeff.emplace_back(momentum, vertex);
451  }
452  }
453  } else {
454  size_t j = 0;
455  for (auto const& tpr : tPCeff) {
456  const TrackingParticle& tp = *tpr;
457 
458  // TODO: do we want to fill these from all TPs that include IT
459  // and OOT (as below), or limit to IT+OOT TPs passing tpSelector
460  // (as it was before)? The latter would require another instance
461  // of tpSelector with intimeOnly=False.
462  if (doSimPlots_) {
463  histoProducerAlgo_->fill_generic_simTrack_histos(
464  histograms.histoProducerAlgo, tp.momentum(), tp.vertex(), tp.eventId().bunchCrossing());
465  }
466  if (tp.eventId().bunchCrossing() == 0)
467  ++nIntimeTPs;
468 
469  if (tpSelector(tp)) {
470  selected_tPCeff.push_back(j);
471  momVert_tPCeff.emplace_back(parametersDefinerTP_->momentumAndVertex(event, setup, tpr));
472  }
473  ++j;
474  }
475  }
476  if (doSimPlots_) {
477  histoProducerAlgo_->fill_simTrackBased_histos(histograms.histoProducerAlgo, nIntimeTPs);
478  }
479 }
480 
482  const std::vector<size_t>& selected_tPCeff,
483  DynArray<float>& dR_tPCeff,
484  DynArray<float>& dR_tPCeff_jet,
485  const edm::View<reco::Candidate>* cores) const {
486  if (tPCeff.empty()) {
487  return 0;
488  }
489  float etaL[tPCeff.size()], phiL[tPCeff.size()];
490  size_t n_selTP_dr = 0;
491  for (size_t iTP : selected_tPCeff) {
492  //calculare dR wrt inclusive collection (also with PU, low pT, displaced)
493  auto const& tp2 = *(tPCeff[iTP]);
494  auto&& p = tp2.momentum();
495  etaL[iTP] = etaFromXYZ(p.x(), p.y(), p.z());
496  phiL[iTP] = atan2f(p.y(), p.x());
497  }
498  for (size_t iTP1 : selected_tPCeff) {
499  auto const& tp = *(tPCeff[iTP1]);
501  double dR_jet = std::numeric_limits<double>::max();
502  if (dRtpSelector(tp)) { //only for those needed for efficiency!
503  ++n_selTP_dr;
504  float eta = etaL[iTP1];
505  float phi = phiL[iTP1];
506  for (size_t iTP2 : selected_tPCeff) {
507  //calculare dR wrt inclusive collection (also with PU, low pT, displaced)
508  if (iTP1 == iTP2) {
509  continue;
510  }
511  auto dR_tmp = reco::deltaR2(eta, phi, etaL[iTP2], phiL[iTP2]);
512  if (dR_tmp < dR)
513  dR = dR_tmp;
514  } // ttp2 (iTP)
515  if (cores != nullptr) {
516  for (unsigned int ji = 0; ji < cores->size(); ji++) { //jet loop
517  const reco::Candidate& jet = (*cores)[ji];
518  double jet_eta = jet.eta();
519  double jet_phi = jet.phi();
520  auto dR_jet_tmp = reco::deltaR2(eta, phi, jet_eta, jet_phi);
521  if (dR_jet_tmp < dR_jet)
522  dR_jet = dR_jet_tmp;
523  }
524  }
525  }
526  dR_tPCeff[iTP1] = std::sqrt(dR);
527  dR_tPCeff_jet[iTP1] = std::sqrt(dR_jet);
528 
529  } // tp
530  return n_selTP_dr;
531 }
532 
534  const edm::View<reco::Track>& trackCollectionDr,
535  DynArray<float>& dR_trk,
536  DynArray<float>& dR_trk_jet,
537  const edm::View<reco::Candidate>* cores) const {
538  if (trackCollectionDr.empty()) {
539  return;
540  }
541  int i = 0;
542  float etaL[trackCollectionDr.size()];
543  float phiL[trackCollectionDr.size()];
544  bool validL[trackCollectionDr.size()];
545  for (auto const& track2 : trackCollectionDr) {
546  auto&& p = track2.momentum();
547  etaL[i] = etaFromXYZ(p.x(), p.y(), p.z());
548  phiL[i] = atan2f(p.y(), p.x());
549  validL[i] = !trackFromSeedFitFailed(track2);
550  ++i;
551  }
552  for (View<reco::Track>::size_type i = 0; i < trackCollection.size(); ++i) {
553  auto const& track = trackCollection[i];
555  auto dR_jet = std::numeric_limits<float>::max();
557  auto&& p = track.momentum();
558  float eta = etaFromXYZ(p.x(), p.y(), p.z());
559  float phi = atan2f(p.y(), p.x());
560  for (View<reco::Track>::size_type j = 0; j < trackCollectionDr.size(); ++j) {
561  if (!validL[j])
562  continue;
563  auto dR_tmp = reco::deltaR2(eta, phi, etaL[j], phiL[j]);
564  if ((dR_tmp < dR) & (dR_tmp > std::numeric_limits<float>::min()))
565  dR = dR_tmp;
566  }
567  if (cores != nullptr) {
568  for (unsigned int ji = 0; ji < cores->size(); ji++) { //jet loop
569  const reco::Candidate& jet = (*cores)[ji];
570  double jet_eta = jet.eta();
571  double jet_phi = jet.phi();
572  auto dR_jet_tmp = reco::deltaR2(eta, phi, jet_eta, jet_phi);
573  if (dR_jet_tmp < dR_jet)
574  dR_jet = dR_jet_tmp;
575  }
576  }
577  }
578  dR_trk[i] = std::sqrt(dR);
579  dR_trk_jet[i] = std::sqrt(dR_jet);
580  }
581 }
582 
584  const edm::EventSetup& setup,
585  const Histograms& histograms) const {
586  if (label.empty()) {
587  // Disable if there are no track collections
588  return;
589  }
590 
591  using namespace reco;
592 
593  LogDebug("TrackValidator") << "\n===================================================="
594  << "\n"
595  << "Analyzing new event"
596  << "\n"
597  << "====================================================\n"
598  << "\n";
599 
600  const TrackerTopology& ttopo = setup.getData(tTopoEsToken);
601 
602  // FIXME: we really need to move to edm::View for reading the
603  // TrackingParticles... Unfortunately it has non-trivial
604  // consequences on the associator/association interfaces etc.
605  TrackingParticleRefVector tmpTPeff;
606  TrackingParticleRefVector tmpTPfake;
607  const TrackingParticleRefVector* tmpTPeffPtr = nullptr;
608  const TrackingParticleRefVector* tmpTPfakePtr = nullptr;
609 
611  edm::Handle<TrackingParticleRefVector> TPCollectionHeffRefVector;
612 
613  const bool tp_effic_refvector = label_tp_effic.isUninitialized();
614  if (!tp_effic_refvector) {
615  event.getByToken(label_tp_effic, TPCollectionHeff);
616  tmpTPeff.reserve(TPCollectionHeff->size());
617  for (size_t i = 0, size = TPCollectionHeff->size(); i < size; ++i) {
618  tmpTPeff.push_back(TrackingParticleRef(TPCollectionHeff, i));
619  }
620  tmpTPeffPtr = &tmpTPeff;
621  } else {
622  event.getByToken(label_tp_effic_refvector, TPCollectionHeffRefVector);
623  tmpTPeffPtr = TPCollectionHeffRefVector.product();
624  }
626  edm::Handle<TrackingParticleCollection> TPCollectionHfake;
627  event.getByToken(label_tp_fake, TPCollectionHfake);
628  tmpTPfake.reserve(TPCollectionHfake->size());
629  for (size_t i = 0, size = TPCollectionHfake->size(); i < size; ++i) {
630  tmpTPfake.push_back(TrackingParticleRef(TPCollectionHfake, i));
631  }
632  tmpTPfakePtr = &tmpTPfake;
633  } else {
634  edm::Handle<TrackingParticleRefVector> TPCollectionHfakeRefVector;
635  event.getByToken(label_tp_fake_refvector, TPCollectionHfakeRefVector);
636  tmpTPfakePtr = TPCollectionHfakeRefVector.product();
637  }
638 
639  TrackingParticleRefVector const& tPCeff = *tmpTPeffPtr;
640  TrackingParticleRefVector const& tPCfake = *tmpTPfakePtr;
641 
642 #ifdef EDM_ML_DEBUG
643  ensureEffIsSubsetOfFake(tPCeff, tPCfake);
644 #endif
645 
648  //warning: make sure the TP collection used in the map is the same used in the MTV!
649  event.getByToken(_simHitTpMapTag, simHitsTPAssoc);
650  parametersDefinerTP_->initEvent(simHitsTPAssoc);
651  cosmictpSelector.initEvent(simHitsTPAssoc);
652  }
653 
654  // Find the sim PV and tak its position
656  event.getByToken(label_tv, htv);
657  const TrackingVertex::LorentzVector* theSimPVPosition = getSimPVPosition(htv);
658  if (simPVMaxZ_ >= 0) {
659  if (!theSimPVPosition)
660  return;
661  if (std::abs(theSimPVPosition->z()) > simPVMaxZ_)
662  return;
663  }
664 
665  // Check, when necessary, if reco PV matches to sim PV
666  const reco::Vertex::Point* thePVposition = nullptr;
668  thePVposition = getRecoPVPosition(event, htv);
669  if (doPlotsOnlyForTruePV_ && !thePVposition)
670  return;
671 
672  // Rest of the code assumes that if thePVposition is non-null, the
673  // PV-association histograms get filled. In above, the "nullness"
674  // is used to deliver the information if the reco PV is matched to
675  // the sim PV.
677  thePVposition = nullptr;
678  }
679 
680  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
681  event.getByToken(bsSrc, recoBeamSpotHandle);
682  reco::BeamSpot const& bs = *recoBeamSpotHandle;
683 
685  event.getByToken(label_pileupinfo, puinfoH);
686  PileupSummaryInfo puinfo;
687 
688  for (unsigned int puinfo_ite = 0; puinfo_ite < (*puinfoH).size(); ++puinfo_ite) {
689  if ((*puinfoH)[puinfo_ite].getBunchCrossing() == 0) {
690  puinfo = (*puinfoH)[puinfo_ite];
691  break;
692  }
693  }
694 
695  // Number of 3D layers for TPs
697  event.getByToken(tpNLayersToken_, tpNLayersH);
698  const auto& nLayers_tPCeff = *tpNLayersH;
699 
700  event.getByToken(tpNPixelLayersToken_, tpNLayersH);
701  const auto& nPixelLayers_tPCeff = *tpNLayersH;
702 
703  event.getByToken(tpNStripStereoLayersToken_, tpNLayersH);
704  const auto& nStripMonoAndStereoLayers_tPCeff = *tpNLayersH;
705 
706  // Precalculate TP selection (for efficiency), and momentum and vertex wrt PCA
707  //
708  // TODO: ParametersDefinerForTP ESProduct needs to be changed to
709  // EDProduct because of consumes.
710  //
711  // In principle, we could just precalculate the momentum and vertex
712  // wrt PCA for all TPs for once and put that to the event. To avoid
713  // repetitive calculations those should be calculated only once for
714  // each TP. That would imply that we should access TPs via Refs
715  // (i.e. View) in here, since, in general, the eff and fake TP
716  // collections can be different (and at least HI seems to use that
717  // feature). This would further imply that the
718  // RecoToSimCollection/SimToRecoCollection should be changed to use
719  // View<TP> instead of vector<TP>, and migrate everything.
720  //
721  // Or we could take only one input TP collection, and do another
722  // TP-selection to obtain the "fake" collection like we already do
723  // for "efficiency" TPs.
724  std::vector<size_t> selected_tPCeff;
725  std::vector<std::tuple<TrackingParticle::Vector, TrackingParticle::Point>> momVert_tPCeff;
726  tpParametersAndSelection(histograms, tPCeff, event, setup, bs, momVert_tPCeff, selected_tPCeff);
727 
728  //calculate dR for TPs
729  declareDynArray(float, tPCeff.size(), dR_tPCeff);
730 
731  //calculate dR_jet for TPs
732  const edm::View<reco::Candidate>* coresVector = nullptr;
733  if (not cores_.isUninitialized()) {
735  event.getByToken(cores_, cores);
736  if (cores.isValid()) {
737  coresVector = cores.product();
738  }
739  }
740  declareDynArray(float, tPCeff.size(), dR_tPCeff_jet);
741 
742  size_t n_selTP_dr = tpDR(tPCeff, selected_tPCeff, dR_tPCeff, dR_tPCeff_jet, coresVector);
743 
747  }
748 
749  // dE/dx
750  // at some point this could be generalized, with a vector of tags and a corresponding vector of Handles
751  // I'm writing the interface such to take vectors of ValueMaps
752  std::vector<const edm::ValueMap<reco::DeDxData>*> v_dEdx;
753  if (dodEdxPlots_) {
756  event.getByToken(m_dEdx1Tag, dEdx1Handle);
757  event.getByToken(m_dEdx2Tag, dEdx2Handle);
758  v_dEdx.push_back(dEdx1Handle.product());
759  v_dEdx.push_back(dEdx2Handle.product());
760  }
761 
762  std::vector<const MVACollection*> mvaCollections;
763  std::vector<const QualityMaskCollection*> qualityMaskCollections;
764  std::vector<float> mvaValues;
765 
766  int w = 0; //counter counting the number of sets of histograms
767  for (unsigned int ww = 0; ww < associators.size(); ww++) {
768  // run value filtering of recoToSim map already here as it depends only on the association, not track collection
769  reco::SimToRecoCollection const* simRecCollPFull = nullptr;
770  reco::RecoToSimCollection const* recSimCollP = nullptr;
771  reco::RecoToSimCollection recSimCollL;
772  if (!useAssociators_) {
773  Handle<reco::SimToRecoCollection> simtorecoCollectionH;
774  event.getByToken(associatormapStRs[ww], simtorecoCollectionH);
775  simRecCollPFull = simtorecoCollectionH.product();
776 
777  Handle<reco::RecoToSimCollection> recotosimCollectionH;
778  event.getByToken(associatormapRtSs[ww], recotosimCollectionH);
779  recSimCollP = recotosimCollectionH.product();
780 
781  // We need to filter the associations of the fake-TrackingParticle
782  // collection only from RecoToSim collection, otherwise the
783  // RecoToSim histograms get false entries
784  recSimCollL = associationMapFilterValues(*recSimCollP, tPCfake);
785  recSimCollP = &recSimCollL;
786  }
787 
788  for (unsigned int www = 0; www < label.size();
789  www++, w++) { // need to increment w here, since there are many continues in the loop body
790  //
791  //get collections from the event
792  //
793  edm::Handle<View<Track>> trackCollectionHandle;
794  if (!event.getByToken(labelToken[www], trackCollectionHandle) && ignoremissingtkcollection_)
795  continue;
796  const edm::View<Track>& trackCollection = *trackCollectionHandle;
797 
798  reco::SimToRecoCollection const* simRecCollP = nullptr;
799  reco::SimToRecoCollection simRecCollL;
800 
801  //associate tracks
802  LogTrace("TrackValidator") << "Analyzing " << label[www] << " with " << associators[ww] << "\n";
803  if (useAssociators_) {
805  event.getByToken(associatorTokens[ww], theAssociator);
806 
807  // The associator interfaces really need to be fixed...
809  // trackRefs.vectorHolder()->reserve(trackCollection.size()); NOT a good idea
810  for (edm::View<Track>::size_type i = 0; i < trackCollection.size(); ++i) {
811  trackRefs.push_back(trackCollection.refAt(i));
812  }
813 
814  LogTrace("TrackValidator") << "Calling associateRecoToSim method"
815  << "\n";
816  recSimCollL = theAssociator->associateRecoToSim(trackRefs, tPCfake);
817  recSimCollP = &recSimCollL;
818  LogTrace("TrackValidator") << "Calling associateSimToReco method"
819  << "\n";
820  // It is necessary to do the association wrt. fake TPs,
821  // because this SimToReco association is used also for
822  // duplicates. Since the set of efficiency TPs are required to
823  // be a subset of the set of fake TPs, for efficiency
824  // histograms it doesn't matter if the association contains
825  // associations of TPs not in the set of efficiency TPs.
826  simRecCollL = theAssociator->associateSimToReco(trackRefs, tPCfake);
827  simRecCollP = &simRecCollL;
828  } else {
829  // We need to filter the associations of the current track
830  // collection only from SimToReco collection, otherwise the
831  // SimToReco histograms get false entries. The filtering must
832  // be done separately for each track collection.
833  simRecCollL = associationMapFilterValues(*simRecCollPFull, trackCollection);
834  simRecCollP = &simRecCollL;
835  }
836 
837  reco::RecoToSimCollection const& recSimColl = *recSimCollP;
838  reco::SimToRecoCollection const& simRecColl = *simRecCollP;
839 
840  // read MVA collections
844  for (const auto& tokenTpl : mvaQualityCollectionTokens_[www]) {
845  event.getByToken(std::get<0>(tokenTpl), hmva);
846  event.getByToken(std::get<1>(tokenTpl), hqual);
847 
848  mvaCollections.push_back(hmva.product());
849  qualityMaskCollections.push_back(hqual.product());
850  if (mvaCollections.back()->size() != trackCollection.size()) {
851  throw cms::Exception("Configuration")
852  << "Inconsistency in track collection and MVA sizes. Track collection " << www << " has "
853  << trackCollection.size() << " tracks, whereas the MVA " << (mvaCollections.size() - 1)
854  << " for it has " << mvaCollections.back()->size() << " entries. Double-check your configuration.";
855  }
856  if (qualityMaskCollections.back()->size() != trackCollection.size()) {
857  throw cms::Exception("Configuration")
858  << "Inconsistency in track collection and quality mask sizes. Track collection " << www << " has "
859  << trackCollection.size() << " tracks, whereas the quality mask " << (qualityMaskCollections.size() - 1)
860  << " for it has " << qualityMaskCollections.back()->size()
861  << " entries. Double-check your configuration.";
862  }
863  }
864  }
865 
866  // ########################################################
867  // fill simulation histograms (LOOP OVER TRACKINGPARTICLES)
868  // ########################################################
869 
870  //compute number of tracks per eta interval
871  //
872  LogTrace("TrackValidator") << "\n# of TrackingParticles: " << tPCeff.size() << "\n";
873  int ats(0); //This counter counts the number of simTracks that are "associated" to recoTracks
874  int st(0); //This counter counts the number of simulated tracks passing the MTV selection (i.e. tpSelector(tp) )
875 
876  //loop over already-selected TPs for tracking efficiency
877  for (size_t i = 0; i < selected_tPCeff.size(); ++i) {
878  size_t iTP = selected_tPCeff[i];
879  const TrackingParticleRef& tpr = tPCeff[iTP];
880  const TrackingParticle& tp = *tpr;
881 
882  auto const& momVert = momVert_tPCeff[i];
883  TrackingParticle::Vector momentumTP;
884  TrackingParticle::Point vertexTP;
885 
886  double dxySim(0);
887  double dzSim(0);
888  double dxyPVSim = 0;
889  double dzPVSim = 0;
890  double dR = dR_tPCeff[iTP];
891  double dR_jet = dR_tPCeff_jet[iTP];
892 
893  //---------- THIS PART HAS TO BE CLEANED UP. THE PARAMETER DEFINER WAS NOT MEANT TO BE USED IN THIS WAY ----------
894  //If the TrackingParticle is collison like, get the momentum and vertex at production state
896  momentumTP = tp.momentum();
897  vertexTP = tp.vertex();
898  //Calcualte the impact parameters w.r.t. PCA
899  const TrackingParticle::Vector& momentum = std::get<TrackingParticle::Vector>(momVert);
900  const TrackingParticle::Point& vertex = std::get<TrackingParticle::Point>(momVert);
901  dxySim = TrackingParticleIP::dxy(vertex, momentum, bs.position());
902  dzSim = TrackingParticleIP::dz(vertex, momentum, bs.position());
903 
904  if (theSimPVPosition) {
905  dxyPVSim = TrackingParticleIP::dxy(vertex, momentum, *theSimPVPosition);
906  dzPVSim = TrackingParticleIP::dz(vertex, momentum, *theSimPVPosition);
907  }
908  }
909  //If the TrackingParticle is comics, get the momentum and vertex at PCA
910  else {
911  momentumTP = std::get<TrackingParticle::Vector>(momVert);
912  vertexTP = std::get<TrackingParticle::Point>(momVert);
913  dxySim = TrackingParticleIP::dxy(vertexTP, momentumTP, bs.position());
914  dzSim = TrackingParticleIP::dz(vertexTP, momentumTP, bs.position());
915 
916  // Do dxy and dz vs. PV make any sense for cosmics? I guess not
917  }
918  //---------- THE PART ABOVE HAS TO BE CLEANED UP. THE PARAMETER DEFINER WAS NOT MEANT TO BE USED IN THIS WAY ----------
919 
920  // in the coming lines, histos are filled using as input
921  // - momentumTP
922  // - vertexTP
923  // - dxySim
924  // - dzSim
925  if (!doSimTrackPlots_)
926  continue;
927 
928  // ##############################################
929  // fill RecoAssociated SimTracks' histograms
930  // ##############################################
931  const reco::Track* matchedTrackPointer = nullptr;
932  const reco::Track* matchedSecondTrackPointer = nullptr;
933  unsigned int selectsLoose = mvaCollections.size();
934  unsigned int selectsHP = mvaCollections.size();
935  if (simRecColl.find(tpr) != simRecColl.end()) {
936  auto const& rt = simRecColl[tpr];
937  if (!rt.empty()) {
938  ats++; //This counter counts the number of simTracks that have a recoTrack associated
939  // isRecoMatched = true; // UNUSED
940  matchedTrackPointer = rt.begin()->first.get();
941  if (rt.size() >= 2) {
942  matchedSecondTrackPointer = (rt.begin() + 1)->first.get();
943  }
944  LogTrace("TrackValidator") << "TrackingParticle #" << st << " with pt=" << sqrt(momentumTP.perp2())
945  << " associated with quality:" << rt.begin()->second << "\n";
946 
947  if (doMVAPlots_) {
948  // for each MVA we need to take the value of the track
949  // with largest MVA value (for the cumulative histograms)
950  //
951  // also identify the first MVA that possibly selects any
952  // track matched to this TrackingParticle, separately
953  // for loose and highPurity qualities
954  for (size_t imva = 0; imva < mvaCollections.size(); ++imva) {
955  const auto& mva = *(mvaCollections[imva]);
956  const auto& qual = *(qualityMaskCollections[imva]);
957 
958  auto iMatch = rt.begin();
959  float maxMva = mva[iMatch->first.key()];
960  for (; iMatch != rt.end(); ++iMatch) {
961  auto itrk = iMatch->first.key();
962  maxMva = std::max(maxMva, mva[itrk]);
963 
964  if (selectsLoose >= imva && trackSelected(qual[itrk], reco::TrackBase::loose))
965  selectsLoose = imva;
966  if (selectsHP >= imva && trackSelected(qual[itrk], reco::TrackBase::highPurity))
967  selectsHP = imva;
968  }
969  mvaValues.push_back(maxMva);
970  }
971  }
972  }
973  } else {
974  LogTrace("TrackValidator") << "TrackingParticle #" << st << " with pt,eta,phi: " << sqrt(momentumTP.perp2())
975  << " , " << momentumTP.eta() << " , " << momentumTP.phi() << " , "
976  << " NOT associated to any reco::Track"
977  << "\n";
978  }
979 
980  int nSimHits = tp.numberOfTrackerHits();
981  int nSimLayers = nLayers_tPCeff[tpr];
982  int nSimPixelLayers = nPixelLayers_tPCeff[tpr];
983  int nSimStripMonoAndStereoLayers = nStripMonoAndStereoLayers_tPCeff[tpr];
984  histoProducerAlgo_->fill_recoAssociated_simTrack_histos(histograms.histoProducerAlgo,
985  w,
986  tp,
987  momentumTP,
988  vertexTP,
989  dxySim,
990  dzSim,
991  dxyPVSim,
992  dzPVSim,
993  nSimHits,
994  nSimLayers,
995  nSimPixelLayers,
996  nSimStripMonoAndStereoLayers,
997  matchedTrackPointer,
998  puinfo.getPU_NumInteractions(),
999  dR,
1000  dR_jet,
1001  thePVposition,
1002  theSimPVPosition,
1003  bs.position(),
1004  mvaValues,
1005  selectsLoose,
1006  selectsHP);
1007  mvaValues.clear();
1008 
1009  if (matchedTrackPointer && matchedSecondTrackPointer) {
1010  histoProducerAlgo_->fill_duplicate_histos(
1011  histograms.histoProducerAlgo, w, *matchedTrackPointer, *matchedSecondTrackPointer);
1012  }
1013 
1014  if (doSummaryPlots_) {
1015  if (dRtpSelector(tp)) {
1016  histograms.h_simul_coll[ww]->Fill(www);
1017  if (matchedTrackPointer) {
1018  histograms.h_assoc_coll[ww]->Fill(www);
1019  }
1020  }
1021  }
1022 
1023  } // End for (TrackingParticleCollection::size_type i=0; i<tPCeff.size(); i++){
1024 
1025  // ##############################################
1026  // fill recoTracks histograms (LOOP OVER TRACKS)
1027  // ##############################################
1028  if (!doRecoTrackPlots_)
1029  continue;
1030  LogTrace("TrackValidator") << "\n# of reco::Tracks with " << label[www].process() << ":" << label[www].label()
1031  << ":" << label[www].instance() << ": " << trackCollection.size() << "\n";
1032 
1033  int sat(0); //This counter counts the number of recoTracks that are associated to SimTracks from Signal only
1034  int at(0); //This counter counts the number of recoTracks that are associated to SimTracks
1035  int rT(0); //This counter counts the number of recoTracks in general
1036  int seed_fit_failed = 0;
1037  size_t n_selTrack_dr = 0;
1038 
1039  //calculate dR for tracks
1040  declareDynArray(float, trackCollection.size(), dR_trk);
1041  declareDynArray(float, trackCollection.size(), dR_trk_jet);
1042 #ifndef NO_TRACK_DR
1043  // this accounts for most of the time spent in MTV and it is used to fill just one histo that is of doubtful usefulness but (maybe) for the whole collection
1044  const edm::View<Track>* trackCollectionDr = &trackCollection;
1046  trackCollectionDr = trackCollectionForDrCalculation.product();
1047  }
1048  trackDR(trackCollection, *trackCollectionDr, dR_trk, dR_trk_jet, coresVector);
1049 #endif
1050 
1051  for (View<Track>::size_type i = 0; i < trackCollection.size(); ++i) {
1052  auto track = trackCollection.refAt(i);
1053  rT++;
1055  ++seed_fit_failed;
1056  if ((*dRTrackSelector)(*track, bs.position()))
1057  ++n_selTrack_dr;
1058 
1059  bool isSigSimMatched(false);
1060  bool isSimMatched(false);
1061  bool isChargeMatched(true);
1062  int numAssocRecoTracks = 0;
1063  int nSimHits = 0;
1064  double sharedFraction = 0.;
1065 
1066  auto tpFound = recSimColl.find(track);
1067  isSimMatched = tpFound != recSimColl.end();
1068  if (isSimMatched) {
1069  const auto& tp = tpFound->val;
1070  nSimHits = tp[0].first->numberOfTrackerHits();
1071  sharedFraction = tp[0].second;
1072  if (tp[0].first->charge() != track->charge())
1073  isChargeMatched = false;
1074  if (simRecColl.find(tp[0].first) != simRecColl.end())
1075  numAssocRecoTracks = simRecColl[tp[0].first].size();
1076  at++;
1077  for (unsigned int tp_ite = 0; tp_ite < tp.size(); ++tp_ite) {
1078  TrackingParticle trackpart = *(tp[tp_ite].first);
1079  if ((trackpart.eventId().event() == 0) && (trackpart.eventId().bunchCrossing() == 0)) {
1080  isSigSimMatched = true;
1081  sat++;
1082  break;
1083  }
1084  }
1085  LogTrace("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
1086  << " associated with quality:" << tp.begin()->second << "\n";
1087  } else {
1088  LogTrace("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
1089  << " NOT associated to any TrackingParticle"
1090  << "\n";
1091  }
1092 
1093  // set MVA values for this track
1094  // take also the indices of first MVAs to select by loose and
1095  // HP quality
1096  unsigned int selectsLoose = mvaCollections.size();
1097  unsigned int selectsHP = mvaCollections.size();
1098  if (doMVAPlots_) {
1099  for (size_t imva = 0; imva < mvaCollections.size(); ++imva) {
1100  const auto& mva = *(mvaCollections[imva]);
1101  const auto& qual = *(qualityMaskCollections[imva]);
1102  mvaValues.push_back(mva[i]);
1103 
1104  if (selectsLoose >= imva && trackSelected(qual[i], reco::TrackBase::loose))
1105  selectsLoose = imva;
1106  if (selectsHP >= imva && trackSelected(qual[i], reco::TrackBase::highPurity))
1107  selectsHP = imva;
1108  }
1109  }
1110 
1111  double dR = dR_trk[i];
1112  double dR_jet = dR_trk_jet[i];
1113  histoProducerAlgo_->fill_generic_recoTrack_histos(histograms.histoProducerAlgo,
1114  w,
1115  *track,
1116  ttopo,
1117  bs.position(),
1118  thePVposition,
1119  theSimPVPosition,
1120  isSimMatched,
1121  isSigSimMatched,
1122  isChargeMatched,
1123  numAssocRecoTracks,
1124  puinfo.getPU_NumInteractions(),
1125  nSimHits,
1126  sharedFraction,
1127  dR,
1128  dR_jet,
1129  mvaValues,
1130  selectsLoose,
1131  selectsHP);
1132  mvaValues.clear();
1133 
1134  if (doSummaryPlots_) {
1135  histograms.h_reco_coll[ww]->Fill(www);
1136  if (isSimMatched) {
1137  histograms.h_assoc2_coll[ww]->Fill(www);
1138  if (numAssocRecoTracks > 1) {
1139  histograms.h_looper_coll[ww]->Fill(www);
1140  }
1141  if (!isSigSimMatched) {
1142  histograms.h_pileup_coll[ww]->Fill(www);
1143  }
1144  }
1145  }
1146 
1147  // dE/dx
1148  if (dodEdxPlots_)
1149  histoProducerAlgo_->fill_dedx_recoTrack_histos(histograms.histoProducerAlgo, w, track, v_dEdx);
1150 
1151  //Fill other histos
1152  if (!isSimMatched)
1153  continue;
1154 
1155  histoProducerAlgo_->fill_simAssociated_recoTrack_histos(histograms.histoProducerAlgo, w, *track);
1156 
1157  /* TO BE FIXED LATER
1158  if (associators[ww]=="trackAssociatorByChi2"){
1159  //association chi2
1160  double assocChi2 = -tp.begin()->second;//in association map is stored -chi2
1161  h_assochi2[www]->Fill(assocChi2);
1162  h_assochi2_prob[www]->Fill(TMath::Prob((assocChi2)*5,5));
1163  }
1164  else if (associators[ww]=="quickTrackAssociatorByHits"){
1165  double fraction = tp.begin()->second;
1166  h_assocFraction[www]->Fill(fraction);
1167  h_assocSharedHit[www]->Fill(fraction*track->numberOfValidHits());
1168  }
1169  */
1170 
1171  if (doResolutionPlots_[www]) {
1172  //Get tracking particle parameters at point of closest approach to the beamline
1173  TrackingParticleRef tpr = tpFound->val.begin()->first;
1174  TrackingParticle::Vector momentumTP = parametersDefinerTP_->momentum(event, setup, tpr);
1175  TrackingParticle::Point vertexTP = parametersDefinerTP_->vertex(event, setup, tpr);
1176  int chargeTP = tpr->charge();
1177 
1178  histoProducerAlgo_->fill_ResoAndPull_recoTrack_histos(
1179  histograms.histoProducerAlgo, w, momentumTP, vertexTP, chargeTP, *track, bs.position());
1180  }
1181 
1182  //TO BE FIXED
1183  //std::vector<PSimHit> simhits=tpr.get()->trackPSimHit(DetId::Tracker);
1184  //nrecHit_vs_nsimHit_rec2sim[w]->Fill(track->numberOfValidHits(), (int)(simhits.end()-simhits.begin() ));
1185 
1186  } // End of for(View<Track>::size_type i=0; i<trackCollection.size(); ++i){
1187  mvaCollections.clear();
1188  qualityMaskCollections.clear();
1189 
1190  histoProducerAlgo_->fill_trackBased_histos(histograms.histoProducerAlgo, w, at, rT, n_selTrack_dr, n_selTP_dr);
1191  // Fill seed-specific histograms
1192  if (doSeedPlots_) {
1193  histoProducerAlgo_->fill_seed_histos(
1194  histograms.histoProducerAlgo, www, seed_fit_failed, trackCollection.size());
1195  }
1196 
1197  LogTrace("TrackValidator") << "Collection " << www << "\n"
1198  << "Total Simulated (selected): " << n_selTP_dr << "\n"
1199  << "Total Reconstructed (selected): " << n_selTrack_dr << "\n"
1200  << "Total Reconstructed: " << rT << "\n"
1201  << "Total Associated (recoToSim): " << at << "\n"
1202  << "Total Fakes: " << rT - at << "\n";
1203  } // End of for (unsigned int www=0;www<label.size();www++){
1204  } //END of for (unsigned int ww=0;ww<associators.size();ww++){
1205 }
reco::SimToRecoCollection associateSimToReco(const edm::Handle< edm::View< reco::Track >> &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
size
Write out results.
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoEsToken
unsigned int size_type
Definition: View.h:90
bool empty() const
Is the RefVector empty.
Definition: RefVector.h:99
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
EncodedEventId eventId() const
Signal source, crossing number.
edm::EDGetTokenT< SimHitTPAssociationProducer::SimHitTPAssociationList > _simHitTpMapTag
edm::EDGetTokenT< edm::ValueMap< reco::DeDxData > > m_dEdx2Tag
int event() const
get the contents of the subdetector field (should be protected?)
bool trackFromSeedFitFailed(const reco::Track &track)
std::vector< edm::EDGetTokenT< reco::SimToRecoCollection > > associatormapStRs
reco::RecoToSimCollection associateRecoToSim(const edm::Handle< edm::View< reco::Track >> &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
CosmicTrackingParticleSelector cosmictpSelector
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
bool empty() const
T w() const
T const * product() const
Definition: Handle.h:70
std::vector< std::vector< std::tuple< edm::EDGetTokenT< MVACollection >, edm::EDGetTokenT< QualityMaskCollection > > > > mvaQualityCollectionTokens_
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
edm::EDGetTokenT< edm::ValueMap< unsigned int > > tpNStripStereoLayersToken_
def replace(string, replacements)
edm::EDGetTokenT< edm::ValueMap< unsigned int > > tpNLayersToken_
void trackDR(const edm::View< reco::Track > &trackCollection, const edm::View< reco::Track > &trackCollectionDr, DynArray< float > &dR_trk, DynArray< float > &dR_trk_jet, const edm::View< reco::Candidate > *cores) const
bool has(unsigned int index) const
Check if an element (=index) is in the set.
Definition: IndexSet.h:54
T_AssociationMap associationMapFilterValues(const T_AssociationMap &map, const T_RefVector &valueRefs)
TrackingParticleSelector dRtpSelector
std::string const & label() const
Definition: InputTag.h:36
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > > associatorTokens
const bool doPlotsOnlyForTruePV_
edm::EDGetTokenT< reco::BeamSpot > bsSrc
constexpr uint32_t mask
Definition: gpuClustering.h:26
const_iterator find(const key_type &k) const
find element with specified reference key
#define LogTrace(id)
size_type size() const
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const_iterator end() const
last iterator over the map (read only)
~MultiTrackValidator() override
Destructor.
math::XYZPointD Point
point in the space
edm::EDGetTokenT< edm::ValueMap< unsigned int > > tpNPixelLayersToken_
math::XYZTLorentzVectorD LorentzVector
std::vector< edm::InputTag > associators
char const * label
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &, Histograms &) const override
Method called to book the DQM histograms.
ProductID id() const
Accessor for product ID.
Definition: RefVector.h:117
std::vector< edm::EDGetTokenT< edm::View< reco::Track > > > labelToken
edm::EDGetTokenT< edm::ValueMap< reco::DeDxData > > m_dEdx1Tag
const reco::Vertex::Point * getRecoPVPosition(const edm::Event &event, const edm::Handle< TrackingVertexCollection > &htv) const
std::vector< edm::EDGetTokenT< reco::RecoToSimCollection > > associatormapRtSs
void tpParametersAndSelection(const Histograms &histograms, const TrackingParticleRefVector &tPCeff, const edm::Event &event, const edm::EventSetup &setup, const reco::BeamSpot &bs, std::vector< std::tuple< TrackingParticle::Vector, TrackingParticle::Point >> &momVert_tPCeff, std::vector< size_t > &selected_tPCeff) const
auto dz(const T_Vertex &vertex, const T_Momentum &momentum, const T_Point &point)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const EncodedEventId & eventId() const
T sqrt(T t)
Definition: SSEVec.h:19
int bunchCrossing() const
get the detector field from this detid
TrackingParticleSelector tpSelector
std::vector< bool > doResolutionPlots_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< edm::View< reco::Track > > labelTokenForDrCalculation
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > label_pileupinfo
std::vector< edm::InputTag > label
std::unique_ptr< ParametersDefinerForTP > parametersDefinerTP_
void reserve(size_type n)
Reserve space for RefVector.
Definition: RefVector.h:108
trackCollection
Definition: JetHT_cfg.py:51
MultiTrackValidator(const edm::ParameterSet &pset)
Constructor.
ObjectSelector< CosmicTrackingParticleSelector > CosmicTrackingParticleSelector
edm::EDGetTokenT< TrackingParticleRefVector > label_tp_fake_refvector
std::unique_ptr< MTVHistoProducerAlgoForTracker > histoProducerAlgo_
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
edm::EDGetTokenT< TrackingVertexCollection > label_tv
edm::EDGetTokenT< reco::VertexToTrackingVertexAssociator > vertexAssociatorToken_
std::unique_ptr< RecoTrackSelectorBase > dRTrackSelector
edm::Ref< edm::HepMCProduct, HepMC::GenParticle > GenParticleRef
const bool ignoremissingtkcollection_
const bool doPVAssociationPlots_
edm::EDGetTokenT< edm::View< reco::Vertex > > recoVertexToken_
std::vector< edm::EDGetTokenT< std::vector< PSimHit > > > simHitTokens_
const bool calculateDrSingleCollection_
fixed size matrix
HLT enums.
auto dxy(const T_Vertex &vertex, const T_Momentum &momentum, const T_Point &point)
void push_back(const RefToBase< T > &)
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
edm::EDGetTokenT< TrackingParticleCollection > label_tp_fake
void initEvent(edm::Handle< SimHitTPAssociationProducer::SimHitTPAssociationList > simHitsTPAssocToSet) const
Monte Carlo truth information used for tracking validation.
void insert(unsigned int index)
Insert an element (=index) to the set.
Definition: IndexSet.h:47
#define declareDynArray(T, n, x)
Definition: DynArray.h:91
reco::VertexRecoToSimCollection associateRecoToSim(const edm::Handle< edm::View< reco::Vertex >> &vCH, const edm::Handle< TrackingVertexCollection > &tVCH) const
edm::EDGetTokenT< edm::View< reco::Candidate > > cores_
size_t tpDR(const TrackingParticleRefVector &tPCeff, const std::vector< size_t > &selected_tPCeff, DynArray< float > &dR_tPCeff, DynArray< float > &dR_tPCeff_jet, const edm::View< reco::Candidate > *cores) const
const TrackingVertex::LorentzVector * getSimPVPosition(const edm::Handle< TrackingVertexCollection > &htv) const
math::XYZVectorD Vector
point in the space
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
edm::EDGetTokenT< TrackingParticleRefVector > label_tp_effic_refvector
doResolutionPlotsForLabels
do resolution plots only for these labels (or all if empty)
static std::unique_ptr< RecoTrackSelectorBase > makeRecoTrackSelectorFromTPSelectorParameters(const edm::ParameterSet &pset)
void dqmAnalyze(const edm::Event &, const edm::EventSetup &, const Histograms &) const override
Method called once per event.
void reserve(unsigned int size)
Reserve memory for the set.
Definition: IndexSet.h:34
SingleObjectSelector< TrackingParticleCollection, ::TrackingParticleSelector > TrackingParticleSelector
edm::EDGetTokenT< TrackingParticleCollection > label_tp_effic
const int getPU_NumInteractions() const
edm::Ref< TrackingParticleCollection > TrackingParticleRef
Definition: event.py:1
Definition: Run.h:45
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
#define LogDebug(id)
const bool parametersDefinerIsCosmic_