22 LogTrace(
"MuonIdentification") <<
"No tracks found";
30 throw cms::Exception(
"FatalError") <<
"Unable to find GlobalTrackingGeometryRecord in event!\n";
32 float bestMatchChi2 = 9999;
33 unsigned int bestMatch = 0;
34 const unsigned int offset = 0;
36 for( edm::SimTrackContainer::const_iterator simTrk = simTracks->begin();
37 simTrk != simTracks->end(); simTrk++ )
40 if (chi2>bestMatchChi2)
continue;
42 bestMatch = simTrk->trackId();
47 std::vector<reco::MuonChamberMatch>& matches = aMuon.
matches();
48 int numberOfTruthMatchedChambers = 0;
51 for(std::vector<reco::MuonChamberMatch>::iterator chamberMatch = matches.begin();
52 chamberMatch != matches.end(); chamberMatch ++)
55 edm::LogWarning(
"MuonIdentification") <<
"Detector id of a muon chamber corresponds to not a muon detector";
59 double distance = 99999;
65 iEvent.
getByLabel(
"g4SimHits",
"MuonDTHits", simHits);
66 if ( simHits.isValid() ) {
67 for( edm::PSimHitContainer::const_iterator
hit = simHits->begin();
hit != simHits->end();
hit++)
69 }
else LogTrace(
"MuonIdentification") <<
"No DT simulated hits are found";
73 CSCDetId detId(chamberMatch->id.rawId());
76 iEvent.
getByLabel(
"g4SimHits",
"MuonCSCHits", simHits);
77 if ( simHits.isValid() ) {
78 for( edm::PSimHitContainer::const_iterator
hit = simHits->begin();
hit != simHits->end();
hit++)
80 }
else LogTrace(
"MuonIdentification") <<
"No CSC simulated hits are found";
82 if (distance < 9999) {
83 chamberMatch->truthMatches.push_back( bestSegmentMatch );
84 numberOfTruthMatchedChambers++;
85 LogTrace(
"MuonIdentification") <<
"Best truth matched hit:" <<
86 "\tDetId: " << chamberMatch->id.rawId() <<
"\n" <<
87 "\tprojection: ( " << bestSegmentMatch.
x <<
", " << bestSegmentMatch.
y <<
" )\n";
90 LogTrace(
"MuonIdentification") <<
"Truth matching summary:\n\tnumber of chambers: " << matches.size() <<
91 "\n\tnumber of truth matched chambers: " << numberOfTruthMatchedChambers <<
"\n";
97 const DetId& chamberId,
105 const GeomDet* chamberGeometry = geometry->idToDet( chamberId );
108 if (chamberGeometry && simUnitGeometry ) {
112 if ( fabs(direction.
z()) > 0.001) {
113 LocalPoint projection = entryPoint - direction*(entryPoint.z()/direction.
z());
114 if ( fabs(projection.
z()) > 0.001 )
115 edm::LogWarning(
"MuonIdentification") <<
"z coordinate of the hit projection must be zero and it's not!\n";
117 double new_distance = 99999;
118 if( entryPoint.z()*exitPoint.
z() < -1 )
121 if ( fabs(entryPoint.z()) < fabs(exitPoint.
z()) )
122 new_distance = fabs(entryPoint.z());
124 new_distance = fabs(exitPoint.
z());
127 if (new_distance < distance) {
129 segmentMatch.
x = projection.
x();
130 segmentMatch.
y = projection.
y();
131 segmentMatch.
xErr = 0;
132 segmentMatch.
yErr = 0;
133 segmentMatch.
dXdZ = direction.
x()/direction.
z();
134 segmentMatch.
dYdZ = direction.
y()/direction.
z();
137 distance = new_distance;
138 LogTrace(
"MuonIdentificationVerbose") <<
"Better truth matched segment found:\n" <<
139 "\tDetId: " << chamberId.
rawId() <<
"\n" <<
140 "\tentry point: ( " << entryPoint.x() <<
", " << entryPoint.y() <<
", " << entryPoint.z() <<
" )\n" <<
141 "\texit point: ( " << exitPoint.
x() <<
", " << exitPoint.
y() <<
", " << exitPoint.
z() <<
" )\n" <<
142 "\tprojection: ( " << projection.
x() <<
", " << projection.
y() <<
", " << projection.
z() <<
" )\n";
146 if ( ! chamberGeometry )
edm::LogWarning(
"MuonIdentification") <<
"Cannot get chamber geomtry for DetId: " << chamberId.
rawId();
147 if ( ! simUnitGeometry )
edm::LogWarning(
"MuonIdentification") <<
"Cannot get detector unit geomtry for DetId: " << hit.
detUnitId();
154 if (deltaPhi>1.8*3.1416) deltaPhi = 2*3.1416-
deltaPhi;
double p() const
momentum vector magnitude
static void truthMatchMuon(const edm::Event &iEvent, const edm::EventSetup &iSetup, reco::Muon &aMuon)
double theta() const
polar angle
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
virtual TrackRef track() const
reference to a Track
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)
uint32_t rawId() const
get the raw id
Local3DPoint exitPoint() const
Exit point in the local Det frame.
unsigned int offset(bool)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
std::vector< MuonChamberMatch > & matches()
get muon matching information
ESHandle< TrackerGeometry > geometry
const math::XYZTLorentzVectorD & momentum() const
particle info...
T const * get() const
Returns C++ pointer to the item.
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)