Go to the documentation of this file.00001
00017 #include "RecoMuon/GlobalTrackingTools/interface/DynamicTruncation.h"
00018 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00019 #include "TrackingTools/TrackFitters/interface/RecHitLessByDet.h"
00020 #include "RecoMuon/GlobalTrackingTools/interface/ChamberSegmentUtility.h"
00021 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00022 #include "RecoMuon/DetLayers/interface/MuonDetLayerGeometry.h"
00023 #include "RecoMuon/Records/interface/MuonRecoGeometryRecord.h"
00024 #include "RecoMuon/Navigation/interface/MuonNavigationSchool.h"
00025 #include "TrackingTools/DetLayers/interface/NavigationSetter.h"
00026 #include "RecoMuon/Navigation/interface/MuonNavigationPrinter.h"
00027 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00028 #include "RecoTracker/Record/interface/NavigationSchoolRecord.h"
00029 #include "RecoMuon/GlobalTrackingTools/interface/MuonTkNavigationSchool.h"
00030 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
00031 #include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimator.h"
00032 #include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
00033
00034
00035 #define MAX_THR 1e7
00036
00037 using namespace edm;
00038 using namespace std;
00039 using namespace reco;
00040
00041 DynamicTruncation::DynamicTruncation(const edm::Event& event, const MuonServiceProxy& theService):
00042 DTThr(0), CSCThr(0)
00043 {
00044 theEvent = &event;
00045 theSetup = &theService.eventSetup();
00046 propagator = theService.propagator("SmartPropagator");
00047 propagatorCompatibleDet = theService.propagator("SteppingHelixPropagatorAny");
00048 theG = theService.trackingGeometry();
00049 theService.eventSetup().get<TransientRecHitRecord>().get("MuonRecHitBuilder",theMuonRecHitBuilder);
00050 theService.eventSetup().get<TrackingComponentsRecord>().get("KFUpdator",updatorHandle);
00051 theService.eventSetup().get<MuonGeometryRecord>().get(cscGeom);
00052 theService.eventSetup().get<MuonRecoGeometryRecord>().get(navMuon);
00053 theService.eventSetup().get<IdealMagneticFieldRecord>().get(magfield);
00054 navigation = new DirectMuonNavigation(theService.detLayerGeometry());
00055 }
00056
00057
00058
00059 DynamicTruncation::~DynamicTruncation() {
00060 if (navigation) delete navigation;
00061 }
00062
00063
00064
00065 TransientTrackingRecHit::ConstRecHitContainer DynamicTruncation::filter(const Trajectory& traj) {
00066 result.clear();
00067
00068 std::vector<TrajectoryMeasurement> muonMeasurements = traj.measurements();
00069 TrajectoryMeasurement lastTKm = muonMeasurements.front();
00070 for (std::vector<TrajectoryMeasurement>::const_iterator imT = muonMeasurements.begin(); imT != muonMeasurements.end(); imT++ ) {
00071 if ( !(*imT).recHit()->isValid() ) continue;
00072 const TransientTrackingRecHit* hit = &(*(*imT).recHit());
00073 if (hit->geographicalId().det() == DetId::Tracker) {
00074 result.push_back((*imT).recHit());
00075 if (!(*imT).forwardPredictedState().isValid()) continue;
00076 if ((*imT).forwardPredictedState().globalPosition().mag()
00077 > lastTKm.forwardPredictedState().globalPosition().mag()) lastTKm = *imT;
00078 }
00079 }
00080
00081
00082 currentState = lastTKm.forwardPredictedState();
00083
00084
00085 update(currentState, lastTKm.recHit());
00086
00087
00088 map<int, std::vector<DetId> > detMap;
00089 compatibleDets(currentState, detMap);
00090
00091
00092 filteringAlgo(detMap);
00093
00094 return result;
00095 }
00096
00097
00098
00099 void DynamicTruncation::setThr(int bThr, int eThr) {
00100 if (bThr <= MAX_THR && bThr >= 0) DTThr = bThr;
00101 else DTThr = MAX_THR;
00102 if (eThr <= MAX_THR && eThr >= 0) CSCThr = eThr;
00103 else CSCThr = MAX_THR;
00104 }
00105
00106
00107
00108 double DynamicTruncation::getBest(std::vector<CSCSegment>& segs, TrajectoryStateOnSurface& tsos, CSCSegment& bestCSCSeg) {
00109 unsigned int i = 0;
00110 double val = MAX_THR;
00111 std::vector<CSCSegment>::size_type sz = segs.size();
00112 for (i=0; i<sz; i++) {
00113 StateSegmentMatcher estim(&tsos, &segs[i]);
00114 double tmp = estim.value();
00115 if (tmp < val) {
00116 bestCSCSeg = segs[i];
00117 val = tmp;
00118 }
00119 }
00120 return val;
00121 }
00122
00123
00124
00125 double DynamicTruncation::getBest(std::vector<DTRecSegment4D>& segs, TrajectoryStateOnSurface& tsos, DTRecSegment4D& bestDTSeg) {
00126 unsigned int i = 0;
00127 double val = MAX_THR;
00128 std::vector<DTRecSegment4D>::size_type sz = segs.size();
00129 for (i=0; i<sz; i++) {
00130 StateSegmentMatcher estim(&tsos, &segs[i]);
00131 double tmp = estim.value();
00132 if (tmp < val) {
00133 bestDTSeg = segs[i];
00134 val = tmp;
00135 }
00136 }
00137 return val;
00138 }
00139
00140
00141
00142 void DynamicTruncation::compatibleDets(TrajectoryStateOnSurface& tsos, map<int, std::vector<DetId> >& detMap) {
00143
00144
00145 MeasurementEstimator *theEstimator = new Chi2MeasurementEstimator(100, 3);
00146 std::vector<const DetLayer *> navLayers;
00147 navLayers = navigation->compatibleLayers(*(currentState.freeState()), alongMomentum);
00148 unsigned int nlayer = 0;
00149 for ( unsigned int ilayer=0; ilayer<navLayers.size(); ilayer++ ) {
00150
00151 if (navLayers[ilayer]->subDetector() == GeomDetEnumerators::RPCEndcap
00152 || navLayers[ilayer]->subDetector() == GeomDetEnumerators::RPCBarrel) continue;
00153 std::vector<DetLayer::DetWithState> comps = navLayers[ilayer]->compatibleDets(currentState,
00154 *propagatorCompatibleDet, *theEstimator);
00155
00156
00157 if (comps.size() > 0) {
00158 DetId id(comps.front().first->geographicalId().rawId());
00159 detMap[nlayer].push_back(id);
00160 }
00161 }
00162 if (theEstimator) delete theEstimator;
00163 }
00164
00165
00166
00167 void DynamicTruncation::filteringAlgo(map<int, std::vector<DetId> >& detMap) {
00168 ChamberSegmentUtility getSegs(*theEvent, *theSetup);
00169 for (unsigned int iDet = 0; iDet < detMap.size(); ++iDet) {
00170 double bestLayerValue = MAX_THR;
00171 ConstRecHitContainer layerRH;
00172 std::vector<DetId> chamber = detMap[iDet];
00173 for (unsigned int j = 0; j < chamber.size(); ++j) {
00174 DetId id = chamber[j];
00175
00176 if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::DT) {
00177 DTChamberId DTid(id);
00178
00179 std::vector<DTRecSegment4D> allDTsegs;
00180 std::map<int, std::vector<DTRecSegment4D> >::const_iterator dtIter = getSegs.getDTlist().find(DTid.station());
00181 if (dtIter != getSegs.getDTlist().end()){
00182 allDTsegs = dtIter->second;
00183 }
00184
00185 std::vector<DTRecSegment4D>::size_type sz = allDTsegs.size();
00186 for (unsigned int iSeg=0; iSeg<sz; ++iSeg) {
00187
00188
00189 TrajectoryStateOnSurface tsosdt = propagator->propagate(currentState,
00190 theG->idToDet(allDTsegs[iSeg].chamberId())->surface());
00191 if (!tsosdt.isValid()) continue;
00192
00193 std::vector<DTRecSegment4D> DTsegs;
00194 DTsegs.push_back(allDTsegs[iSeg]);
00195
00196 DTRecSegment4D bestDTSeg;
00197 double bestChamberValue = getBest(DTsegs, tsosdt, bestDTSeg);
00198 if (bestChamberValue < bestLayerValue) bestLayerValue = bestChamberValue;
00199
00200
00201 if (bestChamberValue >= DTThr || bestChamberValue > bestLayerValue) continue;
00202 layerRH.clear();
00203 std::vector<DTRecHit1D> DTrh = getSegs.getDTRHmap(bestDTSeg);
00204 for (std::vector<DTRecHit1D>::iterator it = DTrh.begin(); it != DTrh.end(); it++) {
00205 layerRH.push_back(theMuonRecHitBuilder->build(&*it));
00206 }
00207 }
00208 }
00209 if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::CSC) {
00210 CSCDetId CSCid(id);
00211
00212 std::vector<CSCSegment> allCSCsegs;
00213 std::map<int, std::vector<CSCSegment> >::const_iterator cscIter = getSegs.getCSClist().find(CSCid.station());
00214 if (cscIter != getSegs.getCSClist().end()){
00215 allCSCsegs = cscIter->second;
00216 }
00217
00218 std::vector<CSCSegment>::size_type sz = allCSCsegs.size();
00219 for (unsigned int iSeg=0; iSeg<sz; ++iSeg) {
00220
00221
00222 TrajectoryStateOnSurface tsoscsc = propagator->propagate(currentState,
00223 theG->idToDet(allCSCsegs[iSeg].cscDetId())->surface());
00224 if (!tsoscsc.isValid()) continue;
00225
00226 std::vector<CSCSegment> CSCsegs;
00227 CSCsegs.push_back(allCSCsegs[iSeg]);
00228
00229 CSCSegment bestCSCSeg;
00230 double bestChamberValue = getBest(CSCsegs, tsoscsc, bestCSCSeg);
00231 if (bestChamberValue < bestLayerValue) bestLayerValue = bestChamberValue;
00232
00233
00234 if (bestChamberValue >= CSCThr || bestChamberValue > bestLayerValue) continue;
00235 layerRH.clear();
00236
00237 std::vector<CSCRecHit2D> CSCrh = getSegs.getCSCRHmap(bestCSCSeg);
00238 for (std::vector<CSCRecHit2D>::iterator it = CSCrh.begin(); it != CSCrh.end(); ++it) {
00239 layerRH.push_back(theMuonRecHitBuilder->build(&*it));
00240 }
00241 }
00242 }
00243 }
00244
00245 if (layerRH.size() > 0) {
00246 for (ConstRecHitContainer::iterator it = layerRH.begin(); it != layerRH.end(); ++it) {
00247 result.push_back((*it));
00248 }
00249
00250
00251 layerRH = sort(layerRH);
00252
00253
00254 DetId id = layerRH.front()->geographicalId();
00255 if (id.subdetId() == MuonSubdetId::DT) updateWithDThits(layerRH);
00256 else updateWithCSChits(layerRH);
00257 }
00258 layerRH.clear();
00259 }
00260 }
00261
00262
00263
00264 void DynamicTruncation::update(TrajectoryStateOnSurface& tsos, ConstRecHitPointer rechit) {
00265 TrajectoryStateOnSurface temp = updatorHandle->update(tsos, *rechit);
00266 if (temp.isValid()) currentState = updatorHandle->update(tsos, *rechit);
00267 }
00268
00269
00270
00271 void DynamicTruncation::updateWithDThits(ConstRecHitContainer& recHits) {
00272 for (ConstRecHitContainer::const_iterator it = recHits.begin(); it != recHits.end(); ++it) {
00273 DTLayerId layid((*it)->det()->geographicalId());
00274 TrajectoryStateOnSurface temp = propagator->propagate(currentState, theG->idToDet(layid)->surface());
00275 if (temp.isValid()) currentState = updatorHandle->update(temp, **it);
00276 }
00277 }
00278
00279
00280
00281 void DynamicTruncation::updateWithCSChits(ConstRecHitContainer& recHits) {
00282 for (ConstRecHitContainer::const_iterator it = recHits.begin(); it != recHits.end(); ++it) {
00283 const CSCLayer* cscChamber = cscGeom->layer((*it)->det()->geographicalId());
00284 CSCDetId layid = cscChamber->geographicalId();
00285 TrajectoryStateOnSurface temp = propagator->propagate(currentState, theG->idToDet(layid)->surface());
00286 if (temp.isValid()) currentState = updatorHandle->update(temp, **it);
00287 }
00288 }
00289
00290
00291
00292 TransientTrackingRecHit::ConstRecHitContainer DynamicTruncation::sort(ConstRecHitContainer& recHits) {
00293 unsigned int i=0;
00294 unsigned int j=0;
00295 ConstRecHitContainer::size_type n = recHits.size();
00296 for(i=1; i<n; ++i)
00297 for(j=n-1; j>=i; --j)
00298 {
00299 if(recHits[j-1]->globalPosition().mag() > recHits[j]->globalPosition().mag())
00300 {
00301 swap (recHits[j-1],recHits[j]);
00302 }
00303 }
00304 return recHits;
00305 }
00306