test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AutoParametrizedMagneticFieldProducer.cc
Go to the documentation of this file.
1 
8 
12 
16 
21 
22 #include <string>
23 #include <iostream>
24 
25 using namespace std;
26 using namespace edm;
27 
28 namespace magneticfield{
30  {
31  public:
34 
35  std::auto_ptr<MagneticField> produce(const IdealMagneticFieldRecord&);
36 
37  int closerNominaCurrent(float current);
39  std::vector<int> nominalCurrents;
40  // std::vector<std::string> nominalLabels;
41  };
42 }
43 
44 using namespace magneticfield;
45 
46 AutoParametrizedMagneticFieldProducer::AutoParametrizedMagneticFieldProducer(const edm::ParameterSet& iConfig) : pset(iConfig) {
48  nominalCurrents={-1, 0,9558,14416,16819,18268,19262};
49  // nominalLabels ={"3.8T","0T","2T", "3T", "3.5T", "3.8T", "4T"};
50 }
51 
52 std::auto_ptr<MagneticField>
54 {
55  string version = pset.getParameter<string>("version");
56 
57  // Get value of the current from condition DB
58  float current = pset.getParameter<int>("valueOverride");
59  string message;
60  if (current < 0) {
61  ESHandle<RunInfo> rInfo;
62  iRecord.getRecord<RunInfoRcd>().get(rInfo);
63  current = rInfo->m_avg_current;
64  message = " (from RunInfo DB)";
65  } else {
66  message = " (from valueOverride card)";
67  }
68  float cnc= closerNominaCurrent(current);
69 
70  edm::LogInfo("MagneticField|AutoParametrizedMagneticField") << "Current: " << current << message << "; using map for: " << cnc;
71 
72  vector<double> parameters;
73 
74  if (cnc==0) {
75  version = "Uniform";
76  parameters.push_back(0);
77  }
78 
79  else if (version=="Parabolic"){
80  parameters.push_back(3.8114); //c1
81  parameters.push_back(-3.94991e-06); //b0
82  parameters.push_back(7.53701e-06); //b1
83  parameters.push_back(2.43878e-11); //a
84  if (cnc!=18268){ // Linear scaling for B!= 3.8T; note that just c1, b0 and b1 have to be scaled to get linear scaling
85  double scale=double(cnc)/double(18268);
86  parameters[0]*=scale;
87  parameters[1]*=scale;
88  parameters[2]*=scale;
89  }
90  } else {
91  //Other parametrizations are not relevant here and not supported
92  throw cms::Exception("InvalidParameter") << "version " << version << " is not supported";
93  }
94 
95  return ParametrizedMagneticFieldFactory::get(version, parameters);
96 }
97 
99  int i=0;
100  for(;i<(int)nominalCurrents.size()-1;i++) {
101  if(2*current < nominalCurrents[i]+nominalCurrents[i+1] )
102  return nominalCurrents[i];
103  }
104  return nominalCurrents[i];
105 }
106 
107 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
static std::auto_ptr< MagneticField > get(std::string version, const edm::ParameterSet &parameters)
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
std::auto_ptr< MagneticField > produce(const IdealMagneticFieldRecord &)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60