Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JHistHDG.cc File Reference

Program to histogram event-by-event data of shower light for making PDFs. More...

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 56 of file JHistHDG.cc.

57{
58 using namespace std;
59 using namespace JPP;
60
62 JLimit_t& numberOfEvents = inputFile.getLimit();
63 string outputFile;
64 string detectorFile;
65 bool hadronicMode;
66 int debug;
67
68 try {
69
70 JParser<> zap("Program to histogram event-by-event data of shower light for making PDFs.");
71
72 zap['f'] = make_field(inputFile);
73 zap['o'] = make_field(outputFile);
74 zap['n'] = make_field(numberOfEvents) = JLimit::max();
75 zap['a'] = make_field(detectorFile);
76 zap['H'] = make_field(hadronicMode);
77 zap['d'] = make_field(debug) = 1;
78
79 zap(argc, argv);
80 }
81 catch(const exception &error) {
82 FATAL(error.what() << endl);
83 }
84
85 if(hadronicMode) {
86 NOTICE("Plotting hadronic showers." << endl);
87 } else {
88 NOTICE("Plotting EM showers." << endl);
89 }
90
91
93
94 try {
95 load(detectorFile, detector);
96 }
97 catch(const JException& error) {
98 FATAL(error);
99 }
100
101 JHead head(JMultipleFileScanner<Head>(inputFile).getHeader()); // Monte Carlo header
102
103 const Vec offset = getOffset(head);
104
105 NOTICE("Apply detector offset " << offset << endl);
106
107 detector -= getPosition(offset);
108
109 const JCylinder3D can(detector.begin(), detector.end());
110
111 const JPMTRouter pmtRouter(detector);
112
113 const double P_atm = NAMESPACE::getAmbientPressure();
114 const double wmin = getMinimalWavelength();
115 const double wmax = getMaximalWavelength();
116
117 const JDispersion dispersion(P_atm);
118
119 const double ng[] = { dispersion.getIndexOfRefractionGroup(wmax),
120 dispersion.getIndexOfRefractionGroup(wmin) };
121
122 typedef JHistogram1D_t::abscissa_type abscissa_type;
123
128 JHistogramGridMap_t>::maplist> JMultiHistogram_t;
129
130 typedef JPDFTransformer<4, abscissa_type> JFunction4DTransformer_t;
131
132 JMultiHistogram_t h0; // occurrence rate of PMT (used for normalisation)
133 JMultiHistogram_t h1; // light from cascade
134
135 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));
136
137 set<double> C; // cosine emission angle
138
139 JQuadrature qeant(-1.0, 1.0, 20, JGeanx(1.00, -2.2));
140
141 for (JQuadrature::const_iterator i = qeant.begin(); i != qeant.end(); ++i) {
142 C.insert(i->getX());
143 }
144
145 C.insert(-1.01);
146 C.insert(-1.00);
147 C.insert( 1.00);
148 C.insert( 1.01);
149
150 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};
151 const double Dmax_m = 80.0;
152
153 for (int i = 0; i != sizeof(R)/sizeof(R[0]); ++i) {
154
155 const double R_m = R[i];
156
157 for (set<double>::const_iterator c = C.begin(); c != C.end(); ++c) {
158
159 const double cd = *c;
160
161 const double grid = 10.0 + 0.0 * R_m/100.0; // [deg]
162 const double alpha = 2.0 * sqrt(1.0 - cos(grid * PI / 180.0)); // azimuth angle unit step size
163
164 const int number_of_theta_points = max(2, (int) (180.0/(1.4 * grid)));
165 const double theta_step = PI / (number_of_theta_points + 1);
166
167 for (double theta = -0.5*theta_step; theta < PI + theta_step; theta += theta_step) {
168
169 const int number_of_phi_points = max(2, (int) (PI * sin(theta) / alpha));
170 const double phi_step = PI / (number_of_phi_points + 1);
171
172 for (double phi = -0.5*phi_step; phi < PI + phi_step; phi += phi_step) {
173
174 for (JMultiHistogram_t* p : { &h0, &h1 }) {
175 (*p)[R_m][cd][theta][phi];
176 }
177 }
178 }
179 }
180 }
181
182 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 };
183
184 for (JMultiHistogram_t::super_iterator i1 = h1.super_begin(); i1 != h1.super_end(); ++i1) {
185 for (int j = 0; j != sizeof(buffer)/sizeof(buffer[0]); ++j) {
186 i1.getValue()[buffer[j]];
187 }
188 }
189
190 while (inputFile.hasNext()) {
191
192 NOTICE("event: " << setw(10) << inputFile.getCounter() << '\r'); STATUS(endl);
193
194 const Evt* event = inputFile.next();
195
196 if (!has_neutrino(*event)) {
197 WARNING("Event " << inputFile.getCounter() << " does not correspond to a neutrino interaction; skip.");
198 continue;
199 }
200
201 if (!has_electron(*event) || count_hadrons(*event) == 0) {
202 WARNING("No electron/hadrons found; skip.");
203 continue;
204 }
205
206 const Trk& neutrino = get_neutrino(*event);
207
208 const double Evis = getVisibleEnergy (*event, can);
209 const Vec EvisVector = getVisibleEnergyVector(*event, can);
210
211 JVertex3D vertex = getVertex(neutrino);
212
213 const JRotation3D R(getDirection(EvisVector));
214
215 vertex.rotate(R);
216
217 for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
218
219 try {
220
221 JAxis3D axis = pmtRouter.getPMT(hit->pmt_id);
222
223 axis.transform(R, vertex.getPosition());
224
225 if ((!hadronicMode && from_electron(*hit)) || (hadronicMode && from_hadron(*hit))) {
226
227 const double t1 = vertex.getT() + axis.getLength() * getInverseSpeedOfLight() * getIndexOfRefraction();
228
229 const double D_m = axis.getLength();
230 const double cd = axis.getZ() / D_m;
231 const double theta = axis.getTheta();
232 const double phi = fabs(axis.getPhi());
233 const double dt = getTime(*hit) - t1;
234 const double npe = getNPE (*hit);
235
236 if (D_m < Dmax_m) {
237 h1.fill(D_m, cd, theta, phi, dt, npe/Evis);
238 }
239 }
240 }
241 catch(const exception& error) {
242 FATAL(error.what() << endl);
243 }
244 }
245
246 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
247
248 JPosition3D P = module->getPosition();
249
250 P.rotate(R);
251
252 P.sub(vertex);
253
254 if (P.getLength() < h0.getXmax()) {
255
256 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
257
258 JAxis3D axis = *pmt;
259
260 axis.transform(R, vertex);
261
262 h0.fill(axis.getLength(), axis.getZ()/axis.getLength(), axis.getTheta(), fabs(axis.getPhi()), 0.0, 1.0);
263 }
264 }
265 }
266 }
267
268 double integral = 0;
269 for (JMultiHistogram_t::super_iterator i = h0.super_begin(); i != h0.super_end(); ++i) {
270 integral+=i.getValue().getIntegral();
271 }
272 DEBUG("Integral:\t" << integral << endl);
273
274 // output
275
276 JFileStreamWriter out(outputFile.c_str());
277
278 NOTICE("Storing, " << flush);
279
280 for (const JMultiHistogram_t* p : { &h0, &h1 }) {
281 out.store(*p);
282 }
283
284 out.close();
285 NOTICE("done." << endl);
286}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define WARNING(A)
Definition JMessage.hh:65
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Monte Carlo run header.
Definition JHead.hh:1236
Detector data structure.
Definition JDetector.hh:96
Router for direct addressing of PMT data in detector data structure.
Definition JPMTRouter.hh:37
Axis object.
Definition JAxis3D.hh:41
void transform(const JAxis3D &axis)
Transform axis to reference frame of given axis.
Definition JAxis3D.hh:359
Data structure for position in three dimensions.
JPosition3D & rotate(const JRotation3D &R)
Rotate.
const JPosition3D & getPosition() const
Get position.
double getLength() const
Get length.
Definition JVector3D.hh:246
double getZ() const
Get z position.
Definition JVector3D.hh:115
JVector3D & sub(const JVector3D &vector)
Subtract vector.
Definition JVector3D.hh:158
double getTheta() const
Get theta angle.
Definition JVersor3D.hh:128
double getPhi() const
Get phi angle.
Definition JVersor3D.hh:144
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition JVertex3D.hh:147
Binary buffered file output.
General exception.
Definition JException.hh:24
Utility class to parse command line options.
Definition JParser.hh:1698
Implementation of dispersion for water in deep sea.
Function object for the probability density function of photon emission from EM-shower as a function ...
Definition JGeant.hh:32
Probability density function of photon emission from EM-shower as a function of cosine of the emissio...
Definition JGeanx.hh:32
Template definition of transformer of the probability density function (PDF) of the time response of ...
General purpose class for object reading from a list of file names.
virtual bool hasNext() override
Check availability of next element.
counter_type getCounter() const
Get counter.
virtual const pointer_type & next() override
Get next element.
container_type::const_iterator const_iterator
collection_type::abscissa_type abscissa_type
Type definition for numerical integration.
Transformable multidimensional histogram.
JDirection3D getDirection(const Vec &dir)
Get direction.
bool from_hadron(const Hit &hit)
Test whether given hit was produced by a hadronic shower.
JVertex3D getVertex(const Trk &track)
Get vertex.
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
bool has_electron(const Evt &evt)
Test whether given event has an electron.
JPosition3D getPosition(const Vec &pos)
Get position.
bool from_electron(const Hit &hit)
Test whether given hit was produced by an electron.
double getNPE(const Hit &hit)
Get true charge of hit.
Vec getOffset(const JHead &header)
Get offset.
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
int count_hadrons(const Evt &evt)
Count the number of hadrons in a given event (not including neutral pions)
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
double getIndexOfRefraction()
Get average index of refraction of water corresponding to group velocity.
double getMinimalWavelength()
Get minimal wavelength for PDF evaluations.
const double getInverseSpeedOfLight()
Get inverse speed of light.
double getMaximalWavelength()
Get maximal wavelength for PDF evaluations.
static const double C
Physics constants.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double getVisibleEnergy(const Trk &, const JCylinder3D &)
Get the visible energy of a track.
Vec getVisibleEnergyVector(const Trk &track, const JCylinder3D &can=getMaximumContainmentVolume())
Get the visible energy vector of a track.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
const char * getTime()
Get current local time conform ISO-8601 standard.
JHistogram1D< JElement2D< double, double >, JCollection > JHistogram1D_t
Type definition of a 1 dimensional histogram based on a JCollection.
int j
Definition JPolint.hh:801
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
The cylinder used for photon tracking.
Definition JHead.hh:575
Detector file.
Definition JHead.hh:227
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
static counter_type max()
Get maximum counter value.
Definition JLimit.hh:128
Type definition of a JHistogramMap based on JGridMap implementation.
Type definition of a JHistogramMap based on JMap implementation.
Auxiliary class for recursive map list generation.
Definition JMapList.hh:109
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition Trk.hh:15
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition Vec.hh:13