26 LogTrace(
"MuonIdentification") <<
"No tracks found";
34 throw cms::Exception(
"FatalError") <<
"Unable to find GlobalTrackingGeometryRecord in event!\n";
36 float bestMatchChi2 = 9999;
38 const unsigned int offset = 0;
40 for (edm::SimTrackContainer::const_iterator simTrk = simTracks->begin(); simTrk != simTracks->end(); simTrk++) {
42 if (chi2 > bestMatchChi2)
45 bestMatch = simTrk->trackId();
51 int numberOfTruthMatchedChambers = 0;
54 for (std::vector<reco::MuonChamberMatch>::iterator chamberMatch = matches.begin(); chamberMatch != matches.end();
57 edm::LogWarning(
"MuonIdentification") <<
"Detector id of a muon chamber corresponds to not a muon detector";
67 iEvent.
getByLabel(
"g4SimHits",
"MuonDTHits", simHits);
68 if (simHits.isValid()) {
69 for (edm::PSimHitContainer::const_iterator
hit = simHits->begin();
hit != simHits->end();
hit++)
73 LogTrace(
"MuonIdentification") <<
"No DT simulated hits are found";
77 CSCDetId detId(chamberMatch->id.rawId());
80 iEvent.
getByLabel(
"g4SimHits",
"MuonCSCHits", simHits);
81 if (simHits.isValid()) {
82 for (edm::PSimHitContainer::const_iterator
hit = simHits->begin();
hit != simHits->end();
hit++)
86 LogTrace(
"MuonIdentification") <<
"No CSC simulated hits are found";
88 if (distance < 9999) {
89 chamberMatch->truthMatches.push_back(bestSegmentMatch);
90 numberOfTruthMatchedChambers++;
91 LogTrace(
"MuonIdentification") <<
"Best truth matched hit:" 92 <<
"\tDetId: " << chamberMatch->id.rawId() <<
"\n" 93 <<
"\tprojection: ( " << bestSegmentMatch.
x <<
", " << bestSegmentMatch.
y 97 LogTrace(
"MuonIdentification") <<
"Truth matching summary:\n\tnumber of chambers: " << matches.size()
98 <<
"\n\tnumber of truth matched chambers: " << numberOfTruthMatchedChambers <<
"\n";
104 const DetId& chamberId,
106 printf(
"DONT FORGET TO CALL REGISTERCONSUMES()\n");
116 if (chamberGeometry && simUnitGeometry) {
120 if (fabs(direction.
z()) > 0.001) {
121 LocalPoint projection = entryPoint - direction * (entryPoint.z() / direction.
z());
122 if (fabs(projection.
z()) > 0.001)
123 edm::LogWarning(
"MuonIdentification") <<
"z coordinate of the hit projection must be zero and it's not!\n";
125 double new_distance = 99999;
126 if (entryPoint.z() * exitPoint.
z() < -1)
129 if (fabs(entryPoint.z()) < fabs(exitPoint.
z()))
130 new_distance = fabs(entryPoint.z());
132 new_distance = fabs(exitPoint.
z());
135 if (new_distance < distance) {
137 segmentMatch.
x = projection.
x();
138 segmentMatch.
y = projection.
y();
139 segmentMatch.
xErr = 0;
140 segmentMatch.
yErr = 0;
141 segmentMatch.
dXdZ = direction.
x() / direction.
z();
142 segmentMatch.
dYdZ = direction.
y() / direction.
z();
145 distance = new_distance;
146 LogTrace(
"MuonIdentificationVerbose")
147 <<
"Better truth matched segment found:\n" 148 <<
"\tDetId: " << chamberId.
rawId() <<
"\n" 149 <<
"\tentry point: ( " << entryPoint.x() <<
", " << entryPoint.y() <<
", " << entryPoint.z() <<
" )\n" 150 <<
"\texit point: ( " << exitPoint.
x() <<
", " << exitPoint.
y() <<
", " << exitPoint.
z() <<
" )\n" 151 <<
"\tprojection: ( " << projection.
x() <<
", " << projection.
y() <<
", " << projection.
z() <<
" )\n";
155 if (!chamberGeometry)
156 edm::LogWarning(
"MuonIdentification") <<
"Cannot get chamber geomtry for DetId: " << chamberId.
rawId();
157 if (!simUnitGeometry)
164 if (deltaPhi > 1.8 * 3.1416)
166 return pow((recoTrk.
p() - simTrk.
momentum().rho()) / simTrk.
momentum().rho(), 2) +
pow(deltaPhi / (2 * 3.1416), 2) +
double p() const
momentum vector magnitude
static void truthMatchMuon(const edm::Event &iEvent, const edm::EventSetup &iSetup, reco::Muon &aMuon)
TrackRef track() const override
reference to a Track
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
double theta() const
polar angle
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
constexpr uint32_t rawId() const
get the raw id
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
double phi() const
azimuthal angle of momentum vector
static void checkSimHitForBestMatch(reco::MuonSegmentMatch &segmentMatch, double &distance, const PSimHit &hit, const DetId &chamberId, const edm::ESHandle< GlobalTrackingGeometry > &geometry)
Local3DPoint exitPoint() const
Exit point in the local Det frame.
T const * get() const
Returns C++ pointer to the item.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
def bestMatch(object, matchCollection)
void registerConsumes(edm::ConsumesCollector &iC)
std::vector< MuonChamberMatch > & matches()
get muon matching information
ESHandle< TrackerGeometry > geometry
const math::XYZTLorentzVectorD & momentum() const
const GeomDet * idToDet(DetId) const override
std::vector< PSimHit > PSimHitContainer
std::vector< SimTrack > SimTrackContainer
Local3DPoint entryPoint() const
Entry point in the local Det frame.
Power< A, B >::type pow(const A &a, const B &b)
unsigned int detUnitId() const
static double matchChi2(const reco::Track &recoTrk, const SimTrack &simTrk)