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

Program to histogram event-by-event data of muon 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/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 "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"

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

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* p : { &h0, &h1, &h2 }) {
255  (*p)[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 x : { 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} ) {
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* p : { &h0, &h1, &h2 }) {
362  out.store(*p);
363  }
364 
365  out.close();
366 }
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:33
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
JWriter & store(const JSerialisable &object)
Write object.
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:33
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:80
Implementation of dispersion for water in deep sea.
Definition: JDispersion.hh:26
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
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:69
static const JGeaneWater gWater
Function object for energy loss of muon in sea water.
Definition: JGeane.hh:323
double getTime(const Hit &hit)
Get true time of hit.
double getPhi() const
Get phi angle.
Definition: JVersor3D.hh:144
string outputFile
#define KM3NET
Definition: Jpp.hh:32
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
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:45
Detector file.
Definition: JHead.hh:196
JDirection3D getDirection(const Vec &dir)
Get direction.
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:30
#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.
double getY() const
Get y position.
Definition: JVector3D.hh:104
int debug
debug level
Definition: JSirene.cc:63
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:108
Type definition of a JHistogramMap based on JMap implementation.
Monte Carlo run header.
Definition: JHead.hh:1113
Template specialisation of JMultipleFileScanner for Monte Carlo header.
#define FATAL(A)
Definition: JMessage.hh:67
then echo Variable JPP_DIR undefined exit fi source $JPP_DIR setenv sh $JPP_DIR set_variable NORTH set_variable EAST set_variable SOUTH set_variable WEST set_variable WORKDIR tmp set_variable R set_variable CT set_variable YMAX set_variable YMIN if do_usage *then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:35
const double getSpeedOfLight()
Get speed of light.
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.
double getX() const
Get x position.
Definition: JVector3D.hh:94
collection_type::abscissa_type abscissa_type
double getTanThetaC()
Get average tangent of Cherenkov angle of water corresponding to group velocity.
double getNPE(const Hit &hit)
Get true charge of hit.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
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 usage $script[input file[working directory[option]]] nWhere option can be E
Definition: JMuonPostfit.sh:35
then $DIR JPlotNPE PDG P
Definition: JPlotNPE-PDG.sh:60
double getAngularAcceptance(const double x)
Angular acceptence of PMT.
Definition: JDrawLED.cc:84