KaliVeda
Toolkit for HIC analysis
KVCalibrator.h
1 #ifndef __KV_CALIBRATOR__
2 #define __KV_CALIBRATOR__
3 
4 #include "KVBase.h"
5 #include "TRef.h"
6 #include "KVDetector.h"
7 #include "TF1.h"
8 #include "KVValueRange.h"
9 
56 
99 class KVCalibrator: public KVBase {
100 
110 
111 protected:
113  {
116  fCalibFunc = f;
117  }
119  {
120  return fCalibFunc;
121  }
123  {
128 
129  int status;
130  Double_t res = ProtectedGetX(fCalibFunc, x, status); // fCalibFunc->GetX(x);
131  fInversionFail = (status != 0);
132  return res;
133  }
134  bool in_range(double X, double Xmin, double Xmax)
135  {
137  return (X >= Xmin) && (X <= Xmax);
138  }
140 public:
142  : KVBase("Calibrator", "KVCalibrator"), fDetector(nullptr), fCalibFunc(nullptr), fReady(kFALSE), fUseInverseFunction(kFALSE), fInputMin(99), fInputMax(-1), fInversionFail(kFALSE) {}
143  KVCalibrator(const TString& formula, const TString& type)
144  : KVBase("Calibrator", type), fDetector(nullptr), fCalibFunc(new TF1("KVCalibrator::fCalibFunc", formula)), fReady(kFALSE), fUseInverseFunction(kFALSE), fInputMin(99), fInputMax(-1), fInversionFail(kFALSE)
145  {
147  }
148  virtual ~KVCalibrator()
149  {
151  }
152 
154  {
156  return (fCalibFunc ? fCalibFunc->GetNpar() : 0);
157  }
158  void SetParameter(int i, Double_t par_val) const
159  {
160  if (fCalibFunc) fCalibFunc->SetParameter(i, par_val);
161  }
162  Double_t GetParameter(int i) const
163  {
164  return (fCalibFunc ? fCalibFunc->GetParameter(i) : 0);
165  }
166  void SetStatus(Bool_t ready)
167  {
168  fReady = ready;
169  if (ready)
170  if (IsUseInverseFunction())
172  }
174  {
175  return fReady;
176  }
177  virtual void Print(Option_t* opt = "") const;
178  virtual void Reset()
179  {
180  for (Int_t i = 0; i < GetNumberParams(); i++) {
181  SetParameter(i, 0.0);
182  }
183  SetStatus(kFALSE);
184  }
185  virtual Double_t Compute(Double_t x, const KVNameValueList&) const
186  {
188 
190  }
191  virtual Double_t Invert(Double_t x, const KVNameValueList&) const
192  {
194 
196  }
198  {
200  return Compute(x, par);
201  }
202  virtual Bool_t IsAvailableFor(const KVNameValueList&) const
203  {
209 
210  return kTRUE;
211  }
212 
213  static KVCalibrator* MakeCalibrator(const Char_t* type);
214 
215  virtual void SetOptions(const KVNameValueList&);
216  void SetInputSignalType(const TString& type)
217  {
218  fInputSignal = type;
219  }
220  void SetOutputSignalType(const TString& type)
221  {
223  }
225  {
226  return fInputSignal;
227  }
229  {
230  return fOutputSignal;
231  }
233  {
234  fDetector = d;
235  }
237  {
238  return fDetector;
239  }
240 
241  void SetUseInverseFunction(Bool_t yes = kTRUE)
242  {
245  fUseInverseFunction = yes;
246  }
248  {
251  return fUseInverseFunction;
252  }
254  {
257  return fInversionFail;
258  }
259 
260  TGraph* GetGraphOfCalibration(int npts, KVValueRange<double> input_range, const KVNameValueList& par = "");
261 
262  ClassDef(KVCalibrator, 2)//Base class for calibration of detectors
263 };
264 
265 #endif
int Int_t
#define SafeDelete(p)
#define d(i)
#define f(i)
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
#define ClassDef(name, id)
#define X(type, name)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Base class for KaliVeda framework.
Definition: KVBase.h:142
Double_t ProtectedGetX(const TF1 *func, Double_t val, int &status, Double_t xmin=0.0, Double_t xmax=0.0) const
Definition: KVBase.cpp:1691
Base class for all detector calibrations.
Definition: KVCalibrator.h:99
Double_t operator()(Double_t x, const KVNameValueList &par="")
Definition: KVCalibrator.h:197
TF1 * GetCalibFunction() const
Definition: KVCalibrator.h:118
KVDetector * GetDetector() const
Definition: KVCalibrator.h:236
void adjust_range_of_inverse_calibration()
void SetCalibFunction(TF1 *f)
Definition: KVCalibrator.h:112
void SetUseInverseFunction(Bool_t yes=kTRUE)
Definition: KVCalibrator.h:241
virtual Double_t Invert(Double_t x, const KVNameValueList &) const
Definition: KVCalibrator.h:191
Bool_t fReady
= kTRUE if calibration formula & parameters have been set up
Definition: KVCalibrator.h:103
Bool_t GetStatus() const
Definition: KVCalibrator.h:173
Bool_t fInversionFail
problem inverting calibration function
Definition: KVCalibrator.h:109
Int_t GetNumberParams() const
Definition: KVCalibrator.h:153
Double_t fInputMin
required minimum input signal for inverse calibration
Definition: KVCalibrator.h:107
virtual ~KVCalibrator()
Definition: KVCalibrator.h:148
virtual void Reset()
Definition: KVCalibrator.h:178
virtual Bool_t IsAvailableFor(const KVNameValueList &) const
Definition: KVCalibrator.h:202
virtual void SetOptions(const KVNameValueList &)
void SetParameter(int i, Double_t par_val) const
Definition: KVCalibrator.h:158
Double_t do_inversion(Double_t x) const
Definition: KVCalibrator.h:122
virtual Double_t Compute(Double_t x, const KVNameValueList &) const
Definition: KVCalibrator.h:185
void SetStatus(Bool_t ready)
Definition: KVCalibrator.h:166
TGraph * GetGraphOfCalibration(int npts, KVValueRange< double > input_range, const KVNameValueList &par="")
TF1 * fCalibFunc
calibration function
Definition: KVCalibrator.h:102
Double_t GetParameter(int i) const
Definition: KVCalibrator.h:162
virtual void Print(Option_t *opt="") const
Print a description of the calibration object, including a list of its parameters.
Double_t fInputMax
required maximum input signal for inverse calibration
Definition: KVCalibrator.h:108
KVCalibrator(const TString &formula, const TString &type)
Definition: KVCalibrator.h:143
TString GetInputSignalType() const
Definition: KVCalibrator.h:224
TString fOutputSignal
type of output calibrated signal
Definition: KVCalibrator.h:105
void SetOutputSignalType(const TString &type)
Definition: KVCalibrator.h:220
void SetDetector(KVDetector *d)
Definition: KVCalibrator.h:232
void SetInputSignalType(const TString &type)
Definition: KVCalibrator.h:216
TString GetOutputSignalType() const
Definition: KVCalibrator.h:228
KVDetector * fDetector
associated detector
Definition: KVCalibrator.h:101
Bool_t fUseInverseFunction
true if inverse i.e. TF1::GetX should be used for Compute()
Definition: KVCalibrator.h:106
TString fInputSignal
type of signal used as input
Definition: KVCalibrator.h:104
Bool_t InversionFailure() const
Definition: KVCalibrator.h:253
Bool_t IsUseInverseFunction() const
Definition: KVCalibrator.h:247
static KVCalibrator * MakeCalibrator(const Char_t *type)
bool in_range(double X, double Xmin, double Xmax)
Definition: KVCalibrator.h:134
Base class for detector geometry description.
Definition: KVDetector.h:160
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
Range of values specified by minimum, maximum.
Definition: KVValueRange.h:18
virtual Double_t GetParameter(const TString &name) const
virtual Int_t GetNpar() const
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
virtual void SetParameter(const TString &name, Double_t value)
Double_t x[n]