GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CacheBranchFx.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2024, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <c.andreopoulos \at cern.ch>
7  University of Liverpool
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 //____________________________________________________________________________
68 void CacheBranchFx::CreateSpline(string type)
69 {
70  int n = fFx.size();
71  double * x = new double[n];
72  double * y = new double[n];
73 
74  int i=0;
75  map<double,double>::const_iterator iter = fFx.begin();
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  fSpline->SetType(type);
85 
86  delete [] x;
87  delete [] y;
88 }
89 //____________________________________________________________________________
90 void CacheBranchFx::Print(ostream & stream) const
91 {
92  stream << "type: [CacheBranchFx] - nentries: " << fFx.size()
93  << " / spline: " << ((fSpline) ? "built" : "null");
94 }
95 //____________________________________________________________________________
96 double CacheBranchFx::operator () (double x) const
97 {
98  if(!fSpline) return 0;
99  else return fSpline->Evaluate(x);
100 }
101 //____________________________________________________________________________
void Print(ostream &stream) const
map< double, double > fFx
x-&gt;y map
Definition: CacheBranchFx.h:75
void SetType(string type)
Definition: Spline.cxx:769
A numeric analysis tool class for interpolating 1-D functions.
Definition: Spline.h:58
string fName
cache branch name
Definition: CacheBranchFx.h:74
void CreateSpline(string type="TSpline3")
double Evaluate(double x) const
Definition: Spline.cxx:363
void AddValues(double x, double y)
Spline * fSpline
spline y = f(x)
Definition: CacheBranchFx.h:76
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
ClassImp(CacheBranchFx)
double operator()(double x) const
A simple cache branch storing the cached data in a TNtuple.
Definition: CacheBranchFx.h:49
The TObject at the root of concrete cache branches.
Definition: CacheBranchI.h:25