Jpp  18.4.0
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/JConstants.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/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 "JSirene/JVisibleEnergyToolkit.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 103 of file JHistHDF.cc.

104 {
105  using namespace std;
106  using namespace JPP;
107  using namespace KM3NET;
108 
109  JMultipleFileScanner<Evt> inputFile;
110  JLimit_t& numberOfEvents = inputFile.getLimit();
111  string outputFile;
112  string detectorFile;
113  int debug;
114 
115  try {
116 
117  JParser<> zap("Program to histogram event-by-event data of muon light for making PDFs.");
118 
119  zap['f'] = make_field(inputFile);
120  zap['o'] = make_field(outputFile);
121  zap['n'] = make_field(numberOfEvents) = JLimit::max();
122  zap['a'] = make_field(detectorFile);
123  zap['d'] = make_field(debug) = 1;
124 
125  zap(argc, argv);
126  }
127  catch(const exception &error) {
128  FATAL(error.what() << endl);
129  }
130 
131 
133 
134  try {
135  load(detectorFile, detector);
136  }
137  catch(const JException& error) {
138  FATAL(error);
139  }
140 
141  JHead head(JMultipleFileScanner<Head>(inputFile).getHeader()); // Monte Carlo header
142 
143  const bool KM3Sim = is_km3sim(head);
144 
145  if (KM3Sim) {
146  detector -= JCenter3D(detector.begin(), detector.end()); // For KM3Sim, you get it from the detector file
147  } else {
148  detector -= get<JPosition3D>(head); // For KM3, the MC origin is stored in the header
149  }
150 
151  const JCylinder3D can = get<JCylinder3D>(head);
152 
153  const JPMTRouter pmtRouter(detector);
154 
155  const double P_atm = NAMESPACE::getAmbientPressure();
156  const double wmax = getMaximalWavelength();
157 
158  const JDispersion dispersion(P_atm);
159 
160  typedef JHistogram1D_t::abscissa_type abscissa_type;
161 
165  JHistogramGridMap_t>::maplist> JMultiHistogram_t;
166 
167  typedef JPDFTransformer<3, abscissa_type> JFunction3DTransformer_t;
168 
169  JMultiHistogram_t h0; // occurrence rate of PMT (used for normalisation)
170  JMultiHistogram_t h1; // light from muon
171  JMultiHistogram_t h2; // light from showers
172 
173  const double cmin = dispersion.getKmin (wmax);
174 
175  h1.transformer.reset(new JFunction3DTransformer_t(35.0, 2, cmin, 0.0, NAMESPACE::getAngularAcceptance, 0.10));
176  h2.transformer.reset(new JFunction3DTransformer_t(35.0, 2, cmin, 0.0, NAMESPACE::getAngularAcceptance, 0.10));
177 
178 
179  // configure bins
180 
181  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 };
182 
183  for (int i = 0; i != sizeof(R)/sizeof(R[0]); ++i) {
184 
185  const double R_m = R[i];
186 
187  const double grid = 10.0 + 0.0 * R_m/100.0; // [deg]
188  const double alpha = 2.0 * sqrt(1.0 - cos(grid * PI / 180.0)); // azimuth angle unit step size
189 
190  const int number_of_theta_points = max(2, (int) (180.0/(1.4 * grid)));
191  const double theta_step = PI / (number_of_theta_points + 1);
192 
193  for (double theta = -0.5*theta_step; theta < PI + theta_step; theta += theta_step) {
194 
195  const int number_of_phi_points = max(2, (int) (PI * sin(theta) / alpha));
196  const double phi_step = PI / (number_of_phi_points + 1);
197 
198  for (double phi = -0.5*phi_step; phi < PI + phi_step; phi += phi_step) {
199 
200  for (JMultiHistogram_t* p : { &h0, &h1, &h2 }) {
201  (*p)[R_m][theta][phi];
202  }
203  }
204  }
205  }
206 
207  for (JMultiHistogram_t::super_iterator
208  i1 = h1.super_begin(),
209  i2 = h2.super_begin(); i1 != h1.super_end(); ++i1, ++i2) {
210 
211  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} ) {
212  i1.getValue()[x];
213  i2.getValue()[x];
214  }
215  }
216 
217 
218  while (inputFile.hasNext()) {
219 
220  NOTICE("event: " << setw(10) << inputFile.getCounter() << '\r'); STATUS(endl);
221 
222  const Evt* event = inputFile.next();
223 
224  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
225 
226  if (is_muon(*track)) {
227 
228  // track parameters
229 
230  const double Evis = getVisibleEnergy (*event, can);
231  const Vec EvisVector = getVisibleEnergyVector(*event, can);
232 
233  JVertex3D vertex = getVertex(*track);
234 
235  const JRotation3D R(getDirection(EvisVector));
236 
237  vertex.rotate(R);
238 
239  JRange<double> Z(0.0, gWater(track->E)); // range of muon
240 
241  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
242 
243  try {
244 
245  JAxis3D axis = pmtRouter.getPMT(hit->pmt_id);
246  axis.transform(R, vertex);
247 
248  const double t1 = vertex.getT() + (axis.getZ() + axis.getX()*getTanThetaC()) / getSpeedOfLight();
249 
250  const double R_m = axis.getX();
251  const double theta = axis.getTheta();
252  const double phi = fabs(axis.getPhi());
253  const double dt = getTime(*hit) - t1;
254  const double npe = getNPE (*hit);
255 
256  const int classID = (KM3Sim ? classify_km3sim(*track, *hit) : classify_km3(*track, *hit));
257 
258  switch (classID) {
259 
260  case 1:
261  h1.fill(R_m, theta, phi, dt, npe); // light from muon
262  break;
263 
264  case 2:
265  h2.fill(R_m, theta, phi, dt, npe / max(1.0, Evis)); // light from shower
266  break;
267  }
268  }
269  catch(const exception& error) {
270  FATAL(error.what() << endl);
271  }
272  }
273 
274 
275  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
276 
277  JPosition3D P = module->getPosition();
278 
279  P.rotate(R);
280 
281  P.sub(vertex);
282 
283  if (sqrt(P.getX()*P.getX() + P.getY()*P.getY()) <= h0.getXmax()) {
284 
285  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
286 
287  JAxis3D axis = *pmt;
288 
289  axis.transform(R, vertex);
290 
291  if (Z(axis.getZ() - axis.getX()/getTanThetaC())) {
292  h0.fill(axis.getX(), axis.getTheta(), fabs(axis.getPhi()), 0.0, 1.0);
293  }
294  }
295  }
296  }
297  }
298  }
299  }
300  NOTICE(endl);
301 
302 
303  // output
304 
305  JFileStreamWriter out(outputFile.c_str());
306 
307  for (const JMultiHistogram_t* p : { &h0, &h1, &h2 }) {
308  out.store(*p);
309  }
310 
311  out.close();
312 }
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
JWriter & store(const JSerialisable &object)
Write object.
#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
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
Vec getVisibleEnergyVector(const Trk &track, const JCylinder3D &can=getMaximumContainmentVolume())
Get the visible energy vector of a track.
static const JGeaneWater gWater
Function object for energy loss of muon in sea water.
Definition: JGeane.hh:381
double getTime(const Hit &hit)
Get true time of hit.
double getPhi() const
Get phi angle.
Definition: JVersor3D.hh:144
string outputFile
#define KM3NET
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[*]
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.
double getY() const
Get y position.
Definition: JVector3D.hh:104
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:108
Type definition of a JHistogramMap based on JMap implementation.
Template specialisation of JMultipleFileScanner for Monte Carlo header.
#define FATAL(A)
Definition: JMessage.hh:67
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
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.
bool is_km3sim(const JHead &header)
Check for detector simulation.
double getNPE(const Hit &hit)
Get true charge of hit.
do set_variable MODULE getModule a $WORKDIR detector_a datx L $STRING JEditDetector a $WORKDIR detector_a datx M $MODULE setz o $WORKDIR detector_a datx JEditDetector a $WORKDIR detector_b datx M $MODULE setz o $WORKDIR detector_b datx done echo Output stored at $WORKDIR detector_a datx and $WORKDIR tripod_a txt JDrawDetector2D a $WORKDIR detector_a datx a $WORKDIR detector_b datx L BL o detector $FORMAT $BATCH JDrawDetector2D T $WORKDIR tripod_a txt T $WORKDIR tripod_b txt L BL o tripod $FORMAT $BATCH JCompareDetector a $WORKDIR detector_a datx b $WORKDIR detector_b datx o $WORKDIR abc root &dev null for KEY in X Y Z
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
do set_variable DETECTOR_TXT $WORKDIR detector
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition: JVertex3D.hh:147
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
The cylinder used for photon tracking.
Definition: JHead.hh:575
double getAngularAcceptance(const double x)
Angular acceptence of PMT.
Definition: JDrawLED.cc:68