Jpp  test_elongated_shower_pde
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JNPE_t.hh
Go to the documentation of this file.
1 
2 #include "JLang/JException.hh"
3 #include "JTools/JCollection.hh"
4 #include "JTools/JMap.hh"
5 #include "JTools/JGridMap.hh"
6 #include "JTools/JMapList.hh"
7 #include "JTools/JSpline.hh"
8 #include "JTools/JPolint.hh"
9 #include "JTools/JElement.hh"
10 #include "JPhysics/JNPETable.hh"
11 #include "JPhysics/JPDFTable.hh"
12 #include "JPhysics/JPDFToolkit.hh"
13 #include "JPhysics/JPDFTypes.hh"
14 #include "JPhysics/JGeanz.hh"
15 #include "JMath/JZero.hh"
16 
17 
18 /**
19  * \file
20  *
21  * Auxiliary data structure for muon PDF.
22  * \author mdejong
23  */
24 struct JMuonNPE_t {
25 
30 
31 
32  /**
33  * Constructor.
34  *
35  * The PDF file descriptor should contain the wild card character JPHYSICS::WILD_CARD.\n
36  *
37  * \param fileDescriptor PDF file descriptor
38  */
39  JMuonNPE_t(const std::string& fileDescriptor)
40  {
41  using namespace std;
42  using namespace JPP;
43 
44  const JPDFType_t pdf_t[] = { DIRECT_LIGHT_FROM_MUON,
50 
51  const int N = sizeof(pdf_t) / sizeof(pdf_t[0]);
52 
54  JCollection,
55  double> JFunction1D_t;
56  typedef JPDFTable<JFunction1D_t, JNPEMaplist_t> JPDF_t;
57 
58 
59  const JNPE_t::JSupervisor supervisor(new JNPE_t::JDefaultResult(zero));
60 
61  for (int i = 0; i != N; ++i) {
62 
63  JPDF_t pdf;
64 
65  const JPDFType_t type = pdf_t[i];
66  const string file_name = getFilename(fileDescriptor, type);
67 
68  cout << "loading PDF from file " << file_name << "... " << flush;
69 
70  pdf.load(file_name.c_str());
71 
72  cout << "OK" << endl;
73 
74  pdf.setExceptionHandler(supervisor);
75 
76  if (is_bremsstrahlung(type))
77  YB.push_back(JNPE_t(pdf));
78  else if (is_deltarays(type))
79  YA.push_back(JNPE_t(pdf));
80  else
81  Y1.push_back(JNPE_t(pdf));
82  }
83 
84  // Add PDFs
85 
86  cout << "adding PDFs... " << flush;
87 
88  Y1[1].add(Y1[0]); Y1.erase(Y1.begin());
89  YA[1].add(YA[0]); YA.erase(YA.begin());
90  YB[1].add(YB[0]); YB.erase(YB.begin());
91 
92  cout << "OK" << endl;
93  }
94 
95 
96  /**
97  * Get PDF.
98  *
99  * The orientation of the PMT should be defined according this <a href="https://common.pages.km3net.de/jpp/JPDF.PDF">documentation</a>.\n
100  * In this, the zenith and azimuth angles are limited to \f[\left[0, \pi\right]\f].
101  *
102  * \param E muon energy at minimum distance of approach [GeV]
103  * \param R minimum distance of approach [m]
104  * \param theta PMT zenith angle [rad]
105  * \param phi PMT azimuth angle [rad]
106  * \return number of photo-electrons
107  */
108  double calculate(const double E,
109  const double R,
110  const double theta,
111  const double phi) const
112  {
113  using namespace JPP;
114 
115  const double y1 = getNPE(Y1, R, theta, phi);
116  const double yA = getNPE(YA, R, theta, phi);
117  const double yB = getNPE(YB, R, theta, phi);
118 
120  return y1 + getDeltaRaysFromMuon(E) * yA + E * yB;
121  else
122  return 0.0;
123  }
124 
125 private:
126  std::vector<JNPE_t> Y1; //!< light from muon
127  std::vector<JNPE_t> YA; //!< light from delta-rays
128  std::vector<JNPE_t> YB; //!< light from EM showers
129 
130  /**
131  * Get number of photo-electrons.
132  *
133  * \param NPE NPE tables
134  * \param R distance between muon and PMT [m]
135  * \param theta zenith angle orientation PMT [rad]
136  * \param phi azimuth angle orientation PMT [rad]
137  * \return number of photo-electrons
138  */
139  static inline double getNPE(const std::vector<JNPE_t>& NPE,
140  const double R,
141  const double theta,
142  const double phi)
143  {
144  using namespace std;
145  using namespace JPP;
146 
147  double npe = 0.0;
148 
149  for (vector<JNPE_t>::const_iterator i = NPE.begin(); i != NPE.end(); ++i) {
150 
151  if (R <= i->getXmax()) {
152 
153  try {
154 
155  const double y = get_value((*i)(std::max(R, i->getXmin()), theta, phi));
156 
157  if (y > 0.0) {
158  npe += y;
159  }
160  }
161  catch(const exception& error) {
162  cerr << error.what() << endl;
163  }
164  }
165  }
166 
167  return npe;
168  }
169 };
170 
171 
172 /**
173  * Auxiliary data structure for shower PDF.
174  */
175 struct JShowerNPE_t {
176 
182 
183 
184  /**
185  * Constructor.
186  *
187  * The PDF file descriptor should contain the wild card character JPHYSICS::WILD_CARD.\n
188  *
189  * \param fileDescriptor PDF file descriptor
190  * \param numberOfPoints number of points for shower elongation
191  */
192  JShowerNPE_t(const std::string& fileDescriptor,
193  const int numberOfPoints = 0) :
195  {
196  using namespace std;
197  using namespace JPP;
198 
199  const JPDFType_t pdf_t[] = { SCATTERED_LIGHT_FROM_EMSHOWER,
201 
202  const int N = sizeof(pdf_t) / sizeof(pdf_t[0]);
203 
205  JCollection,
206  double> JFunction1D_t;
207  typedef JPDFTable<JFunction1D_t, JNPEMaplist_t> JPDF_t;
208 
209 
210  const JNPE_t::JSupervisor supervisor(new JNPE_t::JDefaultResult(zero));
211 
212  for (int i = 0; i != N; ++i) {
213 
214  const string file_name = getFilename(fileDescriptor, pdf_t[i]);
215 
216  cout << "loading input from file " << file_name << "... " << flush;
217 
218  JPDF_t pdf;
219 
220  pdf.load(file_name.c_str());
221 
222  pdf.setExceptionHandler(supervisor);
223 
224  if (npe.empty())
225  npe = JNPE_t(pdf);
226  else
227  npe.add(JNPE_t(pdf));
228 
229  F[i] = JNPE_t(pdf);
230 
231  cout << "OK" << endl;
232  }
233  }
234 
235 
236  /**
237  * Get PDF.
238  *
239  * The orientation of the PMT should be defined according this <a href="https://common.pages.km3net.de/jpp/JPDF.PDF">documentation</a>.\n
240  * In this, the zenith and azimuth angles are limited to \f[\left[0, \pi\right]\f].
241  *
242  * \param E shower energy at minimum distance of approach [GeV]
243  * \param D distance [m]
244  * \param cd cosine emission angle
245  * \param theta PMT zenith angle [rad]
246  * \param phi PMT azimuth angle [rad]
247  * \return hypothesis value
248  */
249  double calculate(const double E,
250  const double D,
251  const double cd,
252  const double theta,
253  const double phi) const
254  {
255  using namespace std;
256  using namespace JPP;
257 
258  double Y = 0.0;
259 
260  if (numberOfPoints > 0) {
261 
262  const double W = 1.0 / (double) numberOfPoints;
263 
264  for (int i = 0; i != numberOfPoints; ++i) {
265 
266  const double z = geanz.getLength(E, (i + 0.5) / (double) numberOfPoints);
267 
268  const double __D = sqrt(D*D - 2.0*(D*cd)*z + z*z);
269  const double __cd = (D * cd - z) / __D;
270 
271  try {
272  Y += W * npe (__D, __cd, theta, phi);
273  }
274  catch(const exception& error) {
275  //cerr << error.what() << endl;
276  }
277  }
278 
279  } else {
280 
281  try {
282  Y = npe(D, cd, theta, phi);
283  }
284  catch(const exception& error) {
285  //cerr << error.what() << endl;
286  }
287  }
288 
289  return E * Y;
290  }
291 
292 private:
294  JNPE_t npe; //!< PDF for shower
295  JNPE_t F[2]; //!< PDF for shower
296 };
JPP::JMAPLIST< JPP::JPolint1FunctionalMap, JPP::JPolint1FunctionalMap, JPP::JPolint1FunctionalGridMap, JPP::JPolint1FunctionalGridMap >::maplist JNPEMaplist_t
Definition: JNPE_t.hh:180
Exceptions.
double calculate(const double E, const double R, const double theta, const double phi) const
Get PDF.
Definition: JNPE_t.hh:108
int numberOfPoints
Definition: JNPE_t.hh:293
JShowerNPE_t(const std::string &fileDescriptor, const int numberOfPoints=0)
Constructor.
Definition: JNPE_t.hh:192
Auxiliary methods for PDF calculations.
then usage E
Definition: JMuonPostfit.sh:35
The elements in a collection are sorted according to their abscissa values and a given distance opera...
std::vector< JNPE_t > Y1
light from muon
Definition: JNPE_t.hh:126
JPP::JNPETable< double, double, JNPEMaplist_t > JNPE_t
Definition: JNPE_t.hh:181
scattered light from EM shower
Definition: JPDFTypes.hh:41
JMuonNPE_t(const std::string &fileDescriptor)
Constructor.
Definition: JNPE_t.hh:39
JPP::JNPETable< double, double, JNPEMaplist_t > JNPE_t
Definition: JNPE_t.hh:29
static const double MASS_MUON
muon mass [GeV]
static const double INDEX_OF_REFRACTION_WATER
Average index of refraction of water corresponding to the group velocity.
Auxiliary data structure for shower PDF.
Definition: JNPE_t.hh:175
direct light from EM showers
Definition: JPDFTypes.hh:32
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
JPP::JMAPLIST< JPP::JPolint1FunctionalMap, JPP::JPolint1FunctionalGridMap, JPP::JPolint1FunctionalGridMap >::maplist JNPEMaplist_t
Definition: JNPE_t.hh:28
Definition of zero value for any class.
direct light from muon
Definition: JPDFTypes.hh:29
Numbering scheme for PDF types.
Template class for spline interpolation in 1D.
Definition: JSpline.hh:666
void add(const JNPETable &input)
Add NPE table.
Definition: JNPETable.hh:124
bool is_bremsstrahlung(const int pdf)
Test if given PDF type corresponds to Cherenkov light from Bremsstrahlung.
Definition: JPDFTypes.hh:165
scattered light from muon
Definition: JPDFTypes.hh:30
Type definition of a 1st degree polynomial interpolation based on a JGridMap implementation.
static double getNPE(const std::vector< JNPE_t > &NPE, const double R, const double theta, const double phi)
Get number of photo-electrons.
Definition: JNPE_t.hh:139
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.
static const JGeanz geanz(1.85, 0.62, 0.54)
Function object for longitudinal EM-shower profile.
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.
then awk F
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:43
direct light from delta-rays
Definition: JPDFTypes.hh:35
std::vector< JNPE_t > YB
light from EM showers
Definition: JNPE_t.hh:128
std::vector< JNPE_t > YA
light from delta-rays
Definition: JNPE_t.hh:127
int numberOfPoints
Definition: JResultPDF.cc:22
bool is_deltarays(const int pdf)
Test if given PDF type corresponds to Cherenkov light from delta-rays.
Definition: JPDFTypes.hh:179
double getDeltaRaysFromMuon(const double E)
Equivalent EM-shower energy due to delta-rays per unit muon track length.
Definition: JPDFToolkit.hh:67
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
Longitudinal emission profile EM-shower.
double getLength(const double E, const double P, const double eps=1.0e-3) const
Get shower length for a given integrated probability.
Definition: JGeanz.hh:122
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition: JResult.hh:998
double calculate(const double E, const double D, const double cd, const double theta, const double phi) const
Get PDF.
Definition: JNPE_t.hh:249
JNPE_t npe
PDF for shower.
Definition: JNPE_t.hh:294