GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
genie::Spline Class Reference

A numeric analysis tool class for interpolating 1-D functions. More...

#include <Spline.h>

Inheritance diagram for genie::Spline:
Inheritance graph
[legend]
Collaboration diagram for genie::Spline:
Collaboration graph
[legend]

Public Member Functions

 Spline ()
 
 Spline (string filename, string xtag="", string ytag="", bool is_xml=false)
 
 Spline (TNtupleD *ntuple, string xy, string cut="")
 
 Spline (TTree *tree, string xy, string cut="")
 
 Spline (TSQLServer *db, string query)
 
 Spline (int nentries, double x[], double y[])
 
 Spline (int nentries, float x[], float y[])
 
 Spline (const Spline &spline)
 
 Spline (const TSpline3 &spline, int nknots)
 
virtual ~Spline ()
 
bool LoadFromXmlFile (string filename, string xtag, string ytag)
 
bool LoadFromAsciiFile (string filename)
 
bool LoadFromNtuple (TNtupleD *nt, string xy, string cut="")
 
bool LoadFromTree (TTree *tr, string xy, string cut="")
 
bool LoadFromDBase (TSQLServer *db, string query)
 
bool LoadFromTSpline3 (const TSpline3 &spline, int nknots)
 
int NKnots (void) const
 
void GetKnot (int iknot, double &x, double &y) const
 
double GetKnotX (int iknot) const
 
double GetKnotY (int iknot) const
 
double XMin (void) const
 
double XMax (void) const
 
double YMax (void) const
 
double Evaluate (double x) const
 
bool IsWithinValidRange (double x) const
 
void SetName (string name)
 
string Name (void) const
 
void YCanBeNegative (bool tf)
 
void SaveAsXml (string filename, string xtag, string ytag, string name="") const
 
void SaveAsXml (ofstream &str, string xtag, string ytag, string name="") const
 
void SaveAsText (string filename, string format="%10.6f\t%10.6f") const
 
void SaveAsROOT (string filename, string name="", bool recreate=false) const
 
TGraph * GetAsTGraph (int np=500, bool xscaling=false, bool inlog=false, double fx=1., double fy=1.) const
 
TSpline3 * GetAsTSpline (void) const
 
void FindClosestKnot (double x, double &xknot, double &yknot, Option_t *opt="-+") const
 
bool ClosestKnotValueIsZero (double x, Option_t *opt="-+") const
 
void Add (const Spline &spl, double c=1)
 
void Multiply (const Spline &spl, double c=1)
 
void Divide (const Spline &spl, double c=1)
 
void Add (double a)
 
void Multiply (double a)
 
void Divide (double a)
 
void SetType (string type)
 
string GetType (void)
 
void Print (ostream &stream) const
 

Private Member Functions

void InitSpline (void)
 
void ResetSpline (void)
 
void BuildSpline (int nentries, double x[], double y[])
 

Private Attributes

string fName
 
int fNKnots
 
double fXMin
 
double fXMax
 
double fYMax
 
TSpline3 * fInterpolator
 
bool fYCanBeNegative
 
TSpline5 * fInterpolator5
 
ROOT::Math::Interpolator * fGSLInterpolator
 
string fInterpolatorType
 

Friends

ostream & operator<< (ostream &stream, const Spline &spl)
 

Detailed Description

A numeric analysis tool class for interpolating 1-D functions.

      Uses ROOT's TSpline3 for the actual interpolation and can retrieve
      function (x,y(x)) pairs from an XML file, a flat ascii file, a
      TNtuple, a TTree or an SQL database.\n

      Update May 15, 2022 IK: 
      Adding as extra interpolators TSpline5 and 
      ROOT::Math::GSLInterpolator (LINEAR, POLYNOMIAL, CSPLINE, CSPLINE_PERIODIC,
      AKIMA, AKIMA_PERIODIC)
References:
[1] GENIE docdb 297
Author
Costas Andreopoulos <c.andreopoulos cern.ch> University of Liverpool
Igor Kakorin kakor.nosp@m.in@j.nosp@m.inr.r.nosp@m.u Joint Institute for Nuclear Research
Created:
May 04, 2004
License:
Copyright (c) 2003-2024, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Definition at line 58 of file Spline.h.

Constructor & Destructor Documentation

Spline::Spline ( )

Definition at line 52 of file Spline.cxx.

References InitSpline().

53 {
54  this->InitSpline();
55 }
void InitSpline(void)
Definition: Spline.cxx:723
Spline::Spline ( string  filename,
string  xtag = "",
string  ytag = "",
bool  is_xml = false 
)

Definition at line 57 of file Spline.cxx.

References InitSpline(), LoadFromAsciiFile(), LoadFromXmlFile(), LOG, and pDEBUG.

57  :
58 TObject()
59 {
60  string fmt = (is_xml) ? "XML" : "ASCII";
61 
62  LOG("Spline", pDEBUG)
63  << "Constructing spline from data in " << fmt << " file: " << filename;
64 
65  this->InitSpline();
66 
67  if(is_xml)
68  this->LoadFromXmlFile(filename, xtag, ytag);
69  else
70  this->LoadFromAsciiFile(filename);
71 }
bool LoadFromAsciiFile(string filename)
Definition: Spline.cxx:242
bool LoadFromXmlFile(string filename, string xtag, string ytag)
Definition: Spline.cxx:155
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void InitSpline(void)
Definition: Spline.cxx:723
#define pDEBUG
Definition: Messenger.h:63
Spline::Spline ( TNtupleD *  ntuple,
string  xy,
string  cut = "" 
)

Definition at line 73 of file Spline.cxx.

References InitSpline(), LoadFromNtuple(), LOG, and pDEBUG.

