Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Framework/interface/ESProducer.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0004 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0005 #include "TrackingTools/GeomPropagators/interface/AnalyticalPropagator.h"
0006 
0007 #include "MagneticField/Engine/interface/MagneticField.h"
0008 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0009 
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 #include "FWCore/Framework/interface/ModuleFactory.h"
0013 #include "FWCore/Framework/interface/ESProducer.h"
0014 #include <FWCore/Utilities/interface/ESInputTag.h>
0015 
0016 #include <string>
0017 #include <memory>
0018 
0019 using namespace edm;
0020 
0021 class AnalyticalPropagatorESProducer : public edm::ESProducer {
0022 public:
0023   AnalyticalPropagatorESProducer(const edm::ParameterSet& p);
0024   std::unique_ptr<Propagator> produce(const TrackingComponentsRecord&);
0025 
0026   static void fillDescriptions(edm::ConfigurationDescriptions& oDesc);
0027 
0028 private:
0029   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magToken_;
0030   const double dphiCut_;
0031   const PropagationDirection dir_;
0032 };
0033 
0034 AnalyticalPropagatorESProducer::AnalyticalPropagatorESProducer(const edm::ParameterSet& p)
0035     : magToken_{setWhatProduced(this, p.getParameter<std::string>("ComponentName"))
0036                     .consumesFrom<MagneticField, IdealMagneticFieldRecord>(
0037                         edm::ESInputTag("", p.getParameter<std::string>("SimpleMagneticField")))},
0038       dphiCut_{p.getParameter<double>("MaxDPhi")},
0039       dir_{[](std::string const& pdir) {
0040         if (pdir == "oppositeToMomentum")
0041           return oppositeToMomentum;
0042         if (pdir == "alongMomentum")
0043           return alongMomentum;
0044         if (pdir == "anyDirection")
0045           return anyDirection;
0046         return alongMomentum;
0047       }(p.getParameter<std::string>("PropagationDirection"))} {}
0048 
0049 void AnalyticalPropagatorESProducer::fillDescriptions(edm::ConfigurationDescriptions& oDesc) {
0050   edm::ParameterSetDescription desc;
0051   desc.add<std::string>("ComponentName")->setComment("the data label assigned to the Propagator");
0052   desc.add<std::string>("SimpleMagneticField", "")->setComment("the data label used to retrieve the MagneticField");
0053   desc.add<std::string>("PropagationDirection");
0054   desc.add<double>("MaxDPhi");
0055 
0056   oDesc.addDefault(desc);
0057 }
0058 
0059 std::unique_ptr<Propagator> AnalyticalPropagatorESProducer::produce(const TrackingComponentsRecord& iRecord) {
0060   return std::make_unique<AnalyticalPropagator>(&iRecord.get(magToken_), dir_, dphiCut_);
0061 }
0062 
0063 DEFINE_FWK_EVENTSETUP_MODULE(AnalyticalPropagatorESProducer);