Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:43

0001 /** \class SmartPropagatorESProducer
0002  *  ES producer needed to put the SmartPropagator inside the EventSetup
0003  *
0004  *  \author R. Bellan - INFN Torino <riccardo.bellan@cern.ch>
0005  */
0006 
0007 #include "FWCore/Framework/interface/ESProducer.h"
0008 
0009 #include "TrackingTools/GeomPropagators/interface/SmartPropagator.h"
0010 #include "DataFormats/TrajectorySeed/interface/PropagationDirection.h"
0011 
0012 #include "FWCore/Framework/interface/EventSetup.h"
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 #include "DataFormats/Common/interface/Handle.h"
0015 #include "FWCore/Framework/interface/ModuleFactory.h"
0016 #include "FWCore/Utilities/interface/Exception.h"
0017 
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0020 
0021 #include "MagneticField/Engine/interface/MagneticField.h"
0022 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0023 
0024 #include <memory>
0025 
0026 class SmartPropagatorESProducer : public edm::ESProducer {
0027 public:
0028   /// Constructor
0029   SmartPropagatorESProducer(const edm::ParameterSet&);
0030 
0031   /// Destructor
0032   ~SmartPropagatorESProducer() override;
0033 
0034   // Operations
0035   std::unique_ptr<Propagator> produce(const TrackingComponentsRecord&);
0036 
0037 private:
0038   PropagationDirection thePropagationDirection;
0039   double theEpsilon;
0040   edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magToken_;
0041   edm::ESGetToken<Propagator, TrackingComponentsRecord> trackerToken_;
0042   edm::ESGetToken<Propagator, TrackingComponentsRecord> muonToken_;
0043 };
0044 
0045 using namespace edm;
0046 using namespace std;
0047 
0048 SmartPropagatorESProducer::SmartPropagatorESProducer(const ParameterSet& parameterSet) {
0049   string myname = parameterSet.getParameter<string>("ComponentName");
0050 
0051   string propDir = parameterSet.getParameter<string>("PropagationDirection");
0052 
0053   if (propDir == "oppositeToMomentum")
0054     thePropagationDirection = oppositeToMomentum;
0055   else if (propDir == "alongMomentum")
0056     thePropagationDirection = alongMomentum;
0057   else if (propDir == "anyDirection")
0058     thePropagationDirection = anyDirection;
0059   else
0060     throw cms::Exception("SmartPropagatorESProducer") << "Wrong fit direction chosen in SmartPropagatorESProducer";
0061 
0062   theEpsilon = parameterSet.getParameter<double>("Epsilon");
0063 
0064   auto cc = setWhatProduced(this, myname);
0065   magToken_ = cc.consumes();
0066   trackerToken_ = cc.consumes(edm::ESInputTag("", parameterSet.getParameter<string>("TrackerPropagator")));
0067   muonToken_ = cc.consumes(edm::ESInputTag("", parameterSet.getParameter<string>("MuonPropagator")));
0068 }
0069 
0070 SmartPropagatorESProducer::~SmartPropagatorESProducer() {}
0071 
0072 std::unique_ptr<Propagator> SmartPropagatorESProducer::produce(const TrackingComponentsRecord& iRecord) {
0073   return std::make_unique<SmartPropagator>(
0074       iRecord.get(trackerToken_), iRecord.get(muonToken_), &iRecord.get(magToken_), thePropagationDirection, theEpsilon);
0075 }
0076 
0077 DEFINE_FWK_EVENTSETUP_MODULE(SmartPropagatorESProducer);