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
JHistHDG.cc File Reference

Program to histogram event-by-event data of shower light for making PDFs. More...

#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/offline/Hit.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JPhysics/JPDFToolkit.hh"
#include "JPhysics/JDispersion.hh"
#include "JPhysics/Antares.hh"
#include "JPhysics/KM3NeT.hh"
#include "JIO/JFileStreamIO.hh"
#include "JGeometry3D/JGeometry3DToolkit.hh"
#include "JGeometry3D/JPosition3D.hh"
#include "JGeometry3D/JDirection3D.hh"
#include "JGeometry3D/JAxis3D.hh"
#include "JPhysics/JConstants.hh"
#include "JTools/JHistogram1D_t.hh"
#include "JTools/JHistogramMap_t.hh"
#include "JTools/JTransformableMultiHistogram.hh"
#include "JTools/JFunction1D_t.hh"
#include "JTools/JFunctionalMap_t.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JPMTRouter.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JPhysics/JPDFTransformer.hh"
#include "JPhysics/JPDF.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Program to histogram event-by-event data of shower light for making PDFs.

Author
lquinn

Definition in file JHistHDG.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 51 of file JHistHDG.cc.

52 {
53  using namespace std;
54  using namespace JPP;
55 
56  JMultipleFileScanner<Evt> inputFile;
57  JLimit_t& numberOfEvents = inputFile.getLimit();
58  string outputFile;
59  string detectorFile;
60  bool hadronicMode;
61  int debug;
62 
63  try {
64 
65  JParser<> zap("Program to histogram event-by-event data of shower light for making PDFs.");
66 
67  zap['f'] = make_field(inputFile);
68  zap['o'] = make_field(outputFile);
69  zap['n'] = make_field(numberOfEvents) = JLimit::max();
70  zap['a'] = make_field(detectorFile);
71  zap['H'] = make_field(hadronicMode);
72  zap['d'] = make_field(debug) = 1;
73 
74  zap(argc, argv);
75  }
76  catch(const exception &error) {
77  FATAL(error.what() << endl);
78  }
79 
80  if(hadronicMode) {
81  NOTICE("Plotting hadronic showers." << endl);
82  } else {
83  NOTICE("Plotting EM showers." << endl);
84  }
85 
86 
88 
89  try {
90  load(detectorFile, detector);
91  }
92  catch(const JException& error) {
93  FATAL(error);
94  }
95 
96  const JPosition3D center = get<JPosition3D>(getHeader(inputFile));
97 
98  NOTICE("Apply detector offset " << center << endl);
99 
100  detector -= center;
101 
102  const JPMTRouter pmtRouter(detector);
103 
104  const double P_atm = NAMESPACE::getAmbientPressure();
105  const double wmin = getMinimalWavelength();
106  const double wmax = getMaximalWavelength();
107 
108  const JDispersion dispersion(P_atm);
109 
110  const double ng[] = { dispersion.getIndexOfRefractionGroup(wmax),
111  dispersion.getIndexOfRefractionGroup(wmin) };
112 
113  typedef JHistogram1D_t::abscissa_type abscissa_type;
114 
119  JHistogramGridMap_t>::maplist> JMultiHistogram_t;
120 
121  typedef JPDFTransformer<4, abscissa_type> JFunction4DTransformer_t;
122 
123  JMultiHistogram_t h0; // occurrence rate of PMT (used for normalisation)
124  JMultiHistogram_t h1; // light from cascade
125 
126  h1.transformer.reset(new JFunction4DTransformer_t(21.5, 2, ng[0], 0.0, JGeant(JGeanx(1.00, -2.2)), 1e-2, NAMESPACE::getAngularAcceptance, 0.05));
127 
128  set<double> C; // cosine emission angle
129 
130  JQuadrature qeant(-1.0, 1.0, 20, JGeanx(1.00, -2.2));
131 
132  for (JQuadrature::const_iterator i = qeant.begin(); i != qeant.end(); ++i) {
133  C.insert(i->getX());
134  }
135 
136  C.insert(-1.01);
137  C.insert(-1.00);
138  C.insert( 1.00);
139  C.insert( 1.01);
140 
141  const double R[] = {0.0, 2.5, 5.0, 7.5, 10.0, 12.5, 15.0, 17.5, 20.0, 25.0, 30.0, 35.0, 40.0, 50.0, 60.0, 70.0, 80.0};
142  const double Dmax_m = 80.0;
143 
144  for (int i = 0; i != sizeof(R)/sizeof(R[0]); ++i) {
145 
146  const double R_m = R[i];
147 
148  for (set<double>::const_iterator c = C.begin(); c != C.end(); ++c) {
149 
150  const double cd = *c;
151 
152  const double grid = 10.0 + 0.0 * R_m/100.0; // [deg]
153  const double alpha = 2.0 * sqrt(1.0 - cos(grid * PI / 180.0)); // azimuth angle unit step size
154 
155  const int number_of_theta_points = max(2, (int) (180.0/(1.4 * grid)));
156  const double theta_step = PI / (number_of_theta_points + 1);
157 
158  for (double theta = -0.5*theta_step; theta < PI + theta_step; theta += theta_step) {
159 
160  const int number_of_phi_points = max(2, (int) (PI * sin(theta) / alpha));
161  const double phi_step = PI / (number_of_phi_points + 1);
162 
163  for (double phi = -0.5*phi_step; phi < PI + phi_step; phi += phi_step) {
164 
165  for (JMultiHistogram_t* p : { &h0, &h1 }) {
166  (*p)[R_m][cd][theta][phi];
167  }
168  }
169  }
170  }
171  }
172 
173  double buffer[] = { 0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 7.5, 10.0, 15.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 85.0, 100.0 };
174 
175  for (JMultiHistogram_t::super_iterator i1 = h1.super_begin(); i1 != h1.super_end(); ++i1) {
176  for (int j = 0; j != sizeof(buffer)/sizeof(buffer[0]); ++j) {
177  i1.getValue()[buffer[j]];
178  }
179  }
180 
181  while (inputFile.hasNext()) {
182 
183  NOTICE("event: " << setw(10) << inputFile.getCounter() << '\r'); STATUS(endl);
184 
185  const Evt* event = inputFile.next();
186  Trk track;
187 
188  if (count_electrons(*event) && !hadronicMode) {
189  track = get_electron(*event);
190  }
191  else if (count_hadrons(*event) && hadronicMode){
192  track = get_hadronic_cascade(*event);
193  }
194  else {
195  WARNING("No electron/hadrons found. Perhaps you meant to run this program in hadronic mode." << endl);
196  continue;
197  }
198 
199  double E = track.E;
200  JPosition3D pos = getPosition (track);
201  JDirection3D dir = getDirection(track);
202  double t0 = track.t;
203 
204  const JRotation3D R(dir);
205 
206  pos.rotate(R);
207 
208  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
209 
210  try {
211 
212  JAxis3D axis = pmtRouter.getPMT(hit->pmt_id);
213  axis.transform(R, pos);
214 
215  if ((!hadronicMode && from_electron(*hit)) || (hadronicMode && from_hadron(*hit))) {
216 
217  const double t1 = t0 + axis.getLength() * getInverseSpeedOfLight() * getIndexOfRefraction();
218 
219  const double D_m = axis.getLength();
220  const double cd = axis.getZ()/D_m;
221  const double theta = axis.getTheta();
222  const double phi = fabs(axis.getPhi());
223  const double dt = getTime(*hit) - t1;
224  const double npe = getNPE (*hit);
225 
226  if (D_m < Dmax_m) {
227  h1.fill(D_m, cd, theta, phi, dt, npe/E);
228  }
229  }
230  }
231  catch(const exception& error) {
232  FATAL(error.what() << endl);
233  }
234  }
235 
236  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
237 
238  JPosition3D P = module->getPosition();
239 
240  P.rotate(R);
241 
242  P.sub(pos);
243 
244  if (P.getLength() < h0.getXmax()) {
245 
246  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
247 
248  JAxis3D axis = *pmt;
249  axis.transform(R, pos);
250 
251  h0.fill(axis.getLength(), axis.getZ()/axis.getLength(), axis.getTheta(), fabs(axis.getPhi()), 0.0, 1.0);
252  }
253  }
254  }
255  }
256 
257  double integral = 0;
258  for (JMultiHistogram_t::super_iterator i = h0.super_begin(); i != h0.super_end(); ++i) {
259  integral+=i.getValue().getIntegral();
260  }
261  DEBUG("Integral:\t" << integral << endl);
262 
263  // output
264 
265  JFileStreamWriter out(outputFile.c_str());
266 
267  NOTICE("Storing, " << flush);
268 
269  for (const JMultiHistogram_t* p : { &h0, &h1 }) {
270  out.store(*p);
271  }
272 
273  out.close();
274  NOTICE("done." << endl);
275 }
JDetector detector
Definition: JRunAnalyzer.hh:23
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:35
int count_electrons(const Evt &evt)
Count the number of electrons in a given event.
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
#define WARNING(A)
Definition: JMessage.hh:65
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:33
then usage E
Definition: JMuonPostfit.sh:35
double t
track time [ns] (when the particle is at pos )
Definition: Trk.hh:19
double getIndexOfRefraction()
Get average index of refraction of water corresponding to group velocity.
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Implementation of dispersion for water in deep sea.
Definition: JDispersion.hh:26
Template definition of transformer of the probability density function (PDF) of the time response of ...
Rotation matrix.
Definition: JRotation3D.hh:111
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
double getMinimalWavelength()
Get minimal wavelength for PDF evaluations.
Definition: JPDFToolkit.hh:26
double getTime(const Hit &hit)
Get true time of hit.
double getPhi() const
Get phi angle.
Definition: JVersor3D.hh:144
string outputFile
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:20
void transform(const JAxis3D &axis)
Transform axis to reference frame of given axis.
Definition: JAxis3D.hh:359
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Axis object.
Definition: JAxis3D.hh:38
static const double C
Physics constants.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
JVector3D & sub(const JVector3D &vector)
Subtract vector.
Definition: JVector3D.hh:158
double getMaximalWavelength()
Get maximal wavelength for PDF evaluations.
Definition: JPDFToolkit.hh:37
Detector file.
Definition: JHead.hh:224
JDirection3D getDirection(const Vec &dir)
Get direction.
Trk get_hadronic_cascade(const Evt &evt)
Auxiliary function to get average direction and total energy of a hadronic cascade.
const Trk & get_electron(const Evt &evt)
Get first electron from the event tracklist.
Transformable multidimensional histogram.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
double getTheta() const
Get theta angle.
Definition: JVersor3D.hh:128
Type definition of a JHistogramMap based on JGridMap implementation.
JPosition3D getPosition(const Vec &pos)
Get position.
double getAmbientPressure()
Get ambient pressure.
Definition: Antares.hh:40
#define NOTICE(A)
Definition: JMessage.hh:64
static const double PI
Mathematical constants.
JHistogram1D< JElement2D< double, double >, JCollection > JHistogram1D_t
Type definition of a 1 dimensional histogram based on a JCollection.
int debug
debug level
Definition: JSirene.cc:68
Type definition for numerical integration.
Definition: JQuadrature.hh:37
double getLength() const
Get length.
Definition: JVector3D.hh:246
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:108
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
Type definition of a JHistogramMap based on JMap implementation.
bool from_hadron(const Hit &hit)
Test whether given hit was produced by a hadronic shower.
#define FATAL(A)
Definition: JMessage.hh:67
Probability density function of photon emission from EM-shower as a function of cosine of the emissio...
Definition: JGeanx.hh:31
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
General purpose class for object reading from a list of file names.
const double getInverseSpeedOfLight()
Get inverse speed of light.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
collection_type::abscissa_type abscissa_type
double getNPE(const Hit &hit)
Get true charge of hit.
int j
Definition: JPolint.hh:682
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
$WORKDIR ev_configure_domsimulator txt echo process $DOM_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DOM_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
Function object for the probability density function of photon emission from EM-shower as a function ...
Definition: JGeant.hh:30
bool from_electron(const Hit &hit)
Test whether given hit was produced by an electron.
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:14
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:186
Binary buffered file output.
double getZ() const
Get z position.
Definition: JVector3D.hh:115
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
then $DIR JPlotNPE PDG P
Definition: JPlotNPE-PDG.sh:62
int count_hadrons(const Evt &evt)
Count the number of hadrons in a given event (not including neutral pions)
double getAngularAcceptance(const double x)
Angular acceptence of PMT.
Definition: JDrawLED.cc:68