HighLAND
baseToyMaker.cxx
1 #include "baseToyMaker.hxx"
2 #include "Parameters.hxx"
3 
4 //******************************************************************
5 baseToyMaker::baseToyMaker(UInt_t seed, bool zero_var):ToyMaker(){
6 //******************************************************************
7 
8  _binnedPDF = new BinnedGaussian(10,0,1);
9 
10  // Set the seed
11  _RandomGenerator.SetSeed(seed);
12 
13  // Use a random generator for each systematic
14  _individualRandomGenerator = (bool) (ND::params().GetParameterI("baseAnalysis.Systematics.IndividualRandomGenerator"));
15 
16  if (_individualRandomGenerator){
17  for (UInt_t isyst = 0; isyst<NMAXSYSTEMATICS;isyst++){
18  SystematicBase* syst = _systematics[isyst];
19  if (!syst) continue;
20 
21  _seeds[isyst] = syst->GetIndex() + seed*NMAXSYSTEMATICS;
22  _RandomGenerators[isyst].SetSeed(_seeds[isyst]);
23  }
24  }
25 
26  // Save the random Seed
27  _seed = seed;
28 
29  // Apply 0 variation
30  _zero_var = zero_var;
31 }
32 
33 //******************************************************************
35 //******************************************************************
36 
37  // Set the same weight (1) for al toys. This will be later normalized to the number of toys
38  Float_t weight = 1.;
39 
40 
41  for (UInt_t isyst = 0; isyst<NMAXSYSTEMATICS;isyst++){
42  SystematicBase* syst = _systematics[isyst];
43  if (!syst) continue;
44 
45  // Create the proper structure for the ToyExperiment adding each of the toyVariations
46  toy.AddToyVariation(syst->GetIndex(), syst->GetNParameters());
47 
48  // Loop over parameters for this systematic
49  for (UInt_t ipar = 0;ipar<syst->GetNParameters();ipar++){
50  Float_t var = 0;
51  // When the option _zero_var is enabled all variations are 0
52  if (!_zero_var){
53  if (_individualRandomGenerator){
54  if (syst->PDF() == SystematicBase::kUniform) var = _RandomGenerators[isyst].Uniform(0.,1.);
55  else if (syst->PDF() == SystematicBase::kGaussian) var = _RandomGenerators[isyst].Gaus(0.,1.);
56  }
57  else{
58  if (syst->PDF() == SystematicBase::kUniform) var = _RandomGenerator.Uniform(0.,1.);
59  else if (syst->PDF() == SystematicBase::kGaussian) var = _RandomGenerator.Gaus(0.,1.);
60  }
61  }
62  toy.SetToyVariation(isyst,ipar,var,weight);
63  }
64  }
65 }
66 
Int_t GetIndex() const
Return the index of this systematic.
bool _zero_var
Apply 0 variation.
int GetParameterI(std::string)
Get parameter. Value is returned as integer.
Definition: Parameters.cxx:217
TRandom3 _RandomGenerator
A random generator that can be used to generate throws.
This class defines a symmetric binned gaussian.
Definition: BinnedPDF.hxx:46
baseToyMaker(UInt_t seed, bool zero_var=false)
Create the Toy experiment.
Definition: baseToyMaker.cxx:5
UInt_t _seed
The random seed used.
PDFEnum PDF() const
Return the PDF of this systematic.
SystematicBase * _systematics[NMAXSYSTEMATICS]
The systematics that need to be considered.
Definition: ToyMaker.hxx:46
void SetToyVariation(UInt_t index, UInt_t ipar, Float_t var, Float_t weight=1.)
Set the variation for a given systematic (index) and a given parameter (ipar) in that systematic...
void FillToyExperiment(ToyExperiment &toy)
Fills the Toy Experiment with a given index.
void AddToyVariation(Int_t index, UInt_t npar)
Add a systematic, specifying the systematic index and number of systematic parameters.
UInt_t GetNParameters() const
Returns the number of systematic parameters associated to this systematic.