Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
cmf::RandomUniverseUtility Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/CovarianceMatrixFit/utilities/RandomUniverseUtility.h"

Public Member Functions

void CreateLocationWithVariedSystematics (cmf::Location const &nominalLoc, cmf::Location &vecLoc, size_t universeNum)
 
void CreateLocationsWithVariedSystematics (cmf::Location const &nominalLoc, std::vector< cmf::Location > &vecLocs)
 
void CreateLocationWithVariedOscParameters (cmf::Location const &nominalPoint, cmf::Location &vecPoint, size_t universeNum)
 
void CreateLocationsWithVariedOscParameters (cmf::Location const &nominalLoc, std::vector< cmf::Location > &vecLoc)
 
void Initialize (fhicl::ParameterSet const &pset)
 
void FillPoissonSpectrum (std::vector< float > &spectrum, std::vector< float > &poissonSpectrum)
 
void MakeUniverseHistograms (cmf::FakeUniverse &fakeU, unsigned int uNumber)
 

Static Public Member Functions

static RandomUniverseUtilityInstance ()
 

Private Member Functions

 RandomUniverseUtility ()
 
 ~RandomUniverseUtility ()
 
void PoissonSpectrumBinByBin (std::vector< float > &spectrum, std::vector< float > &poissonSpectrum)
 
bool UniformDrawParameters (std::string const &name)
 

Private Attributes

TRandom3 fRand
 RNG for picking the variation in parameters. More...
 
TH2D * fSystDrawHist
 keep track of the systematic parameter values More...
 
TH2D * fOscParamDrawHist
 keep track of the oscillation parameter values More...
 
bool fPoissonFluctuate
 do we want to poisson fluctuate the FD prediction? More...
 
bool fPoissonByHist
 use histogram method for picking poisson numbers More...
 
bool fPoissonByBin
 use bin by bin method for picking poisson numbers More...
 
unsigned int fNumUniverses
 number of fake universes to create More...
 

Detailed Description

Definition at line 19 of file RandomUniverseUtility.h.

Constructor & Destructor Documentation

cmf::RandomUniverseUtility::RandomUniverseUtility ( )
private

Definition at line 30 of file RandomUniverseUtility.cxx.

Referenced by Instance().

31  {
32  }
cmf::RandomUniverseUtility::~RandomUniverseUtility ( )
private

Definition at line 35 of file RandomUniverseUtility.cxx.

36  {
37  }

Member Function Documentation

void cmf::RandomUniverseUtility::CreateLocationsWithVariedOscParameters ( cmf::Location const &  nominalLoc,
std::vector< cmf::Location > &  vecLoc 
)

Definition at line 247 of file RandomUniverseUtility.cxx.

References CreateLocationWithVariedOscParameters(), fNumUniverses, LOG_DEBUG, and submit_hadd::u.

Referenced by cmf::RandomUniverses::beginJob().

