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