xsec_vs_energy Class Reference

#include <neugen3_dummy.h>

List of all members.

Public Member Functions

 xsec_vs_energy ()
 xsec_vs_energy (int nentries, double E[], double xsec[])
 xsec_vs_energy (const xsec_vs_energy *xs)
 ~xsec_vs_energy ()
void load_from_file (const char *filename)
double xsec (double E) const
TGraph * get_as_graph (int npoints=100, bool scale_with_e=false) const
void build_spline (int nentries, double E[], double xsec[])
double E_min (void) const
double E_max (void) const

Private Member Functions

void init (void)

Private Attributes

TSpline3 * _interpolator
pair< double, double > _validity_range

Detailed Description

____________________________________________________________________________

Definition at line 34 of file neugen3_dummy.h.


Constructor & Destructor Documentation

xsec_vs_energy::xsec_vs_energy (  ) 

Definition at line 21 of file xsec_vs_energy.cxx.

References init().

00022 {
00023   init();
00024 }

xsec_vs_energy::xsec_vs_energy ( int  nentries,
double  E[],
double  xsec[] 
)

Definition at line 26 of file xsec_vs_energy.cxx.

References build_spline(), and init().

00027 {
00028   init();
00029 
00030   build_spline(nentries, E, xsec);
00031 }

xsec_vs_energy::xsec_vs_energy ( const xsec_vs_energy xs  ) 

Definition at line 33 of file xsec_vs_energy.cxx.

References _interpolator, _validity_range, nentries, and xsec().

00034 {
00035   _validity_range.first  = xs->_validity_range.first;
00036   _validity_range.second = xs->_validity_range.second;
00037 
00038   // TSpline3 copy ctor was made protected (was dangerous anyway
00039   // since it did a shallow copy and thus shared underlying data)
00040   //_interpolator = new TSpline3( *(xs->_interpolator) );
00041   // effectively do the copy ctor
00042   int nentries = xs->_interpolator->GetNpx();
00043   double* E    = new double[nentries];
00044   double* xsec = new double[nentries];
00045   for (int i=0; i<nentries; ++i)
00046     xs->_interpolator->GetKnot(i,E[i],xsec[i]);
00047   _interpolator = new TSpline3("spl3",E,xsec,nentries,"0",
00048                                _validity_range.first,
00049                                _validity_range.second);
00050   delete [] E;
00051   delete [] xsec;
00052 }

xsec_vs_energy::~xsec_vs_energy (  ) 

Definition at line 54 of file xsec_vs_energy.cxx.

References _interpolator.

00055 {
00056   if(_interpolator) delete _interpolator;
00057 }


Member Function Documentation

void xsec_vs_energy::build_spline ( int  nentries,
double  E[],
double  xsec[] 
)

Definition at line 74 of file xsec_vs_energy.cxx.

References _interpolator, _validity_range, E_max(), and E_min().

Referenced by load_from_file(), and xsec_vs_energy().

00075 {
00076   double E_min = E[ TMath::LocMin(nentries, E) ]; // minimum energy in spline
00077   double E_max = E[ TMath::LocMax(nentries, E) ]; // maximum energy in spline
00078   
00079   _validity_range.first  = E_min;
00080   _validity_range.second = E_max;
00081 
00082   if(_interpolator) delete _interpolator;
00083       
00084   _interpolator = new TSpline3("spl3", E, xsec, nentries, "0", E_min, E_max);
00085 }

double xsec_vs_energy::E_max ( void   )  const [inline]

Definition at line 38 of file xsec_vs_energy.h.

References _validity_range.

Referenced by build_spline(), and get_as_graph().

00038 { return _validity_range.second; }

double xsec_vs_energy::E_min ( void   )  const [inline]

Definition at line 37 of file xsec_vs_energy.h.

References _validity_range.

Referenced by build_spline(), and get_as_graph().

00037 { return _validity_range.first;  }

TGraph * xsec_vs_energy::get_as_graph ( int  npoints = 100,
bool  scale_with_e = false 
) const

Definition at line 96 of file xsec_vs_energy.cxx.

References _validity_range, E_max(), E_min(), and xsec().

00097 {
00098   double E_min = _validity_range.first;
00099   double E_max = _validity_range.second;
00100 
00101   if(npoints < 2) npoints = 2;
00102   
00103   double dE = (E_max - E_min) / (npoints-1);
00104 
00105   double * E  = new double[npoints];
00106   double * xs = new double[npoints];
00107 
00108   for(int i=0; i<npoints; i++) {
00109     
00110       E[i]  = E_min + i*dE;
00111       xs[i] = xsec( E[i] );
00112 
00113       if (scale_with_e) xs[i] /= E[i];
00114   }
00115 
00116   TGraph * graph = new TGraph(npoints, E, xs);
00117 
00118   //delete [] E;
00119   //delete [] xs;
00120     
00121   return graph;  
00122 }

void xsec_vs_energy::init ( void   )  [private]

Definition at line 124 of file xsec_vs_energy.cxx.

References _interpolator, and _validity_range.

Referenced by xsec_vs_energy().

00125 {
00126   _validity_range.first  = 0;
00127   _validity_range.second = 0;
00128 
00129   _interpolator = 0;
00130 }

void xsec_vs_energy::load_from_file ( const char *  filename  ) 

Definition at line 59 of file xsec_vs_energy.cxx.

References build_spline(), nentries, and xsec().

Referenced by nulook_wrapper::run().

00060 {
00061   TNtuple nt("ntuple","xsec vs energy","energy:xsec");
00062 
00063   nt.ReadFile(filename);
00064 
00065   nt.Draw("energy:xsec","","GOFF"); // select all entries - graphics off
00066   
00067   int nentries   = nt.GetSelectedRows();
00068   double * energy = nt.GetV1();
00069   double * xsec   = nt.GetV2();
00070 
00071   build_spline(nentries, energy, xsec);
00072 }

double xsec_vs_energy::xsec ( double  E  )  const

Definition at line 87 of file xsec_vs_energy.cxx.

References _interpolator, and _validity_range.

Referenced by get_as_graph(), load_from_file(), and xsec_vs_energy().

00088 {
00089   // check for E_min < E < E_max
00090   bool is_in_range = (_validity_range.first < E && E < _validity_range.second);
00091   
00092   if(is_in_range) return _interpolator->Eval(E);
00093   else            return -1;                                                
00094 }


Member Data Documentation

TSpline3* xsec_vs_energy::_interpolator [private]

Definition at line 44 of file xsec_vs_energy.h.

Referenced by build_spline(), init(), xsec(), xsec_vs_energy(), and ~xsec_vs_energy().

pair<double, double> xsec_vs_energy::_validity_range [private]

Definition at line 45 of file xsec_vs_energy.h.

Referenced by build_spline(), E_max(), E_min(), get_as_graph(), init(), xsec(), and xsec_vs_energy().


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

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1