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  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
40 
41  private:
43  const bool debug_;
50  };
51 } // namespace magneticfield
52 
53 using namespace magneticfield;
54 
56  : pset_{iConfig},
57  debug_{iConfig.getUntrackedParameter<bool>("debugBuilder", false)},
58  useParametrizedTrackerField_{iConfig.getParameter<bool>("useParametrizedTrackerField")},
59  useMergeFileIfAvailable_{iConfig.getParameter<bool>("useMergeFileIfAvailable")},
60  conf_{iConfig, debug_},
61  version_{iConfig.getParameter<std::string>("version")} {
62  LogTrace("MagGeoBuilder") << "info:Constructing a DD4hep_VolumeBasedMagneticFieldESProducer";
63 
64  auto cc = setWhatProduced(this, iConfig.getUntrackedParameter<std::string>("label", ""));
65  cpvToken_ = cc.consumes(edm::ESInputTag{"", "magfield"});
66  if (useParametrizedTrackerField_) {
67  paramFieldToken_ = cc.consumes(edm::ESInputTag{"", iConfig.getParameter<std::string>("paramLabel")});
68  }
69 }
70 
71 // ------------ method called to produce the data ------------
73  const IdealMagneticFieldRecord& iRecord) {
74  if (debug_) {
75  LogTrace("MagGeoBuilder") << "DD4hep_VolumeBasedMagneticFieldESProducer::produce() " << version_;
76  }
77 
79 
80  // Set scaling factors
81  if (!conf_.keys.empty()) {
82  builder.setScaling(conf_.keys, conf_.values);
83  }
84 
85  // Set specification for the grid tables to be used.
86  if (!conf_.gridFiles.empty()) {
87  builder.setGridFiles(conf_.gridFiles);
88  }
89 
90  auto cpv = iRecord.getTransientHandle(cpvToken_);
91  const cms::DDCompactView* cpvPtr = cpv.product();
92  const cms::DDDetector* det = cpvPtr->detector();
93  builder.build(det);
94  LogTrace("MagGeoBuilder") << "produce() finished build";
95 
96  // Get slave field (from ES)
97  const MagneticField* paramField = nullptr;
99  LogTrace("MagGeoBuilder") << "Getting MF for parametrized field";
100  paramField = &iRecord.get(paramFieldToken_);
101  }
102  return std::make_unique<VolumeBasedMagneticField>(conf_.geometryVersion,
103  builder.barrelLayers(),
104  builder.endcapSectors(),
105  builder.barrelVolumes(),
106  builder.endcapVolumes(),
107  builder.maxR(),
108  builder.maxZ(),
109  paramField,
110  false);
111 }
112 
115  desc.addUntracked<bool>("debugBuilder", false);
116  desc.add<bool>("useMergeFileIfAvailable", true);
117  desc.add<bool>("useParametrizedTrackerField");
118  desc.addUntracked<std::string>("label", "");
119  desc.add<std::string>("version");
120  desc.add<std::string>("paramLabel");
121 
122  //from MagFieldConfig
123  desc.add<int>("geometryVersion");
124  {
126  sub.add<std::string>("volumes");
127  sub.add<std::string>("sectors");
128  sub.add<int>("master");
129  sub.add<std::string>("path");
130  desc.addVPSet("gridFiles", sub);
131  }
132  desc.add<std::vector<int> >("scalingVolumes");
133  desc.add<std::vector<double> >("scalingFactors");
134  //default used to be compatible with older configurations
135  desc.add<std::vector<double> >("paramData", std::vector<double>());
136 
137  descriptions.addDefault(desc);
138 }
139 
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
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< int > keys
Scaling factors for the field in specific volumes.
ParameterDescriptionBase * add(U const &iLabel, T const &value)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
void setGridFiles(const TableFileMap &gridFiles)
edm::ESGetToken< cms::DDCompactView, IdealMagneticFieldRecord > cpvToken_
std::string version
Version of the data tables to be used.
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)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
std::vector< MagVolume6Faces * > endcapVolumes() const