CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
GlobalCosmicMuonTrajectoryBuilder Class Reference

#include <GlobalCosmicMuonTrajectoryBuilder.h>

Inheritance diagram for GlobalCosmicMuonTrajectoryBuilder:
MuonTrajectoryBuilder

Public Types

typedef MuonTransientTrackingRecHit::ConstMuonRecHitContainer ConstMuonRecHitContainer
 
typedef MuonTransientTrackingRecHit::ConstMuonRecHitPointer ConstMuonRecHitPointer
 
typedef TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
 
typedef TransientTrackingRecHit::ConstRecHitPointer ConstRecHitPointer
 
typedef MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
 
typedef MuonTransientTrackingRecHit::MuonRecHitPointer MuonRecHitPointer
 
typedef TransientTrackingRecHit::RecHitContainer RecHitContainer
 
typedef TransientTrackingRecHit::RecHitPointer RecHitPointer
 
typedef std::pair< const Trajectory *, reco::TrackRefTrackCand
 
- Public Types inherited from MuonTrajectoryBuilder
typedef MuonCandidate::CandidateContainer CandidateContainer
 
typedef std::pair< const Trajectory *, reco::TrackRefTrackCand
 
typedef MuonCandidate::TrajectoryContainer TrajectoryContainer
 

Public Member Functions

 GlobalCosmicMuonTrajectoryBuilder (const edm::ParameterSet &, const MuonServiceProxy *service, edm::ConsumesCollector &iC)
 Constructor. More...
 
std::vector< TrackCandmatch (const TrackCand &, const edm::Handle< reco::TrackCollection > &)
 check if tk and muon Tracks are matched More...
 
const Propagatorpropagator () const
 
void setEvent (const edm::Event &) override
 pass the Event to the algo at each event More...
 
CandidateContainer trajectories (const TrackCand &) override
 choose tk Track and build combined trajectories More...
 
TrajectoryContainer trajectories (const TrajectorySeed &) override
 dummy implementation, unused in this class More...
 
 ~GlobalCosmicMuonTrajectoryBuilder () override
 Destructor. More...
 
- Public Member Functions inherited from MuonTrajectoryBuilder
 MuonTrajectoryBuilder ()
 constructor More...
 
virtual ~MuonTrajectoryBuilder ()
 destructor More...
 

Private Member Functions

ConstRecHitContainer getTransientRecHits (const reco::Track &) const
 
bool isTraversing (const reco::Track &tk) const
 
CosmicMuonSmoothersmoother () const
 
void sortHits (ConstRecHitContainer &, ConstRecHitContainer &, ConstRecHitContainer &)
 
const CosmicMuonUtilitiesutilities () const
 

Private Attributes

const std::vector< Trajectory > * allTrackerTrajs
 
std::string category_
 
edm::ESHandle< TransientTrackingRecHitBuildertheMuonRecHitBuilder
 
std::string theMuonRecHitBuilderName
 
std::string thePropagatorName
 
const MuonServiceProxytheService
 
CosmicMuonSmoothertheSmoother
 
edm::EDGetTokenT< reco::TrackCollectiontheTkTrackToken
 
edm::ESHandle< TransientTrackingRecHitBuildertheTrackerRecHitBuilder
 
std::string theTrackerRecHitBuilderName
 
edm::Handle< reco::TrackCollectiontheTrackerTracks
 
GlobalMuonTrackMatchertheTrackMatcher
 
bool tkTrajsAvailable
 

Detailed Description

Definition at line 36 of file GlobalCosmicMuonTrajectoryBuilder.h.

Member Typedef Documentation

◆ ConstMuonRecHitContainer

Definition at line 46 of file GlobalCosmicMuonTrajectoryBuilder.h.

◆ ConstMuonRecHitPointer

Definition at line 44 of file GlobalCosmicMuonTrajectoryBuilder.h.

◆ ConstRecHitContainer

Definition at line 39 of file GlobalCosmicMuonTrajectoryBuilder.h.

◆ ConstRecHitPointer

Definition at line 41 of file GlobalCosmicMuonTrajectoryBuilder.h.

◆ MuonRecHitContainer

Definition at line 45 of file GlobalCosmicMuonTrajectoryBuilder.h.

◆ MuonRecHitPointer

Definition at line 43 of file GlobalCosmicMuonTrajectoryBuilder.h.

◆ RecHitContainer

Definition at line 38 of file GlobalCosmicMuonTrajectoryBuilder.h.

◆ RecHitPointer

Definition at line 40 of file GlobalCosmicMuonTrajectoryBuilder.h.

◆ TrackCand

Definition at line 47 of file GlobalCosmicMuonTrajectoryBuilder.h.

Constructor & Destructor Documentation

◆ GlobalCosmicMuonTrajectoryBuilder()

GlobalCosmicMuonTrajectoryBuilder::GlobalCosmicMuonTrajectoryBuilder ( const edm::ParameterSet par,
const MuonServiceProxy service,
edm::ConsumesCollector iC 
)

Constructor.

Definition at line 30 of file GlobalCosmicMuonTrajectoryBuilder.cc.

