Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JFitToT.hh
Go to the documentation of this file.
1#ifndef __JCALIBRATE__JFITTOT__
2#define __JCALIBRATE__JFITTOT__
3
4#include <limits>
5
6#include "TMath.h"
7#include "TString.h"
8#include "TF1.h"
9#include "TH1.h"
10#include "TFitResult.h"
11
12#include "JLang/JException.hh"
13
14#include "JTools/JRange.hh"
15
18
19#include "JROOT/JMinimizer.hh"
20#include "JROOT/JRootToolkit.hh"
21
22
23/**
24 * \author mkarel, bjung
25 */
26
27namespace JCALIBRATE {}
28namespace JPP { using namespace JCALIBRATE; }
29
30namespace JCALIBRATE {
31
32 using JTOOLS::JRange;
36
37 static const std::string FITTOT_SUFFIX = ".1ToT";
38 static const std::string FITTOT_FNAME = "fittot";
39
40 static const char* FITTOT_GAIN_PARNAME = "gain";
41 static const char* FITTOT_GAINSPREAD_PARNAME = "gainSpread";
42 static const char* FITTOT_NORMALIZATION_PARNAME = "normalization";
43
44 static const double FITTOT_GAIN_MIN = 0.25; //!< Default minimal gain
45 static const double FITTOT_GAIN_MAX = 3.00; //!< Default maximal gain
46
47 static const double FITTOT_GAINSPREAD_MIN = 0.05; //!< Default minimal gain spread
48 static const double FITTOT_GAINSPREAD_MAX = 2.00; //!< Default maximal gain spread
49
50
51 /**
52 * Fit parameters for two-fold coincidence rate due to K40.
53 */
55 /**
56 * Constructor.
57 *
58 * \param parameters PMT parameters
59 */
60 JFitToTParameters(const JPMTParameters& parameters) :
61 gain (parameters.gain),
62 gainSpread (parameters.gainSpread),
63 normalization (1.0)
64 {}
65
66
67 /**
68 * Copy constructor.
69 *
70 * \param data data
71 */
72 JFitToTParameters(const Double_t* data) :
73 gain (0.0),
74 gainSpread (0.0),
75 normalization (1.0)
76 {
77 if (data != NULL) {
79 }
80 }
81
82
83 /**
84 * Get number of model parameters.
85 *
86 * \return number of parameters
87 */
89 {
90 return sizeof(JFitToTParameters) / sizeof(Double_t);
91 }
92
93
94 /**
95 * Get model parameters.
96 *
97 * \return pointer to parameters
98 */
99 const Double_t* getModelParameters() const
100 {
101 return &this->gain;
102 }
103
104
105 /**
106 * Get model parameters.
107 *
108 * \return pointer to parameters
109 */
111 {
112 return &this->gain;
113 }
114
115
116 /**
117 * Set model parameter.
118 *
119 * \param i parameter index
120 * \param value parameter value
121 */
122 void setModelParameter(const int i, const Double_t value)
123 {
124 getModelParameters()[i] = value;
125 }
126
127
128 /**
129 * Set model parameters.
130 *
131 * \param data pointer to parameters
132 */
133 void setModelParameters(const Double_t* data)
134 {
135 for (Int_t i = 0; i != getNumberOfModelParameters(); ++i) {
136 setModelParameter(i, data[i]);
137 }
138 }
139
140
141 /**
142 * Get model parameter.
143 *
144 * \param i parameter index
145 * \return parameter value
146 */
147 const Double_t getModelParameter(const int i) const
148 {
149 return getModelParameters()[i];
150 }
151
152
153 /**
154 * Get model parameter.
155 *
156 * \param p pointer to data member
157 * \return parameter index and value
158 */
160 {
161 const Int_t i = &(this->*p) - getModelParameters();
162
164 }
165
166
167 // fit parameters
168
169 Double_t gain; //!< PMT gain
170 Double_t gainSpread; //!< PMT gain spread
172 };
173
174
175 /**
176 * Parametrisation of time-over-threshold distribution.
177 *
178 * Note that for use in ROOT fit operations, the member method JFitToT::getValue is static.\n
179 */
180 struct JFitToT :
181 public TF1,
182 public JFitToTParameters
183 {
184
185 /**
186 * Constructor.
187 *
188 * \param parameters parameters
189 * \param range abscissa range
190 */
191 JFitToT(const JPMTParameters& parameters, const JRange<double>& range) :
192
193 TF1(FITTOT_FNAME.c_str(),
194 this,
196 range.getLowerLimit(),
197 range.getUpperLimit(),
199
200 JFitToTParameters(parameters),
201
202 cpu(parameters)
203 {}
204
205
206 /**
207 * Access method for the analogue signal processor
208 *
209 * \return reference to analogue signal processor
210 */
212 {
213 return cpu;
214 }
215
216
217 /**
218 * Fit histogram.
219 *
220 * Note that the PMT parameters which are part of the model are reset before the fit according the status of each PMT and
221 * the obtained fit parameters are copied back to the model parameters after the fit.
222 *
223 * \param h1 ROOT 1D-histogram
224 * \param option fit option
225 * \return fit result
226 */
227 TFitResultPtr operator()(TH1& h1, const std::string& option)
228 {
229 using namespace std;
230 using namespace JPP;
231
232 // Set initial gain and gain-spread
233 const Int_t Ngain = this->getModelParameter(&JFitToT::JFitToTParameters::gain);
234 const Int_t NgainSpread = this->getModelParameter(&JFitToT::JFitToTParameters::gainSpread);
235 const Int_t Nnormalization = this->getModelParameter(&JFitToT::JFitToTParameters::normalization);
236
237 SetParName(Ngain, MAKE_CSTRING(FITTOT_GAIN_PARNAME));
238 SetParName(NgainSpread, MAKE_CSTRING(FITTOT_GAINSPREAD_PARNAME));
239 SetParName(Nnormalization, MAKE_CSTRING(FITTOT_NORMALIZATION_PARNAME));
240
241 normalization = h1.Integral(h1.FindBin(this->GetXmin()),
242 h1.FindBin(this->GetXmax()));
243
244 SetParameters(getModelParameters());
245 FixParameter(Nnormalization, normalization);
246
247 for (Int_t i = 0; i != GetNpar(); ++i) {
248 SetParError(i, 0.0);
249 }
250
251 // Fit histogram
252 const TFitResultPtr result = h1.Fit(this, option.c_str());
253
254 this->setModelParameters(this->GetParameters());
255
256 cpu.gain = getModelParameter(Ngain);
257 cpu.gainSpread = getModelParameter(NgainSpread);
258
259 return result;
260 }
261
262
263 /**
264 * Get rate as a function of the fit parameters.
265 *
266 * \param x pointer to abscissa values
267 * \param par pointer to parameter values
268 * \return rate distribution at specified time-over-threshold [Hz/ns]
269 */
270 Double_t getValue(const Double_t* x, const Double_t* par)
271 {
272 const double tot_ns = x[0];
273
274 // Set new parameter values
275 cpu.gain = par[0];
276 cpu.gainSpread = par[1];
277
278 // Determine normalization factor
279 const int NPE = 1;
280 const double Whist = par[2];
281 const double Wpdf = cpu.getIntegralOfTimeOverThresholdProbability(GetXmin(), GetXmax(), NPE);
282
283 return (Wpdf > 0.0 ? (Whist / Wpdf) : Whist) * cpu.getTimeOverThresholdProbability(tot_ns, NPE);
284 }
285
286 private:
287
288 using TF1::operator();
289
291 };
292}
293
294#endif
Exceptions.
PMT analogue signal processor.
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:72
Auxiliary class to define a range between two values.
Data structure for PMT parameters.
double gainSpread
gain spread [unit]
Range of values.
Definition JRange.hh:42
Auxiliary classes and methods for PMT calibration.
static const double FITTOT_GAINSPREAD_MAX
Default maximal gain spread.
Definition JFitToT.hh:48
static const std::string FITTOT_FNAME
Definition JFitToT.hh:38
static const std::string FITTOT_SUFFIX
Definition JFitToT.hh:37
static const char * FITTOT_GAIN_PARNAME
Definition JFitToT.hh:40
static const char * FITTOT_NORMALIZATION_PARNAME
Definition JFitToT.hh:42
static const double FITTOT_GAIN_MAX
Default maximal gain.
Definition JFitToT.hh:45
static const char * FITTOT_GAINSPREAD_PARNAME
Definition JFitToT.hh:41
static const double FITTOT_GAIN_MIN
Default minimal gain.
Definition JFitToT.hh:44
static const double FITTOT_GAINSPREAD_MIN
Default minimal gain spread.
Definition JFitToT.hh:47
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Fit parameters for two-fold coincidence rate due to K40.
Definition JFitToT.hh:54
const Double_t * getModelParameters() const
Get model parameters.
Definition JFitToT.hh:99
void setModelParameters(const Double_t *data)
Set model parameters.
Definition JFitToT.hh:133
JFitToTParameters(const Double_t *data)
Copy constructor.
Definition JFitToT.hh:72
static Int_t getNumberOfModelParameters()
Get number of model parameters.
Definition JFitToT.hh:88
Double_t gainSpread
PMT gain spread.
Definition JFitToT.hh:170
const Double_t getModelParameter(const int i) const
Get model parameter.
Definition JFitToT.hh:147
void setModelParameter(const int i, const Double_t value)
Set model parameter.
Definition JFitToT.hh:122
Double_t gain
PMT gain.
Definition JFitToT.hh:169
JFitParameter_t getModelParameter(Double_t JFitToTParameters::*p) const
Get model parameter.
Definition JFitToT.hh:159
Double_t * getModelParameters()
Get model parameters.
Definition JFitToT.hh:110
JFitToTParameters(const JPMTParameters &parameters)
Constructor.
Definition JFitToT.hh:60
Parametrisation of time-over-threshold distribution.
Definition JFitToT.hh:183
TFitResultPtr operator()(TH1 &h1, const std::string &option)
Fit histogram.
Definition JFitToT.hh:227
JPMTAnalogueSignalProcessor cpu
Definition JFitToT.hh:290
Double_t getValue(const Double_t *x, const Double_t *par)
Get rate as a function of the fit parameters.
Definition JFitToT.hh:270
JFitToT(const JPMTParameters &parameters, const JRange< double > &range)
Constructor.
Definition JFitToT.hh:191
const JPMTAnalogueSignalProcessor & getCPU() const
Access method for the analogue signal processor.
Definition JFitToT.hh:211
double getTimeOverThresholdProbability(const double tot_ns, const int NPE) const
Get probability of having a pulse with specific time-over-threshold.
double getIntegralOfTimeOverThresholdProbability(const double Tmin, const double Tmax, const int NPE) const
Get cumulative probability of time-over-threshold distribution.
Auxiliary data structure for a parameter index and its value.