Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-21 01:40:08

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 <memory>
0008 
0009 #include "DataFormats/Common/interface/Handle.h"
0010 #include "DataFormats/TrajectorySeed/interface/PropagationDirection.h"
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 #include "FWCore/Framework/interface/ESProducer.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/Framework/interface/ModuleFactory.h"
0015 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0018 #include "FWCore/Utilities/interface/Exception.h"
0019 #include "MagneticField/Engine/interface/MagneticField.h"
0020 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0021 #include "TrackingTools/GeomPropagators/interface/SmartPropagator.h"
0022 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0023 
0024 class SmartPropagatorESProducer : public edm::ESProducer {
0025 public:
0026   /// Constructor
0027   SmartPropagatorESProducer(const edm::ParameterSet&);
0028 
0029   /// Destructor
0030   ~SmartPropagatorESProducer() override = default;
0031 
0032   // Operations
0033   std::unique_ptr<Propagator> produce(const TrackingComponentsRecord&);
0034 
0035   // fillDescriptions
0036   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0037 
0038 private:
0039   PropagationDirection thePropagationDirection;
0040   double theEpsilon;
0041   edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magToken_;
0042   edm::ESGetToken<Propagator, TrackingComponentsRecord> trackerToken_;
0043   edm::ESGetToken<Propagator, TrackingComponentsRecord> muonToken_;
0044 };
0045 
0046 using namespace edm;
0047 using namespace std;
0048 
0049 SmartPropagatorESProducer::SmartPropagatorESProducer(const ParameterSet& parameterSet) {
0050   string myname = parameterSet.getParameter<string>("ComponentName");
0051 
0052   string propDir = parameterSet.getParameter<string>("PropagationDirection");
0053 
0054   if (propDir == "oppositeToMomentum")
0055     thePropagationDirection = oppositeToMomentum;
0056   else if (propDir == "alongMomentum")
0057     thePropagationDirection = alongMomentum;
0058   else if (propDir == "anyDirection")
0059     thePropagationDirection = anyDirection;
0060   else
0061     throw cms::Exception("SmartPropagatorESProducer") << "Wrong fit direction chosen in SmartPropagatorESProducer";
0062 
0063   theEpsilon = parameterSet.getParameter<double>("Epsilon");
0064 
0065   auto cc = setWhatProduced(this, myname);
0066   magToken_ = cc.consumes();
0067   trackerToken_ = cc.consumes(edm::ESInputTag("", parameterSet.getParameter<string>("TrackerPropagator")));
0068   muonToken_ = cc.consumes(edm::ESInputTag("", parameterSet.getParameter<string>("MuonPropagator")));
0069 }
0070 
0071 std::unique_ptr<Propagator> SmartPropagatorESProducer::produce(const TrackingComponentsRecord& iRecord) {
0072   return std::make_unique<SmartPropagator>(
0073       iRecord.get(trackerToken_), iRecord.get(muonToken_), &iRecord.get(magToken_), thePropagationDirection, theEpsilon);
0074 }
0075 
0076 void SmartPropagatorESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0077   edm::ParameterSetDescription desc;
0078   desc.add<string>("ComponentName", "SmartPropagator");
0079   desc.add<string>("PropagationDirection", "alongMomentum");
0080   desc.add<double>("Epsilon", 5.0);
0081   desc.add<string>("TrackerPropagator", "PropagatorWithMaterial");
0082   desc.add<string>("MuonPropagator", "SteppingHelixPropagatorAlong");
0083   descriptions.addWithDefaultLabel(desc);
0084 }
0085 
0086 DEFINE_FWK_EVENTSETUP_MODULE(SmartPropagatorESProducer);