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  LogTrace("MagGeoBuilder") << "info:Constructing a DD4hep_VolumeBasedMagneticFieldESProducer";
59 
60  auto cc = setWhatProduced(this, iConfig.getUntrackedParameter<std::string>("label", ""));
61  cpvToken_ = cc.consumes(edm::ESInputTag{"", "magfield"});
62  if (useParametrizedTrackerField_) {
63  paramFieldToken_ = cc.consumes(edm::ESInputTag{"", iConfig.getParameter<std::string>("paramLabel")});
64  }
65 }
66 
67 // ------------ method called to produce the data ------------
69  const IdealMagneticFieldRecord& iRecord) {
70  if (debug_) {
71  LogTrace("MagGeoBuilder") << "DD4hep_VolumeBasedMagneticFieldESProducer::produce() " << version_;
72  }
73 
75 
76  // Set scaling factors
77  if (!conf_.keys.empty()) {
78  builder.setScaling(conf_.keys, conf_.values);
79  }
80 
81  // Set specification for the grid tables to be used.
82  if (!conf_.gridFiles.empty()) {
83  builder.setGridFiles(conf_.gridFiles);
84  }
85 
86  auto cpv = iRecord.getTransientHandle(cpvToken_);
87  const cms::DDCompactView* cpvPtr = cpv.product();
88  const cms::DDDetector* det = cpvPtr->detector();
89  builder.build(det);
90  LogTrace("MagGeoBuilder") << "produce() finished build";
91 
92  // Get slave field (from ES)
93  const MagneticField* paramField = nullptr;
95  LogTrace("MagGeoBuilder") << "Getting MF for parametrized field";
96  paramField = &iRecord.get(paramFieldToken_);
97  }
98  return std::make_unique<VolumeBasedMagneticField>(conf_.geometryVersion,
99  builder.barrelLayers(),
100  builder.endcapSectors(),
101  builder.barrelVolumes(),
102  builder.endcapVolumes(),
103  builder.maxR(),
104  builder.maxZ(),
105  paramField,
106  false);
107 }
108 
ESTransientHandle< ProductT > getTransientHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
std::vector< MagBLayer * > barrelLayers() const
Get barrel layers.
std::unique_ptr< MagneticField > produce(const IdealMagneticFieldRecord &iRecord)
const DD4hep_VolumeBasedMagneticFieldESProducer & operator=(const DD4hep_VolumeBasedMagneticFieldESProducer &)=delete
const cms::DDDetector * detector() const
Definition: DDCompactView.h:34
std::vector< double > values
#define LogTrace(id)
magneticfield::TableFileMap gridFiles
Specification of which data table is to be used for each volume.
T getUntrackedParameter(std::string const &, T const &) const
std::vector< int > keys
Scaling factors for the field in specific volumes.
void setGridFiles(const TableFileMap &gridFiles)
edm::ESGetToken< cms::DDCompactView, IdealMagneticFieldRecord > cpvToken_
std::string version
Version of the data tables to be used.
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > paramFieldToken_
std::vector< MagESector * > endcapSectors() const
Get endcap layers.
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)
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
std::vector< MagVolume6Faces * > endcapVolumes() const