33  : theService(service) {
34  ParameterSet smootherPSet = par.getParameter<ParameterSet>("SmootherParameters");
35  theSmoother = new CosmicMuonSmoother(smootherPSet, theService);
36 
37  ParameterSet trackMatcherPSet = par.getParameter<ParameterSet>("GlobalMuonTrackMatcher");
38  theTrackMatcher = new GlobalMuonTrackMatcher(trackMatcherPSet, theService);
39 
40  theTkTrackToken = iC.consumes<reco::TrackCollection>(par.getParameter<InputTag>("TkTrackCollectionLabel"));
41 
42  theTrackerRecHitBuilderName = par.getParameter<string>("TrackerRecHitBuilder");
43  theMuonRecHitBuilderName = par.getParameter<string>("MuonRecHitBuilder");
44  thePropagatorName = par.getParameter<string>("Propagator");
45  category_ = "Muon|RecoMuon|CosmicMuon|GlobalCosmicMuonTrajectoryBuilder";
46 }

References category_, edm::ConsumesCollector::consumes(), edm::ParameterSet::getParameter(), HLT_2018_cff::GlobalMuonTrackMatcher, theMuonRecHitBuilderName, thePropagatorName, theService, theSmoother, theTkTrackToken, theTrackerRecHitBuilderName, and theTrackMatcher.

◆ ~GlobalCosmicMuonTrajectoryBuilder()

GlobalCosmicMuonTrajectoryBuilder::~GlobalCosmicMuonTrajectoryBuilder ( )
override

Destructor.

Definition at line 52 of file GlobalCosmicMuonTrajectoryBuilder.cc.

52  {
53  if (theSmoother)
54  delete theSmoother;
55  if (theTrackMatcher)
56  delete theTrackMatcher;
57 }

References theSmoother, and theTrackMatcher.

Member Function Documentation

◆ getTransientRecHits()

TransientTrackingRecHit::ConstRecHitContainer GlobalCosmicMuonTrajectoryBuilder::getTransientRecHits ( const reco::Track track) const
private

Definition at line 317 of file GlobalCosmicMuonTrajectoryBuilder.cc.

318  {
320 
321  auto hitCloner = static_cast<TkTransientTrackingRecHitBuilder const*>(theTrackerRecHitBuilder.product())->cloner();
323  track, *theService->trackingGeometry(), &*theService->magneticField());
324  for (trackingRecHit_iterator hit = track.recHitsBegin(); hit != track.recHitsEnd(); ++hit) {
325  if ((*hit)->isValid()) {
326  DetId recoid = (*hit)->geographicalId();
327  if (recoid.det() == DetId::Tracker) {
328  TrajectoryStateOnSurface predTsos =
329  theService->propagator(thePropagatorName)
330  ->propagate(currTsos, theService->trackingGeometry()->idToDet(recoid)->surface());
331  LogTrace(category_) << "predtsos " << predTsos.isValid();
332  if (predTsos.isValid()) {
333  currTsos = predTsos;
334  result.emplace_back(hitCloner(**hit, predTsos));
335  }
336  } else if (recoid.det() == DetId::Muon) {
337  result.push_back(theMuonRecHitBuilder->build(&**hit));
338  }
339  }
340  }
341  return result;
342 }

References TransientTrackingRecHitBuilder::build(), category_, DetId::det(), trajectoryStateTransform::innerStateOnSurface(), TrajectoryStateOnSurface::isValid(), LogTrace, DetId::Muon, edm::ESHandle< T >::product(), mps_fire::result, theMuonRecHitBuilder, thePropagatorName, theService, theTrackerRecHitBuilder, HLT_2018_cff::track, and DetId::Tracker.

Referenced by trajectories().

◆ isTraversing()

bool GlobalCosmicMuonTrajectoryBuilder::isTraversing ( const reco::Track tk) const
private

Definition at line 467 of file GlobalCosmicMuonTrajectoryBuilder.cc.

467  {
469  for (trackingRecHit_iterator hit = track.recHitsBegin(); hit != track.recHitsEnd(); ++hit) {
470  if ((*hit)->isValid()) {
471  firstValid = hit;
472  break;
473  }
474  }
475 
476  trackingRecHit_iterator lastValid;
477  for (trackingRecHit_iterator hit = track.recHitsEnd() - 1; hit != track.recHitsBegin() - 1; --hit) {
478  if ((*hit)->isValid()) {
479  lastValid = hit;
480  break;
481  }
482  }
483 
484  GlobalPoint posFirst = theService->trackingGeometry()->idToDet((*firstValid)->geographicalId())->position();
485 
486  GlobalPoint posLast = theService->trackingGeometry()->idToDet((*lastValid)->geographicalId())->position();
487 
488  GlobalPoint middle(
489  (posFirst.x() + posLast.x()) / 2, (posFirst.y() + posLast.y()) / 2, (posFirst.z() + posLast.z()) / 2);
490 
491  if ((middle.mag() < posFirst.mag()) && (middle.mag() < posLast.mag())) {
492  return true;
493  }
494  return false;
495 }

References align_cfg::firstValid, PV3DBase< T, PVType, FrameType >::mag(), position, theService, HLT_2018_cff::track, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by match().

◆ match()

