CacheBranchFx.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2020, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
7  University of Liverpool & STFC Rutherford Appleton Laboratory
8 */
9 //____________________________________________________________________________
10 
12 
13 using namespace genie;
14 
16 
17 //____________________________________________________________________________
18 namespace genie
19 {
20  ostream & operator << (ostream & stream, const CacheBranchFx & cbntp)
21  {
22  cbntp.Print(stream);
23  return stream;
24  }
25 }
26 //____________________________________________________________________________
29 {
30  this->Init();
31 }
32 //____________________________________________________________________________
35 {
36  this->Init();
37  fName = name;
38 }
39 //____________________________________________________________________________
41 {
42  this->CleanUp();
43 }
44 //____________________________________________________________________________
46 {
47  fName = "";
48  fSpline = 0;
49 }
50 //____________________________________________________________________________
52 {
53  if(fSpline) delete fSpline;
54  fFx.clear();
55 }
56 //____________________________________________________________________________
58 {
59  this->CleanUp();
60  this->Init();
61 }
62 //____________________________________________________________________________
63 void CacheBranchFx::AddValues(double x, double y)
64 {
65  fFx.insert(map<double,double>::value_type(x,y));
66 }
67 //____________________________________________________________________________
69 {
70  int n = fFx.size();
71  double * x = new double[n];
72  double * y = new double[n];
73 
74  int i=0;
76  for( ; iter !=fFx.end(); ++iter) {
77  x[i] = iter->first;
78  y[i] = iter->second;
79  i++;
80  }
81 
82  if(fSpline) delete fSpline;
83  fSpline = new Spline(n,x,y);
84 
85  delete [] x;
86  delete [] y;
87 }
88 //____________________________________________________________________________
89 void CacheBranchFx::Print(ostream & stream) const
90 {
91  stream << "type: [CacheBranchFx] - nentries: " << fFx.size()
92  << " / spline: " << ((fSpline) ? "built" : "null");
93 }
94 //____________________________________________________________________________
95 double CacheBranchFx::operator () (double x) const
96 {
97  if(!fSpline) return 0;
98  else return fSpline->Evaluate(x);
99 }
100 //____________________________________________________________________________
static QCString name
Definition: declinfo.cpp:673
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
void Print(ostream &stream) const
map< double, double > fFx
x->y map
Definition: CacheBranchFx.h:63
A numeric analysis tool class for interpolating 1-D functions.
Definition: Spline.h:46
string fName
cache branch name
Definition: CacheBranchFx.h:62
intermediate_table::const_iterator const_iterator
double Evaluate(double x) const
Definition: Spline.cxx:361
void AddValues(double x, double y)
std::void_t< T > n
Spline * fSpline
spline y = f(x)
Definition: CacheBranchFx.h:64
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
ClassImp(CacheBranchFx)
double operator()(double x) const
list x
Definition: train.py:276
A simple cache branch storing the cached data in a TNtuple.
Definition: CacheBranchFx.h:37
The TObject at the root of concrete cache branches.
Definition: CacheBranchI.h:25