Jpp  test_elongated_shower_pde
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMakePDE.cc File Reference

Program to create interpolation tables of the PDF of the arrival time of the Cherenkov light from a shower. More...

#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <set>
#include <cmath>
#include "JTools/JFunction1D_t.hh"
#include "JTools/JFunctionalMap_t.hh"
#include "JTools/JMultiMapTransformer.hh"
#include "JTools/JQuadrature.hh"
#include "JPhysics/JPDFTable.hh"
#include "JPhysics/JPDFTypes.hh"
#include "JPhysics/JGeanx.hh"
#include "JPhysics/JGeanz.hh"
#include "JSystem/JSystemToolkit.hh"
#include "Jeep/JTimer.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JConstants.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Program to create interpolation tables of the PDF of the arrival time of the Cherenkov light from a shower.

The PDFs are tabulated as a function of (E, D, cos(theta), theta, phi, t), where:

The orientation of the PMT is defined in the coordinate system in which the shower developes along the z-axis and the PMT is located in the x-z plane.

Author
jseneca, mdejong

Definition in file JMakePDE.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 42 of file JMakePDE.cc.

43 {
44  using namespace std;
45  using namespace JPP;
46 
47  string fileDescriptor;
48  string outputFile;
49  int numberOfPoints;
50  size_t elong_sample_count;
51  size_t cosine_angle_count; // Cosine angle is not as sharp when elongated
52  double epsilon;
53  double TTS;
54  set<double> Ds; // distance [m]
55  set<double> Es; // logarithm of energy (GeV)
56  bool option;
57  int debug;
58 
59  try {
60 
61  JParser<> zap("Program to create interpolation tables of the PDF of the arrival time of the Cherenkov light from a shower.");
62 
63  zap['F'] = make_field(fileDescriptor, "file name descriptor for PDF tables");
64  zap['o'] = make_field(outputFile, "file name output PDF");
65  zap['n'] = make_field(numberOfPoints, "points for integration") = 25;
66  zap['e'] = make_field(epsilon, "precision for integration") = 1.0e-10;
67  zap['D'] = make_field(Ds, "distance [m]") = JPARSER::initialised();
68  zap['E'] = make_field(Es, "energy [log10(GeV)]") = JPARSER::initialised();
69  zap['C'] = make_field(cosine_angle_count, "points for cosine angle") = 60;
70  zap['N'] = make_field(elong_sample_count, "points for elongation") = 20;
71  zap['T'] = make_field(TTS, "sigma of time bluring [ns]") = 2.0;
72  zap['O'] = make_field(option, "optional transfomation");
73  zap['d'] = make_field(debug) = 0;
74 
75  zap(argc, argv);
76  }
77  catch(const exception &error) {
78  FATAL(error.what() << endl);
79  }
80 
81  typedef JPolint1Function1D_t JFunction1D_t;
82 
83  typedef JMAPLIST<JPolint1FunctionalMap,
84  JPolint1FunctionalMap,
85  JPolint1FunctionalGridMap,
86  JPolint1FunctionalGridMap>::maplist J4DMapList_t;
87 
88  typedef JMAPLIST<JPolint1FunctionalMap,
89  JPolint1FunctionalMap,
90  JPolint1FunctionalMap,
91  JPolint1FunctionalGridMap,
92  JPolint1FunctionalGridMap>::maplist J5DMapList_t;
93 
94  typedef JPDFTable<JFunction1D_t, J4DMapList_t> JPDF4d_t;
95  typedef JPDFTable<JFunction1D_t, J5DMapList_t> JPDF5d_t;
96 
97  typedef JPDFTransformer<4, JFunction1D_t::argument_type> JFunction4DTransformer_t;
98  typedef JPDFTransformer<5, JFunction1D_t::argument_type> JFunction5DTransformer_t;
99  typedef JArray<5, JFunction1D_t::argument_type> JArray_t;
100 
101  JPDF4d_t i_pdf;
102 
103  NOTICE("Memory " << FIXED(5,1) << getMemoryUsage() << "%" << endl);
104  {
105  const string file_name = getFilename(fileDescriptor, SCATTERED_LIGHT_FROM_EMSHOWER);
106 
107  NOTICE("loading input from file " << file_name << "... " << flush);
108 
109  i_pdf.load(file_name.c_str());
110 
111  NOTICE("OK" << endl);
112  }
113  NOTICE("Memory " << FIXED(5,1) << getMemoryUsage() << "%" << endl);
114  {
115  JPDF4d_t pdf;
116 
117  const string file_name = getFilename(fileDescriptor, DIRECT_LIGHT_FROM_EMSHOWER);
118 
119  NOTICE("loading input from file " << file_name << "... " << flush);
120 
121  pdf.load(file_name.c_str());
122 
123  NOTICE("OK" << endl);
124  NOTICE("Memory " << FIXED(5,1) << getMemoryUsage() << "%" << endl);
125 
126  pdf.setExceptionHandler(new JPDF4d_t::JDefaultResult(JMATH::zero));
127 
128  NOTICE("Add PDF... " << flush);
129 
130  JTimer timer;
131 
132  timer.start();
133 
134  i_pdf.add(pdf);
135 
136  timer.stop();
137 
138  if (debug >= debug_t) {
139  timer.print(cout, unit_t);
140  }
141 
142  NOTICE("OK" << endl);
143  }
144  NOTICE("Memory " << FIXED(5,1) << getMemoryUsage() << "%" << endl);
145 
146  i_pdf.setExceptionHandler(new JPDF4d_t::JDefaultResult(JMATH::zero));
147 
148  if ( TTS > 0.0 ){
149  NOTICE("Smearing combined table with sigma [ns] = " << TTS );
150  i_pdf.blur( TTS );
151  }
152 
153  JPDF5d_t o_pdf;
154 
155  const JFunction4DTransformer_t* i_transformer = dynamic_cast<JFunction4DTransformer_t*>(i_pdf.transformer->clone());
156  const JFunction5DTransformer_t* o_transformer = (i_transformer != NULL ? new JFunction5DTransformer_t(*i_transformer) : NULL);
157 
158  if (o_transformer != NULL && debug >= debug_t) {
159  o_transformer->print(cout);
160  }
161 
162  NOTICE("building multi-dimensional function object" << flush); DEBUG(endl);
163 
164 
165  if (Es.empty()) {
166  Es.insert( 1.0 );
167  Es.insert( 2.0 );
168  Es.insert( 3.0 );
169  Es.insert( 3.5 );
170  Es.insert( 4.0 );
171  Es.insert( 4.5 );
172  Es.insert( 5.0 );
173  Es.insert( 5.5 );
174  Es.insert( 6.0 );
175  Es.insert( 6.5 );
176  Es.insert( 7.0 );
177  Es.insert( 7.5 );
178  Es.insert( 8.0 );
179  };
180 
181  if (Ds.empty()) {
182  Ds.insert( 0.10);
183  Ds.insert( 0.50);
184  Ds.insert( 1.00);
185  Ds.insert( 2.00);
186  Ds.insert( 5.00);
187  Ds.insert( 8.00);
188  Ds.insert( 10.00);
189  Ds.insert( 20.00);
190  Ds.insert( 30.00);
191  Ds.insert( 40.00);
192  Ds.insert( 50.00);
193  Ds.insert( 60.00);
194  Ds.insert( 70.00);
195  Ds.insert( 80.00);
196  Ds.insert( 90.00);
197  Ds.insert(100.00);
198  Ds.insert(120.00);
199  Ds.insert(150.00);
200  Ds.insert(170.00);
201  Ds.insert(190.00);
202  Ds.insert(210.00);
203  Ds.insert(230.00);
204  Ds.insert(250.00);
205  Ds.insert(270.00);
206  Ds.insert(290.00);
207  Ds.insert(310.00);
208  Ds.insert(400.00);
209  Ds.insert(800.00); // ARCA is big, we go to 800 m
210  }
211 
212  set<double> C; // cosine emission angle
213 
214  JQuadrature qeant(-1.0, +1.0, cosine_angle_count, geanx);
215 
216  for (JQuadrature::const_iterator i = qeant.begin(); i != qeant.end(); ++i) {
217  C.insert(i->getX());
218  }
219 
220  C.insert(-1.00);
221  C.insert(+1.00);
222 
223  set<double> X; // time [ns]
224 
225  X.insert( 0.00);
226  X.insert( 0.50);
227  X.insert( 1.00);
228  X.insert( 1.50);
229  X.insert( 2.00);
230  X.insert( 2.50);
231  X.insert( 3.00);
232  X.insert( 3.50);
233  X.insert( 4.00);
234  X.insert( 5.0);
235  X.insert( 6.0);
236  X.insert( 8.0);
237  X.insert( 10.0);
238  X.insert( 15.0);
239  X.insert( 20.0);
240  X.insert( 25.0);
241  X.insert( 30.0);
242  X.insert( 40.0);
243  X.insert( 50.0);
244  X.insert( 60.0);
245  X.insert( 80.0);
246  X.insert(100.0);
247  X.insert(120.0);
248  X.insert(150.0);
249  X.insert(200.0);
250  X.insert(250.0);
251  X.insert(300.0);
252  X.insert(350.0);
253  X.insert(400.0);
254  X.insert(450.0);
255  X.insert(500.0);
256  X.insert(600.0);
257  X.insert(700.0);
258  X.insert(800.0);
259  X.insert(900.0);
260  X.insert(1200.0);
261  X.insert(1500.0);
262 
263  const double grid = 7.0; // [deg]
264  const double alpha = 2.0 * sqrt(1.0 - cos(grid * PI / 180.0)); // azimuth angle unit step size
265 
266  for (const double E : Es) {
267 
268  DEBUG("E: " << E << endl);
269 
270  vector< double > elong_lengths;
271 
272  for (size_t i = 0; i != elong_sample_count ; ++i ){
273 
274  const double fraction = (double) (i + 0.5) / (double) elong_sample_count;
275  const double len = geanz.getLength(pow(10.0, E), fraction, 1e-6);
276 
277  DEBUG("fraction: " << fraction << ", length [m]: "<< len << endl);
278 
279  elong_lengths.push_back(len);
280  }
281 
282  for (const double D_m : Ds) {
283 
284  DEBUG("D_m: " << D_m << endl);
285 
286  for (const double cd : C) {
287 
288  NOTICE("Memory " << FIXED(5,1) << getMemoryUsage() << "%" << endl);
289 
290  const unsigned int number_of_theta_points = max(2u, (unsigned int) (180.0/(1.4 * grid)));
291 
292  for (double theta = 0.0; theta <= PI + epsilon; theta += PI/number_of_theta_points) {
293 
294  const unsigned int number_of_phi_points = max(2u, (unsigned int) (PI * sin(theta) / alpha));
295 
296  for (double phi = 0.0; phi <= PI + epsilon; phi += PI/number_of_phi_points) {
297 
298  JFunction1D_t& f1 = o_pdf[E][D_m][cd][theta][phi];
299 
300  const JArray_t array(E, D_m, cd, theta, phi);
301 
302  double t_old = (o_transformer != NULL ? o_transformer->getXn(array, *X.begin()) : *X.begin());
303  double y_old = 0.0;
304 
305  for (set<double>::const_iterator x = X.begin(); x != X.end(); ++x) {
306 
307  const double t = (o_transformer != NULL ? o_transformer->getXn(array, *x) : *x);
308 
309  double y = 0.0;
310 
311  for( vector< double >::iterator ilen = elong_lengths.begin(); ilen != elong_lengths.end(); ++ilen ){
312 
313  const double Z0 = cd * D_m;
314  const double Z1 = Z0 - *ilen;
315 
316  const double D_m_prime = sqrt( D_m * D_m + Z1 * Z1 - Z0 * Z0 );
317  const double cd_prime = Z1 / D_m_prime;
318  const double t_prime = t - (*ilen) / getSpeedOfLight() - ( D_m_prime - D_m ) * getIndexOfRefraction() / getSpeedOfLight();
319 
320  y += i_pdf(D_m_prime, cd_prime, theta, phi, t_prime);
321  }
322 
323  y /= (float) elong_sample_count;
324 
325  if (y != 0.0) {
326 
327  if (*x < 0.0) {
328  WARNING("dt < 0 " << *x << ' ' << D_m << ' ' << t << ' ' << y << endl);
329  }
330 
331  if (y_old == 0.0) {
332  f1[t_old] = y_old;
333  }
334 
335  f1[t] = y;
336 
337  } else {
338 
339  if (y_old != 0.0) {
340  f1[t] = y;
341  }
342  }
343 
344  t_old = t;
345  y_old = y;
346  }
347  }
348  }
349  }
350  }
351  }
352  NOTICE("OK" << endl);
353  NOTICE("Memory " << FIXED(5,1) << getMemoryUsage() << "%" << endl);
354 
355  o_pdf.compile();
356 
357  if (o_transformer != NULL && option) {
358 
359  NOTICE("transform... " << flush);
360 
361  o_pdf.transform(*o_transformer);
362 
363  NOTICE("OK" << endl);
364  }
365 
366  try {
367 
368  NOTICE("storing output to file " << outputFile << "... " << flush);
369 
370  o_pdf.store(outputFile.c_str());
371 
372  NOTICE("OK" << endl);
373  }
374  catch(const JException& error) {
375  FATAL(error.what() << endl);
376  }
377 }
Utility class to parse command line options.
Definition: JParser.hh:1500
#define WARNING(A)
Definition: JMessage.hh:65
float getMemoryUsage(JShell &shell, const pid_t pid)
Get memory usage in percent of given process identifier.
debug
Definition: JMessage.hh:29
then usage E
Definition: JMuonPostfit.sh:35
double getIndexOfRefraction()
Get average index of refraction of water corresponding to group velocity.
scattered light from EM shower
Definition: JPDFTypes.hh:41
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
static const double C
Physics constants.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
static const JGeanz geanz(1.85, 0.62, 0.54)
Function object for longitudinal EM-shower profile.
#define NOTICE(A)
Definition: JMessage.hh:64
T pow(const T &x, const double y)
Power .
Definition: JMath.hh:98
then break fi done getCenter read X Y Z let X
direct light from EM shower
Definition: JPDFTypes.hh:40
static const double PI
Mathematical constants.
int debug
debug level
Definition: JSirene.cc:68
#define FATAL(A)
Definition: JMessage.hh:67
const double getSpeedOfLight()
Get speed of light.
static const JGeanx geanx(0.35,-5.40)
Function object for the number of photons from EM-shower as a function of emission angle...
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
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
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
double u[N+1]
Definition: JPolint.hh:755
unit
Definition: JScale.hh:31