std::vector< GlobalCosmicMuonTrajectoryBuilder::TrackCand > GlobalCosmicMuonTrajectoryBuilder::match ( const TrackCand mu,
const edm::Handle< reco::TrackCollection > &  tktracks 
)

check if tk and muon Tracks are matched

Definition at line 344 of file GlobalCosmicMuonTrajectoryBuilder.cc.

345  {
346  std::vector<TrackCand> result;
347 
349  *(mu.second), *theService->trackingGeometry(), &*theService->magneticField());
351  *(mu.second), *theService->trackingGeometry(), &*theService->magneticField());
352  //build tracker TrackCands and pick the best match if size greater than 2
353  vector<TrackCand> tkTrackCands;
354  for (reco::TrackCollection::size_type i = 0; i < theTrackerTracks->size(); ++i) {
356  TrackCand tkCand = TrackCand((Trajectory*)nullptr, tkTrack);
357  tkTrackCands.push_back(tkCand);
358  LogTrace(category_) << "chisq is " << theTrackMatcher->match(mu, tkCand, 0, 0);
359  LogTrace(category_) << "d is " << theTrackMatcher->match(mu, tkCand, 1, 0);
360  LogTrace(category_) << "r_pos is " << theTrackMatcher->match(mu, tkCand, 2, 0);
361  }
362 
363  // now if only 1 tracker tracks, return it
364  if (tkTrackCands.size() <= 1) {
365  return tkTrackCands;
366  }
367 
368  // if there're many tracker tracks
369 
370  // if muon is only on one side
371  GlobalPoint innerPos = innerTsos.globalPosition();
372  GlobalPoint outerPos = outerTsos.globalPosition();
373 
374  if ((innerPos.basicVector().dot(innerTsos.globalMomentum().basicVector()) *
375  outerPos.basicVector().dot(outerTsos.globalMomentum().basicVector()) >
376  0)) {
377  GlobalPoint geoInnerPos = (innerPos.mag() < outerPos.mag()) ? innerPos : outerPos;
378  LogTrace(category_) << "geoInnerPos Mu " << geoInnerPos << endl;
379 
380  // if there're tracker tracks totally on the other half
381  // and there're tracker tracks on the same half
382  // remove the tracks on the other half
383  for (vector<TrackCand>::const_iterator itkCand = tkTrackCands.begin(); itkCand != tkTrackCands.end(); ++itkCand) {
384  reco::TrackRef tkTrack = itkCand->second;
385 
386  GlobalPoint tkInnerPos(tkTrack->innerPosition().x(), tkTrack->innerPosition().y(), tkTrack->innerPosition().z());
387  GlobalPoint tkOuterPos(tkTrack->outerPosition().x(), tkTrack->outerPosition().y(), tkTrack->outerPosition().z());
388  LogTrace(category_) << "tkTrack " << tkInnerPos << " " << tkOuterPos << endl;
389 
390  float closetDistance11 = (geoInnerPos - tkInnerPos).mag();
391  float closetDistance12 = (geoInnerPos - tkOuterPos).mag();
392  float closetDistance1 = (closetDistance11 < closetDistance12) ? closetDistance11 : closetDistance12;
393  LogTrace(category_) << "closetDistance1 " << closetDistance1 << endl;
394 
395  if (true || !isTraversing(*tkTrack)) {
396  bool keep = true;
397  for (vector<TrackCand>::const_iterator itkCand2 = tkTrackCands.begin(); itkCand2 != tkTrackCands.end();
398  ++itkCand2) {
399  if (itkCand2 == itkCand)
400  continue;
401  reco::TrackRef tkTrack2 = itkCand2->second;
402 
403  GlobalPoint tkInnerPos2(
404  tkTrack2->innerPosition().x(), tkTrack2->innerPosition().y(), tkTrack2->innerPosition().z());
405  GlobalPoint tkOuterPos2(
406  tkTrack2->outerPosition().x(), tkTrack2->outerPosition().y(), tkTrack2->outerPosition().z());
407  LogTrace(category_) << "tkTrack2 " << tkInnerPos2 << " " << tkOuterPos2 << endl;
408 
409  float farthestDistance21 = (geoInnerPos - tkInnerPos2).mag();
410  float farthestDistance22 = (geoInnerPos - tkOuterPos2).mag();
411  float farthestDistance2 = (farthestDistance21 > farthestDistance22) ? farthestDistance21 : farthestDistance22;
412  LogTrace(category_) << "farthestDistance2 " << farthestDistance2 << endl;
413 
414  if (closetDistance1 > farthestDistance2 - 1e-3) {
415  keep = false;
416  break;
417  }
418  }
419  if (keep)
420  result.push_back(*itkCand);
421  else
422  LogTrace(category_) << "The Track is on different hemisphere" << endl;
423  } else {
424  result.push_back(*itkCand);
425  }
426  }
427  if (result.empty()) {
428  //if all tk tracks on the other side, still keep them
429  result = tkTrackCands;
430  }
431  } else { // muon is traversing
432  result = tkTrackCands;
433  }
434 
435  // match muCand to tkTrackCands
436  vector<TrackCand> matched_trackerTracks = theTrackMatcher->match(mu, result);
437 
438  LogTrace(category_) << "TrackMatcher found " << matched_trackerTracks.size() << "tracker tracks matched";
439 
440  //now pick the best matched one
441  if (matched_trackerTracks.size() < 2) {
442  return matched_trackerTracks;
443  } else {
444  // in case of more than 1 tkTrack,
445  // select the best-one based on distance (matchOption==1)
446  // at innermost Mu hit surface. (surfaceOption == 0)
447  result.clear();
449 
450  double quality = 1e6;
451  double max_quality = 1e6;
452  for (vector<TrackCand>::const_iterator iter = matched_trackerTracks.begin(); iter != matched_trackerTracks.end();
453  iter++) {
454  quality = theTrackMatcher->match(mu, *iter, 1, 0);
455  LogTrace(category_) << " quality of tracker track is " << quality;
456  if (quality < max_quality) {
457  max_quality = quality;
458  bestMatch = (*iter);
459  }
460  }
461  LogTrace(category_) << " Picked tracker track with quality " << max_quality;
462  result.push_back(bestMatch);
463  return result;
464  }
465 }

