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

Program to histogram event-by-event and track-by-track for making PDFs of lights of individual particles. More...

#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdexcept>
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/offline/Hit.hh"
#include "km3net-dataformat/offline/Trk.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"
#include "JAAnet/JParticleTypes.hh"

Go to the source code of this file.

Functions

std::vector< Int_t > getHitRemapping (const std::vector< Trk > *tracklist)
 
int main (int argc, char **argv)
 

Detailed Description

Program to histogram event-by-event and track-by-track for making PDFs of lights of individual particles.

Author
jseneca

Definition in file JHistHDE.cc.

Function Documentation

std::vector<Int_t> getHitRemapping ( const std::vector< Trk > *  tracklist)
inline

Definition at line 55 of file JHistHDE.cc.

56 {
57  using namespace std;
58  using namespace JPP;
59 
60  vector<Int_t> hit_remapping;
61 
62  for (vector<Trk>::const_iterator i = tracklist->begin(); i != tracklist->end(); ++i) {
63 
64  //Skip pathological neutrino that is not the primary incoming neutrino
65 
66  if(i->type == TRACK_TYPE_NUMU && i != tracklist->begin()) {
67  continue;
68  }
69 
70  hit_remapping.push_back(i->id);
71  }
72 
73  return hit_remapping;
74 }
int main ( int  argc,
char **  argv 
)

Definition at line 76 of file JHistHDE.cc.

