Jpp - 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,
48 
49  const int N = sizeof(pdf_t) / sizeof(pdf_t[0]);
50 
52  JCollection,
53  double> JFunction1D_t;
54  typedef JPDFTable<JFunction1D_t, JNPEMaplist_t> JPDF_t;
55 
56 
57  const JNPE_t::JSupervisor supervisor(new JNPE_t::JDefaultResult(zero));
58 
59  for (int i = 0; i != N; ++i) {
60 
61  JPDF_t pdf;
62 
63  const string file_name = getFilename(fileDescriptor, pdf_t[i]);
64 
65  cout << "loading PDF from file " << file_name << "... " << flush;
66 
67  pdf.load(file_name.c_str());
68 
69  cout << "OK" << endl;
70 
71  pdf.setExceptionHandler(supervisor);
72 
73  if (!is_bremsstrahlung(pdf_t[i]))
74  Y1.push_back(JNPE_t(pdf));
75  else
76  YB.push_back(JNPE_t(pdf));
77  }
78 
79  // Add PDFs
80 
81  cout << "adding PDFs... " << flush;
82 
83  Y1[1].add(Y1[0]); Y1.erase(Y1.begin());
84  YB[1].add(YB[0]); YB.erase(YB.begin());
85 
86  cout << "OK" << endl;
87  }
88 
89 
90  /**
91  * Get PDF.
92  *
93  * The orientation of the PMT should be defined according this <a href="https://common.pages.km3net.de/jpp/JPDF.PDF">documentation</a>.\n
94  * In this, the zenith and azimuth angles are limited to \f[\left[0, \pi\right]\f].
95  *
96  * \param E muon energy at minimum distance of approach [GeV]
97  * \param R minimum distance of approach [m]
98  * \param theta PMT zenith angle [rad]
99  * \param phi PMT azimuth angle [rad]
100  * \return number of photo-electrons
101  */
102  double calculate(const double E,
103  const double R,
104  const double theta,
105  const double phi) const
106  {
107  using namespace JPP;
108 
109  const double yA = getNPE(Y1, R, theta, phi);
110  const double yB = getNPE(YB, R, theta, phi);
111 
113  return yA + E * yB;
114  else
115  return 0.0;
116  }
117 
118 private:
119  std::vector<JNPE_t> Y1; //!< light from muon
120  std::vector<JNPE_t> YB; //!< light from EM showers
121 
122  /**
123  * Get number of photo-electrons.
124  *
125  * \param NPE NPE tables
126  * \param R distance between muon and PMT [m]
127  * \param theta zenith angle orientation PMT [rad]
128  * \param phi azimuth angle orientation PMT [rad]
129  * \return number of photo-electrons
130  */
131  static inline double getNPE(const std::vector<JNPE_t>& NPE,
132  const double R,
133  const double theta,
134  const double phi)
135  {
136  using namespace std;
137  using namespace JPP;
138 
139  double npe = 0.0;
140 
141  for (vector<JNPE_t>::const_iterator i = NPE.begin(); i != NPE.end(); ++i) {
142 
143  if (R <= i->getXmax()) {
144 
145  try {
146 
147  const double y = get_value((*i)(std::max(R, i->getXmin()), theta, phi));
148 
149  if (y > 0.0) {
150  npe += y;
151  }
152  }
153  catch(const exception& error) {
154  cerr << error.what() << endl;
155  }
156  }
157  }
158 
159  return npe;
160  }
161 };
162 
163 
164 /**
165  * Auxiliary data structure for shower PDF.
166  */
167 struct JShowerNPE_t {
168 
174 
175 
176  /**
177  * Constructor.
178  *
179  * The PDF file descriptor should contain the wild card character JPHYSICS::WILD_CARD.\n
180  *
181  * \param fileDescriptor PDF file descriptor
182  * \param numberOfPoints number of points for shower elongation
183  */
184  JShowerNPE_t(const std::string& fileDescriptor,
185  const int numberOfPoints = 0) :
187  {
188  using namespace std;
189  using namespace JPP;
190 
191  const JPDFType_t pdf_t[] = { SCATTERED_LIGHT_FROM_EMSHOWER,
193 
194  const int N = sizeof(pdf_t) / sizeof(pdf_t[0]);
195 
197  JCollection,
198  double> JFunction1D_t;
199  typedef JPDFTable<JFunction1D_t, JNPEMaplist_t> JPDF_t;
200 
201 
202  const JNPE_t::JSupervisor supervisor(new JNPE_t::JDefaultResult(zero));
203 
204  for (int i = 0; i != N; ++i) {
205 
206  const string file_name = getFilename(fileDescriptor, pdf_t[i]);
207 
208  cout << "loading input from file " << file_name << "... " << flush;
209 
210  JPDF_t pdf;
211 
212  pdf.load(file_name.c_str());
213 
214  pdf.setExceptionHandler(supervisor);
215 
216  if (npe.empty())
217  npe = JNPE_t(pdf);
218  else
219  npe.add(JNPE_t(pdf));
220 
221  F[i] = JNPE_t(pdf);
222 
223  cout << "OK" << endl;
224  }
225  }
226 
227 
228  /**
229  * Get PDF.
230  *
231  * The orientation of the PMT should be defined according this <a href="https://common.pages.km3net.de/jpp/JPDF.PDF">documentation</a>.\n
232  * In this, the zenith and azimuth angles are limited to \f[\left[0, \pi\right]\f].
233  *
234  * \param E shower energy at minimum distance of approach [GeV]
235  * \param D distance [m]
236  * \param cd cosine emission angle
237  * \param theta PMT zenith angle [rad]
238  * \param phi PMT azimuth angle [rad]
239  * \return hypothesis value
240  */
241  double calculate(const double E,
242  const double D,
243  const double cd,
244  const double theta,
245  const double phi) const
246  {
247  using namespace std;
248  using namespace JPP;
249 
250  double Y = 0.0;
251 
252  if (numberOfPoints > 0) {
253 
254  const double W = 1.0 / (double) numberOfPoints;
255 
256  for (int i = 0; i != numberOfPoints; ++i) {
257 
258  const double z = geanz.getLength(E, (i + 0.5) / (double) numberOfPoints);
259 
260  const double __D = sqrt(D*D - 2.0*(D*cd)*z + z*z);
261  const double __cd = (D * cd - z) / __D;
262 
263  try {
264  Y += W * npe (__D, __cd, theta, phi);
265  }
266  catch(const exception& error) {
267  //cerr << error.what() << endl;
268  }
269  }
270 
271  } else {
272 
273  try {
274  Y = npe(D, cd, theta, phi);
275  }
276  catch(const exception& error) {
277  //cerr << error.what() << endl;
278  }
279  }
280 
281  return E * Y;
282  }
283 
284 private:
286  JNPE_t npe; //!< PDF for shower
287  JNPE_t F[2]; //!< PDF for shower
288 };
JPP::JMAPLIST< JPP::JPolint1FunctionalMap, JPP::JPolint1FunctionalMap, JPP::JPolint1FunctionalGridMap, JPP::JPolint1FunctionalGridMap >::maplist JNPEMaplist_t
Definition: JNPE_t.hh:172
Exceptions.
double calculate(const double E, const double R, const double theta, const double phi) const
Get PDF.
Definition: JNPE_t.hh:102
do echo Generating $dir eval D
Definition: JDrawLED.sh:50
int numberOfPoints
Definition: JNPE_t.hh:285
JShowerNPE_t(const std::string &fileDescriptor, const int numberOfPoints=0)
Constructor.
Definition: JNPE_t.hh:184
Auxiliary methods for PDF calculations.
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:119
JPP::JNPETable< double, double, JNPEMaplist_t > JNPE_t
Definition: JNPE_t.hh:173
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:167
direct light from EM showers
Definition: JPDFTypes.hh:32
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:657
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:163
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:131
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.
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 echo Variable JPP_DIR undefined exit fi source $JPP_DIR setenv sh $JPP_DIR set_variable NORTH set_variable EAST set_variable SOUTH set_variable WEST set_variable WORKDIR tmp set_variable R set_variable CT set_variable YMAX set_variable YMIN if do_usage *then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:35
std::vector< JNPE_t > YB
light from EM showers
Definition: JNPE_t.hh:120
int numberOfPoints
Definition: JResultPDF.cc:22
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
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition: JMuonPostfit.sh:35
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:241
then usage $script[input file[working directory[option]]] nWhere option can be E
Definition: JMuonPostfit.sh:35
JNPE_t npe
PDF for shower.
Definition: JNPE_t.hh:286