References PV3DBase< T, PVType, FrameType >::basicVector(), deltar::bestMatch(), category_, Basic3DVector< T >::dot(), MillePedeFileConverter_cfg::e, TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), mps_fire::i, trajectoryStateTransform::innerStateOnSurface(), isTraversing(), keep, LogTrace, PV3DBase< T, PVType, FrameType >::mag(), mag(), GlobalMuonTrackMatcher::match(), amptDefaultParameters_cff::mu, trajectoryStateTransform::outerStateOnSurface(), qcdUeDQM_cfi::quality, mps_fire::result, theService, theTrackerTracks, and theTrackMatcher.

Referenced by trajectories().

◆ propagator()

const Propagator* GlobalCosmicMuonTrajectoryBuilder::propagator ( ) const
inline

◆ setEvent()

void GlobalCosmicMuonTrajectoryBuilder::setEvent ( const edm::Event event)
overridevirtual

pass the Event to the algo at each event

Implements MuonTrajectoryBuilder.

Definition at line 62 of file GlobalCosmicMuonTrajectoryBuilder.cc.

62  {
63  event.getByToken(theTkTrackToken, theTrackerTracks);
64 
65  // edm::Handle<std::vector<Trajectory> > handleTrackerTrajs;
66  // if ( event.getByLabel(theTkTrackLabel,handleTrackerTrajs) && handleTrackerTrajs.isValid() ) {
67  // tkTrajsAvailable = true;
68  // allTrackerTrajs = &*handleTrackerTrajs;
69  // LogInfo("GlobalCosmicMuonTrajectoryBuilder")
70  // << "Tk Trajectories Found! " << endl;
71  // } else {
72  // LogInfo("GlobalCosmicMuonTrajectoryBuilder")
73  // << "No Tk Trajectories Found! " << endl;
74  // tkTrajsAvailable = false;
75  // }
76 
79 }

References get, theMuonRecHitBuilder, theMuonRecHitBuilderName, theService, theTkTrackToken, theTrackerRecHitBuilder, theTrackerRecHitBuilderName, and theTrackerTracks.

◆ smoother()

CosmicMuonSmoother* GlobalCosmicMuonTrajectoryBuilder::smoother ( ) const
inlineprivate

Definition at line 75 of file GlobalCosmicMuonTrajectoryBuilder.h.

75 { return theSmoother; }

References theSmoother.

Referenced by utilities().

◆ sortHits()

void GlobalCosmicMuonTrajectoryBuilder::sortHits ( ConstRecHitContainer hits,
ConstRecHitContainer muonHits,
ConstRecHitContainer tkHits 
)
private

Definition at line 209 of file GlobalCosmicMuonTrajectoryBuilder.cc.

