Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 517 of file JMarkovGenerator.hh.

Constructor & Destructor Documentation

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 526 of file JMarkovGenerator.hh.

526  {
527  // copy histograms
528  hx = (TH1*) _hx->Clone( _hx->GetName() ) ;
529  hy = (TH1*) _hy->Clone( _hy->GetName() ) ;
530  hz = (TH1*) _hz->Clone( _hz->GetName() ) ;
531  // normalize histograms
532  hx->Scale( 1.0/hx->Integral("width") ) ;
533  hy->Scale( 1.0/hy->Integral("width") ) ;
534  hz->Scale( 1.0/hz->Integral("width") ) ;
535  }
JMARKOV::JHistGenerator::~JHistGenerator ( )
inline

Definition at line 537 of file JMarkovGenerator.hh.

537  {
538  delete hx ;
539  delete hy ;
540  delete hz ;
541  }

Member Function Documentation

JPosition3D JMARKOV::JHistGenerator::getPosition ( )
inlinevirtual

Return a randomly generated position.

Implements JMARKOV::JGenerator.

Definition at line 543 of file JMarkovGenerator.hh.

543  {
544  double x = hx->GetRandom() ;
545  double y = hy->GetRandom() ;
546  double z = hz->GetRandom() ;
547  return JPosition3D(x,y,z) ;
548  }
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
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 550 of file JMarkovGenerator.hh.

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

Member Data Documentation

TH1* JMARKOV::JHistGenerator::hx

Definition at line 569 of file JMarkovGenerator.hh.

TH1* JMARKOV::JHistGenerator::hy

Definition at line 570 of file JMarkovGenerator.hh.

TH1* JMARKOV::JHistGenerator::hz

Definition at line 571 of file JMarkovGenerator.hh.


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