249  {
250  // check that the vector is the correct size
251  vecLocs.resize(fNumUniverses, nominalLoc);
252 
253  for(unsigned int u = 0; u < fNumUniverses; ++u){
254 
255  this->CreateLocationWithVariedOscParameters(nominalLoc, vecLocs[u], u);
256 
257  LOG_DEBUG("RandomUniverseUtility")
258  << " new point "
259  << u;
260  } // end loop over the number of universes
261 
262  // fOscParamDrawHist->LabelsDeflate("Y");
263  // fOscParamDrawHist->LabelsOption("h", "Y");
264 
265  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
void CreateLocationWithVariedOscParameters(cmf::Location const &nominalPoint, cmf::Location &vecPoint, size_t universeNum)
unsigned int fNumUniverses
number of fake universes to create
void cmf::RandomUniverseUtility::CreateLocationsWithVariedSystematics ( cmf::Location const &  nominalLoc,
std::vector< cmf::Location > &  vecLocs 
)

Definition at line 80 of file RandomUniverseUtility.cxx.

References CreateLocationWithVariedSystematics(), fNumUniverses, and submit_hadd::u.

Referenced by cmf::RandomUniverses::beginJob().

82  {
83  // check that the vector is the correct size
84  vecLoc.resize(fNumUniverses, nominalLoc);
85 
86  for(unsigned int u = 0; u < fNumUniverses; ++u){
87 
88  this->CreateLocationWithVariedSystematics(nominalLoc, vecLoc[u], u);
89  } // end loop over the number of universes
90 
91  // fSystDrawHist->LabelsDeflate("Y");
92  // fSystDrawHist->LabelsOption("h", "Y");
93 
94  }
void CreateLocationWithVariedSystematics(cmf::Location const &nominalLoc, cmf::Location &vecLoc, size_t universeNum)
unsigned int fNumUniverses
number of fake universes to create
void cmf::RandomUniverseUtility::CreateLocationWithVariedOscParameters ( cmf::Location const &  nominalPoint,
cmf::Location vecPoint,
size_t  universeNum 
)

Definition at line 150 of file RandomUniverseUtility.cxx.

References cmf::Location::FDLocation(), fOscParamDrawHist, fRand, cmf::kFARDET, cmf::kL, cmf::kNEARDET, LOG_DEBUG, cmf::Location::SetParameterValue(), string, art::to_string(), and febshutoff_auto::val.

Referenced by CreateLocationsWithVariedOscParameters().

153  {
154  // loop over all the parameters and vary the ones we want
155  double val;
157 
158  // set the location to the nominal location
159  vecLoc = nominalLoc;
160 
161  // prepare some output for the random values in this universe
162  std::string oscStr("Oscillation Parameters " + std::to_string(universeNum) + ": ");
163 
164  // get the names of the oscillation parameters. The parameters are the same
165  // in both the ND and FD
166  std::map<std::string, double> oscParVals;
167  for(auto const& itr : nominalLoc.FDLocation()){
168 
169  name = itr.first;
170  val = itr.second.Value();
171 
172  LOG_DEBUG("RandomUniverseUtility")
173  << name
174  << " is osc par: "
175  << itr.second.IsOscPar()
176  << " is fixed: "
177  << itr.second.IsFixed();
178 
179  // The distance the neutrino travels should never be adjusted, so
180  // don't bother putting it into oscParVals
181  if(itr.second.IsOscPar() && (cmf::OscParm_t)itr.second.Key() != cmf::kL){
182  if(!itr.second.IsFixed()){
183  // we have a parameter that is not fixed, so let's figure out how to
184  // vary it
185  // first check if it is in the list of nuisance parameters, if not
186  // look to see if it is constrained.
187  if(itr.second.IsNuisance()){
188  // treat the parameter as Gaussian distributed
189  val = fRand.Gaus(itr.second.CentralValue(),
190  itr.second.Variance());
191 
192  LOG_DEBUG("RandomUniverseUtility")
193  << "nuisance parameter "
194  << name
195  << " val "
196  << val
197  << " "
198  << itr.second.CentralValue()
199  << " "
200  << itr.second.Variance()
201  << " "
202  << itr.second.CentralValue() - itr.second.Variance();
203  }
204  else if(itr.second.IsConstrained()){
205  val = fRand.Rndm() * (itr.second.UpperBound() - itr.second.LowerBound()) +
206  itr.second.LowerBound();
207 
208  LOG_DEBUG("RandomUniverseUtility")
209  << "non-nuisance parameter "
210  << name
211  << " val "
212  << val
213  << " "
214  << itr.second.LowerBound()
215  << " "
216  << itr.second.UpperBound()
217  << " "
218  << itr.second.UpperBound() - itr.second.LowerBound();
219  }
220 
221  oscStr += name + ": " + std::to_string(val) + "\t";
222  }
223  oscParVals.emplace(name, val);
224  } // end if we have an oscillation parameter
225  } // end loop over parameters
226 
227  //loop over oscParVals and set the oscillation parameter values that have
228  // changed
229  for(auto const& itr : oscParVals){
230 
231  // only add the parameter to the draw histogram if it isn't fixed
232  if(!vecLoc.FDLocation().find(itr.first)->second.IsFixed()){
233  fOscParamDrawHist->Fill(universeNum, itr.first.c_str(), itr.second);
234  }
235 
236  // do this for both fixed and not fixed parameters to ensure we have
237  // all oscillation parameters set
238  vecLoc.SetParameterValue(itr.first, itr.second, cmf::kNEARDET);
239  vecLoc.SetParameterValue(itr.first, itr.second, cmf::kFARDET );
240  } // end loop over oscillation parameters to change
241 
242  LOG_DEBUG("RandomUniverseUtility")
243  << vecLoc;
244  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
const XML_Char * name
Definition: expat.h:151
enum cmf::osc_params OscParm_t
TH2D * fOscParamDrawHist
keep track of the oscillation parameter values
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
TRandom3 fRand
RNG for picking the variation in parameters.
enum BeamMode string
void cmf::RandomUniverseUtility::CreateLocationWithVariedSystematics ( cmf::Location const &  nominalLoc,
cmf::Location vecLoc,
size_t  universeNum 
)

Definition at line 100 of file RandomUniverseUtility.cxx.

References cmf::Location::FDLocation(), fRand, fSystDrawHist, cmf::kFARDET, cmf::kNEARDET, LOG_VERBATIM, cmf::Location::NDLocation(), cmf::Location::SetParameterValue(), string, art::to_string(), and UniformDrawParameters().

Referenced by cmf::RandomUniverses::beginJob(), and CreateLocationsWithVariedSystematics().

103  {
104  // we will pick a random value from a unit gaussian, ie gaussian with
105  // sigma = 1. That will be the fractional change on the sigma we want
106  // to apply to the new input point
107  double sigFrac = 0.;
108 
109  // get the names of the systematic parameters in the ND and FD
110  std::map<std::string, double> systParVals;
111  for(auto const& itr : nominalLoc.NDLocation()){
112  if(itr.second.IsOscPar() ||
113  itr.second.IsFixed() ) continue;
114 
115  // each systematic parameter should have a different random number
116  // change in sigma so that we don't artificially make them change
117  // in a correlated way if doing more than one parameter in a job
118  sigFrac = (this->UniformDrawParameters(itr.first)) ? fRand.Rndm() : fRand.Gaus();
119 
120  systParVals.emplace(itr.first, sigFrac);
121  }
122  for(auto const& itr : nominalLoc.FDLocation()){
123  if(itr.second.IsOscPar() ||
124  itr.second.IsFixed() ||
125  systParVals.count(itr.first) > 0 ) continue;
126 
127  sigFrac = (this->UniformDrawParameters(itr.first)) ? fRand.Rndm() : fRand.Gaus();
128 
129  systParVals.emplace(itr.first, sigFrac);
130  }
131 
132  // prepare some output for the random values in this universe
133  std::string systStr("Systematic Parameters " + std::to_string(universeNum));
134 
135  for(auto const& itr : systParVals){
136 
137  systStr += "\n\t" + itr.first + ": " + std::to_string(itr.second);
138 
139  fSystDrawHist->Fill(universeNum, itr.first.c_str(), itr.second);
140 
141  vecLoc.SetParameterValue(itr.first, itr.second, cmf::kNEARDET);
142  vecLoc.SetParameterValue(itr.first, itr.second, cmf::kFARDET );
143  } // end loop over systematic parameters to change
144 
145  LOG_VERBATIM("RandomUniverseUtility")
146  << systStr;
147  }
TH2D * fSystDrawHist
keep track of the systematic parameter values
bool UniformDrawParameters(std::string const &name)
#define LOG_VERBATIM(category)
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
TRandom3 fRand
RNG for picking the variation in parameters.
void SetParameterValue(std::string const &parName, double const &value, cmf::DetType_t const &det)
Definition: Parameter.cxx:220
enum BeamMode string
void cmf::RandomUniverseUtility::FillPoissonSpectrum ( std::vector< float > &  spectrum,
std::vector< float > &  poissonSpectrum 
)

Definition at line 270 of file RandomUniverseUtility.cxx.

References fPoissonByBin, fPoissonFluctuate, and PoissonSpectrumBinByBin().

Referenced by cmf::RandomUniverses::writeResults().

272  {
273  // just copy the spectrum into the poissonSpectrum if we aren't configured for this
274  if(!fPoissonFluctuate){
275  poissonSpectrum = spectrum;
276  return;
277  }
278 
279  // first reset the poisson spectrum to be all 0's
280  poissonSpectrum.resize(spectrum.size(), 0.);
281 
282  if(fPoissonByBin) this->PoissonSpectrumBinByBin(spectrum, poissonSpectrum);
283 
284  // for(size_t b = 0; b < poissonSpectrum.size(); ++b){
285  // LOG_VERBATIM("RandomUniverseUtility")
286  // << "FillPoisonSpectrum bin "
287  // << b
288  // << " detector "
289  // << cmf::cDetType_Strings[cmf::CovarianceBinUtility::Instance()->BinToDetector(b)]
290  // << " without fluctuations "
291  // << spectrum[b]
292  // << " poisson expectation "
293  // << poissonSpectrum[b];
294  // }
295 
296  }
bool fPoissonByBin
use bin by bin method for picking poisson numbers
void PoissonSpectrumBinByBin(std::vector< float > &spectrum, std::vector< float > &poissonSpectrum)
bool fPoissonFluctuate
do we want to poisson fluctuate the FD prediction?
void cmf::RandomUniverseUtility::Initialize ( fhicl::ParameterSet const &  pset)

Definition at line 40 of file RandomUniverseUtility.cxx.

References fNumUniverses, fOscParamDrawHist, fPoissonByBin, fPoissonByHist, fPoissonFluctuate, fRand, fSystDrawHist, and fhicl::ParameterSet::get().

Referenced by cmf::RandomUniverses::reconfigure().

41  {
42  // set the seed for the random number to be what is configured, plus the
43  // start universe value in case lots are jobs are submitted with the same seed
44  // by accident
45  fRand.SetSeed(pset.get<unsigned long int>("RandomSeed", 0) +
46  pset.get<unsigned int >("StartUniverse", 0));
47 
48  fNumUniverses = pset.get<unsigned int>("NumUniverses", 1);
49  fPoissonFluctuate = pset.get<bool >("PoissonFluctuate", false);
50  fPoissonByHist = pset.get<bool >("PoissonDrawWithHistogram", false);
51  fPoissonByBin = pset.get<bool >("PoissonDrawWithBin", true );
52 
53  // fill histogram with systematic names and which values were used
55 
56  fSystDrawHist = tfs->make<TH2D>("SystematicParameterDraws",
57  ";Universe;Uncertainty Draw;",
59  0,
61  2,
62  0,
63  2);
64  fSystDrawHist->SetCanExtend(TH1::kAllAxes);
65  fSystDrawHist->SetStats(false);
66 
67  fOscParamDrawHist = tfs->make<TH2D>("OscillationParameterDraws",
68  ";Unvierse;Parameter Draw",
70  0,
72  2,
73  0,
74  2);
75  fOscParamDrawHist->SetCanExtend(TH1::kAllAxes);
76  fOscParamDrawHist->SetStats(0);
77  }
TH2D * fSystDrawHist
keep track of the systematic parameter values
unsigned int fNumUniverses
number of fake universes to create
bool fPoissonByBin
use bin by bin method for picking poisson numbers
TH2D * fOscParamDrawHist
keep track of the oscillation parameter values
bool fPoissonByHist
use histogram method for picking poisson numbers
TRandom3 fRand
RNG for picking the variation in parameters.
bool fPoissonFluctuate
do we want to poisson fluctuate the FD prediction?
RandomUniverseUtility * cmf::RandomUniverseUtility::Instance ( )
static

Definition at line 22 of file RandomUniverseUtility.cxx.

References cmf::gRUU, and RandomUniverseUtility().

Referenced by cmf::RandomUniverses::beginJob(), cmf::RandomUniverses::reconfigure(), and cmf::RandomUniverses::writeResults().

23  {
24  if(gRUU == nullptr) gRUU = new RandomUniverseUtility();
25 
26  return gRUU;
27  }
static RandomUniverseUtility * gRUU
void cmf::RandomUniverseUtility::MakeUniverseHistograms ( cmf::FakeUniverse fakeU,
unsigned int  uNumber 
)

Definition at line 322 of file RandomUniverseUtility.cxx.

References cmf::FakeUniverse::AsimovSpectrum(), b, dir, art::TFileDirectory::make(), art::TFileDirectory::mkdir(), cmf::FakeUniverse::PoissonSpectrum(), string, plotROC::title, and art::to_string().

Referenced by cmf::RandomUniverses::writeResults().

324  {
326 
327  auto unumStr = std::to_string(uNumber);
328  // first off, let's make a new directory for this universe
329  art::TFileDirectory dir = tfs->mkdir("Universe_" + unumStr);
330 
331  std::string title = "Universe " + unumStr;
332  std::string name = "PoissonUniverse_" + unumStr;
333 
334  title += ";Bin;Events";
335  TH1D *poissonHist = dir.make<TH1D>(name.data(),
336  title.data(),
337  fakeU.PoissonSpectrum().size() - 1,
338  0.,
339  fakeU.PoissonSpectrum().size() - 1);
340  poissonHist->Sumw2();
341 
342  // comment out the next lines as FakeUniverse no longer carries the raw count
343  // information. Leave these here in case we want to pass in the vector from
344  // elsewhere
345 // name = "RawCount_" + unumStr;
346 // TH1D *countHist = dir.make<TH1D>(name.data(),
347 // title.data(),
348 // fakeU.EventCounts().size() - 1,
349 // 0.,
350 // fakeU.EventCounts().size() - 1);
351 
352  name = "AsimovUniverse_" + unumStr;
353  TH1D *asimovHist = dir.make<TH1D>(name.data(),
354  title.data(),
355  fakeU.AsimovSpectrum().size() - 1,
356  0.,
357  fakeU.AsimovSpectrum().size() - 1);
358  asimovHist->Sumw2();
359 
360  name = "RatioToAsimovUniverse_" + unumStr;
361  TH1D *ratioHist = dir.make<TH1D>(name.data(),
362  title.data(),
363  fakeU.AsimovSpectrum().size() - 1,
364  0.,
365  fakeU.AsimovSpectrum().size() - 1);
366  ratioHist->Sumw2();
367 
368  for(size_t b = 0; b < fakeU.PoissonSpectrum().size(); ++b){
369  poissonHist->SetBinContent(b + 1, fakeU.PoissonSpectrum()[b]);
370  asimovHist ->SetBinContent(b + 1, fakeU.AsimovSpectrum()[b] );
371  //countHist ->SetBinContent(b + 1, fakeU.EventCounts()[b] );
372  }
373 
374  ratioHist->Divide(poissonHist, asimovHist);
375  }
const XML_Char * name
Definition: expat.h:151
TFileDirectory mkdir(std::string const &dir, std::string const &descr="")
T * make(ARGS...args) const
TDirectory * dir
Definition: macro.C:5
const hit & b
Definition: hits.cxx:21
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
std::vector< float > const & AsimovSpectrum() const
std::vector< float > const & PoissonSpectrum() const
enum BeamMode string
void cmf::RandomUniverseUtility::PoissonSpectrumBinByBin ( std::vector< float > &  spectrum,
std::vector< float > &  poissonSpectrum 
)
private

Definition at line 300 of file RandomUniverseUtility.cxx.

References b, fRand, cmf::CovarianceBinUtility::Instance(), cmf::KeyToString(), and LOG_DEBUG.

Referenced by FillPoissonSpectrum().

302  {
303  for(size_t b = 0; b < spectrum.size(); ++b){
304  poissonSpectrum[b] = fRand.Poisson(spectrum[b]);
305 
306  LOG_DEBUG("RandomUniverseUtility")
307  << "PoissonSpectrumBinByBin, bin: "
308  << b
309  << " "
311  << " "
312  << spectrum[b]
313  << "->"
314  << poissonSpectrum[b]
315  << " ratio: "
316  << 1. - poissonSpectrum[b] / spectrum[b];
317 
318  }
319  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
const hit & b
Definition: hits.cxx:21
TRandom3 fRand
RNG for picking the variation in parameters.
static std::string KeyToString(long const &key)
Definition: StaticFuncs.h:228
static CovarianceBinUtility * Instance()
bool cmf::RandomUniverseUtility::UniformDrawParameters ( std::string const &  name)
inlineprivate

Definition at line 68 of file RandomUniverseUtility.h.

Referenced by CreateLocationWithVariedSystematics().

69  {
70  return (name.find("lightmodel") != std::string::npos ||
71  name.find("ckv-proton") != std::string::npos ||
72  name.find("Calibration") != std::string::npos ||
73  name.find("fluxpca") != std::string::npos);
74  }
const XML_Char * name
Definition: expat.h:151

Member Data Documentation

unsigned int cmf::RandomUniverseUtility::fNumUniverses
private

number of fake universes to create

Definition at line 59 of file RandomUniverseUtility.h.

Referenced by CreateLocationsWithVariedOscParameters(), CreateLocationsWithVariedSystematics(), and Initialize().

TH2D* cmf::RandomUniverseUtility::fOscParamDrawHist
private

keep track of the oscillation parameter values

Definition at line 55 of file RandomUniverseUtility.h.

Referenced by CreateLocationWithVariedOscParameters(), and Initialize().

bool cmf::RandomUniverseUtility::fPoissonByBin
private

use bin by bin method for picking poisson numbers

Definition at line 58 of file RandomUniverseUtility.h.

Referenced by FillPoissonSpectrum(), and Initialize().

bool cmf::RandomUniverseUtility::fPoissonByHist
private

use histogram method for picking poisson numbers

Definition at line 57 of file RandomUniverseUtility.h.

Referenced by Initialize().

bool cmf::RandomUniverseUtility::fPoissonFluctuate
private

do we want to poisson fluctuate the FD prediction?

Definition at line 56 of file RandomUniverseUtility.h.

Referenced by FillPoissonSpectrum(), and Initialize().

TRandom3 cmf::RandomUniverseUtility::fRand
private

RNG for picking the variation in parameters.

Definition at line 53 of file RandomUniverseUtility.h.

Referenced by CreateLocationWithVariedOscParameters(), CreateLocationWithVariedSystematics(), Initialize(), and PoissonSpectrumBinByBin().

TH2D* cmf::RandomUniverseUtility::fSystDrawHist
private

keep track of the systematic parameter values

Definition at line 54 of file RandomUniverseUtility.h.

Referenced by CreateLocationWithVariedSystematics(), and Initialize().


The documentation for this class was generated from the following files: