Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPDF_t.hh
Go to the documentation of this file.
1 #include "JLang/JException.hh"
2 #include "JTools/JCollection.hh"
3 #include "JTools/JMap.hh"
4 #include "JTools/JGridMap.hh"
5 #include "JTools/JMapList.hh"
6 #include "JTools/JSpline.hh"
7 #include "JTools/JPolint.hh"
8 #include "JTools/JElement.hh"
9 #include "JTools/JResult.hh"
10 #include "JPhysics/JPDFTable.hh"
11 #include "JPhysics/JPDFToolkit.hh"
12 #include "JPhysics/JPDFTypes.hh"
13 #include "JMath/JZero.hh"
14 
15 
16 /**
17  * \file
18  *
19  * Auxiliary data structure for muon PDF.
20  * \author mdejong
21  */
22 struct JMuonPDF_t {
23 
27 
33 
34 
35  /**
36  * Constructor.
37  *
38  * The PDF file descriptor should contain the wild card character JPHYSICS::WILD_CARD.\n
39  * The <tt>TTS</tt> corresponds to the additional time smearing applied to the PDFs.
40  *
41  * \param fileDescriptor PDF file descriptor
42  * \param TTS TTS [ns]
43  * \param numberOfPoints number of points for Gauss-Hermite integration of TTS
44  * \param epsilon precision for Gauss-Hermite integration of TTS
45  */
46  JMuonPDF_t(const std::string& fileDescriptor,
47  const double TTS,
48  const int numberOfPoints = 25,
49  const double epsilon = 1.0e-10)
50  {
51  using namespace std;
52  using namespace JPP;
53 
54  const JPDFType_t pdf_t[] = { DIRECT_LIGHT_FROM_MUON,
60 
61  const int N = sizeof(pdf_t) / sizeof(pdf_t[0]);
62 
63  JPDF_t pdf[N];
64 
65  const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(zero));
66 
67  for (int i = 0; i != N; ++i) {
68 
69  const string file_name = getFilename(fileDescriptor, pdf_t[i]);
70 
71  cout << "loading input from file " << file_name << "... " << flush;
72 
73  pdf[i].load(file_name.c_str());
74 
75  pdf[i].setExceptionHandler(supervisor);
76 
77  cout << "OK" << endl;
78  }
79 
80  // Add PDFs
81 
82  cout << "adding PDFs... " << flush;
83 
84  pdfA = pdf[1]; pdfA.add(pdf[0]);
85  pdfB = pdf[3]; pdfB.add(pdf[2]);
86  pdfC = pdf[5]; pdfC.add(pdf[4]);
87 
88  cout << "OK" << endl;
89 
90  if (TTS > 0.0) {
91 
92  cout << "bluring PDFs... " << flush;
93 
94  pdfA.blur(TTS, numberOfPoints, epsilon);
95  pdfB.blur(TTS, numberOfPoints, epsilon);
96  pdfC.blur(TTS, numberOfPoints, epsilon);
97 
98  cout << "OK" << endl;
99 
100  } else if (TTS < 0.0) {
101 
102  THROW(JValueOutOfRange, "Illegal value of TTS [ns]: " << TTS);
103  }
104  }
105 
106 
107  /**
108  * Get PDF.
109  *
110  * The orientation of the PMT should be defined according this <a href="https://common.pages.km3net.de/jpp/JPDF.PDF">documentation</a>.\n
111  * In this, the zenith and azimuth angles are limited to \f[\left[0, \pi\right]\f].
112  *
113  * \param E muon energy at minimum distance of approach [GeV]
114  * \param R minimum distance of approach [m]
115  * \param theta PMT zenith angle [rad]
116  * \param phi PMT azimuth angle [rad]
117  * \param t1 arrival time relative to Cherenkov hypothesis [ns]
118  * \return hypothesis value
119  */
120  result_type calculate(const double E,
121  const double R,
122  const double theta,
123  const double phi,
124  const double t1) const
125  {
126  using namespace JPP;
127 
128  result_type h1 = (pdfA(R, theta, phi, t1) +
129  pdfB(R, theta, phi, t1) * E +
130  pdfC(R, theta, phi, t1) * getDeltaRaysFromMuon(E));
131 
132  // safety measures
133 
134  if (h1.f <= 0.0) {
135  h1.f = 0.0;
136  h1.fp = 0.0;
137  }
138 
139  if (h1.v <= 0.0) {
140  h1.v = 0.0;
141  }
142 
143  return h1;
144  }
145 
146  JPDF_t pdfA; //!< PDF for minimum ionisong particle
147  JPDF_t pdfB; //!< PDF for average energy losses
148  JPDF_t pdfC; //!< PDF for delta-rays
149 };
150 
151 
152 /**
153  * Auxiliary data structure for shower PDF.
154  */
155 struct JShowerPDF_t {
156 
160 
167 
168 
169  /**
170  * Constructor.
171  *
172  * The PDF file descriptor should contain the wild card character JPHYSICS::WILD_CARD.\n
173  * The <tt>TTS</tt> corresponds to the additional time smearing applied to the PDFs.
174  *
175  * \param fileDescriptor PDF file descriptor
176  * \param TTS TTS [ns]
177  * \param numberOfPoints number of points for Gauss-Hermite integration of TTS
178  * \param epsilon precision for Gauss-Hermite integration of TTS
179  */
180  JShowerPDF_t(const std::string& fileDescriptor,
181  const double TTS,
182  const int numberOfPoints = 25,
183  const double epsilon = 1.0e-10)
184  {
185  using namespace std;
186  using namespace JPP;
187 
188  const JPDFType_t pdf_t[] = { SCATTERED_LIGHT_FROM_EMSHOWER,
190 
191  const int N = sizeof(pdf_t) / sizeof(pdf_t[0]);
192 
193  const JPDF_t::JSupervisor supervisor(new JPDF_t::JDefaultResult(zero));
194 
195  for (int i = 0; i != N; ++i) {
196 
197  const string file_name = getFilename(fileDescriptor, pdf_t[i]);
198 
199  cout << "loading input from file " << file_name << "... " << flush;
200 
201  JPDF_t pdf;
202 
203  pdf.load(file_name.c_str());
204 
205  pdf.setExceptionHandler(supervisor);
206 
207  if (pdfA.empty())
208  pdfA = pdf;
209  else
210  pdfA.add(pdf);
211 
212  cout << "OK" << endl;
213  }
214 
215  if (TTS > 0.0) {
216 
217  cout << "bluring PDFs... " << flush;
218 
219  pdfA.blur(TTS, numberOfPoints, epsilon);
220 
221  cout << "OK" << endl;
222 
223  } else if (TTS < 0.0) {
224 
225  THROW(JValueOutOfRange, "Illegal value of TTS [ns]: " << TTS);
226  }
227  }
228 
229 
230  /**
231  * Get PDF.
232  *
233  * The orientation of the PMT should be defined according this <a href="https://common.pages.km3net.de/jpp/JPDF.PDF">documentation</a>.\n
234  * In this, the zenith and azimuth angles are limited to \f[\left[0, \pi\right]\f].
235  *
236  * \param E shower energy at minimum distance of approach [GeV]
237  * \param D distance [m]
238  * \param cd cosine emission angle
239  * \param theta PMT zenith angle [rad]
240  * \param phi PMT azimuth angle [rad]
241  * \param t1 arrival time relative to Cherenkov hypothesis [ns]
242  * \return hypothesis value
243  */
244  result_type calculate(const double E,
245  const double D,
246  const double cd,
247  const double theta,
248  const double phi,
249  const double t1) const
250  {
251  using namespace JPP;
252 
253  result_type h1 = pdfA(D, cd, theta, phi, t1) * E;
254 
255  // safety measures
256 
257  if (h1.f <= 0.0) {
258  h1.f = 0.0;
259  h1.fp = 0.0;
260  }
261 
262  if (h1.v <= 0.0) {
263  h1.v = 0.0;
264  }
265 
266  return h1;
267  }
268 
269  JPDF_t pdfA; //!< PDF for shower
270 };
void load(const char *file_name)
Load from input file.
Exceptions.
do echo Generating $dir eval D
Definition: JDrawLED.sh:50
JPP::JPDFTable< JFunction1D_t, JPDFMaplist_t > JPDF_t
Definition: JPDF_t.hh:31
JPP::JMAPLIST< JPP::JPolint1FunctionalMap, JPP::JPolint1FunctionalMap, JPP::JPolint0FunctionalGridMap, JPP::JPolint0FunctionalGridMap >::maplist JPDFMaplist_t
Definition: JPDF_t.hh:164
Auxiliary methods for PDF calculations.
General purpose class for collection of elements, see: &lt;a href=&quot;JTools.PDF&quot;;&gt;Collection of elements...
Definition: JCollection.hh:73
The elements in a collection are sorted according to their abscissa values and a given distance opera...
This include file containes various data structures that can be used as specific return types for the...
scattered light from EM shower
Definition: JPDFTypes.hh:41
JPP::JSplineFunction1D< JPP::JSplineElement2S< double, double >, JPP::JCollection, JPP::JResultPDF< double > > JFunction1D_t
Definition: JPDF_t.hh:26
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
direct light from EM showers
Definition: JPDFTypes.hh:32
void setExceptionHandler(const supervisor_type &supervisor)
Set the supervisor for handling of exceptions.
void blur(const double TTS, const int numberOfPoints=25, const double epsilon=1.0e-10, const double quantile=0.99)
Blur PDF.
Definition: JPDFTable.hh:110
JPDF_t pdfA
PDF for shower.
Definition: JPDF_t.hh:269
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
Definition of zero value for any class.
Auxiliary data structure for shower PDF.
Definition: JPDF_t.hh:155
JPP::JMAPLIST< JPP::JPolint1FunctionalMap, JPP::JPolint0FunctionalGridMap, JPP::JPolint0FunctionalGridMap >::maplist JPDFMaplist_t
Definition: JPDF_t.hh:30
direct light from muon
Definition: JPDFTypes.hh:29
JMuonPDF_t(const std::string &fileDescriptor, const double TTS, const int numberOfPoints=25, const double epsilon=1.0e-10)
Constructor.
Definition: JPDF_t.hh:46
Numbering scheme for PDF types.
Template class for spline interpolation in 1D.
Definition: JSpline.hh:657
result_type calculate(const double E, const double R, const double theta, const double phi, const double t1) const
Get PDF.
Definition: JPDF_t.hh:120
scattered light from muon
Definition: JPDFTypes.hh:30
JFunction1D_t::result_type result_type
Definition: JPDF_t.hh:166
JFunction1D_t::result_type result_type
Definition: JPDF_t.hh:32
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.
JPDF_t pdfB
PDF for average energy losses.
Definition: JPDF_t.hh:147
Data structure for result including value, first derivative and integrals of function.
Definition: JResult.hh:337
void add(const JMultiFunction_t &input)
Add function.
function_type::result_type result_type
Definition: JSpline.hh:678
result_type calculate(const double E, const double D, const double cd, const double theta, const double phi, const double t1) const
Get PDF.
Definition: JPDF_t.hh:244
scattered light from delta-rays
Definition: JPDFTypes.hh:36
direct light from EM shower
Definition: JPDFTypes.hh:40
scattered light from EM showers
Definition: JPDFTypes.hh:33
General purpose class for a collection of sorted elements.
JPDFType_t
PDF types.
Definition: JPDFTypes.hh:27
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:108
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:40
JPDF_t pdfC
PDF for delta-rays.
Definition: JPDF_t.hh:148
direct light from delta-rays
Definition: JPDFTypes.hh:35
Type definition of a zero degree polynomial interpolation based on a JGridMap implementation.
int numberOfPoints
Definition: JResultPDF.cc:22
double getDeltaRaysFromMuon(const double E)
Equivalent EM-shower energy due to delta-rays per unit muon track length.
Definition: JPDFToolkit.hh:75
std::string getFilename(const std::string &file_name)
Get file name part, i.e. part after last JEEP::PATHNAME_SEPARATOR if any.
Definition: JeepToolkit.hh:88
JShowerPDF_t(const std::string &fileDescriptor, const double TTS, const int numberOfPoints=25, const double epsilon=1.0e-10)
Constructor.
Definition: JPDF_t.hh:180
JPDF_t pdfA
PDF for minimum ionisong particle.
Definition: JPDF_t.hh:146
JPP::JSplineFunction1D< JPP::JSplineElement2S< double, double >, JPP::JCollection, JPP::JResultPDF< double > > JFunction1D_t
Definition: JPDF_t.hh:159
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition: JMuonPostfit.sh:37
then usage $script[input file[working directory[option]]] nWhere option can be E
Definition: JMuonPostfit.sh:37
JPP::JPDFTable< JFunction1D_t, JPDFMaplist_t > JPDF_t
Definition: JPDF_t.hh:165