Jpp
Functions
JHistHDG.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/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 "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"
#include "JPhysics/JPDFTransformer.hh"
#include "JPhysics/JPDF.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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 51 of file JHistHDG.cc.

52 {
53  using namespace std;
54  using namespace JPP;
55 
56  JMultipleFileScanner<Evt> inputFile;
57  JLimit_t& numberOfEvents = inputFile.getLimit();
58  string outputFile;
59  string detectorFile;
60  bool hadronicMode;
61  int debug;
62 
63  try {
64 
65  JParser<> zap("Program to histogram event-by-event data of shower light for making PDFs.");
66 
67  zap['f'] = make_field(inputFile);
68  zap['o'] = make_field(outputFile);
69  zap['n'] = make_field(numberOfEvents) = JLimit::max();
70  zap['a'] = make_field(detectorFile);
71  zap['H'] = make_field(hadronicMode);
72  zap['d'] = make_field(debug) = 1;
73 
74  zap(argc, argv);
75  }
76  catch(const exception &error) {
77  FATAL(error.what() << endl);
78  }
79 
80  if(hadronicMode) {
81  NOTICE("Plotting hadronic showers." << endl);
82  } else {
83  NOTICE("Plotting EM showers." << endl);
84  }
85 
86 
87  JDetector detector;
88 
89  try {
90  load(detectorFile, detector);
91  }
92  catch(const JException& error) {
93  FATAL(error);
94  }
95 
96  const JPosition3D center = get<JPosition3D>(getHeader(inputFile));
97 
98  NOTICE("Apply detector offset " << center << endl);
99 
100  detector -= center;
101 
102  const JPMTRouter pmtRouter(detector);
103 
104  const double P_atm = NAMESPACE::getAmbientPressure();
105  const double wmin = getMinimalWavelength();
106  const double wmax = getMaximalWavelength();
107 
108  const JDispersion dispersion(P_atm);
109 
110  const double ng[] = { dispersion.getIndexOfRefractionGroup(wmax),
111  dispersion.getIndexOfRefractionGroup(wmin) };
112 
113  typedef JHistogram1D_t::abscissa_type abscissa_type;
114 
115  typedef JTransformableMultiHistogram<JHistogram1D_t,
116  JMAPLIST<JHistogramMap_t,
117  JHistogramMap_t,
118  JHistogramGridMap_t,
119  JHistogramGridMap_t>::maplist> JMultiHistogram_t;
120 
121  typedef JPDFTransformer<4, abscissa_type> JFunction4DTransformer_t;
122 
123  JMultiHistogram_t h0; // occurrence rate of PMT (used for normalisation)
124  JMultiHistogram_t h1; // light from cascade
125 
126  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));
127 
128  set<double> C; // cosine emission angle
129 
130  JQuadrature qeant(-1.0, 1.0, 20, JGeanx(1.00, -2.2));
131 
132  for (JQuadrature::const_iterator i = qeant.begin(); i != qeant.end(); ++i) {
133  C.insert(i->getX());
134  }
135 
136  C.insert(-1.01);
137  C.insert(-1.00);
138  C.insert( 1.00);
139  C.insert( 1.01);
140 
141  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};
142  const double Dmax_m = 80.0;
143 
144  for (int i = 0; i != sizeof(R)/sizeof(R[0]); ++i) {
145 
146  const double R_m = R[i];
147 
148  for (set<double>::const_iterator c = C.begin(); c != C.end(); ++c) {
149 
150  const double cd = *c;
151 
152  const double grid = 10.0 + 0.0 * R_m/100.0; // [deg]
153  const double alpha = 2.0 * sqrt(1.0 - cos(grid * PI / 180.0)); // azimuth angle unit step size
154 
155  const int number_of_theta_points = max(2, (int) (180.0/(1.4 * grid)));
156  const double theta_step = PI / (number_of_theta_points + 1);
157 
158  for (double theta = -0.5*theta_step; theta < PI + theta_step; theta += theta_step) {
159 
160  const int number_of_phi_points = max(2, (int) (PI * sin(theta) / alpha));
161  const double phi_step = PI / (number_of_phi_points + 1);
162 
163  for (double phi = -0.5*phi_step; phi < PI + phi_step; phi += phi_step) {
164 
165  for (JMultiHistogram_t* buffer[] = { &h0, &h1, NULL }, **histogram = buffer; *histogram != NULL; ++histogram) {
166  (**histogram)[R_m][cd][theta][phi];
167  }
168  }
169  }
170  }
171  }
172 
173  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 };
174  for (JMultiHistogram_t::super_iterator
175  i1 = h1.super_begin(); i1 != h1.super_end(); ++i1) {
176 
177  for (int j = 0; j != sizeof(buffer)/sizeof(buffer[0]); ++j) {
178  i1.getValue()[buffer[j]];
179  }
180  }
181 
182  while (inputFile.hasNext()) {
183 
184  NOTICE("event: " << setw(10) << inputFile.getCounter() << '\r'); STATUS(endl);
185 
186  const Evt* event = inputFile.next();
187  Trk track;
188 
189  if(count_electrons(*event) && !hadronicMode) {
190  track = get_electron(*event);
191  }
192  else if (count_hadrons(*event) && hadronicMode){
193  track = get_hadronic_cascade(*event);
194  }
195  else {
196  WARNING("No electron/hadrons found. Perhaps you meant to run this program in hadronic mode." << endl);
197  continue;
198  }
199 
200  double E = track.E;
201  JPosition3D pos = getPosition (track);
202  JDirection3D dir = getDirection(track);
203  double t0 = track.t;
204 
205  const JRotation3D R(dir);
206 
207  pos.rotate(R);
208 
209  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
210 
211  try {
212 
213  JAxis3D axis = pmtRouter.getPMT(hit->pmt_id);
214  axis.transform(R, pos);
215 
216  if ((!hadronicMode && from_electron(*hit)) || (hadronicMode && from_hadron(*hit))) {
217 
218  const double t1 = t0 + axis.getLength() * getInverseSpeedOfLight() * getIndexOfRefraction();
219 
220  const double D_m = axis.getLength();
221  const double cd = axis.getZ()/D_m;
222  const double theta = axis.getTheta();
223  const double phi = fabs(axis.getPhi());
224  const double dt = getTime(*hit) - t1;
225  const double npe = getNPE(*hit);
226 
227  if (D_m < Dmax_m) {
228  h1.fill(D_m, cd, theta, phi, dt, npe/E);
229  }
230  }
231  }
232  catch(const exception& error) {
233  FATAL(error.what() << endl);
234  }
235  }
236 
237  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
238 
239  JPosition3D P = module->getPosition();
240 
241  P.rotate(R);
242 
243  P.sub(pos);
244 
245  if (P.getLength() < h0.getXmax()) {
246 
247  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
248 
249  JAxis3D axis = *pmt;
250  axis.transform(R, pos);
251 
252  h0.fill(axis.getLength(), axis.getZ()/axis.getLength(), axis.getTheta(), fabs(axis.getPhi()), 0.0, 1.0);
253  }
254  }
255  }
256  }
257 
258  double integral = 0;
259  for (JMultiHistogram_t::super_iterator i = h0.super_begin(); i != h0.super_end(); ++i) {
260  integral+=i.getValue().getIntegral();
261  }
262  DEBUG("Integral:\t" << integral << endl);
263 
264  // output
265 
266  JFileStreamWriter out(outputFile.c_str());
267 
268  NOTICE("Storing, " << flush);
269 
270  for (const JMultiHistogram_t* buffer[] = { &h0, &h1, NULL }, **i = buffer; *i != NULL; ++i) {
271  out.store(**i);
272  }
273 
274  out.close();
275  NOTICE("done." << endl);
276 }
JAANET::get_electron
const Trk & get_electron(const Evt &evt)
Get first electron from the event tracklist.
Definition: JAAnetToolkit.hh:474
JAANET::from_electron
bool from_electron(const Hit &hit)
Test whether given hit was produced by an electron.
Definition: JAAnetToolkit.hh:491
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:456
std::vector
Definition: JSTDTypes.hh:12
JSUPPORT::JLimit_t
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:215
JAANET::getNPE
double getNPE(const Hit &hit)
Get true charge of hit.
Definition: JAAnetToolkit.hh:104
JTOOLS::j
int j
Definition: JPolint.hh:634
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JTOOLS::C
static const double C
Speed of light in vacuum [m/ns].
Definition: JConstants.hh:22
std::set
Definition: JSTDTypes.hh:13
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
WARNING
#define WARNING(A)
Definition: JMessage.hh:65
JTOOLS::JHistogram1D::abscissa_type
collection_type::abscissa_type abscissa_type
Definition: JHistogram1D.hh:121
JTOOLS::getInverseSpeedOfLight
const double getInverseSpeedOfLight()
Get inverse speed of light.
Definition: JConstants.hh:100
debug
int debug
debug level
Definition: JSirene.cc:59
ANTARES::getAmbientPressure
double getAmbientPressure()
Get ambient pressure.
Definition: Antares.hh:30
JAANET::from_hadron
bool from_hadron(const Hit &hit)
Test whether given hit was produced by a hadronic shower.
Definition: JAAnetToolkit.hh:616
JPHYSICS::getMinimalWavelength
double getMinimalWavelength()
Get minimal wavelength for PDF evaluations.
Definition: JPDFToolkit.hh:38
JTOOLS::getIndexOfRefraction
double getIndexOfRefraction()
Get average index of refraction of water.
Definition: JConstants.hh:111
JSUPPORT::JLimit::getLimit
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
JAANET::getTime
double getTime(const Hit &hit)
Get true time of hit.
Definition: JAAnetToolkit.hh:87
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
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::get_hadronic_cascade
Trk get_hadronic_cascade(const Evt &evt)
Auxiliary function to get average direction and total energy of a hadronic cascade.
Definition: JAAnetToolkit.hh:627
JAANET::getDirection
JDirection3D getDirection(const Vec &v)
Get direction.
Definition: JAAnetToolkit.hh:221
JAANET::count_electrons
int count_electrons(const Evt &evt)
Count the number of electrons in a given event.
Definition: JAAnetToolkit.hh:452
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JAANET::getPosition
JPosition3D getPosition(const Vec &v)
Get position.
Definition: JAAnetToolkit.hh:197
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JTOOLS::PI
static const double PI
Constants.
Definition: JConstants.hh:20
JAANET::count_hadrons
int count_hadrons(const Evt &evt)
Count the number of hadrons in a given event (not including neutral pions)
Definition: JAAnetToolkit.hh:602
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
JPHYSICS::getMaximalWavelength
double getMaximalWavelength()
Get maximal wavelength for PDF evaluations.
Definition: JPDFToolkit.hh:49