CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DynamicTruncation.cc
Go to the documentation of this file.
1 
35 
44 
45 
46 #define MAX_THR 1e7
47 
48 using namespace edm;
49 using namespace std;
50 using namespace reco;
51 
53  DTThr(0), CSCThr(0)
54 {
55  theEvent = &event;
56  theSetup = &theService.eventSetup();
57  propagator = theService.propagator("SmartPropagator");
58  propagatorCompatibleDet = theService.propagator("SteppingHelixPropagatorAny");
59  theG = theService.trackingGeometry();
60  theService.eventSetup().get<TransientRecHitRecord>().get("MuonRecHitBuilder",theMuonRecHitBuilder);
61  theService.eventSetup().get<TrackingComponentsRecord>().get("KFUpdator",updatorHandle);
62  theService.eventSetup().get<MuonGeometryRecord>().get(cscGeom);
63  theService.eventSetup().get<MuonRecoGeometryRecord>().get(navMuon);
64  theService.eventSetup().get<IdealMagneticFieldRecord>().get(magfield);
65  navigation = new DirectMuonNavigation(theService.detLayerGeometry());
66 }
67 
68 
69 
71  if (navigation) delete navigation;
72 }
73 
74 
75 
77  result.clear();
78 
79  // Fill the map with the APE chamber by chamber (DT)
80  // IT ALSO WORKS IF APE IS 0
81  edm::ESHandle<AlignmentErrors> dtAlignmentErrors;
82  theSetup->get<DTAlignmentErrorRcd>().get( dtAlignmentErrors );
83  for ( std::vector<AlignTransformError>::const_iterator it = dtAlignmentErrors->m_alignError.begin();
84  it != dtAlignmentErrors->m_alignError.end(); it++ ) {
85  CLHEP::HepSymMatrix error = (*it).matrix();
86  GlobalError glbErr(error[0][0], error[1][0], error[1][1], error[2][0], error[2][1], error[2][2]);
87  DTChamberId DTid((*it).rawId());
88  dtApeMap.insert( pair<DTChamberId, GlobalError> (DTid, glbErr) );
89  }
90 
91  // Fill the map with the APE chamber by chamber (CSC)
92  // IT ALSO WORKS IF APE IS 0
93  edm::ESHandle<AlignmentErrors> cscAlignmentErrors;
94  theSetup->get<CSCAlignmentErrorRcd>().get( cscAlignmentErrors );
95  for ( std::vector<AlignTransformError>::const_iterator it = cscAlignmentErrors->m_alignError.begin();
96  it != cscAlignmentErrors->m_alignError.end(); it++ ) {
97  CLHEP::HepSymMatrix error = (*it).matrix();
98  GlobalError glbErr(error[0][0], error[1][0], error[1][1], error[2][0], error[2][1], error[2][2]);
99  CSCDetId CSCid((*it).rawId());
100  cscApeMap.insert( pair<CSCDetId, GlobalError> (CSCid, glbErr) );
101  }
102 
103  // Put the tracker hits in the final vector and get the last tracker valid measure
104  std::vector<TrajectoryMeasurement> muonMeasurements = traj.measurements();
105  TrajectoryMeasurement lastTKm = muonMeasurements.front();
106  for (std::vector<TrajectoryMeasurement>::const_iterator imT = muonMeasurements.begin(); imT != muonMeasurements.end(); imT++ ) {
107  if ( !(*imT).recHit()->isValid() ) continue;
108  const TransientTrackingRecHit* hit = &(*(*imT).recHit());
109  if (hit->geographicalId().det() == DetId::Tracker) {
110  result.push_back((*imT).recHit());
111  if (!(*imT).forwardPredictedState().isValid()) continue;
112  if ((*imT).forwardPredictedState().globalPosition().mag()
113  > lastTKm.forwardPredictedState().globalPosition().mag()) lastTKm = *imT;
114  }
115  }
116 
117  // get the last (forward) predicted state for the tracker
119 
120  // update the state with the last tracker measure
121  update(currentState, lastTKm.recHit());
122 
123  // use the navigation to get the list of compatible dets
124  map<int, std::vector<DetId> > detMap;
125  compatibleDets(currentState, detMap);
126 
127  // selects the muon hits for the final refit
128  filteringAlgo(detMap);
129 
130  return result;
131 }
132 
133 
134 
135 void DynamicTruncation::setThr(int bThr, int eThr) {
136  if (bThr <= MAX_THR && bThr >= 0) DTThr = bThr; // DT thr
137  else DTThr = MAX_THR;
138  if (eThr <= MAX_THR && eThr >= 0) CSCThr = eThr; // CSC thr
139  else CSCThr = MAX_THR;
140 }
141 
142 
143 
144 double DynamicTruncation::getBest(std::vector<CSCSegment>& segs, TrajectoryStateOnSurface& tsos, CSCSegment& bestCSCSeg) {
145  unsigned int i = 0;
146  double val = MAX_THR;
147  std::vector<CSCSegment>::size_type sz = segs.size();
148  for (i=0; i<sz; i++) {
149  LocalError apeLoc; //default constructor is all zeroes, OK
150  apeLoc = ErrorFrameTransformer().transform(cscApeMap.find(segs[i].cscDetId())->second, theG->idToDet(segs[i].cscDetId())->surface());
151  StateSegmentMatcher estim(&tsos, &segs[i], &apeLoc);
152  double tmp = estim.value();
153  if (tmp < val) {
154  bestCSCSeg = segs[i];
155  val = tmp;
156  }
157  }
158  return val;
159 }
160 
161 
162 
163 double DynamicTruncation::getBest(std::vector<DTRecSegment4D>& segs, TrajectoryStateOnSurface& tsos, DTRecSegment4D& bestDTSeg) {
164  unsigned int i = 0;
165  double val = MAX_THR;
167  for (i=0; i<sz; i++) {
168  LocalError apeLoc; //default constructor is all zeroes, OK
169  apeLoc = ErrorFrameTransformer().transform(dtApeMap.find(segs[i].chamberId())->second, theG->idToDet(segs[i].chamberId())->surface());
170  StateSegmentMatcher estim(&tsos, &segs[i], &apeLoc);
171  double tmp = estim.value();
172  if (tmp < val) {
173  bestDTSeg = segs[i];
174  val = tmp;
175  }
176  }
177  return val;
178 }
179 
180 
181 
182 void DynamicTruncation::compatibleDets(TrajectoryStateOnSurface& tsos, map<int, std::vector<DetId> >& detMap) {
183  // SteppingHelixPropagator prop(magfield.product(), anyDirection);
184  // MuonPatternRecoDumper dumper;
185  MeasurementEstimator *theEstimator = new Chi2MeasurementEstimator(100, 3);
186  std::vector<const DetLayer *> navLayers;
188  for ( unsigned int ilayer=0; ilayer<navLayers.size(); ilayer++ ) {
189  // Skip RPC layers
190  if (navLayers[ilayer]->subDetector() == GeomDetEnumerators::RPCEndcap
191  || navLayers[ilayer]->subDetector() == GeomDetEnumerators::RPCBarrel) continue;
192  std::vector<DetLayer::DetWithState> comps = navLayers[ilayer]->compatibleDets(currentState,
193  *propagatorCompatibleDet, *theEstimator);
194  // cout << comps.size() << " compatible Dets with " << navLayers[ilayer]->subDetector() << " Layer " << ilayer << " "
195  // << dumper.dumpLayer(navLayers[ilayer]) << " " << endl;
196  if (comps.size() > 0) {
197  for ( unsigned int icomp=0; icomp<comps.size(); icomp++ ) {
198  DetId id(comps[icomp].first->geographicalId().rawId());
199  detMap[ilayer].push_back(id);
200  }
201  }
202  }
203  if (theEstimator) delete theEstimator;
204 }
205 
206 
207 
208 void DynamicTruncation::filteringAlgo(map<int, std::vector<DetId> >& detMap) {
210  for (unsigned int iDet = 0; iDet < detMap.size(); ++iDet) {
211  double bestLayerValue = MAX_THR;
212  bool isDTorCSC = false;
213  ConstRecHitContainer layerRH;
214  std::vector<DetId> chamber = detMap[iDet];
215  for (unsigned int j = 0; j < chamber.size(); ++j) {
216  DetId id = chamber[j];
217 
218  if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::DT) {
219  isDTorCSC = true;
220 
221  DTChamberId DTid(id);
222 
223  std::vector<DTRecSegment4D> allDTsegs;
224  std::map<int, std::vector<DTRecSegment4D> >::const_iterator dtIter = getSegs.getDTlist().find(DTid.station());
225  if (dtIter != getSegs.getDTlist().end()){
226  allDTsegs = dtIter->second;
227  }
228  std::vector<DTRecSegment4D>::size_type sz = allDTsegs.size();
229  for (unsigned int iSeg=0; iSeg<sz; ++iSeg) {
230 
231  // Propagate the state to the current chamber
232  TrajectoryStateOnSurface tsosdt = propagator->propagate(currentState,
233  theG->idToDet(allDTsegs[iSeg].chamberId())->surface());
234  if (!tsosdt.isValid()) continue;
235 
236  std::vector<DTRecSegment4D> DTsegs;
237  DTsegs.push_back(allDTsegs[iSeg]);
238 
239  DTRecSegment4D bestDTSeg;
240  double bestChamberValue = getBest(DTsegs, tsosdt, bestDTSeg);
241  if (bestChamberValue < bestLayerValue) bestLayerValue = bestChamberValue;
242 
243  // Check if the best estimator value is below the THR and then get the RH componing the segment
244  if (bestChamberValue >= DTThr || bestChamberValue > bestLayerValue) continue;
245  layerRH.clear();
246  std::vector<DTRecHit1D> DTrh = getSegs.getDTRHmap(bestDTSeg);
247  for (std::vector<DTRecHit1D>::iterator it = DTrh.begin(); it != DTrh.end(); it++) {
248  layerRH.push_back(theMuonRecHitBuilder->build(&*it));
249  }
250  }
251  }
252  if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::CSC) {
253  isDTorCSC = true;
254  CSCDetId CSCid(id);
255 
256  std::vector<CSCSegment> allCSCsegs;
257  std::map<int, std::vector<CSCSegment> >::const_iterator cscIter = getSegs.getCSClist().find(CSCid.station());
258  if (cscIter != getSegs.getCSClist().end()){
259  allCSCsegs = cscIter->second;
260  }
261 
262  std::vector<CSCSegment>::size_type sz = allCSCsegs.size();
263  for (unsigned int iSeg=0; iSeg<sz; ++iSeg) {
264 
265  // Propagate the state to the current chamber
266  TrajectoryStateOnSurface tsoscsc = propagator->propagate(currentState,
267  theG->idToDet(allCSCsegs[iSeg].cscDetId())->surface());
268  if (!tsoscsc.isValid()) continue;
269 
270  std::vector<CSCSegment> CSCsegs;
271  CSCsegs.push_back(allCSCsegs[iSeg]);
272 
273  CSCSegment bestCSCSeg;
274  double bestChamberValue = getBest(CSCsegs, tsoscsc, bestCSCSeg);
275  if (bestChamberValue < bestLayerValue) bestLayerValue = bestChamberValue;
276 
277  // Check if the best estimator value is below the THR and then get the RH componing the segment
278  if (bestChamberValue >= CSCThr || bestChamberValue > bestLayerValue) continue;
279  layerRH.clear();
280  std::vector<CSCRecHit2D> CSCrh = getSegs.getCSCRHmap(bestCSCSeg);
281  for (std::vector<CSCRecHit2D>::iterator it = CSCrh.begin(); it != CSCrh.end(); ++it) {
282  layerRH.push_back(theMuonRecHitBuilder->build(&*it));
283  }
284  }
285  }
286  }
287 
288  if (isDTorCSC) {
289  if (bestLayerValue < MAX_THR) estimators.push_back(bestLayerValue);
290  else estimators.push_back(-1);
291  }
292 
293  if (layerRH.size() > 0) {
294  for (ConstRecHitContainer::iterator it = layerRH.begin(); it != layerRH.end(); ++it) {
295  result.push_back((*it));
296  }
297 
298  // sort the vector
299  layerRH = sort(layerRH);
300 
301  // update the currentState using all rh
302  DetId id = layerRH.front()->geographicalId();
303  if (id.subdetId() == MuonSubdetId::DT) updateWithDThits(layerRH);
304  else updateWithCSChits(layerRH);
305  }
306  layerRH.clear();
307  }
308 }
309 
310 
311 
313  TrajectoryStateOnSurface temp = updatorHandle->update(tsos, *rechit);
314  if (temp.isValid()) currentState = updatorHandle->update(tsos, *rechit);
315 }
316 
317 
318 
320  for (ConstRecHitContainer::const_iterator it = recHits.begin(); it != recHits.end(); ++it) {
321  DTLayerId layid((*it)->det()->geographicalId());
322  TrajectoryStateOnSurface temp = propagator->propagate(currentState, theG->idToDet(layid)->surface());
323  if (temp.isValid()) currentState = updatorHandle->update(temp, **it);
324  }
325 }
326 
327 
328 
330  for (ConstRecHitContainer::const_iterator it = recHits.begin(); it != recHits.end(); ++it) {
331  const CSCLayer* cscChamber = cscGeom->layer((*it)->det()->geographicalId());
332  CSCDetId layid = cscChamber->geographicalId();
333  TrajectoryStateOnSurface temp = propagator->propagate(currentState, theG->idToDet(layid)->surface());
334  if (temp.isValid()) currentState = updatorHandle->update(temp, **it);
335  }
336 }
337 
338 
339 
341  unsigned int i=0;
342  unsigned int j=0;
343  ConstRecHitContainer::size_type n = recHits.size();
344  for(i=1; i<n; ++i)
345  for(j=n-1; j>=i; --j)
346  {
347  if(recHits[j-1]->globalPosition().mag() > recHits[j]->globalPosition().mag())
348  {
349  swap (recHits[j-1],recHits[j]);
350  }
351  }
352  return recHits;
353 }
354 
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:70
DirectMuonNavigation * navigation
static GlobalError transform(const LocalError &le, const Surface &surf)
int i
Definition: DBlmapReader.cc:9
void compatibleDets(TrajectoryStateOnSurface &, std::map< int, std::vector< DetId > > &)
TrajectoryStateOnSurface currentState
edm::ESHandle< Propagator > propagatorCompatibleDet
std::vector< double > estimators
TrajectoryStateOnSurface forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
GlobalPoint globalPosition() const
ConstRecHitPointer recHit() const
std::vector< CSCRecHit2D > getCSCRHmap(CSCSegment)
uint16_t size_type
std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
U second(std::pair< T, U > const &p)
DataContainer const & measurements() const
Definition: Trajectory.h:203
void filteringAlgo(std::map< int, std::vector< DetId > > &)
static const int CSC
Definition: MuonSubdetId.h:15
T mag() const
Definition: PV3DBase.h:66
std::vector< DTRecHit1D > getDTRHmap(DTRecSegment4D)
edm::ESHandle< MuonDetLayerGeometry > navMuon
const std::map< int, std::vector< CSCSegment > > & getCSClist() const
ConstRecHitContainer result
FreeTrajectoryState * freeState(bool withErrors=true) const
const edm::EventSetup * theSetup
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
double getBest(std::vector< CSCSegment > &, TrajectoryStateOnSurface &, CSCSegment &)
int j
Definition: DBlmapReader.cc:9
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:72
edm::ESHandle< TrajectoryStateUpdator > updatorHandle
TransientTrackingRecHit::ConstRecHitContainer filter(const Trajectory &)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool first
Definition: L1TdeRCT.cc:94
const edm::Event * theEvent
edm::ESHandle< TransientTrackingRecHitBuilder > theMuonRecHitBuilder
#define MAX_THR
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: DetId.h:20
std::map< DTChamberId, GlobalError > dtApeMap
DynamicTruncation(const edm::Event &, const MuonServiceProxy &)
const T & get() const
Definition: EventSetup.h:55
void update(TrajectoryStateOnSurface &, ConstRecHitPointer)
ConstRecHitContainer sort(ConstRecHitContainer &)
edm::ESHandle< Propagator > propagator
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
void setThr(int, int)
const std::map< int, std::vector< DTRecSegment4D > > & getDTlist() const
void updateWithDThits(ConstRecHitContainer &)
void updateWithCSChits(ConstRecHitContainer &)
int station() const
Definition: CSCDetId.h:88
static const int DT
Definition: MuonSubdetId.h:14
DetId geographicalId() const
int station() const
Return the station number.
Definition: DTChamberId.h:53
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
edm::ESHandle< MagneticField > magfield
std::map< CSCDetId, GlobalError > cscApeMap
edm::ESHandle< GlobalTrackingGeometry > theG
edm::ESHandle< CSCGeometry > cscGeom