Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    SimTracker/TrackAssociatorProducers
0004 // Class:      TrackAssociatorByHitsProducer
0005 //
0006 /**\class TrackAssociatorByHitsProducer TrackAssociatorByHitsProducer.cc SimTracker/TrackAssociatorProducers/plugins/TrackAssociatorByHitsProducer.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Christopher Jones
0015 //         Created:  Mon, 05 Jan 2015 20:38:27 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/global/EDProducer.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 #include "FWCore/Framework/interface/EventSetup.h"
0029 #include "FWCore/Utilities/interface/EDGetToken.h"
0030 
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0033 
0034 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0035 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0036 
0037 #include "TrackAssociatorByHitsImpl.h"
0038 #include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h"
0039 #include "SimTracker/TrackerHitAssociation/interface/TrackerHitAssociator.h"
0040 
0041 //
0042 // class declaration
0043 //
0044 
0045 using SimHitTPAssociationList = TrackAssociatorByHitsImpl::SimHitTPAssociationList;
0046 
0047 class TrackAssociatorByHitsProducer : public edm::global::EDProducer<> {
0048 public:
0049   explicit TrackAssociatorByHitsProducer(const edm::ParameterSet&);
0050   ~TrackAssociatorByHitsProducer() override = default;
0051 
0052   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0053 
0054 private:
0055   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0056 
0057   // ----------member data ---------------------------
0058   TrackerHitAssociator::Config trackerHitAssociatorConfig_;
0059   edm::EDGetTokenT<SimHitTPAssociationList> simHitTpMapToken_;
0060   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0061   edm::EDPutTokenT<reco::TrackToTrackingParticleAssociator> putToken_;
0062 
0063   TrackAssociatorByHitsImpl::SimToRecoDenomType SimToRecoDenominator;
0064   const double quality_SimToReco;
0065   const double purity_SimToReco;
0066   const double cut_RecoToSim;
0067   const bool UsePixels;
0068   const bool UseGrouped;
0069   const bool UseSplitting;
0070   const bool ThreeHitTracksAreSpecial;
0071   const bool AbsoluteNumberOfHits;
0072 };
0073 
0074 //
0075 // constants, enums and typedefs
0076 //
0077 
0078 //
0079 // static data member definitions
0080 //
0081 
0082 //
0083 // constructors and destructor
0084 //
0085 TrackAssociatorByHitsProducer::TrackAssociatorByHitsProducer(const edm::ParameterSet& iConfig)
0086     : trackerHitAssociatorConfig_(iConfig, consumesCollector()),
0087       simHitTpMapToken_(consumes<SimHitTPAssociationList>(iConfig.getParameter<edm::InputTag>("simHitTpMapTag"))),
0088       tTopoToken_(esConsumes()),
0089       putToken_(produces<reco::TrackToTrackingParticleAssociator>()),
0090       SimToRecoDenominator(TrackAssociatorByHitsImpl::denomnone),
0091       quality_SimToReco(iConfig.getParameter<double>("Quality_SimToReco")),
0092       purity_SimToReco(iConfig.getParameter<double>("Purity_SimToReco")),
0093       cut_RecoToSim(iConfig.getParameter<double>("Cut_RecoToSim")),
0094       UsePixels(iConfig.getParameter<bool>("UsePixels")),
0095       UseGrouped(iConfig.getParameter<bool>("UseGrouped")),
0096       UseSplitting(iConfig.getParameter<bool>("UseSplitting")),
0097       ThreeHitTracksAreSpecial(iConfig.getParameter<bool>("ThreeHitTracksAreSpecial")),
0098       AbsoluteNumberOfHits(iConfig.getParameter<bool>("AbsoluteNumberOfHits")) {
0099   std::string tmp = iConfig.getParameter<std::string>("SimToRecoDenominator");
0100   if (tmp == "sim") {
0101     SimToRecoDenominator = TrackAssociatorByHitsImpl::denomsim;
0102   } else if (tmp == "reco") {
0103     SimToRecoDenominator = TrackAssociatorByHitsImpl::denomreco;
0104   }
0105 
0106   if (SimToRecoDenominator == TrackAssociatorByHitsImpl::denomnone) {
0107     throw cms::Exception("TrackAssociatorByHitsImpl") << "SimToRecoDenominator not specified as sim or reco";
0108   }
0109 }
0110 
0111 //
0112 // member functions
0113 //
0114 
0115 // ------------ method called to produce the data  ------------
0116 void TrackAssociatorByHitsProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0117   using namespace edm;
0118 
0119   auto thAssoc = std::make_unique<TrackerHitAssociator>(iEvent, trackerHitAssociatorConfig_);
0120 
0121   iEvent.emplace(putToken_,
0122                  std::make_unique<TrackAssociatorByHitsImpl>(
0123                      iEvent.productGetter(),
0124                      std::move(thAssoc),
0125                      &iSetup.getData(tTopoToken_),
0126                      //warning: make sure the TP collection used in the map is the same used in the associator!
0127                      &iEvent.get(simHitTpMapToken_),
0128                      SimToRecoDenominator,
0129                      quality_SimToReco,
0130                      purity_SimToReco,
0131                      cut_RecoToSim,
0132                      UsePixels,
0133                      UseGrouped,
0134                      UseSplitting,
0135                      ThreeHitTracksAreSpecial,
0136                      AbsoluteNumberOfHits));
0137 }
0138 
0139 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0140 void TrackAssociatorByHitsProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0141   //The following says we do not know what parameters are allowed so do no validation
0142   // Please change this to state exactly what you do use, even if it is no parameters
0143   edm::ParameterSetDescription desc;
0144   desc.setUnknown();
0145   descriptions.addDefault(desc);
0146 }
0147 
0148 //define this as a plug-in
0149 DEFINE_FWK_MODULE(TrackAssociatorByHitsProducer);