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