Jpp  16.0.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Public Attributes | List of all members
JMARKOV::JSphereGenerator Class Reference

Implementation of the JGenerator interface. More...

#include <JMarkovGenerator.hh>

Inheritance diagram for JMARKOV::JSphereGenerator:
JMARKOV::JGenerator

Public Member Functions

 JSphereGenerator (const JPosition3D &_x0, double _r=0, TH2 *_h=NULL)
 Constructor. More...
 
 ~JSphereGenerator ()
 
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

JPosition3D x0
 
double r
 
TH2 * h
 

Detailed Description

Implementation of the JGenerator interface.

Generates positions on a sphere of radius _r centered at _x0 by sampling from a 2D histogram of cosTheta vs phi.

When r=0, it simply returns the position x0.

Definition at line 582 of file JMarkovGenerator.hh.

Constructor & Destructor Documentation

JMARKOV::JSphereGenerator::JSphereGenerator ( const JPosition3D _x0,
double  _r = 0,
TH2 *  _h = NULL 
)
inline

Constructor.

The histogram is cloned and automatically normalized. The x-axis is assumed to be cos(theta), and the y-axis is assumed to be phi in radians. Empty bins should be avoided!

Definition at line 592 of file JMarkovGenerator.hh.

592  : x0(_x0), r(_r) {
593  h = NULL ;
594 
595  if( r>0 ) {
596  // copy histogram
597  h = (TH2*) _h->Clone( _h->GetName() ) ;
598  // check that it has the proper limits
599  if( h->GetXaxis()->GetXmin()<-1 || h->GetXaxis()->GetXmax()>1 ) {
600  cerr << "FATAL ERROR in JSphereGenerator. Invalid x-axis range." << endl ;
601  exit(1) ;
602  }
603  if( h->GetYaxis()->GetXmin() < -M_PI || h->GetYaxis()->GetXmax() > M_PI ) {
604  cerr << "FATAL ERROR in JSphereGenerator. Invalid y-axis range." << endl ;
605  exit(1) ;
606  }
607  // normalize histogram
608  h->Scale( 1.0/h->Integral("width") ) ;
609  h->SetOption("colz") ;
610  }
611  }
exit
Definition: JPizza.sh:36
JMARKOV::JSphereGenerator::~JSphereGenerator ( )
inline

Definition at line 613 of file JMarkovGenerator.hh.

613  {
614  delete h ;
615  }

Member Function Documentation

JPosition3D JMARKOV::JSphereGenerator::getPosition ( )
inlinevirtual

Return a randomly generated position.

Implements JMARKOV::JGenerator.

Definition at line 617 of file JMarkovGenerator.hh.

617  {
618  if( r==0 ) return x0 ;
619 
620  double costheta, phi ;
621  h->GetRandom2(costheta,phi) ;
622  return x0 + r * JVector3D(JVersor3D(JAngle3D(acos(costheta),phi))) ;
623  }
Data structure for angles in three dimensions.
Definition: JAngle3D.hh:33
Data structure for vector in three dimensions.
Definition: JVector3D.hh:34
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:26
double JMARKOV::JSphereGenerator::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 625 of file JMarkovGenerator.hh.

625  {
626  if( r==0 ) return 1 ;
627 
628  // check that the position is in fact on the target surface
629  const double tolerance = 1e-5 ;
630  if( fabs( pos.getDistance(x0)-r ) > tolerance*r ) {
631  return 0.0 ;
632  }
633 
634  JVersor3D dir(pos-x0) ;
635  double ct = dir.getDZ() ;
636  double phi = dir.getPhi() ;
637 
638  if( ct < h->GetXaxis()->GetXmin() || ct >=h->GetXaxis()->GetXmax() ) return 0.0 ;
639  if( phi< h->GetYaxis()->GetXmin() || phi>=h->GetYaxis()->GetXmax() ) return 0.0 ;
640 
641  Int_t bin = h->FindBin(ct,phi) ;
642  return h->GetBinContent(bin) / (r*r) ;
643  }
double getDistance(const JVector3D &pos) const
Get distance to point.
Definition: JVector3D.hh:270
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:26

Member Data Documentation

JPosition3D JMARKOV::JSphereGenerator::x0

Definition at line 645 of file JMarkovGenerator.hh.

double JMARKOV::JSphereGenerator::r

Definition at line 646 of file JMarkovGenerator.hh.

TH2* JMARKOV::JSphereGenerator::h

Definition at line 647 of file JMarkovGenerator.hh.


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