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 
30 
39 
40 
41 #define MAX_THR 1e7
42 
43 using namespace edm;
44 using namespace std;
45 using namespace reco;
46 
48  DTThr(0), CSCThr(0), useAPE(false)
49 {
50  theEvent = &event;
51  theSetup = &theService.eventSetup();
52  propagator = theService.propagator("SmartPropagator");
53  propagatorCompatibleDet = theService.propagator("SteppingHelixPropagatorAny");
54  theG = theService.trackingGeometry();
55  theService.eventSetup().get<TransientRecHitRecord>().get("MuonRecHitBuilder",theMuonRecHitBuilder);
56  theService.eventSetup().get<TrackingComponentsRecord>().get("KFUpdator",updatorHandle);
57  theService.eventSetup().get<MuonGeometryRecord>().get(cscGeom);
58  theService.eventSetup().get<MuonRecoGeometryRecord>().get(navMuon);
59  theService.eventSetup().get<IdealMagneticFieldRecord>().get(magfield);
60  navigation = new DirectMuonNavigation(theService.detLayerGeometry());
61 }
62 
63 
64 
66  if (navigation) delete navigation;
67 }
68 
69 
70 
72  result.clear();
73 
74  // Fill the map with the APE chamber by chamber (DT)
75  // IT ALSO WORKS IF APE IS 0
76  edm::ESHandle<AlignmentErrors> dtAlignmentErrors;
77  theSetup->get<DTAlignmentErrorRcd>().get( dtAlignmentErrors );
78  for ( std::vector<AlignTransformError>::const_iterator it = dtAlignmentErrors->m_alignError.begin();
79  it != dtAlignmentErrors->m_alignError.end(); it++ ) {
80  CLHEP::HepSymMatrix error = (*it).matrix();
81  GlobalError glbErr(error[0][0], error[1][0], error[1][1], error[2][0], error[2][1], error[2][2]);
82  DTChamberId DTid((*it).rawId());
83  dtApeMap.insert( pair<DTChamberId, GlobalError> (DTid, glbErr) );
84  }
85 
86  // Fill the map with the APE chamber by chamber (CSC)
87  // IT ALSO WORKS IF APE IS 0
88  edm::ESHandle<AlignmentErrors> cscAlignmentErrors;
89  theSetup->get<CSCAlignmentErrorRcd>().get( cscAlignmentErrors );
90  for ( std::vector<AlignTransformError>::const_iterator it = cscAlignmentErrors->m_alignError.begin();
91  it != cscAlignmentErrors->m_alignError.end(); it++ ) {
92  CLHEP::HepSymMatrix error = (*it).matrix();
93  GlobalError glbErr(error[0][0], error[1][0], error[1][1], error[2][0], error[2][1], error[2][2]);
94  CSCDetId CSCid((*it).rawId());
95  cscApeMap.insert( pair<CSCDetId, GlobalError> (CSCid, glbErr) );
96  }
97 
98  // Put the tracker hits in the final vector and get the last tracker valid measure
99  std::vector<TrajectoryMeasurement> muonMeasurements = traj.measurements();
100  TrajectoryMeasurement lastTKm = muonMeasurements.front();
101  for (std::vector<TrajectoryMeasurement>::const_iterator imT = muonMeasurements.begin(); imT != muonMeasurements.end(); imT++ ) {
102  if ( !(*imT).recHit()->isValid() ) continue;
103  const TransientTrackingRecHit* hit = &(*(*imT).recHit());
104  if (hit->geographicalId().det() == DetId::Tracker) {
105  result.push_back((*imT).recHit());
106  if (!(*imT).forwardPredictedState().isValid()) continue;
107  if ((*imT).forwardPredictedState().globalPosition().mag()
108  > lastTKm.forwardPredictedState().globalPosition().mag()) lastTKm = *imT;
109  }
110  }
111 
112  // get the last (forward) predicted state for the tracker
114 
115  // update the state with the last tracker measure
116  update(currentState, lastTKm.recHit());
117 
118  // use the navigation to get the list of compatible dets
119  map<int, std::vector<DetId> > detMap;
120  compatibleDets(currentState, detMap);
121 
122  // selects the muon hits for the final refit
123  filteringAlgo(detMap);
124 
125  return result;
126 }
127 
128 
129 
130 void DynamicTruncation::setThr(int bThr, int eThr, int useAPE_) {
131  if (useAPE_ == 1) useAPE = true;
132  else useAPE = false;
133  if (bThr <= MAX_THR && bThr >= 0) DTThr = bThr; // DT thr
134  else DTThr = MAX_THR;
135  if (eThr <= MAX_THR && eThr >= 0) CSCThr = eThr; // CSC thr
136  else CSCThr = MAX_THR;
137 }
138 
139 
140 
141 double DynamicTruncation::getBest(std::vector<CSCSegment>& segs, TrajectoryStateOnSurface& tsos, CSCSegment& bestCSCSeg) {
142  unsigned int i = 0;
143  double val = MAX_THR;
144  std::vector<CSCSegment>::size_type sz = segs.size();
145  for (i=0; i<sz; i++) {
146  LocalError apeLoc; //default constructor is all zeroes, OK
147  if (useAPE) apeLoc = ErrorFrameTransformer().transform(cscApeMap.find(segs[i].cscDetId())->second, theG->idToDet(segs[i].cscDetId())->surface());
148  StateSegmentMatcher estim(&tsos, &segs[i], &apeLoc);
149  double tmp = estim.value();
150  if (tmp < val) {
151  bestCSCSeg = segs[i];
152  val = tmp;
153  }
154  }
155  return val;
156 }
157 
158 
159 
160 double DynamicTruncation::getBest(std::vector<DTRecSegment4D>& segs, TrajectoryStateOnSurface& tsos, DTRecSegment4D& bestDTSeg) {
161  unsigned int i = 0;
162  double val = MAX_THR;
164  for (i=0; i<sz; i++) {
165  LocalError apeLoc; //default constructor is all zeroes, OK
166  if (useAPE) apeLoc = ErrorFrameTransformer().transform(dtApeMap.find(segs[i].chamberId())->second, theG->idToDet(segs[i].chamberId())->surface());
167  StateSegmentMatcher estim(&tsos, &segs[i], &apeLoc);
168  double tmp = estim.value();
169  if (tmp < val) {
170  bestDTSeg = segs[i];
171  val = tmp;
172  }
173  }
174  return val;
175 }
176 
177 
178 
179 void DynamicTruncation::compatibleDets(TrajectoryStateOnSurface& tsos, map<int, std::vector<DetId> >& detMap) {
180  // SteppingHelixPropagator prop(magfield.product(), anyDirection);
181  // MuonPatternRecoDumper dumper;
182  MeasurementEstimator *theEstimator = new Chi2MeasurementEstimator(100, 3);
183  std::vector<const DetLayer *> navLayers;
185  for ( unsigned int ilayer=0; ilayer<navLayers.size(); ilayer++ ) {
186  // Skip RPC layers
187  if (navLayers[ilayer]->subDetector() == GeomDetEnumerators::RPCEndcap
188  || navLayers[ilayer]->subDetector() == GeomDetEnumerators::RPCBarrel) continue;
189  std::vector<DetLayer::DetWithState> comps = navLayers[ilayer]->compatibleDets(currentState,
190  *propagatorCompatibleDet, *theEstimator);
191  // cout << comps.size() << " compatible Dets with " << navLayers[ilayer]->subDetector() << " Layer " << ilayer << " "
192  // << dumper.dumpLayer(navLayers[ilayer]) << " " << endl;
193  if (comps.size() > 0) {
194  for ( unsigned int icomp=0; icomp<comps.size(); icomp++ ) {
195  DetId id(comps[icomp].first->geographicalId().rawId());
196  detMap[ilayer].push_back(id);
197  }
198  }
199  }
200  if (theEstimator) delete theEstimator;
201 }
202 
203 
204 
205 void DynamicTruncation::filteringAlgo(map<int, std::vector<DetId> >& detMap) {
207  for (unsigned int iDet = 0; iDet < detMap.size(); ++iDet) {
208  double bestLayerValue = MAX_THR;
209  bool isDTorCSC = false;
210  ConstRecHitContainer layerRH, layerSEG;
211  std::vector<DetId> chamber = detMap[iDet];
212  for (unsigned int j = 0; j < chamber.size(); ++j) {
213  DetId id = chamber[j];
214 
215  if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::DT) {
216  isDTorCSC = true;
217 
218  DTChamberId DTid(id);
219 
220  std::vector<DTRecSegment4D> allDTsegs;
221  std::map<int, std::vector<DTRecSegment4D> >::const_iterator dtIter = getSegs.getDTlist().find(DTid.station());
222  if (dtIter != getSegs.getDTlist().end()){
223  allDTsegs = dtIter->second;
224  }
225  std::vector<DTRecSegment4D>::size_type sz = allDTsegs.size();
226  for (unsigned int iSeg=0; iSeg<sz; ++iSeg) {
227 
228  // Propagate the state to the current chamber
229  TrajectoryStateOnSurface tsosdt = propagator->propagate(currentState,
230  theG->idToDet(allDTsegs[iSeg].chamberId())->surface());
231  if (!tsosdt.isValid()) continue;
232 
233  std::vector<DTRecSegment4D> DTsegs;
234  DTsegs.push_back(allDTsegs[iSeg]);
235 
236  DTRecSegment4D bestDTSeg;
237  double bestChamberValue = getBest(DTsegs, tsosdt, bestDTSeg);
238  if (bestChamberValue < bestLayerValue) bestLayerValue = bestChamberValue;
239 
240  // Check if the best estimator value is below the THR and then get the RH componing the segment
241  if (bestChamberValue >= DTThr || bestChamberValue > bestLayerValue) continue;
242  layerRH.clear(); layerSEG.clear();
243  layerSEG.push_back(theMuonRecHitBuilder->build(&bestDTSeg));
244  std::vector<DTRecHit1D> DTrh = getSegs.getDTRHmap(bestDTSeg);
245  for (std::vector<DTRecHit1D>::iterator it = DTrh.begin(); it != DTrh.end(); it++) {
246  layerRH.push_back(theMuonRecHitBuilder->build(&*it));
247  }
248  }
249  }
250  if (id.det() == DetId::Muon && id.subdetId() == MuonSubdetId::CSC) {
251  isDTorCSC = true;
252  CSCDetId CSCid(id);
253 
254  std::vector<CSCSegment> allCSCsegs;
255  std::map<int, std::vector<CSCSegment> >::const_iterator cscIter = getSegs.getCSClist().find(CSCid.station());
256  if (cscIter != getSegs.getCSClist().end()){
257  allCSCsegs = cscIter->second;
258  }
259 
260  std::vector<CSCSegment>::size_type sz = allCSCsegs.size();
261  for (unsigned int iSeg=0; iSeg<sz; ++iSeg) {
262 
263  // Propagate the state to the current chamber
264  TrajectoryStateOnSurface tsoscsc = propagator->propagate(currentState,
265  theG->idToDet(allCSCsegs[iSeg].cscDetId())->surface());
266  if (!tsoscsc.isValid()) continue;
267 
268  std::vector<CSCSegment> CSCsegs;
269  CSCsegs.push_back(allCSCsegs[iSeg]);
270 
271  CSCSegment bestCSCSeg;
272  double bestChamberValue = getBest(CSCsegs, tsoscsc, bestCSCSeg);
273  if (bestChamberValue < bestLayerValue) bestLayerValue = bestChamberValue;
274 
275  // Check if the best estimator value is below the THR and then get the RH componing the segment
276  if (bestChamberValue >= CSCThr || bestChamberValue > bestLayerValue) continue;
277  layerRH.clear(); layerSEG.clear();
278  layerSEG.push_back(theMuonRecHitBuilder->build(&bestCSCSeg));
279  std::vector<CSCRecHit2D> CSCrh = getSegs.getCSCRHmap(bestCSCSeg);
280  for (std::vector<CSCRecHit2D>::iterator it = CSCrh.begin(); it != CSCrh.end(); ++it) {
281  layerRH.push_back(theMuonRecHitBuilder->build(&*it));
282  }
283  }
284  }
285  }
286 
287  if (isDTorCSC) {
288  if (bestLayerValue < MAX_THR) estimators.push_back(bestLayerValue);
289  else estimators.push_back(-1);
290  }
291 
292  // For segment based fits
293  if (layerSEG.size() > 0) {
294  result.push_back(layerSEG.front());
295  DetId id_ = layerSEG.front()->geographicalId();
296  if (id_.subdetId() == MuonSubdetId::DT) {
297  DTChamberId MuonChId(id_);
298  TrajectoryStateOnSurface temp = propagator->propagate(currentState, theG->idToDet(MuonChId)->surface());
299  if (temp.isValid())
300  currentState = updatorHandle->update(temp, *layerSEG.front());
301  }
302  if (id_.subdetId() == MuonSubdetId::CSC) {
303  CSCDetId MuonChId(id_);
304  TrajectoryStateOnSurface temp = propagator->propagate(currentState, theG->idToDet(MuonChId)->surface());
305  if (temp.isValid())
306  currentState = updatorHandle->update(temp, *layerSEG.front());
307  }
308  }
309 
310 
311 
312 
313  /*
314  // For hit based fits
315  if (layerRH.size() > 0) {
316  for (ConstRecHitContainer::iterator it = layerRH.begin(); it != layerRH.end(); ++it) result.push_back((*it));
317 
318  // sort the vector
319  layerRH = sort(layerRH);
320 
321  // update the currentState using all rh
322  DetId id = layerRH.front()->geographicalId();
323  if (id.subdetId() == MuonSubdetId::DT) updateWithDThits(layerRH);
324  else updateWithCSChits(layerRH);
325  }
326  */
327 
328  layerSEG.clear();
329  layerRH.clear();
330  }
331 }
332 
333 
334 
336  TrajectoryStateOnSurface temp = updatorHandle->update(tsos, *rechit);
337  if (temp.isValid()) currentState = updatorHandle->update(tsos, *rechit);
338 }
339 
340 
341 
343  for (ConstRecHitContainer::const_iterator it = recHits.begin(); it != recHits.end(); ++it) {
344  DTLayerId layid((*it)->det()->geographicalId());
345  TrajectoryStateOnSurface temp = propagator->propagate(currentState, theG->idToDet(layid)->surface());
346  if (temp.isValid()) currentState = updatorHandle->update(temp, **it);
347  }
348 }
349 
350 
351 
353  for (ConstRecHitContainer::const_iterator it = recHits.begin(); it != recHits.end(); ++it) {
354  const CSCLayer* cscChamber = cscGeom->layer((*it)->det()->geographicalId());
355  CSCDetId layid = cscChamber->geographicalId();
356  TrajectoryStateOnSurface temp = propagator->propagate(currentState, theG->idToDet(layid)->surface());
357  if (temp.isValid()) currentState = updatorHandle->update(temp, **it);
358  }
359 }
360 
361 
362 
364  unsigned int i=0;
365  unsigned int j=0;
366  ConstRecHitContainer::size_type n = recHits.size();
367  for(i=1; i<n; ++i)
368  for(j=n-1; j>=i; --j)
369  {
370  if(recHits[j-1]->globalPosition().mag() > recHits[j]->globalPosition().mag())
371  {
372  swap (recHits[j-1],recHits[j]);
373  }
374  }
375  return recHits;
376 }
377 
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 > > &)
ConstRecHitPointer const & recHit() const
TrajectoryStateOnSurface currentState
edm::ESHandle< Propagator > propagatorCompatibleDet
std::vector< double > estimators
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
GlobalPoint globalPosition() const
uint16_t size_type
std::vector< const DetLayer * > compatibleLayers(const FreeTrajectoryState &fts, PropagationDirection timeDirection) const
U second(std::pair< T, U > const &p)
std::vector< CSCRecHit2D > getCSCRHmap(const CSCSegment &)
DataContainer const & measurements() const
Definition: Trajectory.h:215
void filteringAlgo(std::map< int, std::vector< DetId > > &)
static const int CSC
Definition: MuonSubdetId.h:13
T mag() const
Definition: PV3DBase.h:67
edm::ESHandle< MuonDetLayerGeometry > navMuon
const std::map< int, std::vector< CSCSegment > > & getCSClist() const
ConstRecHitContainer result
const edm::EventSetup * theSetup
FreeTrajectoryState const * freeState(bool withErrors=true) const
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:79
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
const edm::Event * theEvent
edm::ESHandle< TransientTrackingRecHitBuilder > theMuonRecHitBuilder
#define MAX_THR
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: DetId.h:18
void setThr(int, int, int)
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
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:12
DetId geographicalId() const
volatile std::atomic< bool > shutdown_flag false
std::vector< DTRecHit1D > getDTRHmap(const DTRecSegment4D &)
int station() const
Return the station number.
Definition: DTChamberId.h:51
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
edm::ESHandle< MagneticField > magfield
std::map< CSCDetId, GlobalError > cscApeMap
edm::ESHandle< GlobalTrackingGeometry > theG
edm::ESHandle< CSCGeometry > cscGeom