ParameterUtility.cxx
Go to the documentation of this file.
1 //
2 // Created by Brian Rebel on 8/17/20.
3 //
4 
6 
7 namespace cmf{
8 
9  //-----------------------------------------------------------------------------
11  cmf::DetType_t const& det,
13  {
14  // nothing to be done with an empty parameter set
15  if(pset.is_empty()) return;
16 
18  bool fixed;
19  bool nuisance;
20  bool constraint;
21  float centralVal;
22  float variance;
23  float sigma;
24  double val;
25  float lowerBound;
26  float upperBound;
27  std::string parstr;
28  std::string detstr;
29 
30  auto const& parNames = pset.get_names();
31 
32  for(auto const& itr : parNames){
33 
34  param = pset.get<fhicl::ParameterSet>(itr);
35 
36  LOG_DEBUG("ParameterSetToLocation")
37  << param.to_indented_string();
38 
39  detstr = param.get<std::string>("Detector", "BOTH");
40  parstr = param.get<std::string>("Parameter" );
41  fixed = param.get<bool >("Fixed", true );
42  val = param.get<double >("Value", 0. );
43  nuisance = param.get<bool >("Nuisance", false );
44  sigma = param.get<float >("Sigma", 1.e6 );
45  centralVal = param.get<float >("CentralValue", 0. );
46  variance = param.get<float >("Variance", 1.e-5 );
47  constraint = param.get<bool >("Constraint", false );
48  lowerBound = param.get<float >("LoVal", 0. );
49  upperBound = param.get<float >("HiVal", 1.e6 );
50 
51  // remove any Wgt from the parameter name
52  if(parstr.find("Wgt") != std::string::npos) parstr.erase(parstr.find("Wgt"), 3);
53 
54  if(detstr == "BOTH" || cmf::StringToDetectorType(detstr) == det){
56  det,
57  val,
58  fixed,
59  sigma,
60  centralVal,
61  variance,
62  nuisance,
63  constraint,
64  lowerBound,
65  upperBound));
66 
67  LOG_DEBUG("ParameterSpaceLoc")
68  << "inserting parameter "
69  << parstr;
70 
71  } // end if using the correct detector
72 
73  } // end loop over parameter names
74 
75  }
76 
77  //-----------------------------------------------------------------------------
79  cmf::DetType_t const& det,
81  {
82  // nothing to be done with an empty parameter set
83  if(pset.is_empty()) return;
84 
86  bool fixed;
87  bool nuisance;
88  bool constraint;
89  float centralVal;
90  float variance;
91  float sigma;
92  double val;
93  float lowerBound;
94  float upperBound;
95  std::string parstr;
96  std::string detstr;
97 
98  auto const& parNames = pset.get_names();
99 
100  for(auto const& itr : parNames){
101 
102  param = pset.get<fhicl::ParameterSet>(itr);
103 
104  LOG_DEBUG("ParameterSetToLocation")
105  << param.to_indented_string();
106 
107  detstr = param.get<std::string>("Detector", "BOTH");
108  parstr = param.get<std::string>("Parameter" );
109  fixed = param.get<bool >("Fixed", true );
110  val = param.get<double >("Value", 0. );
111  nuisance = param.get<bool >("Nuisance", false );
112  sigma = param.get<float >("Sigma", 1.e6 );
113  centralVal = param.get<float >("CentralValue", 0. );
114  variance = param.get<float >("Variance", 1.e-5 );
115  constraint = param.get<bool >("Constraint", false );
116  lowerBound = param.get<float >("LoVal", 0. );
117  upperBound = param.get<float >("HiVal", 1.e6 );
118 
119  // remove any Wgt from the parameter name
120  if(parstr.find("Wgt") != std::string::npos) parstr.erase(parstr.find("Wgt"), 3);
121 
122  if(detstr == "BOTH" || cmf::StringToDetectorType(detstr) == det){
123  loc.emplace(parstr, cmf::Parameter(parstr,
124  det,
125  val,
126  fixed,
127  sigma,
128  centralVal,
129  variance,
130  nuisance,
131  constraint,
132  lowerBound,
133  upperBound));
134 
135  LOG_DEBUG("ParameterSpaceLoc")
136  << "inserting parameter "
137  << loc.find(parstr)->second.Name()
138  << " "
139  << loc.find(parstr)->second.Value()
140  << " / "
141  << val;
142 
143  } // end if using the correct detector
144 
145  } // end loop over parameter names
146 
147  }
148 
149  static ParameterUtility *gParUtil = nullptr;
150 
151  //-----------------------------------------------------------------------------
153  if(gParUtil == nullptr)
154  gParUtil = new ParameterUtility();
155 
156  return gParUtil;
157  }
158 
159  //-----------------------------------------------------------------------------
161  {
162  }
163 
164  //-----------------------------------------------------------------------------
166  {
167  // have default empty vectors for these which is what we expect if
168  // making the event lists
169  std::vector<std::string> psetNames({"OscillationParameters",
170  "SystematicParameters"});
171 
172  for(auto const& nameItr : psetNames){
173  if(nameItr.find("Systematic") != std::string::npos){
175  }
176  else if(nameItr.find("Oscillation") != std::string::npos){
179  }
180  LOG_DEBUG("ParameterUtility")
181  << nameItr
182  << " "
183  << fNDOscParameters.size()
184  << " "
185  << fFDOscParameters.size()
186  << " "
187  << fSysParameters.size();
188  } // end loop over oscillation or systematic parameter sets
189 
190  LOG_VERBATIM("cmf::CovarianceMatrixMaker")
191  << "\n-------------------------------------------------------"
192  << "\nPARAMETER SUMMARY"
193  << "\n-------------------------------------------------------"
194  << "\n\nRunning with systematic parameters set to \n";
195  for(auto const& itr : fSysParameters){
196  LOG_VERBATIM("ParameterUtility")
197  << " -- parameter: "
198  << std::setw(30)
199  << itr.first
200  << " val: "
201  << std::setw(15)
202  << itr.second.Value()
203  << " fixed: "
204  << std::setw(3)
205  << itr.second.IsFixed();
206  }
207 
208  LOG_VERBATIM("ParameterUtility")
209  << "\nRunning with oscillation parameters set to \n";
210  for(auto const& itr : fNDOscParameters){
211  LOG_VERBATIM("ParameterUtility")
212  << " -- parameter: "
213  << std::setw(30)
214  << itr.first
215  << " val ND: "
216  << std::setw(15)
217  << itr.second.Value()
218  << " val FD: "
219  << std::setw(15)
220  << fFDOscParameters.find(itr.first)->second.Value()
221  << " fixed: "
222  << std::setw(3)
223  << itr.second.IsFixed();
224  }
225 
226  }
227 
228  //-----------------------------------------------------------------------------
230  cmf::DetType_t const& det) const
231  {
232  if(fNDOscParameters.count(parName) < 1)
233  throw cet::exception("ParameterUtility")
234  << "oscillation parameter "
235  << parName
236  << " is not in the list";
237 
238  if(det == cmf::kNEARDET)
239  return fNDOscParameters.find(parName)->second;
240 
241  return fFDOscParameters.find(parName)->second;
242  }
243 
244  //-----------------------------------------------------------------------------
246  {
247  if(fSysParameters.count(parName) < 1)
248  throw cet::exception("ParameterUtility")
249  << "systematic parameter "
250  << parName
251  << " is not in the list";
252 
253  return fSysParameters.find(parName)->second;
254  }
255 
256  //-----------------------------------------------------------------------------
258  {
259  // the oscillation parameters are the same in the ND and FD
260  if(fNDOscParameters.count(parName) > 0)
261  return fNDOscParameters.find(parName)->second;
262 
263  // the systematic parameters could be different, so check the ND list
264  // first and then return from the FD list
265  if(fSysParameters.count(parName) > 0)
266  return fSysParameters.find(parName)->second;
267 
268  throw cet::exception("ParameterUtility")
269  << "ParameterUtility does not know about parameter "
270  << parName;
271 
272  // the following line is to keep the compiler happy
273  return fSysParameters.find(parName)->second;
274  }
275 
276  //-----------------------------------------------------------------------------
278  {
279  // the systematic parameters could be different, so check the ND list
280  // first and then return from the FD list
281  return fSysParameters.count(parName) > 0;
282  }
283 
284  //-----------------------------------------------------------------------------
286  {
288 
289  for(auto const& parItr : fSysParameters){
290  loc.InsertParameter(parItr.second);
291 
292  // the fSysParameters map just has the FD location, we
293  // want the systematic uncertainties to be in the ND location too
294  loc.InsertParameter(cmf::Parameter(parItr.second.Name(),
296  parItr.second.Value(),
297  parItr.second.IsFixed(),
298  parItr.second.Sigma(),
299  parItr.second.CentralValue(),
300  parItr.second.Variance(),
301  parItr.second.IsNuisance(),
302  parItr.second.IsConstrained(),
303  parItr.second.LowerBound(),
304  parItr.second.UpperBound()));
305  }
306 
307  return std::move(loc);
308  }
309 
310  //-----------------------------------------------------------------------------
311  std::vector<std::string> ParameterUtility::SysParNames() const
312  {
313  std::vector<std::string> parNames;
314  for(auto const& parItr : fSysParameters) parNames.emplace_back(parItr.first);
315 
316  return std::move(parNames);
317  }
318 
319  //-----------------------------------------------------------------------------
320  std::vector<uint8_t> ParameterUtility::SysParKeys() const
321  {
322  std::vector<uint8_t> parKeys;
323  for(auto const& parItr : fSysParameters) parKeys.emplace_back(parItr.second.Key());
324 
325  return std::move(parKeys);
326  }
327 
328 } // end namespace
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
cmf::Parameter const & ParameterInfo(std::string const &parName)
void Initialize(fhicl::ParameterSet const &pset)
bool is_empty() const
enum cmf::det_type DetType_t
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
cmf::ParameterSpaceLoc fSysParameters
values for the systematic parameters, same in both detectors
std::vector< std::string > SysParNames() const
static ParameterUtility * Instance()
cmf::ParameterSpaceLoc fNDOscParameters
values for the oscillation parameters in ND
cmf::Parameter const & OscParameterInfo(std::string const &parName, cmf::DetType_t const &det) const
cmf::ParameterSpaceLoc fFDOscParameters
values for the oscillation parameters in FD
bool UseSysPar(std::string const &parName)
T get(std::string const &key) const
Definition: ParameterSet.h:231
static cmf::DetType_t StringToDetectorType(std::string const &str)
Definition: StaticFuncs.h:271
void InsertParameter(cmf::Parameter const &par)
Definition: Parameter.cxx:216
static ParameterUtility * gParUtil
std::vector< std::string > get_names() const
double sigma(TH1F *hist, double percentile)
std::vector< uint8_t > SysParKeys() const
Module to combine a set of results into a single file currently only does one data product type at a ...
Definition: Event.cxx:24
void ParameterSetToLocation(fhicl::ParameterSet const &pset, cmf::DetType_t const &det, cmf::Location &loc)
std::string to_indented_string() const
cmf::Location ParametersAsLocation()
std::map< std::string, Parameter > ParameterSpaceLoc
Definition: Parameter.h:19
#define LOG_VERBATIM(category)
double variance(Eigen::VectorXd x)
cmf::Parameter const & SysParameterInfo(std::string const &parName) const
enum BeamMode string