Jpp
Functions
JHistHDE.cc File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdexcept>
#include "evt/Head.hh"
#include "evt/Evt.hh"
#include "evt/Hit.hh"
#include "evt/Trk.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"
#include "JAAnet/JParticleTypes.hh"

Go to the source code of this file.

Functions

vector< Int_t > getHitRemapping (const vector< Trk > *tracklist)
 
int main (int argc, char **argv)
 

Detailed Description

Program to histogram event-by-event and track-by-track for making PDFs of lights of individual particles.

Author
jseneca

Definition in file JHistHDE.cc.

Function Documentation

◆ getHitRemapping()

vector<Int_t> getHitRemapping ( const vector< Trk > *  tracklist)
inline

Definition at line 58 of file JHistHDE.cc.

58  {
59  vector<Int_t> hit_remapping;
60  for (vector<Trk>::const_iterator i = tracklist->begin(); i != tracklist->end(); ++i) {
61  //Skip pathological neutrino that is not the primary incoming neutrino
62  if(i->type == TRACK_TYPE_NUMU && i != tracklist->begin()){continue;}
63  hit_remapping.push_back(i->id);
64  }
65  return hit_remapping;
66 }

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 68 of file JHistHDE.cc.

69 {
70  using namespace std;
71  using namespace JPP;
72 
73  JMultipleFileScanner<Evt> inputFile;
74  //JLimit_t& numberOfEvents = inputFile.getLimit();
75  string outputFile = "J%s.HDE"; //'s' for single (particle), or simulation
76  string detectorFile;
77  vector<int> particles;
78  bool fix_bug;
79  int debug;
80 
81  try {
82 
83  JParser<> zap("Program to histogram event-by-event data of shower light for making PDFs.");
84 
85  zap['f'] = make_field(inputFile);
86  zap['o'] = make_field(outputFile);
87  //zap['n'] = make_field(numberOfEvents) = JLimit::max();
88  zap['a'] = make_field(detectorFile);
89  zap['p'] = make_field(particles);
90  zap['b'] = make_field(fix_bug);
91  zap['d'] = make_field(debug) = 1;
92 
93  if (zap.read(argc, argv) != 0)
94  return 1;
95  }
96  catch(const exception &error) {
97  FATAL(error.what() << endl);
98  }
99 
100  JDetector detector;
101 
102  if(outputFile.find('%') != string::npos){
103  sort(particles.begin(), particles.end());
104  string prefix_t = "";
105  for(vector<int>::iterator ptype = particles.begin(); ptype != particles.end(); ptype++){
106  prefix_t += to_string((long long int)*ptype) + "_";
107  }
108  prefix_t.erase(prefix_t.size() - 1);
109  string::size_type pos_1 = outputFile.find('%');
110  outputFile.replace(pos_1, 1, prefix_t);
111  }
112 
113  try {
114  load(detectorFile, detector);
115  }
116  catch(const JException& error) {
117  FATAL(error);
118  }
119 
120  const JPosition3D center = get<JPosition3D>(getHeader(inputFile));
121 
122  NOTICE("Apply detector offset " << center << endl);
123 
124  detector -= center;
125 
126  const JPMTRouter pmtRouter(detector);
127 
128  const double P_atm = NAMESPACE::getAmbientPressure();
129  const double wmin = getMinimalWavelength();
130  const double wmax = getMaximalWavelength();
131 
132  const JDispersion dispersion(P_atm);
133 
134  const double ng[] = { dispersion.getIndexOfRefractionGroup(wmax),
135  dispersion.getIndexOfRefractionGroup(wmin) };
136 
137  typedef JHistogram1D_t::abscissa_type abscissa_type;
138 
139  typedef JTransformableMultiHistogram<JHistogram1D_t,
140  JMAPLIST<JHistogramMap_t,
141  JHistogramMap_t,
142  JHistogramMap_t,
143  JHistogramGridMap_t,
144  JHistogramGridMap_t>::maplist> JMultiHistogram_t;
145 
146  typedef JPDFTransformer<5, abscissa_type> JFunction5DTransformer_t;
147 
148  JMultiHistogram_t h0; // occurrence rate of PMT (used for normalisation)
149  JMultiHistogram_t h1; // light from track cascade
150 
151  h1.transformer.reset(new JFunction5DTransformer_t(21.5, 2, ng[0], 0.0, JGeant(JGeanx(1.00, -2.2)), 1e-2, NAMESPACE::getAngularAcceptance, 0.05));
152 
153  set<double> C; // cosine emission angle
154 
155  JQuadrature qeant(-1.0, 1.0, 30, JGeanx(1.00, -2.2));
156 
157  for (JQuadrature::const_iterator i = qeant.begin(); i != qeant.end(); ++i) {
158  C.insert(i->getX());
159  }
160 
161  C.insert(-1.01);
162  C.insert(-1.00);
163  C.insert( 1.00);
164  C.insert( 1.01);
165 
166  const double E_b[] = {0.01, 0.2, 0.4, 0.6, 0.8, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 25.0, 30.0, 40.0, 55.0, 70.0, 85.0, 100.0};
167 
168  const double R[] = {0.0, 1.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, 65.0, 80.0};
169  const double Dmax_m = R[sizeof(R)/sizeof(R[0]) - 1]; //Last element of R
170 
171  for (int iE = 0; iE != sizeof(E_b)/sizeof(E_b[0]); ++iE) {
172 
173  const double E_m = E_b[iE];
174 
175  for (int i = 0; i != sizeof(R)/sizeof(R[0]); ++i) {
176 
177  const double R_m = R[i];
178 
179  for (set<double>::const_iterator c = C.begin(); c != C.end(); ++c) {
180 
181  const double cd = *c;
182 
183  const double grid = 10.0 + 0.0 * R_m/100.0; // [deg]
184  const double alpha = 2.0 * sqrt(1.0 - cos(grid * PI / 180.0)); // azimuth angle unit step size
185 
186  const int number_of_theta_points = (max(2, (int) (180.0/(1.4 * grid))));
187  const double theta_step = PI / (number_of_theta_points + 1);
188 
189  for (double theta = -0.5*theta_step; theta < PI + theta_step; theta += theta_step) {
190  const int number_of_phi_points = (max(2, (int) (PI * sin(theta) / alpha)));
191  const double phi_step = PI / (number_of_phi_points + 1);
192 
193  for (double phi = -0.5*phi_step; phi < PI + phi_step; phi += phi_step) {
194 
195  for (JMultiHistogram_t* buffer[] = { &h0, &h1, NULL }, **histogram = buffer; *histogram != NULL; ++histogram) {
196  (**histogram)[E_m][R_m][cd][theta][phi];
197  }
198  }
199  }
200  }
201  }
202  }
203 
204  double buffer[] = {-15.0,-10.0,-7.5,-5,-4,-3,-2,-1.5,-1.0,-0.5,-0.1, 0.0,0.1, 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 };
205  for (JMultiHistogram_t::super_iterator
206  i1 = h1.super_begin(); i1 != h1.super_end(); ++i1) {
207  for (int j = 0; j != sizeof(buffer)/sizeof(buffer[0]); ++j) {
208  i1.getValue()[buffer[j]];
209  }
210  }//Buffer defines the binning of the inner histograms (dt)
211 
212 
213  long long int h0_fillcount = 0;
214  long long int h1_fillcount = 0;
215 
216  while (inputFile.hasNext()) {
217 
218  //NOTICE("event: " << setw(10) << inputFile.getCounter() << '\r'); STATUS(endl);
219  //I suspect the printing above slows down the program considerably
220 
221  const Evt* event = inputFile.next();
222  const vector<Trk>* mc_tracks = &(event->mc_trks);
223 
224  vector<int> hit_remap;
225 
226  //Fixes 2016 atmospheric neutrino simulation hit-making neutrino bug
227  //Remove after fix.
228  if(fix_bug){
229  hit_remap = getHitRemapping(mc_tracks);
230  //*************************************************
231  } else {
232  for (vector<Trk>::const_iterator i = mc_tracks->begin(); i != mc_tracks->end(); ++i) {
233  hit_remap.push_back(i->id);
234  }
235  }
236 
237  double t0 = (*mc_tracks)[1].t;
238 
239  for (vector<Hit>::const_iterator hit = event->mc_hits.begin(); hit != event->mc_hits.end(); ++hit) {
240 
241  try {
242 
243  if(hit->origin >= (int)(*mc_tracks).size()){
244  std::out_of_range err("Hit origin not in tracklist. Avoided segfault");
245  throw err;
246  }
247 
248  Int_t corr_origin = hit_remap[hit->origin];
249  Trk curr_track = (*mc_tracks)[corr_origin]; //Get track from corrected origin
250  JDirection3D dir = getDirection(curr_track); const JRotation3D R(dir);
251  JPosition3D pos = getPosition(curr_track); pos.rotate(R);
252  JAxis3D axis = pmtRouter.getPMT(hit->pmt_id);
253  axis.transform(R, pos);
254 
255  const double E = curr_track.E;
256  const double t1 = t0 + axis.getLength() * getInverseSpeedOfLight() * getIndexOfRefraction();
257  const double D_m = axis.getLength();
258  const double cd = axis.getZ()/D_m;
259  const double theta = axis.getTheta();
260  const double phi = fabs(axis.getPhi());
261  const double dt = getTime(*hit) - t1;
262  const double npe = getNPE(*hit);
263 
264  if(D_m < Dmax_m){
265  h1.fill(E, D_m, cd, theta, phi, dt, npe);
266  h1_fillcount += 1;
267  }
268  }
269  catch(const exception& error) {
270  std::cout << "Fatal error for event: " << inputFile.getCounter() << std::endl;
271  FATAL(error.what() << endl);
272  }
273  }
274 
275  // ignore primary neutrino -> ^
276  for (vector<Trk>::const_iterator tr = event->mc_trks.begin() + 1; tr != event->mc_trks.end(); ++tr) {
277 
278  if(find(particles.begin(), particles.end(), tr->type) == particles.end()){
279  continue;
280  }
281 
282  //cout << "Particle accepted: " << tr->type << endl;
283 
284 
285  JDirection3D dir = getDirection(*tr); const JRotation3D R(dir);
286  JPosition3D pos = getPosition(*tr); pos.rotate(R);
287 
288  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
289 
290  JPosition3D P = module->getPosition();
291 
292  P.rotate(R);
293 
294  P.sub(pos);
295 
296  if (P.getLength() < Dmax_m) {
297 
298  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
299 
300  JAxis3D axis = *pmt;
301  axis.transform(R, pos);
302 
303  h0.fill(tr->E, axis.getLength(), axis.getZ()/axis.getLength(), axis.getTheta(), fabs(axis.getPhi()), 0.0, 1.0);
304  h0_fillcount += 1;
305  }
306  }
307  }
308  }
309 
310  if(h1_fillcount > h0_fillcount){
311  std::cout << "WARNING: recorded hits in normalization histogram that were not recorded in normalization histogram. This should not happen." << std::endl;
312  std::cout << "h1_fillcount: " << h1_fillcount << ", h0_fillcount: " << h0_fillcount << std::endl;
313  }
314  };
315 
316  double integral = 0;
317  for (JMultiHistogram_t::super_iterator i = h0.super_begin(); i != h0.super_end(); ++i) {
318  integral+=i.getValue().getIntegral();
319  }
320  DEBUG("Integral:\t" << integral << endl);
321 
322  // output
323 
324  JFileStreamWriter out(outputFile.c_str());
325 
326  NOTICE("Storing " << outputFile << ", " << flush);
327 
328  for (const JMultiHistogram_t* buffer[] = { &h0, &h1, NULL }, **i = buffer; *i != NULL; ++i) {
329  out.store(**i);
330  }
331 
332  out.close();
333  NOTICE("JHistHDE done. " << endl);
334  return 1;
335 }
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
JAANET::TRACK_TYPE_NUMU
Definition: JParticleTypes.hh:67
JGEOMETRY3D::JAxis3D::transform
void transform(const JAxis3D &axis)
Transform axis to reference frame of given axis.
Definition: JAxis3D.hh:370
std::vector< int >
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
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
JDETECTOR::JPMTRouter
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:33
JTOOLS::C
static const double C
Speed of light in vacuum [m/ns].
Definition: JConstants.hh:22
std::set
Definition: JSTDTypes.hh:13
JGEOMETRY3D::JPosition3D::rotate
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:185
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
JTOOLS::getInverseSpeedOfLight
const double getInverseSpeedOfLight()
Get inverse speed of light.
Definition: JConstants.hh:100
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::getMinimalWavelength
double getMinimalWavelength()
Get minimal wavelength for PDF evaluations.
Definition: JPDFToolkit.hh:38
JGEOMETRY3D::JPosition3D
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
JTOOLS::getIndexOfRefraction
double getIndexOfRefraction()
Get average index of refraction of water.
Definition: JConstants.hh:111
JAANET::getTime
double getTime(const Hit &hit)
Get true time of hit.
Definition: JAAnetToolkit.hh:87
JSUPPORT::JMultipleFileScanner::hasNext
virtual bool hasNext()
Check availability of next element.
Definition: JMultipleFileScanner.hh:350
JLANG::to_string
std::string to_string(const T &value)
Convert value to string.
Definition: JLangToolkit.hh:192
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
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
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
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
getHitRemapping
vector< Int_t > getHitRemapping(const vector< Trk > *tracklist)
Definition: JHistHDE.cc:58
JTOOLS::PI
static const double PI
Constants.
Definition: JConstants.hh:20
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
JGEOMETRY3D::JVector3D::getLength
double getLength() const
Get length.
Definition: JVector3D.hh:244
JPHYSICS::getMaximalWavelength
double getMaximalWavelength()
Get maximal wavelength for PDF evaluations.
Definition: JPDFToolkit.hh:49
JLANG::JException
General exception.
Definition: JException.hh:40
JGEOMETRY3D::JVersor3D::getPhi
double getPhi() const
Get phi angle.
Definition: JVersor3D.hh:140