CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Static Private Member Functions
MuonIdTruthInfo Class Reference

#include <MuonIdTruthInfo.h>

Public Member Functions

void registerConsumes (edm::ConsumesCollector &iC)
 

Static Public Member Functions

static void truthMatchMuon (const edm::Event &iEvent, const GlobalTrackingGeometry &iGeometry, reco::Muon &aMuon)
 

Static Private Member Functions

static void checkSimHitForBestMatch (reco::MuonSegmentMatch &segmentMatch, double &distance, const PSimHit &hit, const DetId &chamberId, const GlobalTrackingGeometry &geometry)
 
static double matchChi2 (const reco::Track &recoTrk, const SimTrack &simTrk)
 

Detailed Description

Definition at line 21 of file MuonIdTruthInfo.h.

Member Function Documentation

◆ checkSimHitForBestMatch()

void MuonIdTruthInfo::checkSimHitForBestMatch ( reco::MuonSegmentMatch segmentMatch,
double &  distance,
const PSimHit hit,
const DetId chamberId,
const GlobalTrackingGeometry geometry 
)
staticprivate

Definition at line 97 of file MuonIdTruthInfo.cc.

References HLT_2024v10_cff::distance, reco::MuonSegmentMatch::dXdZ, reco::MuonSegmentMatch::dXdZErr, reco::MuonSegmentMatch::dYdZ, reco::MuonSegmentMatch::dYdZErr, ecal::raw::entryPoint(), LogTrace, DetId::rawId(), GeomDet::toGlobal(), GeomDet::toLocal(), reco::MuonSegmentMatch::x, PV3DBase< T, PVType, FrameType >::x(), reco::MuonSegmentMatch::xErr, reco::MuonSegmentMatch::y, PV3DBase< T, PVType, FrameType >::y(), reco::MuonSegmentMatch::yErr, and PV3DBase< T, PVType, FrameType >::z().

Referenced by truthMatchMuon().

101  {
102  printf("DONT FORGET TO CALL REGISTERCONSUMES()\n");
103 
104  // find the hit position projection at the reference surface of the chamber:
105  // first get entry and exit point of the hit in the global coordinates, then
106  // get local coordinates of these points wrt the chamber and then find the
107  // projected X-Y coordinates
108 
109  const GeomDet* chamberGeometry = geometry.idToDet(chamberId);
110  const GeomDet* simUnitGeometry = geometry.idToDet(DetId(hit.detUnitId()));
111 
112  if (chamberGeometry && simUnitGeometry) {
113  LocalPoint entryPoint = chamberGeometry->toLocal(simUnitGeometry->toGlobal(hit.entryPoint()));
114  LocalPoint exitPoint = chamberGeometry->toLocal(simUnitGeometry->toGlobal(hit.exitPoint()));
115  LocalVector direction = exitPoint - entryPoint;
116  if (fabs(direction.z()) > 0.001) {
117  LocalPoint projection = entryPoint - direction * (entryPoint.z() / direction.z());
118  if (fabs(projection.z()) > 0.001)
119  edm::LogWarning("MuonIdentification") << "z coordinate of the hit projection must be zero and it's not!\n";
120 
121  double new_distance = 99999;
122  if (entryPoint.z() * exitPoint.z() < -1) // changed sign, so the reference point is inside
123  new_distance = 0;
124  else {
125  if (fabs(entryPoint.z()) < fabs(exitPoint.z()))
126  new_distance = fabs(entryPoint.z());
127  else
128  new_distance = fabs(exitPoint.z());
129  }
130 
131  if (new_distance < distance) {
132  // find a SimHit closer to the reference surface, update segmentMatch
133  segmentMatch.x = projection.x();
134  segmentMatch.y = projection.y();
135  segmentMatch.xErr = 0;
136  segmentMatch.yErr = 0;
137  segmentMatch.dXdZ = direction.x() / direction.z();
138  segmentMatch.dYdZ = direction.y() / direction.z();
139  segmentMatch.dXdZErr = 0;
140  segmentMatch.dYdZErr = 0;
141  distance = new_distance;
142  LogTrace("MuonIdentificationVerbose")
143  << "Better truth matched segment found:\n"
144  << "\tDetId: " << chamberId.rawId() << "\n"
145  << "\tentry point: ( " << entryPoint.x() << ", " << entryPoint.y() << ", " << entryPoint.z() << " )\n"
146  << "\texit point: ( " << exitPoint.x() << ", " << exitPoint.y() << ", " << exitPoint.z() << " )\n"
147  << "\tprojection: ( " << projection.x() << ", " << projection.y() << ", " << projection.z() << " )\n";
148  }
149  }
150  } else {
151  if (!chamberGeometry)
152  edm::LogWarning("MuonIdentification") << "Cannot get chamber geomtry for DetId: " << chamberId.rawId();
153  if (!simUnitGeometry)
154  edm::LogWarning("MuonIdentification") << "Cannot get detector unit geomtry for DetId: " << hit.detUnitId();
155  }
156 }
void entryPoint(InputDataCPU const &, InputDataGPU &, OutputDataGPU &, ScratchDataGPU &, OutputDataCPU &, ConditionsProducts const &, cudaStream_t, uint32_t const, uint32_t const)
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:58
T z() const
Definition: PV3DBase.h:61
#define LogTrace(id)
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
Definition: DetId.h:17
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
Log< level::Warning, false > LogWarning

