CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GlobalMuonRefitter.cc
Go to the documentation of this file.
1 
16 
17 //---------------
18 // C++ Headers --
19 //---------------
20 
21 #include <iostream>
22 #include <iomanip>
23 #include <algorithm>
24 
25 //-------------------------------
26 // Collaborating Class Headers --
27 //-------------------------------
28 
30 
40 
41 
52 
55 
63 
64 using namespace std;
65 using namespace edm;
66 
67 //----------------
68 // Constructors --
69 //----------------
70 
72  const MuonServiceProxy* service) :
73  theCosmicFlag(par.getParameter<bool>("PropDirForCosmics")),
74  theDTRecHitLabel(par.getParameter<InputTag>("DTRecSegmentLabel")),
75  theCSCRecHitLabel(par.getParameter<InputTag>("CSCRecSegmentLabel")),
76  theService(service) {
77 
78  theCategory = par.getUntrackedParameter<string>("Category", "Muon|RecoMuon|GlobalMuon|GlobalMuonRefitter");
79 
80  theHitThreshold = par.getParameter<int>("HitThreshold");
81  theDTChi2Cut = par.getParameter<double>("Chi2CutDT");
82  theCSCChi2Cut = par.getParameter<double>("Chi2CutCSC");
83  theRPCChi2Cut = par.getParameter<double>("Chi2CutRPC");
84 
85  // Refit direction
86  string refitDirectionName = par.getParameter<string>("RefitDirection");
87 
88  if (refitDirectionName == "insideOut" ) theRefitDirection = insideOut;
89  else if (refitDirectionName == "outsideIn" ) theRefitDirection = outsideIn;
90  else
91  throw cms::Exception("TrackTransformer constructor")
92  <<"Wrong refit direction chosen in TrackTransformer ParameterSet"
93  << "\n"
94  << "Possible choices are:"
95  << "\n"
96  << "RefitDirection = insideOut or RefitDirection = outsideIn";
97 
98  theFitterName = par.getParameter<string>("Fitter");
99  thePropagatorName = par.getParameter<string>("Propagator");
100 
101  theSkipStation = par.getParameter<int>("SkipStation");
102  theTrackerSkipSystem = par.getParameter<int>("TrackerSkipSystem");
103  theTrackerSkipSection = par.getParameter<int>("TrackerSkipSection");//layer, wheel, or disk depending on the system
104 
105  theTrackerRecHitBuilderName = par.getParameter<string>("TrackerRecHitBuilder");
106  theMuonRecHitBuilderName = par.getParameter<string>("MuonRecHitBuilder");
107 
108  theRPCInTheFit = par.getParameter<bool>("RefitRPCHits");
109 
110  theDYTthrs = par.getParameter< std::vector<int> >("DYTthrs");
111 
112  if (par.existsAs<double>("RescaleErrorFactor")) {
113  theRescaleErrorFactor = par.getParameter<double>("RescaleErrorFactor");
114  edm::LogWarning("GlobalMuonRefitter") << "using error rescale factor " << theRescaleErrorFactor;
115  }
116  else
117  theRescaleErrorFactor = 1000.;
118 
119 
120  theCacheId_TRH = 0;
121 
122 }
123 
124 //--------------
125 // Destructor --
126 //--------------
127 
129 }
130 
131 
132 //
133 // set Event
134 //
136 
137  theEvent = &event;
138  event.getByLabel(theDTRecHitLabel, theDTRecHits);
139  event.getByLabel(theCSCRecHitLabel, theCSCRecHits);
140 }
141 
142 
144 
146 
147  // Transient Rechit Builders
148  unsigned long long newCacheId_TRH = setup.get<TransientRecHitRecord>().cacheIdentifier();
149  if ( newCacheId_TRH != theCacheId_TRH ) {
150  LogDebug(theCategory) << "TransientRecHitRecord changed!";
153  }
154 }
155 
156 
157 //
158 // build a combined tracker-muon trajectory
159 //
160 vector<Trajectory> GlobalMuonRefitter::refit(const reco::Track& globalTrack,
161  const int theMuonHitsOption,
162  const TrackerTopology *tTopo) const {
163  LogTrace(theCategory) << " *** GlobalMuonRefitter *** option " << theMuonHitsOption << endl;
164 
165  ConstRecHitContainer allRecHitsTemp; // all muon rechits temp
166 
167  reco::TransientTrack track(globalTrack,&*(theService->magneticField()),theService->trackingGeometry());
168 
169  for (trackingRecHit_iterator hit = track.recHitsBegin(); hit != track.recHitsEnd(); ++hit)
170  if ((*hit)->isValid()) {
171  if ((*hit)->geographicalId().det() == DetId::Tracker)
172  allRecHitsTemp.push_back(theTrackerRecHitBuilder->build(&**hit));
173  else if ((*hit)->geographicalId().det() == DetId::Muon) {
174  if ((*hit)->geographicalId().subdetId() == 3 && !theRPCInTheFit) {
175  LogTrace(theCategory) << "RPC Rec Hit discarged";
176  continue;
177  }
178  allRecHitsTemp.push_back(theMuonRecHitBuilder->build(&**hit));
179  }
180  }
181  vector<Trajectory> refitted = refit(globalTrack,track,allRecHitsTemp,theMuonHitsOption, tTopo);
182  return refitted;
183 }
184 
185 //
186 // build a combined tracker-muon trajectory
187 //
188 vector<Trajectory> GlobalMuonRefitter::refit(const reco::Track& globalTrack,
189  const reco::TransientTrack track,
190  const TransientTrackingRecHit::ConstRecHitContainer& allRecHitsTemp,
191  const int theMuonHitsOption,
192  const TrackerTopology *tTopo) const {
193 
194  // MuonHitsOption: 0 - tracker only
195  // 1 - include all muon hits
196  // 2 - include only first muon hit(s)
197  // 3 - include only selected muon hits
198  // 4 - redo pattern recognition with dynamic truncation
199 
200  vector<int> stationHits(4,0);
201  map<DetId, int> hitMap;
202 
203  ConstRecHitContainer allRecHits; // all muon rechits
204  ConstRecHitContainer fmsRecHits; // only first muon rechits
205  ConstRecHitContainer selectedRecHits; // selected muon rechits
206  ConstRecHitContainer DYTRecHits; // rec hits from dynamic truncation algorithm
207 
208  LogTrace(theCategory) << " *** GlobalMuonRefitter *** option " << theMuonHitsOption << endl;
209  LogTrace(theCategory) << " Track momentum before refit: " << globalTrack.pt() << endl;
210  LogTrace(theCategory) << " Hits size before : " << allRecHitsTemp.size() << endl;
211 
212  allRecHits = getRidOfSelectStationHits(allRecHitsTemp, tTopo);
213  // printHits(allRecHits);
214  LogTrace(theCategory) << " Hits size: " << allRecHits.size() << endl;
215 
216  vector <Trajectory> outputTraj;
217 
218  if ((theMuonHitsOption == 1) || (theMuonHitsOption == 3) || (theMuonHitsOption == 4) ) {
219  // refit the full track with all muon hits
220  vector <Trajectory> globalTraj = transform(globalTrack, track, allRecHits);
221 
222  if (!globalTraj.size()) {
223  LogTrace(theCategory) << "No trajectory from the TrackTransformer!" << endl;
224  return vector<Trajectory>();
225  }
226 
227  LogTrace(theCategory) << " Initial trajectory state: "
228  << globalTraj.front().lastMeasurement().updatedState().freeState()->parameters() << endl;
229 
230  if (theMuonHitsOption == 1 )
231  outputTraj.push_back(globalTraj.front());
232 
233  if (theMuonHitsOption == 3 ) {
234  checkMuonHits(globalTrack, allRecHits, hitMap);
235  selectedRecHits = selectMuonHits(globalTraj.front(),hitMap);
236  LogTrace(theCategory) << " Selected hits size: " << selectedRecHits.size() << endl;
237  outputTraj = transform(globalTrack, track, selectedRecHits);
238  }
239 
240  if (theMuonHitsOption == 4 ) {
241  // here we use the single thr per subdetector (better performance can be obtained using thr as function of eta)
242 
244  dytRefit.setThr(theDYTthrs.at(0),theDYTthrs.at(1),theDYTthrs.at(2));
245  DYTRecHits = dytRefit.filter(globalTraj.front());
246  //vector<double> est = dytRefit.getEstimators();
247  if ((DYTRecHits.size() > 1) && (DYTRecHits.front()->globalPosition().mag() > DYTRecHits.back()->globalPosition().mag()))
248  stable_sort(DYTRecHits.begin(),DYTRecHits.end(),RecHitLessByDet(alongMomentum));
249  outputTraj = transform(globalTrack, track, DYTRecHits);
250  }
251 
252  } else if (theMuonHitsOption == 2 ) {
253  getFirstHits(globalTrack, allRecHits, fmsRecHits);
254  outputTraj = transform(globalTrack, track, fmsRecHits);
255  }
256 
257 
258  if (outputTraj.size()) {
259  LogTrace(theCategory) << "Refitted pt: " << outputTraj.front().firstMeasurement().updatedState().globalParameters().momentum().perp() << endl;
260  return outputTraj;
261  } else {
262  LogTrace(theCategory) << "No refitted Tracks... " << endl;
263  return vector<Trajectory>();
264  }
265 
266 }
267 
268 
269 //
270 //
271 //
274  map<DetId, int> &hitMap) const {
275 
276  LogTrace(theCategory) << " GlobalMuonRefitter::checkMuonHits " << endl;
277 
278  float coneSize = 20.0;
279 
280  // loop through all muon hits and calculate the maximum # of hits in each chamber
281  for (ConstRecHitContainer::const_iterator imrh = all.begin(); imrh != all.end(); imrh++ ) {
282 
283  if ( (*imrh != 0 ) && !(*imrh)->isValid() ) continue;
284 
285  int detRecHits = 0;
286  MuonRecHitContainer dRecHits;
287 
288  DetId id = (*imrh)->geographicalId();
289  DetId chamberId;
290 
291  // Skip tracker hits
292  if (id.det()!=DetId::Muon) continue;
293 
294  if ( id.subdetId() == MuonSubdetId::DT ) {
295  DTChamberId did(id.rawId());
296  chamberId=did;
297 
298  if ((*imrh)->recHits().size()>1) {
299  std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
300  for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
301  if ((*imrh)->recHits().size()>1) {
302  std::vector <const TrackingRecHit*> hits1d = (*hit2d)->recHits();
303  for (std::vector <const TrackingRecHit*>::const_iterator hit1d = hits1d.begin(); hit1d!= hits1d.end(); hit1d++) {
304  DetId id1 = (*hit1d)->geographicalId();
305  DTLayerId lid(id1.rawId());
306  // Get the 1d DT RechHits from this layer
307  DTRecHitCollection::range dRecHits = theDTRecHits->get(lid);
308  int layerHits=0;
309  for (DTRecHitCollection::const_iterator ir = dRecHits.first; ir != dRecHits.second; ir++ ) {
310  double rhitDistance = fabs(ir->localPosition().x()-(**hit1d).localPosition().x());
311  if ( rhitDistance < coneSize ) layerHits++;
312  LogTrace(theCategory) << " " << (ir)->localPosition() << " " << (**hit1d).localPosition()
313  << " Distance: " << rhitDistance << " recHits: " << layerHits << " SL: " << lid.superLayer() << endl;
314  }
315  if (layerHits>detRecHits) detRecHits=layerHits;
316  }
317  }
318  }
319 
320  } else {
321  DTLayerId lid(id.rawId());
322 
323  // Get the 1d DT RechHits from this layer
324  DTRecHitCollection::range dRecHits = theDTRecHits->get(lid);
325 
326  for (DTRecHitCollection::const_iterator ir = dRecHits.first; ir != dRecHits.second; ir++ ) {
327  double rhitDistance = fabs(ir->localPosition().x()-(**imrh).localPosition().x());
328  if ( rhitDistance < coneSize ) detRecHits++;
329  LogTrace(theCategory) << " " << (ir)->localPosition() << " " << (**imrh).localPosition()
330  << " Distance: " << rhitDistance << " recHits: " << detRecHits << endl;
331  }
332  }
333  }// end of if DT
334  else if ( id.subdetId() == MuonSubdetId::CSC ) {
335  CSCDetId did(id.rawId());
336  chamberId=did.chamberId();
337 
338  if ((*imrh)->recHits().size()>1) {
339  std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
340  for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
341  DetId id1 = (*hit2d)->geographicalId();
342  CSCDetId lid(id1.rawId());
343 
344  // Get the CSC Rechits from this layer
345  CSCRecHit2DCollection::range dRecHits = theCSCRecHits->get(lid);
346  int layerHits=0;
347 
348  for (CSCRecHit2DCollection::const_iterator ir = dRecHits.first; ir != dRecHits.second; ir++ ) {
349  double rhitDistance = (ir->localPosition()-(**hit2d).localPosition()).mag();
350  if ( rhitDistance < coneSize ) layerHits++;
351  LogTrace(theCategory) << ir->localPosition() << " " << (**hit2d).localPosition()
352  << " Distance: " << rhitDistance << " recHits: " << layerHits << endl;
353  }
354  if (layerHits>detRecHits) detRecHits=layerHits;
355  }
356  } else {
357  // Get the CSC Rechits from this layer
358  CSCRecHit2DCollection::range dRecHits = theCSCRecHits->get(did);
359 
360  for (CSCRecHit2DCollection::const_iterator ir = dRecHits.first; ir != dRecHits.second; ir++ ) {
361  double rhitDistance = (ir->localPosition()-(**imrh).localPosition()).mag();
362  if ( rhitDistance < coneSize ) detRecHits++;
363  LogTrace(theCategory) << ir->localPosition() << " " << (**imrh).localPosition()
364  << " Distance: " << rhitDistance << " recHits: " << detRecHits << endl;
365  }
366  }
367  }
368  else {
369  if ( id.subdetId() != MuonSubdetId::RPC ) LogError(theCategory)<<" Wrong Hit Type ";
370  continue;
371  }
372 
373  map<DetId,int>::iterator imap=hitMap.find(chamberId);
374  if (imap!=hitMap.end()) {
375  if (detRecHits>imap->second) imap->second=detRecHits;
376  } else hitMap[chamberId]=detRecHits;
377 
378  } // end of loop over muon rechits
379 
380  for (map<DetId,int>::iterator imap=hitMap.begin(); imap!=hitMap.end(); imap++ )
381  LogTrace(theCategory) << " Station " << imap->first.rawId() << ": " << imap->second <<endl;
382 
383  LogTrace(theCategory) << "CheckMuonHits: "<<all.size();
384 
385  // check order of muon measurements
386  if ( (all.size() > 1) &&
387  ( all.front()->globalPosition().mag() >
388  all.back()->globalPosition().mag() ) ) {
389  LogTrace(theCategory)<< "reverse order: ";
390  stable_sort(all.begin(),all.end(),RecHitLessByDet(alongMomentum));
391  }
392 }
393 
394 
395 //
396 // Get the hits from the first muon station (containing hits)
397 //
400  ConstRecHitContainer& first) const {
401 
402  LogTrace(theCategory) << " GlobalMuonRefitter::getFirstHits\nall rechits length:" << all.size() << endl;
403  first.clear();
404 
405  int station_to_keep = 999;
406  vector<int> stations;
407  for (ConstRecHitContainer::const_iterator ihit = all.begin(); ihit != all.end(); ++ihit) {
408 
409  int station = 0;
410  bool use_it = true;
411  DetId id = (*ihit)->geographicalId();
412  unsigned raw_id = id.rawId();
413  if (!(*ihit)->isValid()) station = -1;
414  else {
415  if (id.det() == DetId::Muon) {
416  switch (id.subdetId()) {
417  case MuonSubdetId::DT: station = DTChamberId(raw_id).station(); break;
418  case MuonSubdetId::CSC: station = CSCDetId(raw_id).station(); break;
419  case MuonSubdetId::RPC: station = RPCDetId(raw_id).station(); use_it = false; break;
420  }
421  }
422  }
423 
424  if (use_it && station > 0 && station < station_to_keep) station_to_keep = station;
425  stations.push_back(station);
426 
427  LogTrace(theCategory) << "rawId: " << raw_id << " station = " << station << " station_to_keep is now " << station_to_keep;
428  }
429 
430  if (station_to_keep <= 0 || station_to_keep > 4 || stations.size() != all.size())
431  LogInfo(theCategory) << "failed to getFirstHits (all muon hits are outliers/bad ?)! station_to_keep = "
432  << station_to_keep << " stations.size " << stations.size() << " all.size " << all.size();
433 
434  for (unsigned i = 0; i < stations.size(); ++i)
435  if (stations[i] >= 0 && stations[i] <= station_to_keep) first.push_back(all[i]);
436 
437  return;
438 }
439 
440 
441 //
442 // select muon hits compatible with trajectory;
443 // check hits in chambers with showers
444 //
447  const map<DetId, int> &hitMap) const {
448 
449  ConstRecHitContainer muonRecHits;
450  const double globalChi2Cut = 200.0;
451 
452  vector<TrajectoryMeasurement> muonMeasurements = traj.measurements();
453 
454  // loop through all muon hits and skip hits with bad chi2 in chambers with high occupancy
455  for (std::vector<TrajectoryMeasurement>::const_iterator im = muonMeasurements.begin(); im != muonMeasurements.end(); im++ ) {
456 
457  if ( !(*im).recHit()->isValid() ) continue;
458  if ( (*im).recHit()->det()->geographicalId().det() != DetId::Muon ) {
459  // if ( ( chi2ndf < globalChi2Cut ) )
460  muonRecHits.push_back((*im).recHit());
461  continue;
462  }
463  ConstMuonRecHitPointer immrh = dynamic_cast<const MuonTransientTrackingRecHit*>((*im).recHit().get());
464 
465  DetId id = immrh->geographicalId();
466  DetId chamberId;
467  int threshold = 0;
468  double chi2Cut = 0.0;
469 
470  // get station of hit if it is in DT
471  if ( (*immrh).isDT() ) {
472  DTChamberId did(id.rawId());
473  chamberId = did;
474  threshold = theHitThreshold;
475  chi2Cut = theDTChi2Cut;
476  }
477  // get station of hit if it is in CSC
478  else if ( (*immrh).isCSC() ) {
479  CSCDetId did(id.rawId());
480  chamberId = did.chamberId();
481  threshold = theHitThreshold;
482  chi2Cut = theCSCChi2Cut;
483  }
484  // get station of hit if it is in RPC
485  else if ( (*immrh).isRPC() ) {
486  RPCDetId rpcid(id.rawId());
487  chamberId = rpcid;
488  threshold = theHitThreshold;
489  chi2Cut = theRPCChi2Cut;
490  } else
491  continue;
492 
493  double chi2ndf = (*im).estimate()/(*im).recHit()->dimension();
494 
495  bool keep = true;
496  map<DetId,int>::const_iterator imap=hitMap.find(chamberId);
497  if ( imap!=hitMap.end() )
498  if (imap->second>threshold) keep = false;
499 
500  if ( (keep || (chi2ndf<chi2Cut)) && (chi2ndf<globalChi2Cut) ) {
501  muonRecHits.push_back((*im).recHit());
502  } else {
504  << "Skip hit: " << id.rawId() << " chi2="
505  << chi2ndf << " ( threshold: " << chi2Cut << ") Det: "
506  << imap->second << endl;
507  }
508  }
509 
510  // check order of rechits
511  reverse(muonRecHits.begin(),muonRecHits.end());
512  return muonRecHits;
513 }
514 
515 
516 //
517 // print RecHits
518 //
520 
521  LogTrace(theCategory) << "Used RecHits: " << hits.size();
522  for (ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
523  if ( !(*ir)->isValid() ) {
524  LogTrace(theCategory) << "invalid RecHit";
525  continue;
526  }
527 
528  const GlobalPoint& pos = (*ir)->globalPosition();
529 
531  << "r = " << sqrt(pos.x() * pos.x() + pos.y() * pos.y())
532  << " z = " << pos.z()
533  << " dimension = " << (*ir)->dimension()
534  << " det = " << (*ir)->det()->geographicalId().det()
535  << " subdet = " << (*ir)->det()->subDetector()
536  << " raw id = " << (*ir)->det()->geographicalId().rawId();
537  }
538 
539 }
540 
541 
542 //
543 // add Trajectory* to TrackCand if not already present
544 //
547 
548  if (!recHits.empty()){
549  ConstRecHitContainer::const_iterator frontHit = recHits.begin();
550  ConstRecHitContainer::const_iterator backHit = recHits.end() - 1;
551  while( !(*frontHit)->isValid() && frontHit != backHit) {frontHit++;}
552  while( !(*backHit)->isValid() && backHit != frontHit) {backHit--;}
553 
554  double rFirst = (*frontHit)->globalPosition().mag();
555  double rLast = (*backHit) ->globalPosition().mag();
556 
557  if(rFirst < rLast) return insideOut;
558  else if(rFirst > rLast) return outsideIn;
559  else {
560  LogError(theCategory) << "Impossible determine the rechits order" <<endl;
561  return undetermined;
562  }
563  } else {
564  LogError(theCategory) << "Impossible determine the rechits order" <<endl;
565  return undetermined;
566  }
567 }
568 
569 
570 //
571 // Convert Tracks into Trajectories with a given set of hits
572 //
573 vector<Trajectory> GlobalMuonRefitter::transform(const reco::Track& newTrack,
574  const reco::TransientTrack track,
575  const TransientTrackingRecHit::ConstRecHitContainer& urecHitsForReFit) const {
576 
577  TransientTrackingRecHit::ConstRecHitContainer recHitsForReFit = urecHitsForReFit;
578  LogTrace(theCategory) << "GlobalMuonRefitter::transform: " << recHitsForReFit.size() << " hits:";
579  printHits(recHitsForReFit);
580 
581  if(recHitsForReFit.size() < 2) return vector<Trajectory>();
582 
583  // Check the order of the rechits
584  RefitDirection recHitsOrder = checkRecHitsOrdering(recHitsForReFit);
585 
586  LogTrace(theCategory) << "checkRecHitsOrdering() returned " << recHitsOrder
587  << ", theRefitDirection is " << theRefitDirection
588  << " (insideOut == " << insideOut << ", outsideIn == " << outsideIn << ")";
589 
590  // Reverse the order in the case of inconsistency between the fit direction and the rechit order
591  if(theRefitDirection != recHitsOrder) reverse(recHitsForReFit.begin(),recHitsForReFit.end());
592 
593  // Even though we checked the rechits' ordering above, we may have
594  // already flipped them elsewhere (getFirstHits() is such a
595  // culprit). Use the global positions of the states and the desired
596  // refit direction to find the starting TSOS.
597  TrajectoryStateOnSurface firstTSOS, lastTSOS;
598  unsigned int innerId; //UNUSED: outerId;
599  bool order_swapped = track.outermostMeasurementState().globalPosition().mag() < track.innermostMeasurementState().globalPosition().mag();
600  bool inner_is_first;
601  LogTrace(theCategory) << "order swapped? " << order_swapped;
602 
603  // Fill the starting state, depending on the ordering above.
604  if ((theRefitDirection == insideOut && !order_swapped) || (theRefitDirection == outsideIn && order_swapped)) {
605  innerId = newTrack.innerDetId();
606  //UNUSED: outerId = newTrack.outerDetId();
607  firstTSOS = track.innermostMeasurementState();
608  lastTSOS = track.outermostMeasurementState();
609  inner_is_first = true;
610  }
611  else {
612  innerId = newTrack.outerDetId();
613  //UNUSED: outerId = newTrack.innerDetId();
614  firstTSOS = track.outermostMeasurementState();
615  lastTSOS = track.innermostMeasurementState();
616  inner_is_first = false;
617  }
618 
619  LogTrace(theCategory) << "firstTSOS: inner_is_first? " << inner_is_first
620  << " globalPosition is " << firstTSOS.globalPosition()
621  << " innerId is " << innerId;
622 
623  if(!firstTSOS.isValid()){
624  LogWarning(theCategory) << "Error wrong initial state!" << endl;
625  return vector<Trajectory>();
626  }
627 
628  firstTSOS.rescaleError(theRescaleErrorFactor);
629 
630  // This is the only way to get a TrajectorySeed with settable propagation direction
631  PTrajectoryStateOnDet garbage1;
633  PropagationDirection propDir =
634  (firstTSOS.globalPosition().basicVector().dot(firstTSOS.globalMomentum().basicVector())>0) ? alongMomentum : oppositeToMomentum;
635 
636  // These lines cause the code to ignore completely what was set
637  // above, and force propDir for tracks from collisions!
638 // if(propDir == alongMomentum && theRefitDirection == outsideIn) propDir=oppositeToMomentum;
639 // if(propDir == oppositeToMomentum && theRefitDirection == insideOut) propDir=alongMomentum;
640 
641  const TrajectoryStateOnSurface& tsosForDir = inner_is_first ? lastTSOS : firstTSOS;
642  propDir = (tsosForDir.globalPosition().basicVector().dot(tsosForDir.globalMomentum().basicVector())>0) ? alongMomentum : oppositeToMomentum;
643  LogTrace(theCategory) << "propDir based on firstTSOS x dot p is " << propDir
644  << " (alongMomentum == " << alongMomentum << ", oppositeToMomentum == " << oppositeToMomentum << ")";
645 
646  // Additional propagation diretcion determination logic for cosmic muons
647  if (theCosmicFlag) {
648  PropagationDirection propDir_first = (firstTSOS.globalPosition().basicVector().dot(firstTSOS.globalMomentum().basicVector()) > 0) ? alongMomentum : oppositeToMomentum;
649  PropagationDirection propDir_last = (lastTSOS .globalPosition().basicVector().dot(lastTSOS .globalMomentum().basicVector()) > 0) ? alongMomentum : oppositeToMomentum;
650  LogTrace(theCategory) << "propDir_first " << propDir_first << ", propdir_last " << propDir_last
651  << " : they " << (propDir_first == propDir_last ? "agree" : "disagree");
652 
653  int y_count = 0;
654  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator it = recHitsForReFit.begin(); it != recHitsForReFit.end(); ++it) {
655  if ((*it)->globalPosition().y() > 0) ++y_count;
656  else --y_count;
657  }
658 
659  PropagationDirection propDir_ycount = alongMomentum;
660  if (y_count > 0) {
661  if (theRefitDirection == insideOut) propDir_ycount = oppositeToMomentum;
662  else if (theRefitDirection == outsideIn) propDir_ycount = alongMomentum;
663  }
664  else {
665  if (theRefitDirection == insideOut) propDir_ycount = alongMomentum;
666  else if (theRefitDirection == outsideIn) propDir_ycount = oppositeToMomentum;
667  }
668 
669  LogTrace(theCategory) << "y_count = " << y_count
670  << "; based on geometrically-outermost TSOS, propDir is " << propDir << ": "
671  << (propDir == propDir_ycount ? "agrees" : "disagrees")
672  << " with ycount determination";
673 
674  if (propDir_first != propDir_last) {
675  LogTrace(theCategory) << "since first/last disagreed, using y_count propDir";
676  propDir = propDir_ycount;
677  }
678  }
679 
680  TrajectorySeed seed(garbage1,garbage2,propDir);
681 
682  if(recHitsForReFit.front()->geographicalId() != DetId(innerId)){
683  LogDebug(theCategory)<<"Propagation occured"<<endl;
684  LogTrace(theCategory) << "propagating firstTSOS at " << firstTSOS.globalPosition()
685  << " to first rechit with surface pos " << recHitsForReFit.front()->det()->surface().toGlobal(LocalPoint(0,0,0));
686  firstTSOS = theService->propagator(thePropagatorName)->propagate(firstTSOS, recHitsForReFit.front()->det()->surface());
687  if(!firstTSOS.isValid()){
688  LogDebug(theCategory)<<"Propagation error!"<<endl;
689  return vector<Trajectory>();
690  }
691  }
692 
693 /*
694  cout << " GlobalMuonRefitter : theFitter " << propDir << endl;
695  cout << " First TSOS: "
696  << firstTSOS.globalPosition() << " p="
697  << firstTSOS.globalMomentum() << " = "
698  << firstTSOS.globalMomentum().mag() << endl;
699 
700  cout << " Starting seed: "
701  << " nHits= " << seed.nHits()
702  << " tsos: "
703  << seed.startingState().parameters().position() << " p="
704  << seed.startingState().parameters().momentum() << endl;
705 
706  cout << " RecHits: "
707  << recHitsForReFit.size() << endl;
708 */
709 
710  vector<Trajectory> trajectories = theFitter->fit(seed,recHitsForReFit,firstTSOS);
711 
712  if(trajectories.empty()){
713  LogDebug(theCategory) << "No Track refitted!" << endl;
714  return vector<Trajectory>();
715  }
716 
717  return trajectories;
718 }
719 
720 
721 //
722 // Remove Selected Station Rec Hits
723 //
725  const TrackerTopology *tTopo) const
726 {
728  ConstRecHitContainer::const_iterator it = hits.begin();
729  for (; it!=hits.end(); it++) {
730 
731  DetId id = (*it)->geographicalId();
732 
733  //Check that this is a Muon hit that we're toying with -- else pass on this because the hacker is a moron / not careful
734 
735  if (id.det() == DetId::Tracker && theTrackerSkipSystem > 0) {
736  int layer = -999;
737  int disk = -999;
738  int wheel = -999;
739  if ( id.subdetId() == theTrackerSkipSystem){
740  // continue; //caveat that just removes the whole system from refitting
741 
742  if (theTrackerSkipSystem == PXB) {
743 
744  layer = tTopo->pxbLayer(id);
745  }
746  if (theTrackerSkipSystem == TIB) {
747 
748  layer = tTopo->tibLayer(id);
749  }
750 
751  if (theTrackerSkipSystem == TOB) {
752 
753  layer = tTopo->tobLayer(id);
754  }
755  if (theTrackerSkipSystem == PXF) {
756 
757  disk = tTopo->pxfDisk(id);
758  }
759  if (theTrackerSkipSystem == TID) {
760 
761  wheel = tTopo->tidWheel(id);
762  }
763  if (theTrackerSkipSystem == TEC) {
764 
765  wheel = tTopo->tecWheel(id);
766  }
767  if (theTrackerSkipSection >= 0 && layer == theTrackerSkipSection) continue;
768  if (theTrackerSkipSection >= 0 && disk == theTrackerSkipSection) continue;
769  if (theTrackerSkipSection >= 0 && wheel == theTrackerSkipSection) continue;
770  }
771  }
772 
773  if (id.det() == DetId::Muon && theSkipStation) {
774  int station = -999;
775  //UNUSED: int wheel = -999;
776  if ( id.subdetId() == MuonSubdetId::DT ) {
777  DTChamberId did(id.rawId());
778  station = did.station();
779  //UNUSED: wheel = did.wheel();
780  } else if ( id.subdetId() == MuonSubdetId::CSC ) {
781  CSCDetId did(id.rawId());
782  station = did.station();
783  } else if ( id.subdetId() == MuonSubdetId::RPC ) {
784  RPCDetId rpcid(id.rawId());
785  station = rpcid.station();
786  }
787  if(station == theSkipStation) continue;
788  }
789  results.push_back(*it);
790  }
791  return results;
792 }
793 
#define LogDebug(id)
std::string theMuonRecHitBuilderName
void printHits(const ConstRecHitContainer &) const
print all RecHits of a trajectory
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
edm::Handle< DTRecHitCollection > theDTRecHits
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:52
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:187
const MuonServiceProxy * theService
unsigned int tibLayer(const DetId &id) const
RefitDirection theRefitDirection
edm::ESHandle< TransientTrackingRecHitBuilder > theTrackerRecHitBuilder
std::string thePropagatorName
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
unsigned int pxfDisk(const DetId &id) const
T y() const
Definition: PV3DBase.h:63
GlobalPoint globalPosition() const
void setServices(const edm::EventSetup &)
set the services needed by the TrackTransformer
unsigned int tidWheel(const DetId &id) const
PropagationDirection
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
edm::ESHandle< TransientTrackingRecHitBuilder > theMuonRecHitBuilder
void checkMuonHits(const reco::Track &, ConstRecHitContainer &, std::map< DetId, int > &) const
check muon RecHits, calculate chamber occupancy and select hits to be used in the final fit ...
TrajectoryStateOnSurface innermostMeasurementState() const
std::vector< int > theDYTthrs
void getFirstHits(const reco::Track &, ConstRecHitContainer &, ConstRecHitContainer &) const
get the RecHits in the tracker and the first muon chamber with hits
const edm::Event * theEvent
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:45
DataContainer const & measurements() const
Definition: Trajectory.h:215
const int keep
static const int CSC
Definition: MuonSubdetId.h:15
T mag() const
Definition: PV3DBase.h:67
edm::ESHandle< TrajectoryFitter > theFitter
ConstRecHitContainer selectMuonHits(const Trajectory &, const std::map< DetId, int > &) const
select muon hits compatible with trajectory; check hits in chambers with showers
ConstRecHitContainer getRidOfSelectStationHits(const ConstRecHitContainer &hits, const TrackerTopology *tTopo) const
T sqrt(T t)
Definition: SSEVec.h:48
double pt() const
track transverse momentum
Definition: TrackBase.h:131
T z() const
Definition: PV3DBase.h:64
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:59
CSCDetId chamberId() const
Definition: CSCDetId.h:55
edm::Handle< CSCRecHit2DCollection > theCSCRecHits
RefitDirection checkRecHitsOrdering(const ConstRecHitContainer &) const
TrajectoryStateOnSurface outermostMeasurementState() const
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
#define LogTrace(id)
edm::InputTag theDTRecHitLabel
unsigned int pxbLayer(const DetId &id) const
std::vector< ConstRecHitPointer > ConstRecHitContainer
virtual void setEvent(const edm::Event &)
pass the Event to the algo at each event
GlobalMuonRefitter(const edm::ParameterSet &, const MuonServiceProxy *)
constructor with Parameter Set and MuonServiceProxy
Definition: DetId.h:20
void setThr(int, int, int)
const T & get() const
Definition: EventSetup.h:55
GlobalVector globalMomentum() const
static const int RPC
Definition: MuonSubdetId.h:16
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
int station() const
Definition: CSCDetId.h:88
static const int DT
Definition: MuonSubdetId.h:14
virtual ~GlobalMuonRefitter()
destructor
unsigned long long theCacheId_TRH
int station() const
Return the station number.
Definition: DTChamberId.h:53
T x() const
Definition: PV3DBase.h:62
std::string theTrackerRecHitBuilderName
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
unsigned int tecWheel(const DetId &id) const
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:61
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
std::vector< Trajectory > refit(const reco::Track &globalTrack, const int theMuonHitsOption, const TrackerTopology *tTopo) const
build combined trajectory from sta Track and tracker RecHits
unsigned int tobLayer(const DetId &id) const
edm::InputTag theCSCRecHitLabel
std::vector< Trajectory > transform(const reco::Track &newTrack, const reco::TransientTrack track, const TransientTrackingRecHit::ConstRecHitContainer &recHitsForReFit) const
refit the track with a new set of RecHits
T dot(const Basic3DVector &rh) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
int station() const
Definition: RPCDetId.h:99