Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
genie::supernova::OrderedSampler Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/GenieSNova/src/Sampler.h"

Public Member Functions

 OrderedSampler ()
 
 ~OrderedSampler ()
 
void Init (TH1 *hist, bool integral=false)
 
bool End ()
 
double GenerateNext ()
 
int GetBin ()
 
void Reload ()
 
void SetProbScale (double scale)
 
const size_t Nbins ()
 
const double * GetBinEdges ()
 
const double GetBinValue (size_t n)
 

Protected Member Functions

double BinStart ()
 
double BinEnd ()
 
void Step ()
 
void StartNextBin ()
 

Protected Attributes

size_t fBin
 
double fPos
 
std::vector< double > fBinEdges
 
std::vector< double > fBinValues
 
double fFreqCurrent
 
double fProbScale
 

Detailed Description

Definition at line 22 of file Sampler.h.

Constructor & Destructor Documentation

OrderedSampler::OrderedSampler ( )

Definition at line 44 of file Sampler.cxx.

OrderedSampler::~OrderedSampler ( )

Definition at line 48 of file Sampler.cxx.

48 {}

Member Function Documentation

double OrderedSampler::BinEnd ( )
protected

Definition at line 155 of file Sampler.cxx.

References fBin, and fBinEdges.

Referenced by GenerateNext(), StartNextBin(), and Step().

156 {
157  return fBinEdges[fBin + 1];
158 }
std::vector< double > fBinEdges
Definition: Sampler.h:48
double OrderedSampler::BinStart ( )
protected

Definition at line 148 of file Sampler.cxx.

References fBin, and fBinEdges.

Referenced by GenerateNext(), and StartNextBin().

149 {
150  return fBinEdges[fBin];
151 }
std::vector< double > fBinEdges
Definition: Sampler.h:48
bool OrderedSampler::End ( void  )

Definition at line 77 of file Sampler.cxx.

References fBin, and fBinEdges.

Referenced by genie::supernova::GFluxGenerator::End(), GenerateNext(), and StartNextBin().

78 {
79  return fBin >= fBinEdges.size() - 1;
80 }
std::vector< double > fBinEdges
Definition: Sampler.h:48
double OrderedSampler::GenerateNext ( void  )

Definition at line 84 of file Sampler.cxx.

References BinEnd(), BinStart(), End(), fPos, LOG, pDEBUG, StartNextBin(), and Step().

Referenced by genie::supernova::GFluxGenerator::GenerateNext().

