19 #include "TDecompChol.h"
33 : m_recoTrack(recoTrack) {
37 std::cout <<
"BEGIN MuonResidualsFromTrack" << std::endl;
39 LogTrace(metname) <<
"Tracking Component changed!";
53 std::cout <<
"Tracker Hit " << iT <<
" is found. Add to refit. Dimension: " <<
hit->dimension() << std::endl;
55 recHitsForRefit.push_back(trackerRecHitBuilder->build(&*
hit));
64 <<
" is found. We do not add muon hits to refit. Dimension: " <<
hit->dimension() << std::endl;
68 std::cout <<
"Muon Hit in DT wheel " << chamberId.wheel() <<
" station " << chamberId.station()
69 <<
" sector " << chamberId.sector() <<
"." << std::endl;
73 std::cout <<
"Muon hit in CSC endcap " << cscDetId.endcap() <<
" station " << cscDetId.station() <<
" ring "
74 << cscDetId.ring() <<
" chamber " << cscDetId.chamber() <<
"." << std::endl;
77 std::cout <<
"Muon Hit in RPC" << std::endl;
80 std::cout <<
"Warning! Muon Hit not in DT or CSC or RPC" << std::endl;
92 double lastTrackerTsosGlobalPositionR = 0.0;
94 std::vector<TrajectoryMeasurement> vTrajMeasurement = traj->
measurements();
96 std::cout <<
" Size of vector of TrajectoryMeasurements: " << vTrajMeasurement.size() << std::endl;
97 int nTrajMeasurement = 0;
98 for (std::vector<TrajectoryMeasurement>::const_iterator iTrajMeasurement = vTrajMeasurement.begin();
99 iTrajMeasurement != vTrajMeasurement.end();
100 ++iTrajMeasurement) {
103 std::cout <<
" TrajectoryMeasurement #" << nTrajMeasurement << std::endl;
113 std::cout <<
" TrajectoryMeasurement TSOS validity: " << tsos.
isValid() << std::endl;
118 std::cout <<
" TrajectoryMeasurement TSOS localPosition"
121 std::cout <<
" TrajectoryMeasurement TSOS globalPosition"
123 <<
" R: " << tsosGlobalPositionR <<
" z: " << tsos.
globalPosition().
z() << std::endl;
125 if (tsosGlobalPositionR > lastTrackerTsosGlobalPositionR) {
126 lastTrackerTsos = tsos;
127 lastTrackerTsosGlobalPositionR = tsosGlobalPositionR;
133 std::cout <<
" TrajectoryMeasurement hit validity: " << trajMeasurementHit->
isValid() << std::endl;
134 if (trajMeasurementHit->
isValid()) {
136 int trajMeasurementHitDim = trajMeasurementHit->
dimension();
139 std::cout <<
" TrajectoryMeasurement hit Det: Tracker" << std::endl;
141 std::cout <<
" TrajectoryMeasurement hit dimension: " << trajMeasurementHitDim << std::endl;
157 std::cout <<
" TrajectoryMeasurement hit Det: Muon" << std::endl;
162 std::cout <<
" TrajectoryMeasurement hit subDet: DT wheel " << chamberId.wheel() <<
" station "
163 << chamberId.station() <<
" sector " << chamberId.sector() << std::endl;
170 const GeomDet* geomDet = muonDetIdAssociator_->getGeomDet(chamberId);
182 int residualDT13IsAdded =
false;
183 int residualDT2IsAdded =
false;
188 std::cout <<
"AR: pushing back chamber: " << chamberId << std::endl;
196 std::cout <<
" TrajectoryMeasurement hit dimension: " << trajMeasurementHitDim << std::endl;
197 if (trajMeasurementHitDim > 1) {
198 std::vector<const TrackingRecHit*> vDTSeg2D = trajMeasurementHit->
recHits();
200 std::cout <<
" vDTSeg2D size: " << vDTSeg2D.size() << std::endl;
201 for (std::vector<const TrackingRecHit*>::const_iterator itDTSeg2D = vDTSeg2D.begin();
202 itDTSeg2D != vDTSeg2D.end();
204 std::vector<const TrackingRecHit*> vDTHits1D = (*itDTSeg2D)->recHits();
206 std::cout <<
" vDTHits1D size: " << vDTHits1D.size() << std::endl;
207 for (std::vector<const TrackingRecHit*>::const_iterator itDTHits1D = vDTHits1D.begin();
208 itDTHits1D != vDTHits1D.end();
218 std::cout <<
" hit superLayerId: " << superLayerId.superLayer() << std::endl;
220 std::cout <<
" hit layerId: " << layerId.layer() << std::endl;
222 if (superLayerId.superlayer() == 2 && vDTHits1D.size() >= 3) {
228 std::cout <<
" This is first appearance of the DT with hits in superlayer 2"
231 m_dt2[chamberId]->addResidual(prop, &tsos, hit, chamber_width, chamber_length);
232 residualDT2IsAdded =
true;
234 }
else if ((superLayerId.superlayer() == 1 || superLayerId.superlayer() == 3) &&
235 vDTHits1D.size() >= 6) {
241 std::cout <<
" This is first appearance of the DT with hits in superlayers 1 and 3"
244 m_dt13[chamberId]->addResidual(prop, &tsos, hit, chamber_width, chamber_length);
245 residualDT13IsAdded =
true;
251 if (residualDT13IsAdded ==
true && residualDT2IsAdded ==
true && chamberId.wheel() == 0 &&
252 chamberId.station() == 2 && chamberId.sector() == 7) {
254 std::cout <<
"MYMARK " << tsosX <<
" " << hitX <<
" " << tsosX - hitX <<
" "
255 <<
m_dt13[chamberId]->trackx() <<
" " <<
m_dt13[chamberId]->residual() <<
" " << tsosY <<
" "
256 << hitY <<
" " << tsosY - hitY <<
" " <<
m_dt2[chamberId]->tracky() <<
" "
257 <<
m_dt2[chamberId]->residual() <<
" " << tsosF.localPosition().x() <<
" "
258 << tsosF.localPosition().y() <<
" " << tsosF.localPosition().z() <<
" "
269 const CSCDetId chamberId2(cscDetId.endcap(), cscDetId.station(), cscDetId.ring(), cscDetId.chamber());
271 std::cout <<
" TrajectoryMeasurement hit subDet: CSC endcap " << cscDetId.endcap() <<
" station "
272 << cscDetId.station() <<
" ring " << cscDetId.ring() <<
" chamber " << cscDetId.chamber()
275 std::cout <<
" TrajectoryMeasurement hit dimension: " << trajMeasurementHitDim << std::endl;
277 if (trajMeasurementHitDim == 4) {
278 std::vector<const TrackingRecHit*> vCSCHits2D = trajMeasurementHit->
recHits();
280 std::cout <<
" vCSCHits2D size: " << vCSCHits2D.size() << std::endl;
281 if (vCSCHits2D.size() >= 5) {
282 for (std::vector<const TrackingRecHit*>::const_iterator itCSCHits2D = vCSCHits2D.begin();
283 itCSCHits2D != vCSCHits2D.end();
295 std::cout <<
" hit layer: " << cscDetId.layer() << std::endl;
298 if (cscDetId.layer() == 0)
309 std::cout <<
" This is first appearance of the CSC with hits QQQ" << std::endl;
312 m_csc[chamberId2]->addResidual(prop, &tsos, hit, 250.0, 250.0);
318 std::cout <<
" TrajectoryMeasurement hit subDet: UNKNOWN" << std::endl;
320 std::cout <<
"AR: trajMeasurementHitId.det(): " << trajMeasurementHitId.
subdetId() << std::endl;
324 std::cout <<
" TrajectoryMeasurement hit det: UNKNOWN" << std::endl;
326 std::cout <<
"AR: trajMeasurementHitId.det(): " << trajMeasurementHitId.
det() << std::endl;
333 int iT2 = 0, iM2 = 0;
335 if (hit2->isValid()) {
336 DetId hitId2 = hit2->geographicalId();
340 std::cout <<
"Tracker Hit " << iT2 <<
" is found. We don't calcualte Tsos for it" << std::endl;
348 std::cout <<
"Muon Hit " << iM2 <<
" is found. Dimension: " << hit2->dimension() << std::endl;
352 std::cout <<
"Muon Hit in DT wheel " << chamberId.wheel() <<
" station " << chamberId.station()
353 <<
" sector " << chamberId.sector() << std::endl;
355 const GeomDet* geomDet = muonDetIdAssociator_->getGeomDet(chamberId);
359 if (hit2->dimension() > 1) {
361 std::vector<TrackingRecHit*> vDTSeg2D = hit2->recHits();
364 std::cout <<
" vDTSeg2D size: " << vDTSeg2D.size() << std::endl;
370 for (std::vector<TrackingRecHit*>::const_iterator itDTSeg2D = vDTSeg2D.begin(); itDTSeg2D != vDTSeg2D.end();
373 std::vector<TrackingRecHit*> vDTHits1D = (*itDTSeg2D)->recHits();
375 std::cout <<
" vDTHits1D size: " << vDTHits1D.size() << std::endl;
379 for (std::vector<TrackingRecHit*>::const_iterator itDTHits1D = vDTHits1D.begin();
380 itDTHits1D != vDTHits1D.end();
391 std::cout <<
" hit superLayerId: " << superLayerId.superLayer() << std::endl;
393 std::cout <<
" hit layerId: " << layerId.layer() << std::endl;
395 if (superLayerId.superlayer() == 2 && vDTHits1D.size() >= 3) {
401 std::cout <<
" This is first appearance of the DT with hits in superlayer 2"
411 extrapolation = prop->propagate(lastTrackerTsos, globalGeometry->idToDet(hitId)->surface());
415 std::cout <<
" extrapolation localPosition()"
420 m_dt2[chamberId]->addResidual(prop, &extrapolation, hit, chamber_width, chamber_length);
424 }
else if ((superLayerId.superlayer() == 1 || superLayerId.superlayer() == 3) &&
425 vDTHits1D.size() >= 6) {
431 std::cout <<
" This is first appearance of the DT with hits in superlayers 1 and 3"
441 extrapolation = prop->propagate(lastTrackerTsos, globalGeometry->idToDet(hitId)->surface());
445 std::cout <<
" extrapolation localPosition()"
450 m_dt13[chamberId]->addResidual(prop, &extrapolation, hit, chamber_width, chamber_length);
482 const CSCDetId chamberId(cscDetId2.endcap(), cscDetId2.station(), cscDetId2.ring(), cscDetId2.chamber());
484 std::cout <<
"Muon hit in CSC endcap " << cscDetId2.endcap() <<
" station " << cscDetId2.station()
485 <<
" ring " << cscDetId2.ring() <<
" chamber " << cscDetId2.chamber() <<
"." << std::endl;
487 if (hit2->dimension() == 4) {
489 std::vector<TrackingRecHit*> vCSCHits2D = hit2->recHits();
491 std::cout <<
" vCSCHits2D size: " << vCSCHits2D.size() << std::endl;
492 if (vCSCHits2D.size() >= 5) {
497 for (std::vector<TrackingRecHit*>::const_iterator itCSCHits2D = vCSCHits2D.begin();
498 itCSCHits2D != vCSCHits2D.end();
513 std::cout <<
" hit layer: " << cscDetId.layer() << std::endl;
519 <<
" x: " << globalGeometry->idToDet(hitId)->toGlobal(hit->
localPosition()).
x()
520 <<
" y: " << globalGeometry->idToDet(hitId)->toGlobal(hit->
localPosition()).
y()
521 <<
" z: " << globalGeometry->idToDet(hitId)->toGlobal(hit->
localPosition()).
z()
526 if (cscDetId.layer() == 0)
531 std::cout <<
"Have we seen this chamber before?";
534 std::cout <<
" NO. m_csc.count() = " <<
m_csc.count(chamberId) << std::endl;
538 std::cout <<
" This is first appearance of the CSC with hits m_csc.count() = "
539 <<
m_csc.count(chamberId) << std::endl;
544 std::cout <<
" YES. m_csc.count() = " <<
m_csc.count(chamberId) << std::endl;
548 std::cout <<
" lastTrackerTsos localPosition"
552 std::cout <<
" lastTrackerTsos globalPosition"
556 std::cout <<
" Do extrapolation from lastTrackerTsos to hit surface" << std::endl;
559 extrapolation = prop->propagate(lastTrackerTsos, globalGeometry->idToDet(hitId)->surface());
561 std::cout <<
" extrapolation.isValid() = " << extrapolation.
isValid() << std::endl;
565 std::cout <<
" extrapolation localPosition()"
570 m_csc[chamberId]->addResidual(prop, &extrapolation, hit, 250.0, 250.0);
578 std::cout <<
"Muon Hit in RPC" << std::endl;
581 std::cout <<
"Warning! Muon Hit not in DT or CSC or RPC" << std::endl;
591 std::cout <<
"END MuonResidualsFromTrack" << std::endl << std::endl;
598 : m_recoMuon(recoMuon) {
599 bool m_debug =
false;
621 for (std::vector<reco::MuonChamberMatch>::const_iterator chamberMatch =
m_recoMuon->
matches().begin();
627 for (std::vector<reco::MuonSegmentMatch>::const_iterator segMatch = chamberMatch->segmentMatches.begin();
628 segMatch != chamberMatch->segmentMatches.end();
636 const DTChamberId chamberId(chamberMatch->id.rawId());
640 if (segment ==
nullptr)
643 if (segment->
hasPhi() && fabs(chamberMatch->x - segMatch->x) > maxResidual)
645 if (segment->
hasZed() && fabs(chamberMatch->y - segMatch->y) > maxResidual)
659 std::cout <<
"multi segment match to tmuon: dt2 -- should not happen!" << std::endl;
660 m_dt2[chamberId]->setSegmentResidual(&(*chamberMatch), &(*segMatch));
668 std::cout <<
"multi segment match to tmuon: dt13 -- should not happen!" << std::endl;
669 m_dt13[chamberId]->setSegmentResidual(&(*chamberMatch), &(*segMatch));
674 const CSCDetId cscDetId(chamberMatch->id.rawId());
675 const CSCDetId chamberId(cscDetId.chamberId());
677 if (fabs(chamberMatch->x - segMatch->x) > maxResidual)
687 std::cout <<
"multi segment match to tmuon: csc -- should not happen!" << std::endl;
688 m_csc[chamberId]->setSegmentResidual(&(*chamberMatch), &(*segMatch));
697 for (std::map<DetId, MuonChamberResidual*>::const_iterator residual =
m_dt13.begin(); residual !=
m_dt13.end();
699 delete residual->second;
701 for (std::map<DetId, MuonChamberResidual*>::const_iterator residual =
m_dt2.begin(); residual !=
m_dt2.end();
703 delete residual->second;
705 for (std::map<DetId, MuonChamberResidual*>::const_iterator residual =
m_csc.begin(); residual !=
m_csc.end();
707 delete residual->second;
743 return m_dt2[chamberId];
747 return m_csc[chamberId];
754 TMatrixDSym cov44(4);
756 int subs[4] = {3, 4, 1, 2};
757 for (
int i = 0;
i < 4;
i++)
758 for (
int j = 0;
j < 4;
j++)
759 cov44(
i,
j) = cov55(subs[
i], subs[
j]);
764 bool m_debug =
false;
768 std::cout <<
"MuonResidualsFromTrack:: cov initial:" << std::endl;
772 std::cout <<
"MuonResidualsFromTrack:: cov does not exist!" << std::endl;
778 std::cout <<
"MuonResidualsFromTrack:: cov before:" << std::endl;
784 r_err =
m_csc[chamberId]->residual_error();
785 result(0, 0) += r_err * r_err;
786 r_err =
m_csc[chamberId]->resslope_error();
787 result(2, 2) += r_err * r_err;
790 r_err =
m_dt13[chamberId]->residual_error();
791 result(0, 0) += r_err * r_err;
792 r_err =
m_dt13[chamberId]->resslope_error();
793 result(2, 2) += r_err * r_err;
796 r_err =
m_dt2[chamberId]->residual_error();
797 result(1, 1) += r_err * r_err;
798 r_err =
m_dt2[chamberId]->resslope_error();
799 result(3, 3) += r_err * r_err;
802 std::cout <<
"MuonResidualsFromTrack:: cov after:" << std::endl;
809 bool m_debug =
false;
812 TMatrixDSym cov44 =
covMatrix(chamberId);
815 TDecompChol decomp(cov44);
816 bool ok = decomp.Invert(result);
818 std::cout <<
"MuonResidualsFromTrack:: corr after:" << std::endl;
822 std::cout <<
"MuonResidualsFromTrack:: cov inversion failed!" << std::endl;
827 bool m_debug =
false;
833 TDecompChol decomp(corr44);
834 bool ok = decomp.Decompose();
835 result = decomp.GetU();
838 std::cout <<
"MuonResidualsFromTrack:: corr cholesky after:" << std::endl;
842 std::cout <<
"MuonResidualsFromTrack:: corr decomposition failed!" << std::endl;
std::map< DetId, MuonChamberResidual * > m_csc
static constexpr auto TEC
virtual int dimension() const =0
std::vector< DetId > m_chamberIds
bool isNonnull() const
Checks for non-null.
virtual float length() const =0
ConstRecHitPointer const & recHit() const
std::map< DetId, TMatrixDSym > m_trkCovMatrix
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
virtual TrackRef innerTrack() const
const std::string metname
static edm::ESInputTag builderESInputTag()
LocalPoint localPosition() const
constexpr uint32_t rawId() const
get the raw id
TMatrixDSym covMatrix(DetId chamberId)
GlobalPoint globalPosition() const
const Bounds & bounds() const
const reco::Muon * m_recoMuon
const Plane & surface() const
The nominal surface of the GeomDet.
LocalError positionError() const
static const unsigned int BestInStationByDR
bool isTrackerMuon() const override
DataContainer const & measurements() const
std::map< DetId, MuonChamberResidual * > m_dt2
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
virtual std::vector< const TrackingRecHit * > recHits() const =0
Access to component RecHits (if any)
auto recHits() const
Access to reconstructed hits on the track.
TMatrixDSym corrMatrix(DetId chamberId)
const AlgebraicSymMatrix55 & matrix() const
T const * get() const
Returns C++ pointer to the item.
bool hasPhi() const
Does it have the Phi projection?
const LocalTrajectoryError & localError() const
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
std::vector< ConstRecHitPointer > ConstRecHitContainer
double normalizedChi2() const
bool hasZed() const
Does it have the Z projection?
~MuonResidualsFromTrack()
const reco::Track * m_recoTrack
virtual LocalError localPositionError() const =0
TMatrixD choleskyCorrMatrix(DetId chamberId)
double trackerRedChi2() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
std::vector< MuonChamberMatch > & matches()
get muon matching information
void addTrkCovMatrix(DetId, TrajectoryStateOnSurface &)
static const unsigned int BelongsToTrackByDR
TrajectoryStateOnSurface const & updatedState() const
DetId geographicalId() const
virtual LocalPoint localPosition() const =0
virtual float width() const =0
static constexpr auto TID
std::map< DetId, MuonChamberResidual * > m_dt13
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
MuonResidualsFromTrack(edm::ESHandle< TransientTrackingRecHitBuilder > builder, edm::ESHandle< MagneticField > magneticField, edm::ESHandle< GlobalTrackingGeometry > globalGeometry, edm::ESHandle< DetIdAssociator > muonDetIdAssociator_, edm::ESHandle< Propagator > prop, const Trajectory *traj, const reco::Track *recoTrack, AlignableNavigator *navigator, double maxResidual)
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
TrajectoryStateCombiner m_tsoscomb
constexpr Detector det() const
get the detector field from this detid
MuonChamberResidual * chamberResidual(DetId chamberId, int type)