Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
0002 #include "MagneticField/Engine/interface/MagneticField.h"
0003 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0004 #include "MagneticField/VolumeBasedEngine/interface/VolumeBasedMagneticField.h"
0005 
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "FWCore/Framework/interface/ModuleFactory.h"
0009 #include "FWCore/Framework/interface/ESProducer.h"
0010 
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 
0013 #include <string>
0014 #include <memory>
0015 
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0018 
0019 class SteppingHelixPropagatorESProducer : public edm::ESProducer {
0020 public:
0021   SteppingHelixPropagatorESProducer(const edm::ParameterSet& p);
0022   ~SteppingHelixPropagatorESProducer() override;
0023   std::unique_ptr<Propagator> produce(const TrackingComponentsRecord&);
0024 
0025 private:
0026   const edm::ParameterSet pset_;
0027   edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magToken_;
0028   edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> vbMagToken_;
0029   const bool setVBFPointer_;
0030 };
0031 
0032 using namespace edm;
0033 
0034 SteppingHelixPropagatorESProducer::SteppingHelixPropagatorESProducer(const edm::ParameterSet& p)
0035     : pset_{p}, setVBFPointer_{pset_.getParameter<bool>("SetVBFPointer")} {
0036   std::string myname = p.getParameter<std::string>("ComponentName");
0037   auto c = setWhatProduced(this, myname);
0038   magToken_ = c.consumes();
0039   if (setVBFPointer_) {
0040     vbMagToken_ = c.consumes(edm::ESInputTag("", pset_.getParameter<std::string>("VBFName")));
0041   }
0042 }
0043 
0044 SteppingHelixPropagatorESProducer::~SteppingHelixPropagatorESProducer() {}
0045 
0046 std::unique_ptr<Propagator> SteppingHelixPropagatorESProducer::produce(const TrackingComponentsRecord& iRecord) {
0047   //   if (_propagator){
0048   //     delete _propagator;
0049   //     _propagator = 0;
0050   //   }
0051   auto const& magfield = iRecord.get(magToken_);
0052 
0053   std::string pdir = pset_.getParameter<std::string>("PropagationDirection");
0054 
0055   PropagationDirection dir = alongMomentum;
0056 
0057   if (pdir == "oppositeToMomentum")
0058     dir = oppositeToMomentum;
0059   if (pdir == "alongMomentum")
0060     dir = alongMomentum;
0061   if (pdir == "anyDirection")
0062     dir = anyDirection;
0063 
0064   std::unique_ptr<SteppingHelixPropagator> shProp;
0065   shProp = std::make_unique<SteppingHelixPropagator>(&magfield, dir);
0066 
0067   bool useInTeslaFromMagField = pset_.getParameter<bool>("useInTeslaFromMagField");
0068   bool useMagVolumes = pset_.getParameter<bool>("useMagVolumes");
0069 
0070   // if useMagVolumes == true and an alternate VBF field is not specified with setVBFPointer_,
0071   // Force "useInTeslaFromMagField=true" for a B=0 VBF map.
0072   if (useMagVolumes == true && !useInTeslaFromMagField && !setVBFPointer_ && magfield.nominalValue() == 0) {
0073     const VolumeBasedMagneticField* vbfCPtr = dynamic_cast<const VolumeBasedMagneticField*>(&magfield);
0074     if (vbfCPtr == nullptr) {
0075       edm::LogWarning("SteppingHelixPropagator")
0076           << "Config specifies useMagVolumes==True but no VBF field available: SHP has no access to yoke material "
0077              "properties. Use setVBFPointer=true and VBFName cards to set a VBF field, otherwise set "
0078              "useMagVolumes==False."
0079           << std::endl;
0080     } else {
0081       edm::LogInfo("SteppingHelixPropagator")
0082           << "Config specifies useMagVolumes==true and VBF field available: Forcing useInTeslaFromMagField = True."
0083           << std::endl;
0084       useInTeslaFromMagField = true;
0085     }
0086   }
0087 
0088   if (setVBFPointer_) {
0089     auto const& vbfField = iRecord.get(vbMagToken_);
0090     const VolumeBasedMagneticField* vbfCPtr = dynamic_cast<const VolumeBasedMagneticField*>(&vbfField);
0091     shProp->setVBFPointer(vbfCPtr);
0092   }
0093 
0094   shProp->setUseInTeslaFromMagField(useInTeslaFromMagField);
0095 
0096   bool haveX0Corr = pset_.getParameter<bool>("ApplyRadX0Correction");
0097   shProp->applyRadX0Correction(haveX0Corr);
0098 
0099   bool assumeNoMaterial = pset_.getParameter<bool>("AssumeNoMaterial");
0100   shProp->setMaterialMode(assumeNoMaterial);
0101 
0102   bool noErrorPropagation = pset_.getParameter<bool>("NoErrorPropagation");
0103   shProp->setNoErrorPropagation(noErrorPropagation);
0104 
0105   bool debugMode = pset_.getParameter<bool>("debug");
0106   shProp->setDebug(debugMode);
0107 
0108   shProp->setUseMagVolumes(useMagVolumes);
0109 
0110   bool useMatVolumes = pset_.getParameter<bool>("useMatVolumes");
0111   shProp->setUseMatVolumes(useMatVolumes);
0112 
0113   bool useIsYokeFlag = pset_.getParameter<bool>("useIsYokeFlag");
0114   shProp->setUseIsYokeFlag(useIsYokeFlag);
0115 
0116   bool returnTangentPlane = pset_.getParameter<bool>("returnTangentPlane");
0117   shProp->setReturnTangentPlane(returnTangentPlane);
0118 
0119   bool sendLogWarning = pset_.getParameter<bool>("sendLogWarning");
0120   shProp->setSendLogWarning(sendLogWarning);
0121 
0122   bool useTuningForL2Speed = pset_.getParameter<bool>("useTuningForL2Speed");
0123   shProp->setUseTuningForL2Speed(useTuningForL2Speed);
0124 
0125   bool useECoffsets = pset_.getParameter<bool>("useEndcapShiftsInZ");
0126   if (useECoffsets) {
0127     double valPos = pset_.getParameter<double>("endcapShiftInZPos");
0128     double valNeg = pset_.getParameter<double>("endcapShiftInZNeg");
0129     shProp->setEndcapShiftsInZPosNeg(valPos, valNeg);
0130   }
0131 
0132   return shProp;
0133 }
0134 
0135 #include "FWCore/Utilities/interface/typelookup.h"
0136 
0137 DEFINE_FWK_EVENTSETUP_MODULE(SteppingHelixPropagatorESProducer);