85 {
86  LOG("Sampler", pDEBUG) << "from pos=" << fPos;
87 
88  if (this->End()) return 0;
89  do {
90  if (fPos >= this->BinEnd()) this->StartNextBin();
91  if (End()) return 0;
92 
93  // Generate random step, using the average distance in current bin
94  this->Step();
95  LOG("Sampler", pDEBUG) << "now pos=" << fPos
96  << " (bin =[" << this->BinStart()
97  << "," << this->BinEnd() << "])";
98  } while (fPos >= this->BinEnd());
99 
100  LOG("Sampler", pDEBUG) << "return pos=" << fPos;
101  return fPos;
102 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
#define pDEBUG
Definition: Messenger.h:64
int OrderedSampler::GetBin ( )

Definition at line 106 of file Sampler.cxx.

References fBin.

Referenced by genie::supernova::GFluxGenerator::GenerateNext().

107 {
108  return fBin;
109 }
const double * OrderedSampler::GetBinEdges ( )

Definition at line 135 of file Sampler.cxx.

References fBinEdges.

136 {
137  return fBinEdges.data();
138 }
std::vector< double > fBinEdges
Definition: Sampler.h:48
const double OrderedSampler::GetBinValue ( size_t  n)

Definition at line 142 of file Sampler.cxx.

References fBinValues, fProbScale, and getGoodRuns4SAM::n.

Referenced by Step().

142  {
143  return fBinValues[n] * fProbScale;
144 }
std::vector< double > fBinValues
Definition: Sampler.h:49
void OrderedSampler::Init ( TH1 *  hist,
bool  integral = false 
)

Definition at line 52 of file Sampler.cxx.

References fBin, fBinEdges, fBinValues, MECModelEnuComparisons::i, LOG, Nbins(), pDEBUG, pNOTICE, and StartNextBin().

Referenced by genie::supernova::GFluxGenerator::GFluxGenerator().

53 {
54  LOG("Sampler", pDEBUG) << "init";
55 
56  fBin = 0;
57  int Nbins = hist->GetNbinsX() + 1;
58 
59  fBinEdges.resize(Nbins);
60  fBinValues.resize(Nbins);
61 
62  for (int i = 0; i < Nbins; ++i) {
63  fBinEdges[i] = hist->GetBinLowEdge(i);
64  fBinValues[i] = hist->GetBinContent(i);
65  if(integral)
66  fBinValues[i] /= hist->GetBinWidth(i);
67  }
68 
69  // Start from bin#1, skipping underflow
70  this->StartNextBin();
71  LOG("Sampler", pNOTICE) << "Ordered sample with nbins=" << Nbins
72  << " [" << fBinEdges.front() << "," << fBinEdges.back() << "]";
73 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
std::vector< double > fBinValues
Definition: Sampler.h:49
std::vector< double > fBinEdges
Definition: Sampler.h:48
#define pNOTICE
Definition: Messenger.h:62
#define pDEBUG
Definition: Messenger.h:64
const size_t OrderedSampler::Nbins ( )

Definition at line 128 of file Sampler.cxx.

References fBinValues.

Referenced by Init().

129 {
130  return fBinValues.size();
131 }
std::vector< double > fBinValues
Definition: Sampler.h:49
void OrderedSampler::Reload ( )

Definition at line 113 of file Sampler.cxx.

References fBin, and StartNextBin().

Referenced by genie::supernova::GFluxGenerator::Reload().

114 {
115  fBin = 0;
116  this->StartNextBin();
117 }
void OrderedSampler::SetProbScale ( double  scale)

Definition at line 121 of file Sampler.cxx.

References fProbScale, and scale.

Referenced by genie::supernova::GFluxGenerator::SetProbScale().

122 {
123  fProbScale = scale;
124 }
Double_t scale
Definition: plot.C:25
void OrderedSampler::StartNextBin ( )
protected

Definition at line 186 of file Sampler.cxx.

References BinEnd(), BinStart(), End(), fBin, fBinValues, fPos, LOG, and pDEBUG.

Referenced by GenerateNext(), Init(), and Reload().

187  {
188  // Go to next bin and update all the variables
189  ++fBin;
190  LOG("Sampler", pDEBUG) << "Starting bin#" << fBin << "/" << fBinValues.size()
191  << "(" << this->End() << ")";
192 
193  // Start the steps from beginning of this bin
194  fPos = this->BinStart();
195 
196  if (this->End()) return;
197 
198  LOG("Sampler", pDEBUG) << "Starting bin#" << fBin
199  << " [" << this->BinStart() << "," << this->BinEnd() << "]"
200  << " Freq=" << fBinValues[fBin];
201 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
std::vector< double > fBinValues
Definition: Sampler.h:49
#define pDEBUG
Definition: Messenger.h:64
void OrderedSampler::Step ( )
protected

Definition at line 162 of file Sampler.cxx.

References BinEnd(), e, fBin, fPos, GetBinValue(), genie::RandomGen::Instance(), LOG, pDEBUG, generate_hists::rnd, genie::RandomGen::RndFlux(), and fillBadChanDBTables::step.

Referenced by GenerateNext().

163 {
164  double binValue = this->GetBinValue(fBin);
165 
166  // If the bin value is too small, move on to the next bin.
167  if (binValue < 1e-15) {
168  fPos = this->BinEnd();
169  return;
170  }
171 
173 
174  float tau = 1. / binValue;
175  double step = rnd->RndFlux().Exp(tau);
176 
177  LOG("Sampler", pDEBUG) << "step by " << step << ": " << fPos << "->" << fPos + step;
178 
179  fPos += step;
180 
181  return;
182 }
static RandomGen * Instance()
Access instance.
Definition: RandomGen.cxx:79
const double GetBinValue(size_t n)
Definition: Sampler.cxx:142
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:30
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
TRandom3 & RndFlux(void) const
rnd number generator used by flux drivers
Definition: RandomGen.h:72
Float_t e
Definition: plot.C:35
#define pDEBUG
Definition: Messenger.h:64

Member Data Documentation

size_t genie::supernova::OrderedSampler::fBin
protected

Definition at line 46 of file Sampler.h.

Referenced by BinEnd(), BinStart(), End(), GetBin(), Init(), Reload(), StartNextBin(), and Step().

std::vector<double> genie::supernova::OrderedSampler::fBinEdges
protected

Definition at line 48 of file Sampler.h.

Referenced by BinEnd(), BinStart(), End(), GetBinEdges(), and Init().

std::vector<double> genie::supernova::OrderedSampler::fBinValues
protected

Definition at line 49 of file Sampler.h.

Referenced by GetBinValue(), Init(), Nbins(), and StartNextBin().

double genie::supernova::OrderedSampler::fFreqCurrent
protected

Definition at line 51 of file Sampler.h.

double genie::supernova::OrderedSampler::fPos
protected

Definition at line 47 of file Sampler.h.

Referenced by GenerateNext(), StartNextBin(), and Step().

double genie::supernova::OrderedSampler::fProbScale
protected

Definition at line 54 of file Sampler.h.

Referenced by GetBinValue(), and SetProbScale().


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