All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ana::UniverseOracle Class Reference

#include <UniverseOracle.h>

Public Member Functions

bool SystExists (const std::string &name) const
 
std::vector< std::string > Systs () const
 List of all known syst names. More...
 
const std::vector< float > & ShiftsForSyst (const std::string &name) const
 List of shifts for this syst in each universe. More...
 
unsigned int ParameterSetIndex (const std::string &name) const
 Which index in the weights array corresponds to this parameter set? More...
 
unsigned int SystIndex (const std::string &name) const
 Which index in the weights array corresponds to the shifting of just this syst (in any parameter set)? More...
 
unsigned int ClosestShiftIndex (const std::string &name, double shift, ESide side=ESide::kEither, double *trueShift=0) const
 Within that entry, which index corresponds most closely to 'shift'? More...
 

Static Public Member Functions

static UniverseOracleInstance ()
 

Protected Member Functions

 UniverseOracle ()
 

Protected Attributes

std::map< std::string,
unsigned int > 
fPSetIdxs
 
std::map< std::string,
unsigned int > 
fSystIdxs
 
std::map< std::string,
std::vector< float > > 
fShiftVals
 

Detailed Description

Definition at line 16 of file UniverseOracle.h.

Constructor & Destructor Documentation

ana::UniverseOracle::UniverseOracle ( )
protected

Definition at line 75 of file UniverseOracle.cxx.

76  {
77  const caf::SRGlobal global = GetSRGlobal();
78  std::cout << "\nSystematic weights in file:" << std::endl;
79  PrintSRGlobal(global);
80 
81  for(unsigned int i = 0; i < global.wgts.size(); ++i){
82  const caf::SRWeightPSet& pset = global.wgts[i];
83 
84  // Save the pset index in all cases
85  fPSetIdxs[pset.name] = i;
86 
87  // Only save the remaining fields in parameter sets where only a single
88  // knob is shifted
89  if(pset.map.size() != 1) continue;
90 
91  // Save which position in the vector this was
92  fSystIdxs[pset.map[0].param.name] = i;
93  // Save all the knob values
94  fShiftVals[pset.map[0].param.name] = pset.map[0].vals;
95  }
96  }
caf::SRGlobal GetSRGlobal()
std::map< std::string, unsigned int > fSystIdxs
std::vector< SRWeightPSet > wgts
Definition: SRGlobal.h:13
void PrintSRGlobal(const caf::SRGlobal &global)
std::vector< SRWeightMapEntry > map
Definition: SRWeightPSet.h:21
std::map< std::string, std::vector< float > > fShiftVals
std::string name
Definition: SRWeightPSet.h:16
std::map< std::string, unsigned int > fPSetIdxs
BEGIN_PROLOG could also be cout

Member Function Documentation

unsigned int ana::UniverseOracle::ClosestShiftIndex ( const std::string &  name,
double  shift,
ESide  side = ESide::kEither,
double *  trueShift = 0 
) const

Within that entry, which index corresponds most closely to 'shift'?

Definition at line 143 of file UniverseOracle.cxx.

147  {
148  const std::vector<float>& v = ShiftsForSyst(name);
149  int bestIdx = -1;
150  double bestDist;
151  for(unsigned int i = 0; i < v.size(); ++i){
152  if(side == ESide::kBelow && v[i] > shift) continue;
153  if(side == ESide::kAbove && v[i] < shift) continue;
154  const double dv = fabs(v[i]-shift);
155  if(bestIdx == -1 || dv < bestDist){
156  bestIdx = i;
157  bestDist = dv;
158  if(trueShift) *trueShift = v[i];
159  }
160  }
161  return unsigned(bestIdx);
162  }
const std::vector< float > & ShiftsForSyst(const std::string &name) const
List of shifts for this syst in each universe.
shift
Definition: fcl_checks.sh:26
then echo fcl name
UniverseOracle & ana::UniverseOracle::Instance ( )
static

Definition at line 68 of file UniverseOracle.cxx.

69  {
70  static UniverseOracle uo;
71  return uo;
72  }
unsigned int ana::UniverseOracle::ParameterSetIndex ( const std::string &  name) const

Which index in the weights array corresponds to this parameter set?

Definition at line 121 of file UniverseOracle.cxx.

122  {
123  auto it = fPSetIdxs.find(name);
124  if(it == fPSetIdxs.end()){
125  std::cout << "UniverseOracle: pset '" << name << "' not known" << std::endl;
126  abort();
127  }
128  return it->second;
129  }
std::map< std::string, unsigned int > fPSetIdxs
then echo fcl name
BEGIN_PROLOG could also be cout
const std::vector< float > & ana::UniverseOracle::ShiftsForSyst ( const std::string &  name) const

List of shifts for this syst in each universe.

Definition at line 114 of file UniverseOracle.cxx.

115  {
116  assert(SystExists(name));
117  return fShiftVals.find(name)->second;
118  }
std::map< std::string, std::vector< float > > fShiftVals
bool SystExists(const std::string &name) const
then echo fcl name
bool ana::UniverseOracle::SystExists ( const std::string &  name) const

Definition at line 99 of file UniverseOracle.cxx.

100  {
101  return fShiftVals.find(name) != fShiftVals.end();
102  }
std::map< std::string, std::vector< float > > fShiftVals
then echo fcl name
unsigned int ana::UniverseOracle::SystIndex ( const std::string &  name) const

Which index in the weights array corresponds to the shifting of just this syst (in any parameter set)?

Definition at line 132 of file UniverseOracle.cxx.

133  {
134  auto it = fSystIdxs.find(name);
135  if(it == fSystIdxs.end()){
136  std::cout << "UniverseOracle: syst '" << name << "' not known" << std::endl;
137  abort();
138  }
139  return it->second;
140  }
std::map< std::string, unsigned int > fSystIdxs
then echo fcl name
BEGIN_PROLOG could also be cout
std::vector< std::string > ana::UniverseOracle::Systs ( ) const

List of all known syst names.

Definition at line 105 of file UniverseOracle.cxx.

106  {
107  std::vector<std::string> ret;
108  ret.reserve(fShiftVals.size());
109  for(auto it: fShiftVals) ret.push_back(it.first);
110  return ret;
111  }
std::map< std::string, std::vector< float > > fShiftVals

Member Data Documentation

std::map<std::string, unsigned int> ana::UniverseOracle::fPSetIdxs
protected

Definition at line 42 of file UniverseOracle.h.

std::map<std::string, std::vector<float> > ana::UniverseOracle::fShiftVals
protected

Definition at line 44 of file UniverseOracle.h.

std::map<std::string, unsigned int> ana::UniverseOracle::fSystIdxs
protected

Definition at line 43 of file UniverseOracle.h.


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