211  {
212  if (tkHits.empty()) {
213  LogTrace(category_) << "No valid tracker hits";
214  return;
215  }
216  if (muonHits.empty()) {
217  LogTrace(category_) << "No valid muon hits";
218  return;
219  }
220 
221  ConstRecHitContainer::const_iterator frontTkHit = tkHits.begin();
222  ConstRecHitContainer::const_iterator backTkHit = tkHits.end() - 1;
223  while (!(*frontTkHit)->isValid() && frontTkHit != backTkHit) {
224  frontTkHit++;
225  }
226  while (!(*backTkHit)->isValid() && backTkHit != frontTkHit) {
227  backTkHit--;
228  }
229 
230  ConstRecHitContainer::const_iterator frontMuHit = muonHits.begin();
231  ConstRecHitContainer::const_iterator backMuHit = muonHits.end() - 1;
232  while (!(*frontMuHit)->isValid() && frontMuHit != backMuHit) {
233  frontMuHit++;
234  }
235  while (!(*backMuHit)->isValid() && backMuHit != frontMuHit) {
236  backMuHit--;
237  }
238 
239  if (frontTkHit == backTkHit) {
240  LogTrace(category_) << "No valid tracker hits";
241  return;
242  }
243  if (frontMuHit == backMuHit) {
244  LogTrace(category_) << "No valid muon hits";
245  return;
246  }
247 
248  GlobalPoint frontTkPos = (*frontTkHit)->globalPosition();
249  GlobalPoint backTkPos = (*backTkHit)->globalPosition();
250 
251  GlobalPoint frontMuPos = (*frontMuHit)->globalPosition();
252  GlobalPoint backMuPos = (*backMuHit)->globalPosition();
253 
254  //sort hits going from higher to lower positions
255  if (frontTkPos.y() < backTkPos.y()) { //check if tk hits order same direction
256  reverse(tkHits.begin(), tkHits.end());
257  }
258 
259  if (frontMuPos.y() < backMuPos.y()) {
260  reverse(muonHits.begin(), muonHits.end());
261  }
262 
263  // LogTrace(category_)<< "tkHits after sort: "<<tkHits.size()<<endl;;
264  // LogTrace(category_) <<utilities()->print(tkHits)<<endl;
265  // LogTrace(category_) << "== End of tkHits == "<<endl;
266 
267  // LogTrace(category_)<< "muonHits after sort: "<<muonHits.size()<<endl;;
268  // LogTrace(category_) <<utilities()->print(muonHits)<<endl;
269  // LogTrace(category_)<< "== End of muonHits == "<<endl;
270 
271  //separate muon hits into 2 different hemisphere
272  ConstRecHitContainer::iterator middlepoint = muonHits.begin();
273  bool insertInMiddle = false;
274 
275  for (ConstRecHitContainer::iterator ihit = muonHits.begin(); ihit != muonHits.end() - 1; ihit++) {
276  GlobalPoint ipos = (*ihit)->globalPosition();
277  GlobalPoint nextpos = (*(ihit + 1))->globalPosition();
278  if ((ipos - nextpos).mag() < 100.0)
279  continue;
280 
281  GlobalPoint middle((ipos.x() + nextpos.x()) / 2, (ipos.y() + nextpos.y()) / 2, (ipos.z() + nextpos.z()) / 2);
282  LogTrace(category_) << "ipos " << ipos << "nextpos" << nextpos << " middle " << middle << endl;
283  if ((middle.perp() < ipos.perp()) && (middle.perp() < nextpos.perp())) {
284  LogTrace(category_) << "found middlepoint" << endl;
285  middlepoint = ihit;
286  insertInMiddle = true;
287  break;
288  }
289  }
290 
291  //insert track hits in correct order
292  if (insertInMiddle) { //if tk hits should be sandwich
293  GlobalPoint jointpointpos = (*middlepoint)->globalPosition();
294  LogTrace(category_) << "jointpoint " << jointpointpos << endl;
295  if ((frontTkPos - jointpointpos).mag() >
296  (backTkPos - jointpointpos).mag()) { //check if tk hits order same direction
297  reverse(tkHits.begin(), tkHits.end());
298  }
299  muonHits.insert(middlepoint + 1, tkHits.begin(), tkHits.end());
300  hits = muonHits;
301  } else { // append at one end
302  if (frontTkPos.y() < frontMuPos.y()) { //insert at the end
303  LogTrace(category_) << "insert at the end " << frontTkPos << frontMuPos << endl;
304 
305  hits = muonHits;
306  hits.insert(hits.end(), tkHits.begin(), tkHits.end());
307  } else { //insert at the beginning
308  LogTrace(category_) << "insert at the beginning " << frontTkPos << frontMuPos << endl;
309  hits = tkHits;
310  hits.insert(hits.end(), muonHits.begin(), muonHits.end());
311  }
312  }
313 }

References category_, hfClusterShapes_cfi::hits, LogTrace, mag(), PV3DBase< T, PVType, FrameType >::perp(), groupFilesInBlocks::reverse, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by trajectories().

◆ trajectories() [1/2]

MuonCandidate::CandidateContainer GlobalCosmicMuonTrajectoryBuilder::trajectories ( const TrackCand muCand)
overridevirtual

choose tk Track and build combined trajectories

Implements MuonTrajectoryBuilder.

Definition at line 84 of file GlobalCosmicMuonTrajectoryBuilder.cc.

