Jpp
JEnergyRegressor.hh
Go to the documentation of this file.
1 #ifndef __JFIT__JENERGYREGRESSOR__
2 #define __JFIT__JENERGYREGRESSOR__
3 
4 #include <string>
5 
7 #include "JPhysics/JPDFTypes.hh"
8 #include "JPhysics/JPDFTable.hh"
9 #include "JPhysics/JNPETable.hh"
10 #include "JPhysics/JPDFToolkit.hh"
11 #include "JTools/JFunction1D_t.hh"
13 #include "JTools/JConstants.hh"
14 #include "JDetector/JPMT.hh"
15 #include "JDetector/JModule.hh"
16 #include "JFit/JRegressor.hh"
17 #include "JFit/JEnergy.hh"
18 #include "JFit/JNPE.hh"
19 #include "JFit/JNPEHit.hh"
20 #include "JFit/JMEstimator.hh"
21 #include "JFit/JFitToolkit.hh"
22 #include "JFit/JTimeRange.hh"
23 #include "Jeep/JMessage.hh"
24 
25 
26 /**
27  * \file
28  * Data regression method for JFIT::JEnergy.
29  * \author mdejong
30  */
31 namespace JFIT {}
32 namespace JPP { using namespace JFIT; }
33 
34 namespace JFIT {
35 
41  using JDETECTOR::JPMT;
42  using JDETECTOR::JModule;
43 
44 
45  /**
46  * Regressor function object for JEnergy fit.
47  */
48  template<>
49  struct JRegressor<JEnergy> :
50  public JAbstractRegressor<JEnergy>
51  {
54 
59 
60 
61  /**
62  * Constructor.
63  *
64  * The PDF file descriptor should contain the wild card character JPHYSICS::WILD_CARD
65  * which will be replaced by the PDF types listed in JRegressor<JEnergy, JSimplex>::pdf_t.
66  *
67  * \param fileDescriptor PDF file descriptor
68  */
69  JRegressor(const std::string& fileDescriptor) :
70  estimator(new JMEstimatorNormal())
71  {
72  using namespace std;
73  using namespace JTOOLS;
74  using namespace JPHYSICS;
75 
76  typedef JSplineFunction1D_t JFunction1D_t;
78 
79  const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(JMATH::zero));
80 
81  for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
82 
83  try {
84 
85  JPDF_t pdf;
86 
87  const string file_name = getFilename(fileDescriptor, pdf_t[i]);
88 
89  NOTICE("loading PDF from file " << file_name << "... " << flush);
90 
91  pdf.load(file_name.c_str());
92 
93  NOTICE("OK" << endl);
94 
95  pdf.setExceptionHandler(supervisor);
96 
97  if (!is_bremsstrahlung(pdf_t[i]))
98  Y1.push_back(JNPE_t(pdf));
99  else
100  YB.push_back(JNPE_t(pdf));
101  }
102  catch(const JLANG::JException& error) {
103  FATAL(error.what() << endl);
104  }
105  }
106 
107  // Add PDFs
108 
109  if (Y1.size() == 2) { Y1[1].add(Y1[0]); Y1.erase(Y1.begin()); }
110  if (YB.size() == 2) { YB[1].add(YB[0]); YB.erase(YB.begin()); }
111  }
112 
113 
114  /**
115  * Fit function.
116  * This method is used to determine chi2 of given number of photo-electrons for given energy of muon.
117  *
118  * \param x energy
119  * \param npe npe
120  * \return chi2
121  */
122  inline double operator()(const JEnergy& x, const JNPEHit& npe) const
123  {
124  const double E = x.getE();
125  const double u = npe.getChi2(E);
126 
127  return estimator->getRho(u);
128  }
129 
130 
131  /**
132  * Create data structure for handling light yields for PMT.
133  * Note that the PMT geometry is relative to the muon trajectory,
134  * conform method JDETECTOR::JPMT::transform.
135  *
136  * \param pmt PMT
137  * \param R_Hz singles rate [Hz]
138  * \return light yields
139  */
140  inline JNPE getNPE(const JPMT& pmt,
141  const double R_Hz) const
142  {
143  using namespace JTOOLS;
144 
145  const double x = pmt.getX();
146  const double y = pmt.getY();
147  const double R = sqrt(x*x + y*y);
148  const double z = pmt.getZ() - R / getTanThetaC();
149 
150  const double theta = pmt.getTheta();
151  const double phi = fabs(pmt.getPhi());
152 
153  const double yA = getNPE(Y1, R, theta, phi);
154  const double yB = getNPE(YB, R, theta, phi);
155 
156  return JNPE(JK40(T_ns, R_Hz), yA, yB, z);
157  }
158 
159 
160  /**
161  * Create data structure for handling light yields for module.
162  * Note that the module geometry is relative to the muon trajectory,
163  * conform method JDETECTOR::JModule::transform.
164  *
165  * \param module module
166  * \param rates_Hz K40 singles and multiples rates [Hz]
167  * \return light yields
168  */
169  inline JNPE getNPE(const JModule& module,
170  const JK40Rates& rates_Hz) const
171  {
172  using namespace JTOOLS;
173 
174  const double x = module.getX();
175  const double y = module.getY();
176  const double R = sqrt(x*x + y*y);
177  const double z = module.getZ() - R / getTanThetaC();
178 
179  double yA = 0.0;
180  double yB = 0.0;
181 
182  for (JModule::const_iterator pmt = module.begin(); pmt != module.end(); ++pmt) {
183 
184  const JNPE npe = this->getNPE(*pmt, rates_Hz.getSinglesRate());
185 
186  yA += npe.getYA();
187  yB += npe.getYB();
188  }
189 
190  return JNPE(JK40(T_ns, module.size(), rates_Hz), yA, yB, z);
191  }
192 
193 
194  /**
195  * Get maximal road width of NPE.
196  *
197  * \return road width [m]
198  */
199  inline double getRmax() const
200  {
201  return std::max(getRmax(Y1),
202  getRmax(YB));
203  }
204 
205 
206  std::vector<JNPE_t> Y1; //!< light from muon
207  std::vector<JNPE_t> YB; //!< light from EM showers
208 
209  static JTimeRange T_ns; //!< Time window with respect to Cherenkov hypothesis [ns]
210 
211 
212  static const int NUMBER_OF_PDFS = 4;
213 
214  static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
215 
217 
218 
219  protected:
220  /**
221  * Get maximal road width of PDF.
222  *
223  * \param NPE NPE tables
224  * \return road width [m]
225  */
226  static inline double getRmax(const std::vector<JNPE_t>& NPE)
227  {
228  double xmax = 0.0;
229 
230  for (std::vector<JNPE_t>::const_iterator i = NPE.begin(); i != NPE.end(); ++i) {
231  if (!i->empty() && i->getXmax() > xmax) {
232  xmax = i->getXmax();
233  }
234  }
235 
236  return xmax;
237  }
238 
239 
240  /**
241  * Get number of photo-electrons.
242  *
243  * \param NPE NPE tables
244  * \param R distance between muon and PMT [m]
245  * \param theta zenith angle orientation PMT [rad]
246  * \param phi azimuth angle orientation PMT [rad]
247  * \return number of photo-electrons
248  */
249  static inline double getNPE(const std::vector<JNPE_t>& NPE,
250  const double R,
251  const double theta,
252  const double phi)
253  {
254  using JTOOLS::get_value;
255 
256  double npe = 0.0;
257 
258  for (std::vector<JNPE_t>::const_iterator i = NPE.begin(); i != NPE.end(); ++i) {
259 
260  if (R <= i->getXmax()) {
261 
262  try {
263 
264  const double y = get_value((*i)(std::max(R, i->getXmin()), theta, phi));
265 
266  if (y > 0.0) {
267  npe += y;
268  }
269  }
270  catch(const JLANG::JException& error) {
271  ERROR(error << std::endl);
272  }
273  }
274  }
275 
276  return npe;
277  }
278  };
279 
280 
281  /**
282  * PDF types.
283  */
288 
289 
290  /**
291  * Time range.
292  */
294 }
295 
296 #endif
JModule.hh
JTOOLS::JPolint1FunctionalGridMap
Type definition of a 1st degree polynomial interpolation based on a JGridMap implementation.
Definition: JFunctionalMap_t.hh:91
JFIT::JRegressor< JEnergy >::operator()
double operator()(const JEnergy &x, const JNPEHit &npe) const
Fit function.
Definition: JEnergyRegressor.hh:122
JFIT::JEnergy
Data structure for fit of energy.
Definition: JEnergy.hh:24
JFIT::JAbstractRegressor
Abstract class for global fit method.
Definition: JRegressor.hh:75
JLANG::JSinglePointer
The template JSinglePointer class can be used to hold a pointer to an object.
Definition: JSinglePointer.hh:24
JFIT
Auxiliary classes and methods for linear and iterative data regression.
Definition: JEnergy.hh:15
JMessage.hh
JFitToolkit.hh
JFIT::JEnergy::getE
double getE() const
Get energy.
Definition: JEnergy.hh:144
JFIT::JRegressor< JEnergy >::getNPE
JNPE getNPE(const JModule &module, const JK40Rates &rates_Hz) const
Create data structure for handling light yields for module.
Definition: JEnergyRegressor.hh:169
JRegressor.hh
JGEOMETRY3D::JVector3D::getZ
double getZ() const
Get z position.
Definition: JVector3D.hh:114
JSinglePointer.hh
JTOOLS::u
double u[N+1]
Definition: JPolint.hh:706
JPDFToolkit.hh
std::vector
Definition: JSTDTypes.hh:12
JFIT::JRegressor< JEnergy >::T_ns
static JTimeRange T_ns
Time window with respect to Cherenkov hypothesis [ns].
Definition: JEnergyRegressor.hh:209
JTOOLS::JRange< double >
JPHYSICS
Auxiliary classes and methods for calculation of PDF and muon energy loss.
Definition: JAbstractMedium.hh:9
JFIT::JNPEHit
Auxiliary class for simultaneously handling light yields and response of PMT.
Definition: JNPEHit.hh:19
JFIT::JNPE::getYB
double getYB() const
Get light yield due to bremsstrahlung.
Definition: JNPE.hh:80
JAANET::getNPE
double getNPE(const Hit &hit)
Get true charge of hit.
Definition: JAAnetToolkit.hh:104
JFIT::JRegressor< JEnergy >::Y1
std::vector< JNPE_t > Y1
light from muon
Definition: JEnergyRegressor.hh:206
JTOOLS::JMAPLIST
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:108
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JPHYSICS::JNPETable< double, double, JNPEMaplist_t >
JNPEHit.hh
JFIT::JRegressor< JEnergy >::getNPE
static double getNPE(const std::vector< JNPE_t > &NPE, const double R, const double theta, const double phi)
Get number of photo-electrons.
Definition: JEnergyRegressor.hh:249
JTOOLS::get_value
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition: JResult.hh:936
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDETECTOR::JK40Rates
Auxiliary class for K40 rates.
Definition: JK40Rates.hh:41
ERROR
#define ERROR(A)
Definition: JMessage.hh:66
JFunction1D_t.hh
JGEOMETRY3D::JVersor3D::getTheta
double getTheta() const
Get theta angle.
Definition: JVersor3D.hh:125
JDETECTOR::JK40Rates::getSinglesRate
double getSinglesRate() const
Get singles rate.
Definition: JK40Rates.hh:97
debug
int debug
debug level
Definition: JSirene.cc:59
JTOOLS::JPolint1FunctionalMap
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.
Definition: JFunctionalMap_t.hh:55
JConstants.hh
JFunctionalMap_t.hh
JFIT::JRegressor< JEnergy >::JNPEMaplist_t
JTOOLS::JMAPLIST< JTOOLS::JPolint1FunctionalMap, JTOOLS::JPolint1FunctionalGridMap, JTOOLS::JPolint1FunctionalGridMap >::maplist JNPEMaplist_t
Definition: JEnergyRegressor.hh:57
JFIT::JRegressor< JEnergy >::getRmax
static double getRmax(const std::vector< JNPE_t > &NPE)
Get maximal road width of PDF.
Definition: JEnergyRegressor.hh:226
JFIT::JNPEHit::getChi2
double getChi2(const double E_GeV) const
Get chi2.
Definition: JNPEHit.hh:87
JFIT::JRegressor
Template definition of a data regressor of given model.
Definition: JRegressor.hh:68
JFIT::JRegressor< JEnergy >::getNPE
JNPE getNPE(const JPMT &pmt, const double R_Hz) const
Create data structure for handling light yields for PMT.
Definition: JEnergyRegressor.hh:140
JPHYSICS::is_bremsstrahlung
bool is_bremsstrahlung(const int pdf)
Test if given PDF type corresponds to Cherenkov light from Bremsstrahlung.
Definition: JPDFTypes.hh:158
JDETECTOR::JModule
Data structure for a composite optical module.
Definition: JModule.hh:49
JNPETable.hh
JFIT::JK40
Auxiliary class for converting various rates to expectation values of the number of hits within a giv...
Definition: JK40.hh:30
JEEP::getFilename
std::string getFilename(const std::string &file_name)
Get file name part, i.e.
Definition: JeepToolkit.hh:86
JPHYSICS::JPDFTable
Multi-dimensional PDF table for arrival time of Cherenkov light.
Definition: JPDFTable.hh:39
JTimeRange.hh
JTOOLS::JSplineFunction1D_t
Type definition of a spline interpolation method based on a JCollection with double result type.
Definition: JFunction1D_t.hh:35
JDETECTOR::JPMT
Data structure for PMT geometry and calibration.
Definition: JPMT.hh:53
JFIT::JMEstimatorNormal
Normal M-estimator.
Definition: JMEstimator.hh:66
JPHYSICS::SCATTERED_LIGHT_FROM_EMSHOWERS
scattered light from EM showers
Definition: JPDFTypes.hh:33
JFIT::JNPE
Auxiliary class for handling various light yields.
Definition: JNPE.hh:27
JPHYSICS::JPDFType_t
JPDFType_t
PDF types.
Definition: JPDFTypes.hh:27
JTOOLS::getTanThetaC
double getTanThetaC()
Get average tangent of Cherenkov angle of water.
Definition: JConstants.hh:133
JFIT::JRegressor< JEnergy >::getRmax
double getRmax() const
Get maximal road width of NPE.
Definition: JEnergyRegressor.hh:199
JMEstimator.hh
std
Definition: jaanetDictionary.h:36
JFIT::JRegressor< JEnergy >::YB
std::vector< JNPE_t > YB
light from EM showers
Definition: JEnergyRegressor.hh:207
JGEOMETRY3D::JVector3D::getY
double getY() const
Get y position.
Definition: JVector3D.hh:103
JEnergy.hh
JLANG::JException::what
virtual const char * what() const
Get error message.
Definition: JException.hh:48
JPHYSICS::DIRECT_LIGHT_FROM_MUON
direct light from muon
Definition: JPDFTypes.hh:29
JFIT::JRegressor< JEnergy >::JRegressor
JRegressor(const std::string &fileDescriptor)
Constructor.
Definition: JEnergyRegressor.hh:69
JMATH::zero
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:94
JGEOMETRY3D::JVector3D::getX
double getX() const
Get x position.
Definition: JVector3D.hh:93
JTOOLS
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Definition: JAbstractCollection.hh:9
JFIT::JRegressor< JEnergy >::estimator
JLANG::JSinglePointer< JMEstimator > estimator
M-Estimator function.
Definition: JEnergyRegressor.hh:216
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
JPMT.hh
JPHYSICS::DIRECT_LIGHT_FROM_EMSHOWERS
direct light from EM showers
Definition: JPDFTypes.hh:32
JNPE.hh
JFIT::JNPE::getYA
double getYA() const
Get light yield due to muon itself.
Definition: JNPE.hh:69
JPDFTypes.hh
JLANG::JException
General exception.
Definition: JException.hh:23
JPDFTable.hh
JEEP::JMessage
Auxiliary class for handling debug parameter within a class.
Definition: JMessage.hh:44
JFIT::JRegressor< JEnergy >::JNPE_t
JPHYSICS::JNPETable< double, double, JNPEMaplist_t > JNPE_t
Definition: JEnergyRegressor.hh:58
JGEOMETRY3D::JVersor3D::getPhi
double getPhi() const
Get phi angle.
Definition: JVersor3D.hh:141
JPHYSICS::SCATTERED_LIGHT_FROM_MUON
scattered light from muon
Definition: JPDFTypes.hh:30