Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/JRootToolkit.hh"
20 
21 
22 /**
23  * \author mkarel, bjung
24  */
25 
26 namespace JCALIBRATE {}
27 namespace JPP { using namespace JCALIBRATE; }
28 
29 namespace JCALIBRATE {
30 
31  using JTOOLS::JRange;
35 
36  static const char FITTOT_SEPARATOR = '.';
37  static const std::string FITTOT_SUFFIX = "1ToT";
38  static const std::string FITTOT_FNAME = "fittot";
39 
40  static const double FITTOT_GAIN_MIN = 0.25; //!< Default minimal gain
41  static const double FITTOT_GAIN_MAX = 2.00; //!< Default maximal gain
42 
43  static const double FITTOT_GAINSPREAD_MIN = 0.05; //!< Default minimal gain spread
44  static const double FITTOT_GAINSPREAD_MAX = 1.00; //!< Default maximal gain spread
45 
46 
47  /**
48  * Fit parameters for two-fold coincidence rate due to K40.
49  */
51  /**
52  * Constructor.
53  *
54  * \param parameters PMT parameters
55  */
57  gain (parameters.gain),
58  gainSpread (parameters.gainSpread),
59  normalization (1.0)
60  {}
61 
62 
63  /**
64  * Copy constructor.
65  *
66  * \param data data
67  */
68  JFitToTParameters(const Double_t* data) :
69  gain (0.0),
70  gainSpread (0.0),
71  normalization (1.0)
72  {
73  if (data != NULL) {
74  setModelParameters(data);
75  }
76  }
77 
78 
79  /**
80  * Get number of model parameters.
81  *
82  * \return number of parameters
83  */
85  {
86  return sizeof(JFitToTParameters) / sizeof(Double_t);
87  }
88 
89 
90  /**
91  * Get model parameters.
92  *
93  * \return pointer to parameters
94  */
95  const Double_t* getModelParameters() const
96  {
97  return &this->gain;
98  }
99 
100 
101  /**
102  * Get model parameters.
103  *
104  * \return pointer to parameters
105  */
106  Double_t* getModelParameters()
107  {
108  return &this->gain;
109  }
110 
111 
112  /**
113  * Set model parameter.
114  *
115  * \param i parameter index
116  * \param value parameter value
117  */
118  void setModelParameter(const int i, const Double_t value)
119  {
120  getModelParameters()[i] = value;
121  }
122 
123 
124  /**
125  * Set model parameters.
126  *
127  * \param data pointer to parameters
128  */
129  void setModelParameters(const Double_t* data)
130  {
131  for (Int_t i = 0; i != getNumberOfModelParameters(); ++i) {
132  setModelParameter(i, data[i]);
133  }
134  }
135 
136 
137  /**
138  * Get model parameter.
139  *
140  * \param i parameter index
141  * \return parameter value
142  */
143  const Double_t getModelParameter(const int i) const
144  {
145  return getModelParameters()[i];
146  }
147 
148 
149  /**
150  * Get model parameter.
151  *
152  * \param p pointer to data member
153  * \return parameter index and value
154  */
156  {
157  const Int_t i = &(this->*p) - getModelParameters();
158 
159  return JFitParameter_t(i, getModelParameter(i));
160  }
161 
162 
163  // fit parameters
164 
165  Double_t gain; //!< PMT gain
166  Double_t gainSpread; //!< PMT gain spread
167  Double_t normalization;
168  };
169 
170 
171  /**
172  * Parametrisation of time-over-threshold distribution.
173  *
174  * Note that for use in ROOT fit operations, the member method JFitToT::getValue is static.\n
175  */
176  struct JFitToT :
177  public TF1,
178  public JFitToTParameters
179  {
180 
181  /**
182  * Constructor.
183  *
184  * \param parameters parameters
185  * \param range abscissa range
186  */
188 
189  TF1(FITTOT_FNAME.c_str(),
190  this,
191  &JFitToT::getValue,
192  range.getLowerLimit(),
193  range.getUpperLimit(),
195 
196  JFitToTParameters(parameters),
197 
198  cpu(parameters)
199  {}
200 
201 
202  /**
203  * Access method for the analogue signal processor
204  *
205  * \return reference to analogue signal processor
206  */
208  {
209  return cpu;
210  }
211 
212 
213  /**
214  * Fit histogram.
215  *
216  * Note that the PMT parameters which are part of the model are reset before the fit according the status of each PMT and
217  * the obtained fit parameters are copied back to the model parameters after the fit.
218  *
219  * \param h1 ROOT 1D-histogram
220  * \param option fit option
221  * \return fit result
222  */
223  TFitResultPtr operator()(TH1& h1, const std::string& option)
224  {
225  using namespace std;
226  using namespace JPP;
227 
228  // Set initial gain and gain-spread
229  const Int_t Ngain = this->getModelParameter(&JFitToT::JFitToTParameters::gain);
230  const Int_t NgainSpread = this->getModelParameter(&JFitToT::JFitToTParameters::gainSpread);
231  const Int_t Nnormalization = this->getModelParameter(&JFitToT::JFitToTParameters::normalization);
232 
233  SetParName(Ngain, MAKE_CSTRING("gain"));
234  SetParName(NgainSpread, MAKE_CSTRING("gainSpread"));
235  SetParName(Nnormalization, MAKE_CSTRING("normalization"));
236 
237  normalization = h1.Integral(h1.FindBin(this->GetXmin()),
238  h1.FindBin(this->GetXmax()));
239 
240  SetParameters(getModelParameters());
241 
242  // Set parameter and fit ranges
245 
246  FixParameter(Nnormalization, normalization);
247 
248  // Fit histogram
249  const TFitResultPtr result = h1.Fit(this, option.c_str());
250 
251  this->setModelParameters(this->GetParameters());
252 
253  cpu.gain = getModelParameter(Ngain);
254  cpu.gainSpread = getModelParameter(NgainSpread);
255 
256  return result;
257  }
258 
259 
260  /**
261  * Get rate as a function of the fit parameters.
262  *
263  * \param x pointer to abscissa values
264  * \param par pointer to parameter values
265  * \return rate distribution at specified time-over-threshold [Hz/ns]
266  */
267  Double_t getValue(const Double_t* x, const Double_t* par)
268  {
269  const double tot_ns = x[0];
270 
271  // Set new parameter values
272  cpu.gain = par[0];
273  cpu.gainSpread = par[1];
274 
275  // Determine normalization factor
276  const int NPE = 1;
277  const double Whist = par[2];
278  const double Wpdf = cpu.getIntegralOfTimeOverThresholdProbability(GetXmin(), GetXmax(), NPE);
279 
280  return (Wpdf > 0.0 ? (Whist / Wpdf) : Whist) * cpu.getTimeOverThresholdProbability(tot_ns, NPE);
281  }
282 
283  private:
284 
286  };
287 }
288 
289 #endif
static Int_t getNumberOfModelParameters()
Get number of model parameters.
Definition: JFitToT.hh:84
double gain
gain [unit]
JFitToT(const JPMTParameters &parameters, const JRange< double > &range)
Constructor.
Definition: JFitToT.hh:187
Exceptions.
JFitParameter_t getModelParameter(Double_t JFitToTParameters::*p) const
Get model parameter.
Definition: JFitToT.hh:155
const Double_t getModelParameter(const int i) const
Get model parameter.
Definition: JFitToT.hh:143
double gainSpread
gain spread [unit]
JFitToTParameters(const Double_t *data)
Copy constructor.
Definition: JFitToT.hh:68
static const double FITTOT_GAIN_MAX
Default maximal gain.
Definition: JFitToT.hh:41
Double_t gainSpread
PMT gain spread.
Definition: JFitToT.hh:166
static const double FITTOT_GAIN_MIN
Default minimal gain.
Definition: JFitToT.hh:40
Double_t * getModelParameters()
Get model parameters.
Definition: JFitToT.hh:106
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
Double_t getValue(const Double_t *x, const Double_t *par)
Get rate as a function of the fit parameters.
Definition: JFitToT.hh:267
Parametrisation of time-over-threshold distribution.
Definition: JFitToT.hh:176
Fit parameters for two-fold coincidence rate due to K40.
Definition: JFitToT.hh:50
const JPMTAnalogueSignalProcessor & getCPU() const
Access method for the analogue signal processor.
Definition: JFitToT.hh:207
JPMTAnalogueSignalProcessor cpu
Definition: JFitToT.hh:285
static const std::string FITTOT_SUFFIX
Definition: JFitToT.hh:37
const Double_t * getModelParameters() const
Get model parameters.
Definition: JFitToT.hh:95
Auxiliary data structure for a parameter index and its value.
JFitToTParameters(const JPMTParameters &parameters)
Constructor.
Definition: JFitToT.hh:56
static const char FITTOT_SEPARATOR
Definition: JFitToT.hh:36
static const double FITTOT_GAINSPREAD_MAX
Default maximal gain spread.
Definition: JFitToT.hh:44
return result
Definition: JPolint.hh:727
Double_t gain
PMT gain.
Definition: JFitToT.hh:165
Range of values.
Definition: JRange.hh:38
bool setParLimits(TF1 &f1, const Int_t index, Double_t xmin, Double_t xmax)
Set fit parameter limits.
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi mv $WORKDIR/fit.root $MODULE_ROOT typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
Definition: module-Z:fit.sh:84
then $JPP_DIR examples JDetector JToT o $OUTPUT_FILE n N $NPE P gain
Definition: JToT.sh:45
Auxiliary class to define a range between two values.
void setModelParameters(const Double_t *data)
Set model parameters.
Definition: JFitToT.hh:129
void setModelParameter(const int i, const Double_t value)
Set model parameter.
Definition: JFitToT.hh:118
double getIntegralOfTimeOverThresholdProbability(const double Tmin, const double Tmax, const int NPE) const
Get cumulative probability of time-over-threshold distribution.
double getTimeOverThresholdProbability(const double tot_ns, const int NPE) const
Get probability of having a pulse with specific time-over-threshold.
PMT analogue signal processor.
static const double FITTOT_GAINSPREAD_MIN
Default minimal gain spread.
Definition: JFitToT.hh:43
Data structure for PMT parameters.
TFitResultPtr operator()(TH1 &h1, const std::string &option)
Fit histogram.
Definition: JFitToT.hh:223
static const std::string FITTOT_FNAME
Definition: JFitToT.hh:38