CMS 3D CMS Logo

AutoParametrizedMagneticFieldProducer.cc
Go to the documentation of this file.
1 
10 
14 
17 
18 #include <string>
19 
20 using namespace std;
21 using namespace edm;
22 
23 namespace magneticfield {
25  public:
28 
29  std::unique_ptr<MagneticField> produce(const IdealMagneticFieldRecord&);
30 
31  int closerNominaCurrent(float current) const;
33  const int currentOverride_;
34  const std::array<int, 7> nominalCurrents_;
35  // std::vector<std::string> nominalLabels_;
37  };
38 } // namespace magneticfield
39 
40 using namespace magneticfield;
41 
42 AutoParametrizedMagneticFieldProducer::AutoParametrizedMagneticFieldProducer(const edm::ParameterSet& iConfig)
43  : version_{iConfig.getParameter<string>("version")},
44  currentOverride_{iConfig.getParameter<int>("valueOverride")},
45  nominalCurrents_{{-1, 0, 9558, 14416, 16819, 18268, 19262}}
46 // nominalLabels_{["3.8T","0T","2T", "3T", "3.5T", "3.8T", "4T"}}
47 {
48  auto cc = setWhatProduced(this, iConfig.getUntrackedParameter<std::string>("label", ""));
49  if (currentOverride_ < 0) {
50  runInfoToken_ = cc.consumes();
51  }
52 }
53 
54 std::unique_ptr<MagneticField> AutoParametrizedMagneticFieldProducer::produce(const IdealMagneticFieldRecord& iRecord) {
55  // Get value of the current from condition DB
56  float current = currentOverride_;
57  string message;
58  if (current < 0) {
59  current = iRecord.get(runInfoToken_).m_avg_current;
60  message = " (from RunInfo DB)";
61  } else {
62  message = " (from valueOverride card)";
63  }
64  float cnc = closerNominaCurrent(current);
65 
66  edm::LogInfo("MagneticField") << "Current: " << current << message << "; using map for: " << cnc;
67 
68  vector<double> parameters;
69 
70  auto version = version_;
71  if (cnc == 0) {
72  version = "Uniform";
73  parameters.push_back(0);
74  } else if (version == "Parabolic") {
75  parameters.push_back(3.8114); //c1
76  parameters.push_back(-3.94991e-06); //b0
77  parameters.push_back(7.53701e-06); //b1
78  parameters.push_back(2.43878e-11); //a
79  if (cnc !=
80  18268) { // Linear scaling for B!= 3.8T; note that just c1, b0 and b1 have to be scaled to get linear scaling
81  double scale = double(cnc) / double(18268);
82  parameters[0] *= scale;
83  parameters[1] *= scale;
84  parameters[2] *= scale;
85  }
86  } else {
87  //Other parametrizations are not relevant here and not supported
88  throw cms::Exception("InvalidParameter") << "version " << version << " is not supported";
89  }
90 
92 }
93 
95  int i = 0;
96  for (; i < (int)nominalCurrents_.size() - 1; i++) {
97  if (2 * current < nominalCurrents_[i] + nominalCurrents_[i + 1])
98  return nominalCurrents_[i];
99  }
100  return nominalCurrents_[i];
101 }
102 
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::unique_ptr< MagneticField > produce(const IdealMagneticFieldRecord &)
static std::unique_ptr< MagneticField > get(std::string version, const edm::ParameterSet &parameters)
Log< level::Info, false > LogInfo
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
HLT enums.
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const