Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
Public Member Functions | Public Attributes | List of all members
JMARKOV::JHistGenerator Class Reference

Implementation of the JGenerator interface. More...

#include <JMarkovGenerator.hh>

Inheritance diagram for JMARKOV::JHistGenerator:
JMARKOV::JGenerator

Public Member Functions

 JHistGenerator (TH1 *_hx, TH1 *_hy, TH1 *_hz)
 Constructor. More...
 
 ~JHistGenerator ()
 
JPosition3D getPosition ()
 Return a randomly generated position. More...
 
double getWeight (JPosition3D pos)
 return the weight (=probability density dP/dV) for the given position. More...
 

Public Attributes

TH1 * hx
 
TH1 * hy
 
TH1 * hz
 

Detailed Description

Implementation of the JGenerator interface.

Generates positions by sampling from 3 histograms that represent the projection of the distribution along the X, Y and Z axis.

Definition at line 521 of file JMarkovGenerator.hh.

Constructor & Destructor Documentation

◆ JHistGenerator()

JMARKOV::JHistGenerator::JHistGenerator ( TH1 *  _hx,
TH1 *  _hy,
TH1 *  _hz 
)
inline

Constructor.

The histograms are cloned and automatically normalized.

Note: empty bins should always be avoided!

Definition at line 530 of file JMarkovGenerator.hh.

530  {
531  // copy histograms
532  hx = (TH1*) _hx->Clone( _hx->GetName() ) ;
533  hy = (TH1*) _hy->Clone( _hy->GetName() ) ;
534  hz = (TH1*) _hz->Clone( _hz->GetName() ) ;
535  // normalize histograms
536  hx->Scale( 1.0/hx->Integral("width") ) ;
537  hy->Scale( 1.0/hy->Integral("width") ) ;
538  hz->Scale( 1.0/hz->Integral("width") ) ;
539  }

◆ ~JHistGenerator()

JMARKOV::JHistGenerator::~JHistGenerator ( )
inline

Definition at line 541 of file JMarkovGenerator.hh.

541  {
542  delete hx ;
543  delete hy ;
544  delete hz ;
545  }

Member Function Documentation

◆ getPosition()

JPosition3D JMARKOV::JHistGenerator::getPosition ( )
inlinevirtual

Return a randomly generated position.

Implements JMARKOV::JGenerator.

Definition at line 547 of file JMarkovGenerator.hh.

547  {
548  double x = hx->GetRandom() ;
549  double y = hy->GetRandom() ;
550  double z = hz->GetRandom() ;
551  return JPosition3D(x,y,z) ;
552  }
Data structure for position in three dimensions.
Definition: JPosition3D.hh:38

◆ getWeight()

double JMARKOV::JHistGenerator::getWeight ( JPosition3D  pos)
inlinevirtual

return the weight (=probability density dP/dV) for the given position.

When the generator is properly normalized, the integral of this quantity over the whole space is 1.

Implements JMARKOV::JGenerator.

Definition at line 554 of file JMarkovGenerator.hh.

554  {
555  Int_t bin ;
556  double w = 1 ;
557 
558  bin = hx->GetXaxis()->FindBin( pos.getX() ) ;
559  if( bin==0 || bin==hx->GetNbinsX()+1 ) return 0.0 ; // out of range
560  w *= hx->GetBinContent(bin) ;
561 
562  bin = hy->GetXaxis()->FindBin( pos.getY() ) ;
563  if( bin==0 || bin==hy->GetNbinsX()+1 ) return 0.0 ; // out of range
564  w *= hy->GetBinContent(bin) ;
565 
566  bin = hz->GetXaxis()->FindBin( pos.getZ() ) ;
567  if( bin==0 || bin==hz->GetNbinsX()+1 ) return 0.0 ; // out of range
568  w *= hz->GetBinContent(bin) ;
569 
570  return w ;
571  }
double getY() const
Get y position.
Definition: JVector3D.hh:104
double getZ() const
Get z position.
Definition: JVector3D.hh:115
double getX() const
Get x position.
Definition: JVector3D.hh:94
data_type w[N+1][M+1]
Definition: JPolint.hh:867

Member Data Documentation

◆ hx

TH1* JMARKOV::JHistGenerator::hx

Definition at line 573 of file JMarkovGenerator.hh.

◆ hy

TH1* JMARKOV::JHistGenerator::hy

Definition at line 574 of file JMarkovGenerator.hh.

◆ hz

TH1* JMARKOV::JHistGenerator::hz

Definition at line 575 of file JMarkovGenerator.hh.


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