73  :
74 TObject()
75 {
76  LOG("Spline", pDEBUG) << "Constructing spline from data in a TNtuple";
77 
78  this->InitSpline();
79  this->LoadFromNtuple(ntuple, var, cut);
80 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool LoadFromNtuple(TNtupleD *nt, string xy, string cut="")
Definition: Spline.cxx:253
void InitSpline(void)
Definition: Spline.cxx:723
#define pDEBUG
Definition: Messenger.h:63
Spline::Spline ( TTree *  tree,
string  xy,
string  cut = "" 
)

Definition at line 82 of file Spline.cxx.

References InitSpline(), LoadFromTree(), LOG, and pDEBUG.

82  :
83 TObject()
84 {
85  LOG("Spline", pDEBUG) << "Constructing spline from data in a TTree";
86 
87  this->InitSpline();
88  this->LoadFromTree(tree, var, cut);
89 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void InitSpline(void)
Definition: Spline.cxx:723
bool LoadFromTree(TTree *tr, string xy, string cut="")
Definition: Spline.cxx:261
#define pDEBUG
Definition: Messenger.h:63
Spline::Spline ( TSQLServer *  db,
string  query 
)

Definition at line 91 of file Spline.cxx.

References InitSpline(), LoadFromDBase(), LOG, and pDEBUG.

91  :
92 TObject()
93 {
94  LOG("Spline", pDEBUG) << "Constructing spline from data in a MySQL server";
95 
96  this->InitSpline();
97  this->LoadFromDBase(db, query);
98 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool LoadFromDBase(TSQLServer *db, string query)
Definition: Spline.cxx:299
void InitSpline(void)
Definition: Spline.cxx:723
#define pDEBUG
Definition: Messenger.h:63
Spline::Spline ( int  nentries,
double  x[],
double  y[] 
)

Definition at line 100 of file Spline.cxx.

References BuildSpline(), InitSpline(), LOG, and pDEBUG.

100  :
101 TObject()
102 {
103  LOG("Spline", pDEBUG)
104  << "Constructing spline from the arrays passed to the ctor";
105 
106  this->InitSpline();
107  this->BuildSpline(nentries, x, y);
108 }
void BuildSpline(int nentries, double x[], double y[])
Definition: Spline.cxx:750
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void InitSpline(void)
Definition: Spline.cxx:723
#define pDEBUG
Definition: Messenger.h:63
Spline::Spline ( int  nentries,
float  x[],
float  y[] 
)

Definition at line 110 of file Spline.cxx.

References BuildSpline(), InitSpline(), LOG, and pDEBUG.

110  :
111 TObject()
112 {
113  LOG("Spline", pDEBUG)
114  << "Constructing spline from the arrays passed to the ctor";
115 
116  double * dblx = new double[nentries];
117  double * dbly = new double[nentries];
118 
119  for(int i = 0; i < nentries; i++) {
120  dblx[i] = double( x[i] );
121  dbly[i] = double( y[i] );
122  }
123 
124  this->InitSpline();
125  this->BuildSpline(nentries, dblx, dbly);
126 
127  delete [] dblx;
128  delete [] dbly;
129 }
void BuildSpline(int nentries, double x[], double y[])
Definition: Spline.cxx:750
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void InitSpline(void)
Definition: Spline.cxx:723
#define pDEBUG
Definition: Messenger.h:63
Spline::Spline ( const Spline spline)

Definition at line 131 of file Spline.cxx.

References GetAsTSpline(), InitSpline(), LoadFromTSpline3(), LOG, NKnots(), and pDEBUG.

131  :
132  TObject(), fInterpolator(0)
133 {
134  LOG("Spline", pDEBUG) << "Spline copy constructor";
135  this->InitSpline();
136  this->LoadFromTSpline3( *spline.GetAsTSpline(), spline.NKnots() );
137 }
TSpline3 * GetAsTSpline(void) const
Definition: Spline.h:108
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool LoadFromTSpline3(const TSpline3 &spline, int nknots)
Definition: Spline.cxx:305
TSpline3 * fInterpolator
Definition: Spline.h:143
int NKnots(void) const
Definition: Spline.h:84
void InitSpline(void)
Definition: Spline.cxx:723
#define pDEBUG
Definition: Messenger.h:63
Spline::Spline ( const TSpline3 &  spline,
int  nknots 
)

Definition at line 139 of file Spline.cxx.

References InitSpline(), LoadFromTSpline3(), LOG, and pDEBUG.

139  :
140  TObject(), fInterpolator(0)
141 {
142  LOG("Spline", pDEBUG)
143  << "Constructing spline from the input TSpline3 object";
144  this->InitSpline();
145  this->LoadFromTSpline3( spline, nknots );
146 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool LoadFromTSpline3(const TSpline3 &spline, int nknots)
Definition: Spline.cxx:305
TSpline3 * fInterpolator
Definition: Spline.h:143
void InitSpline(void)
Definition: Spline.cxx:723
#define pDEBUG
Definition: Messenger.h:63
Spline::~Spline ( )
virtual

Definition at line 148 of file Spline.cxx.

References fGSLInterpolator, fInterpolator, and fInterpolator5.

149 {
150  if(fInterpolator) delete fInterpolator;
151  if(fInterpolator5) delete fInterpolator5;
153 }
ROOT::Math::Interpolator * fGSLInterpolator
Definition: Spline.h:146
TSpline5 * fInterpolator5
Definition: Spline.h:145
TSpline3 * fInterpolator
Definition: Spline.h:143

Member Function Documentation

void Spline::Add ( const Spline spl,
double  c = 1 
)

Definition at line 587 of file Spline.cxx.

References BuildSpline(), Evaluate(), GetKnot(), IsWithinValidRange(), LOG, NKnots(), pERROR, ResetSpline(), XMax(), and XMin().

588 {
589  // continue only if the input spline is defined at a wider x-range
590  double xmin = this->XMin();
591  double xmax = this->XMax();
592  bool ok = spl.IsWithinValidRange(xmin) && spl.IsWithinValidRange(xmax);
593  if(!ok) {
594  LOG("Spline", pERROR) << "** Can't add splines. X-range mismatch!";
595  return;
596  }
597 
598  int nknots = this->NKnots();
599  double * x = new double[nknots];
600  double * y = new double[nknots];
601 
602  for(int i=0; i<nknots; i++) {
603  this->GetKnot(i,x[i],y[i]);
604  y[i] += (c * spl.Evaluate(x[i]));
605  }
606  this->ResetSpline();
607  this->BuildSpline(nknots,x,y);
608  delete [] x;
609  delete [] y;
610 }
#define pERROR
Definition: Messenger.h:59
void BuildSpline(int nentries, double x[], double y[])
Definition: Spline.cxx:750
double Evaluate(double x) const
Definition: Spline.cxx:363
bool IsWithinValidRange(double x) const
Definition: Spline.cxx:357
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void ResetSpline(void)
Definition: Spline.cxx:742
void GetKnot(int iknot, double &x, double &y) const
Definition: Spline.cxx:326
double XMax(void) const
Definition: Spline.h:89
int NKnots(void) const
Definition: Spline.h:84
double XMin(void) const
Definition: Spline.h:88
void Spline::Add ( double  a)

Definition at line 670 of file Spline.cxx.

References a, BuildSpline(), GetKnot(), NKnots(), and ResetSpline().

671 {
672  int nknots = this->NKnots();
673  double * x = new double[nknots];
674  double * y = new double[nknots];
675 
676  for(int i=0; i<nknots; i++) {
677  this->GetKnot(i,x[i],y[i]);
678  y[i]+=a;
679  }
680  this->ResetSpline();
681  this->BuildSpline(nknots,x,y);
682  delete [] x;
683  delete [] y;
684 }
void BuildSpline(int nentries, double x[], double y[])
Definition: Spline.cxx:750
void ResetSpline(void)
Definition: Spline.cxx:742
const double a
void GetKnot(int iknot, double &x, double &y) const
Definition: Spline.cxx:326
int NKnots(void) const
Definition: Spline.h:84
void Spline::BuildSpline ( int  nentries,
double  x[],
double  y[] 
)
private

Definition at line 750 of file Spline.cxx.

References fInterpolator, fNKnots, fXMax, fXMin, fYMax, LOG, and pDEBUG.

Referenced by Add(), Divide(), LoadFromTree(), LoadFromTSpline3(), LoadFromXmlFile(), Multiply(), and Spline().

751 {
752  LOG("Spline", pDEBUG) << "Building spline...";
753 
754  double xmin = x[0]; // minimum x in spline
755  double xmax = x[nentries-1]; // maximum x in spline
756 
757  fNKnots = nentries;
758  fXMin = xmin;
759  fXMax = xmax;
760  fYMax = y[ TMath::LocMax(nentries, y) ]; // maximum y in spline
761 
762  if(fInterpolator) delete fInterpolator;
763 
764  fInterpolator = new TSpline3("spl3", x, y, nentries, "0");
765 
766  LOG("Spline", pDEBUG) << "...done building spline";
767 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
double fXMax
Definition: Spline.h:141
double fYMax
Definition: Spline.h:142
int fNKnots
Definition: Spline.h:139
TSpline3 * fInterpolator
Definition: Spline.h:143
double fXMin
Definition: Spline.h:140
#define pDEBUG
Definition: Messenger.h:63
bool Spline::ClosestKnotValueIsZero ( double  x,
Option_t *  opt = "-+" 
) const

Definition at line 561 of file Spline.cxx.

References genie::utils::math::AreEqual(), and FindClosestKnot().

Referenced by Evaluate(), and genie::PhysInteractionSelector::SelectInteraction().

562 {
563  double xknot = 0, yknot = 0;
564  this->FindClosestKnot(x, xknot, yknot, opt);
565  if(utils::math::AreEqual(yknot,0)) return true;
566  return false;
567 }
bool AreEqual(double x1, double x2)
Definition: MathUtils.cxx:236
void FindClosestKnot(double x, double &xknot, double &yknot, Option_t *opt="-+") const
Definition: Spline.cxx:534
void Spline::Divide ( const Spline spl,
double  c = 1 
)

Definition at line 637 of file Spline.cxx.

References BuildSpline(), Evaluate(), GetKnot(), IsWithinValidRange(), LOG, NKnots(), pERROR, ResetSpline(), XMax(), and XMin().

638 {
639  // continue only if the input spline is defined at a wider x-range
640  double xmin = this->XMin();
641  double xmax = this->XMax();
642  bool ok = spl.IsWithinValidRange(xmin) && spl.IsWithinValidRange(xmax);
643  if(!ok) {
644  LOG("Spline", pERROR) << "** Can't divide splines. X-range mismatch!";
645  return;
646  }
647 
648  int nknots = this->NKnots();
649  double * x = new double[nknots];
650  double * y = new double[nknots];
651 
652  for(int i=0; i<nknots; i++) {
653  this->GetKnot(i,x[i],y[i]);
654  double denom = c * spl.Evaluate(x[i]);
655  bool denom_is_zero = TMath::Abs(denom) < DBL_EPSILON;
656  if(denom_is_zero) {
657  LOG("Spline", pERROR) << "** Refusing to divide spline knot by 0";
658  delete [] x;
659  delete [] y;
660  return;
661  }
662  y[i] /= denom;
663  }
664  this->ResetSpline();
665  this->BuildSpline(nknots,x,y);
666  delete [] x;
667  delete [] y;
668 }
#define pERROR
Definition: Messenger.h:59
void BuildSpline(int nentries, double x[], double y[])
Definition: Spline.cxx:750
double Evaluate(double x) const
Definition: Spline.cxx:363
bool IsWithinValidRange(double x) const
Definition: Spline.cxx:357
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void ResetSpline(void)
Definition: Spline.cxx:742
void GetKnot(int iknot, double &x, double &y) const
Definition: Spline.cxx:326
double XMax(void) const
Definition: Spline.h:89
int NKnots(void) const
Definition: Spline.h:84
double XMin(void) const
Definition: Spline.h:88
void Spline::Divide ( double  a)

Definition at line 702 of file Spline.cxx.

References a, BuildSpline(), GetKnot(), LOG, NKnots(), pERROR, and ResetSpline().

703 {
704  bool a_is_zero = TMath::Abs(a) < DBL_EPSILON;
705  if(a_is_zero==0) {
706  LOG("Spline", pERROR) << "** Refusing to divide spline by 0";
707  return;
708  }
709  int nknots = this->NKnots();
710  double * x = new double[nknots];
711  double * y = new double[nknots];
712 
713  for(int i=0; i<nknots; i++) {
714  this->GetKnot(i,x[i],y[i]);
715  y[i]/=a;
716  }
717  this->ResetSpline();
718  this->BuildSpline(nknots,x,y);
719  delete [] x;
720  delete [] y;
721 }
#define pERROR
Definition: Messenger.h:59
void BuildSpline(int nentries, double x[], double y[])
Definition: Spline.cxx:750
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void ResetSpline(void)
Definition: Spline.cxx:742
const double a
void GetKnot(int iknot, double &x, double &y) const
Definition: Spline.cxx:326
int NKnots(void) const
Definition: Spline.h:84
double Spline::Evaluate ( double  x) const

Definition at line 363 of file Spline.cxx.

References ClosestKnotValueIsZero(), fGSLInterpolator, FindClosestKnot(), fInterpolator, fInterpolator5, fInterpolatorType, fXMax, fXMin, fYCanBeNegative, IsWithinValidRange(), LOG, pDEBUG, and pINFO.

Referenced by Add(), BuildSpectrum(), CalcTotalXSec(), genie::GMCJDriver::ComputeInteractionProbabilities(), genie::GMCJDriver::ComputeProbScales(), genie::NuclearData::DeuteriumSuppressionFactor(), Divide(), genie::GiBUURESFormFactor::FormFactors::FFRes(), genie::KineGeneratorWithCache::FindMaxXSec(), genie::AGCharm2019::GenerateCharmHadron(), GetAsTGraph(), genie::DISXSec::Integrate(), genie::HEDISXSec::Integrate(), genie::DMDISXSec::Integrate(), genie::HELeptonXSec::Integrate(), genie::AlamSimoAtharVacasSKXSec::Integrate(), genie::SPPXSec::Integrate(), genie::ReinSehgalRESXSec::Integrate(), genie::ReinSehgalRESXSecFast::Integrate(), genie::SpectralFunc1d::LoadConfig(), Multiply(), genie::CacheBranchFx::operator()(), SaveGraphsToRootFile(), genie::PhysInteractionSelector::SelectInteraction(), genie::ReinSehgalRESPXSec::XSec(), and genie::GEVGDriver::XSecSum().

364 {
365  LOG("Spline", pDEBUG) << "Evaluating spline at point x = " << x;
366  assert(!TMath::IsNaN(x));
367 
368  double y = 0;
369  if( this->IsWithinValidRange(x) ) {
370 
371  // we can interpolate within the range of spline knots - be careful with
372  // strange cubic spline behaviour when close to knots with y=0
373  bool is0p = this->ClosestKnotValueIsZero(x, "+");
374  bool is0n = this->ClosestKnotValueIsZero(x, "-");
375 
376  if(!is0p && !is0n) {
377  // both knots (on the left and right are non-zero) - just interpolate
378  LOG("Spline", pDEBUG) << "Point is between non-zero knots";
379  if (fInterpolatorType == "TSpline3")
380  y = fInterpolator->Eval(x);
381  else if (fInterpolatorType == "TSpline5")
382  y = fInterpolator5->Eval(x);
383  else
384  y = fGSLInterpolator->Eval(x);
385  } else {
386  // at least one of the neighboring knots has y=0
387  if(is0p && is0n) {
388  // both neighboring knots have y=0
389  LOG("Spline", pDEBUG) << "Point is between zero knots";
390  y=0;
391  } else {
392  // just 1 neighboring knot has y=0 - do a linear interpolation
393  LOG("Spline", pDEBUG)
394  << "Point has zero" << (is0n ? " left " : " right ") << "knot";
395  double xpknot=0, ypknot=0, xnknot=0, ynknot=0;
396  this->FindClosestKnot(x, xnknot, ynknot, "-");
397  this->FindClosestKnot(x, xpknot, ypknot, "+");
398  if(is0n) y = ypknot * (x-xnknot)/(xpknot-xnknot);
399  else y = ynknot * (x-xnknot)/(xpknot-xnknot);
400  }
401  }
402 
403  } else {
404  LOG("Spline", pDEBUG) << "x = " << x
405  << " is not within spline range [" << fXMin << ", " << fXMax << "]";
406  }
407 
408  if(y<0 && !fYCanBeNegative) {
409  LOG("Spline", pINFO) << "Negative y (" << y << ")";
410  LOG("Spline", pINFO) << "x = " << x;
411  LOG("Spline", pINFO) << "spline range [" << fXMin << ", " << fXMax << "]";
412  }
413 
414  LOG("Spline", pDEBUG) << "Spline(x = " << x << ") = " << y;
415 
416  return y;
417 }
ROOT::Math::Interpolator * fGSLInterpolator
Definition: Spline.h:146
bool fYCanBeNegative
Definition: Spline.h:144
bool ClosestKnotValueIsZero(double x, Option_t *opt="-+") const
Definition: Spline.cxx:561
bool IsWithinValidRange(double x) const
Definition: Spline.cxx:357
string fInterpolatorType
Definition: Spline.h:147
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
double fXMax
Definition: Spline.h:141
#define pINFO
Definition: Messenger.h:62
TSpline5 * fInterpolator5
Definition: Spline.h:145
TSpline3 * fInterpolator
Definition: Spline.h:143
double fXMin
Definition: Spline.h:140
void FindClosestKnot(double x, double &xknot, double &yknot, Option_t *opt="-+") const
Definition: Spline.cxx:534
#define pDEBUG
Definition: Messenger.h:63
void Spline::FindClosestKnot ( double  x,
double &  xknot,
double &  yknot,
Option_t *  opt = "-+" 
) const

Definition at line 534 of file Spline.cxx.

References fInterpolator.

Referenced by ClosestKnotValueIsZero(), and Evaluate().

536 {
537  string option(opt);
538 
539  bool pos = (option.find("+") != string::npos);
540  bool neg = (option.find("-") != string::npos);
541 
542  if(!pos && !neg) return;
543 
544  int iknot = fInterpolator->FindX(x);
545 
546  double xp=0, yp=0, xn=0, yn=0;
547  fInterpolator->GetKnot(iknot, xn,yn);
548  fInterpolator->GetKnot(iknot+1,xp,yp);
549 
550  bool p = (TMath::Abs(x-xp) < TMath::Abs(x-xn));
551 
552  if(pos&&neg) {
553  if(p) { xknot = xp; yknot = yp; }
554  else { xknot = xn; yknot = yn; }
555  } else {
556  if(pos) { xknot = xp; yknot = yp; }
557  if(neg) { xknot = xn; yknot = yn; }
558  }
559 }
TSpline3 * fInterpolator
Definition: Spline.h:143
TGraph * Spline::GetAsTGraph ( int  np = 500,
bool  xscaling = false,
bool  inlog = false,
double  fx = 1.,
double  fy = 1. 
) const

Definition at line 496 of file Spline.cxx.

References Evaluate(), fXMax, and fXMin.

Referenced by SaveToPsFile().

498 {
499  double xmin = fXMin;
500  double xmax = fXMax;
501 
502  np = TMath::Max(np,2);
503 
504  bool use_log = in_log && (fXMin>0) && (fXMax>0);
505 
506  if(use_log) {
507  xmin = TMath::Log10(xmin);
508  xmax = TMath::Log10(xmax);
509  }
510 
511  double dx = (xmax - xmin) / (np-1);
512 
513  double * x = new double[np];
514  double * y = new double[np];
515 
516  for(int i=0; i<np; i++) {
517  x[i] = ( (use_log) ? TMath::Power(10, xmin+i*dx) : xmin + i*dx );
518  y[i] = this->Evaluate( x[i] );
519 
520  // scale with x if needed
521  if (scale_with_x) y[i] /= x[i];
522 
523  // apply x,y scaling
524  y[i] *= fy;
525  x[i] *= fx;
526  }
527 
528  TGraph * graph = new TGraph(np, x, y);
529  delete[] x;
530  delete[] y;
531  return graph;
532 }
double Evaluate(double x) const
Definition: Spline.cxx:363
double fXMax
Definition: Spline.h:141
double fXMin
Definition: Spline.h:140
TSpline3* genie::Spline::GetAsTSpline ( void  ) const
inline

Definition at line 108 of file Spline.h.

References fInterpolator.

Referenced by Spline().

108 { return fInterpolator; }
TSpline3 * fInterpolator
Definition: Spline.h:143
void Spline::GetKnot ( int  iknot,
double &  x,
double &  y 
) const

Definition at line 326 of file Spline.cxx.

References fInterpolator, LOG, and pWARN.

Referenced by Add(), Divide(), Multiply(), and Print().

327 {
328  if(!fInterpolator) {
329  LOG("Spline", pWARN) << "Spline has not been built yet!";
330  return;
331  }
332  fInterpolator->GetKnot(iknot,x,y);
333 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pWARN
Definition: Messenger.h:60
TSpline3 * fInterpolator
Definition: Spline.h:143
double Spline::GetKnotX ( int  iknot) const

Definition at line 335 of file Spline.cxx.

References fInterpolator, LOG, and pWARN.

336 {
337  if(!fInterpolator) {
338  LOG("Spline", pWARN) << "Spline has not been built yet!";
339  return 0;
340  }
341  double x,y;
342  fInterpolator->GetKnot(iknot,x,y);
343  return x;
344 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pWARN
Definition: Messenger.h:60
TSpline3 * fInterpolator
Definition: Spline.h:143
double Spline::GetKnotY ( int  iknot) const

Definition at line 346 of file Spline.cxx.

References fInterpolator, LOG, and pWARN.

347 {
348  if(!fInterpolator) {
349  LOG("Spline", pWARN) << "Spline has not been built yet!";
350  return 0;
351  }
352  double x,y;
353  fInterpolator->GetKnot(iknot,x,y);
354  return y;
355 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pWARN
Definition: Messenger.h:60
TSpline3 * fInterpolator
Definition: Spline.h:143
string genie::Spline::GetType ( void  )
inline

Definition at line 122 of file Spline.h.

References fInterpolatorType.

122 { return fInterpolatorType; }
string fInterpolatorType
Definition: Spline.h:147
void Spline::InitSpline ( void  )
private

Definition at line 723 of file Spline.cxx.

References fGSLInterpolator, fInterpolator, fInterpolator5, fInterpolatorType, fName, fXMax, fXMin, fYCanBeNegative, fYMax, LOG, and pDEBUG.

Referenced by ResetSpline(), and Spline().

724 {
725  LOG("Spline", pDEBUG) << "Initializing spline...";
726 
727  fName = "genie-spline";
728  fXMin = 0.0;
729  fXMax = 0.0;
730  fYMax = 0.0;
731 
732  fInterpolator = 0;
733  fInterpolator5 = 0;
734  fGSLInterpolator = 0;
735  fInterpolatorType = "TSpline3";
736 
737  fYCanBeNegative = false;
738 
739  LOG("Spline", pDEBUG) << "...done initializing spline";
740 }
ROOT::Math::Interpolator * fGSLInterpolator
Definition: Spline.h:146
bool fYCanBeNegative
Definition: Spline.h:144
string fInterpolatorType
Definition: Spline.h:147
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
double fXMax
Definition: Spline.h:141
double fYMax
Definition: Spline.h:142
string fName
Definition: Spline.h:138
TSpline5 * fInterpolator5
Definition: Spline.h:145
TSpline3 * fInterpolator
Definition: Spline.h:143
double fXMin
Definition: Spline.h:140
#define pDEBUG
Definition: Messenger.h:63
bool Spline::IsWithinValidRange ( double  x) const

Definition at line 357 of file Spline.cxx.

References fXMax, and fXMin.

Referenced by Add(), Divide(), Evaluate(), and Multiply().

358 {
359  bool is_in_range = (fXMin <= x && x <= fXMax);
360  return is_in_range;
361 }
double fXMax
Definition: Spline.h:141
double fXMin
Definition: Spline.h:140
bool Spline::LoadFromAsciiFile ( string  filename)

Definition at line 242 of file Spline.cxx.

References LoadFromNtuple(), LOG, and pDEBUG.

Referenced by Spline().

243 {
244  LOG("Spline", pDEBUG) << "Retrieving data from file: " << filename;
245 
246  TNtupleD nt("ntuple","","x:y");
247  nt.ReadFile(filename.c_str());
248 
249  this->LoadFromNtuple(&nt, "x:y");
250  return true;
251 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool LoadFromNtuple(TNtupleD *nt, string xy, string cut="")
Definition: Spline.cxx:253
#define pDEBUG
Definition: Messenger.h:63
bool Spline::LoadFromDBase ( TSQLServer *  db,
string  query 
)

Definition at line 299 of file Spline.cxx.

References LOG, and pDEBUG.

Referenced by Spline().

300 {
301  LOG("Spline", pDEBUG) << "Retrieving data from data-base: ";
302  return false;
303 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pDEBUG
Definition: Messenger.h:63
bool Spline::LoadFromNtuple ( TNtupleD *  nt,
string  xy,
string  cut = "" 
)

Definition at line 253 of file Spline.cxx.

References LoadFromTree().

Referenced by LoadFromAsciiFile(), and Spline().

254 {
255  if(!nt) return false;
256 
257  TTree * tree = dynamic_cast<TTree *> (nt);
258  return this->LoadFromTree(tree,var,cut);
259 }
bool LoadFromTree(TTree *tr, string xy, string cut="")
Definition: Spline.cxx:261
bool Spline::LoadFromTree ( TTree *  tr,
string  xy,
string  cut = "" 
)

Definition at line 261 of file Spline.cxx.

References BuildSpline(), LOG, and pDEBUG.

Referenced by LoadFromNtuple(), and Spline().

262 {
263  LOG("Spline", pDEBUG) << "Retrieving data from tree: " << tree->GetName();
264 
265  if(!cut.size()) tree->Draw(var.c_str(), "", "GOFF");
266  else tree->Draw(var.c_str(), cut.c_str(), "GOFF");
267 
268  TH2F * hst = (TH2F*)gROOT->FindObject("htemp");
269  if(hst) { hst->SetDirectory(0); delete hst; }
270 
271  // Now, take into account that the data retrieved from the ntuple would
272  // not be sorted in x and the resulting spline will be bogus...
273  // Sort the x array, use the x-sorting to re-arrange the y array and only
274  // then build the spline..
275 
276  int n = tree->GetSelectedRows();
277 
278  int * idx = new int[n];
279  double * x = new double[n];
280  double * y = new double[n];
281 
282  TMath::Sort(n,tree->GetV1(),idx,false);
283 
284  for(int i=0; i<n; i++) {
285  int ii = idx[i];
286  x[i] = (tree->GetV1())[ii];
287  y[i] = (tree->GetV2())[ii];
288  }
289 
290  this->BuildSpline(n,x,y);
291 
292  delete [] idx;
293  delete [] x;
294  delete [] y;
295 
296  return true;
297 }
void BuildSpline(int nentries, double x[], double y[])
Definition: Spline.cxx:750
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pDEBUG
Definition: Messenger.h:63
bool Spline::LoadFromTSpline3 ( const TSpline3 &  spline,
int  nknots 
)

Definition at line 305 of file Spline.cxx.

References BuildSpline().

Referenced by Spline().

306 {
307  int nentries = nknots;
308 
309  double * x = new double[nentries];
310  double * y = new double[nentries];
311  double cx = 0, cy = 0;
312 
313  for(int i = 0; i < nentries; i++) {
314  spline.GetKnot(i, cx, cy);
315  x[i] = cx;
316  y[i] = cy;
317  }
318  this->BuildSpline(nentries, x, y);
319 
320  delete [] x;
321  delete [] y;
322 
323  return true;
324 }
void BuildSpline(int nentries, double x[], double y[])
Definition: Spline.cxx:750
bool Spline::LoadFromXmlFile ( string  filename,
string  xtag,
string  ytag 
)

Definition at line 155 of file Spline.cxx.

References BuildSpline(), genie::utils::xml::GetAttribute(), LOG, pDEBUG, pERROR, pINFO, genie::utils::str::TrimSpaces(), and genie::utils::xml::TrimSpaces().

Referenced by Spline().

156 {
157  LOG("Spline", pDEBUG) << "Retrieving data from file: " << filename;
158 
159  xmlDocPtr xml_doc = xmlParseFile(filename.c_str());
160 
161  if(xml_doc==NULL) {
162  LOG("Spline", pERROR)
163  << "XML file could not be parsed! [filename: " << filename << "]";
164  return false;
165  }
166 
167  xmlNodePtr xmlCur = xmlDocGetRootElement(xml_doc);
168 
169  if(xmlCur==NULL) {
170  LOG("Spline", pERROR)
171  << "XML doc. has null root element! [filename: " << filename << "]";
172  return false;
173  }
174  if( xmlStrcmp(xmlCur->name, (const xmlChar *) "spline") ) {
175  LOG("Spline", pERROR)
176  << "XML doc. has invalid root element! [filename: " << filename << "]";
177  return false;
178  }
179 
180  string name = utils::str::TrimSpaces(
181  utils::xml::GetAttribute(xmlCur, "name"));
182  string snkn = utils::str::TrimSpaces(
183  utils::xml::GetAttribute(xmlCur, "nknots"));
184  int nknots = atoi( snkn.c_str() );
185 
186  LOG("Spline", pINFO)
187  << "Parsing XML spline: " << name << ", nknots = " << nknots;
188 
189  int iknot = 0;
190  double * vx = new double[nknots];
191  double * vy = new double[nknots];
192 
193  xmlNodePtr xmlSplChild = xmlCur->xmlChildrenNode; // <knots>'s
194 
195  // loop over all xml tree nodes that are children of the <spline> node
196  while (xmlSplChild != NULL) {
197  LOG("Spline", pDEBUG)
198  << "Got <spline> children node: " << xmlSplChild->name;
199 
200  // enter everytime you find a <knot> tag
201  if( (!xmlStrcmp(xmlSplChild->name, (const xmlChar *) "knot")) ) {
202 
203  xmlNodePtr xmlKnotChild = xmlSplChild->xmlChildrenNode;
204 
205  // loop over all xml tree nodes that are children of this <knot>
206  while (xmlKnotChild != NULL) {
207  LOG("Spline", pDEBUG)
208  << "Got <knot> children node: " << xmlKnotChild->name;
209 
210  // enter everytime you find a <E> or a <xsec> tag
211  const xmlChar * tag = xmlKnotChild->name;
212  bool is_xtag = ! xmlStrcmp(tag,(const xmlChar *) xtag.c_str());
213  bool is_ytag = ! xmlStrcmp(tag,(const xmlChar *) ytag.c_str());
214  if (is_xtag || is_ytag) {
215  xmlNodePtr xmlValTagChild = xmlKnotChild->xmlChildrenNode;
216  string val = utils::xml::TrimSpaces(
217  xmlNodeListGetString(xml_doc, xmlValTagChild, 1));
218 
219  if (is_xtag) vx[iknot] = atof(val.c_str());
220  if (is_ytag) vy[iknot] = atof(val.c_str());
221 
222  xmlFree(xmlValTagChild);
223  LOG("Spline", pDEBUG) << "tag: " << tag << ", value: " << val;
224  }//if current tag is <E>,<xsec>
225 
226  xmlKnotChild = xmlKnotChild->next;
227  }//[end of] loop over tags within <knot>...</knot> tags
228  xmlFree(xmlKnotChild);
229  iknot++;
230  } // if <knot>
231  xmlSplChild = xmlSplChild->next;
232  } //[end of] loop over tags within <spline>...</spline> tags
233  xmlFree(xmlSplChild);
234 
235  this->BuildSpline(nknots, vx, vy);
236  delete [] vx;
237  delete [] vy;
238 
239  return true;
240 }
#define pERROR
Definition: Messenger.h:59
string TrimSpaces(xmlChar *xmls)
void BuildSpline(int nentries, double x[], double y[])
Definition: Spline.cxx:750
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pINFO
Definition: Messenger.h:62
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
const char * name
string GetAttribute(xmlNodePtr xml_cur, string attr_name)
#define pDEBUG
Definition: Messenger.h:63
void Spline::Multiply ( const Spline spl,
double  c = 1 
)

Definition at line 612 of file Spline.cxx.

References BuildSpline(), Evaluate(), GetKnot(), IsWithinValidRange(), LOG, NKnots(), pERROR, ResetSpline(), XMax(), and XMin().

613 {
614  // continue only if the input spline is defined at a wider x-range
615  double xmin = this->XMin();
616  double xmax = this->XMax();
617  bool ok = spl.IsWithinValidRange(xmin) && spl.IsWithinValidRange(xmax);
618  if(!ok) {
619  LOG("Spline", pERROR) << "** Can't multiply splines. X-range mismatch!";
620  return;
621  }
622 
623  int nknots = this->NKnots();
624  double * x = new double[nknots];
625  double * y = new double[nknots];
626 
627  for(int i=0; i<nknots; i++) {
628  this->GetKnot(i,x[i],y[i]);
629  y[i] *= (c * spl.Evaluate(x[i]));
630  }
631  this->ResetSpline();
632  this->BuildSpline(nknots,x,y);
633  delete [] x;
634  delete [] y;
635 }
#define pERROR
Definition: Messenger.h:59
void BuildSpline(int nentries, double x[], double y[])
Definition: Spline.cxx:750
double Evaluate(double x) const
Definition: Spline.cxx:363
bool IsWithinValidRange(double x) const
Definition: Spline.cxx:357
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void ResetSpline(void)
Definition: Spline.cxx:742
void GetKnot(int iknot, double &x, double &y) const
Definition: Spline.cxx:326
double XMax(void) const
Definition: Spline.h:89
int NKnots(void) const
Definition: Spline.h:84
double XMin(void) const
Definition: Spline.h:88
void Spline::Multiply ( double  a)

Definition at line 686 of file Spline.cxx.

References a, BuildSpline(), GetKnot(), NKnots(), and ResetSpline().

687 {
688  int nknots = this->NKnots();
689  double * x = new double[nknots];
690  double * y = new double[nknots];
691 
692  for(int i=0; i<nknots; i++) {
693  this->GetKnot(i,x[i],y[i]);
694  y[i]*=a;
695  }
696  this->ResetSpline();
697  this->BuildSpline(nknots,x,y);
698  delete [] x;
699  delete [] y;
700 }
void BuildSpline(int nentries, double x[], double y[])
Definition: Spline.cxx:750
void ResetSpline(void)
Definition: Spline.cxx:742
const double a
void GetKnot(int iknot, double &x, double &y) const
Definition: Spline.cxx:326
int NKnots(void) const
Definition: Spline.h:84
string genie::Spline::Name ( void  ) const
inline

Definition at line 95 of file Spline.h.

References fName.

Referenced by Print().

95 { return fName; }
string fName
Definition: Spline.h:138
int genie::Spline::NKnots ( void  ) const
inline

Definition at line 84 of file Spline.h.

References fNKnots.

Referenced by Add(), Divide(), Multiply(), Print(), SaveAsText(), SaveAsXml(), and Spline().

84 {return fNKnots;}
int fNKnots
Definition: Spline.h:139
void Spline::Print ( ostream &  stream) const

Definition at line 569 of file Spline.cxx.

References GetKnot(), Name(), NKnots(), XMax(), and XMin().

Referenced by genie::operator<<().

570 {
571  int nknots = this->NKnots();
572  double xmin = this->XMin();
573  double xmax = this->XMax();
574 
575  stream << endl;
576  stream << "** Spline: " << this->Name() << endl;
577  stream << "Has " << nknots
578  << " knots in the [" << xmin << ", " << xmax << "] range" << endl;
579  double x,y;
580  for(int i=0; i<nknots; i++) {
581  this->GetKnot(i,x,y);
582  stream << "-- knot : " << i
583  << " -> (x = " << x << ", y = " << y << ")" << endl;
584  }
585 }
void GetKnot(int iknot, double &x, double &y) const
Definition: Spline.cxx:326
double XMax(void) const
Definition: Spline.h:89
string Name(void) const
Definition: Spline.h:95
int NKnots(void) const
Definition: Spline.h:84
double XMin(void) const
Definition: Spline.h:88
void Spline::ResetSpline ( void  )
private

Definition at line 742 of file Spline.cxx.

References fGSLInterpolator, fInterpolator, fInterpolator5, and InitSpline().

Referenced by Add(), Divide(), and Multiply().

743 {
744  if(fInterpolator) delete fInterpolator;
745  if(fInterpolator5) delete fInterpolator5;
747  this->InitSpline();
748 }
ROOT::Math::Interpolator * fGSLInterpolator
Definition: Spline.h:146
TSpline5 * fInterpolator5
Definition: Spline.h:145
TSpline3 * fInterpolator
Definition: Spline.h:143
void InitSpline(void)
Definition: Spline.cxx:723
void Spline::SaveAsROOT ( string  filename,
string  name = "",
bool  recreate = false 
) const

Definition at line 485 of file Spline.cxx.

References fInterpolator, and fName.

486 {
487  string spline_name = (name.size()>0 ? name : fName);
488 
489  string opt = ( (recreate) ? "RECREATE" : "UPDATE" );
490 
491  TFile f(filename.c_str(), opt.c_str());
492  if(fInterpolator) fInterpolator->Write(spline_name.c_str());
493  f.Close();
494 }
string fName
Definition: Spline.h:138
TSpline3 * fInterpolator
Definition: Spline.h:143
const char * name
void Spline::SaveAsText ( string  filename,
string  format = "%10.6f\t%10.6f" 
) const

Definition at line 464 of file Spline.cxx.

References fInterpolator, LOG, NKnots(), and pERROR.

465 {
466  ofstream outtxt(filename.c_str());
467  if(!outtxt.is_open()) {
468  LOG("Spline", pERROR) << "Couldn't create file = " << filename;
469  return;
470  }
471  int nknots = this->NKnots();
472  outtxt << nknots << endl;
473 
474  double x=0, y=0;
475  for(int iknot = 0; iknot < nknots; iknot++) {
476  fInterpolator->GetKnot(iknot, x, y);
477  char line[1024];
478  sprintf(line,format.c_str(),x,y);
479  outtxt << line << endl;
480  }
481  outtxt << endl;
482  outtxt.close();
483 }
#define pERROR
Definition: Messenger.h:59
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
TSpline3 * fInterpolator
Definition: Spline.h:143
int NKnots(void) const
Definition: Spline.h:84
void Spline::SaveAsXml ( string  filename,
string  xtag,
string  ytag,
string  name = "" 
) const

Definition at line 419 of file Spline.cxx.

References fName, LOG, and pERROR.

Referenced by genie::XSecSplineList::SaveAsXml().

421 {
422  ofstream outxml(filename.c_str());
423  if(!outxml.is_open()) {
424  LOG("Spline", pERROR) << "Couldn't create file = " << filename;
425  return;
426  }
427  string spline_name = (name.size()>0 ? name : fName);
428 
429  this->SaveAsXml(outxml, xtag, ytag, spline_name);
430 
431  outxml << endl;
432  outxml.close();
433 }
#define pERROR
Definition: Messenger.h:59
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
string fName
Definition: Spline.h:138
void SaveAsXml(string filename, string xtag, string ytag, string name="") const
Definition: Spline.cxx:419
const char * name
void Spline::SaveAsXml ( ofstream &  str,
string  xtag,
string  ytag,
string  name = "" 
) const

Definition at line 435 of file Spline.cxx.

References fInterpolator, fName, and NKnots().

437 {
438  string spline_name = (name.size()>0 ? name : fName);
439 
440  // create a spline tag with the number of knots as an attribute
441  int nknots = this->NKnots();
442  string padding = " ";
443  ofs << padding << "<spline name=\"" << spline_name
444  << "\" nknots=\"" << nknots << "\">" << endl;
445 
446  // start printing the knots
447  double x=0, y=0;
448  for(int iknot = 0; iknot < nknots; iknot++)
449  {
450  fInterpolator->GetKnot(iknot, x, y);
451 
452  ofs << std::fixed << setprecision(5);
453  ofs << "\t<knot>"
454  << " <" << xtag << "> " << setfill(' ')
455  << setw(10) << x << " </" << xtag << ">";
456  ofs << std::scientific << setprecision(10);
457  ofs << " <" << ytag << "> " << setfill(' ')
458  << setw(10) << y << " </" << ytag << ">"
459  << " </knot>" << endl;
460  }
461  ofs << padding << "</spline>" << endl;
462 }
string fName
Definition: Spline.h:138
TSpline3 * fInterpolator
Definition: Spline.h:143
const char * name
int NKnots(void) const
Definition: Spline.h:84
void genie::Spline::SetName ( string  name)
inline

Definition at line 94 of file Spline.h.

References fName.

94 { fName = name; }
string fName
Definition: Spline.h:138
const char * name
void Spline::SetType ( string  type)

Definition at line 769 of file Spline.cxx.

References fGSLInterpolator, fInterpolator, fInterpolator5, fInterpolatorType, fNKnots, LOG, pWARN, and genie::utils::str::ToUpper().

Referenced by genie::CacheBranchFx::CreateSpline().

770 {
771  if(!fInterpolator) return;
772 
774 
775  ROOT::Math::Interpolation::Type gsltype;
776 
777  if ( fInterpolatorType == "TSPLINE3" || fInterpolatorType == "" )
778  {
779  fInterpolatorType = "TSpline3";
780  return;
781  }
782  else if ( fInterpolatorType == "TSPLINE5" )
783  {
784  fInterpolatorType = "TSpline5";
785  if(fInterpolator5) delete fInterpolator5;
786  double x[fNKnots], y[fNKnots];
787  for (int i=0; i<fNKnots; i++)
788  {
789  fInterpolator->GetKnot(i, x[i], y[i]);
790  }
791  fInterpolator5 = new TSpline5("spl5", x, y, fNKnots, "0");
792  return;
793  }
794  else if ( fInterpolatorType == "LINEAR" )
795  {
796  gsltype = ROOT::Math::Interpolation::kLINEAR;
797  }
798  else if ( fInterpolatorType == "POLYNOMIAL" )
799  {
800  gsltype = ROOT::Math::Interpolation::kPOLYNOMIAL;
801  }
802  else if ( fInterpolatorType == "CSPLINE" )
803  {
804  gsltype = ROOT::Math::Interpolation::kCSPLINE;
805  }
806  else if ( fInterpolatorType == "CSPLINE_PERIODIC" )
807  {
808  gsltype = ROOT::Math::Interpolation::kCSPLINE_PERIODIC;
809  }
810  else if ( fInterpolatorType == "AKIMA" )
811  {
812  gsltype = ROOT::Math::Interpolation::kAKIMA;
813  }
814  else if ( fInterpolatorType == "AKIMA_PERIODIC" )
815  {
816  gsltype = ROOT::Math::Interpolation::kAKIMA_PERIODIC;
817  }
818  else
819  {
820  fInterpolatorType = "TSpline3";
821  LOG("Spline", pWARN)
822  << "Unknown interpolator type. Setting it to default [TSpline3].";
823  return;
824  }
825 
827  vector<double> x(fNKnots);
828  vector<double> y(fNKnots);
829  for (int i=0; i<fNKnots; i++)
830  {
831  fInterpolator->GetKnot(i, x[i], y[i]);
832  }
833  fGSLInterpolator = new ROOT::Math::Interpolator(x, y, gsltype);
834 
835 
836 }
ROOT::Math::Interpolator * fGSLInterpolator
Definition: Spline.h:146
string fInterpolatorType
Definition: Spline.h:147
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pWARN
Definition: Messenger.h:60
int fNKnots
Definition: Spline.h:139
TSpline5 * fInterpolator5
Definition: Spline.h:145
TSpline3 * fInterpolator
Definition: Spline.h:143
string ToUpper(string input)
Definition: StringUtils.cxx:92
double genie::Spline::XMax ( void  ) const
inline

Definition at line 89 of file Spline.h.

References fXMax.

Referenced by Add(), genie::KineGeneratorWithCache::CacheMaxXSec(), Divide(), genie::KineGeneratorWithCache::FindMaxXSec(), Multiply(), and Print().

89 {return fXMax; }
double fXMax
Definition: Spline.h:141
double genie::Spline::XMin ( void  ) const
inline

Definition at line 88 of file Spline.h.

References fXMin.

Referenced by Add(), Divide(), genie::KineGeneratorWithCache::FindMaxXSec(), Multiply(), and Print().

88 {return fXMin; }
double fXMin
Definition: Spline.h:140
void genie::Spline::YCanBeNegative ( bool  tf)
inline

Definition at line 97 of file Spline.h.

References fYCanBeNegative.

97 { fYCanBeNegative = tf; }
bool fYCanBeNegative
Definition: Spline.h:144
double genie::Spline::YMax ( void  ) const
inline

Definition at line 90 of file Spline.h.

References fYMax.

90 {return fYMax; }
double fYMax
Definition: Spline.h:142

Friends And Related Function Documentation

ostream& operator<< ( ostream &  stream,
const Spline spl 
)
friend

Definition at line 45 of file Spline.cxx.

46  {
47  spl.Print(stream);
48  return stream;
49  }
void Print(ostream &stream) const
Definition: Spline.cxx:569

Member Data Documentation

ROOT::Math::Interpolator* genie::Spline::fGSLInterpolator
private

Definition at line 146 of file Spline.h.

Referenced by Evaluate(), InitSpline(), ResetSpline(), SetType(), and ~Spline().

TSpline3* genie::Spline::fInterpolator
private
TSpline5* genie::Spline::fInterpolator5
private

Definition at line 145 of file Spline.h.

Referenced by Evaluate(), InitSpline(), ResetSpline(), SetType(), and ~Spline().

string genie::Spline::fInterpolatorType
private

Definition at line 147 of file Spline.h.

Referenced by Evaluate(), GetType(), InitSpline(), and SetType().

string genie::Spline::fName
private

Definition at line 138 of file Spline.h.

Referenced by InitSpline(), Name(), SaveAsROOT(), SaveAsXml(), and SetName().

int genie::Spline::fNKnots
private

Definition at line 139 of file Spline.h.

Referenced by BuildSpline(), NKnots(), and SetType().

double genie::Spline::fXMax
private

Definition at line 141 of file Spline.h.

Referenced by BuildSpline(), Evaluate(), GetAsTGraph(), InitSpline(), IsWithinValidRange(), and XMax().

double genie::Spline::fXMin
private

Definition at line 140 of file Spline.h.

Referenced by BuildSpline(), Evaluate(), GetAsTGraph(), InitSpline(), IsWithinValidRange(), and XMin().

bool genie::Spline::fYCanBeNegative
private

Definition at line 144 of file Spline.h.

Referenced by Evaluate(), InitSpline(), and YCanBeNegative().

double genie::Spline::fYMax
private

Definition at line 142 of file Spline.h.

Referenced by BuildSpline(), InitSpline(), and YMax().


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