Parameter.cxx
Go to the documentation of this file.
1 //
2 // Created by Brian Rebel on 8/17/20.
3 //
4 
8 
9 namespace cmf{
10 
11  //------------------------------------------------------------
12  std::ostream& operator<<(std::ostream& o, cmf::OscPar const& op) {
14  << " "
15  << op.Value();
16 
17  return o;
18  }
19 
20  //----------------------------------------------------------------------------
22  : fDetector (cmf::kFARDET )
23  , fVal (cmf::kGarbageDouble)
24  , fCentralVal (cmf::kGarbageFloat )
25  , fSigmaSize (1.e-5 )
26  , fVariance (1.e-5 )
27  , fIsFixed (false )
28  , fIsNuisance (false )
29  , fIsConstrained(false )
30  , fLowerBound (cmf::kGarbageFloat )
31  , fUpperBound (cmf::kGarbageFloat )
32  , fParType (cmf::kUnknownPar )
33  {
34  }
35 
36  //----------------------------------------------------------------------------
38  cmf::DetType_t const& det,
39  double const& val,
40  bool const& fixed,
41  float const& sigmaSize,
42  float const& cv,
43  float const& variance,
44  bool const& nuisance,
45  bool const& constrained,
46  float const& lowerBound,
47  float const& upperBound)
48  : fDetector (det )
49  , fVal (val )
50  , fCentralVal (cv )
51  , fSigmaSize (sigmaSize )
52  , fVariance (variance )
53  , fIsFixed (fixed )
54  , fIsNuisance (nuisance )
55  , fIsConstrained(constrained )
56  , fLowerBound (lowerBound )
57  , fUpperBound (upperBound )
59  {
60  if(fVariance < 1.e-5) fVariance = 1.e-5;
61 
65  }
66  else{
67  fKey = cmf::VarNameToKey(name);
74  else if (fKey >= kFirstEShiftVar && fKey <= cmf::kLastEShiftVar)
76  else
78  }
79 
80 
81  // sanity check warning - if the parameter is fixed and labeled as nuisance,
82  // tell the user that the fixed part wins
83  if(fIsFixed && fIsNuisance){
84  LOG_WARNING("Parameter")
85  << name
86  << " is set to be fixed but is also set to be a nuisance parameter, "
87  << "assume that leaving it fixed is correct and set IsNuisance to "
88  << " false";
89 
90  fIsNuisance = false;
91  }
92 
93  }
94 
95  //----------------------------------------------------------------------------
97  return fKey < other.Key();
98  }
99 
100  //----------------------------------------------------------------------------
102  return fKey == other.Key();
103  }
104 
105  //------------------------------------------------------------
106  std::ostream& operator<<(std::ostream& o, cmf::Parameter const& par) {
107 
108  o << "-- parameter: "
109  << std::setw(30) << par.Name() << std::setw(10)
110  << " val: " << par.Value()
111  << " fixed: " << par.IsFixed()
112  << " oscillation " << par.IsOscPar()
113  << " nuisance " << par.IsNuisance()
114  << " constrained " << par.IsConstrained()
115  << " lower: " << par.LowerBound()
116  << " upper: " << par.UpperBound()
117  << std::endl;
118 
119  return o;
120  }
121 
122  //------------------------------------------------------------
123  std::ostream& operator<<(std::ostream& o, cmf::Location const& loc) {
124  o << std::endl;
125  for(auto const& itr : loc.NDLocation()){
126  o << " -- parameter: "
127  << std::setw(30)
128  << itr.first
129  << std::setw(15)
130  << " val ND: "
131  << itr.second.Value()
132  << " fixed: "
133  << std::setw(5)
134  << itr.second.IsFixed();
135  if(loc.FDLocation().count(itr.first) > 0)
136  o << " val FD: "
137  << std::setw(15)
138  << " "
139  << loc.FDLocation().find(itr.first)->second.Value()
140  << " fixed: "
141  << std::setw(5)
142  << itr.second.IsFixed();
143 
144  o << std::endl;
145  }
146  for(auto const& itr : loc.FDLocation()){
147  if(loc.NDLocation().count(itr.first) < 1)
148  o << " -- parameter: "
149  << std::setw(30)
150  << itr.first
151  << std::setw(15)
152  << " val FD: "
153  << itr.second.Value()
154  << " fixed: "
155  << std::setw(5)
156  << itr.second.IsFixed()
157  << std::endl;
158  }
159 
160  return o;
161  }
162 
163  //----------------------------------------------------------------------------
165  {
166  for(auto const& itr : oscPars){
167  fNDLoc.emplace(cmf::cOscParams_Strings[itr.first],
170  itr.second,
171  true,
172  0,
173  itr.second,
174  0,
175  false,
176  false,
177  0.,
178  1.));
179  fFDLoc.emplace(cmf::cOscParams_Strings[itr.first],
181  cmf::kFARDET,
182  itr.second,
183  true,
184  0,
185  itr.second,
186  0,
187  false,
188  false,
189  0.,
190  1.));
191  }
192 
193  // add in the baselines
194  fNDLoc.emplace(cmf::cOscParams_Strings[cmf::kL],
197  1,
198  true,
199  0,
200  1,
201  0,
202  false,
203  false,
204  0.,
205  1.));
206 
207  fFDLoc.emplace(cmf::cOscParams_Strings[cmf::kL],
209  cmf::kFARDET,
210  810,
211  true,
212  0,
213  810,
214  0,
215  false,
216  false,
217  0.,
218  1.));
219 
220  }
221 
222  //----------------------------------------------------------------------------
224  {
225  if(par.Detector() == cmf::kNEARDET){
226  if(fNDLoc.count(par.Name()) < 1) fNDLoc.emplace(par.Name(), par);
227  else fNDLoc.find(par.Name())->second.SetValue(par.Value());
228  }
229  if(par.Detector() == cmf::kFARDET){
230  if(fFDLoc.count(par.Name()) < 1) fFDLoc.emplace(par.Name(), par);
231  else fFDLoc.find(par.Name())->second.SetValue(par.Value());
232  }
233  }
234 
235  //----------------------------------------------------------------------------
237  double const& value,
238  cmf::DetType_t const& det)
239  {
240  if(det == cmf::kNEARDET){
241  if(fNDLoc.count(parName) > 0) fNDLoc.find(parName)->second.SetValue(value);
242  else
243  LOG_WARNING("Location")
244  << parName
245  << " is not a recognized parameter for the NearDet";
246  }
247  else if(det == cmf::kFARDET ){
248  if(fFDLoc.count(parName) > 0) fFDLoc.find(parName)->second.SetValue(value);
249  else
250  LOG_WARNING("Location")
251  << parName
252  << " is not a recognized parameter for the FarDet";
253  }
254  }
255 
256  //----------------------------------------------------------------------------
258  {
260 
261  for(auto const& itr : fFDLoc){
262  oscMap.emplace((cmf::OscParm_t)itr.second.Key(),
263  itr.second.Value());
264  }
265 
266  return std::move(oscMap);
267  }
268 
269 }// namespace
const XML_Char * name
Definition: expat.h:151
float const & LowerBound() const
Definition: Parameter.h:115
enum cmf::osc_params OscParm_t
bool const & IsConstrained() const
Definition: Parameter.h:113
float fSigmaSize
size of 1 sigma
Definition: Parameter.h:130
static const double kGarbageDouble
Definition: Constants.h:18
float fCentralVal
central value for the parameter
Definition: Parameter.h:129
Int_t par
Definition: SimpleIterate.C:24
bool const & IsFixed() const
Definition: Parameter.h:111
bool fIsConstrained
is this parameter constrained in allowed values?
Definition: Parameter.h:134
enum cmf::det_type DetType_t
cmf::OscillationParameterMap AsOscillationParameterMap()
Definition: Parameter.cxx:257
float fUpperBound
upper bound for the constrained parameter
Definition: Parameter.h:136
bool IsOscPar() const
Definition: Parameter.h:112
std::ostream & operator<<(std::ostream &o, cmf::Event const &event)
Definition: Event.cxx:27
const std::string cOscParams_Strings[kNumOscParams]
Definition: Constants.h:272
static uint8_t VarNameToKey(std::string const &name)
Definition: StaticFuncs.h:381
std::map< cmf::OscParm_t, float > OscillationParameterMap
Definition: Constants.h:730
const XML_Char int const XML_Char * value
Definition: expat.h:331
cmf::ParameterSpaceLoc const & NDLocation() const
Definition: Parameter.h:160
float fLowerBound
lower bound for the constrained parameter
Definition: Parameter.h:135
static const float kGarbageFloat
Definition: Constants.h:19
const std::string cv[Ncv]
bool const & IsNuisance() const
Definition: Parameter.h:114
friend std::ostream & operator<<(std::ostream &o, cmf::Parameter const &par)
Definition: Parameter.cxx:106
cmf::ParameterSpaceLoc const & FDLocation() const
Definition: Parameter.h:161
uint8_t fDetector
which detector is this parameter for?
Definition: Parameter.h:127
cmf::DetType_t const Detector() const
Definition: Parameter.h:107
void InsertParameter(cmf::Parameter const &par)
Definition: Parameter.cxx:223
float const & Value() const
Definition: Parameter.h:43
uint8_t const & Key() const
Definition: Parameter.h:106
bool fIsNuisance
is this parameter treated as a nuisance parameter?
Definition: Parameter.h:133
bool operator<(cmf::Parameter const &other) const
Definition: Parameter.cxx:96
double fVal
current value for the parameter in the fit
Definition: Parameter.h:128
#define LOG_WARNING(category)
static bool IsOscillationParameter(std::string const &str)
float fVariance
amount parameter can vary when making random universes
Definition: Parameter.h:131
Module to combine a set of results into a single file currently only does one data product type at a ...
Definition: Event.cxx:24
cmf::OscParm_t const & Param() const
Definition: Parameter.h:42
bool fIsFixed
is this parameter fixed during fits?
Definition: Parameter.h:132
float const & UpperBound() const
Definition: Parameter.h:116
bool operator==(cmf::Parameter const &other) const
Definition: Parameter.cxx:101
uint8_t fKey
key for this parameter
Definition: Parameter.h:126
double const & Value() const
Definition: Parameter.h:105
std::string const Name() const
Definition: Parameter.h:103
Float_t e
Definition: plot.C:35
double variance(Eigen::VectorXd x)
static cmf::OscParm_t StringToOscParmType(std::string const &str)
void SetParameterValue(std::string const &parName, double const &value, cmf::DetType_t const &det)
Definition: Parameter.cxx:236
uint8_t fParType
type of paramter this is
Definition: Parameter.h:137
enum BeamMode string