ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
generate::hist_generator Class Reference

generate a distribution according to an input histogram (after smoothing) More...

#include <generate.h>

Inheritance diagram for generate::hist_generator:
Collaboration diagram for generate::hist_generator:

Public Member Functions

 hist_generator (TH1D *h, bool _smooth=true)
 
 hist_generator (const hist_generator &)=delete
 
hist_generator operator= (const hist_generator &)=delete
 
virtual ~hist_generator ()
 
double generate () const
 actually generate a random number from the distribution More...
 
TH1D * histogram ()
 
TH1D * rawhistogram ()
 
TH1D * smoothhistogram ()
 

Private Member Functions

int getbin (double y) const
 
double invert (double y) const
 

Private Attributes

std::vector< double > m_y
 
std::vector< double > m_x
 
std::vector< double > m_dx
 
std::vector< double > m_dy
 
std::vector< double > m_dxdy
 
TH1D * m_s
 
TH1D * m_raw
 
TH1D * m_smooth
 
BasicRandomm_random
 

Detailed Description

generate a distribution according to an input histogram (after smoothing)

Definition at line 72 of file generate.h.

Constructor & Destructor Documentation

◆ hist_generator() [1/2]

generate::hist_generator::hist_generator ( TH1D *  h,
bool  _smooth = true 
)

save the original histogram (should save a copy ho hum)

smooth the original

else simply clone the original

generate a pdf from the smoothed distribution

assign the actual generator use a shared generator

use a dedicated generator mrandom = new BasicRandom(false);

Definition at line 231 of file generate.cxx.

231  : m_random(0) {
232 
234  m_raw = h;
235 
236  if ( _smooth ) {
238  m_smooth = smooth( h );
239  }
240  else {
242  m_smooth = (TH1D*)h->Clone( (std::string(h->GetName())+"-smooth").c_str() );
243  m_smooth->SetDirectory(0);
244  }
245 
246 
248  m_s = PDF( m_smooth );
249  delete m_smooth;
250 
251  m_s->SetMinimum(0);
252  m_s->SetMaximum(1);
253 
254  m_y.push_back( 0 );
255  m_x.push_back( m_s->GetBinLowEdge(1) );
256 
257 
258  for ( int i=1 ; i<=m_s->GetNbinsX() ; i++ ) {
259  m_x.push_back( m_s->GetBinLowEdge(i+1) );
260  m_y.push_back( m_s->GetBinContent(i) );
261  }
262 
263  m_dy.resize(m_x.size());
264  m_dx.resize(m_x.size());
265  m_dxdy.resize(m_x.size());
266 
267  // std::cout << "calculating gradients ..." << std::endl;
268 
269  for ( unsigned i=0 ; i<m_y.size()-1 ; i++ ) {
270  double dy = m_y[i+1] - m_y[i];
271  double dx = m_x[i+1] - m_x[i];
272 
273  double dxdy = dx/dy;
274 
275  m_dy[i] = dy;
276  m_dx[i] = dx;
277  m_dxdy[i] = dxdy;
278  }
279 
282  m_random = new BasicRandom(true);
285 
286 }

◆ hist_generator() [2/2]

generate::hist_generator::hist_generator ( const hist_generator )
delete

◆ ~hist_generator()

virtual generate::hist_generator::~hist_generator ( )
inlinevirtual

Definition at line 81 of file generate.h.

81 { delete m_s; if ( m_random ) delete m_random; }

Member Function Documentation

◆ generate()

double generate::hist_generator::generate ( ) const
inlinevirtual

actually generate a random number from the distribution

Implements generate::generator_base.

Definition at line 84 of file generate.h.

84  {
85  return invert(m_random->uniform());
86  }

◆ getbin()

int generate::hist_generator::getbin ( double  y) const
inlineprivate

Definition at line 94 of file generate.h.

94  {
95  for ( unsigned i=0 ; i<m_y.size() ; i++ ) if ( y<=m_y[i] ) return i;
96  return m_y.size()-1;
97  }

◆ histogram()

TH1D* generate::hist_generator::histogram ( )
inline

Definition at line 88 of file generate.h.

88 { return m_s; }

◆ invert()

double generate::hist_generator::invert ( double  y) const
inlineprivate

Definition at line 99 of file generate.h.

99  {
100  int i = getbin(y);
101  if ( i==0 ) return 0;
102  else return (y-m_y[i-1])*m_dxdy[i-1]+m_x[i-1];
103  }

◆ operator=()

hist_generator generate::hist_generator::operator= ( const hist_generator )
delete

◆ rawhistogram()

TH1D* generate::hist_generator::rawhistogram ( )
inline

Definition at line 89 of file generate.h.

89 { return m_raw; }

◆ smoothhistogram()

TH1D* generate::hist_generator::smoothhistogram ( )
inline

Definition at line 90 of file generate.h.

90 { return m_smooth; }

Member Data Documentation

◆ m_dx

std::vector<double> generate::hist_generator::m_dx
private

Definition at line 112 of file generate.h.

◆ m_dxdy

std::vector<double> generate::hist_generator::m_dxdy
private

Definition at line 115 of file generate.h.

◆ m_dy

std::vector<double> generate::hist_generator::m_dy
private

Definition at line 113 of file generate.h.

◆ m_random

BasicRandom* generate::hist_generator::m_random
private

Definition at line 121 of file generate.h.

◆ m_raw

TH1D* generate::hist_generator::m_raw
private

Definition at line 118 of file generate.h.

◆ m_s

TH1D* generate::hist_generator::m_s
private

Definition at line 117 of file generate.h.

◆ m_smooth

TH1D* generate::hist_generator::m_smooth
private

Definition at line 119 of file generate.h.

◆ m_x

std::vector<double> generate::hist_generator::m_x
private

Definition at line 109 of file generate.h.

◆ m_y

std::vector<double> generate::hist_generator::m_y
private

Definition at line 108 of file generate.h.


The documentation for this class was generated from the following files:
generate::hist_generator::m_dx
std::vector< double > m_dx
Definition: generate.h:112
generate::hist_generator::m_s
TH1D * m_s
Definition: generate.h:117
lumiFormat.i
int i
Definition: lumiFormat.py:85
extractSporadic.h
list h
Definition: extractSporadic.py:97
generate::hist_generator::getbin
int getbin(double y) const
Definition: generate.h:94
generate::PDF
TH1D * PDF(TH1D *hin)
generate a (normalised) pdf from a distribution
Definition: generate.cxx:112
generate::hist_generator::m_random
BasicRandom * m_random
Definition: generate.h:121
generate::hist_generator::invert
double invert(double y) const
Definition: generate.h:99
generate::smooth
TH1D * smooth(TH1D *hin, bool sym)
smooth a distribution about the maximum NB: maximum is not smoothed
Definition: generate.cxx:158
generate::hist_generator::m_raw
TH1D * m_raw
Definition: generate.h:118
makeTRTBarrelCans.dy
tuple dy
Definition: makeTRTBarrelCans.py:21
y
#define y
h
BasicRandom
Definition: BasicRandom.h:32
generate::hist_generator::m_smooth
TH1D * m_smooth
Definition: generate.h:119
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
generate::hist_generator::m_dy
std::vector< double > m_dy
Definition: generate.h:113
BasicRandom::uniform
double uniform()
Definition: BasicRandom.h:54
generate::hist_generator::m_x
std::vector< double > m_x
Definition: generate.h:109
generate::hist_generator::m_y
std::vector< double > m_y
Definition: generate.h:108
generate::hist_generator::m_dxdy
std::vector< double > m_dxdy
Definition: generate.h:115