Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
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.
 
 ~JSphereGenerator ()
 
JPosition3D getPosition ()
 Return a randomly generated position.
 
double getWeight (JPosition3D pos)
 return the weight (=probability density dP/dV) for the given position.
 

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

Constructor & Destructor Documentation

◆ JSphereGenerator()

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

596 : x0(_x0), r(_r) {
597
598 using namespace std;
599 using namespace JPP;
600
601 h = NULL ;
602
603 if( r>0 ) {
604 // copy histogram
605 h = (TH2*) _h->Clone( _h->GetName() ) ;
606 // check that it has the proper limits
607 if( h->GetXaxis()->GetXmin()<-1 || h->GetXaxis()->GetXmax()>1 ) {
608 cerr << "FATAL ERROR in JSphereGenerator. Invalid x-axis range." << endl ;
609 exit(1) ;
610 }
611 if( h->GetYaxis()->GetXmin() < -M_PI || h->GetYaxis()->GetXmax() > M_PI ) {
612 cerr << "FATAL ERROR in JSphereGenerator. Invalid y-axis range." << endl ;
613 exit(1) ;
614 }
615 // normalize histogram
616 h->Scale( 1.0/h->Integral("width") ) ;
617 h->SetOption("colz") ;
618 }
619 }
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).

◆ ~JSphereGenerator()

JMARKOV::JSphereGenerator::~JSphereGenerator ( )
inline

Definition at line 621 of file JMarkovGenerator.hh.

621 {
622 delete h ;
623 }

Member Function Documentation

◆ getPosition()

JPosition3D JMARKOV::JSphereGenerator::getPosition ( )
inlinevirtual

Return a randomly generated position.

Implements JMARKOV::JGenerator.

Definition at line 625 of file JMarkovGenerator.hh.

625 {
626
627 using namespace std;
628 using namespace JPP;
629
630 if( r==0 ) return x0 ;
631
632 double costheta, phi ;
633 h->GetRandom2(costheta,phi) ;
634 return x0 + r * JPosition3D(JAngle3D(acos(costheta),phi));
635 }
Data structure for angles in three dimensions.
Definition JAngle3D.hh:35
Data structure for position in three dimensions.

◆ getWeight()

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

637 {
638
639 using namespace std;
640 using namespace JPP;
641
642 if( r==0 ) return 1 ;
643
644 // check that the position is in fact on the target surface
645 const double tolerance = 1e-5 ;
646 if( fabs( pos.getDistance(x0)-r ) > tolerance*r ) {
647 return 0.0 ;
648 }
649
650 JDirection3D dir(pos-x0) ;
651 double ct = dir.getDZ() ;
652 double phi = dir.getPhi() ;
653
654 if( ct < h->GetXaxis()->GetXmin() || ct >=h->GetXaxis()->GetXmax() ) return 0.0 ;
655 if( phi< h->GetYaxis()->GetXmin() || phi>=h->GetYaxis()->GetXmax() ) return 0.0 ;
656
657 Int_t bin = h->FindBin(ct,phi) ;
658 return h->GetBinContent(bin) / (r*r) ;
659 }
Data structure for direction in three dimensions.

Member Data Documentation

◆ x0

JPosition3D JMARKOV::JSphereGenerator::x0

Definition at line 661 of file JMarkovGenerator.hh.

◆ r

double JMARKOV::JSphereGenerator::r

Definition at line 662 of file JMarkovGenerator.hh.

◆ h

TH2* JMARKOV::JSphereGenerator::h

Definition at line 663 of file JMarkovGenerator.hh.


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