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