CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonTrackLoader.cc
Go to the documentation of this file.
1 
11 
15 
25 
27 
31 
36 
39 
40 using namespace edm;
41 using namespace std;
42 
43 // constructor
45  theService(service){
46 
47 
48  // option to do or not the smoothing step.
49  // the trajectories which are passed to the track loader are supposed to be non-smoothed
50  theSmoothingStep = parameterSet.getParameter<bool>("DoSmoothing");
52  theSmootherName = parameterSet.getParameter<string>("Smoother");
53 
54  // update at vertex
55  theUpdatingAtVtx = parameterSet.getParameter<bool>("VertexConstraint");
56 
57  // beam spot input tag
58  theBeamSpotInputTag = parameterSet.getParameter<edm::InputTag>("beamSpot");
60 
61 
62  // Flag to put the trajectory into the event
63  theTrajectoryFlag = parameterSet.getUntrackedParameter<bool>("PutTrajectoryIntoEvent",true);
64 
65  theL2SeededTkLabel = parameterSet.getUntrackedParameter<string>("MuonSeededTracksInstance",string());
66 
67  ParameterSet updatorPar = parameterSet.getParameter<ParameterSet>("MuonUpdatorAtVertexParameters");
68  theUpdatorAtVtx = new MuonUpdatorAtVertex(updatorPar,service);
69 
70  thePutTkTrackFlag = parameterSet.getUntrackedParameter<bool>("PutTkTrackIntoEvent",false);
71  theSmoothTkTrackFlag = parameterSet.getUntrackedParameter<bool>("SmoothTkTrack",false);
72  theAllowNoVtxFlag = parameterSet.getUntrackedParameter<bool>("AllowNoVertex",false);
73 }
74 
77 }
78 
80 MuonTrackLoader::loadTracks(const TrajectoryContainer& trajectories,
81  Event& event, const string& instance, bool reallyDoSmoothing) {
82  std::vector<bool> dummyVecBool;
83  return loadTracks(trajectories, event, dummyVecBool, instance, reallyDoSmoothing);
84 }
85 
87 MuonTrackLoader::loadTracks(const TrajectoryContainer& trajectories,
88  Event& event, std::vector<bool>& tkBoolVec,
89  const string& instance, bool reallyDoSmoothing) {
90 
91  const bool doSmoothing = theSmoothingStep && reallyDoSmoothing;
92 
93  const string metname = "Muon|RecoMuon|MuonTrackLoader";
94 
95  // the track collectios; they will be loaded in the event
96  auto_ptr<reco::TrackCollection> trackCollection(new reco::TrackCollection());
97  // ... and its reference into the event
98  reco::TrackRefProd trackCollectionRefProd = event.getRefBeforePut<reco::TrackCollection>(instance);
99 
100  // track collection for the tracks updated at vertex
101  auto_ptr<reco::TrackCollection> updatedAtVtxTrackCollection(new reco::TrackCollection());
102  // ... and its (eventually) reference into the event
103  reco::TrackRefProd trackUpdatedCollectionRefProd;
104  if(theUpdatingAtVtx) trackUpdatedCollectionRefProd = event.getRefBeforePut<reco::TrackCollection>(instance+"UpdatedAtVtx");
105 
106  // Association map between updated and non updated at vtx tracks
107  auto_ptr<reco:: TrackToTrackMap> trackToTrackmap(new reco::TrackToTrackMap);
108 
109  // the track extra collection, it will be loaded in the event
110  auto_ptr<reco::TrackExtraCollection> trackExtraCollection(new reco::TrackExtraCollection() );
111  // ... and its reference into the event
112  reco::TrackExtraRefProd trackExtraCollectionRefProd = event.getRefBeforePut<reco::TrackExtraCollection>(instance);
113 
114  // the rechit collection, it will be loaded in the event
115  auto_ptr<TrackingRecHitCollection> recHitCollection(new TrackingRecHitCollection() );
116  // ... and its reference into the event
117  TrackingRecHitRefProd recHitCollectionRefProd = event.getRefBeforePut<TrackingRecHitCollection>(instance);
118 
119  // Collection of Trajectory
120  auto_ptr<vector<Trajectory> > trajectoryCollection(new vector<Trajectory>);
121 
122  // Association map between track and trajectory
123  std::auto_ptr<TrajTrackAssociationCollection> trajTrackMap( new TrajTrackAssociationCollection() );
124 
125  // don't waste any time...
126  if ( trajectories.empty() ) {
127  event.put(recHitCollection,instance);
128  event.put(trackExtraCollection,instance);
129  if(theTrajectoryFlag) {
130  event.put(trajectoryCollection,instance);
131  event.put( trajTrackMap, instance );
132  }
133  if(theUpdatingAtVtx){
134  event.put(trackToTrackmap);
135  event.put(updatedAtVtxTrackCollection,instance+"UpdatedAtVtx");
136  }
137  return event.put(trackCollection,instance);
138  }
139 
141  event.getByToken(theBeamSpotToken, beamSpot);
142 
143  LogTrace(metname) << "Create the collection of Tracks";
144 
145  reco::TrackRef::key_type trackIndex = 0;
146  reco::TrackRef::key_type trackUpdatedIndex = 0;
147 
148  reco::TrackExtraRef::key_type trackExtraIndex = 0;
149  TrackingRecHitRef::key_type recHitsIndex = 0;
150 
152  edm::Ref< std::vector<Trajectory> >::key_type iTjRef = 0;
153  std::map<unsigned int, unsigned int> tjTkMap;
154 
155  if(doSmoothing)
157 
158  unsigned int tjCnt = 0;
159  for(TrajectoryContainer::const_iterator rawTrajectory = trajectories.begin();
160  rawTrajectory != trajectories.end(); ++rawTrajectory, ++tjCnt){
161 
162  Trajectory &trajectory = **rawTrajectory;
163 
164  if(doSmoothing){
165  vector<Trajectory> trajectoriesSM = theSmoother->trajectories(**rawTrajectory);
166 
167  if(!trajectoriesSM.empty()) {
168  const edm::RefToBase<TrajectorySeed> tmpSeedRef = (**rawTrajectory).seedRef();
169  trajectory = trajectoriesSM.front();
170  trajectory.setSeedRef(tmpSeedRef);
171  LogDebug(metname) << "theSeedRef.isNonnull " << trajectory.seedRef().isNonnull();
172  } else
173  LogInfo(metname)<<"The trajectory has not been smoothed!"<<endl;
174  }
175 
176  if(theTrajectoryFlag) {
177  trajectoryCollection->push_back(trajectory);
178  iTjRef++;
179  }
180 
181  // get the transient rechit from the trajectory
182  Trajectory::RecHitContainer transHits = trajectory.recHits();
183 
184  if ( trajectory.direction() == oppositeToMomentum)
185  reverse(transHits.begin(),transHits.end());
186 
187  // build the "bare" track from the trajectory.
188  // This track has the parameters defined at PCA (no update)
189  pair<bool,reco::Track> resultOfTrackExtrapAtPCA = buildTrackAtPCA(trajectory, *beamSpot);
190 
191  // Check if the extrapolation went well
192  if(!resultOfTrackExtrapAtPCA.first) {
193  delete *rawTrajectory;
194  continue;
195  }
196 
197  // take the "bare" track at PCA
198  reco::Track &track = resultOfTrackExtrapAtPCA.second;
199 
200  // build the "bare" track extra from the trajectory
201  reco::TrackExtra trackExtra = buildTrackExtra( trajectory );
202 
203  // get the TrackExtraRef (persitent reference of the track extra)
204  reco::TrackExtraRef trackExtraRef(trackExtraCollectionRefProd, trackExtraIndex++ );
205 
206  // set the persistent track-extra reference to the Track
207  track.setExtra(trackExtraRef);
208 
209  // build the updated-at-vertex track, starting from the previous track
210  pair<bool,reco::Track> updateResult(false,reco::Track());
211 
212  if(theUpdatingAtVtx){
213  // build the "bare" track UPDATED at vtx
214  updateResult = buildTrackUpdatedAtPCA(track, *beamSpot);
215 
216  if(!updateResult.first) ++trackIndex;
217  else{
218 
219  // set the persistent track-extra reference to the Track
220  updateResult.second.setExtra(trackExtraRef);
221 
222  // Fill the map
223  trackToTrackmap->insert(reco::TrackRef(trackCollectionRefProd,trackIndex++),
224  reco::TrackRef(trackUpdatedCollectionRefProd,trackUpdatedIndex++));
225  }
226  }
227 
228  // Fill the track extra with the rec hit (persistent-)reference
229  for (Trajectory::RecHitContainer::const_iterator recHit = transHits.begin();
230  recHit != transHits.end(); ++recHit) {
231  TrackingRecHit *singleHit = (**recHit).hit()->clone();
232  track.appendHitPattern( *singleHit);
233  if(theUpdatingAtVtx && updateResult.first) updateResult.second.appendHitPattern(*singleHit);
234  recHitCollection->push_back( singleHit );
235  // set the TrackingRecHitRef (persitent reference of the tracking rec hits)
236  trackExtra.add(TrackingRecHitRef(recHitCollectionRefProd, recHitsIndex++ ));
237  }
238 
239  // fill the TrackExtraCollection
240  trackExtraCollection->push_back(trackExtra);
241 
242  // fill the TrackCollection
243  trackCollection->push_back(track);
244  iTkRef++;
245  LogTrace(metname) << "Debug Track being loaded pt "<< track.pt();
246  // fill the TrackCollection updated at vtx
247  if(theUpdatingAtVtx && updateResult.first)
248  updatedAtVtxTrackCollection->push_back(updateResult.second);
249 
250  // We don't need the original trajectory anymore.
251  // It has been copied by value in the trajectoryCollection, if
252  // it is required to put it into the event.
253  delete *rawTrajectory;
254 
255  if(tkBoolVec.size()>tjCnt) tkBoolVec[tjCnt] = true;
256  if(theTrajectoryFlag) tjTkMap[iTjRef-1] = iTkRef-1;
257  }
258 
259 
260 
261  // Put the Collections in the event
262  LogTrace(metname) << "put the Collections in the event";
263  event.put(recHitCollection,instance);
264  event.put(trackExtraCollection,instance);
265 
266  OrphanHandle<reco::TrackCollection> returnTrackHandle;
267  OrphanHandle<reco::TrackCollection> nonUpdatedHandle;
268  if(theUpdatingAtVtx){
269  nonUpdatedHandle = event.put(trackCollection,instance);
270  event.put(trackToTrackmap);
271  returnTrackHandle = event.put(updatedAtVtxTrackCollection,instance+"UpdatedAtVtx");
272  }
273  else {
274  returnTrackHandle = event.put(trackCollection,instance);
275  nonUpdatedHandle = returnTrackHandle;
276  }
277 
278  if ( theTrajectoryFlag ) {
279  OrphanHandle<std::vector<Trajectory> > rTrajs = event.put(trajectoryCollection,instance);
280  // Now Create traj<->tracks association map
281  for ( std::map<unsigned int, unsigned int>::iterator i = tjTkMap.begin();
282  i != tjTkMap.end(); i++ ) {
283  trajTrackMap->insert( edm::Ref<std::vector<Trajectory> >( rTrajs, (*i).first ),
284  edm::Ref<reco::TrackCollection>( nonUpdatedHandle, (*i).second ) );
285  }
286  event.put( trajTrackMap, instance );
287  }
288 
289  return returnTrackHandle;
290 }
291 
294  Event& event) {
295 
296  const string metname = "Muon|RecoMuon|MuonTrackLoader";
297 
298  // the muon collection, it will be loaded in the event
299  auto_ptr<reco::MuonTrackLinksCollection> trackLinksCollection(new reco::MuonTrackLinksCollection());
300 
301  // don't waste any time...
302  if ( muonCands.empty() ) {
303  auto_ptr<reco::TrackExtraCollection> trackExtraCollection(new reco::TrackExtraCollection() );
304  auto_ptr<TrackingRecHitCollection> recHitCollection(new TrackingRecHitCollection() );
305  auto_ptr<reco::TrackCollection> trackCollection( new reco::TrackCollection() );
306 
307  event.put(recHitCollection);
308  event.put(trackExtraCollection);
309  event.put(trackCollection);
310 
311  //need to also put the tracker tracks collection if requested
312  if(thePutTkTrackFlag){
313  //will take care of putting nothing in the event but the empty collection
314  TrajectoryContainer trackerTrajs;
315  loadTracks(trackerTrajs, event, theL2SeededTkLabel, theSmoothTkTrackFlag);
316  }
317 
318  return event.put(trackLinksCollection);
319  }
320 
321  // get combined Trajectories
322  TrajectoryContainer combinedTrajs;
323  TrajectoryContainer trackerTrajs;
324  for (CandidateContainer::const_iterator it = muonCands.begin(); it != muonCands.end(); ++it) {
325  LogDebug(metname) << "Loader glbSeedRef " << (*it)->trajectory()->seedRef().isNonnull();
326  if ((*it)->trackerTrajectory() ) LogDebug(metname) << " " << "tkSeedRef " << (*it)->trackerTrajectory()->seedRef().isNonnull();
327 
328  combinedTrajs.push_back((*it)->trajectory());
329  if ( thePutTkTrackFlag ) trackerTrajs.push_back((*it)->trackerTrajectory());
330 
331  else {
332  if ((*it)->trackerTrajectory()) delete ((*it)->trackerTrajectory());
333  }
334 
335  // // Create the links between sta and tracker tracks
336  // reco::MuonTrackLinks links;
337  // links.setStandAloneTrack((*it)->muonTrack());
338  // links.setTrackerTrack((*it)->trackerTrack());
339  // trackLinksCollection->push_back(links);
340  // delete *it;
341  }
342 
343  // create the TrackCollection of combined Trajectories
344  // FIXME: could this be done one track at a time in the previous loop?
345  LogTrace(metname) << "Build combinedTracks";
346  std::vector<bool> combTksVec(combinedTrajs.size(), false);
347  OrphanHandle<reco::TrackCollection> combinedTracks = loadTracks(combinedTrajs, event, combTksVec);
348 
350  std::vector<bool> trackerTksVec(trackerTrajs.size(), false);
351  if(thePutTkTrackFlag) {
352  LogTrace(metname) << "Build trackerTracks: "
353  << trackerTrajs.size();
354  trackerTracks = loadTracks(trackerTrajs, event, trackerTksVec, theL2SeededTkLabel, theSmoothTkTrackFlag);
355  } else {
356  for (TrajectoryContainer::iterator it = trackerTrajs.begin(); it != trackerTrajs.end(); ++it) {
357  if(*it) delete *it;
358  }
359  }
360 
361  LogTrace(metname) << "Set the final links in the MuonTrackLinks collection";
362 
363  unsigned int candposition(0), position(0), tkposition(0);
364  //reco::TrackCollection::const_iterator glIt = combinedTracks->begin(),
365  // glEnd = combinedTracks->end();
366 
367  for (CandidateContainer::const_iterator it = muonCands.begin(); it != muonCands.end(); ++it, ++candposition) {
368 
369  // The presence of the global track determines whether to fill the MuonTrackLinks or not
370  // N.B. We are assuming here that the global tracks in "combinedTracks"
371  // have the same order as the muon candidates in "muonCands"
372  // (except for possible missing tracks), which should always be the case...
373  //if( glIt == glEnd ) break;
374  if(combTksVec[candposition]) {
375  reco::TrackRef combinedTR(combinedTracks, position++);
376  //++glIt;
377 
378  // Create the links between sta and tracker tracks
380  links.setStandAloneTrack((*it)->muonTrack());
381  links.setTrackerTrack((*it)->trackerTrack());
382  links.setGlobalTrack(combinedTR);
383 
384  if(thePutTkTrackFlag && trackerTksVec[candposition]) {
385  reco::TrackRef trackerTR(trackerTracks, tkposition++);
386  links.setTrackerTrack(trackerTR);
387  }
388 
389  trackLinksCollection->push_back(links);
390  }
391 
392  else { // if no global track, still increment the tracker-track counter when appropriate
393  if(thePutTkTrackFlag && trackerTksVec[candposition]) tkposition++;
394  }
395 
396  delete *it;
397  }
398 
399  if( thePutTkTrackFlag && trackerTracks.isValid() && !(combinedTracks->size() > 0 && trackerTracks->size() > 0 ) )
400  LogWarning(metname)<<"The MuonTrackLinkCollection is incomplete";
401 
402  // put the MuonCollection in the event
403  LogTrace(metname) << "put the MuonCollection in the event" << "\n";
404 
405  return event.put(trackLinksCollection);
406 }
407 
409 MuonTrackLoader::loadTracks(const TrajectoryContainer& trajectories,
410  Event& event, const std::vector<std::pair<Trajectory*,reco::TrackRef> >& miniMap, const string& instance, bool reallyDoSmoothing) {
411 
412  const bool doSmoothing = theSmoothingStep && reallyDoSmoothing;
413 
414  const string metname = "Muon|RecoMuon|MuonTrackLoader|TevMuonTrackLoader";
415 
416  LogDebug(metname)<<"TeV LoadTracks instance: " << instance;
417 
418  // the track collectios; they will be loaded in the event
419  auto_ptr<reco::TrackCollection> trackCollection(new reco::TrackCollection());
420  // ... and its reference into the event
421  reco::TrackRefProd trackCollectionRefProd = event.getRefBeforePut<reco::TrackCollection>(instance);
422 
423  // Association map between GlobalMuons and TeVMuons
424  auto_ptr<reco:: TrackToTrackMap> trackToTrackmap(new reco::TrackToTrackMap);
425 
426  // the track extra collection, it will be loaded in the event
427  auto_ptr<reco::TrackExtraCollection> trackExtraCollection(new reco::TrackExtraCollection() );
428  // ... and its reference into the event
429  reco::TrackExtraRefProd trackExtraCollectionRefProd = event.getRefBeforePut<reco::TrackExtraCollection>(instance);
430 
431  // the rechit collection, it will be loaded in the event
432  auto_ptr<TrackingRecHitCollection> recHitCollection(new TrackingRecHitCollection() );
433  // ... and its reference into the event
434  TrackingRecHitRefProd recHitCollectionRefProd = event.getRefBeforePut<TrackingRecHitCollection>(instance);
435 
436  // Collection of Trajectory
437  auto_ptr<vector<Trajectory> > trajectoryCollection(new vector<Trajectory>);
438 
439  // Association map between track and trajectory
440  std::auto_ptr<TrajTrackAssociationCollection> trajTrackMap( new TrajTrackAssociationCollection() );
441 
442  // don't waste any time...
443  if ( trajectories.empty() ) {
444  event.put(recHitCollection,instance);
445  event.put(trackExtraCollection,instance);
446  if(theTrajectoryFlag) {
447  event.put(trajectoryCollection,instance);
448  event.put( trajTrackMap, instance );
449  }
450  event.put(trackToTrackmap, instance);
451  return event.put(trackCollection,instance);
452  }
453 
454  LogTrace(metname) << "Create the collection of Tracks";
455 
457  event.getByToken(theBeamSpotToken,beamSpot);
458 
459  reco::TrackRef::key_type trackIndex = 0;
460  // reco::TrackRef::key_type trackUpdatedIndex = 0;
461 
462  reco::TrackExtraRef::key_type trackExtraIndex = 0;
463  TrackingRecHitRef::key_type recHitsIndex = 0;
464 
466  edm::Ref< std::vector<Trajectory> >::key_type iTjRef = 0;
467  std::map<unsigned int, unsigned int> tjTkMap;
468 
469  if(doSmoothing)
471 
472 
473  for(TrajectoryContainer::const_iterator rawTrajectory = trajectories.begin();
474  rawTrajectory != trajectories.end(); ++rawTrajectory){
475 
476  reco::TrackRef glbRef;
477  std::vector<std::pair<Trajectory*,reco::TrackRef> >::const_iterator mmit;
478  for(mmit = miniMap.begin();mmit!=miniMap.end();++mmit){
479  if(mmit->first == *rawTrajectory) glbRef = mmit->second;
480  }
481 
482  Trajectory &trajectory = **rawTrajectory;
483 
484  if(doSmoothing){
485  vector<Trajectory> trajectoriesSM = theSmoother->trajectories(**rawTrajectory);
486 
487  if(!trajectoriesSM.empty()) {
488  const edm::RefToBase<TrajectorySeed> tmpSeedRef = (**rawTrajectory).seedRef();
489  trajectory = trajectoriesSM.front();
490  trajectory.setSeedRef(tmpSeedRef);
491  } else
492  LogInfo(metname)<<"The trajectory has not been smoothed!"<<endl;
493  }
494 
495  if(theTrajectoryFlag) {
496  trajectoryCollection->push_back(trajectory);
497  iTjRef++;
498  }
499 
500  // get the transient rechit from the trajectory
501  Trajectory::RecHitContainer transHits = trajectory.recHits();
502 
503  if ( trajectory.direction() == oppositeToMomentum)
504  reverse(transHits.begin(),transHits.end());
505 
506  // build the "bare" track from the trajectory.
507  // This track has the parameters defined at PCA (no update)
508  pair<bool,reco::Track> resultOfTrackExtrapAtPCA = buildTrackAtPCA(trajectory, *beamSpot);
509 
510  // Check if the extrapolation went well
511  if(!resultOfTrackExtrapAtPCA.first) {
512  // ++trackIndex;//ADAM
513  delete *rawTrajectory;
514  continue;
515  }
516 
517  // take the "bare" track at PCA
518  reco::Track &track = resultOfTrackExtrapAtPCA.second;
519 
520  // build the "bare" track extra from the trajectory
521  reco::TrackExtra trackExtra = buildTrackExtra( trajectory );
522 
523  // get the TrackExtraRef (persitent reference of the track extra)
524  reco::TrackExtraRef trackExtraRef(trackExtraCollectionRefProd, trackExtraIndex++ );
525 
526  // set the persistent track-extra reference to the Track
527  track.setExtra(trackExtraRef);
528 
529  // Fill the map
530  trackToTrackmap->insert(glbRef,
531  reco::TrackRef(trackCollectionRefProd,trackIndex++));
532 
533  // build the updated-at-vertex track, starting from the previous track
534  pair<bool,reco::Track> updateResult(false,reco::Track());
535 
536  // Fill the track extra with the rec hit (persistent-)reference
537  for (Trajectory::RecHitContainer::const_iterator recHit = transHits.begin();
538  recHit != transHits.end(); ++recHit) {
539  TrackingRecHit *singleHit = (**recHit).hit()->clone();
540  track.appendHitPattern( *singleHit);
541  if(theUpdatingAtVtx && updateResult.first) updateResult.second.appendHitPattern( *singleHit); // i was already incremented
542  recHitCollection->push_back( singleHit );
543  // set the TrackingRecHitRef (persitent reference of the tracking rec hits)
544  trackExtra.add(TrackingRecHitRef(recHitCollectionRefProd, recHitsIndex++ ));
545  }
546 
547  // fill the TrackExtraCollection
548  trackExtraCollection->push_back(trackExtra);
549 
550  // fill the TrackCollection
551  trackCollection->push_back(track);
552  iTkRef++;
553  LogTrace(metname) << "Debug Track being loaded pt "<< track.pt();
554 
555  // We don't need the original trajectory anymore.
556  // It has been copied by value in the trajectoryCollection, if
557  // it is required to put it into the event.
558  delete *rawTrajectory;
559 
560  if(theTrajectoryFlag) tjTkMap[iTjRef-1] = iTkRef-1;
561  }
562 
563 
564 
565  // Put the Collections in the event
566  LogTrace(metname) << "put the Collections in the event";
567  event.put(recHitCollection,instance);
568  event.put(trackExtraCollection,instance);
569 
570  OrphanHandle<reco::TrackCollection> returnTrackHandle;
571  OrphanHandle<reco::TrackCollection> nonUpdatedHandle;
572  if(theUpdatingAtVtx){
573  }
574  else {
575  event.put(trackToTrackmap,instance);
576  returnTrackHandle = event.put(trackCollection,instance);
577  nonUpdatedHandle = returnTrackHandle;
578  }
579 
580  if ( theTrajectoryFlag ) {
581  OrphanHandle<std::vector<Trajectory> > rTrajs = event.put(trajectoryCollection,instance);
582  // Now Create traj<->tracks association map
583  for ( std::map<unsigned int, unsigned int>::iterator i = tjTkMap.begin();
584  i != tjTkMap.end(); i++ ) {
585  trajTrackMap->insert( edm::Ref<std::vector<Trajectory> >( rTrajs, (*i).first ),
586  edm::Ref<reco::TrackCollection>( nonUpdatedHandle, (*i).second ) );
587  }
588  event.put( trajTrackMap, instance );
589  }
590 
591  return returnTrackHandle;
592 }
593 
594 
595 pair<bool,reco::Track> MuonTrackLoader::buildTrackAtPCA(const Trajectory& trajectory, const reco::BeamSpot &beamSpot) const {
596 
597  const string metname = "Muon|RecoMuon|MuonTrackLoader";
598 
600 
601  // FIXME: check the prop direction
602  TrajectoryStateOnSurface innerTSOS = trajectory.geometricalInnermostState();
603 
604  // This is needed to extrapolate the tsos at vertex
605  LogTrace(metname) << "Propagate to PCA...";
606  pair<bool,FreeTrajectoryState>
607  extrapolationResult = theUpdatorAtVtx->propagate(innerTSOS, beamSpot);
608  FreeTrajectoryState ftsAtVtx;
609 
610  if(extrapolationResult.first)
611  ftsAtVtx = extrapolationResult.second;
612  else{
613  if(TrackerBounds::isInside(innerTSOS.globalPosition())){
614  LogInfo(metname) << "Track in the Tracker: taking the innermost state instead of the state at PCA";
615  ftsAtVtx = *innerTSOS.freeState();
616  }
617  else{
618  if ( theAllowNoVtxFlag ) {
619  LogInfo(metname) << "Propagation to PCA failed, taking the innermost state instead of the state at PCA";
620  ftsAtVtx = *innerTSOS.freeState();
621  } else {
622  LogInfo(metname) << "Stand Alone track: this track will be rejected";
623  return pair<bool,reco::Track>(false,reco::Track());
624  }
625  }
626  }
627 
628  LogTrace(metname) << "TSOS after the extrapolation at vtx";
629  LogTrace(metname) << debug.dumpFTS(ftsAtVtx);
630 
631  GlobalPoint pca = ftsAtVtx.position();
632  math::XYZPoint persistentPCA(pca.x(),pca.y(),pca.z());
633  GlobalVector p = ftsAtVtx.momentum();
634  math::XYZVector persistentMomentum(p.x(),p.y(),p.z());
635 
636  bool bon = true;
637  if(fabs(theService->magneticField()->inTesla(GlobalPoint(0,0,0)).z()) < 0.01) bon=false;
638  double ndof = trajectory.ndof(bon);
639 
640  reco::Track track(trajectory.chiSquared(),
641  ndof,
642  persistentPCA,
643  persistentMomentum,
644  ftsAtVtx.charge(),
645  ftsAtVtx.curvilinearError());
646 
647  return pair<bool,reco::Track>(true,track);
648 }
649 
650 
651 pair<bool,reco::Track> MuonTrackLoader::buildTrackUpdatedAtPCA(const reco::Track &track, const reco::BeamSpot &beamSpot) const {
652 
653  const string metname = "Muon|RecoMuon|MuonTrackLoader";
655 
656  // build the transient track
657  reco::TransientTrack transientTrack(track,
658  &*theService->magneticField(),
659  theService->trackingGeometry());
660 
661  LogTrace(metname) << "Apply the vertex constraint";
662  pair<bool,FreeTrajectoryState> updateResult = theUpdatorAtVtx->update(transientTrack,beamSpot);
663 
664  if(!updateResult.first){
665  return pair<bool,reco::Track>(false,reco::Track());
666  }
667 
668  LogTrace(metname) << "FTS after the vertex constraint";
669  FreeTrajectoryState &ftsAtVtx = updateResult.second;
670 
671  LogTrace(metname) << debug.dumpFTS(ftsAtVtx);
672 
673  GlobalPoint pca = ftsAtVtx.position();
674  math::XYZPoint persistentPCA(pca.x(),pca.y(),pca.z());
675  GlobalVector p = ftsAtVtx.momentum();
676  math::XYZVector persistentMomentum(p.x(),p.y(),p.z());
677 
678  reco::Track updatedTrack(track.chi2(),
679  track.ndof(),
680  persistentPCA,
681  persistentMomentum,
682  ftsAtVtx.charge(),
683  ftsAtVtx.curvilinearError());
684 
685  return pair<bool,reco::Track>(true,updatedTrack);
686 }
687 
688 
690 
691  const string metname = "Muon|RecoMuon|MuonTrackLoader";
692 
693  const Trajectory::RecHitContainer transRecHits = trajectory.recHits();
694 
695  // put the collection of TrackingRecHit in the event
696 
697  // sets the outermost and innermost TSOSs
698  // FIXME: check it!
699  TrajectoryStateOnSurface outerTSOS;
700  TrajectoryStateOnSurface innerTSOS;
701  unsigned int innerId=0, outerId=0;
703  DetId outerDetId;
704 
705  if (trajectory.direction() == alongMomentum) {
706  LogTrace(metname)<<"alongMomentum";
707  outerTSOS = trajectory.lastMeasurement().updatedState();
708  innerTSOS = trajectory.firstMeasurement().updatedState();
709  outerId = trajectory.lastMeasurement().recHit()->geographicalId().rawId();
710  innerId = trajectory.firstMeasurement().recHit()->geographicalId().rawId();
711  outerRecHit = trajectory.lastMeasurement().recHit();
712  outerDetId = trajectory.lastMeasurement().recHit()->geographicalId();
713  }
714  else if (trajectory.direction() == oppositeToMomentum) {
715  LogTrace(metname)<<"oppositeToMomentum";
716  outerTSOS = trajectory.firstMeasurement().updatedState();
717  innerTSOS = trajectory.lastMeasurement().updatedState();
718  outerId = trajectory.firstMeasurement().recHit()->geographicalId().rawId();
719  innerId = trajectory.lastMeasurement().recHit()->geographicalId().rawId();
720  outerRecHit = trajectory.firstMeasurement().recHit();
721  outerDetId = trajectory.firstMeasurement().recHit()->geographicalId();
722  }
723  else LogError(metname)<<"Wrong propagation direction!";
724 
725  const GeomDet *outerDet = theService->trackingGeometry()->idToDet(outerDetId);
726  GlobalPoint outerTSOSPos = outerTSOS.globalParameters().position();
727  bool inside = outerDet->surface().bounds().inside(outerDet->toLocal(outerTSOSPos));
728 
729 
730  GlobalPoint hitPos = (outerRecHit->isValid()) ? outerRecHit->globalPosition() : outerTSOS.globalParameters().position() ;
731 
732  if(!inside) {
733  LogTrace(metname)<<"The Global Muon outerMostMeasurementState is not compatible with the recHit detector! Setting outerMost postition to recHit position if recHit isValid: " << outerRecHit->isValid();
734  LogTrace(metname)<<"From " << outerTSOSPos << " to " << hitPos;
735  }
736 
737 
738  //build the TrackExtra
739  GlobalPoint v = (inside) ? outerTSOSPos : hitPos ;
740  GlobalVector p = outerTSOS.globalParameters().momentum();
741  math::XYZPoint outpos( v.x(), v.y(), v.z() );
742  math::XYZVector outmom( p.x(), p.y(), p.z() );
743 
744  v = innerTSOS.globalParameters().position();
745  p = innerTSOS.globalParameters().momentum();
746  math::XYZPoint inpos( v.x(), v.y(), v.z() );
747  math::XYZVector inmom( p.x(), p.y(), p.z() );
748 
749  reco::TrackExtra trackExtra(outpos, outmom, true, inpos, inmom, true,
750  outerTSOS.curvilinearError(), outerId,
751  innerTSOS.curvilinearError(), innerId,
752  trajectory.direction(),trajectory.seedRef());
753 
754  return trackExtra;
755 
756 }
#define LogDebug(id)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::BeamSpot > theBeamSpotToken
T getUntrackedParameter(std::string const &, T const &) const
MuonTrackLoader(edm::ParameterSet &parameterSet, edm::ConsumesCollector &iC, const MuonServiceProxy *service=0)
Constructor for the STA reco the args must be specify!
int i
Definition: DBlmapReader.cc:9
static bool isInside(const GlobalPoint &)
ConstRecHitPointer const & recHit() const
virtual bool inside(const Local3DPoint &) const =0
Determine if the point is inside the bounds.
static PFTauRenderPlugin instance
const std::string metname
const CurvilinearTrajectoryError & curvilinearError() const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
T y() const
Definition: PV3DBase.h:63
std::string theSmootherName
std::pair< bool, FreeTrajectoryState > propagate(const TrajectoryStateOnSurface &tsos, const reco::BeamSpot &beamSpot) const
Propagate the state to the 2D-PCA.
GlobalPoint globalPosition() const
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:62
const Bounds & bounds() const
Definition: Surface.h:128
TrackCharge charge() const
TrajectoryStateOnSurface geometricalInnermostState() const
Definition: Trajectory.cc:233
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
const CurvilinearTrajectoryError & curvilinearError() const
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
std::vector< MuonTrackLinks > MuonTrackLinksCollection
collection of MuonTrackLinks
Definition: MuonFwd.h:22
MuonCandidate::CandidateContainer CandidateContainer
const MuonServiceProxy * theService
ConstRecHitContainer recHits(bool splitting=false) const
Definition: Trajectory.cc:67
std::string dumpFTS(const FreeTrajectoryState &fts) const
PropagationDirection const & direction() const
Definition: Trajectory.cc:196
edm::InputTag theBeamSpotInputTag
double chi2() const
chi-squared of the fit
Definition: TrackBase.h:105
std::pair< bool, FreeTrajectoryState > update(const reco::TransientTrack &track, const reco::BeamSpot &beamSpot) const
Applies the vertex constraint.
double ndof() const
number of degrees of freedom of the fit
Definition: TrackBase.h:107
edm::Ref< TrackingRecHitCollection > TrackingRecHitRef
persistent reference to a TrackingRecHit
virtual ~MuonTrackLoader()
Destructor.
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:193
double pt() const
track transverse momentum
Definition: TrackBase.h:129
FreeTrajectoryState const * freeState(bool withErrors=true) const
T z() const
Definition: PV3DBase.h:64
edm::RefToBase< TrajectorySeed > seedRef(void) const
Definition: Trajectory.h:308
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
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > > TrajTrackAssociationCollection
MuonUpdatorAtVertex * theUpdatorAtVtx
GlobalVector momentum() const
#define LogTrace(id)
MuonCandidate::TrajectoryContainer TrajectoryContainer
virtual TrackingRecHit * clone() const =0
Definition: DetId.h:18
GlobalPoint position() const
int ndof(bool bon=true) const
Definition: Trajectory.cc:74
edm::OrphanHandle< reco::TrackCollection > loadTracks(const TrajectoryContainer &, edm::Event &, const std::string &="", bool=true)
Convert the trajectories into tracks and load the tracks in the event.
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:9
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
void setExtra(const TrackExtraRef &ref)
set reference to &quot;extra&quot; object
Definition: Track.h:94
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:206
#define debug
Definition: HDRShower.cc:19
const GlobalTrajectoryParameters & globalParameters() const
std::string theL2SeededTkLabel
Label for L2SeededTracks.
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
ConstRecHitContainer RecHitContainer
Definition: Trajectory.h:44
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
void add(const TrackingRecHitRef &r)
add a reference to a RecHit
reco::TrackExtra buildTrackExtra(const Trajectory &) const
void setSeedRef(const edm::RefToBase< TrajectorySeed > &seedRef)
Definition: Trajectory.h:310
std::pair< bool, reco::Track > buildTrackAtPCA(const Trajectory &trajectory, const reco::BeamSpot &) const
Build a track at the PCA WITHOUT any vertex constriant.
edm::ESHandle< TrajectorySmoother > theSmoother
void appendHitPattern(const TrackingRecHit &hit)
Definition: TrackBase.h:259
const MuonServiceProxy * theService
TrajectoryStateOnSurface const & updatedState() const
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:170
T x() const
Definition: PV3DBase.h:62
bool isNonnull() const
Checks for non-null.
Definition: RefToBase.h:279
std::pair< bool, reco::Track > buildTrackUpdatedAtPCA(const reco::Track &trackAtPCA, const reco::BeamSpot &) const
Takes a track at the PCA and applies the vertex constriant.
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
double chiSquared() const
Definition: Trajectory.h:254