Jpp
Functions
JHistHDF.cc File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include "evt/Head.hh"
#include "evt/Evt.hh"
#include "evt/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/JPDFTransformer.hh"
#include "JPhysics/JDispersion.hh"
#include "JPhysics/Antares.hh"
#include "JPhysics/KM3NeT.hh"
#include "JIO/JFileStreamIO.hh"
#include "JGeometry3D/JPosition3D.hh"
#include "JGeometry3D/JDirection3D.hh"
#include "JGeometry3D/JAxis3D.hh"
#include "JGeometry3D/JGeometry3DToolkit.hh"
#include "JTools/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"

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 muon light for making PDFs.

Author
mdejong

Definition in file JHistHDF.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 163 of file JHistHDF.cc.

164 {
165  using namespace std;
166  using namespace JPP;
167 
168  JMultipleFileScanner<Evt> inputFile;
169  JLimit_t& numberOfEvents = inputFile.getLimit();
170  string outputFile;
171  string detectorFile;
172  int debug;
173 
174  try {
175 
176  JParser<> zap("Program to histogram event-by-event data of muon light for making PDFs.");
177 
178  zap['f'] = make_field(inputFile);
179  zap['o'] = make_field(outputFile);
180  zap['n'] = make_field(numberOfEvents) = JLimit::max();
181  zap['a'] = make_field(detectorFile);
182  zap['d'] = make_field(debug) = 1;
183 
184  zap(argc, argv);
185  }
186  catch(const exception &error) {
187  FATAL(error.what() << endl);
188  }
189 
190 
191  using namespace KM3NET;
192 
193 
195 
196  try {
197  load(detectorFile, detector);
198  }
199  catch(const JException& error) {
200  FATAL(error);
201  }
202 
203  JHead head(JMultipleFileScanner<Head>(inputFile).getHeader()); // Monte Carlo header
204 
205  const JPMTRouter pmtRouter(detector);
206 
207  const double P_atm = NAMESPACE::getAmbientPressure();
208  const double wmax = getMaximalWavelength();
209 
210  const JDispersion dispersion(P_atm);
211 
212  typedef JHistogram1D_t::abscissa_type abscissa_type;
213 
217  JHistogramGridMap_t>::maplist> JMultiHistogram_t;
218 
219  typedef JPDFTransformer<3, abscissa_type> JFunction3DTransformer_t;
220 
221  JMultiHistogram_t h0; // occurrence rate of PMT (used for normalisation)
222  JMultiHistogram_t h1; // light from muon
223  JMultiHistogram_t h2; // light from showers
224 
225  const JHitClassifier<JMultiHistogram_t> classifier(head, detector);
226 
227  const double cmin = dispersion.getKmin (wmax);
228 
229  h1.transformer.reset(new JFunction3DTransformer_t(35.0, 2, cmin, 0.0, NAMESPACE::getAngularAcceptance, 0.10));
230  h2.transformer.reset(new JFunction3DTransformer_t(35.0, 2, cmin, 0.0, NAMESPACE::getAngularAcceptance, 0.10));
231 
232 
233  // configure bins
234 
235  const double R[] = { 0.0, 5.0, 10.0, 20.0, 30.0, 40.0, 50.0, 70.0, 80.0, 90.0, 100.0, 170.0, 250.0 };
236 
237  for (int i = 0; i != sizeof(R)/sizeof(R[0]); ++i) {
238 
239  const double R_m = R[i];
240 
241  const double grid = 10.0 + 0.0 * R_m/100.0; // [deg]
242  const double alpha = 2.0 * sqrt(1.0 - cos(grid * PI / 180.0)); // azimuth angle unit step size
243 
244  const int number_of_theta_points = max(2, (int) (180.0/(1.4 * grid)));
245  const double theta_step = PI / (number_of_theta_points + 1);
246 
247  for (double theta = -0.5*theta_step; theta < PI + theta_step; theta += theta_step) {
248 
249  const int number_of_phi_points = max(2, (int) (PI * sin(theta) / alpha));
250  const double phi_step = PI / (number_of_phi_points + 1);
251 
252  for (double phi = -0.5*phi_step; phi < PI + phi_step; phi += phi_step) {
253 
254  for (JMultiHistogram_t* buffer[] = { &h0, &h1, &h2, NULL }, **histogram = buffer; *histogram != NULL; ++histogram) {
255  (**histogram)[R_m][theta][phi];
256  }
257  }
258  }
259  }
260 
261  for (JMultiHistogram_t::super_iterator
262  i1 = h1.super_begin(),
263  i2 = h2.super_begin(); i1 != h1.super_end(); ++i1, ++i2) {
264 
265  for (double buffer[] = { 0.0, 1.0, 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, 125.0, 150.0, 200.0, 500.0, -1.0 }, *x = buffer; *x >= 0.0; ++x) {
266  i1.getValue()[*x];
267  i2.getValue()[*x];
268  }
269  }
270 
271 
272  while (inputFile.hasNext()) {
273 
274  NOTICE("event: " << setw(10) << inputFile.getCounter() << '\r'); STATUS(endl);
275 
276  const Evt* event = inputFile.next();
277 
278  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
279 
280  if (is_muon(*track)) {
281 
282  // track parameters
283 
284  double E = track->E;
285  JPosition3D pos = getPosition (*track);
286  JDirection3D dir = getDirection(*track);
287  double t0 = track->t;
288 
289  const JRotation3D R(dir);
290 
291  pos.rotate(R);
292 
293  JRange<double> Z(0.0, gWater(E)); // range of muon
294 
295  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
296 
297  try {
298 
299  JAxis3D axis = pmtRouter.getPMT(hit->pmt_id);
300 
301  axis.transform(R, pos);
302 
303  const double E1 = classifier.getEnergy(*event, *track, axis);
304  const double t1 = t0 + (axis.getZ() + axis.getX()*getTanThetaC()) / getSpeedOfLight();
305 
306  const double R_m = axis.getX();
307  const double theta = axis.getTheta();
308  const double phi = fabs(axis.getPhi());
309  const double dt = getTime(*hit) - t1;
310  const double npe = getNPE(*hit);
311 
312  switch (classifier(*track, *hit)) {
313 
314  case 1:
315  h1.fill(R_m, theta, phi, dt, npe); // light from muon
316  break;
317 
318  case 2:
319  h2.fill(R_m, theta, phi, dt, npe/max(1.0, E1)); // light from shower
320  break;
321  }
322  }
323  catch(const exception& error) {
324  FATAL(error.what() << endl);
325  }
326  }
327 
328 
329  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
330 
331  JPosition3D P = module->getPosition();
332 
333  P.rotate(R);
334 
335  P.sub(pos);
336 
337  if (sqrt(P.getX()*P.getX() + P.getY()*P.getY()) <= h0.getXmax()) {
338 
339  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
340 
341  JAxis3D axis = *pmt;
342 
343  axis.transform(R, pos);
344 
345  if (Z(axis.getZ() - axis.getX()/getTanThetaC())) {
346  h0.fill(axis.getX(), axis.getTheta(), fabs(axis.getPhi()), 0.0, 1.0);
347  }
348  }
349  }
350  }
351  }
352  }
353  }
354  NOTICE(endl);
355 
356 
357  // output
358 
359  JFileStreamWriter out(outputFile.c_str());
360 
361  for (const JMultiHistogram_t* buffer[] = { &h0, &h1, &h2, NULL }, **i = buffer; *i != NULL; ++i) {
362  out.store(**i);
363  }
364 
365  out.close();
366 }
JIO::JFileStreamWriter
Binary buffered file output.
Definition: JFileStreamIO.hh:72
JSUPPORT::JLimit
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
JTOOLS::getSpeedOfLight
const double getSpeedOfLight()
Number of bytes in a gigabyte.
Definition: JConstants.hh:89
JPHYSICS::gWater
static const JGeaneWater gWater
Function object for energy loss of muon in sea water.
Definition: JGeane.hh:328
JGEOMETRY3D::JVector3D::getZ
double getZ() const
Get z position.
Definition: JVector3D.hh:114
JGEOMETRY3D::JAxis3D
Axis object.
Definition: JAxis3D.hh:38
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:456
JGEOMETRY3D::JAxis3D::transform
void transform(const JAxis3D &axis)
Transform axis to reference frame of given axis.
Definition: JAxis3D.hh:370
std::vector
Definition: JSTDTypes.hh:12
JTOOLS::JRange< double >
JGEOMETRY3D::JDirection3D
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:32
JAANET::getNPE
double getNPE(const Hit &hit)
Get true charge of hit.
Definition: JAAnetToolkit.hh:104
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JTOOLS::JMAPLIST
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:108
JIO::JWriter::store
JWriter & store(const JSerialisable &object)
Write object.
Definition: JSerialisable.hh:168
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JDETECTOR::JPMTRouter
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:33
JPHYSICS::JPDFTransformer
Template definition of transformer of the Probability Density Functions of the time response of a PMT...
Definition: JPDFTransformer.hh:33
JAANET::is_muon
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
Definition: JAAnetToolkit.hh:367
JGEOMETRY3D::JPosition3D::rotate
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:185
JAANET::JHead
Monte Carlo run header.
Definition: JHead.hh:839
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JSUPPORT::getHeader
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Definition: JMonteCarloFileSupportkit.hh:425
JSUPPORT::JMultipleFileScanner::getCounter
counter_type getCounter() const
Get counter.
Definition: JMultipleFileScanner.hh:323
JGEOMETRY3D::JVersor3D::getTheta
double getTheta() const
Get theta angle.
Definition: JVersor3D.hh:124
JTOOLS::JHistogram1D::abscissa_type
collection_type::abscissa_type abscissa_type
Definition: JHistogram1D.hh:121
debug
int debug
debug level
Definition: JSirene.cc:59
JSUPPORT::JMultipleFileScanner::next
virtual const pointer_type & next()
Get next element.
Definition: JMultipleFileScanner.hh:398
ANTARES::getAmbientPressure
double getAmbientPressure()
Get ambient pressure.
Definition: Antares.hh:30
JPHYSICS::JDispersion
Implementation of dispersion for water in deep sea.
Definition: JDispersion.hh:26
JGEOMETRY3D::JPosition3D
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
JSUPPORT::JMultipleFileScanner< Head >
Template specialisation of JMultipleFileScanner for Monte Carlo header.
Definition: JMonteCarloFileSupportkit.hh:291
JAANET::getTime
double getTime(const Hit &hit)
Get true time of hit.
Definition: JAAnetToolkit.hh:87
JTOOLS::JHistogramMap_t
Type definition of a JHistogramMap based on JMap implementation.
Definition: JHistogramMap_t.hh:25
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JSUPPORT::JMultipleFileScanner::hasNext
virtual bool hasNext()
Check availability of next element.
Definition: JMultipleFileScanner.hh:350
JTOOLS::JHistogram1D_t
JHistogram1D< JElement2D< double, double >, JCollection > JHistogram1D_t
Type definition of a 1 dimensional histogram based on a JCollection.
Definition: JHistogram1D_t.hh:22
JAANET::getDirection
JDirection3D getDirection(const Vec &v)
Get direction.
Definition: JAAnetToolkit.hh:221
JTOOLS::getTanThetaC
double getTanThetaC()
Get average tangent of Cherenkov angle of water.
Definition: JConstants.hh:133
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JSUPPORT::JMultipleFileScanner
General purpose class for object reading from a list of file names.
Definition: JMultipleFileScanner.hh:167
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
JGEOMETRY3D::JPosition3D::getPosition
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
JAANET::getPosition
JPosition3D getPosition(const Vec &v)
Get position.
Definition: JAAnetToolkit.hh:197
JAANET::detector
Detector file.
Definition: JHead.hh:130
std
Definition: jaanetDictionary.h:36
JGEOMETRY3D::JVector3D::getY
double getY() const
Get y position.
Definition: JVector3D.hh:103
JTOOLS::PI
static const double PI
Constants.
Definition: JConstants.hh:20
JTOOLS::JTransformableMultiHistogram
Transformable multidimensional histogram.
Definition: JTransformableMultiHistogram.hh:37
JTOOLS::JHistogramGridMap_t
Type definition of a JHistogramMap based on JGridMap implementation.
Definition: JHistogramMap_t.hh:34
JGEOMETRY3D::JVector3D::getX
double getX() const
Get x position.
Definition: JVector3D.hh:93
getAngularAcceptance
double getAngularAcceptance(const double x)
Angular acceptence of PMT.
Definition: JDrawLED.cc:84
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JGEOMETRY3D::JVector3D::sub
JVector3D & sub(const JVector3D &vector)
Subtract vector.
Definition: JVector3D.hh:157
JPHYSICS::getMaximalWavelength
double getMaximalWavelength()
Get maximal wavelength for PDF evaluations.
Definition: JPDFToolkit.hh:49
JLANG::JException
General exception.
Definition: JException.hh:40
JGEOMETRY3D::JRotation3D
Rotation matrix.
Definition: JRotation3D.hh:111
KM3NET
Name space for KM3NeT.
Definition: JDAQClock.hh:310
JGEOMETRY3D::JVersor3D::getPhi
double getPhi() const
Get phi angle.
Definition: JVersor3D.hh:140