32 LogTrace(
"MuonIdentification") <<
"No tracks found";
40 throw cms::Exception(
"FatalError") <<
"Unable to find GlobalTrackingGeometryRecord in event!\n";
42 float bestMatchChi2 = 9999;
44 const unsigned int offset = 0;
46 for( edm::SimTrackContainer::const_iterator simTrk = simTracks->begin();
47 simTrk != simTracks->end(); simTrk++ )
50 if (chi2>bestMatchChi2)
continue;
52 bestMatch = simTrk->trackId();
58 int numberOfTruthMatchedChambers = 0;
61 for(std::vector<reco::MuonChamberMatch>::iterator chamberMatch = matches.begin();
62 chamberMatch != matches.end(); chamberMatch ++)
65 edm::LogWarning(
"MuonIdentification") <<
"Detector id of a muon chamber corresponds to not a muon detector";
75 iEvent.
getByLabel(
"g4SimHits",
"MuonDTHits", simHits);
76 if ( simHits.isValid() ) {
77 for( edm::PSimHitContainer::const_iterator
hit = simHits->begin();
hit != simHits->end();
hit++)
79 }
else LogTrace(
"MuonIdentification") <<
"No DT simulated hits are found";
83 CSCDetId detId(chamberMatch->id.rawId());
86 iEvent.
getByLabel(
"g4SimHits",
"MuonCSCHits", simHits);
87 if ( simHits.isValid() ) {
88 for( edm::PSimHitContainer::const_iterator
hit = simHits->begin();
hit != simHits->end();
hit++)
90 }
else LogTrace(
"MuonIdentification") <<
"No CSC simulated hits are found";
92 if (distance < 9999) {
93 chamberMatch->truthMatches.push_back( bestSegmentMatch );
94 numberOfTruthMatchedChambers++;
95 LogTrace(
"MuonIdentification") <<
"Best truth matched hit:" <<
96 "\tDetId: " << chamberMatch->id.rawId() <<
"\n" <<
97 "\tprojection: ( " << bestSegmentMatch.
x <<
", " << bestSegmentMatch.
y <<
" )\n";
100 LogTrace(
"MuonIdentification") <<
"Truth matching summary:\n\tnumber of chambers: " << matches.size() <<
101 "\n\tnumber of truth matched chambers: " << numberOfTruthMatchedChambers <<
"\n";
107 const DetId& chamberId,
110 printf(
"DONT FORGET TO CALL REGISTERCONSUMES()\n");
120 if (chamberGeometry && simUnitGeometry ) {
124 if ( fabs(direction.
z()) > 0.001) {
125 LocalPoint projection = entryPoint - direction*(entryPoint.z()/direction.
z());
126 if ( fabs(projection.
z()) > 0.001 )
127 edm::LogWarning(
"MuonIdentification") <<
"z coordinate of the hit projection must be zero and it's not!\n";
129 double new_distance = 99999;
130 if( entryPoint.z()*exitPoint.
z() < -1 )
133 if ( fabs(entryPoint.z()) < fabs(exitPoint.
z()) )
134 new_distance = fabs(entryPoint.z());
136 new_distance = fabs(exitPoint.
z());
139 if (new_distance < distance) {
141 segmentMatch.
x = projection.
x();
142 segmentMatch.
y = projection.
y();
143 segmentMatch.
xErr = 0;
144 segmentMatch.
yErr = 0;
145 segmentMatch.
dXdZ = direction.
x()/direction.
z();
146 segmentMatch.
dYdZ = direction.
y()/direction.
z();
149 distance = new_distance;
150 LogTrace(
"MuonIdentificationVerbose") <<
"Better truth matched segment found:\n" <<
151 "\tDetId: " << chamberId.
rawId() <<
"\n" <<
152 "\tentry point: ( " << entryPoint.x() <<
", " << entryPoint.y() <<
", " << entryPoint.z() <<
" )\n" <<
153 "\texit point: ( " << exitPoint.
x() <<
", " << exitPoint.
y() <<
", " << exitPoint.
z() <<
" )\n" <<
154 "\tprojection: ( " << projection.
x() <<
", " << projection.
y() <<
", " << projection.
z() <<
" )\n";
158 if ( ! chamberGeometry )
edm::LogWarning(
"MuonIdentification") <<
"Cannot get chamber geomtry for DetId: " << chamberId.
rawId();
159 if ( ! simUnitGeometry )
edm::LogWarning(
"MuonIdentification") <<
"Cannot get detector unit geomtry for DetId: " << hit.
detUnitId();
166 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)
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.
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.
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)