77 {
78  using namespace std;
79  using namespace JPP;
80 
81  JMultipleFileScanner<Evt> inputFile;
82  //JLimit_t& numberOfEvents = inputFile.getLimit();
83  string outputFile = "J%s.HDE"; //'s' for single (particle), or simulation
84  string detectorFile;
85  vector<int> particles;
86  uint fix_bug;
87  int debug;
88 
89  try {
90 
91  JParser<> zap("Program to histogram event-by-event data of shower light for making PDFs.");
92 
93  zap['f'] = make_field(inputFile);
94  zap['o'] = make_field(outputFile);
95  //zap['n'] = make_field(numberOfEvents) = JLimit::max();
96  zap['a'] = make_field(detectorFile);
97  zap['p'] = make_field(particles);
98  zap['b'] = make_field(fix_bug);
99  zap['d'] = make_field(debug) = 1;
100 
101  if (zap.read(argc, argv) != 0)
102  return 1;
103  }
104  catch(const exception &error) {
105  FATAL(error.what() << endl);
106  }
107 
109 
110  if(outputFile.find('%') != string::npos){
111  sort(particles.begin(), particles.end());
112  string prefix_t = "";
113  for(vector<int>::iterator ptype = particles.begin(); ptype != particles.end(); ptype++){
114  prefix_t += to_string((long long int)*ptype) + "_";
115  }
116  prefix_t.erase(prefix_t.size() - 1);
117  string::size_type pos_1 = outputFile.find('%');
118  outputFile.replace(pos_1, 1, prefix_t);
119  }
120 
121  try {
122  load(detectorFile, detector);
123  }
124  catch(const JException& error) {
125  FATAL(error);
126  }
127 
128  const JPosition3D center = get<JPosition3D>(getHeader(inputFile));
129 
130  NOTICE("Apply detector offset " << center << endl);
131 
132  detector -= center;
133 
134  const JPMTRouter pmtRouter(detector);
135 
136  const double P_atm = NAMESPACE::getAmbientPressure();
137  const double wmin = getMinimalWavelength();
138  const double wmax = getMaximalWavelength();
139 
140  const JDispersion dispersion(P_atm);
141 
142  const double ng[] = { dispersion.getIndexOfRefractionGroup(wmax),
143  dispersion.getIndexOfRefractionGroup(wmin) };
144 
145  typedef JHistogram1D_t::abscissa_type abscissa_type;
146 
152  JHistogramGridMap_t>::maplist> JMultiHistogram_t;
153 
154  typedef JPDFTransformer<5, abscissa_type> JFunction5DTransformer_t;
155 
156  JMultiHistogram_t h0; // occurrence rate of PMT (used for normalisation)
157  JMultiHistogram_t h1; // light from track cascade
158 
159  h1.transformer.reset(new JFunction5DTransformer_t(21.5, 2, ng[0], 0.0, JGeant(JGeanx(1.00, -2.2)), 1e-2, NAMESPACE::getAngularAcceptance, 0.05));
160 
161  set<double> C; // cosine emission angle
162 
163  JQuadrature qeant(-1.0, 1.0, 30, JGeanx(1.00, -2.2));
164 
165  for (JQuadrature::const_iterator i = qeant.begin(); i != qeant.end(); ++i) {
166  C.insert(i->getX());
167  }
168 
169  C.insert(-1.01);
170  C.insert(-1.00);
171  C.insert( 1.00);
172  C.insert( 1.01);
173 
174  const double E_b[] = {0.01, 0.2, 0.4, 0.6, 0.8, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 25.0, 30.0, 40.0, 55.0, 70.0, 85.0, 100.0};
175 
176  const double R[] = {0.0, 1.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, 65.0, 80.0};
177  const double Dmax_m = R[sizeof(R)/sizeof(R[0]) - 1]; //Last element of R
178 
179  for (int iE = 0; iE != sizeof(E_b)/sizeof(E_b[0]); ++iE) {
180 
181  const double E_m = E_b[iE];
182 
183  for (int i = 0; i != sizeof(R)/sizeof(R[0]); ++i) {
184 
185  const double R_m = R[i];
186 
187  for (set<double>::const_iterator c = C.begin(); c != C.end(); ++c) {
188 
189  const double cd = *c;
190 
191  const double grid = 10.0 + 0.0 * R_m/100.0; // [deg]
192  const double alpha = 2.0 * sqrt(1.0 - cos(grid * PI / 180.0)); // azimuth angle unit step size
193 
194  const int number_of_theta_points = (max(2, (int) (180.0/(1.4 * grid))));
195  const double theta_step = PI / (number_of_theta_points + 1);
196 
197  for (double theta = -0.5*theta_step; theta < PI + theta_step; theta += theta_step) {
198  const int number_of_phi_points = (max(2, (int) (PI * sin(theta) / alpha)));
199  const double phi_step = PI / (number_of_phi_points + 1);
200 
201  for (double phi = -0.5*phi_step; phi < PI + phi_step; phi += phi_step) {
202 
203  for (JMultiHistogram_t* p : { &h0, &h1 }) {
204  (*p)[E_m][R_m][cd][theta][phi];
205  }
206  }
207  }
208  }
209  }
210  }
211 
212  double buffer[] = {-15.0,-10.0,-7.5,-5,-4,-3,-2,-1.5,-1.0,-0.5,-0.1, 0.0,0.1, 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 };
213  for (JMultiHistogram_t::super_iterator
214  i1 = h1.super_begin(); i1 != h1.super_end(); ++i1) {
215  for (int j = 0; j != sizeof(buffer)/sizeof(buffer[0]); ++j) {
216  i1.getValue()[buffer[j]];
217  }
218  }//Buffer defines the binning of the inner histograms (dt)
219 
220 
221  long long int h0_fillcount = 0;
222  long long int h1_fillcount = 0;
223 
224  while (inputFile.hasNext()) {
225 
226  //NOTICE("event: " << setw(10) << inputFile.getCounter() << '\r'); STATUS(endl);
227  //I suspect the printing above slows down the program considerably
228 
229  const Evt* event = inputFile.next();
230  const vector<Trk>* mc_tracks = &(event->mc_trks);
231 
232  vector<int> hit_remap;
233 
234  //*************************************************
235  //Fixes 2016 atmospheric neutrino simulation hit-making neutrino bug
236  //Remove after fix.
237  if(fix_bug == 0){
238  for (vector<Trk>::const_iterator i = mc_tracks->begin(); i != mc_tracks->end(); ++i) {
239  hit_remap.push_back(i->id);
240  }
241  } else if(fix_bug == 1){
242  hit_remap = getHitRemapping(mc_tracks);
243  } else if(fix_bug == 2){
244  bool skipevent = false;
245  for (vector<Trk>::const_iterator i = mc_tracks->begin(); i != mc_tracks->end(); ++i) {
246  if(i->type == 14){
247  skipevent = true;
248  break;
249  }
250  hit_remap.push_back(i->id);
251  }
252  if(skipevent) continue;
253  }
254  //*************************************************
255 
256  double t0 = (*mc_tracks)[1].t;
257 
258  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
259 
260  try {
261 
262  if(hit->origin >= (int)(*mc_tracks).size()){
263  std::out_of_range err("Hit origin not in tracklist. Avoided segfault");
264  throw err;
265  }
266 
267  Int_t corr_origin = hit_remap[hit->origin];
268  Trk curr_track = (*mc_tracks)[corr_origin]; //Get track from corrected origin
269  JDirection3D dir = getDirection(curr_track); const JRotation3D R(dir);
270  JPosition3D pos = getPosition(curr_track); pos.rotate(R);
271  JAxis3D axis = pmtRouter.getPMT(hit->pmt_id);
272  axis.transform(R, pos);
273 
274  const double E = curr_track.E;
275  const double t1 = t0 + axis.getLength() * getInverseSpeedOfLight() * getIndexOfRefraction();
276  const double D_m = axis.getLength();
277  const double cd = axis.getZ()/D_m;
278  const double theta = axis.getTheta();
279  const double phi = fabs(axis.getPhi());
280  const double dt = getTime(*hit) - t1;
281  const double npe = getNPE (*hit);
282 
283  if(D_m < Dmax_m){
284  h1.fill(E, D_m, cd, theta, phi, dt, npe);
285  h1_fillcount += 1;
286  }
287  }
288  catch(const exception& error) {
289  std::cout << "Fatal error for event: " << inputFile.getCounter() << std::endl;
290  FATAL(error.what() << endl);
291  }
292  }
293 
294  // ignore primary neutrino -> ^
295  for (vector<Trk>::const_iterator tr = event->mc_trks.begin() + 1; tr != event->mc_trks.end(); ++tr) {
296 
297  if(find(particles.begin(), particles.end(), tr->type) == particles.end()){
298  continue;
299  }
300 
301  //cout << "Particle accepted: " << tr->type << endl;
302 
303 
304  JDirection3D dir = getDirection(*tr); const JRotation3D R(dir);
305  JPosition3D pos = getPosition(*tr); pos.rotate(R);
306 
307  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
308 
309  JPosition3D P = module->getPosition();
310 
311  P.rotate(R);
312 
313  P.sub(pos);
314 
315  if (P.getLength() < Dmax_m) {
316 
317  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
318 
319  JAxis3D axis = *pmt;
320  axis.transform(R, pos);
321 
322  h0.fill(tr->E, axis.getLength(), axis.getZ()/axis.getLength(), axis.getTheta(), fabs(axis.getPhi()), 0.0, 1.0);
323  h0_fillcount += 1;
324  }
325  }
326  }
327  }
328 
329  if(h1_fillcount > h0_fillcount){
330  std::cout << "WARNING: recorded hits in normalization histogram that were not recorded in normalization histogram. This should not happen." << std::endl;
331  std::cout << "h1_fillcount: " << h1_fillcount << ", h0_fillcount: " << h0_fillcount << std::endl;
332  }
333  };
334 
335  double integral = 0;
336  for (JMultiHistogram_t::super_iterator i = h0.super_begin(); i != h0.super_end(); ++i) {
337  integral+=i.getValue().getIntegral();
338  }
339  DEBUG("Integral:\t" << integral << endl);
340 
341  // output
342 
343  JFileStreamWriter out(outputFile.c_str());
344 
345  NOTICE("Storing " << outputFile << ", " << flush);
346 
347  for (const JMultiHistogram_t* p : { &h0, &h1 }) {
348  out.store(*p);
349  }
350 
351  out.close();
352  NOTICE("JHistHDE done. " << endl);
353  return 1;
354 }
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:35
Utility class to parse command line options.
Definition: JParser.hh:1514
General exception.
Definition: JException.hh:23
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:33
then usage $script< input file >[option[primary[working directory]]] nWhere option can be E
Definition: JMuonPostfit.sh:40
double getIndexOfRefraction()
Get average index of refraction of water corresponding to group velocity.
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
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
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.
std::vector< Int_t > getHitRemapping(const std::vector< Trk > *tracklist)
Definition: JHistHDE.cc:55
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:226
JDirection3D getDirection(const Vec &dir)
Get direction.
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.
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.
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.
#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.
std::string to_string(const T &value)
Convert value to string.
collection_type::abscissa_type abscissa_type
double getNPE(const Hit &hit)
Get true charge of hit.
int j
Definition: JPolint.hh:703
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
Function object for the probability density function of photon emission from EM-shower as a function ...
Definition: JGeant.hh:30
do set_variable DETECTOR_TXT $WORKDIR detector
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
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
double getAngularAcceptance(const double x)
Angular acceptence of PMT.
Definition: JDrawLED.cc:68