Jpp 21.0.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JShowerBjorkenYRegressor.hh
Go to the documentation of this file.
1#ifndef __JFIT__JSHOWERBJORKENYREGRESSOR__
2#define __JFIT__JSHOWERBJORKENYREGRESSOR__
3
4#include <memory>
5
10
14#include "JTools/JRange.hh"
15#include "JTools/JResult.hh"
19
23
24#include "JMath/JZero.hh"
25
26#include "JFit/JTimeRange.hh"
27#include "JFit/JPMTW0.hh"
28#include "JFit/JSimplex.hh"
29#include "JFit/JMEstimator.hh"
30#include "JFit/JRegressor.hh"
31#include "JFit/JShowerEH.hh"
32#include "JFit/JFitToolkit.hh"
33
34#include "Jeep/JMessage.hh"
35
36/**
37 * \file
38 * Data regression method for JFIT::JShowerEH.
39 * \author adomi
40 */
41
42namespace JFIT {
43
50
51 /**
52 * Regressor function object for JShowerEH fit using JSimplex minimiser.
53 */
54 template<>
55 struct JRegressor<JShowerEH, JSimplex> :
56 public JAbstractRegressor<JShowerEH, JSimplex>
57 {
58 using JAbstractRegressor<JShowerEH, JSimplex>::operator();
59
60 typedef JTOOLS::JSplineFunction1S_t JFunction1D_t;
66
72
73
74 // Part for the Isotropic PDF
76 JTOOLS::JPolint1FunctionalGridMap>::maplist JMapList_t2;
78
80 JTOOLS::JPolint1FunctionalGridMap>::maplist JNPEMapList_t2;
82
83
84 /**
85 * Parameterized constructor
86 *
87 * The PDF file descriptor should contain the wild card character JEEP::FILENAME_WILDCARD which
88 * will be replaced by the corresponding PDF types listed in JRegressor<JShower3Z, JGandalf>::pdf_t.
89 *
90 * \param fileDescriptor PDF file descriptor
91 */
92
93 JRegressor(const std::string& fileDescriptor):
94 estimator(new JMEstimatorNull())
95 {
96 using namespace std;
97 using namespace JPP;
98
99 const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(JMATH::zero));
100 const JPDF_t2::JSupervisor supervisor2(new JPDF_t2::JDefaultResult(JMATH::zero));
101
102 for (int i = 0; i != NUMBER_OF_PDFS; ++i) {
103
104 try {
105
106 JPDF_t pdf;
107 JPDF_t2 pdf2;
108
109 const string file_name = getFilename(fileDescriptor, pdf_t[i]);
110
111 NOTICE("loading PDF from file " << file_name << "... " << flush);
112
113 if(i < 2){
114
115 pdf.load(file_name.c_str());
116
117 pdf.setExceptionHandler(supervisor);
118
119 npe[ i ] = JNPE_t(pdf);
120
121 } else {
122
123 pdf2.load(file_name.c_str());
124
125 NOTICE("OK" << endl);
126
127 pdf2.setExceptionHandler(supervisor2);
128
129 npe2[ i-2 ] = JNPE_t2(pdf2);
130
131 }
132 }
133 catch(const JException& error) {
134 FATAL(error.what() << endl);
135 }
136 }
137
138 // Add PDFs
139 for (int i = 1; i < (NUMBER_OF_PDFS-2); i += 2) {
140
141 npe[ i ].add(npe[i-1]);
142
143 JNPE_t buffer;
144
145 npe[i-1].swap(buffer);
146
147 npe2[ i ].add(npe2[i-1]);
148
149 JNPE_t2 buffer2;
150
151 npe2[i-1].swap(buffer2);
152
153 }
154 }
155
156 /**
157 * Fit function.
158 * This method is used to determine the chi2 of given PMT with respect to shower hypothesis.
159 *
160 * \param shower shower
161 * \param pmt pmt
162 * \return chi2
163 */
164 double operator()(const JShowerEH& shower, const JPMTW0& pmt) const
165 {
166 using namespace JPP;
167 using namespace std;
168
169 JPosition3D D(pmt.getPosition());
170 JDirection3D U(pmt.getDirection());
171
172 D.sub(shower.getPosition());
173
174 double ct = U.getDot(D) / D.getLength();
175
176 JVersor3D shower_dir(shower.getDirection());
177
178 const double z = D.getDot(shower_dir);
179 const double x = D.getX() - z * shower.getDX();
180 const double y = D.getY() - z * shower.getDY();
181 const double cosDelta = z/D.getLength(); // Delta = angle between shower direction and PMT position
182
183 U.rotate(JRotation3Z(-atan2(y,x))); // rotate PMT axis to x-z plane
184
185 const double theta = U.getTheta();
186 const double phi = fabs(U.getPhi());
187
188 double H0 = getH0(pmt.getR()); // background
189 double H1 = getH1(D.getLength(), ct, cosDelta, theta, phi,
190 shower.getEem(), shower.getEh(), shower.getBy()); // signal
191
192 if (H1 >= Vmax_npe) {
193 H1 *= Vmax_npe / H1;
194 }
195
196 H1 += H0; // now H1 is signal + background
197
198 const bool hit = pmt.getN() != 0;
199 const double u = getChi2(H1, hit); // -log(lik)
200
201 return estimator->getRho(u);
202 }
203
204 /**
205 * Get background hypothesis value for time integrated PDF.
206 *
207 * \param R_Hz rate [Hz]
208 * \return hypothesis value
209 */
210 double getH0(const double R_Hz) const
211 {
212 return get_value(JNPE_t::result_type(R_Hz * 1e-9 * T_ns.getLength()));
213 }
214
215 /**
216 * Get signal hypothesis value for time integrated PDF.
217 *
218 * \param D PMT distance from shower [m]
219 * \param ct angle between shower direction and PMT position
220 * \param cosDelta angle between shower direction and PMT position
221 * \param theta PMT zenith angle [deg]
222 * \param phi PMT azimuth angle [deg]
223 * \param Eem EM shower energy [GeV]
224 * \param Eh H shower energy [GeV]
225 * \param Y Bjorken Y
226 * \return hypothesis value
227 */
228 double getH1(const double D,
229 const double ct,
230 const double cosDelta,
231 const double theta,
232 const double phi,
233 const double Eem,
234 const double Eh,
235 const double Y) const
236 {
237
238 double h1 = 0;
239
240 for (int i = 0; i != (NUMBER_OF_PDFS-1); ++i) {
241
242 if (!npe[i].empty() && D <= npe[i].getXmax() && !npe2[i].empty() && D <= npe2[i].getXmax()) {
243
244 try {
245
246 JNPE_t::result_type P_em;
247 JNPE_t2::result_type P_h;
248
249 P_em = fabs(Eem) * npe[i](std::max(D, npe[i].getXmin()), cosDelta, theta, phi);
250
251 P_h = fabs(Eh) * npe2[i](std::max(D, npe2[i].getXmin()), ct);
252
253 double y1 = get_value(P_em) + get_value(P_h);
254
255 if(y1 > 0.0){
256 h1 += y1;
257 }
258
259 }
260 catch(JLANG::JException& error) {
261 ERROR(error << std::endl);
262 }
263 }
264 }
265
266 return h1;
267 }
268
269 static JTimeRange T_ns; //!< Time window with respect to Cherenkov hypothesis [ns]
270 static double Vmax_npe; //!< Maximal integral of PDF [npe]
271
272 static const int NUMBER_OF_PDFS = 4;
273
274 static const JPDFType_t pdf_t[NUMBER_OF_PDFS];
275
276 JNPE_t npe[NUMBER_OF_PDFS-2]; //!< PDF
277 JNPE_t2 npe2[NUMBER_OF_PDFS-2]; //!< PDF
278
279 std::shared_ptr<JMEstimator> estimator; //!< M-Estimator function
280 };
281
282 /**
283 * PDF types.
284 */
285 const JPDFType_t JRegressor<JShowerEH, JSimplex>::pdf_t[] = { DIRECT_LIGHT_FROM_EMSHOWER,
286 SCATTERED_LIGHT_FROM_EMSHOWER,
287 DIRECT_LIGHT_FROM_BRIGHT_POINT,
288 SCATTERED_LIGHT_FROM_BRIGHT_POINT };
289
290 /**
291 * Default values.
292 */
294 double JRegressor<JShowerEH, JSimplex>::Vmax_npe = std::numeric_limits<double>::max();
295
296}
297
298#endif
Auxiliary methods to evaluate Poisson probabilities and chi2.
Various implementations of functional maps.
Maximum likelihood estimator (M-estimators).
General purpose messaging.
#define ERROR(A)
Definition JMessage.hh:66
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
Auxiliary methods for PDF calculations.
Numbering scheme for PDF types.
Physics constants.
Auxiliary class to define a range between two values.
General purpose data regression method.
This include file containes various data structures that can be used as specific return types for the...
Definition of zero value for any class.
const JVersor3Z & getDirection() const
Get direction.
Definition JVersor3Z.hh:81
Data structure for fit of straight line in positive z-direction with energy.
Definition JShowerEH.hh:32
double getEem() const
Get EM energy.
Definition JShowerEH.hh:209
double getEh() const
Get Hadronic energy.
Definition JShowerEH.hh:249
double getBy() const
Get bjorken y.
Definition JShowerEH.hh:107
Data structure for direction in three dimensions.
const JDirection3D & getDirection() const
Get direction.
Data structure for position in three dimensions.
const JPosition3D & getPosition() const
Get position.
Rotation around Z-axis.
Data structure for normalised vector in three dimensions.
Definition JVersor3D.hh:28
double getDY() const
Get y direction.
Definition JVersor3Z.hh:158
double getDX() const
Get x direction.
Definition JVersor3Z.hh:147
General exception.
Definition JException.hh:25
virtual const char * what() const override
Get error message.
Definition JException.hh:65
Custom class for integrated values of the PDF of the arrival time of Cherenkov light.
Definition JNPETable.hh:46
Multi-dimensional PDF table for arrival time of Cherenkov light.
Definition JPDFTable.hh:44
Functional map with polynomial interpolation.
Definition JPolint.hh:1153
Template class for spline interpolation in 1D.
Definition JSpline.hh:734
Auxiliary classes and methods for linear and iterative data regression.
double getChi2(const double P)
Get chi2 corresponding to given probability.
static const JZero zero
Function object to assign zero value.
Definition JZero.hh:105
JPDFType_t
PDF types.
Definition JPDFTypes.hh:24
@ SCATTERED_LIGHT_FROM_EMSHOWER
scattered light from EM shower
Definition JPDFTypes.hh:38
@ SCATTERED_LIGHT_FROM_BRIGHT_POINT
scattered light from bright point
Definition JPDFTypes.hh:43
@ DIRECT_LIGHT_FROM_BRIGHT_POINT
direct light from bright point
Definition JPDFTypes.hh:42
@ DIRECT_LIGHT_FROM_EMSHOWER
direct light from EM shower
Definition JPDFTypes.hh:37
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JPolintMap< 0, JKey_t, JValue_t, JGridMap, typename JResultType< JValue_t >::result_type, JDistance_t > JPolint0FunctionalGridMap
Type definition of a zero degree polynomial interpolation based on a JGridMap implementation.
JPolintMap< 0, JKey_t, JValue_t, JMap, typename JResultType< JValue_t >::result_type, JDistance_t > JPolint0FunctionalMap
Type definition of a zero degree polynomial interpolation based on a JMap implementation.
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition JResult.hh:998
JPolintMap< 1, JKey_t, JValue_t, JMap, typename JResultType< JValue_t >::result_type, JDistance_t > JPolint1FunctionalMap
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.
Auxiliary class for handling PMT geometry, rate and response.
Definition JPMTW0.hh:24
int getN() const
Get number of hits.
Definition JPMTW0.hh:82
double getR() const
Get rate.
Definition JPMTW0.hh:71
Template definition of a data regressor of given model.
Definition JRegressor.hh:70
Auxiliary class for recursive map list generation.
Definition JMapList.hh:109
Map list.
Definition JMapList.hh:25