Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-23 03:25:39

0001 
0002 #include "SimTracker/TrackHistory/interface/TrackHistory.h"
0003 
0004 TrackHistory::TrackHistory(const edm::ParameterSet &config, edm::ConsumesCollector &&collector) : HistoryBase() {
0005   // Name of the track collection
0006   trackProducer_ = config.getUntrackedParameter<edm::InputTag>("trackProducer");
0007   collector.consumes<edm::View<reco::Track>>(trackProducer_);
0008 
0009   // Name of the traking pariticle collection
0010   trackingTruth_ = config.getUntrackedParameter<edm::InputTag>("trackingTruth");
0011   collector.consumes<TrackingParticleCollection>(trackingTruth_);
0012 
0013   // Track association record
0014   trackAssociator_ = config.getUntrackedParameter<edm::InputTag>("trackAssociator");
0015 
0016   // Association by max. value
0017   bestMatchByMaxValue_ = config.getUntrackedParameter<bool>("bestMatchByMaxValue");
0018 
0019   // Enable RecoToSim association
0020   enableRecoToSim_ = config.getUntrackedParameter<bool>("enableRecoToSim");
0021 
0022   // Enable SimToReco association
0023   enableSimToReco_ = config.getUntrackedParameter<bool>("enableSimToReco");
0024 
0025   if (enableRecoToSim_ or enableSimToReco_) {
0026     collector.consumes<reco::TrackToTrackingParticleAssociator>(trackAssociator_);
0027   }
0028 
0029   quality_ = 0.;
0030 }
0031 
0032 void TrackHistory::newEvent(const edm::Event &event, const edm::EventSetup &setup) {
0033   if (enableRecoToSim_ || enableSimToReco_) {
0034     // Track collection
0035     edm::Handle<edm::View<reco::Track>> trackCollection;
0036     event.getByLabel(trackProducer_, trackCollection);
0037 
0038     // Tracking particle information
0039     edm::Handle<TrackingParticleCollection> TPCollection;
0040     event.getByLabel(trackingTruth_, TPCollection);
0041 
0042     // Get the track associator
0043     edm::Handle<reco::TrackToTrackingParticleAssociator> associator;
0044     event.getByLabel(trackAssociator_, associator);
0045 
0046     // Calculate the map between recotracks -> tp
0047     if (enableRecoToSim_)
0048       recoToSim_ = associator->associateRecoToSim(trackCollection, TPCollection);
0049 
0050     // Calculate the map between recotracks <- tp
0051     if (enableSimToReco_)
0052       simToReco_ = associator->associateSimToReco(trackCollection, TPCollection);
0053   }
0054 }
0055 
0056 bool TrackHistory::evaluate(reco::TrackBaseRef tr) {
0057   if (!enableRecoToSim_)
0058     return false;
0059 
0060   std::pair<TrackingParticleRef, double> result = match(tr, recoToSim_, bestMatchByMaxValue_);
0061 
0062   TrackingParticleRef tpr(result.first);
0063   quality_ = result.second;
0064   trackingParticle_ = tpr;
0065 
0066   if (!tpr.isNull()) {
0067     HistoryBase::evaluate(tpr);
0068 
0069     recotrack_ = tr;
0070 
0071     return true;
0072   }
0073 
0074   return false;
0075 }