◆ matchChi2()

double MuonIdTruthInfo::matchChi2 ( const reco::Track recoTrk,
const SimTrack simTrk 
)
staticprivate

Definition at line 158 of file MuonIdTruthInfo.cc.

References SiPixelRawToDigiRegional_cfi::deltaPhi, CoreSimTrack::momentum(), reco::TrackBase::p(), reco::TrackBase::phi(), funct::pow(), and reco::TrackBase::theta().

Referenced by truthMatchMuon().

158  {
159  double deltaPhi = fabs(recoTrk.phi() - simTrk.momentum().phi());
160  if (deltaPhi > 1.8 * 3.1416)
161  deltaPhi = 2 * 3.1416 - deltaPhi; // take care of phi discontinuity
162  return pow((recoTrk.p() - simTrk.momentum().rho()) / simTrk.momentum().rho(), 2) + pow(deltaPhi / (2 * 3.1416), 2) +
163  pow((recoTrk.theta() - simTrk.momentum().theta()) / 3.1416, 2);
164 }
double p() const
momentum vector magnitude
Definition: TrackBase.h:631
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
double theta() const
polar angle
Definition: TrackBase.h:602
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ registerConsumes()

void MuonIdTruthInfo::registerConsumes ( edm::ConsumesCollector iC)

Definition at line 11 of file MuonIdTruthInfo.cc.

References ProducerED_cfi::InputTag, and edm::ConsumesCollector::mayConsume().

11  {
12  iC.mayConsume<edm::SimTrackContainer>(edm::InputTag("g4SimHits", ""));
13  iC.mayConsume<edm::PSimHitContainer>(edm::InputTag("g4SimHits", "MuonDTHits"));
14  iC.mayConsume<edm::PSimHitContainer>(edm::InputTag("g4SimHits", "MuonCSCHits"));
15 }
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
std::vector< PSimHit > PSimHitContainer
std::vector< SimTrack > SimTrackContainer

◆ truthMatchMuon()

void MuonIdTruthInfo::truthMatchMuon ( const edm::Event iEvent,
const GlobalTrackingGeometry iGeometry,
reco::Muon aMuon 
)
static

Definition at line 17 of file MuonIdTruthInfo.cc.

References deltar::bestMatch(), checkSimHitForBestMatch(), nano_mu_local_reco_cff::chi2, MuonSubdetId::CSC, hcalRecHitTable_cff::detId, HLT_2024v10_cff::distance, MuonSubdetId::DT, edm::Ref< C, T, F >::get(), iEvent, LogTrace, matchChi2(), oniaPATMuonsWithTrigger_cff::matches, reco::Muon::matches(), DetId::Muon, hltrates_dqm_sourceclient-live_cfg::offset, FastTrackerRecHitCombiner_cfi::simHits, TrackCandidateProducer_cfi::simTracks, reco::Muon::track(), reco::MuonSegmentMatch::x, and reco::MuonSegmentMatch::y.

Referenced by MuonIdProducer::produce().

