Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:26:31

0001 #include "FWCore/Framework/interface/ESProducer.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "TrackingTools/GeomPropagators/interface/StraightLinePropagator.h"
0004 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0005 #include "MagneticField/Engine/interface/MagneticField.h"
0006 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0007 
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/Framework/interface/ESHandle.h"
0010 #include "FWCore/Framework/interface/ModuleFactory.h"
0011 
0012 #include <string>
0013 #include <memory>
0014 
0015 class StraightLinePropagatorESProducer : public edm::ESProducer {
0016 public:
0017   StraightLinePropagatorESProducer(const edm::ParameterSet& p);
0018   ~StraightLinePropagatorESProducer() override;
0019   std::unique_ptr<Propagator> produce(const TrackingComponentsRecord&);
0020 
0021 private:
0022   const PropagationDirection dir_;
0023   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magToken_;
0024 };
0025 
0026 using namespace edm;
0027 
0028 StraightLinePropagatorESProducer::StraightLinePropagatorESProducer(const edm::ParameterSet& p)
0029     : dir_{[](std::string const& pdir) {
0030         if (pdir == "oppositeToMomentum")
0031           return oppositeToMomentum;
0032         else if (pdir == "anyDirection")
0033           return anyDirection;
0034         return alongMomentum;
0035       }(p.getParameter<std::string>("PropagationDirection"))},
0036       magToken_{setWhatProduced(this, p.getParameter<std::string>("ComponentName"))
0037                     .consumesFrom<MagneticField, IdealMagneticFieldRecord>()}
0038 
0039 {}
0040 
0041 StraightLinePropagatorESProducer::~StraightLinePropagatorESProducer() {}
0042 
0043 std::unique_ptr<Propagator> StraightLinePropagatorESProducer::produce(const TrackingComponentsRecord& iRecord) {
0044   return std::make_unique<StraightLinePropagator>(&iRecord.get(magToken_), dir_);
0045 }
0046 
0047 DEFINE_FWK_EVENTSETUP_MODULE(StraightLinePropagatorESProducer);