CMS 3D CMS Logo

DD4hep_VolumeBasedMagneticFieldESProducer.cc
Go to the documentation of this file.
1 
13 
17 
23 
24 #include <string>
25 
26 namespace magneticfield {
27 
29  public:
31 
32  // forbid copy ctor and assignment op.
35  delete;
36 
37  std::unique_ptr<MagneticField> produce(const IdealMagneticFieldRecord& iRecord);
38 
39  private:
41  const bool debug_;
47  };
48 } // namespace magneticfield
49 
50 using namespace magneticfield;
51 
53  : pset_{iConfig},
54  debug_{iConfig.getUntrackedParameter<bool>("debugBuilder", false)},
55  useParametrizedTrackerField_{iConfig.getParameter<bool>("useParametrizedTrackerField")},
56  conf_{iConfig, debug_},
57  version_{iConfig.getParameter<std::string>("version")} {
58  // LogVerbatim used because LogTrace messages don't seem to appear even when fully enabled.
59  edm::LogVerbatim("DD4hep_VolumeBasedMagneticFieldESProducer")
60  << "info:Constructing a DD4hep_VolumeBasedMagneticFieldESProducer";
61 
62  auto cc = setWhatProduced(this, iConfig.getUntrackedParameter<std::string>("label", ""));
63  cc.setConsumes(cpvToken_, edm::ESInputTag{"", "magfield"});
65  cc.setConsumes(paramFieldToken_, edm::ESInputTag{"", iConfig.getParameter<std::string>("paramLabel")});
66  }
67 }
68 
69 // ------------ method called to produce the data ------------
71  const IdealMagneticFieldRecord& iRecord) {
72  if (debug_) {
73  edm::LogVerbatim("DD4hep_VolumeBasedMagneticFieldESProducer")
74  << "DD4hep_VolumeBasedMagneticFieldESProducer::produce() " << version_;
75  }
76 
78 
79  // Set scaling factors
80  if (!conf_.keys.empty()) {
81  builder.setScaling(conf_.keys, conf_.values);
82  }
83 
84  // Set specification for the grid tables to be used.
85  if (!conf_.gridFiles.empty()) {
86  builder.setGridFiles(conf_.gridFiles);
87  }
88 
89  auto cpv = iRecord.getTransientHandle(cpvToken_);
90  const cms::DDCompactView* cpvPtr = cpv.product();
91  const cms::DDDetector* det = cpvPtr->detector();
92  builder.build(det);
93  edm::LogVerbatim("DD4hep_VolumeBasedMagneticFieldESProducer") << "produce() finished build";
94 
95  // Get slave field (from ES)
96  const MagneticField* paramField = nullptr;
98  edm::LogVerbatim("DD4hep_VolumeBasedMagneticFieldESProducer") << "Getting MF for parametrized field";
99  paramField = &iRecord.get(paramFieldToken_);
100  }
101  return std::make_unique<VolumeBasedMagneticField>(conf_.geometryVersion,
102  builder.barrelLayers(),
103  builder.endcapSectors(),
104  builder.barrelVolumes(),
105  builder.endcapVolumes(),
106  builder.maxR(),
107  builder.maxZ(),
108  paramField,
109  false);
110 }
111 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
std::vector< MagVolume6Faces * > endcapVolumes() const
std::unique_ptr< MagneticField > produce(const IdealMagneticFieldRecord &iRecord)
const DD4hep_VolumeBasedMagneticFieldESProducer & operator=(const DD4hep_VolumeBasedMagneticFieldESProducer &)=delete
ESTransientHandle< ProductT > getTransientHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
std::vector< double > values
magneticfield::TableFileMap gridFiles
Specification of which data table is to be used for each volume.
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
std::vector< int > keys
Scaling factors for the field in specific volumes.
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void setGridFiles(const TableFileMap &gridFiles)
std::vector< MagBLayer * > barrelLayers() const
Get barrel layers.
edm::ESGetToken< cms::DDCompactView, IdealMagneticFieldRecord > cpvToken_
std::string version
Version of the data tables to be used.
std::vector< MagESector * > endcapSectors() const
Get endcap layers.
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > paramFieldToken_
std::vector< MagVolume6Faces * > barrelVolumes() const
void build(const cms::DDDetector *det)
int geometryVersion
Version of the geometry to be used.
void setScaling(const std::vector< int > &keys, const std::vector< double > &values)
const cms::DDDetector * detector() const
Definition: DDCompactView.h:32