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 
magneticfield::AutoParametrizedMagneticFieldProducer::runInfoToken_
edm::ESGetToken< RunInfo, RunInfoRcd > runInfoToken_
Definition: AutoParametrizedMagneticFieldProducer.cc:36
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:29
mps_fire.i
i
Definition: mps_fire.py:428
magneticfield::AutoParametrizedMagneticFieldProducer::produce
std::unique_ptr< MagneticField > produce(const IdealMagneticFieldRecord &)
Definition: AutoParametrizedMagneticFieldProducer.cc:54
MessageLogger.h
RunSummaryRcd.h
ParametrizedMagneticFieldFactory::get
static std::unique_ptr< MagneticField > get(std::string version, const edm::ParameterSet &parameters)
HLT_FULL_cff.scale
scale
Definition: HLT_FULL_cff.py:6637
edm
HLT enums.
Definition: AlignableModifier.h:19
magneticfield
Definition: MagFieldConfig.h:22
ESProducer.h
magneticfield::AutoParametrizedMagneticFieldProducer::version_
const std::string version_
Definition: AutoParametrizedMagneticFieldProducer.cc:32
magneticfield::AutoParametrizedMagneticFieldProducer::closerNominaCurrent
int closerNominaCurrent(float current) const
Definition: AutoParametrizedMagneticFieldProducer.cc:94
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
magneticfield::AutoParametrizedMagneticFieldProducer::~AutoParametrizedMagneticFieldProducer
~AutoParametrizedMagneticFieldProducer() override
Definition: AutoParametrizedMagneticFieldProducer.cc:27
cc
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
magneticfield::AutoParametrizedMagneticFieldProducer::currentOverride_
const int currentOverride_
Definition: AutoParametrizedMagneticFieldProducer.cc:33
IdealMagneticFieldRecord.h
edm::eventsetup::DependentRecordImplementation::get
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
Definition: DependentRecordImplementation.h:103
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
createfilelist.int
int
Definition: createfilelist.py:10
magneticfield::AutoParametrizedMagneticFieldProducer::nominalCurrents_
const std::array< int, 7 > nominalCurrents_
Definition: AutoParametrizedMagneticFieldProducer.cc:34
MagneticField.h
edm::ESGetToken< RunInfo, RunInfoRcd >
magneticfield::AutoParametrizedMagneticFieldProducer
Definition: AutoParametrizedMagneticFieldProducer.cc:24
RunInfo.h
ModuleFactory.h
std
Definition: JetResolutionObject.h:76
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
Exception
Definition: hltDiff.cc:246
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESProducer
Definition: ESProducer.h:104
ParameterSet.h
BeamSplash_cfg.version
version
Definition: BeamSplash_cfg.py:45
ParametrizedMagneticFieldFactory.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37