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