19 #include "TDecompChol.h" 33 : m_recoTrack(recoTrack) {
37 std::cout <<
"BEGIN MuonResidualsFromTrack" << std::endl;
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;
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 " 182 int residualDT13IsAdded =
false;
183 int residualDT2IsAdded =
false;
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();
212 std::cout <<
" hit dimension: " <<
hit->dimension() << std::endl;
214 DetId hitId =
hit->geographicalId();
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" 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" 245 residualDT13IsAdded =
true;
251 if (residualDT13IsAdded ==
true && residualDT2IsAdded ==
true &&
chamberId.wheel() == 0 &&
254 std::cout <<
"MYMARK " << tsosX <<
" " << hitX <<
" " << tsosX - hitX <<
" " 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();
290 std::cout <<
" hit dimension: " <<
hit->dimension() << std::endl;
292 DetId hitId =
hit->geographicalId();
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;
353 <<
" sector " <<
chamberId.sector() << std::endl;
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();
385 std::cout <<
" hit dimension: " <<
hit->dimension() << std::endl;
387 DetId hitId =
hit->geographicalId();
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" 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" 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();
507 std::cout <<
" hit dimension: " <<
hit->dimension() << std::endl;
509 DetId hitId =
hit->geographicalId();
513 std::cout <<
" hit layer: " << cscDetId.layer() << std::endl;
516 <<
" x: " <<
hit->localPosition().
x() <<
" y: " <<
hit->localPosition().
y()
517 <<
" z: " <<
hit->localPosition().
z() << std::endl;
526 if (cscDetId.layer() == 0)
531 std::cout <<
"Have we seen this chamber before?";
538 std::cout <<
" This is first appearance of the CSC with hits m_csc.count() = " 548 std::cout <<
" lastTrackerTsos localPosition" 552 std::cout <<
" lastTrackerTsos globalPosition" 556 std::cout <<
" Do extrapolation from lastTrackerTsos to hit surface" << std::endl;
561 std::cout <<
" extrapolation.isValid() = " << extrapolation.
isValid() << std::endl;
565 std::cout <<
" extrapolation localPosition()" 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;
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();
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;
674 const CSCDetId cscDetId(chamberMatch->id.rawId());
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;
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;
785 result(0, 0) += r_err * r_err;
787 result(2, 2) += r_err * r_err;
791 result(0, 0) += r_err * r_err;
793 result(2, 2) += r_err * r_err;
797 result(1, 1) += r_err * r_err;
799 result(3, 3) += r_err * r_err;
802 std::cout <<
"MuonResidualsFromTrack:: cov after:" << std::endl;
809 bool m_debug =
false;
815 TDecompChol decomp(cov44);
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();
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
virtual float length() const =0
const LocalTrajectoryError & localError() const
bool hasPhi() const
Does it have the Phi projection?
LocalPoint localPosition() const
std::map< DetId, TMatrixDSym > m_trkCovMatrix
const std::string metname
static edm::ESInputTag builderESInputTag()
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
TMatrixDSym covMatrix(DetId chamberId)
bool isNonnull() const
Checks for non-null.
const reco::Muon * m_recoMuon
LocalError positionError() const
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
const GeomDet * idToDet(DetId) const override
constexpr Detector det() const
get the detector field from this detid
static const unsigned int BestInStationByDR
bool isTrackerMuon() const override
DataContainer const & measurements() const
auto recHits() const
Access to reconstructed hits on the track.
std::map< DetId, MuonChamberResidual * > m_dt2
GlobalPoint globalPosition() const
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
virtual std::vector< const TrackingRecHit * > recHits() const =0
Access to component RecHits (if any)
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
double normalizedChi2() const
TMatrixDSym corrMatrix(DetId chamberId)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
virtual TrackRef innerTrack() const
virtual const GeomDet * getGeomDet(const DetId &) const =0
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
std::vector< ConstRecHitPointer > ConstRecHitContainer
const Plane & surface() const
The nominal surface of the GeomDet.
~MuonResidualsFromTrack()
const reco::Track * m_recoTrack
DetId geographicalId() const
virtual LocalError localPositionError() const =0
constexpr uint32_t rawId() const
get the raw id
TMatrixD choleskyCorrMatrix(DetId chamberId)
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
std::vector< MuonChamberMatch > & matches()
get muon matching information
TrajectoryStateOnSurface const & updatedState() const
void addTrkCovMatrix(DetId, TrajectoryStateOnSurface &)
static const unsigned int BelongsToTrackByDR
const AlgebraicSymMatrix55 & matrix() const
T const * get() const
Returns C++ pointer to the item.
bool hasZed() const
Does it have the Z projection?
double trackerRedChi2() const
virtual LocalPoint localPosition() const =0
virtual float width() const =0
static constexpr auto TID
std::map< DetId, MuonChamberResidual * > m_dt13
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)
ConstRecHitPointer const & recHit() const
TrajectoryStateCombiner m_tsoscomb
const Bounds & bounds() const
MuonChamberResidual * chamberResidual(DetId chamberId, int type)