CMS 3D CMS Logo

MtdTracksValidation.cc
Go to the documentation of this file.
1 #include <string>
2 
8 
11 
18 
24 
28 
36 
47 
58 
61 
68 
71 #include "HepMC/GenRanges.h"
72 #include "CLHEP/Units/PhysicalConstants.h"
73 #include "MTDHit.h"
74 
76 public:
77  explicit MtdTracksValidation(const edm::ParameterSet&);
78  ~MtdTracksValidation() override;
79 
80  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
81 
82 private:
83  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
84 
85  void analyze(const edm::Event&, const edm::EventSetup&) override;
86 
87  const std::pair<bool, bool> checkAcceptance(
88  const reco::Track&, const edm::Event&, const edm::EventSetup&, size_t&, float&, float&, float&, float&);
89 
90  const bool mvaGenSel(const HepMC::GenParticle&, const float&);
91  const bool mvaTPSel(const TrackingParticle&);
92  const bool mvaRecSel(const reco::TrackBase&, const reco::Vertex&, const double&, const double&);
93  const bool mvaGenRecMatch(const HepMC::GenParticle&, const double&, const reco::TrackBase&, const bool&);
95 
96  const unsigned long int uniqueId(const uint32_t x, const EncodedEventId& y) {
97  const uint64_t a = static_cast<uint64_t>(x);
98  const uint64_t b = static_cast<uint64_t>(y.rawId());
99 
100  if (x < y.rawId())
101  return (b << 32) | a;
102  else
103  return (a << 32) | b;
104  }
105 
106  bool isETL(const double eta) const { return (std::abs(eta) > trackMinEtlEta_) && (std::abs(eta) < trackMaxEtlEta_); }
107 
108  // ------------ member data ------------
109 
111  const float trackMinPt_;
112  const float trackMaxBtlEta_;
113  const float trackMinEtlEta_;
114  const float trackMaxEtlEta_;
115 
116  static constexpr double etacutGEN_ = 4.; // |eta| < 4;
117  static constexpr double etacutREC_ = 3.; // |eta| < 3;
118  static constexpr double pTcut_ = 0.7; // PT > 0.7 GeV
119  static constexpr double deltaZcut_ = 0.1; // dz separation 1 mm
120  static constexpr double deltaPTcut_ = 0.05; // dPT < 5%
121  static constexpr double deltaDRcut_ = 0.03; // DeltaR separation
122  static constexpr double depositBTLthreshold_ = 1; // threshold for energy deposit in BTL cell [MeV]
123  static constexpr double depositETLthreshold_ = 0.001; // threshold for energy deposit in ETL cell [MeV]
124  static constexpr double rBTL_ = 110.0;
125  static constexpr double zETL_ = 290.0;
126  static constexpr double etaMatchCut_ = 0.05;
127  static constexpr double cluDRradius_ = 0.05; // to cluster rechits around extrapolated track
128 
131 
135 
144 
147 
157 
164 
173 
185 
197 
223 
229 };
230 
231 // ------------ constructor and destructor --------------
233  : folder_(iConfig.getParameter<std::string>("folder")),
234  trackMinPt_(iConfig.getParameter<double>("trackMinimumPt")),
235  trackMaxBtlEta_(iConfig.getParameter<double>("trackMaximumBtlEta")),
236  trackMinEtlEta_(iConfig.getParameter<double>("trackMinimumEtlEta")),
237  trackMaxEtlEta_(iConfig.getParameter<double>("trackMaximumEtlEta")) {
238  GenRecTrackToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("inputTagG"));
239  RecTrackToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("inputTagT"));
240  RecVertexToken_ = consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("inputTagV"));
241  HepMCProductToken_ = consumes<edm::HepMCProduct>(iConfig.getParameter<edm::InputTag>("inputTagH"));
243  consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("SimTag"));
245  consumes<reco::SimToRecoCollection>(iConfig.getParameter<edm::InputTag>("TPtoRecoTrackAssoc"));
247  consumes<reco::RecoToSimCollection>(iConfig.getParameter<edm::InputTag>("TPtoRecoTrackAssoc"));
248  btlSimHitsToken_ = consumes<CrossingFrame<PSimHit>>(iConfig.getParameter<edm::InputTag>("btlSimHits"));
249  etlSimHitsToken_ = consumes<CrossingFrame<PSimHit>>(iConfig.getParameter<edm::InputTag>("etlSimHits"));
250  btlRecHitsToken_ = consumes<FTLRecHitCollection>(iConfig.getParameter<edm::InputTag>("btlRecHits"));
251  etlRecHitsToken_ = consumes<FTLRecHitCollection>(iConfig.getParameter<edm::InputTag>("etlRecHits"));
252  trackAssocToken_ = consumes<edm::ValueMap<int>>(iConfig.getParameter<edm::InputTag>("trackAssocSrc"));
253  pathLengthToken_ = consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("pathLengthSrc"));
254  tmtdToken_ = consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("tmtd"));
255  SigmatmtdToken_ = consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("sigmatmtd"));
256  t0SrcToken_ = consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("t0Src"));
257  Sigmat0SrcToken_ = consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("sigmat0Src"));
258  t0PidToken_ = consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("t0PID"));
259  Sigmat0PidToken_ = consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("sigmat0PID"));
260  t0SafePidToken_ = consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("t0SafePID"));
261  Sigmat0SafePidToken_ = consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("sigmat0SafePID"));
262  trackMVAQualToken_ = consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("trackMVAQual"));
263  mtdgeoToken_ = esConsumes<MTDGeometry, MTDDigiGeometryRecord>();
264  mtdtopoToken_ = esConsumes<MTDTopology, MTDTopologyRcd>();
265  mtdlayerToken_ = esConsumes<MTDDetLayerGeometry, MTDRecoGeometryRecord>();
266  magfieldToken_ = esConsumes<MagneticField, IdealMagneticFieldRecord>();
267  builderToken_ = esConsumes<TransientTrackBuilder, TransientTrackRecord>(edm::ESInputTag("", "TransientTrackBuilder"));
268  particleTableToken_ = esConsumes<HepPDT::ParticleDataTable, edm::DefaultRecord>();
269 }
270 
272 
273 // ------------ method called for each event ------------
275  using namespace edm;
276  using namespace geant_units::operators;
277  using namespace std;
278 
279  auto GenRecTrackHandle = makeValid(iEvent.getHandle(GenRecTrackToken_));
280  auto RecVertexHandle = makeValid(iEvent.getHandle(RecVertexToken_));
281 
282  std::unordered_map<uint32_t, MTDHit> m_btlHits;
283  std::unordered_map<uint32_t, MTDHit> m_etlHits;
284  std::unordered_map<uint32_t, std::set<unsigned long int>> m_btlTrkPerCell;
285  std::unordered_map<uint32_t, std::set<unsigned long int>> m_etlTrkPerCell;
286  std::map<TrackingParticleRef, std::vector<uint32_t>> m_tp2detid;
287 
288  const auto& tMtd = iEvent.get(tmtdToken_);
289  const auto& SigmatMtd = iEvent.get(SigmatmtdToken_);
290  const auto& t0Src = iEvent.get(t0SrcToken_);
291  const auto& Sigmat0Src = iEvent.get(Sigmat0SrcToken_);
292  const auto& t0Pid = iEvent.get(t0PidToken_);
293  const auto& Sigmat0Pid = iEvent.get(Sigmat0PidToken_);
294  const auto& t0Safe = iEvent.get(t0SafePidToken_);
295  const auto& Sigmat0Safe = iEvent.get(Sigmat0SafePidToken_);
296  const auto& mtdQualMVA = iEvent.get(trackMVAQualToken_);
297  const auto& trackAssoc = iEvent.get(trackAssocToken_);
298  const auto& pathLength = iEvent.get(pathLengthToken_);
299 
300  const auto& primRecoVtx = *(RecVertexHandle.product()->begin());
301 
302  // generator level information (HepMC format)
303  auto GenEventHandle = makeValid(iEvent.getHandle(HepMCProductToken_));
304  const HepMC::GenEvent* mc = GenEventHandle->GetEvent();
305  double zsim = convertMmToCm((*(mc->vertices_begin()))->position().z());
306  double tsim = (*(mc->vertices_begin()))->position().t() * CLHEP::mm / CLHEP::c_light;
307 
308  auto pdt = iSetup.getHandle(particleTableToken_);
309  const HepPDT::ParticleDataTable* pdTable = pdt.product();
310 
311  auto simToRecoH = makeValid(iEvent.getHandle(simToRecoAssociationToken_));
312  s2r_ = simToRecoH.product();
313 
314  auto recoToSimH = makeValid(iEvent.getHandle(recoToSimAssociationToken_));
315  r2s_ = recoToSimH.product();
316 
317  //Fill maps with simhits accumulated per DetId
318 
319  auto btlSimHitsHandle = makeValid(iEvent.getHandle(btlSimHitsToken_));
320  MixCollection<PSimHit> btlSimHits(btlSimHitsHandle.product());
321  for (auto const& simHit : btlSimHits) {
322  if (simHit.tof() < 0 || simHit.tof() > 25.)
323  continue;
324  DetId id = simHit.detUnitId();
325  auto const thisHId = uniqueId(simHit.trackId(), simHit.eventId());
326  m_btlTrkPerCell[id.rawId()].insert(thisHId);
327  auto simHitIt = m_btlHits.emplace(id.rawId(), MTDHit()).first;
328  // --- Accumulate the energy (in MeV) of SIM hits in the same detector cell
329  (simHitIt->second).energy += convertUnitsTo(0.001_MeV, simHit.energyLoss());
330  }
331 
332  auto etlSimHitsHandle = makeValid(iEvent.getHandle(etlSimHitsToken_));
333  MixCollection<PSimHit> etlSimHits(etlSimHitsHandle.product());
334  for (auto const& simHit : etlSimHits) {
335  if (simHit.tof() < 0 || simHit.tof() > 25.) {
336  continue;
337  }
338  DetId id = simHit.detUnitId();
339  auto const thisHId = uniqueId(simHit.trackId(), simHit.eventId());
340  m_etlTrkPerCell[id.rawId()].insert(thisHId);
341  auto simHitIt = m_etlHits.emplace(id.rawId(), MTDHit()).first;
342  // --- Accumulate the energy (in MeV) of SIM hits in the same detector cell
343  (simHitIt->second).energy += convertUnitsTo(0.001_MeV, simHit.energyLoss());
344  }
345 
346  //Fill map of DetId per ref to TP
347 
348  auto tpHandle = makeValid(iEvent.getHandle(trackingParticleCollectionToken_));
349  TrackingParticleCollection tpColl = *(tpHandle.product());
350  size_t tpindex(0);
351  for (auto tp = tpColl.begin(); tp != tpColl.end(); tp++, ++tpindex) {
353  if (tp->eventId().bunchCrossing() == 0 && tp->eventId().event() == 0) {
354  if (!mvaTPSel(*tp))
355  continue;
356  for (const auto& simTrk : tp->g4Tracks()) {
357  auto const thisTId = uniqueId(simTrk.trackId(), simTrk.eventId());
358  for (auto const& cell : m_btlTrkPerCell) {
359  if (m_btlHits[cell.first].energy < depositBTLthreshold_) {
360  continue;
361  }
362  for (auto const& simtrack : cell.second) {
363  if (thisTId == simtrack) {
364  m_tp2detid[tpref].emplace_back(cell.first);
365  break;
366  }
367  }
368  }
369  for (auto const& cell : m_etlTrkPerCell) {
370  if (m_etlHits[cell.first].energy < depositETLthreshold_) {
371  continue;
372  }
373  for (auto const& simtrack : cell.second) {
374  if (thisTId == simtrack) {
375  m_tp2detid[tpref].emplace_back(cell.first);
376  break;
377  }
378  }
379  }
380  }
381  }
382  }
383 
384  unsigned int index = 0;
385 
386  // flag to select events with reco vertex close to true simulated primary vertex, or PV fake (particle guns)
387  const bool isGoodVtx = std::abs(primRecoVtx.z() - zsim) < deltaZcut_ || primRecoVtx.isFake();
388 
389  // --- Loop over all RECO tracks ---
390  for (const auto& trackGen : *GenRecTrackHandle) {
391  const reco::TrackRef trackref(iEvent.getHandle(GenRecTrackToken_), index);
392  index++;
393 
394  if (trackAssoc[trackref] == -1) {
395  LogInfo("mtdTracks") << "Extended track not associated";
396  continue;
397  }
398 
399  const reco::TrackRef mtdTrackref = reco::TrackRef(iEvent.getHandle(RecTrackToken_), trackAssoc[trackref]);
400  const reco::Track& track = *mtdTrackref;
401 
402  bool isBTL = false;
403  bool isETL = false;
404  bool twoETLdiscs = false;
405  bool noCrack = std::abs(trackGen.eta()) < trackMaxBtlEta_ || std::abs(trackGen.eta()) > trackMinEtlEta_;
406 
407  if (track.pt() >= trackMinPt_ && std::abs(track.eta()) <= trackMaxEtlEta_) {
408  meTracktmtd_->Fill(tMtd[trackref]);
409  if (std::round(SigmatMtd[trackref] - Sigmat0Pid[trackref]) != 0) {
410  LogWarning("mtdTracks")
411  << "TimeError associated to refitted track is different from TimeError stored in tofPID "
412  "sigmat0 ValueMap: this should not happen";
413  }
414 
415  meTrackt0Src_->Fill(t0Src[trackref]);
416  meTrackSigmat0Src_->Fill(Sigmat0Src[trackref]);
417 
418  meTrackt0Pid_->Fill(t0Pid[trackref]);
419  meTrackSigmat0Pid_->Fill(Sigmat0Pid[trackref]);
420  meTrackt0SafePid_->Fill(t0Safe[trackref]);
421  meTrackSigmat0SafePid_->Fill(Sigmat0Safe[trackref]);
422  meTrackMVAQual_->Fill(mtdQualMVA[trackref]);
423 
424  meTrackPathLenghtvsEta_->Fill(std::abs(track.eta()), pathLength[trackref]);
425 
426  if (std::abs(track.eta()) < trackMaxBtlEta_) {
427  // --- all BTL tracks (with and without hit in MTD) ---
431 
432  bool MTDBtl = false;
433  int numMTDBtlvalidhits = 0;
434  for (const auto hit : track.recHits()) {
435  if (hit->isValid() == false)
436  continue;
437  MTDDetId Hit = hit->geographicalId();
438  if ((Hit.det() == 6) && (Hit.subdetId() == 1) && (Hit.mtdSubDetector() == 1)) {
439  MTDBtl = true;
440  numMTDBtlvalidhits++;
441  }
442  }
443  meTrackNumHits_->Fill(numMTDBtlvalidhits);
444 
445  // --- keeping only tracks with last hit in MTD ---
446  if (MTDBtl == true) {
447  isBTL = true;
452  meBTLTrackPtRes_->Fill((trackGen.pt() - track.pt()) / trackGen.pt());
453  }
454  if (isBTL && Sigmat0Safe[trackref] < 0.) {
455  meTrackNumHitsNT_->Fill(numMTDBtlvalidhits);
456  }
457  } //loop over (geometrical) BTL tracks
458 
459  else {
460  // --- all ETL tracks (with and without hit in MTD) ---
461  if ((track.eta() < -trackMinEtlEta_) && (track.eta() > -trackMaxEtlEta_)) {
462  meETLTrackEffEtaTot_[0]->Fill(track.eta());
463  meETLTrackEffPhiTot_[0]->Fill(track.phi());
464  meETLTrackEffPtTot_[0]->Fill(track.pt());
465  }
466 
467  if ((track.eta() > trackMinEtlEta_) && (track.eta() < trackMaxEtlEta_)) {
468  meETLTrackEffEtaTot_[1]->Fill(track.eta());
469  meETLTrackEffPhiTot_[1]->Fill(track.phi());
470  meETLTrackEffPtTot_[1]->Fill(track.pt());
471  }
472 
473  bool MTDEtlZnegD1 = false;
474  bool MTDEtlZnegD2 = false;
475  bool MTDEtlZposD1 = false;
476  bool MTDEtlZposD2 = false;
477  int numMTDEtlvalidhits = 0;
478  for (const auto hit : track.recHits()) {
479  if (hit->isValid() == false)
480  continue;
481  MTDDetId Hit = hit->geographicalId();
482  if ((Hit.det() == 6) && (Hit.subdetId() == 1) && (Hit.mtdSubDetector() == 2)) {
483  isETL = true;
484  ETLDetId ETLHit = hit->geographicalId();
485 
486  if ((ETLHit.zside() == -1) && (ETLHit.nDisc() == 1)) {
487  MTDEtlZnegD1 = true;
489  meETLTrackPtRes_->Fill((trackGen.pt() - track.pt()) / trackGen.pt());
490  numMTDEtlvalidhits++;
491  }
492  if ((ETLHit.zside() == -1) && (ETLHit.nDisc() == 2)) {
493  MTDEtlZnegD2 = true;
495  meETLTrackPtRes_->Fill((trackGen.pt() - track.pt()) / trackGen.pt());
496  numMTDEtlvalidhits++;
497  }
498  if ((ETLHit.zside() == 1) && (ETLHit.nDisc() == 1)) {
499  MTDEtlZposD1 = true;
501  meETLTrackPtRes_->Fill((trackGen.pt() - track.pt()) / trackGen.pt());
502  numMTDEtlvalidhits++;
503  }
504  if ((ETLHit.zside() == 1) && (ETLHit.nDisc() == 2)) {
505  MTDEtlZposD2 = true;
507  meETLTrackPtRes_->Fill((trackGen.pt() - track.pt()) / trackGen.pt());
508  numMTDEtlvalidhits++;
509  }
510  }
511  }
512  meTrackNumHits_->Fill(-numMTDEtlvalidhits);
513  if (isETL && Sigmat0Safe[trackref] < 0.) {
514  meTrackNumHitsNT_->Fill(-numMTDEtlvalidhits);
515  }
516 
517  // --- keeping only tracks with last hit in MTD ---
518  if ((track.eta() < -trackMinEtlEta_) && (track.eta() > -trackMaxEtlEta_)) {
519  twoETLdiscs = (MTDEtlZnegD1 == true) && (MTDEtlZnegD2 == true);
520  if ((MTDEtlZnegD1 == true) || (MTDEtlZnegD2 == true)) {
521  meETLTrackEffEtaMtd_[0]->Fill(track.eta());
522  meETLTrackEffPhiMtd_[0]->Fill(track.phi());
523  meETLTrackEffPtMtd_[0]->Fill(track.pt());
524  if (twoETLdiscs) {
525  meETLTrackEffEta2Mtd_[0]->Fill(track.eta());
526  meETLTrackEffPhi2Mtd_[0]->Fill(track.phi());
527  meETLTrackEffPt2Mtd_[0]->Fill(track.pt());
528  }
529  }
530  }
531  if ((track.eta() > trackMinEtlEta_) && (track.eta() < trackMaxEtlEta_)) {
532  twoETLdiscs = (MTDEtlZposD1 == true) && (MTDEtlZposD2 == true);
533  if ((MTDEtlZposD1 == true) || (MTDEtlZposD2 == true)) {
534  meETLTrackEffEtaMtd_[1]->Fill(track.eta());
535  meETLTrackEffPhiMtd_[1]->Fill(track.phi());
536  meETLTrackEffPtMtd_[1]->Fill(track.pt());
537  if (twoETLdiscs) {
538  meETLTrackEffEta2Mtd_[1]->Fill(track.eta());
539  meETLTrackEffPhi2Mtd_[1]->Fill(track.phi());
540  meETLTrackEffPt2Mtd_[1]->Fill(track.pt());
541  }
542  }
543  }
544  }
545 
546  LogDebug("MtdTracksValidation") << "Track p/pt = " << track.p() << " " << track.pt() << " eta " << track.eta()
547  << " BTL " << isBTL << " ETL " << isETL << " 2disks " << twoETLdiscs;
548 
549  // TrackingParticle based matching
550 
551  const reco::TrackBaseRef trkrefb(trackref);
552  auto tp_info = getMatchedTP(trkrefb);
553 
554  meTrackPtTot_->Fill(trackGen.pt());
555  meTrackEtaTot_->Fill(std::abs(trackGen.eta()));
556  if (tp_info != nullptr && mvaTPSel(**tp_info)) {
557  const bool withMTD = (m_tp2detid.find(*tp_info) != m_tp2detid.end());
558  LogDebug("MtdTracksValidation") << "Matched with selected TP, MTD sim hits association: " << withMTD;
559  if (noCrack) {
560  meTrackMatchedTPEffPtTot_->Fill(trackGen.pt());
561  if (withMTD) {
562  meTrackMatchedTPmtdEffPtTot_->Fill(trackGen.pt());
563  }
564  }
565  meTrackMatchedTPEffEtaTot_->Fill(std::abs(trackGen.eta()));
566  if (withMTD) {
567  meTrackMatchedTPmtdEffEtaTot_->Fill(std::abs(trackGen.eta()));
568  }
569  if (isBTL || isETL) {
570  if (noCrack) {
571  meTrackMatchedTPEffPtMtd_->Fill(trackGen.pt());
572  if (isBTL || twoETLdiscs) {
573  meTrackMatchedTPEffPtEtl2Mtd_->Fill(trackGen.pt());
574  }
575  if (withMTD) {
576  meTrackMatchedTPmtdEffPtMtd_->Fill(trackGen.pt());
577  }
578  }
579  meTrackMatchedTPEffEtaMtd_->Fill(std::abs(trackGen.eta()));
580  if (isBTL || twoETLdiscs) {
581  meTrackMatchedTPEffEtaEtl2Mtd_->Fill(std::abs(trackGen.eta()));
582  }
583  if (withMTD) {
584  meTrackMatchedTPmtdEffEtaMtd_->Fill(std::abs(trackGen.eta()));
585  }
586  }
587 
588  size_t nlayers(0);
589  float extrho(0.);
590  float exteta(0.);
591  float extphi(0.);
592  float selvar(0.);
593  auto accept = checkAcceptance(trackGen, iEvent, iSetup, nlayers, extrho, exteta, extphi, selvar);
594  if (accept.first && std::abs(exteta) < trackMaxBtlEta_) {
596  meExtraBTLeneInCone_->Fill(selvar);
597  }
598  if (accept.second) {
599  if (std::abs(exteta) < trackMaxBtlEta_) {
601  }
602  if (noCrack) {
603  meExtraPtMtd_->Fill(trackGen.pt());
604  if (nlayers == 2) {
605  meExtraPtEtl2Mtd_->Fill(trackGen.pt());
606  }
607  }
608  meExtraEtaMtd_->Fill(std::abs(trackGen.eta()));
609  if (nlayers == 2) {
610  meExtraEtaEtl2Mtd_->Fill(std::abs(trackGen.eta()));
611  }
612  if (accept.first && accept.second && !(isBTL || isETL)) {
613  edm::LogInfo("MtdTracksValidation")
614  << "MtdTracksValidation: extender fail in " << iEvent.id().run() << " " << iEvent.id().event()
615  << " pt= " << trackGen.pt() << " eta= " << trackGen.eta();
616  meExtraMTDfailExtenderEta_->Fill(std::abs(trackGen.eta()));
617  if (noCrack) {
618  meExtraMTDfailExtenderPt_->Fill(trackGen.pt());
619  }
620  }
621  }
622 
623  } // TP matching
624  }
625 
626  if (isGoodVtx) {
627  const bool vtxFake = primRecoVtx.isFake();
628 
629  if (mvaRecSel(trackGen, primRecoVtx, t0Safe[trackref], Sigmat0Safe[trackref])) {
630  // reco-gen matching used for MVA quality flag
631 
632  if (noCrack) {
633  meMVATrackEffPtTot_->Fill(trackGen.pt());
634  }
635  meMVATrackEffEtaTot_->Fill(std::abs(trackGen.eta()));
636 
637  double dZ = trackGen.vz() - zsim;
638  double dT(-9999.);
639  double pullT(-9999.);
640  if (Sigmat0Safe[trackref] != -1.) {
641  dT = t0Safe[trackref] - tsim;
642  pullT = dT / Sigmat0Safe[trackref];
643  }
644  for (const auto& genP : mc->particle_range()) {
645  // select status 1 genParticles and match them to the reconstructed track
646 
647  float charge = pdTable->particle(HepPDT::ParticleID(genP->pdg_id())) != nullptr
648  ? pdTable->particle(HepPDT::ParticleID(genP->pdg_id()))->charge()
649  : 0.f;
650  if (mvaGenSel(*genP, charge)) {
651  if (mvaGenRecMatch(*genP, zsim, trackGen, vtxFake)) {
653  if (noCrack) {
654  meMVATrackMatchedEffPtTot_->Fill(trackGen.pt());
655  }
656  meMVATrackMatchedEffEtaTot_->Fill(std::abs(trackGen.eta()));
657  if (isBTL || isETL) {
658  meMVATrackResTot_->Fill(dT);
659  meMVATrackPullTot_->Fill(pullT);
660  if (noCrack) {
661  meMVATrackMatchedEffPtMtd_->Fill(trackGen.pt());
662  }
663  meMVATrackMatchedEffEtaMtd_->Fill(std::abs(trackGen.eta()));
664  }
665  break;
666  }
667  }
668  }
669  }
670  } // MC truth matich analysis for good PV
671  } //RECO tracks loop
672 }
673 
674 const std::pair<bool, bool> MtdTracksValidation::checkAcceptance(const reco::Track& track,
675  const edm::Event& iEvent,
676  edm::EventSetup const& iSetup,
677  size_t& nlayers,
678  float& extrho,
679  float& exteta,
680  float& extphi,
681  float& selvar) {
682  bool isMatched(false);
683  nlayers = 0;
684  extrho = 0.;
685  exteta = -999.;
686  extphi = -999.;
687  selvar = 0.;
688 
689  auto geometryHandle = iSetup.getTransientHandle(mtdgeoToken_);
690  const MTDGeometry* geom = geometryHandle.product();
691  auto topologyHandle = iSetup.getTransientHandle(mtdtopoToken_);
692  const MTDTopology* topology = topologyHandle.product();
693 
694  auto layerHandle = iSetup.getTransientHandle(mtdlayerToken_);
695  const MTDDetLayerGeometry* layerGeo = layerHandle.product();
696 
697  auto magfieldHandle = iSetup.getTransientHandle(magfieldToken_);
698  const MagneticField* mfield = magfieldHandle.product();
699 
700  auto ttrackBuilder = iSetup.getTransientHandle(builderToken_);
701 
702  auto tTrack = ttrackBuilder->build(track);
703  TrajectoryStateOnSurface tsos = tTrack.outermostMeasurementState();
704  float theMaxChi2 = 500.;
705  float theNSigma = 10.;
706  std::unique_ptr<MeasurementEstimator> theEstimator =
707  std::make_unique<Chi2MeasurementEstimator>(theMaxChi2, theNSigma);
709 
710  auto btlRecHitsHandle = makeValid(iEvent.getHandle(btlRecHitsToken_));
711  auto etlRecHitsHandle = makeValid(iEvent.getHandle(etlRecHitsToken_));
712 
713  edm::LogVerbatim("MtdTracksValidation")
714  << "MtdTracksValidation: extrapolating track, pt= " << track.pt() << " eta= " << track.eta();
715 
716  //try BTL
717  bool inBTL = false;
718  float eneSum(0.);
719  const std::vector<const DetLayer*>& layersBTL = layerGeo->allBTLLayers();
720  for (const DetLayer* ilay : layersBTL) {
721  std::pair<bool, TrajectoryStateOnSurface> comp = ilay->compatible(tsos, prop, *theEstimator);
722  if (!comp.first)
723  continue;
724  if (!inBTL) {
725  inBTL = true;
726  extrho = comp.second.globalPosition().perp();
727  exteta = comp.second.globalPosition().eta();
728  extphi = comp.second.globalPosition().phi();
729  edm::LogVerbatim("MtdTracksValidation") << "MtdTracksValidation: extrapolation at BTL surface, rho= " << extrho
730  << " eta= " << exteta << " phi= " << extphi;
731  }
732  std::vector<DetLayer::DetWithState> compDets = ilay->compatibleDets(tsos, prop, *theEstimator);
733  for (const auto& detWithState : compDets) {
734  const auto& det = detWithState.first;
735 
736  // loop on compatible rechits and check energy in a fixed size cone around the extrapolation point
737 
738  edm::LogVerbatim("MtdTracksValidation")
739  << "MtdTracksValidation: DetId= " << det->geographicalId().rawId()
740  << " gp= " << detWithState.second.globalPosition().x() << " " << detWithState.second.globalPosition().y()
741  << " " << detWithState.second.globalPosition().z() << " rho= " << detWithState.second.globalPosition().perp()
742  << " eta= " << detWithState.second.globalPosition().eta()
743  << " phi= " << detWithState.second.globalPosition().phi();
744 
745  for (const auto& recHit : *btlRecHitsHandle) {
746  BTLDetId detId = recHit.id();
747  DetId geoId = detId.geographicalId(MTDTopologyMode::crysLayoutFromTopoMode(topology->getMTDTopologyMode()));
748  const MTDGeomDet* thedet = geom->idToDet(geoId);
749  if (thedet == nullptr)
750  throw cms::Exception("MtdTracksValidation") << "GeographicalID: " << std::hex << geoId.rawId() << " ("
751  << detId.rawId() << ") is invalid!" << std::dec << std::endl;
752  if (geoId == det->geographicalId()) {
753  const ProxyMTDTopology& topoproxy = static_cast<const ProxyMTDTopology&>(thedet->topology());
754  const RectangularMTDTopology& topo = static_cast<const RectangularMTDTopology&>(topoproxy.specificTopology());
755 
756  Local3DPoint local_point(0., 0., 0.);
757  local_point = topo.pixelToModuleLocalPoint(local_point, detId.row(topo.nrows()), detId.column(topo.nrows()));
758  const auto& global_point = thedet->toGlobal(local_point);
759  edm::LogVerbatim("MtdTracksValidation")
760  << "MtdTracksValidation: Hit id= " << detId.rawId() << " ene= " << recHit.energy()
761  << " dr= " << reco::deltaR(global_point, detWithState.second.globalPosition());
762  if (reco::deltaR(global_point, detWithState.second.globalPosition()) < cluDRradius_) {
763  eneSum += recHit.energy();
764  //extrho = detWithState.second.globalPosition().perp();
765  //exteta = detWithState.second.globalPosition().eta();
766  //extphi = detWithState.second.globalPosition().phi();
767  }
768  }
769  }
770  }
771  if (eneSum > depositBTLthreshold_) {
772  nlayers++;
773  selvar = eneSum;
774  isMatched = true;
775  edm::LogVerbatim("MtdTracksValidation")
776  << "MtdTracksValidation: BTL matched, energy= " << eneSum << " #layers= " << nlayers;
777  }
778  }
779  if (inBTL) {
780  return std::make_pair(inBTL, isMatched);
781  }
782 
783  //try ETL
784  bool inETL = false;
785  const std::vector<const DetLayer*>& layersETL = layerGeo->allETLLayers();
786  for (const DetLayer* ilay : layersETL) {
787  size_t hcount(0);
788  const BoundDisk& disk = static_cast<const MTDSectorForwardDoubleLayer*>(ilay)->specificSurface();
789  const double diskZ = disk.position().z();
790  if (tsos.globalPosition().z() * diskZ < 0)
791  continue; // only propagate to the disk that's on the same side
792  std::pair<bool, TrajectoryStateOnSurface> comp = ilay->compatible(tsos, prop, *theEstimator);
793  if (!comp.first)
794  continue;
795  if (!inETL) {
796  inETL = true;
797  extrho = comp.second.globalPosition().perp();
798  exteta = comp.second.globalPosition().eta();
799  extphi = comp.second.globalPosition().phi();
800  }
801  edm::LogVerbatim("MtdTracksValidation") << "MtdTracksValidation: extrapolation at ETL surface, rho= " << extrho
802  << " eta= " << exteta << " phi= " << extphi;
803  std::vector<DetLayer::DetWithState> compDets = ilay->compatibleDets(tsos, prop, *theEstimator);
804  for (const auto& detWithState : compDets) {
805  const auto& det = detWithState.first;
806 
807  // loop on compatible rechits and check hits in a fixed size cone around the extrapolation point
808 
809  edm::LogVerbatim("MtdTracksValidation")
810  << "MtdTracksValidation: DetId= " << det->geographicalId().rawId()
811  << " gp= " << detWithState.second.globalPosition().x() << " " << detWithState.second.globalPosition().y()
812  << " " << detWithState.second.globalPosition().z() << " rho= " << detWithState.second.globalPosition().perp()
813  << " eta= " << detWithState.second.globalPosition().eta()
814  << " phi= " << detWithState.second.globalPosition().phi();
815 
816  for (const auto& recHit : *etlRecHitsHandle) {
817  ETLDetId detId = recHit.id();
818  DetId geoId = detId.geographicalId();
819  const MTDGeomDet* thedet = geom->idToDet(geoId);
820  if (thedet == nullptr)
821  throw cms::Exception("MtdTracksValidation") << "GeographicalID: " << std::hex << geoId.rawId() << " ("
822  << detId.rawId() << ") is invalid!" << std::dec << std::endl;
823  if (geoId == det->geographicalId()) {
824  const ProxyMTDTopology& topoproxy = static_cast<const ProxyMTDTopology&>(thedet->topology());
825  const RectangularMTDTopology& topo = static_cast<const RectangularMTDTopology&>(topoproxy.specificTopology());
826 
827  Local3DPoint local_point(topo.localX(recHit.row()), topo.localY(recHit.column()), 0.);
828  const auto& global_point = thedet->toGlobal(local_point);
829  edm::LogVerbatim("MtdTracksValidation")
830  << "MtdTracksValidation: Hit id= " << detId.rawId() << " time= " << recHit.time()
831  << " dr= " << reco::deltaR(global_point, detWithState.second.globalPosition());
832  if (reco::deltaR(global_point, detWithState.second.globalPosition()) < cluDRradius_) {
833  hcount++;
834  if (hcount == 1) {
835  //extrho = detWithState.second.globalPosition().perp();
836  //exteta = detWithState.second.globalPosition().eta();
837  //extphi = detWithState.second.globalPosition().phi();
838  }
839  }
840  }
841  }
842  }
843  if (hcount > 0) {
844  nlayers++;
845  selvar = (float)hcount;
846  isMatched = true;
847  edm::LogVerbatim("MtdTracksValidation")
848  << "MtdTracksValidation: ETL matched, counts= " << hcount << " #layers= " << nlayers;
849  }
850  }
851 
852  if (!inBTL && !inETL) {
853  edm::LogVerbatim("MtdTracksValidation")
854  << "MtdTracksValidation: track not extrapolating to MTD: pt= " << track.pt() << " eta= " << track.eta()
855  << " phi= " << track.phi() << " vz= " << track.vz()
856  << " vxy= " << std::sqrt(track.vx() * track.vx() + track.vy() * track.vy());
857  }
858  return std::make_pair(inETL, isMatched);
859 }
860 
861 // ------------ method for histogram booking ------------
863  ibook.setCurrentFolder(folder_);
864 
865  // histogram booking
866  meBTLTrackRPTime_ = ibook.book1D("TrackBTLRPTime", "Track t0 with respect to R.P.;t0 [ns]", 100, -1, 3);
867  meBTLTrackEffEtaTot_ = ibook.book1D("TrackBTLEffEtaTot", "Track efficiency vs eta (Tot);#eta_{RECO}", 100, -1.6, 1.6);
869  ibook.book1D("TrackBTLEffPhiTot", "Track efficiency vs phi (Tot);#phi_{RECO} [rad]", 100, -3.2, 3.2);
870  meBTLTrackEffPtTot_ = ibook.book1D("TrackBTLEffPtTot", "Track efficiency vs pt (Tot);pt_{RECO} [GeV]", 50, 0, 10);
871  meBTLTrackEffEtaMtd_ = ibook.book1D("TrackBTLEffEtaMtd", "Track efficiency vs eta (Mtd);#eta_{RECO}", 100, -1.6, 1.6);
873  ibook.book1D("TrackBTLEffPhiMtd", "Track efficiency vs phi (Mtd);#phi_{RECO} [rad]", 100, -3.2, 3.2);
874  meBTLTrackEffPtMtd_ = ibook.book1D("TrackBTLEffPtMtd", "Track efficiency vs pt (Mtd);pt_{RECO} [GeV]", 50, 0, 10);
876  ibook.book1D("TrackBTLPtRes", "Track pT resolution ;pT_{Gentrack}-pT_{MTDtrack}/pT_{Gentrack} ", 100, -0.1, 0.1);
877  meETLTrackRPTime_ = ibook.book1D("TrackETLRPTime", "Track t0 with respect to R.P.;t0 [ns]", 100, -1, 3);
879  ibook.book1D("TrackETLEffEtaTotZneg", "Track efficiency vs eta (Tot) (-Z);#eta_{RECO}", 100, -3.2, -1.4);
881  ibook.book1D("TrackETLEffEtaTotZpos", "Track efficiency vs eta (Tot) (+Z);#eta_{RECO}", 100, 1.4, 3.2);
883  ibook.book1D("TrackETLEffPhiTotZneg", "Track efficiency vs phi (Tot) (-Z);#phi_{RECO} [rad]", 100, -3.2, 3.2);
885  ibook.book1D("TrackETLEffPhiTotZpos", "Track efficiency vs phi (Tot) (+Z);#phi_{RECO} [rad]", 100, -3.2, 3.2);
887  ibook.book1D("TrackETLEffPtTotZneg", "Track efficiency vs pt (Tot) (-Z);pt_{RECO} [GeV]", 50, 0, 10);
889  ibook.book1D("TrackETLEffPtTotZpos", "Track efficiency vs pt (Tot) (+Z);pt_{RECO} [GeV]", 50, 0, 10);
891  ibook.book1D("TrackETLEffEtaMtdZneg", "Track efficiency vs eta (Mtd) (-Z);#eta_{RECO}", 100, -3.2, -1.4);
893  ibook.book1D("TrackETLEffEtaMtdZpos", "Track efficiency vs eta (Mtd) (+Z);#eta_{RECO}", 100, 1.4, 3.2);
895  ibook.book1D("TrackETLEffPhiMtdZneg", "Track efficiency vs phi (Mtd) (-Z);#phi_{RECO} [rad]", 100, -3.2, 3.2);
897  ibook.book1D("TrackETLEffPhiMtdZpos", "Track efficiency vs phi (Mtd) (+Z);#phi_{RECO} [rad]", 100, -3.2, 3.2);
899  ibook.book1D("TrackETLEffPtMtdZneg", "Track efficiency vs pt (Mtd) (-Z);pt_{RECO} [GeV]", 50, 0, 10);
901  ibook.book1D("TrackETLEffPtMtdZpos", "Track efficiency vs pt (Mtd) (+Z);pt_{RECO} [GeV]", 50, 0, 10);
903  ibook.book1D("TrackETLEffEta2MtdZneg", "Track efficiency vs eta (Mtd 2 hit) (-Z);#eta_{RECO}", 100, -3.2, -1.4);
905  ibook.book1D("TrackETLEffEta2MtdZpos", "Track efficiency vs eta (Mtd 2 hit) (+Z);#eta_{RECO}", 100, 1.4, 3.2);
906  meETLTrackEffPhi2Mtd_[0] = ibook.book1D(
907  "TrackETLEffPhi2MtdZneg", "Track efficiency vs phi (Mtd 2 hit) (-Z);#phi_{RECO} [rad]", 100, -3.2, 3.2);
908  meETLTrackEffPhi2Mtd_[1] = ibook.book1D(
909  "TrackETLEffPhi2MtdZpos", "Track efficiency vs phi (Mtd 2 hit) (+Z);#phi_{RECO} [rad]", 100, -3.2, 3.2);
911  ibook.book1D("TrackETLEffPt2MtdZneg", "Track efficiency vs pt (Mtd 2 hit) (-Z);pt_{RECO} [GeV]", 50, 0, 10);
913  ibook.book1D("TrackETLEffPt2MtdZpos", "Track efficiency vs pt (Mtd 2 hit) (+Z);pt_{RECO} [GeV]", 50, 0, 10);
915  ibook.book1D("TrackETLPtRes", "Track pT resolution;pT_{Gentrack}-pT_{MTDtrack}/pT_{Gentrack} ", 100, -0.1, 0.1);
916 
917  meTracktmtd_ = ibook.book1D("Tracktmtd", "Track time from TrackExtenderWithMTD;tmtd [ns]", 150, 1, 16);
918  meTrackt0Src_ = ibook.book1D("Trackt0Src", "Track time from TrackExtenderWithMTD;t0Src [ns]", 100, -1.5, 1.5);
920  ibook.book1D("TrackSigmat0Src", "Time Error from TrackExtenderWithMTD; #sigma_{t0Src} [ns]", 100, 0, 0.1);
921 
922  meTrackt0Pid_ = ibook.book1D("Trackt0Pid", "Track t0 as stored in TofPid;t0 [ns]", 100, -1, 1);
923  meTrackSigmat0Pid_ = ibook.book1D("TrackSigmat0Pid", "Sigmat0 as stored in TofPid; #sigma_{t0} [ns]", 100, 0, 0.1);
924  meTrackt0SafePid_ = ibook.book1D("Trackt0SafePID", "Track t0 Safe as stored in TofPid;t0 [ns]", 100, -1, 1);
926  ibook.book1D("TrackSigmat0SafePID", "Sigmat0 Safe as stored in TofPid; #sigma_{t0} [ns]", 100, 0, 0.1);
927  meTrackNumHits_ = ibook.book1D("TrackNumHits", "Number of valid MTD hits per track ; Number of hits", 10, -5, 5);
928  meTrackNumHitsNT_ = ibook.book1D(
929  "TrackNumHitsNT", "Number of valid MTD hits per track no time associated; Number of hits", 10, -5, 5);
930  meTrackMVAQual_ = ibook.book1D("TrackMVAQual", "Track MVA Quality as stored in Value Map ; MVAQual", 100, 0, 1);
932  "TrackPathLenghtvsEta", "MTD Track pathlength vs MTD track Eta;|#eta|;Pathlength", 100, 0, 3.2, 100.0, 400.0, "S");
933 
934  meMVATrackEffPtTot_ = ibook.book1D("MVAEffPtTot", "Pt of tracks associated to LV; track pt [GeV] ", 110, 0., 11.);
936  ibook.book1D("MVAMatchedEffPtTot", "Pt of tracks associated to LV matched to GEN; track pt [GeV] ", 110, 0., 11.);
938  "MVAMatchedEffPtMtd", "Pt of tracks associated to LV matched to GEN with time; track pt [GeV] ", 110, 0., 11.);
939 
940  meExtraPtMtd_ = ibook.book1D("ExtraPtMtd", "Pt of tracks extrapolated to hits; track pt [GeV] ", 110, 0., 11.);
942  ibook.book1D("ExtraPtEtl2Mtd", "Pt of tracks extrapolated to hits, 2 ETL layers; track pt [GeV] ", 110, 0., 11.);
943 
944  meTrackPtTot_ = ibook.book1D("TrackPtTot", "Pt of tracks ; track pt [GeV] ", 110, 0., 11.);
946  ibook.book1D("MatchedTPEffPtTot", "Pt of tracks matched to TP; track pt [GeV] ", 110, 0., 11.);
948  ibook.book1D("MatchedTPEffPtMtd", "Pt of tracks matched to TP with time; track pt [GeV] ", 110, 0., 11.);
950  "MatchedTPEffPtEtl2Mtd", "Pt of tracks matched to TP with time, 2 ETL hits; track pt [GeV] ", 110, 0., 11.);
951 
953  ibook.book1D("MatchedTPmtdEffPtTot", "Pt of tracks matched to TP-mtd hit; track pt [GeV] ", 110, 0., 11.);
955  "MatchedTPmtdEffPtMtd", "Pt of tracks matched to TP-mtd hit with time; track pt [GeV] ", 110, 0., 11.);
956 
957  meMVATrackEffEtaTot_ = ibook.book1D("MVAEffEtaTot", "Eta of tracks associated to LV; track eta ", 66, 0., 3.3);
959  ibook.book1D("MVAMatchedEffEtaTot", "Eta of tracks associated to LV matched to GEN; track eta ", 66, 0., 3.3);
961  "MVAMatchedEffEtaMtd", "Eta of tracks associated to LV matched to GEN with time; track eta ", 66, 0., 3.3);
962 
963  meExtraEtaMtd_ = ibook.book1D("ExtraEtaMtd", "Eta of tracks extrapolated to hits; track eta ", 66, 0., 3.3);
965  ibook.book1D("ExtraEtaEtl2Mtd", "Eta of tracks extrapolated to hits, 2 ETL layers; track eta ", 66, 0., 3.3);
966 
967  meTrackEtaTot_ = ibook.book1D("TrackEtaTot", "Eta of tracks ; track eta ", 66, 0., 3.3);
969  ibook.book1D("MatchedTPEffEtaTot", "Eta of tracks matched to TP; track eta ", 66, 0., 3.3);
970  meMVATrackEffEtaTot_ = ibook.book1D("MVAEffEtaTot", "Eta of tracks ; track eta ", 66, 0., 3.3);
972  ibook.book1D("MatchedTPEffEtaMtd", "Eta of tracks matched to TP with time; track eta ", 66, 0., 3.3);
974  "MatchedTPEffEtaEtl2Mtd", "Eta of tracks matched to TP with time, 2 ETL hits; track eta ", 66, 0., 3.3);
975 
977  ibook.book1D("MatchedTPmtdEffEtaTot", "Eta of tracks matched to TP-mtd hit; track eta ", 66, 0., 3.3);
979  ibook.book1D("MatchedTPmtdEffEtaMtd", "Eta of tracks matched to TP-mtd hit with time; track eta ", 66, 0., 3.3);
980 
981  meMVATrackResTot_ = ibook.book1D(
982  "MVATrackRes", "t_{rec} - t_{sim} for LV associated tracks; t_{rec} - t_{sim} [ns] ", 120, -0.15, 0.15);
984  ibook.book1D("MVATrackPull", "Pull for associated tracks; (t_{rec}-t_{sim})/#sigma_{t}", 50, -5., 5.);
986  "MVATrackZposResTot", "Z_{PCA} - Z_{sim} for associated tracks;Z_{PCA} - Z_{sim} [cm] ", 100, -0.1, 0.1);
987 
989  ibook.book1D("ExtraPhiAtBTL", "Phi at BTL surface of extrapolated tracks; phi [deg]", 720, -180., 180.);
990  meExtraPhiAtBTLmatched_ = ibook.book1D("ExtraPhiAtBTLmatched",
991  "Phi at BTL surface of extrapolated tracksi matched with BTL hits; phi [deg]",
992  720,
993  -180.,
994  180.);
996  "ExtraBTLeneInCone", "BTL reconstructed energy in cone arounnd extrapolated track; E [MeV]", 100, 0., 50.);
998  ibook.book1D("ExtraMTDfailExtenderEta",
999  "Eta of tracks extrapolated to MTD with no track extender match to hits; track eta",
1000  66,
1001  0.,
1002  3.3);
1003  ;
1005  ibook.book1D("ExtraMTDfailExtenderPt",
1006  "Pt of tracks extrapolated to MTD with no track extender match to hits; track pt [GeV] ",
1007  110,
1008  0.,
1009  11.);
1010 }
1011 
1012 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
1013 
1016 
1017  desc.add<std::string>("folder", "MTD/Tracks");
1018  desc.add<edm::InputTag>("inputTagG", edm::InputTag("generalTracks"));
1019  desc.add<edm::InputTag>("inputTagT", edm::InputTag("trackExtenderWithMTD"));
1020  desc.add<edm::InputTag>("inputTagV", edm::InputTag("offlinePrimaryVertices4D"));
1021  desc.add<edm::InputTag>("inputTagH", edm::InputTag("generatorSmeared"));
1022  desc.add<edm::InputTag>("SimTag", edm::InputTag("mix", "MergedTrackTruth"));
1023  desc.add<edm::InputTag>("TPtoRecoTrackAssoc", edm::InputTag("trackingParticleRecoTrackAsssociation"));
1024  desc.add<edm::InputTag>("btlSimHits", edm::InputTag("mix", "g4SimHitsFastTimerHitsBarrel"));
1025  desc.add<edm::InputTag>("etlSimHits", edm::InputTag("mix", "g4SimHitsFastTimerHitsEndcap"));
1026  desc.add<edm::InputTag>("btlRecHits", edm::InputTag("mtdRecHits", "FTLBarrel"));
1027  desc.add<edm::InputTag>("etlRecHits", edm::InputTag("mtdRecHits", "FTLEndcap"));
1028  desc.add<edm::InputTag>("tmtd", edm::InputTag("trackExtenderWithMTD:generalTracktmtd"));
1029  desc.add<edm::InputTag>("sigmatmtd", edm::InputTag("trackExtenderWithMTD:generalTracksigmatmtd"));
1030  desc.add<edm::InputTag>("t0Src", edm::InputTag("trackExtenderWithMTD:generalTrackt0"));
1031  desc.add<edm::InputTag>("sigmat0Src", edm::InputTag("trackExtenderWithMTD:generalTracksigmat0"));
1032  desc.add<edm::InputTag>("trackAssocSrc", edm::InputTag("trackExtenderWithMTD:generalTrackassoc"))
1033  ->setComment("Association between General and MTD Extended tracks");
1034  desc.add<edm::InputTag>("pathLengthSrc", edm::InputTag("trackExtenderWithMTD:generalTrackPathLength"));
1035  desc.add<edm::InputTag>("t0SafePID", edm::InputTag("tofPID:t0safe"));
1036  desc.add<edm::InputTag>("sigmat0SafePID", edm::InputTag("tofPID:sigmat0safe"));
1037  desc.add<edm::InputTag>("sigmat0PID", edm::InputTag("tofPID:sigmat0"));
1038  desc.add<edm::InputTag>("t0PID", edm::InputTag("tofPID:t0"));
1039  desc.add<edm::InputTag>("trackMVAQual", edm::InputTag("mtdTrackQualityMVA:mtdQualMVA"));
1040  desc.add<double>("trackMinimumPt", 0.7); // [GeV]
1041  desc.add<double>("trackMaximumBtlEta", 1.5);
1042  desc.add<double>("trackMinimumEtlEta", 1.6);
1043  desc.add<double>("trackMaximumEtlEta", 3.);
1044  desc.addUntracked<bool>("optionalPlots", true);
1045 
1046  descriptions.add("mtdTracksValid", desc);
1047 }
1048 
1050  bool match = false;
1051  if (gp.status() != 1) {
1052  return match;
1053  }
1054  match = charge != 0.f && gp.momentum().perp() > pTcut_ && std::abs(gp.momentum().eta()) < etacutGEN_;
1055  return match;
1056 }
1057 
1059  bool match = false;
1060  if (tp.status() != 1) {
1061  return match;
1062  }
1063  auto x_pv = tp.parentVertex()->position().x();
1064  auto y_pv = tp.parentVertex()->position().y();
1065  auto z_pv = tp.parentVertex()->position().z();
1066 
1067  auto r_pv = std::sqrt(x_pv * x_pv + y_pv * y_pv);
1068 
1069  match = tp.charge() != 0 && tp.pt() > pTcut_ && std::abs(tp.eta()) < etacutGEN_ && r_pv < rBTL_ && z_pv < zETL_;
1070  return match;
1071 }
1072 
1074  const reco::Vertex& vtx,
1075  const double& t0,
1076  const double& st0) {
1077  bool match = false;
1078  match = trk.pt() > pTcut_ && std::abs(trk.eta()) < etacutREC_ &&
1079  (std::abs(trk.vz() - vtx.z()) <= deltaZcut_ || vtx.isFake());
1080  if (st0 > 0.) {
1081  match = match && std::abs(t0 - vtx.t()) < 3. * st0;
1082  }
1083  return match;
1084 }
1085 
1087  const double& zsim,
1088  const reco::TrackBase& trk,
1089  const bool& vtxFake) {
1090  bool match = false;
1091  double dR = reco::deltaR(genP.momentum(), trk.momentum());
1092  double genPT = genP.momentum().perp();
1093  match = std::abs(genPT - trk.pt()) < trk.pt() * deltaPTcut_ && dR < deltaDRcut_ &&
1094  (std::abs(trk.vz() - zsim) < deltaZcut_ || vtxFake);
1095  return match;
1096 }
1097 
1099  auto found = r2s_->find(recoTrack);
1100 
1101  // reco track not matched to any TP
1102  if (found == r2s_->end())
1103  return nullptr;
1104 
1105  //matched TP equal to any TP associated to in time events
1106  for (const auto& tp : found->val) {
1107  if (tp.first->eventId().bunchCrossing() == 0)
1108  return &tp.first;
1109  }
1110 
1111  // reco track not matched to any TP from vertex
1112  return nullptr;
1113 }
1114 
MonitorElement * meETLTrackEffEtaTot_[2]
edm::EDGetTokenT< edm::ValueMap< int > > trackAssocToken_
static constexpr double etacutGEN_
Log< level::Info, true > LogVerbatim
MonitorElement * meTrackMatchedTPEffEtaMtd_
MonitorElement * meBTLTrackEffPhiMtd_
int getMTDTopologyMode() const
Definition: MTDTopology.h:27
edm::EDGetTokenT< edm::ValueMap< float > > trackMVAQualToken_
edm::EDGetTokenT< edm::ValueMap< float > > pathLengthToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
MonitorElement * meMVATrackResTot_
MonitorElement * meTrackNumHits_
MonitorElement * meTrackt0Pid_
MonitorElement * meExtraMTDfailExtenderEta_
static constexpr double pTcut_
const std::pair< bool, bool > checkAcceptance(const reco::Track &, const edm::Event &, const edm::EventSetup &, size_t &, float &, float &, float &, float &)
MonitorElement * meETLTrackRPTime_
edm::EDGetTokenT< edm::ValueMap< float > > t0SafePidToken_
std::string folder_
edm::EDGetTokenT< edm::ValueMap< float > > t0SrcToken_
static constexpr double rBTL_
edm::ESGetToken< MTDTopology, MTDTopologyRcd > mtdtopoToken_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
const std::string folder_
edm::EDGetTokenT< edm::HepMCProduct > HepMCProductToken_
HepPDT::ParticleDataTable ParticleDataTable
T z() const
Definition: PV3DBase.h:61
MonitorElement * meMVATrackMatchedEffEtaMtd_
const bool mvaRecSel(const reco::TrackBase &, const reco::Vertex &, const double &, const double &)
virtual const Topology & topology() const
Definition: GeomDet.cc:67
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > builderToken_
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
virtual const PixelTopology & specificTopology() const
static constexpr double etacutREC_
static constexpr double deltaPTcut_
MonitorElement * meBTLTrackPtRes_
edm::EDGetTokenT< std::vector< reco::Vertex > > RecVertexToken_
MonitorElement * meETLTrackEffPtTot_[2]
MonitorElement * meBTLTrackEffEtaMtd_
MonitorElement * meETLTrackEffPhi2Mtd_[2]
Definition: MTDHit.h:4
edm::EDGetTokenT< edm::ValueMap< float > > tmtdToken_
MonitorElement * meExtraBTLeneInCone_
MonitorElement * meExtraMTDfailExtenderPt_
MonitorElement * meMVATrackMatchedEffPtTot_
MonitorElement * meMVATrackEffPtTot_
MonitorElement * meExtraEtaMtd_
MonitorElement * meMVATrackEffEtaTot_
const reco::SimToRecoCollection * s2r_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
const unsigned long int uniqueId(const uint32_t x, const EncodedEventId &y)
LocalPoint pixelToModuleLocalPoint(const LocalPoint &plp, int row, int col) const
MonitorElement * meTrackMatchedTPmtdEffEtaTot_
static constexpr double cluDRradius_
const reco::RecoToSimCollection * r2s_
const edm::Ref< std::vector< TrackingParticle > > * getMatchedTP(const reco::TrackBaseRef &)
const_iterator find(const key_type &k) const
find element with specified reference key
const bool mvaGenSel(const HepMC::GenParticle &, const float &)
Detector identifier base class for the MIP Timing Layer.
Definition: MTDDetId.h:21
const bool mvaTPSel(const TrackingParticle &)
constexpr NumType convertUnitsTo(double desiredUnits, NumType val)
Definition: GeantUnits.h:73
edm::EDGetTokenT< reco::TrackCollection > GenRecTrackToken_
MonitorElement * meETLTrackEffPhiMtd_[2]
const_iterator end() const
last iterator over the map (read only)
void Fill(long long x)
double pt() const
track transverse momentum
Definition: TrackBase.h:637
edm::EDGetTokenT< reco::TrackCollection > RecTrackToken_
MonitorElement * meExtraEtaEtl2Mtd_
MonitorElement * meBTLTrackEffPhiTot_
edm::ESGetToken< MTDDetLayerGeometry, MTDRecoGeometryRecord > mtdlayerToken_
int iEvent
Definition: GenABIO.cc:224
GlobalPoint globalPosition() const
MonitorElement * meTrackMatchedTPmtdEffEtaMtd_
MonitorElement * meTrackMatchedTPEffEtaTot_
float localX(const float mpX) const override
edm::EDGetTokenT< FTLRecHitCollection > etlRecHitsToken_
MonitorElement * meBTLTrackRPTime_
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:661
MonitorElement * meETLTrackEffEta2Mtd_[2]
static constexpr double depositBTLthreshold_
MonitorElement * meETLTrackPtRes_
MonitorElement * meETLTrackEffPt2Mtd_[2]
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
MonitorElement * meTrackt0SafePid_
T sqrt(T t)
Definition: SSEVec.h:19
MonitorElement * meBTLTrackEffEtaTot_
static constexpr double deltaZcut_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isETL(const double eta) const
bool isMatched(TrackingRecHit const &hit)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
int nrows() const override
MonitorElement * meMVATrackMatchedEffEtaTot_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< edm::ValueMap< float > > t0PidToken_
MonitorElement * meTrackMatchedTPEffPtEtl2Mtd_
MonitorElement * meTrackMatchedTPmtdEffPtMtd_
edm::EDGetTokenT< FTLRecHitCollection > btlRecHitsToken_
MonitorElement * meTrackMVAQual_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
MonitorElement * meETLTrackEffPhiTot_[2]
float localY(const float mpY) const override
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
const std::vector< const DetLayer * > & allBTLLayers() const
return the BTL DetLayers (barrel), inside-out
edm::EDGetTokenT< edm::ValueMap< float > > SigmatmtdToken_
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
edm::EDGetTokenT< TrackingParticleCollection > trackingParticleCollectionToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
MonitorElement * meTrackNumHitsNT_
Log< level::Info, false > LogInfo
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
Definition: DetId.h:17
constexpr NumType convertMmToCm(NumType millimeters)
Definition: angle_units.h:44
edm::EDGetTokenT< reco::SimToRecoCollection > simToRecoAssociationToken_
MonitorElement * meTrackEtaTot_
static constexpr double etaMatchCut_
static constexpr double zETL_
static constexpr double depositETLthreshold_
MonitorElement * meTrackMatchedTPEffEtaEtl2Mtd_
unsigned long long uint64_t
Definition: Time.h:13
MonitorElement * meMVATrackPullTot_
MonitorElement * meTrackMatchedTPEffPtMtd_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void analyze(const edm::Event &, const edm::EventSetup &) override
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
double b
Definition: hdecay.h:120
edm::EDGetTokenT< CrossingFrame< PSimHit > > etlSimHitsToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
MonitorElement * meTrackSigmat0SafePid_
MonitorElement * meETLTrackEffEtaMtd_[2]
int zside() const
Definition: MTDDetId.h:61
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:664
MonitorElement * meTrackSigmat0Pid_
edm::EDGetTokenT< CrossingFrame< PSimHit > > btlSimHitsToken_
MonitorElement * meTrackMatchedTPmtdEffPtTot_
MonitorElement * meBTLTrackEffPtMtd_
MonitorElement * meTrackt0Src_
edm::EDGetTokenT< edm::ValueMap< float > > Sigmat0PidToken_
static constexpr double deltaDRcut_
MonitorElement * meTracktmtd_
MonitorElement * meBTLTrackEffPtTot_
MonitorElement * meTrackPathLenghtvsEta_
MonitorElement * meTrackMatchedTPEffPtTot_
Detector identifier class for the Endcap Timing Layer.
Definition: ETLDetId.h:15
HLT enums.
int nDisc() const
Definition: ETLDetId.h:124
double a
Definition: hdecay.h:121
const bool mvaGenRecMatch(const HepMC::GenParticle &, const double &, const reco::TrackBase &, const bool &)
Detector identifier class for the Barrel Timing Layer. The crystal count must start from 0...
Definition: BTLDetId.h:19
MonitorElement * meExtraPtMtd_
ESTransientHandle< T > getTransientHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:141
MonitorElement * meExtraPhiAtBTLmatched_
edm::EDGetTokenT< reco::RecoToSimCollection > recoToSimAssociationToken_
Monte Carlo truth information used for tracking validation.
edm::EDGetTokenT< edm::ValueMap< float > > Sigmat0SrcToken_
MonitorElement * meETLTrackEffPtMtd_[2]
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
MonitorElement * meExtraPtEtl2Mtd_
BTLDetId::CrysLayout crysLayoutFromTopoMode(const int &topoMode)
edm::ESGetToken< MTDGeometry, MTDDigiGeometryRecord > mtdgeoToken_
std::vector< TrackingParticle > TrackingParticleCollection
MonitorElement * meTrackPtTot_
MonitorElement * meMVATrackZposResTot_
Log< level::Warning, false > LogWarning
auto makeValid(const U &iOtherHandleType) noexcept(false)
Definition: ValidHandle.h:52
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
MonitorElement * meMVATrackMatchedEffPtMtd_
MonitorElement * meTrackSigmat0Src_
const std::vector< const DetLayer * > & allETLLayers() const
return the ETL DetLayers (endcap), -Z to +Z
Definition: Run.h:45
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magfieldToken_
edm::EDGetTokenT< edm::ValueMap< float > > Sigmat0SafePidToken_
MtdTracksValidation(const edm::ParameterSet &)
#define LogDebug(id)
edm::ESGetToken< HepPDT::ParticleDataTable, edm::DefaultRecord > particleTableToken_
MonitorElement * meExtraPhiAtBTL_