CbmRoot
Loading...
Searching...
No Matches
PMesh.cxx
Go to the documentation of this file.
1/* Copyright (C) 2007-2019 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: I. Froehlich, Florian Uhlig [committer] */
4
5// Small linear mesh to substitute the array from PData
6// The mesh is inherited from TF1, and allow to use
7// mesh->Draw()
8
9// Written: 7.05.2007
10
11#include "PMesh.h"
12
13#include "TH1.h"
14#include "TROOT.h"
15#include "TVirtualPad.h"
16
17#include <iostream>
18
19using namespace std;
20
21PMesh::PMesh(Int_t psize, const Char_t* name) : TF1(name, "0", 0, 1)
22{
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{
53 if (td) delete[] td;
54};
55
56Double_t PMesh::EvalPar(const Double_t* x, const Double_t* /*params*/) { return Eval(x[0]); }
57
58Double_t PMesh::Eval(Double_t x, Double_t /*y*/, Double_t /*z*/, Double_t /*t*/) const { return GetLinearIP(x); }
59
60void PMesh::SetNode(Int_t node, Double_t v)
61{
62 if ((node >= size) || (node < 0)) return;
63 td[node] = v;
64};
65
66Double_t PMesh::GetNode(Int_t node)
67{
68 if ((node >= size) || (node < 0)) return 0;
69 return td[node];
70};
71
72void PMesh::Print(const Option_t* /*delme*/) const
73{
74 cout << "Min: " << min << endl;
75 cout << "Max: " << max << endl;
76 cout << "Size: " << size << endl;
77 TF1::Print();
78}
79
80Double_t PMesh::GetLinearIP(Double_t m) const
81{
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], wup = td[bin + 1];
88 return ((mup * wlow - mlow * wup) + m * (wup - wlow)) / dm;
89 }
90 //catch NAN
91 return 0; // mass out of bounds
92};
fscal v[fmask::Size]
Definition KfSimdPseudo.h:4
Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Definition PMesh.cxx:58
Double_t * td
Definition PMesh.h:16
Int_t size
Definition PMesh.h:18
Double_t GetNode(Int_t node)
Definition PMesh.cxx:66
void SetNode(Int_t node, Double_t v)
Definition PMesh.cxx:60
void Print(const Option_t *) const
Definition PMesh.cxx:72
PMesh(Int_t size, const Char_t *name)
Definition PMesh.cxx:21
~PMesh()
Definition PMesh.cxx:51
Double_t GetLinearIP(Double_t m) const
Definition PMesh.cxx:80
Double_t EvalPar(const Double_t *x, const Double_t *params)
Definition PMesh.cxx:56
Double_t min
Definition PMesh.h:17
Hash for CbmL1LinkKey.