HighLAND
ConfigurationBase.cxx
1 #include "ConfigurationBase.hxx"
2 
3 //********************************************************************
4 ConfigurationBase::ConfigurationBase(){
5 //********************************************************************
6 
7  _name="";
8  _ntoys=1;
9  _enabled = false;
10  _toyEnabled.resize(1);
11  _systematicsEnabled.clear();
12  _weightsEnabled.clear();
13  _variationsEnabled.clear();
14  _toy_randomSeed=-1;
15  _toyMaker=NULL;
16 }
17 
18 //********************************************************************
19 ConfigurationBase::ConfigurationBase(Int_t index, const std::string& name, UInt_t ntoys, Int_t randomSeed, ToyMaker* toyMaker){
20 //********************************************************************
21 
22  _conf_index = index;
23  _name=name;
24  _ntoys=ntoys;
25  _toy_ref=0;
26  _enabled = true;
27  _toyEnabled.resize(ntoys);
28  _systematicsEnabled.clear();
29  _weightsEnabled.clear();
30  _variationsEnabled.clear();
31  _toy_randomSeed=randomSeed;
32  _toyMaker=toyMaker;
33 }
34 
35 //********************************************************************
36 void ConfigurationBase::Dump(SystematicManager& syst){
37 //********************************************************************
38 
39  std::cout << "*********** Configuration: " << Name() << " *************" << std::endl;
40 
41  std::cout << " enabled: " << (Int_t)IsEnabled() << std::endl;
42  std::cout << " NVariations: " << GetEnabledEventVariations().size() << std::endl;
43  std::cout << " NWeights: " << GetEnabledEventWeights().size() << std::endl;
44  std::cout << " NSyst: " << GetEnabledSystematics().size() << std::endl;
45  std::cout << " NToys: " << GetNToys() << std::endl;
46  std::cout << " Random seed: " << GetToyRandomSeed() << std::endl;
47 
48  if (GetEnabledSystematics().size()==0) return;
49 
50  // Dump the systematics for this configuration
51  syst.DisableAllSystematics();
54  syst.DumpWeightSystematics();
55  syst.EnableAllSystematics();
56 
57 }
58 
59 //********************************************************************
60 void ConfigurationBase::EnableSystematics(const std::vector<Int_t>& indices){
61 //********************************************************************
62 
63  // use a set such that the same systematic is not added twice
64  std::set<Int_t> enabled;
65 
66  // Insert all systematics that are already enabled
67  for (std::vector<Int_t>::iterator it = _systematicsEnabled.begin();it!=_systematicsEnabled.end();it++)
68  enabled.insert(*it);
69 
70  // Insert the systematics to enable
71  for (std::vector<Int_t>::const_iterator it = indices.begin();it!=indices.end();it++)
72  enabled.insert(*it);
73 
74  // Copy the sent into the vector of _systematicsEnabled
75  _systematicsEnabled.clear();
76  for (std::set<Int_t>::iterator it = enabled.begin();it!=enabled.end();it++)
77  _systematicsEnabled.push_back(*it);
78 }
79 
80 //********************************************************************
82 //********************************************************************
83 
84  // Creat the toy experiments
85  if (!_toyMaker) return;
87 
88  // Fill the structure to allow saving variations in the config tree
89  const std::vector<ToyExperiment*>& toys = _toyMaker->GetToyExperiments();
90  for (std::vector<ToyExperiment*>::const_iterator it=toys.begin();it!=toys.end();it++){
91  ToyExperiment& toy = **it;
92  ToyVariationWrite wtoy;
93  for (UInt_t i = 0; i<NMAXSYSTEMATICS;i++){
94  if (!toy.GetToyVariations(i)) continue;
95  for(UInt_t j = 0; j < toy.GetToyVariations(i)->GetNParameters(); ++j){
96  if (wtoy.npar>=NMAXPARAMETERS) return;
97  wtoy.variations[wtoy.npar] = toy.GetToyVariations(i)->Variations[j];
98  wtoy.weights[wtoy.npar] = toy.GetToyVariations(i)->Weights[j];
99  wtoy.par_index[wtoy.npar] = wtoy.npar;
100  wtoy.npar++;
101  }
102  }
103  for (UInt_t ipar2 = wtoy.npar;ipar2<NMAXPARAMETERS;ipar2++){
104  wtoy.variations[ipar2] = 0;
105  wtoy.weights[ipar2] = 0;
106  wtoy.par_index[ipar2] = -1;
107  }
108  _toys.push_back(wtoy);
109  }
110 
111 }
112 
const std::vector< ToyExperiment * > & GetToyExperiments() const
Returns the Toy experiment vector.
Definition: ToyMaker.hxx:38
std::string _name
Name of the configuration.
Float_t * Variations
the vector of Variations, one for each of the systematic parameters
UInt_t GetNParameters() const
Number of parameters for this systematic.
ToyMaker * _toyMaker
The ToyMaker, which fills the toy.
void EnableAllSystematics()
Enable all Systematics.
Float_t * Weights
the vector of Weights, one for each of the systematic parameters
Int_t GetNToys() const
Get and sets the number of toys.
std::vector< Int_t > _systematicsEnabled
Vector of indices of the systematics enabled in this configuration.
std::vector< Int_t > _variationsEnabled
Vector of indices of the variations enabled in this configuration.
const std::vector< Int_t > & GetEnabledEventVariations()
Get the variations enabled for this configuration.
void DumpVariationSystematics()
Dump all variationSystematics.
std::vector< Int_t > _weightsEnabled
Vector of indices of the weights enabled in this configuration.
std::vector< bool > _toyEnabled
Tell wether a toy is enabled or not.
void CreateToyExperiments(const SystematicManager &syst)
Create the ToyExperiments using the ToyMaker and the SystematicManager.
A Class that allows saving the variations in the config tree.
const std::string & Name() const
Returns the name of this configuration.
const std::vector< Int_t > & GetEnabledEventWeights()
Get the weights enabled for this configuration.
Int_t GetToyRandomSeed() const
Get and sets the random seed used to generate the toys.
The maximum number of systematics that is supported.
std::vector< ToyVariationWrite > _toys
The variations for each of the toys.
Int_t _toy_ref
The reference toy with the nominal selection.
std::vector< SystematicBase * > & GetSystematics()
Get the vector containing all systematics (contains NULL pointers)
void CreateToyExperiments(Int_t ntoys, const std::vector< SystematicBase *> &systematicsEnabled)
Create the Toy Experiment, provided the number of toys,.
Definition: ToyMaker.cxx:34
void DisableAllSystematics()
Disable all Systematics.
void DumpWeightSystematics()
Dump all weightSystematics.
ToyVariations * GetToyVariations(UInt_t index) const
returns the variations for a given systematic (index)
bool _enabled
Is this configuration enabled ?
void EnableSystematics(const std::vector< Int_t > &systs)
Enable the systematics registered with the given indices.
const std::vector< Int_t > & GetEnabledSystematics()
Get the systematics enabled for this configuration.
Int_t _conf_index
Configuration index.
void EnableSystematics(const std::vector< Int_t > &indices)
Enable the systematic registered with the given name.
Int_t _ntoys
Number of Toy experiments or virtual analyses.
Int_t _toy_randomSeed
The random seed used to generate the toys.