File indexing completed on 2024-04-06 12:27:19
0001
0002
0003
0004
0005 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
0006 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0007
0008 #include "DataFormats/GeometryCommonDetAlgo/interface/ErrorFrameTransformer.h"
0009 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
0010 #include "DataFormats/GeometryCommonDetAlgo/interface/AlignmentPositionError.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012
0013 #include "FWCore/Utilities/interface/Exception.h"
0014
0015 #include <map>
0016
0017 typedef MuonTransientTrackingRecHit::MuonRecHitPointer MuonRecHitPointer;
0018 typedef MuonTransientTrackingRecHit::RecHitContainer MuonRecHitContainer;
0019
0020 MuonTransientTrackingRecHit::MuonTransientTrackingRecHit(const GeomDet* geom, const TrackingRecHit* rh)
0021 : GenericTransientTrackingRecHit(*geom, *rh) {}
0022
0023 MuonTransientTrackingRecHit::MuonTransientTrackingRecHit(const MuonTransientTrackingRecHit& other)
0024 : GenericTransientTrackingRecHit(*other.det(), *(other.hit())) {}
0025
0026 LocalVector MuonTransientTrackingRecHit::localDirection() const {
0027 if (dynamic_cast<const RecSegment*>(hit()))
0028 return dynamic_cast<const RecSegment*>(hit())->localDirection();
0029 else
0030 return LocalVector(0., 0., 0.);
0031 }
0032
0033 LocalError MuonTransientTrackingRecHit::localDirectionError() const {
0034 if (dynamic_cast<const RecSegment*>(hit()))
0035 return dynamic_cast<const RecSegment*>(hit())->localDirectionError();
0036 else
0037 return LocalError(0., 0., 0.);
0038 }
0039
0040 GlobalVector MuonTransientTrackingRecHit::globalDirection() const {
0041 return (det()->surface().toGlobal(localDirection()));
0042 }
0043
0044 GlobalError MuonTransientTrackingRecHit::globalDirectionError() const {
0045 return ErrorFrameTransformer().transform(localDirectionError(), (det()->surface()));
0046 }
0047
0048 AlgebraicSymMatrix MuonTransientTrackingRecHit::parametersError() const {
0049 AlgebraicSymMatrix err = GenericTransientTrackingRecHit::parametersError();
0050 AlgebraicVector par = GenericTransientTrackingRecHit::parameters();
0051
0052 const AlignmentPositionError* APE = det()->alignmentPositionError();
0053 if (APE != nullptr) {
0054 AlgebraicVector positions(2, 0);
0055 AlgebraicVector directions(2, 0);
0056
0057 if (err.num_row() == 1) {
0058 positions[0] = 0.;
0059 positions[1] = 0.;
0060 directions[0] = 0.;
0061 directions[1] = 0.;
0062 LocalErrorExtended lape = ErrorFrameTransformer().transform46(APE->globalError(), positions, directions);
0063 err[0][0] += lape.cxx();
0064 } else if (err.num_row() == 2) {
0065 positions[0] = localPosition().x();
0066 positions[1] = 0.;
0067 directions[0] = 0.;
0068 directions[1] = 0.;
0069 LocalErrorExtended lape = ErrorFrameTransformer().transform46(APE->globalError(), positions, directions);
0070
0071 AlgebraicSymMatrix lapeMatrix(2, 0);
0072 lapeMatrix[1][1] = lape.cxx();
0073 lapeMatrix[0][0] = lape.cphixphix();
0074 lapeMatrix[0][1] = lape.cphixx();
0075
0076 if (err.num_row() != lapeMatrix.num_row())
0077 throw cms::Exception("MuonTransientTrackingRecHit::parametersError")
0078 << "Discrepancy between alignment error matrix and error matrix: APE " << lapeMatrix.num_row()
0079 << ", error matrix " << err.num_row() << std::endl;
0080
0081 err += lapeMatrix;
0082 } else if (err.num_row() == 4) {
0083 positions[0] = par[2];
0084 positions[1] = par[3];
0085 directions[0] = par[0];
0086 directions[1] = par[1];
0087
0088 LocalErrorExtended lape = ErrorFrameTransformer().transform46(APE->globalError(), positions, directions);
0089
0090 AlgebraicSymMatrix lapeMatrix(4, 0);
0091 lapeMatrix[2][2] = lape.cxx();
0092 lapeMatrix[2][3] = lape.cyx();
0093 lapeMatrix[3][3] = lape.cyy();
0094 lapeMatrix[0][0] = lape.cphixphix();
0095 lapeMatrix[0][1] = lape.cphiyphix();
0096 lapeMatrix[1][1] = lape.cphiyphiy();
0097
0098 lapeMatrix[0][2] = lape.cphixx();
0099 lapeMatrix[0][3] = lape.cphixy();
0100 lapeMatrix[1][3] = lape.cphiyy();
0101 lapeMatrix[1][2] = lape.cphiyx();
0102
0103 if (err.num_row() != lapeMatrix.num_row())
0104 throw cms::Exception("MuonTransientTrackingRecHit::parametersError")
0105 << "Discrepancy between alignment error matrix and error matrix: APE " << lapeMatrix.num_row()
0106 << ", error matrix " << err.num_row() << std::endl;
0107
0108 err += lapeMatrix;
0109 }
0110 }
0111 return err;
0112 }
0113
0114 double MuonTransientTrackingRecHit::chi2() const {
0115 if (dynamic_cast<const RecSegment*>(hit()))
0116 return dynamic_cast<const RecSegment*>(hit())->chi2();
0117 else
0118 return 0.;
0119 }
0120
0121 int MuonTransientTrackingRecHit::degreesOfFreedom() const {
0122 if (dynamic_cast<const RecSegment*>(hit()))
0123 return dynamic_cast<const RecSegment*>(hit())->degreesOfFreedom();
0124 else
0125 return 0;
0126 }
0127
0128 bool MuonTransientTrackingRecHit::isDT() const { return (geographicalId().subdetId() == MuonSubdetId::DT); }
0129
0130 bool MuonTransientTrackingRecHit::isCSC() const { return (geographicalId().subdetId() == MuonSubdetId::CSC); }
0131
0132 bool MuonTransientTrackingRecHit::isGEM() const { return (geographicalId().subdetId() == MuonSubdetId::GEM); }
0133
0134 bool MuonTransientTrackingRecHit::isME0() const { return (geographicalId().subdetId() == MuonSubdetId::ME0); }
0135
0136 bool MuonTransientTrackingRecHit::isRPC() const { return (geographicalId().subdetId() == MuonSubdetId::RPC); }
0137
0138
0139
0140 TransientTrackingRecHit::ConstRecHitContainer MuonTransientTrackingRecHit::transientHits() const {
0141 ConstRecHitContainer theSubTransientRecHits;
0142
0143
0144 std::vector<const TrackingRecHit*> ownRecHits = recHits();
0145
0146 if (ownRecHits.empty()) {
0147 theSubTransientRecHits.push_back(TransientTrackingRecHit::RecHitPointer(clone()));
0148 return theSubTransientRecHits;
0149 }
0150
0151
0152 std::vector<const GeomDet*> geomDets = det()->components();
0153
0154 if (isDT() && dimension() == 2 && ownRecHits.front()->dimension() == 1 &&
0155 (geomDets.size() == 3 || geomDets.size() == 2)) {
0156
0157 std::vector<const GeomDet*> subGeomDets;
0158
0159 int sl = 1;
0160 for (std::vector<const GeomDet*>::const_iterator geoDet = geomDets.begin(); geoDet != geomDets.end(); ++geoDet) {
0161 if (sl != 3) {
0162 std::vector<const GeomDet*> tmp = (*geoDet)->components();
0163 std::copy(tmp.begin(), tmp.end(), back_inserter(subGeomDets));
0164 }
0165 ++sl;
0166 }
0167 geomDets.clear();
0168 geomDets = subGeomDets;
0169 }
0170
0171
0172 std::map<DetId, const GeomDet*> gemDetMap;
0173
0174 for (std::vector<const GeomDet*>::const_iterator subDet = geomDets.begin(); subDet != geomDets.end(); ++subDet)
0175 gemDetMap[(*subDet)->geographicalId()] = *subDet;
0176
0177 std::map<DetId, const GeomDet*>::iterator gemDetMap_iter;
0178
0179
0180 for (std::vector<const TrackingRecHit*>::const_iterator rechit = ownRecHits.begin(); rechit != ownRecHits.end();
0181 ++rechit) {
0182 gemDetMap_iter = gemDetMap.find((*rechit)->geographicalId());
0183
0184 if (gemDetMap_iter != gemDetMap.end())
0185 theSubTransientRecHits.push_back(
0186 TransientTrackingRecHit::RecHitPointer(new MuonTransientTrackingRecHit(gemDetMap_iter->second, *rechit)));
0187 else if ((*rechit)->geographicalId() == det()->geographicalId())
0188 theSubTransientRecHits.push_back(
0189 TransientTrackingRecHit::RecHitPointer(new MuonTransientTrackingRecHit(det(), *rechit)));
0190 }
0191 return theSubTransientRecHits;
0192 }
0193
0194 void MuonTransientTrackingRecHit::invalidateHit() {
0195 setType(bad);
0196 trackingRecHit_->setType(bad);
0197
0198 if (isDT()) {
0199 if (dimension() > 1) {
0200 std::vector<TrackingRecHit*> seg2D = recHits();
0201
0202 for (std::vector<TrackingRecHit*>::iterator it = seg2D.begin(); it != seg2D.end(); ++it) {
0203 std::vector<TrackingRecHit*> hits1D = (*it)->recHits();
0204 (*it)->setType(bad);
0205 for (std::vector<TrackingRecHit*>::iterator it2 = hits1D.begin(); it2 != hits1D.end(); ++it2)
0206 (*it2)->setType(bad);
0207 }
0208 }
0209 } else if (isCSC())
0210 if (dimension() == 4) {
0211 std::vector<TrackingRecHit*> hits = recHits();
0212 for (std::vector<TrackingRecHit*>::iterator it = hits.begin(); it != hits.end(); ++it)
0213 (*it)->setType(bad);
0214 }
0215 }