CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoTracker/TrackProducer/src/KfTrackProducerBase.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TrackProducer/interface/KfTrackProducerBase.h"
00002 // system include files
00003 #include <memory>
00004 // user include files
00005 #include "DataFormats/TrackReco/interface/TrackResiduals.h"
00006 #include "FWCore/Framework/interface/Frameworkfwd.h"
00007 #include "FWCore/Framework/interface/MakerMacros.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00010 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00011 
00012 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00013 
00014 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00015 
00016 #include "RecoTracker/TrackProducer/interface/ClusterRemovalRefSetter.h"
00017 #include "TrajectoryToResiduals.h"
00018 
00019 void KfTrackProducerBase::putInEvt(edm::Event& evt,
00020                                    const Propagator* prop,
00021                                    const MeasurementTracker* measTk,
00022                                    std::auto_ptr<TrackingRecHitCollection>& selHits,
00023                                    std::auto_ptr<reco::TrackCollection>& selTracks,
00024                                    std::auto_ptr<reco::TrackExtraCollection>& selTrackExtras,
00025                                    std::auto_ptr<std::vector<Trajectory> >&   selTrajectories,
00026                                    AlgoProductCollection& algoResults)
00027 {
00028 
00029   TrackingRecHitRefProd rHits = evt.getRefBeforePut<TrackingRecHitCollection>();
00030   reco::TrackExtraRefProd rTrackExtras = evt.getRefBeforePut<reco::TrackExtraCollection>();
00031 
00032   edm::Ref<reco::TrackExtraCollection>::key_type idx = 0;
00033   edm::Ref<reco::TrackExtraCollection>::key_type hidx = 0;
00034   edm::Ref<reco::TrackCollection>::key_type iTkRef = 0;
00035   edm::Ref< std::vector<Trajectory> >::key_type iTjRef = 0;
00036   std::map<unsigned int, unsigned int> tjTkMap;
00037 
00038   for(AlgoProductCollection::iterator i=algoResults.begin(); i!=algoResults.end();i++){
00039     Trajectory * theTraj = (*i).first;
00040     if(trajectoryInEvent_) {
00041       selTrajectories->push_back(*theTraj);
00042       iTjRef++;
00043     }
00044 
00045     // const TrajectoryFitter::RecHitContainer& transHits = theTraj->recHits(useSplitting);  // NO: the return type in Trajectory is by VALUE
00046     TrajectoryFitter::RecHitContainer transHits = theTraj->recHits(useSplitting);
00047 
00048     reco::Track * theTrack = (*i).second.first;
00049     
00050     // Hits are going to be re-sorted along momentum few lines later. 
00051     // Therefore the direction stored in the TrackExtra 
00052     // has to be "alongMomentum" as well. Anyway, this direction can be differnt from the one of the orignal
00053     // seed! The name seedDirection() for the Track's method (and the corresponding data member) is
00054     // misleading and should be changed into something like "hitsDirection()". TO BE FIXED!
00055     PropagationDirection seedDir = alongMomentum;
00056 
00057     LogDebug("TrackProducer") << "In KfTrackProducerBase::putInEvt - seedDir=" << seedDir;
00058 
00059     reco::Track t = * theTrack;
00060     selTracks->push_back( t );
00061     iTkRef++;
00062 
00063     // Store indices in local map (starts at 0)
00064     if(trajectoryInEvent_) tjTkMap[iTjRef-1] = iTkRef-1;
00065     
00066     //sets the outermost and innermost TSOSs
00067     TrajectoryStateOnSurface outertsos;
00068     TrajectoryStateOnSurface innertsos;
00069     unsigned int innerId, outerId;
00070     
00071     // ---  NOTA BENE: the convention is to sort hits and measurements "along the momentum".
00072     // This is consistent with innermost and outermost labels only for tracks from LHC collision
00073     if (theTraj->direction() == alongMomentum) {
00074       outertsos = theTraj->lastMeasurement().updatedState();
00075       innertsos = theTraj->firstMeasurement().updatedState();
00076       outerId = theTraj->lastMeasurement().recHit()->geographicalId().rawId();
00077       innerId = theTraj->firstMeasurement().recHit()->geographicalId().rawId();
00078     } else { 
00079       outertsos = theTraj->firstMeasurement().updatedState();
00080       innertsos = theTraj->lastMeasurement().updatedState();
00081       outerId = theTraj->firstMeasurement().recHit()->geographicalId().rawId();
00082       innerId = theTraj->lastMeasurement().recHit()->geographicalId().rawId();
00083     }
00084     // ---
00085     //build the TrackExtra
00086     GlobalPoint v = outertsos.globalParameters().position();
00087     GlobalVector p = outertsos.globalParameters().momentum();
00088     math::XYZVector outmom( p.x(), p.y(), p.z() );
00089     math::XYZPoint  outpos( v.x(), v.y(), v.z() );
00090     v = innertsos.globalParameters().position();
00091     p = innertsos.globalParameters().momentum();
00092     math::XYZVector inmom( p.x(), p.y(), p.z() );
00093     math::XYZPoint  inpos( v.x(), v.y(), v.z() );
00094 
00095     reco::TrackExtraRef teref= reco::TrackExtraRef ( rTrackExtras, idx ++ );
00096     reco::Track & track = selTracks->back();
00097     track.setExtra( teref );
00098     
00099     //======= I want to set the second hitPattern here =============
00100     if (theSchool.isValid())
00101       {
00102         NavigationSetter setter( *theSchool );
00103         setSecondHitPattern(theTraj,track,prop,measTk);
00104       }
00105     //==============================================================
00106     
00107     selTrackExtras->push_back( reco::TrackExtra (outpos, outmom, true, inpos, inmom, true,
00108                                                  outertsos.curvilinearError(), outerId,
00109                                                  innertsos.curvilinearError(), innerId,
00110                                                  seedDir, theTraj->seedRef()));
00111 
00112 
00113     reco::TrackExtra & tx = selTrackExtras->back();
00114     
00115     // ---  NOTA BENE: the convention is to sort hits and measurements "along the momentum".
00116     // This is consistent with innermost and outermost labels only for tracks from LHC collisions
00117     size_t ih = 0;
00118     if (theTraj->direction() == alongMomentum) {
00119       for( TrajectoryFitter::RecHitContainer::const_iterator j = transHits.begin();
00120            j != transHits.end(); j ++ ) {
00121         if ((**j).hit()!=0){
00122           TrackingRecHit * hit = (**j).hit()->clone();
00123           track.setHitPattern( * hit, ih ++ );
00124           selHits->push_back( hit );
00125           tx.add( TrackingRecHitRef( rHits, hidx ++ ) );
00126         }
00127       }
00128     }else{
00129       for( TrajectoryFitter::RecHitContainer::const_iterator j = transHits.end()-1;
00130            j != transHits.begin()-1; --j ) {
00131         if ((**j).hit()!=0){
00132           TrackingRecHit * hit = (**j).hit()->clone();
00133           track.setHitPattern( * hit, ih ++ );
00134           selHits->push_back( hit );
00135         tx.add( TrackingRecHitRef( rHits, hidx ++ ) );
00136         }
00137       }
00138     }
00139     // ----
00140     tx.setResiduals(trajectoryToResiduals(*theTraj));
00141 
00142     delete theTrack;
00143     delete theTraj;
00144   }
00145 
00146   // Now we can re-set refs to hits, as they have already been cloned
00147   if (rekeyClusterRefs_) {
00148       ClusterRemovalRefSetter refSetter(evt, clusterRemovalInfo_);
00149       for (TrackingRecHitCollection::iterator it = selHits->begin(), ed = selHits->end(); it != ed; ++it) {
00150           refSetter.reKey(&*it);
00151       }
00152   }
00153 
00154   LogTrace("TrackingRegressionTest") << "========== TrackProducer Info ===================";
00155   LogTrace("TrackingRegressionTest") << "number of finalTracks: " << selTracks->size();
00156   for (reco::TrackCollection::const_iterator it = selTracks->begin(); it != selTracks->end(); it++) {
00157     LogTrace("TrackingRegressionTest") << "track's n valid and invalid hit, chi2, pt, eta : " 
00158                                        << it->found() << " , " 
00159                                        << it->lost()  <<" , " 
00160                                        << it->normalizedChi2() << " , "
00161                                        << it->pt() << " , "
00162                                        << it->eta() ;
00163   }
00164   LogTrace("TrackingRegressionTest") << "=================================================";
00165   
00166   
00167   rTracks_ = evt.put( selTracks );
00168   evt.put( selTrackExtras );
00169   evt.put( selHits );
00170 
00171   if(trajectoryInEvent_) {
00172     edm::OrphanHandle<std::vector<Trajectory> > rTrajs = evt.put(selTrajectories);
00173 
00174     // Now Create traj<->tracks association map
00175     std::auto_ptr<TrajTrackAssociationCollection> trajTrackMap( new TrajTrackAssociationCollection() );
00176     for ( std::map<unsigned int, unsigned int>::iterator i = tjTkMap.begin(); 
00177           i != tjTkMap.end(); i++ ) {
00178       edm::Ref<std::vector<Trajectory> > trajRef( rTrajs, (*i).first );
00179       edm::Ref<reco::TrackCollection>    tkRef( rTracks_, (*i).second );
00180       trajTrackMap->insert( edm::Ref<std::vector<Trajectory> >( rTrajs, (*i).first ),
00181                             edm::Ref<reco::TrackCollection>( rTracks_, (*i).second ) );
00182     }
00183     evt.put( trajTrackMap );
00184   }
00185 }
00186