Jpp
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 
14 #include "JROOT/JRootToolkit.hh"
15 
16 
17 /**
18  * \author mkarel
19  */
20 
21 namespace JCALIBRATE {}
22 namespace JPP { using namespace JCALIBRATE; }
23 
24 namespace JCALIBRATE {
25 
29 
30  static const double FITTOT_TOT_MIN_NS = 10.0; //!< Minimal time-over-threshold [ns]
31  static const double FITTOT_GAIN_MIN = 0.0; //!< Minimal gain [unit]
32  static const double FITTOT_GAIN_MAX = 10.0; //!< Maximal gain [unit]
33  static const double FITTOT_GAINSPREAD_MIN = 0.0; //!< Minimal gain spread [unit]
34  static const double FITTOT_GAINSPREAD_MAX = 10.0; //!< Maximal gain spread [unit]
35 
36  /**
37  * Fit parameters for two-fold coincidence rate due to K40.
38  */
40  /**
41  * Constructor.
42  *
43  * \param parameters PMT parameters
44  */
45  JFitToTParameters(const JPMTParameters& parameters) :
46  W (1.0),
47  gain (parameters.gain),
48  gainSpread(parameters.gainSpread)
49  {}
50 
51 
52  /**
53  * Copy constructor.
54  *
55  * \param data data
56  */
57  JFitToTParameters(const Double_t* data) :
58  W (0.0),
59  gain (0.0),
60  gainSpread(0.0)
61  {
62  if (data != NULL) {
63  setModelParameters(data);
64  }
65  }
66 
67 
68  /**
69  * Get number of model parameters.
70  *
71  * \return number of parameters
72  */
74  {
75  return sizeof(JFitToTParameters) / sizeof(Double_t);
76  }
77 
78 
79  /**
80  * Get model parameters.
81  *
82  * \return pointer to parameters
83  */
84  const Double_t* getModelParameters() const
85  {
86  return &this->W;
87  }
88 
89 
90  /**
91  * Get model parameters.
92  *
93  * \return pointer to parameters
94  */
95  Double_t* getModelParameters()
96  {
97  return &this->W;
98  }
99 
100 
101  /**
102  * Set model parameters.
103  *
104  * \param data pointer to parameters
105  */
106  void setModelParameters(const Double_t* data)
107  {
108  for (Int_t i = 0; i != getNumberOfModelParameters(); ++i) {
109  getModelParameters()[i] = data[i];
110  }
111  }
112 
113 
114  /**
115  * Get model parameter.
116  *
117  * \param i parameter index
118  * \return parameter value
119  */
120  const Double_t getModelParameter(const int i) const
121  {
122  return getModelParameters()[i];
123  }
124 
125 
126  /**
127  * Get model parameter.
128  *
129  * \param p pointer to data member
130  * \return parameter index and value
131  */
133  {
134  const Int_t i = &(this->*p) - getModelParameters();
135 
136  return JFitParameter_t(i, getModelParameter(i));
137  }
138 
139 
140  // fit parameters
141 
142  Double_t W; //!< normalisation
143  Double_t gain; //!< PMT gain
144  Double_t gainSpread; //!< PMT gain spread
145  };
146 
147 
148  /**
149  * Parametrisation of time-over-threshold distribution.
150  *
151  * Note that for use in ROOT fit operations, the member method JFitToT::getValue is static.\n
152  */
153  struct JFitToT :
154  public JFitToTParameters,
155  public TF1
156  {
157  /**
158  * Constructor.
159  *
160  * \param parameters parameters
161  * \param xmin minimal x
162  * \param xmax maximal x
163  */
164  JFitToT(const JPMTParameters& parameters,
165  const double xmin,
166  const double xmax) :
167 
168  JFitToTParameters(parameters),
169 
170  TF1("fittot",
171  JFitToT::getValue,
172  xmin, xmax,
174 
175  Xmin(xmin),
176  Xmax(xmax)
177  {
178  getInstance().setPMTParameters(parameters);
179  }
180 
181 
182  /**
183  * Fit histogram.
184  *
185  * Note that the PMT parameters which are part of the model are reset before the fit according the status of each PMT and
186  * the obtained fit parameters are copied back to the model parameters after the fit.
187  *
188  * \param h1 ROOT 1D-histogram
189  * \param option fit option
190  */
191  TFitResultPtr operator()(TH1& h1, const std::string& option)
192  {
193  using namespace std;
194  using namespace JPP;
195 
196  Double_t x0 = numeric_limits<Double_t>::max();
197  Double_t y0 = 0.0;
198  this->W = 0.0;
199 
200  for (Int_t i = 1; i <= h1.GetXaxis()->GetNbins(); ++i) {
201 
202  const Double_t x = h1.GetBinCenter (i);
203  const Double_t y = h1.GetBinContent(i);
204 
205  if (x >= this->Xmin &&
206  x <= this->Xmax) {
207  this->W += y;
208  }
209 
210  if (x >= 0.5*TIME_OVER_THRESHOLD_NS &&
211  x <= 2.0*TIME_OVER_THRESHOLD_NS) {
212 
213  if (y >= y0) {
214  x0 = x;
215  y0 = y;
216  }
217  }
218  }
219 
220  double xmin = Xmin + x0 - TIME_OVER_THRESHOLD_NS;
221  double xmax = Xmax + x0 - TIME_OVER_THRESHOLD_NS;
222 
223  if (xmin < FITTOT_TOT_MIN_NS) {
224  xmin = FITTOT_TOT_MIN_NS;
225  }
226 
227  this->SetRange(xmin, xmax);
228 
229  this->gain = getInstance().getNPE(x0);
230 
233 
234  setParLimits(*this, this->getModelParameter(&JFitToT::gain), FITTOT_GAIN_MIN, FITTOT_GAIN_MAX);
235  setParLimits(*this, this->getModelParameter(&JFitToT::gainSpread), FITTOT_GAINSPREAD_MIN, FITTOT_GAINSPREAD_MAX);
236 
237  this->SetParameters(this->getModelParameters());
238 
239  getInstance().gain = this->gain;
241 
242  const TFitResultPtr result = h1.Fit(this, option.c_str());
243 
244  this->setModelParameters(this->GetParameters());
245 
246  return result;
247  }
248 
249 
250 
251  /**
252  * Get rate as a function of the fit parameters.
253  *
254  * \param x pointer to abscissa values
255  * \param par pointer to parameter values
256  * \return rate distribution at specified time-over-threshold [Hz/ns]
257  */
258  static Double_t getValue(const Double_t* x, const Double_t* par)
259  {
260  static const int NPE = 1;
261 
262  const Double_t W = par[0];
263  getInstance().gain = par[1];
264  getInstance().gainSpread = par[2];
265 
266  const Double_t tot_ns = x[0];
267  const Double_t npe = getInstance().getNPE(tot_ns);
268 
269  return W * getInstance().getProbability(npe, NPE) * getInstance().getDerivative(npe);
270  }
271 
272 
273  private:
274  /**
275  * Get unique instance of PMT analogue signal processor.
276  *
277  * \return reference to PMT analogue signal processor.
278  */
280  {
281  static JPMTAnalogueSignalProcessor object;
282 
283  return object;
284  }
285 
286  double Xmin;
287  double Xmax;
288  };
289 }
290 
291 #endif
JCALIBRATE::JFitToT::JFitToT
JFitToT(const JPMTParameters &parameters, const double xmin, const double xmax)
Constructor.
Definition: JFitToT.hh:164
JPMTAnalogueSignalProcessor.hh
JCALIBRATE::JFitToTParameters::gain
Double_t gain
PMT gain.
Definition: JFitToT.hh:143
JCALIBRATE::FITTOT_GAINSPREAD_MIN
static const double FITTOT_GAINSPREAD_MIN
Minimal gain spread [unit].
Definition: JFitToT.hh:33
JCALIBRATE::JFitToT::getValue
static Double_t getValue(const Double_t *x, const Double_t *par)
Get rate as a function of the fit parameters.
Definition: JFitToT.hh:258
JDETECTOR::TIME_OVER_THRESHOLD_NS
const double TIME_OVER_THRESHOLD_NS
Specification for time-over-threshold corresponding to a one photo-electron pulse.
Definition: JDetector/JCalibration.hh:29
JCALIBRATE::JFitToTParameters::W
Double_t W
normalisation
Definition: JFitToT.hh:142
JCALIBRATE
Definition: JCalibrateK40.hh:15
JDETECTOR::JPMTAnalogueSignalProcessor::setPMTParameters
void setPMTParameters(const JPMTParameters &parameters)
Set PMT parameters.
Definition: JPMTAnalogueSignalProcessor.hh:319
JCALIBRATE::JFitToTParameters::getModelParameter
JFitParameter_t getModelParameter(Double_t JFitToTParameters::*p) const
Get model parameter.
Definition: JFitToT.hh:132
JDETECTOR::JPMTParameters::gainSpread
double gainSpread
gain spread [unit]
Definition: JPMTParameters.hh:218
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JCALIBRATE::JFitToTParameters::getModelParameters
Double_t * getModelParameters()
Get model parameters.
Definition: JFitToT.hh:95
JDETECTOR::JPMTParameters::gain
double gain
gain [unit]
Definition: JPMTParameters.hh:217
JCALIBRATE::FITTOT_GAIN_MAX
static const double FITTOT_GAIN_MAX
Maximal gain [unit].
Definition: JFitToT.hh:32
JTOOLS::result
return result
Definition: JPolint.hh:695
JCALIBRATE::JFitToTParameters::JFitToTParameters
JFitToTParameters(const Double_t *data)
Copy constructor.
Definition: JFitToT.hh:57
JCALIBRATE::JFitToTParameters::gainSpread
Double_t gainSpread
PMT gain spread.
Definition: JFitToT.hh:144
JRootToolkit.hh
JCALIBRATE::FITTOT_GAIN_MIN
static const double FITTOT_GAIN_MIN
Minimal gain [unit].
Definition: JFitToT.hh:31
JCALIBRATE::JFitToTParameters::getNumberOfModelParameters
static Int_t getNumberOfModelParameters()
Get number of model parameters.
Definition: JFitToT.hh:73
JCALIBRATE::JFitToT::Xmin
double Xmin
Definition: JFitToT.hh:286
JROOT::setParLimits
bool setParLimits(TF1 &f1, const Int_t index, Double_t xmin, Double_t xmax)
Set fit parameter limits.
Definition: JRootToolkit.hh:293
JCALIBRATE::JFitToTParameters::JFitToTParameters
JFitToTParameters(const JPMTParameters &parameters)
Constructor.
Definition: JFitToT.hh:45
JDETECTOR::JPMTAnalogueSignalProcessor::getProbability
virtual double getProbability(const double npe, const int NPE) const
Get probability for given charge.
Definition: JPMTAnalogueSignalProcessor.hh:413
JCALIBRATE::FITTOT_GAINSPREAD_MAX
static const double FITTOT_GAINSPREAD_MAX
Maximal gain spread [unit].
Definition: JFitToT.hh:34
JDETECTOR::JPMTSignalProcessorInterface::getNPE
double getNPE(const double tot_ns, const double eps=1.0e-3) const
Get number of photo-electrons.
Definition: JPMTSignalProcessorInterface.hh:316
JROOT::setParameter
bool setParameter(TF1 &f1, const JFitParameter_t &parameter)
Set fit parameter.
Definition: JRootToolkit.hh:228
std
Definition: jaanetDictionary.h:36
JCALIBRATE::JFitToT::Xmax
double Xmax
Definition: JFitToT.hh:287
JCALIBRATE::JFitToT
Parametrisation of time-over-threshold distribution.
Definition: JFitToT.hh:153
JROOT::JFitParameter_t
Auxiliary data structure for a parameter index and its value.
Definition: JRootToolkit.hh:182
JFIT::JFitParameter_t
JFitParameter_t
Definition: JFitParameters.hh:15
JDETECTOR::JPMTAnalogueSignalProcessor::getDerivative
virtual double getDerivative(const double npe) const
Get derivative of number of photo-electrons to time-over-threshold.
Definition: JPMTAnalogueSignalProcessor.hh:506
JCALIBRATE::JFitToT::getInstance
static JPMTAnalogueSignalProcessor & getInstance()
Get unique instance of PMT analogue signal processor.
Definition: JFitToT.hh:279
JDETECTOR::JPMTParameters
Data structure for PMT parameters.
Definition: JPMTParameters.hh:29
JCALIBRATE::JFitToTParameters::getModelParameters
const Double_t * getModelParameters() const
Get model parameters.
Definition: JFitToT.hh:84
JCALIBRATE::JFitToTParameters::setModelParameters
void setModelParameters(const Double_t *data)
Set model parameters.
Definition: JFitToT.hh:106
JPMTParameters.hh
JCALIBRATE::JFitToTParameters::getModelParameter
const Double_t getModelParameter(const int i) const
Get model parameter.
Definition: JFitToT.hh:120
JCALIBRATE::FITTOT_TOT_MIN_NS
static const double FITTOT_TOT_MIN_NS
Minimal time-over-threshold [ns].
Definition: JFitToT.hh:30
JCALIBRATE::JFitToT::operator()
TFitResultPtr operator()(TH1 &h1, const std::string &option)
Fit histogram.
Definition: JFitToT.hh:191
JCALIBRATE::JFitToTParameters
Fit parameters for two-fold coincidence rate due to K40.
Definition: JFitToT.hh:39
JDETECTOR::JPMTAnalogueSignalProcessor
PMT analogue signal processor.
Definition: JPMTAnalogueSignalProcessor.hh:46