84  {
86 
87  if (!theTrackerTracks.isValid()) {
88  LogTrace(category_) << "Tracker Track collection is invalid!!!";
89  return result;
90  }
91 
92  LogTrace(category_) << "Found " << theTrackerTracks->size() << " tracker Tracks";
93  if (theTrackerTracks->empty())
94  return result;
95 
96  vector<TrackCand> matched = match(muCand, theTrackerTracks);
97 
98  LogTrace(category_) << "TrackMatcher found " << matched.size() << "tracker tracks matched";
99 
100  if (matched.empty())
101  return result;
102  reco::TrackRef tkTrack = matched.front().second;
103 
104  if (tkTrack.isNull())
105  return result;
106  reco::TrackRef muTrack = muCand.second;
107 
108  ConstRecHitContainer muRecHits;
109 
110  if (muCand.first == nullptr || !muCand.first->isValid()) {
111  muRecHits = getTransientRecHits(*muTrack);
112  } else {
113  muRecHits = muCand.first->recHits();
114  }
115 
116  LogTrace(category_) << "mu RecHits: " << muRecHits.size();
117 
118  ConstRecHitContainer tkRecHits = getTransientRecHits(*tkTrack);
119 
120  // if ( !tkTrajsAvailable ) {
121  // tkRecHits = getTransientRecHits(*tkTrack);
122  // } else {
123  // tkRecHits = allTrackerTrajs->front().recHits();
124  // }
125 
126  ConstRecHitContainer hits; //= tkRecHits;
127  LogTrace(category_) << "tk RecHits: " << tkRecHits.size();
128 
129  // hits.insert(hits.end(), muRecHits.begin(), muRecHits.end());
130  // stable_sort(hits.begin(), hits.end(), DecreasingGlobalY());
131 
132  sortHits(hits, muRecHits, tkRecHits);
133 
134  // LogTrace(category_)<< "Used RecHits after sort: "<<hits.size()<<endl;;
135  // LogTrace(category_) <<utilities()->print(hits)<<endl;
136  // LogTrace(category_) << "== End of Used RecHits == "<<endl;
137 
139  *muTrack, *theService->trackingGeometry(), &*theService->magneticField());
141  *tkTrack, *theService->trackingGeometry(), &*theService->magneticField());
142 
144  *muTrack, *theService->trackingGeometry(), &*theService->magneticField());
146  *tkTrack, *theService->trackingGeometry(), &*theService->magneticField());
147 
148  TrajectoryStateOnSurface firstState1 =
149  (muonState1.globalPosition().y() > tkState1.globalPosition().y()) ? muonState1 : tkState1;
150  TrajectoryStateOnSurface firstState2 =
151  (muonState2.globalPosition().y() > tkState2.globalPosition().y()) ? muonState2 : tkState2;
152 
153  TrajectoryStateOnSurface firstState =
154  (firstState1.globalPosition().y() > firstState2.globalPosition().y()) ? firstState1 : firstState2;
155 
156  GlobalPoint front, back;
157  if (!hits.empty()) {
158  front = hits.front()->globalPosition();
159  back = hits.back()->globalPosition();
160  if ((front.perp() < 130 && fabs(front.z()) < 300) || (back.perp() < 130 && fabs(back.z()) < 300)) {
161  if (hits.front()->globalPosition().perp() > hits.back()->globalPosition().perp())
162  reverse(hits.begin(), hits.end());
164  *tkTrack, *theService->trackingGeometry(), &*theService->magneticField());
166  *tkTrack, *theService->trackingGeometry(), &*theService->magneticField());
167  firstState = (tkState1.globalPosition().perp() < tkState2.globalPosition().perp()) ? tkState1 : tkState2;
168  }
169  }
170  if (!firstState.isValid())
171  return result;
172  LogTrace(category_) << "firstTSOS pos: " << firstState.globalPosition() << "mom: " << firstState.globalMomentum();
173 
174  // begin refitting
175 
177  vector<Trajectory> refitted = theSmoother->trajectories(seed, hits, firstState);
178 
179  if (refitted.empty()) {
180  LogTrace(category_) << "smoothing trajectories fail";
181  refitted = theSmoother->fit(seed, hits, firstState); //FIXME
182  }
183 
184  if (refitted.empty()) {
185  LogTrace(category_) << "refit fail";
186  return result;
187  }
188 
189  auto myTraj = std::make_unique<Trajectory>(refitted.front());
190 
191  const std::vector<TrajectoryMeasurement>& mytms = myTraj->measurements();
192  LogTrace(category_) << "measurements in final trajectory " << mytms.size();
193  LogTrace(category_) << "Orignally there are " << tkTrack->found() << " tk rhs and " << muTrack->found() << " mu rhs.";
194 
195  if (mytms.size() <= tkTrack->found()) {
196  LogTrace(category_) << "insufficient measurements. skip... ";
197  return result;
198  }
199 
200  result.push_back(std::make_unique<MuonCandidate>(std::move(myTraj), muTrack, tkTrack));
201  LogTrace(category_) << "final global cosmic muon: ";
202  for (std::vector<TrajectoryMeasurement>::const_iterator itm = mytms.begin(); itm != mytms.end(); ++itm) {
203  LogTrace(category_) << "updated pos " << itm->updatedState().globalPosition() << "mom "
204  << itm->updatedState().globalMomentum();
205  }
206  return result;
207 }