19  {
20  // get a list of simulated track and find a track with the best match to
21  // the muon.track(). Use its id and chamber id to localize hits
22  // If a hit has non-zero local z coordinate, it's position wrt
23  // to the center of a chamber is extrapolated by a straight line
24 
26  iEvent.getByLabel<edm::SimTrackContainer>("g4SimHits", "", simTracks);
27  if (!simTracks.isValid()) {
28  LogTrace("MuonIdentification") << "No tracks found";
29  return;
30  }
31 
32  float bestMatchChi2 = 9999; //minimization creteria
33  unsigned int bestMatch = 0;
34  const unsigned int offset = 0; // kludge to fix a problem in trackId matching between tracks and hits.
35 
36  for (edm::SimTrackContainer::const_iterator simTrk = simTracks->begin(); simTrk != simTracks->end(); simTrk++) {
37  float chi2 = matchChi2(*aMuon.track().get(), *simTrk);
38  if (chi2 > bestMatchChi2)
39  continue;
40  bestMatchChi2 = chi2;
41  bestMatch = simTrk->trackId();
42  }
43 
44  bestMatch -= offset;
45 
46  std::vector<reco::MuonChamberMatch>& matches = aMuon.matches();
47  int numberOfTruthMatchedChambers = 0;
48 
49  // loop over chambers
50  for (std::vector<reco::MuonChamberMatch>::iterator chamberMatch = matches.begin(); chamberMatch != matches.end();
51  chamberMatch++) {
52  if (chamberMatch->id.det() != DetId::Muon) {
53  edm::LogWarning("MuonIdentification") << "Detector id of a muon chamber corresponds to not a muon detector";
54  continue;
55  }
56  reco::MuonSegmentMatch bestSegmentMatch;
57  double distance = 99999;
58 
59  if (chamberMatch->id.subdetId() == MuonSubdetId::DT) {
60  DTChamberId detId(chamberMatch->id.rawId());
61 
63  iEvent.getByLabel("g4SimHits", "MuonDTHits", simHits);
64  if (simHits.isValid()) {
65  for (edm::PSimHitContainer::const_iterator hit = simHits->begin(); hit != simHits->end(); hit++)
66  if (hit->trackId() == bestMatch)
67  checkSimHitForBestMatch(bestSegmentMatch, distance, *hit, detId, geometry);
68  } else
69  LogTrace("MuonIdentification") << "No DT simulated hits are found";
70  }
71 
72  if (chamberMatch->id.subdetId() == MuonSubdetId::CSC) {
73  CSCDetId detId(chamberMatch->id.rawId());
74 
76  iEvent.getByLabel("g4SimHits", "MuonCSCHits", simHits);
77  if (simHits.isValid()) {
78  for (edm::PSimHitContainer::const_iterator hit = simHits->begin(); hit != simHits->end(); hit++)
79  if (hit->trackId() == bestMatch)
80  checkSimHitForBestMatch(bestSegmentMatch, distance, *hit, detId, geometry);
81  } else
82  LogTrace("MuonIdentification") << "No CSC simulated hits are found";
83  }
84  if (distance < 9999) {
85  chamberMatch->truthMatches.push_back(bestSegmentMatch);
86  numberOfTruthMatchedChambers++;
87  LogTrace("MuonIdentification") << "Best truth matched hit:"
88  << "\tDetId: " << chamberMatch->id.rawId() << "\n"
89  << "\tprojection: ( " << bestSegmentMatch.x << ", " << bestSegmentMatch.y
90  << " )\n";
91  }
92  }
93  LogTrace("MuonIdentification") << "Truth matching summary:\n\tnumber of chambers: " << matches.size()
94  << "\n\tnumber of truth matched chambers: " << numberOfTruthMatchedChambers << "\n";
95 }
static void checkSimHitForBestMatch(reco::MuonSegmentMatch &segmentMatch, double &distance, const PSimHit &hit, const DetId &chamberId, const GlobalTrackingGeometry &geometry)
TrackRef track() const override
reference to a Track
Definition: Muon.h:46
#define LogTrace(id)
int iEvent
Definition: GenABIO.cc:224
def bestMatch(object, matchCollection)
Definition: deltar.py:138
std::vector< MuonChamberMatch > & matches()
get muon matching information
Definition: Muon.h:145
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
static constexpr int DT
Definition: MuonSubdetId.h:11
Log< level::Warning, false > LogWarning
static constexpr int CSC
Definition: MuonSubdetId.h:12
std::vector< SimTrack > SimTrackContainer
static double matchChi2(const reco::Track &recoTrk, const SimTrack &simTrk)