Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/Common/interface/Handle.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/Frameworkfwd.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/Framework/interface/global/EDProducer.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 "SimTracker/Common/interface/TrackingParticleSelector.h"
0012 
0013 #include "SimDataFormats/Associations/interface/VertexToTrackingVertexAssociator.h"
0014 #include "SimTracker/VertexAssociation/interface/VertexAssociatorByTracks.h"
0015 
0016 class VertexAssociatorByTracksProducer : public edm::global::EDProducer<> {
0017 public:
0018   explicit VertexAssociatorByTracksProducer(const edm::ParameterSet &);
0019   ~VertexAssociatorByTracksProducer() override;
0020 
0021   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0022 
0023 private:
0024   void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0025 
0026   // ----------member data ---------------------------
0027   const double R2SMatchedSimRatio_;
0028   const double R2SMatchedRecoRatio_;
0029   const double S2RMatchedSimRatio_;
0030   const double S2RMatchedRecoRatio_;
0031 
0032   const TrackingParticleSelector selector_;
0033   const reco::TrackBase::TrackQuality trackQuality_;
0034 
0035   edm::EDGetTokenT<reco::RecoToSimCollection> trackRecoToSimAssociationToken_;
0036   edm::EDGetTokenT<reco::SimToRecoCollection> trackSimToRecoAssociationToken_;
0037 };
0038 
0039 namespace {
0040   TrackingParticleSelector makeSelector(const edm::ParameterSet &param) {
0041     return TrackingParticleSelector(param.getParameter<double>("ptMinTP"),
0042                                     param.getParameter<double>("ptMaxTP"),
0043                                     param.getParameter<double>("minRapidityTP"),
0044                                     param.getParameter<double>("maxRapidityTP"),
0045                                     param.getParameter<double>("tipTP"),
0046                                     param.getParameter<double>("lipTP"),
0047                                     param.getParameter<int>("minHitTP"),
0048                                     param.getParameter<bool>("signalOnlyTP"),
0049                                     param.getParameter<bool>("intimeOnlyTP"),
0050                                     param.getParameter<bool>("chargedOnlyTP"),
0051                                     param.getParameter<bool>("stableOnlyTP"),
0052                                     param.getParameter<std::vector<int>>("pdgIdTP"));
0053   }
0054 }  // namespace
0055 
0056 VertexAssociatorByTracksProducer::VertexAssociatorByTracksProducer(const edm::ParameterSet &config)
0057     : R2SMatchedSimRatio_(config.getParameter<double>("R2SMatchedSimRatio")),
0058       R2SMatchedRecoRatio_(config.getParameter<double>("R2SMatchedRecoRatio")),
0059       S2RMatchedSimRatio_(config.getParameter<double>("S2RMatchedSimRatio")),
0060       S2RMatchedRecoRatio_(config.getParameter<double>("S2RMatchedRecoRatio")),
0061       selector_(makeSelector(config.getParameter<edm::ParameterSet>("trackingParticleSelector"))),
0062       trackQuality_(reco::TrackBase::qualityByName(config.getParameter<std::string>("trackQuality"))),
0063       trackRecoToSimAssociationToken_(
0064           consumes<reco::RecoToSimCollection>(config.getParameter<edm::InputTag>("trackAssociation"))),
0065       trackSimToRecoAssociationToken_(
0066           consumes<reco::SimToRecoCollection>(config.getParameter<edm::InputTag>("trackAssociation"))) {
0067   produces<reco::VertexToTrackingVertexAssociator>();
0068 }
0069 
0070 VertexAssociatorByTracksProducer::~VertexAssociatorByTracksProducer() {}
0071 
0072 void VertexAssociatorByTracksProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0073   edm::ParameterSetDescription desc;
0074 
0075   // Matching conditions
0076   desc.add<double>("R2SMatchedSimRatio", 0.3);
0077   desc.add<double>("R2SMatchedRecoRatio", 0.0);
0078   desc.add<double>("S2RMatchedSimRatio", 0.0);
0079   desc.add<double>("S2RMatchedRecoRatio", 0.3);
0080 
0081   // RecoTrack selection
0082   desc.add<std::string>("trackQuality", "highPurity");
0083 
0084   // TrackingParticle selection
0085   edm::ParameterSetDescription descTp;
0086 
0087   descTp.add<double>("lipTP", 30.0);
0088   descTp.add<bool>("chargedOnlyTP", true);
0089   descTp.add<std::vector<int>>("pdgIdTP", std::vector<int>());
0090   descTp.add<bool>("signalOnlyTP", true);
0091   descTp.add<double>("minRapidityTP", -2.4);
0092   descTp.add<int>("minHitTP", 0);
0093   descTp.add<double>("ptMinTP", 0.9);
0094   descTp.add<double>("ptMaxTP", 1e100);
0095   descTp.add<double>("maxRapidityTP", 2.4);
0096   descTp.add<double>("tipTP", 3.5);
0097   desc.add<edm::ParameterSetDescription>("trackingParticleSelector", descTp);
0098 
0099   // Track-TrackingParticle association
0100   desc.add<edm::InputTag>("trackAssociation", edm::InputTag("trackingParticleRecoTrackAsssociation"));
0101 
0102   descriptions.add("VertexAssociatorByTracks", desc);
0103 }
0104 
0105 void VertexAssociatorByTracksProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &) const {
0106   edm::Handle<reco::RecoToSimCollection> recotosimCollectionH;
0107   iEvent.getByToken(trackRecoToSimAssociationToken_, recotosimCollectionH);
0108 
0109   edm::Handle<reco::SimToRecoCollection> simtorecoCollectionH;
0110   iEvent.getByToken(trackSimToRecoAssociationToken_, simtorecoCollectionH);
0111 
0112   auto impl = std::make_unique<VertexAssociatorByTracks>(&(iEvent.productGetter()),
0113                                                          R2SMatchedSimRatio_,
0114                                                          R2SMatchedRecoRatio_,
0115                                                          S2RMatchedSimRatio_,
0116                                                          S2RMatchedRecoRatio_,
0117                                                          &selector_,
0118                                                          trackQuality_,
0119                                                          recotosimCollectionH.product(),
0120                                                          simtorecoCollectionH.product());
0121 
0122   auto toPut = std::make_unique<reco::VertexToTrackingVertexAssociator>(std::move(impl));
0123   iEvent.put(std::move(toPut));
0124 }
0125 
0126 DEFINE_FWK_MODULE(VertexAssociatorByTracksProducer);