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