CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/SimTracker/TrackHistory/src/TrackHistory.cc

Go to the documentation of this file.
00001 
00002 #include "SimTracker/Records/interface/TrackAssociatorRecord.h"
00003 #include "SimTracker/TrackHistory/interface/TrackHistory.h"
00004 
00005 
00006 TrackHistory::TrackHistory (
00007     const edm::ParameterSet & config
00008 ) : HistoryBase()
00009 {
00010     // Name of the track collection
00011     trackProducer_ = config.getUntrackedParameter<edm::InputTag> ( "trackProducer" );
00012 
00013     // Name of the traking pariticle collection
00014     trackingTruth_ = config.getUntrackedParameter<edm::InputTag> ( "trackingTruth" );
00015 
00016     // Track association record
00017     trackAssociator_ = config.getUntrackedParameter<std::string> ( "trackAssociator" );
00018 
00019     // Association by max. value
00020     bestMatchByMaxValue_ = config.getUntrackedParameter<bool> ( "bestMatchByMaxValue" );
00021 
00022     // Enable RecoToSim association
00023     enableRecoToSim_ = config.getUntrackedParameter<bool> ( "enableRecoToSim" );
00024 
00025     // Enable SimToReco association
00026     enableSimToReco_ = config.getUntrackedParameter<bool> ( "enableSimToReco" );
00027 
00028     quality_ = 0.;
00029 }
00030 
00031 
00032 void TrackHistory::newEvent (
00033     const edm::Event & event, const edm::EventSetup & setup
00034 )
00035 {
00036     if ( enableRecoToSim_ || enableSimToReco_ )
00037     {
00038         // Track collection
00039         edm::Handle<edm::View<reco::Track> > trackCollection;
00040         event.getByLabel(trackProducer_, trackCollection);
00041 
00042         // Tracking particle information
00043         edm::Handle<TrackingParticleCollection>  TPCollection;
00044         event.getByLabel(trackingTruth_, TPCollection);
00045 
00046         // Get the track associator
00047         edm::ESHandle<TrackAssociatorBase> associator;
00048         setup.get<TrackAssociatorRecord>().get(trackAssociator_, associator);
00049 
00050         // Calculate the map between recotracks -> tp
00051         if ( enableRecoToSim_ ) recoToSim_ = associator->associateRecoToSim(trackCollection, TPCollection, &event, &setup);
00052 
00053         // Calculate the map between recotracks <- tp
00054         if ( enableSimToReco_ ) simToReco_ = associator->associateSimToReco(trackCollection, TPCollection, &event, &setup);
00055     }
00056 }
00057 
00058 
00059 bool TrackHistory::evaluate ( reco::TrackBaseRef tr )
00060 {
00061     if ( !enableRecoToSim_ ) return false;
00062 
00063     std::pair<TrackingParticleRef, double> result =  match(tr, recoToSim_, bestMatchByMaxValue_);
00064 
00065     TrackingParticleRef tpr( result.first );
00066     quality_ = result.second;
00067 
00068     if ( !tpr.isNull() )
00069     {
00070         HistoryBase::evaluate(tpr);
00071 
00072         recotrack_ = tr;
00073 
00074         return true;
00075     }
00076 
00077     return false;
00078 }
00079 
00080