References category_, CosmicMuonSmoother::fit(), getTransientRecHits(), TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), hfClusterShapes_cfi::hits, trajectoryStateTransform::innerStateOnSurface(), edm::Ref< C, T, F >::isNull(), TrajectoryStateOnSurface::isValid(), edm::HandleBase::isValid(), LogTrace, match(), muonTagProbeFilters_cff::matched, eostools::move(), trajectoryStateTransform::outerStateOnSurface(), PV3DBase< T, PVType, FrameType >::perp(), mps_fire::result, groupFilesInBlocks::reverse, SurveyInfoScenario_cff::seed, sortHits(), theService, theSmoother, theTrackerTracks, CosmicMuonSmoother::trajectories(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

◆ trajectories() [2/2]

TrajectoryContainer GlobalCosmicMuonTrajectoryBuilder::trajectories ( const TrajectorySeed )
inlineoverridevirtual

dummy implementation, unused in this class

Implements MuonTrajectoryBuilder.

Definition at line 58 of file GlobalCosmicMuonTrajectoryBuilder.h.

58 { return TrajectoryContainer{}; }

◆ utilities()

const CosmicMuonUtilities* GlobalCosmicMuonTrajectoryBuilder::utilities ( ) const
inlineprivate

Definition at line 77 of file GlobalCosmicMuonTrajectoryBuilder.h.

77 { return smoother()->utilities(); }

References smoother(), and CosmicMuonSmoother::utilities().

Member Data Documentation

◆ allTrackerTrajs

const std::vector<Trajectory>* GlobalCosmicMuonTrajectoryBuilder::allTrackerTrajs
private

Definition at line 100 of file GlobalCosmicMuonTrajectoryBuilder.h.

◆ category_

std::string GlobalCosmicMuonTrajectoryBuilder::category_
private

◆ theMuonRecHitBuilder

edm::ESHandle<TransientTrackingRecHitBuilder> GlobalCosmicMuonTrajectoryBuilder::theMuonRecHitBuilder
private

Definition at line 94 of file GlobalCosmicMuonTrajectoryBuilder.h.

Referenced by getTransientRecHits(), and setEvent().

◆ theMuonRecHitBuilderName

std::string GlobalCosmicMuonTrajectoryBuilder::theMuonRecHitBuilderName
private

◆ thePropagatorName

std::string GlobalCosmicMuonTrajectoryBuilder::thePropagatorName
private

◆ theService

const MuonServiceProxy* GlobalCosmicMuonTrajectoryBuilder::theService
private

◆ theSmoother

CosmicMuonSmoother* GlobalCosmicMuonTrajectoryBuilder::theSmoother
private

◆ theTkTrackToken

edm::EDGetTokenT<reco::TrackCollection> GlobalCosmicMuonTrajectoryBuilder::theTkTrackToken
private

◆ theTrackerRecHitBuilder

edm::ESHandle<TransientTrackingRecHitBuilder> GlobalCosmicMuonTrajectoryBuilder::theTrackerRecHitBuilder
private

Definition at line 91 of file GlobalCosmicMuonTrajectoryBuilder.h.

Referenced by getTransientRecHits(), and setEvent().

◆ theTrackerRecHitBuilderName

std::string GlobalCosmicMuonTrajectoryBuilder::theTrackerRecHitBuilderName
private

◆ theTrackerTracks

edm::Handle<reco::TrackCollection> GlobalCosmicMuonTrajectoryBuilder::theTrackerTracks
private

Definition at line 96 of file GlobalCosmicMuonTrajectoryBuilder.h.

Referenced by match(), setEvent(), and trajectories().

◆ theTrackMatcher

GlobalMuonTrackMatcher* GlobalCosmicMuonTrajectoryBuilder::theTrackMatcher
private

◆ tkTrajsAvailable

bool GlobalCosmicMuonTrajectoryBuilder::tkTrajsAvailable
private

Definition at line 98 of file GlobalCosmicMuonTrajectoryBuilder.h.

muonTagProbeFilters_cff.matched
matched
Definition: muonTagProbeFilters_cff.py:62
CosmicMuonSmoother::trajectories
TrajectoryContainer trajectories(const Trajectory &traj) const override
Definition: CosmicMuonSmoother.h:45
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
service
Definition: service.py:1
CosmicMuonSmoother::fit
std::vector< Trajectory > fit(const Trajectory &) const
Definition: CosmicMuonSmoother.cc:93
mps_fire.i
i
Definition: mps_fire.py:355
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
CosmicMuonSmoother
Definition: CosmicMuonSmoother.h:38
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
GlobalMuonTrackMatcher::match
double match(const TrackCand &sta, const TrackCand &track, int matchOption=0, int surfaceOption=1) const
Definition: GlobalMuonTrackMatcher.cc:100
GlobalCosmicMuonTrajectoryBuilder::sortHits
void sortHits(ConstRecHitContainer &, ConstRecHitContainer &, ConstRecHitContainer &)
Definition: GlobalCosmicMuonTrajectoryBuilder.cc:209
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
TransientRecHitRecord
Definition: TransientRecHitRecord.h:14
align_cfg.firstValid
firstValid
Definition: align_cfg.py:68
GlobalCosmicMuonTrajectoryBuilder::getTransientRecHits
ConstRecHitContainer getTransientRecHits(const reco::Track &) const
Definition: GlobalCosmicMuonTrajectoryBuilder.cc:317
TransientTrackingRecHitBuilder::build
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
deltar.bestMatch
def bestMatch(object, matchCollection)
Definition: deltar.py:138
groupFilesInBlocks.reverse
reverse
Definition: groupFilesInBlocks.py:131
edm::Ref< TrackCollection >
trajectoryStateTransform::outerStateOnSurface
TrajectoryStateOnSurface outerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
Definition: TrajectoryStateTransform.cc:118
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
DetId
Definition: DetId.h:17
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
GlobalCosmicMuonTrajectoryBuilder::isTraversing
bool isTraversing(const reco::Track &tk) const
Definition: GlobalCosmicMuonTrajectoryBuilder.cc:467
CosmicMuonSmoother::utilities
const CosmicMuonUtilities * utilities() const
Definition: CosmicMuonSmoother.h:62
Basic3DVector::dot
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.
Definition: extBasic3DVector.h:189
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:49
GlobalCosmicMuonTrajectoryBuilder::TrackCand
std::pair< const Trajectory *, reco::TrackRef > TrackCand
Definition: GlobalCosmicMuonTrajectoryBuilder.h:47
Point3DBase< float, GlobalTag >
edm::OwnVector::const_iterator
Definition: OwnVector.h:41
GlobalCosmicMuonTrajectoryBuilder::theMuonRecHitBuilder
edm::ESHandle< TransientTrackingRecHitBuilder > theMuonRecHitBuilder
Definition: GlobalCosmicMuonTrajectoryBuilder.h:94
edm::ParameterSet
Definition: ParameterSet.h:36
DetId::Tracker
Definition: DetId.h:25
TrackingRecHit::ConstRecHitContainer
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: TrackingRecHit.h:32
GlobalCosmicMuonTrajectoryBuilder::theService
const MuonServiceProxy * theService
Definition: GlobalCosmicMuonTrajectoryBuilder.h:81
GlobalCosmicMuonTrajectoryBuilder::match
std::vector< TrackCand > match(const TrackCand &, const edm::Handle< reco::TrackCollection > &)
check if tk and muon Tracks are matched
Definition: GlobalCosmicMuonTrajectoryBuilder.cc:344
GlobalCosmicMuonTrajectoryBuilder::theTrackMatcher
GlobalMuonTrackMatcher * theTrackMatcher
Definition: GlobalCosmicMuonTrajectoryBuilder.h:85
MuonCandidate::CandidateContainer
std::vector< std::unique_ptr< MuonCandidate > > CandidateContainer
Definition: MuonCandidate.h:18
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
MuonServiceProxy::propagator
edm::ESHandle< Propagator > propagator(std::string propagatorName) const
get the propagator
Definition: MuonServiceProxy.cc:177
get
#define get
PV3DBase::basicVector
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
PV3DBase::mag
T mag() const
Definition: PV3DBase.h:64
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
TrajectoryStateOnSurface::globalMomentum
GlobalVector globalMomentum() const
Definition: TrajectoryStateOnSurface.h:66
mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: Basic3DVectorLD.h:127
GlobalCosmicMuonTrajectoryBuilder::category_
std::string category_
Definition: GlobalCosmicMuonTrajectoryBuilder.h:102
eostools.move
def move(src, dest)
Definition: eostools.py:511
GlobalCosmicMuonTrajectoryBuilder::theMuonRecHitBuilderName
std::string theMuonRecHitBuilderName
Definition: GlobalCosmicMuonTrajectoryBuilder.h:93
MuonTrajectoryBuilder::TrajectoryContainer
MuonCandidate::TrajectoryContainer TrajectoryContainer
Definition: MuonTrajectoryBuilder.h:23
GlobalCosmicMuonTrajectoryBuilder::theTrackerTracks
edm::Handle< reco::TrackCollection > theTrackerTracks
Definition: GlobalCosmicMuonTrajectoryBuilder.h:96
ConstRecHitContainer
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
Definition: MillePedeAlignmentAlgorithm.cc:74
GlobalCosmicMuonTrajectoryBuilder::theTkTrackToken
edm::EDGetTokenT< reco::TrackCollection > theTkTrackToken
Definition: GlobalCosmicMuonTrajectoryBuilder.h:88
qcdUeDQM_cfi.quality
quality
Definition: qcdUeDQM_cfi.py:31
Trajectory
Definition: Trajectory.h:38
HLT_2018_cff.GlobalMuonTrackMatcher
GlobalMuonTrackMatcher
Definition: HLT_2018_cff.py:8323
GlobalCosmicMuonTrajectoryBuilder::thePropagatorName
std::string thePropagatorName
Definition: GlobalCosmicMuonTrajectoryBuilder.h:87
GlobalCosmicMuonTrajectoryBuilder::theSmoother
CosmicMuonSmoother * theSmoother
Definition: GlobalCosmicMuonTrajectoryBuilder.h:83
TrajectorySeed
Definition: TrajectorySeed.h:17
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
GlobalCosmicMuonTrajectoryBuilder::theTrackerRecHitBuilderName
std::string theTrackerRecHitBuilderName
Definition: GlobalCosmicMuonTrajectoryBuilder.h:90
mps_fire.result
result
Definition: mps_fire.py:303
DetId::Muon
Definition: DetId.h:26
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
trajectoryStateTransform::innerStateOnSurface
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
Definition: TrajectoryStateTransform.cc:110
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
keep
const int keep
Definition: GenParticlePruner.cc:48
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
edm::InputTag
Definition: InputTag.h:15
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
GlobalCosmicMuonTrajectoryBuilder::smoother
CosmicMuonSmoother * smoother() const
Definition: GlobalCosmicMuonTrajectoryBuilder.h:75
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295
hit
Definition: SiStripHitEffFromCalibTree.cc:88
GlobalCosmicMuonTrajectoryBuilder::theTrackerRecHitBuilder
edm::ESHandle< TransientTrackingRecHitBuilder > theTrackerRecHitBuilder
Definition: GlobalCosmicMuonTrajectoryBuilder.h:91
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37