Jpp  18.3.0
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/JConstants.hh"
#include "JPhysics/Antares.hh"
#include "JPhysics/KM3NeT.hh"
#include "JIO/JFileStreamIO.hh"
#include "JGeometry3D/JGeometry3DToolkit.hh"
#include "JGeometry3D/JDirection3D.hh"
#include "JGeometry3D/JCylinder3D.hh"
#include "JGeometry3D/JPosition3D.hh"
#include "JGeometry3D/JAxis3D.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"
#include "JSirene/JVisibleEnergyToolkit.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 56 of file JHistHDG.cc.

57 {
58  using namespace std;
59  using namespace JPP;
60 
61  JMultipleFileScanner<Evt> inputFile;
62  JLimit_t& numberOfEvents = inputFile.getLimit();
63  string outputFile;
64  string detectorFile;
65  bool hadronicMode;
66  int debug;
67 
68  try {
69 
70  JParser<> zap("Program to histogram event-by-event data of shower light for making PDFs.");
71 
72  zap['f'] = make_field(inputFile);
73  zap['o'] = make_field(outputFile);
74  zap['n'] = make_field(numberOfEvents) = JLimit::max();
75  zap['a'] = make_field(detectorFile);
76  zap['H'] = make_field(hadronicMode);
77  zap['d'] = make_field(debug) = 1;
78 
79  zap(argc, argv);
80  }
81  catch(const exception &error) {
82  FATAL(error.what() << endl);
83  }
84 
85  if(hadronicMode) {
86  NOTICE("Plotting hadronic showers." << endl);
87  } else {
88  NOTICE("Plotting EM showers." << endl);
89  }
90 
91 
93 
94  try {
95  load(detectorFile, detector);
96  }
97  catch(const JException& error) {
98  FATAL(error);
99  }
100 
101  const JPosition3D center = get<JPosition3D>(getHeader(inputFile));
102 
103  NOTICE("Apply detector offset " << center << endl);
104 
105  detector -= center;
106 
107  const JHead& header = getHeader(inputFile);
108  const JCylinder3D can = get<JCylinder3D>(header);
109 
110  const JPMTRouter pmtRouter(detector);
111 
112  const double P_atm = NAMESPACE::getAmbientPressure();
113  const double wmin = getMinimalWavelength();
114  const double wmax = getMaximalWavelength();
115 
116  const JDispersion dispersion(P_atm);
117 
118  const double ng[] = { dispersion.getIndexOfRefractionGroup(wmax),
119  dispersion.getIndexOfRefractionGroup(wmin) };
120 
121  typedef JHistogram1D_t::abscissa_type abscissa_type;
122 
127  JHistogramGridMap_t>::maplist> JMultiHistogram_t;
128 
129  typedef JPDFTransformer<4, abscissa_type> JFunction4DTransformer_t;
130 
131  JMultiHistogram_t h0; // occurrence rate of PMT (used for normalisation)
132  JMultiHistogram_t h1; // light from cascade
133 
134  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));
135 
136  set<double> C; // cosine emission angle
137 
138  JQuadrature qeant(-1.0, 1.0, 20, JGeanx(1.00, -2.2));
139 
140  for (JQuadrature::const_iterator i = qeant.begin(); i != qeant.end(); ++i) {
141  C.insert(i->getX());
142  }
143 
144  C.insert(-1.01);
145  C.insert(-1.00);
146  C.insert( 1.00);
147  C.insert( 1.01);
148 
149  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};
150  const double Dmax_m = 80.0;
151 
152  for (int i = 0; i != sizeof(R)/sizeof(R[0]); ++i) {
153 
154  const double R_m = R[i];
155 
156  for (set<double>::const_iterator c = C.begin(); c != C.end(); ++c) {
157 
158  const double cd = *c;
159 
160  const double grid = 10.0 + 0.0 * R_m/100.0; // [deg]
161  const double alpha = 2.0 * sqrt(1.0 - cos(grid * PI / 180.0)); // azimuth angle unit step size
162 
163  const int number_of_theta_points = max(2, (int) (180.0/(1.4 * grid)));
164  const double theta_step = PI / (number_of_theta_points + 1);
165 
166  for (double theta = -0.5*theta_step; theta < PI + theta_step; theta += theta_step) {
167 
168  const int number_of_phi_points = max(2, (int) (PI * sin(theta) / alpha));
169  const double phi_step = PI / (number_of_phi_points + 1);
170 
171  for (double phi = -0.5*phi_step; phi < PI + phi_step; phi += phi_step) {
172 
173  for (JMultiHistogram_t* p : { &h0, &h1 }) {
174  (*p)[R_m][cd][theta][phi];
175  }
176  }
177  }
178  }
179  }
180 
181  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 };
182 
183  for (JMultiHistogram_t::super_iterator i1 = h1.super_begin(); i1 != h1.super_end(); ++i1) {
184  for (int j = 0; j != sizeof(buffer)/sizeof(buffer[0]); ++j) {
185  i1.getValue()[buffer[j]];
186  }
187  }
188 
189  while (inputFile.hasNext()) {
190 
191  NOTICE("event: " << setw(10) << inputFile.getCounter() << '\r'); STATUS(endl);
192 
193  const Evt* event = inputFile.next();
194 
195  if (!has_neutrino(*event)) {
196  WARNING("Event " << inputFile.getCounter() << " does not correspond to a neutrino interaction; skip.");
197  continue;
198  }
199 
200  if (!has_electron(*event) || count_hadrons(*event) == 0) {
201  WARNING("No electron/hadrons found; skip.");
202  continue;
203  }
204 
205  const Trk& neutrino = get_neutrino(*event);
206 
207  const double Evis = getVisibleEnergy (*event, can);
208  const Vec EvisVector = getVisibleEnergyVector(*event, can);
209 
210  JVertex3D vertex = getVertex(neutrino);
211 
212  const JRotation3D R(getDirection(EvisVector));
213 
214  vertex.rotate(R);
215 
216  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
217 
218  try {
219 
220  JAxis3D axis = pmtRouter.getPMT(hit->pmt_id);
221  axis.transform(R, vertex.getPosition());
222 
223  if ((!hadronicMode && from_electron(*hit)) || (hadronicMode && from_hadron(*hit))) {
224 
225  const double t1 = vertex.getT() + axis.getLength() * getInverseSpeedOfLight() * getIndexOfRefraction();
226 
227  const double D_m = axis.getLength();
228  const double cd = axis.getZ() / D_m;
229  const double theta = axis.getTheta();
230  const double phi = fabs(axis.getPhi());
231  const double dt = getTime(*hit) - t1;
232  const double npe = getNPE (*hit);
233 
234  if (D_m < Dmax_m) {
235  h1.fill(D_m, cd, theta, phi, dt, npe/Evis);
236  }
237  }
238  }
239  catch(const exception& error) {
240  FATAL(error.what() << endl);
241  }
242  }
243 
244  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
245 
246  JPosition3D P = module->getPosition();
247 
248  P.rotate(R);
249 
250  P.sub(vertex);
251 
252  if (P.getLength() < h0.getXmax()) {
253 
254  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
255 
256  JAxis3D axis = *pmt;
257  axis.transform(R, vertex);
258 
259  h0.fill(axis.getLength(), axis.getZ()/axis.getLength(), axis.getTheta(), fabs(axis.getPhi()), 0.0, 1.0);
260  }
261  }
262  }
263  }
264 
265  double integral = 0;
266  for (JMultiHistogram_t::super_iterator i = h0.super_begin(); i != h0.super_end(); ++i) {
267  integral+=i.getValue().getIntegral();
268  }
269  DEBUG("Integral:\t" << integral << endl);
270 
271  // output
272 
273  JFileStreamWriter out(outputFile.c_str());
274 
275  NOTICE("Storing, " << flush);
276 
277  for (const JMultiHistogram_t* p : { &h0, &h1 }) {
278  out.store(*p);
279  }
280 
281  out.close();
282  NOTICE("done." << endl);
283 }
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:35
JVertex3D getVertex(const Trk &track)
Get vertex.
Utility class to parse command line options.
Definition: JParser.hh:1514
General exception.
Definition: JException.hh:24
#define WARNING(A)
Definition: JMessage.hh:65
double getIndexOfRefraction()
Get average index of refraction of water corresponding to group velocity.
#define STATUS(A)
Definition: JMessage.hh:63
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
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 ...
bool has_electron(const Evt &evt)
Test whether given event has an electron.
Rotation matrix.
Definition: JRotation3D.hh:111
Vec getVisibleEnergyVector(const Trk &track, const JCylinder3D &can=getMaximumContainmentVolume())
Get the visible energy vector of a track.
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
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
then usage set_variable ACOUSTICS_WORKDIR $WORKDIR set_variable FORMULA sin([0]+2 *$PI *([1]+[2]*x)*x)" set_variable DY 1.0e-8 mkdir $WORKDIR for DETECTOR in $DETECTORS[*]
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
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
double getMaximalWavelength()
Get maximal wavelength for PDF evaluations.
Definition: JPDFToolkit.hh:37
Cylinder object.
Definition: JCylinder3D.hh:39
Detector file.
Definition: JHead.hh:226
JDirection3D getDirection(const Vec &dir)
Get direction.
Monte Carlo run header.
Definition: JHead.hh:1234
Transformable multidimensional histogram.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
double getTheta() const
Get theta angle.
Definition: JVersor3D.hh:128
Type definition of a JHistogramMap based on JGridMap implementation.
double getAmbientPressure()
Get ambient pressure.
Definition: Antares.hh:40
#define NOTICE(A)
Definition: JMessage.hh:64
double getVisibleEnergy(const Trk &track, const JCylinder3D &can=getMaximumContainmentVolume())
Get the visible energy of a track.
static const double PI
Mathematical constants.
JHistogram1D< JElement2D< double, double >, JCollection > JHistogram1D_t
Type definition of a 1 dimensional histogram based on a JCollection.
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
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
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
$WORKDIR ev_configure_dqsimulator txt echo process $DQ_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DQ_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
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.
collection_type::abscissa_type abscissa_type
double getNPE(const Hit &hit)
Get true charge of hit.
int j
Definition: JPolint.hh:792
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
Function object for the probability density function of photon emission from EM-shower as a function ...
Definition: JGeant.hh:30
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
do set_variable DETECTOR_TXT $WORKDIR detector
bool from_electron(const Hit &hit)
Test whether given hit was produced by an electron.
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition: JVertex3D.hh:147
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
int debug
debug level
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20
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)
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
The cylinder used for photon tracking.
Definition: JHead.hh:575
double getAngularAcceptance(const double x)
Angular acceptence of PMT.
Definition: JDrawLED.cc:68