CbmRoot
PMesh.cxx
Go to the documentation of this file.
1 #
2 // Small linear mesh to substitute the array from PData
3 // The mesh is inherited from TF1, and allow to use
4 // mesh->Draw()
5 //
6 //
7 // Author: I. Froehlich
8 // Written: 7.05.2007
9 // Revised:
10 //
12 
13 
14 #include "PMesh.h"
15 #include "TH1.h"
16 #include "TROOT.h"
17 #include "TVirtualPad.h"
18 #include <iostream>
19 
20 using namespace std;
21 
22 PMesh::PMesh(Int_t psize, const Char_t* name) : TF1(name, "0", 0, 1) {
23  // Copied from TF1 constructor...
24  SetName(name);
25  fNpar = 0;
26 
27  fXmin = 0.;
28  fXmax = 0.;
29 
30  fNpx = psize - 1;
31 
32 #if (ROOT_VERSION_CODE >= ROOT_VERSION(6, 12, 0))
33  fType = static_cast<TF1::EFType>(0);
34 #else
35  fType = 0;
36 #endif
37 
38  // fFunction = 0;
39  fNdim = 1;
40 
41  if (psize <= 0) {
42  cout << "PMesh::PMesh: size " << psize << " not allowed" << endl;
43  td = nullptr;
44  }
45  td = new Double_t[psize];
46  size = psize;
47  max = 0.;
48  min = 0.;
49 }
50 
52  if (td) delete[] td;
53 };
54 
55 Double_t PMesh::EvalPar(const Double_t* x, const Double_t* /*params*/) {
56  return Eval(x[0]);
57 }
58 
59 Double_t
60 PMesh::Eval(Double_t x, Double_t /*y*/, Double_t /*z*/, Double_t /*t*/) const {
61  return GetLinearIP(x);
62 }
63 
64 void PMesh::SetNode(Int_t node, Double_t v) {
65  if ((node >= size) || (node < 0)) return;
66  td[node] = v;
67 };
68 
69 Double_t PMesh::GetNode(Int_t node) {
70  if ((node >= size) || (node < 0)) return 0;
71  return td[node];
72 };
73 
74 void PMesh::Print(const Option_t* /*delme*/) const {
75  cout << "Min: " << min << endl;
76  cout << "Max: " << max << endl;
77  cout << "Size: " << size << endl;
78  TF1::Print();
79 }
80 
81 Double_t PMesh::GetLinearIP(Double_t m) const {
82  if ((m > min) && (m < max)) {
83  Double_t dm = (max - min) / (size - 1.);
84 
85  int bin = int((m - min) / dm);
86 
87  double mlow = min + bin * dm, mup = mlow + dm, wlow = td[bin],
88  wup = td[bin + 1];
89  return ((mup * wlow - mlow * wup) + m * (wup - wlow)) / dm;
90  }
91  //catch NAN
92  return 0; // mass out of bounds
93 };
PMesh::SetNode
void SetNode(Int_t node, Double_t v)
Definition: PMesh.cxx:64
PMesh::max
Double_t max
Definition: PMesh.h:17
PMesh::min
Double_t min
Definition: PMesh.h:17
PMesh.h
PMesh::td
Double_t * td
Definition: PMesh.h:16
PMesh::Print
void Print(const Option_t *) const
Definition: PMesh.cxx:74
PMesh::EvalPar
Double_t EvalPar(const Double_t *x, const Double_t *params)
Definition: PMesh.cxx:55
PMesh::GetNode
Double_t GetNode(Int_t node)
Definition: PMesh.cxx:69
PMesh::Eval
Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Definition: PMesh.cxx:60
PMesh::GetLinearIP
Double_t GetLinearIP(Double_t m) const
Definition: PMesh.cxx:81
v
__m128 v
Definition: L1/vectors/P4_F32vec4.h:1
PMesh::PMesh
PMesh(Int_t size, const Char_t *name)
Definition: PMesh.cxx:22
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
m
__m128 m
Definition: L1/vectors/P4_F32vec4.h:26
PMesh::~PMesh
~PMesh()
Definition: PMesh.cxx:51
PMesh::size
Int_t size
Definition: PMesh.h:18