Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:07

0001 
0002 #include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h"
0003 #include "SimDataFormats/Associations/interface/VertexToTrackingVertexAssociator.h"
0004 #include "SimTracker/TrackHistory/interface/VertexHistory.h"
0005 
0006 VertexHistory::VertexHistory(const edm::ParameterSet &config, edm::ConsumesCollector collector) : HistoryBase() {
0007   // Name of the track collection
0008   vertexProducer_ = config.getUntrackedParameter<edm::InputTag>("vertexProducer");
0009 
0010   // Name of the traking pariticle collection
0011   trackingTruth_ = config.getUntrackedParameter<edm::InputTag>("trackingTruth");
0012 
0013   // Vertex association record
0014   vertexAssociator_ = config.getUntrackedParameter<edm::InputTag>("vertexAssociator");
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<edm::View<reco::Vertex>>(vertexProducer_);
0027     collector.consumes<TrackingVertexCollection>(trackingTruth_);
0028     collector.consumes<reco::VertexToTrackingVertexAssociator>(vertexAssociator_);
0029   }
0030 
0031   quality_ = 0.;
0032 }
0033 
0034 void VertexHistory::newEvent(const edm::Event &event, const edm::EventSetup &setup) {
0035   if (enableRecoToSim_ || enableSimToReco_) {
0036     // Vertex collection
0037     edm::Handle<edm::View<reco::Vertex>> vertexCollection;
0038     event.getByLabel(vertexProducer_, vertexCollection);
0039 
0040     // Tracking particle information
0041     edm::Handle<TrackingVertexCollection> TVCollection;
0042     event.getByLabel(trackingTruth_, TVCollection);
0043 
0044     // Get the track associator
0045     edm::Handle<reco::VertexToTrackingVertexAssociator> vertexAssociator;
0046     event.getByLabel(vertexAssociator_, vertexAssociator);
0047 
0048     if (enableRecoToSim_) {
0049       // Calculate the map between recovertex -> simvertex
0050       recoToSim_ = vertexAssociator->associateRecoToSim(vertexCollection, TVCollection);
0051     }
0052 
0053     if (enableSimToReco_) {
0054       // Calculate the map between recovertex <- simvertex
0055       simToReco_ = vertexAssociator->associateSimToReco(vertexCollection, TVCollection);
0056     }
0057   }
0058 }
0059 
0060 bool VertexHistory::evaluate(reco::VertexBaseRef tv) {
0061   if (!enableRecoToSim_)
0062     return false;
0063 
0064   std::pair<TrackingVertexRef, double> result = match(tv, recoToSim_, bestMatchByMaxValue_);
0065 
0066   TrackingVertexRef tvr(result.first);
0067   quality_ = result.second;
0068 
0069   if (!tvr.isNull()) {
0070     HistoryBase::evaluate(tvr);
0071 
0072     recovertex_ = tv;
0073 
0074     return true;
0075   }
0076 
0077   return false;
0078 }