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