Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:49

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/Frameworkfwd.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/Framework/interface/global/EDProducer.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0009 #include "FWCore/Utilities/interface/EDGetToken.h"
0010 
0011 #include "DataFormats/Common/interface/Handle.h"
0012 
0013 #include "SimTracker/Common/interface/TrackingParticleSelector.h"
0014 #include "SimTracker/VertexAssociation/interface/VertexAssociatorByPositionAndTracks.h"
0015 
0016 #include "SimDataFormats/Associations/interface/VertexToTrackingVertexAssociator.h"
0017 
0018 class VertexAssociatorByPositionAndTracksProducer : public edm::global::EDProducer<> {
0019 public:
0020   explicit VertexAssociatorByPositionAndTracksProducer(const edm::ParameterSet &);
0021   ~VertexAssociatorByPositionAndTracksProducer() override;
0022 
0023   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0024 
0025 private:
0026   void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0027 
0028   // ----------member data ---------------------------
0029   const double absZ_;
0030   const double sigmaZ_;
0031   const double maxRecoZ_;
0032   const double absT_;
0033   const double sigmaT_;
0034   const double maxRecoT_;
0035   const double sharedTrackFraction_;
0036 
0037   edm::EDGetTokenT<reco::RecoToSimCollection> trackRecoToSimAssociationToken_;
0038   edm::EDGetTokenT<reco::SimToRecoCollection> trackSimToRecoAssociationToken_;
0039 };
0040 
0041 VertexAssociatorByPositionAndTracksProducer::VertexAssociatorByPositionAndTracksProducer(const edm::ParameterSet &config)
0042     : absZ_(config.getParameter<double>("absZ")),
0043       sigmaZ_(config.getParameter<double>("sigmaZ")),
0044       maxRecoZ_(config.getParameter<double>("maxRecoZ")),
0045       absT_(config.getParameter<double>("absT")),
0046       sigmaT_(config.getParameter<double>("sigmaT")),
0047       maxRecoT_(config.getParameter<double>("maxRecoT")),
0048       sharedTrackFraction_(config.getParameter<double>("sharedTrackFraction")),
0049       trackRecoToSimAssociationToken_(
0050           consumes<reco::RecoToSimCollection>(config.getParameter<edm::InputTag>("trackAssociation"))),
0051       trackSimToRecoAssociationToken_(
0052           consumes<reco::SimToRecoCollection>(config.getParameter<edm::InputTag>("trackAssociation"))) {
0053   produces<reco::VertexToTrackingVertexAssociator>();
0054 }
0055 
0056 VertexAssociatorByPositionAndTracksProducer::~VertexAssociatorByPositionAndTracksProducer() {}
0057 
0058 void VertexAssociatorByPositionAndTracksProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0059   edm::ParameterSetDescription desc;
0060 
0061   // Matching conditions
0062   desc.add<double>("absZ", 0.1);
0063   desc.add<double>("sigmaZ", 3.0);
0064   desc.add<double>("maxRecoZ", 1000.0);
0065   desc.add<double>("absT", -1.0);
0066   desc.add<double>("sigmaT", -1.0);
0067   desc.add<double>("maxRecoT", -1.0);
0068   desc.add<double>("sharedTrackFraction", -1.0);
0069 
0070   // Track-TrackingParticle association
0071   desc.add<edm::InputTag>("trackAssociation", edm::InputTag("trackingParticleRecoTrackAsssociation"));
0072 
0073   descriptions.add("VertexAssociatorByPositionAndTracks", desc);
0074 }
0075 
0076 void VertexAssociatorByPositionAndTracksProducer::produce(edm::StreamID,
0077                                                           edm::Event &iEvent,
0078                                                           const edm::EventSetup &) const {
0079   edm::Handle<reco::RecoToSimCollection> recotosimCollectionH;
0080   iEvent.getByToken(trackRecoToSimAssociationToken_, recotosimCollectionH);
0081 
0082   edm::Handle<reco::SimToRecoCollection> simtorecoCollectionH;
0083   iEvent.getByToken(trackSimToRecoAssociationToken_, simtorecoCollectionH);
0084 
0085   std::unique_ptr<VertexAssociatorByPositionAndTracks> impl;
0086 
0087   if (!recotosimCollectionH.isValid() || !simtorecoCollectionH.isValid()) {
0088     if (!recotosimCollectionH.isValid())
0089       edm::LogWarning("PrimaryVertexAnalyzer4PUSlimmed") << "trackRecoToSimAssociation is not available in the event";
0090     if (!simtorecoCollectionH.isValid())
0091       edm::LogWarning("PrimaryVertexAnalyzer4PUSlimmed") << "trackSimToRecoAssociation is not available in the event";
0092     return;
0093   }
0094   if (sigmaT_ < 0.0) {
0095     impl = std::make_unique<VertexAssociatorByPositionAndTracks>(&(iEvent.productGetter()),
0096                                                                  absZ_,
0097                                                                  sigmaZ_,
0098                                                                  maxRecoZ_,
0099                                                                  sharedTrackFraction_,
0100                                                                  recotosimCollectionH.product(),
0101                                                                  simtorecoCollectionH.product());
0102   } else {
0103     impl = std::make_unique<VertexAssociatorByPositionAndTracks>(&(iEvent.productGetter()),
0104                                                                  absZ_,
0105                                                                  sigmaZ_,
0106                                                                  maxRecoZ_,
0107                                                                  absT_,
0108                                                                  sigmaT_,
0109                                                                  maxRecoT_,
0110                                                                  sharedTrackFraction_,
0111                                                                  recotosimCollectionH.product(),
0112                                                                  simtorecoCollectionH.product());
0113   }
0114 
0115   auto toPut = std::make_unique<reco::VertexToTrackingVertexAssociator>(std::move(impl));
0116   iEvent.put(std::move(toPut));
0117 }
0118 
0119 DEFINE_FWK_MODULE(VertexAssociatorByPositionAndTracksProducer);