Jpp  test_elongated_shower_pde
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Namespaces | Functions | Variables
io_ascii.hh File Reference
#include <string>
#include <istream>
#include <ostream>
#include <sstream>
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/offline/Hit.hh"
#include "km3net-dataformat/offline/Trk.hh"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Exception.hh"
#include "km3net-dataformat/definitions/w2list_gseagen.hh"
#include "km3net-dataformat/definitions/trkmembers.hh"
#include "TDatabasePDG.h"

Go to the source code of this file.

Namespaces

 mc_keys
 
 mc_usr_keys
 
 io_stringutil
 

Functions

bool io_stringutil::startswith (const std::string &a, const std::string &b)
 Check if string starts with given text. More...
 
std::string io_stringutil::trim (const std::string &s)
 Remove leading and trailing white spaces. More...
 
int pdg_code (int geant3_code)
 Convert Geant3 to PDG particle type. More...
 
int geant3_code (int pdg_code)
 Convert PDG to Geant3 particle type. More...
 
bool read (Vec &v, std::istream &is)
 Read a Vec(tor) from a stream. More...
 
bool write (const Vec &v, std::ostream &os)
 Write a Vec(tor) to a stream. More...
 
bool read (Hit &h, std::istream &is, bool read_mc=false)
 Read a hit from a stream. More...
 
bool write (const Hit &h, std::ostream &os, const std::string &tag=mc_keys::hit_t)
 Write a hit to a stream. More...
 
std::vector< double > read_line_to_vector (std::istream &is)
 Read data. More...
 
template<typename T >
void push_front (std::vector< T > &vec, const T &value)
 Put value in front of data. More...
 
bool read (Evt &evt, std::istream &is, bool skip_hits=false)
 Read event from a stream. More...
 
bool write (const Evt &evt, std::ostream &os)
 Write event to a stream. More...
 
bool read (Head &hdr, std::istream &is)
 Read header from a stream. More...
 
bool write (const Head &hdr, std::ostream &os)
 Write header to a stream. More...
 

Variables

const char *const mc_keys::auto_t = "auto"
 
const char *const mc_keys::start_run_t = "start_run:"
 
const char *const mc_keys::start_event_t = "start_event:"
 
const char *const mc_keys::hit_t = "hit:"
 
const char *const mc_keys::hit_raw_t = "hit_raw:"
 
const char *const mc_keys::track_in_t = "track_in:"
 
const char *const mc_keys::track_t = "track:"
 
const char *const mc_keys::track_fit_t = "track_fit:"
 
const char *const mc_keys::neutrino_t = "neutrino:"
 
const char *const mc_keys::track_primary_t = "track_primary:"
 
const char *const mc_keys::track_bundle_t = "track_bundle:"
 
const char *const mc_keys::weights_t = "weights:"
 
const char *const mc_keys::w2list_t = "w2list:"
 
const char *const mc_keys::w3list_t = "w3list:"
 
const char *const mc_keys::hourangle_t = "hourangle:"
 
const char *const mc_keys::eventtime_t = "eventtime:"
 
const char *const mc_keys::center_on_can_t = "center_on_can:"
 
const char *const mc_keys::muon_decay_t = "muon_decay:"
 
const char *const mc_keys::end_event_t = "end_event:"
 
const char *const mc_usr_keys::energy_lost_in_can = "energy_lost_in_can"
 
const char *const mc_usr_keys::muon_decay_x = "muon_decay_x"
 
const char *const mc_usr_keys::muon_decay_y = "muon_decay_y"
 
const char *const mc_usr_keys::muon_decay_z = "muon_decay_z"
 
const char *const mc_usr_keys::center_on_can_x = "center_on_can_x"
 
const char *const mc_usr_keys::center_on_can_y = "center_on_can_y"
 
const char *const mc_usr_keys::center_on_can_z = "center_on_can_z"
 
const char *const mc_usr_keys::hourangle = "hourangle"
 

Function Documentation

int pdg_code ( int  geant3_code)
inline

Convert Geant3 to PDG particle type.

Parameters
geant3_codeGeant3 code
Returns
PDG code

Definition at line 111 of file io_ascii.hh.

112 {
113  if ( geant3_code == -1 ) return -1; // used for k40 hits
114  if ( geant3_code < 0 ) return pdg_code( -geant3_code ); // used for scattered
115 
116  return TDatabasePDG::Instance()->ConvertGeant3ToPdg( geant3_code );
117 }
int pdg_code(int geant3_code)
Convert Geant3 to PDG particle type.
Definition: io_ascii.hh:111
int geant3_code(int pdg_code)
Convert PDG to Geant3 particle type.
Definition: io_ascii.hh:125
int geant3_code ( int  pdg_code)
inline

Convert PDG to Geant3 particle type.

Parameters
pdg_codePDG code
Returns
Geant3 code

Definition at line 125 of file io_ascii.hh.

126 {
127  if (pdg_code == -1 ) return -1;
128  if (pdg_code == +311 ) return geant3_code( 130 ); // K0 -> K0long
129  if (pdg_code == -311 ) return geant3_code( 130 ); // K0bar -> K0long
130 
131  return TDatabasePDG::Instance()->ConvertPdgToGeant3( pdg_code );
132 }
int pdg_code(int geant3_code)
Convert Geant3 to PDG particle type.
Definition: io_ascii.hh:111
int geant3_code(int pdg_code)
Convert PDG to Geant3 particle type.
Definition: io_ascii.hh:125
bool read ( Vec v,
std::istream &  is 
)
inline

Read a Vec(tor) from a stream.

Parameters
vvector
isinput stream
Returns
true if correctly read; else false

Definition at line 142 of file io_ascii.hh.

143 {
144  is >> v.x >> v.y >> v.z;
145  return !is.fail();
146 }
double z
Definition: Vec.hh:14
is
Definition: JDAQCHSM.chsm:167
double y
Definition: Vec.hh:14
double x
Definition: Vec.hh:14
bool write ( const Vec v,
std::ostream &  os 
)
inline

Write a Vec(tor) to a stream.

Parameters
vvector
osoutput stream
Returns
true if correctly written; else false

Definition at line 155 of file io_ascii.hh.

156 {
157  os << v.x << ' ' << v.y << ' ' << v.z;
158  return !os.fail();
159 }
double z
Definition: Vec.hh:14
double y
Definition: Vec.hh:14
double x
Definition: Vec.hh:14
bool read ( Hit h,
std::istream &  is,
bool  read_mc = false 
)
inline

Read a hit from a stream.

Parameters
hhit
isinput stream
read_mcoption to read also type and origin
Returns
true if correctly read; else false

Definition at line 169 of file io_ascii.hh.

170 {
171  h.dom_id = 0; // need a proper det file to
172  h.channel_id = 0; // set these.
173 
174  is >> h.id >> h.pmt_id >> h.a >> h.t;
175  if ( !read_mc )
176  {
177  return !is.fail();
178  }
179  else
180  {
181  is >> h.type >> h.origin;
182  }
183 
184  // at this point, an additional pure_a and pure_t may be present,
185  // but we do not read them.
186 
187  return !is.fail();
188 }
int pmt_id
global PMT identifier as found in evt files
Definition: Hit.hh:20
is
Definition: JDAQCHSM.chsm:167
int origin
track id of the track that created this hit
Definition: Hit.hh:29
double a
hit amplitude (in p.e.)
Definition: Hit.hh:24
int id
Definition: Hit.hh:11
double t
hit time (from tdc+calibration or MC truth)
Definition: Hit.hh:23
int dom_id
module identifier from the data (unique in the detector).
Definition: Hit.hh:14
unsigned int channel_id
PMT channel id {0,1, .., 31} local to moduke.
Definition: Hit.hh:15
int type
particle type or parametrisation used for hit (mc only)
Definition: Hit.hh:28
bool write ( const Hit h,
std::ostream &  os,
const std::string &  tag = mc_keys::hit_t 
)
inline

Write a hit to a stream.

Parameters
hhit
osoutput stream
tagtag
Returns
true if correctly written; else false

Definition at line 199 of file io_ascii.hh.

200 {
201  int om_id = h.pmt_id; // todo: deal with this better.
202 
203  os << tag << ' ' << h.id << ' ' << om_id << ' ' << h.a << ' ' << h.t;
204  if ( tag != mc_keys::hit_raw_t ) {
205  os << ' ' << h.type << ' ' << h.origin; // not writing pure_a and pure_t
206  }
207  os << std::endl;
208  return !os.fail();
209 }
int pmt_id
global PMT identifier as found in evt files
Definition: Hit.hh:20
int origin
track id of the track that created this hit
Definition: Hit.hh:29
double a
hit amplitude (in p.e.)
Definition: Hit.hh:24
int id
Definition: Hit.hh:11
double t
hit time (from tdc+calibration or MC truth)
Definition: Hit.hh:23
const char *const hit_raw_t
Definition: io_ascii.hh:25
int type
particle type or parametrisation used for hit (mc only)
Definition: Hit.hh:28
std::vector<double> read_line_to_vector ( std::istream &  is)
inline

Read data.

Parameters
isinput stream
Returns
data

Definition at line 218 of file io_ascii.hh.

219 {
220  using namespace std;
221 
223 
224  string ss;
225  getline(is, ss);
226  istringstream il(ss);
227  for ( double x; il >> x ; ) r.push_back( x );
228 
229  return r;
230 }
data_type r[M+1]
Definition: JPolint.hh:758
is
Definition: JDAQCHSM.chsm:167
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
template<typename T >
void push_front ( std::vector< T > &  vec,
const T value 
)
inline

Put value in front of data.

Parameters
vecdata
valuevalue

Definition at line 240 of file io_ascii.hh.

241 {
242  vec.insert( vec.begin(), value );
243 }
bool read ( Evt evt,
std::istream &  is,
bool  skip_hits = false 
)
inline

Read event from a stream.

Parameters
evtevent
isinput stream
skip_hitsoption to skip reading of hits
Returns
true if correctly read; else false

Definition at line 254 of file io_ascii.hh.

255 {
256  using namespace std;
257 
258  string w;
259 
260  // find next start_event
261 
262  while ( w != mc_keys::start_event_t && is.good() ) is >> w;
263 
264  int mc_event_type; // dummy - this is always 1 in all files.
265  is >> evt.mc_id >> mc_event_type;
266 
267  Trk trk_nu, trk_primary;
268  bool have_trk_nu(false), have_trk_primary(false);
269 
270 
271  evt.mc_trks.clear();
272  evt.hits.clear();
273  evt.mc_hits.clear();
274 
275  string w_old;
276 
277  while ( is )
278  {
279  static Hit h;
280  static Trk t;
281 
282  is >> w;
283 
284  if (skip_hits && ( w == mc_keys::hit_t || w == mc_keys::hit_raw_t)) {
285  is.ignore( 1000, '\n' );
286  continue;
287  }
288 
289  if ( w == mc_keys::hit_t ) {
290 
291  read( h, is, true );
292  evt.mc_hits.push_back( h );
293 
294  } else if ( w == mc_keys::hit_raw_t ) {
295 
296  read( h, is, false);
297  evt.hits.push_back( h );
298 
299  } else if ( w == mc_keys::track_in_t ||
300  w == mc_keys::track_t ||
301  w == mc_keys::neutrino_t ||
303  w == mc_keys::track_primary_t ) {
304 
305  t.id = 0;
306  t.len = 0.0;
307  t.clearusr();
308  t.comment = w;
309 
310  string line;
311  getline( is, line );
312  istringstream ii(line);
313 
314  if ( w != mc_keys::track_bundle_t ) {
315  ii >> t.id;
316  } else {
317  ii >> t.len;
318  }
319 
320  ii >> t.pos >> t.dir >> t.E;
321 
322  if (!ii.fail()) {
323 
324  if ( w == mc_keys::track_in_t) {
325 
327 
328  ii >> t.t >> t.type;
329 
330  if (!ii.fail()) {
331 
332  t.type = pdg_code( t.type );
333 
334  ii >> t.len;
335 
336  if ( ii.fail() ) { // missing length is not an error
337  evt.mc_trks.push_back( t );
338  continue;
339  }
340 
341  double eloss = 0;
342  ii >> eloss;
343 
344  if ( ii.fail() ) { // missing eloss is not an error
345  evt.mc_trks.push_back( t );
346  continue;
347  }
348 
350 
351  evt.mc_trks.push_back( t );
352  }
353 
354  } else if ( w == mc_keys::track_t ) {
355 
356  ii >> t.t;
357 
358  evt.trks.push_back( t );
359 
360  } else if ( w == mc_keys::neutrino_t ) {
361 
362  trk_nu.status = TRK_ST_PRIMARYNEUTRINO;
363 
364  // the last item we will read is W2LIST_GSEAGEN_CC, make enough space;
365  if (evt.w2list.size() < W2LIST_GSEAGEN_CC+1 ) evt.w2list.resize(W2LIST_GSEAGEN_CC+1);
366 
367  ii >> t.t >>
368  evt.w2list[W2LIST_GSEAGEN_BX] >>
369  evt.w2list[W2LIST_GSEAGEN_BY] >>
371  t.type >>
373 
374  have_trk_nu = true;
375 
376  } else if ( w == mc_keys::track_primary_t ) {
377 
378  trk_primary.status = TRK_ST_PRIMARYCOSMIC;
379 
380  ii >> t.t >> trk_primary.type; // nucleus id (in pdg format or not?)
381 
382  have_trk_primary = true;
383 
384  } else if ( w == mc_keys::track_bundle_t ) {
385 
386  t.type = PDG_MUONBUNDLE;
388 
389  evt.mc_trks.push_back( t );
390 
391  } else {
392 
393  ostream& out = Exception::getOstream();
394  out << "Unknown tag " << w << " for trk ";
395  t.print(out);
396  throw Exception(static_cast<ostringstream&>(out).str());
397  }
398  }
399 
400  if ( ii.fail() ) {
401  ostream& out = Exception::getOstream();
402  out << "Error reading trk ";
403  t.print(out);
404  throw Exception(static_cast<ostringstream&>(out).str());
405  }
406 
407  } else if ( w == mc_keys::weights_t) {
408 
409  evt.w = read_line_to_vector( is );
410 
411  } else if ( w == mc_keys::w2list_t) {
412 
413  auto v = read_line_to_vector( is );
414  evt.w2list.resize( std::max( evt.w2list.size(), v.size()));
415  std::copy( v.begin(), v.end() , evt.w2list.begin() );
416 
417  } else if ( w == mc_keys::w3list_t) {
418 
419  evt.w3list = read_line_to_vector( is );
420 
421  } else if ( w == mc_keys::hourangle_t ) {
422 
423  double ha;
424  is >> ha;
425  evt.setusr(mc_usr_keys::hourangle, ha );
426 
427  } else if ( w == mc_keys::center_on_can_t) {
428 
429  // in corsika files, there is the (undocumented?) center_on_can tag,
430  // which denoets the projection of the primary on the can. The direction
431  // of the center_on_can 'track' is by defintion the direction of the
432  // primary. We record the position in the usr data.
433 
435 
436  if ( v.size() > 3 ) {
440  }
441 
442  } else if ( w == mc_keys::eventtime_t ) {
443 
444  unsigned nsec, n16ns_ticks;
445  is >> nsec >> n16ns_ticks;
446  evt.mc_event_time.SetSec( nsec );
447  evt.mc_event_time.SetNanoSec( n16ns_ticks * 16 );
448 
449  } else if ( w == mc_keys::muon_decay_t) {
450 
451  // in km3sim files, there are additional tags, including this one
453  if ( v.size() > 4 )
454  {
455  evt.setusr(mc_usr_keys::muon_decay_x, v[2] );
456  evt.setusr(mc_usr_keys::muon_decay_y, v[3] );
457  evt.setusr(mc_usr_keys::muon_decay_z, v[4] );
458  }
459 
460  } else if ( w == mc_keys::end_event_t) {
461 
462  // finalize the mc_tracks -- as best we can.
463 
464  // If there is both a primary, and a neutrino, then the primary
465  // will go second (mc_trks[1]) with id=-1 and the neutrino will
466  // be mc_trks[0] with id=0. Unless they are same particle (identical
467  // pos,dir,E); in that case the primary is skipped.
468  // The primarylepton tag is not stored as a seperate Trk.
469 
470  if ( have_trk_primary && have_trk_nu ) {
471 
472  bool same = trk_nu.pos == trk_primary.pos &&
473  trk_nu.dir == trk_primary.dir &&
474  trk_nu.E == trk_primary.E;
475 
476  if (!same) {
477  trk_primary.id = -1;
478  push_front( evt.mc_trks, trk_primary);
479  }
480 
481  trk_nu.id = 0;
482  push_front( evt.mc_trks, trk_nu);
483 
484  } else if ( have_trk_primary ) {
485 
486  trk_primary.id = 0;
487  push_front( evt.mc_trks, trk_primary);
488 
489  } else if ( have_trk_nu ) {
490 
491  trk_nu.id = 0;
492  push_front( evt.mc_trks, trk_nu);
493  }
494 
495  return true;
496 
497  } else {
498  is.ignore( 1000, '\n' );
499  }
500 
501  w_old = w;
502  }
503 
504  if (!is.eof()) {
505  THROW(Exception, "Error while reading ascii event" << w << ' ' << evt.id);
506  }
507 
508  return false;
509 }
void setusr(const std::string &key, double value)
Set user data item with given key.
Definition: AAObject.hh:95
const char *const energy_lost_in_can
Definition: io_ascii.hh:46
static const int W2LIST_GSEAGEN_BX
Bjorken x.
data_type w[N+1][M+1]
Definition: JPolint.hh:757
const char *const w2list_t
Definition: io_ascii.hh:34
const char *const center_on_can_y
Definition: io_ascii.hh:55
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter= ' ')
Read test summary.
const char *const weights_t
Definition: io_ascii.hh:33
const char *const muon_decay_x
Definition: io_ascii.hh:50
double t
track time [ns] (when the particle is at pos )
Definition: Trk.hh:19
int pdg_code(int geant3_code)
Convert Geant3 to PDG particle type.
Definition: io_ascii.hh:111
const char *const neutrino_t
Definition: io_ascii.hh:29
const char *const center_on_can_z
Definition: io_ascii.hh:56
Vec dir
track direction
Definition: Trk.hh:18
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
std::string comment
use as you like
Definition: Trk.hh:35
const char *const w3list_t
Definition: io_ascii.hh:35
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]]=w3 (see e.g. Tag list)
Definition: Evt.hh:39
const char *const muon_decay_t
Definition: io_ascii.hh:39
const char *const muon_decay_y
Definition: io_ascii.hh:51
is
Definition: JDAQCHSM.chsm:167
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:20
void clearusr()
Clear user data.
Definition: AAObject.hh:139
const char *const hourangle
Definition: io_ascii.hh:57
const char *const eventtime_t
Definition: io_ascii.hh:37
static const int PDG_MUONBUNDLE
muon bundle reached the can level (mupage)
Definition: trkmembers.hh:38
static const int W2LIST_GSEAGEN_ICHAN
Interaction channel.
int mc_id
identifier of the MC event (as found in ascii or antcc file).
Definition: Evt.hh:23
TTimeStamp mc_event_time
MC: true generation time (UTC) of the event, (default: 01 Jan 1970 00:00:00)
Definition: Evt.hh:43
const char *const hourangle_t
Definition: io_ascii.hh:36
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
double len
length, if applicable [m]
Definition: Trk.hh:22
static const int TRK_ST_PRIMARYNEUTRINO
initial state neutrino (&#39;neutrino&#39; tag in evt files from gseagen and genhen).
Definition: trkmembers.hh:16
static const int TRK_ST_MUONBUNDLE
initial state muon bundle (mupage)
Definition: trkmembers.hh:18
static const int TRK_ST_PRIMARYCOSMIC
initial state cosmic ray (&#39;track_primary&#39; tag in evt files from corant).
Definition: trkmembers.hh:17
const char *const track_bundle_t
Definition: io_ascii.hh:31
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:24
int id
track identifier
Definition: Trk.hh:16
int status
MC status code, see km3net-dataformat/definitions/trkmembers.csv for values.
Definition: Trk.hh:28
const char *const center_on_can_t
Definition: io_ascii.hh:38
static const int W2LIST_GSEAGEN_CC
Charged current interaction flag.
static const int W2LIST_GSEAGEN_BY
Bjorken y.
static const int TRK_ST_FINALSTATE
particle to be tracked by detector-level MC (&#39;track_in&#39; tag in evt files from gseagen ...
Definition: trkmembers.hh:15
const char *const center_on_can_x
Definition: io_ascii.hh:54
Vec pos
postion of the track at time t [m]
Definition: Trk.hh:17
const char *const track_in_t
Definition: io_ascii.hh:26
Definition: Hit.hh:8
const char *const track_t
Definition: io_ascii.hh:27
std::vector< Trk > trks
list of reconstructed tracks (can be several because of prefits,showers, etc).
Definition: Evt.hh:36
General exception.
Definition: Exception.hh:13
std::vector< Hit > mc_hits
MC: list of MC truth hits.
Definition: Evt.hh:45
const char *const muon_decay_z
Definition: io_ascii.hh:52
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
void push_front(std::vector< T > &vec, const T &value)
Put value in front of data.
Definition: io_ascii.hh:240
const char *const hit_t
Definition: io_ascii.hh:24
int id
offline event identifier
Definition: Evt.hh:21
void print(std::ostream &out=std::cout) const
Print track.
Definition: Trk.hh:183
const char *const track_primary_t
Definition: io_ascii.hh:30
const char *const end_event_t
Definition: io_ascii.hh:40
std::vector< double > read_line_to_vector(std::istream &is)
Read data.
Definition: io_ascii.hh:218
std::vector< Hit > hits
list of hits
Definition: Evt.hh:35
data_type v[N+1][M+1]
Definition: JPolint.hh:756
static std::ostream & getOstream()
Get output stream for conversion of exception.
Definition: Exception.hh:63
const char *const hit_raw_t
Definition: io_ascii.hh:25
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:14
const char *const start_event_t
Definition: io_ascii.hh:23
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list)
Definition: Evt.hh:40
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition: Evt.hh:46
std::vector< double > w3list
MC: atmospheric flux information.
Definition: Evt.hh:41
bool write ( const Evt evt,
std::ostream &  os 
)
inline

Write event to a stream.

Parameters
evtevent
osoutput stream
Returns
true if correctly read; else false

Definition at line 519 of file io_ascii.hh.

520 {
521  using namespace std;
522 
523  // set precision to 12 digits.
524  const int precision = 12;
525  auto old_flags = os.flags();
526  auto old_precision = os.precision( precision );
527  os.unsetf( std::ios_base::scientific | std::ios_base::fixed ); // default behaviour
528 
529  os << mc_keys::start_event_t << ' ' << evt.mc_id << ' ' << 1 << endl;
530 
531  for ( auto& trk : evt.mc_trks ) {
532 
533  const std::string& tag = trk.comment;
534 
535  os << tag << ' '
536  << (tag != mc_keys::track_bundle_t ? trk.id : trk.len) << ' '
537  << trk.pos << ' '
538  << trk.dir << ' '
539  << trk.E;
540 
541  if ( tag == mc_keys::track_in_t ) {
542 
543  os << ' ' << trk.t << ' ' << geant3_code(trk.type) << ' ' << trk.len;
544 
545  if ( trk.haveusr( mc_usr_keys::energy_lost_in_can ) ) {
546  os << ' ' << trk.getusr( mc_usr_keys::energy_lost_in_can );
547  }
548 
549  os << endl;
550 
551  } else if ( tag == mc_keys::track_primary_t ) {
552 
553  os << ' ' << trk.t << ' ' << trk.type << endl;
554 
555  } else if ( tag == mc_keys::neutrino_t ) {
556 
557  double bx(0), by(0);
558  int ichan(0), cc(0);
559 
560  if ( evt.w2list.size() > W2LIST_GSEAGEN_CC ) {
561  bx = evt.w2list[W2LIST_GSEAGEN_BX];
562  by = evt.w2list[W2LIST_GSEAGEN_BY];
563  ichan = evt.w2list[W2LIST_GSEAGEN_ICHAN];
564  cc = evt.w2list[W2LIST_GSEAGEN_CC];
565  }
566 
567  os << ' ' << trk.t
568  << ' ' << bx
569  << ' ' << by
570  << ' ' << ichan
571  << ' ' << trk.type
572  << ' ' << cc
573  << endl;
574 
575  } else {
576 
577  os << endl;
578  }
579  }
580 
581  for ( auto& trk : evt.trks ) {
582  os << mc_keys::track_fit_t << ' ' << trk.id << ' ' << trk.pos << ' ' << trk.dir << ' ' << trk.E << ' ' << trk.t << endl;
583  }
584 
585  for ( auto& hit : evt.mc_hits ) write ( hit, os, mc_keys::hit_t);
586  for ( auto& hit : evt.hits ) write ( hit, os, mc_keys::hit_raw_t);
587 
588  os << mc_keys::weights_t; for (auto& w : evt.w ) os << ' ' << w; os << endl;
589  os << mc_keys::w2list_t; for (auto& w : evt.w2list ) os << ' ' << w; os << endl;
590  os << mc_keys::w3list_t; for (auto& w : evt.w3list ) os << ' ' << w; os << endl;
591 
592  os << mc_keys::eventtime_t << evt.mc_event_time.GetSec() << " "
593  << evt.mc_event_time.GetNanoSec() / 16 << endl;
594 
595  os << mc_keys::end_event_t << endl;
596 
597  // restore os to how we found it.
598  os.flags( old_flags );
599  os.precision( old_precision );
600 
601  return true;
602 }
const char *const energy_lost_in_can
Definition: io_ascii.hh:46
static const int W2LIST_GSEAGEN_BX
Bjorken x.
data_type w[N+1][M+1]
Definition: JPolint.hh:757
const char *const w2list_t
Definition: io_ascii.hh:34
const char *const weights_t
Definition: io_ascii.hh:33
const char *const neutrino_t
Definition: io_ascii.hh:29
const char *const w3list_t
Definition: io_ascii.hh:35
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]]=w3 (see e.g. Tag list)
Definition: Evt.hh:39
const char *const track_fit_t
Definition: io_ascii.hh:28
int geant3_code(int pdg_code)
Convert PDG to Geant3 particle type.
Definition: io_ascii.hh:125
const char *const eventtime_t
Definition: io_ascii.hh:37
static const int W2LIST_GSEAGEN_ICHAN
Interaction channel.
int mc_id
identifier of the MC event (as found in ascii or antcc file).
Definition: Evt.hh:23
TTimeStamp mc_event_time
MC: true generation time (UTC) of the event, (default: 01 Jan 1970 00:00:00)
Definition: Evt.hh:43
const char *const track_bundle_t
Definition: io_ascii.hh:31
static const int W2LIST_GSEAGEN_CC
Charged current interaction flag.
static const int W2LIST_GSEAGEN_BY
Bjorken y.
const char *const track_in_t
Definition: io_ascii.hh:26
std::vector< Trk > trks
list of reconstructed tracks (can be several because of prefits,showers, etc).
Definition: Evt.hh:36
bool write(const Vec &v, std::ostream &os)
Write a Vec(tor) to a stream.
Definition: io_ascii.hh:155
std::vector< Hit > mc_hits
MC: list of MC truth hits.
Definition: Evt.hh:45
const char *const hit_t
Definition: io_ascii.hh:24
const char *const track_primary_t
Definition: io_ascii.hh:30
const char *const end_event_t
Definition: io_ascii.hh:40
std::vector< Hit > hits
list of hits
Definition: Evt.hh:35
const char *const hit_raw_t
Definition: io_ascii.hh:25
const char *const start_event_t
Definition: io_ascii.hh:23
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list)
Definition: Evt.hh:40
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition: Evt.hh:46
std::vector< double > w3list
MC: atmospheric flux information.
Definition: Evt.hh:41
do if[[!-f $ACOUSTICS_WORKDIR/${KEY}.txt]]
Definition: JAcoustics.sh:39
bool read ( Head hdr,
std::istream &  is 
)
inline

Read header from a stream.

The stream may be positioned at any point before the tag mc_keys::start_run_t, which marks the beginning of the header. Information before the header (if any) is disgarded.

Parameters
hdrheader
isinput stream
Returns
true if correctly read; else false

Definition at line 617 of file io_ascii.hh.

618 {
619  using namespace std;
620 
621  string line;
622 
623  bool start = false;
624 
625  while (getline( is, line ))
626  {
628  {
629  break;
630  }
631 
633  {
634  start = true;
635  }
636 
638  {
639  THROW(Exception, "Unexpected tag " << mc_keys::start_event_t << " found while reading header at " << line << " (could mean the evt file has no header)");
640  }
641 
642  if (!start) continue;
643 
644  vector<string> v = splitstring( line, ':' );
645  if (v.size() < 2 )
646  {
647  std::cout << "Warning: line with empty tag found when reading header" << endl;
648  std::cout << " "<< line << endl;
649  std::cout << " will be skipped" << endl;
650  continue;
651  }
652 
653  // the following with unsure key in the map is unique by adding _1 _2 etc.
655 
656  }
657 
658  if (!start)
659  {
660  THROW(Exception, "Reading of MC header terminated before finding a start_run: tag. Please check your file");
661  }
662 
663  return start;
664 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
is
Definition: JDAQCHSM.chsm:167
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
std::string set_line(std::string tag, std::string line, bool ensure_unique=true)
Set data with the given tag.
Definition: Head.hh:175
bool startswith(const std::string &a, const std::string &b)
Check if string starts with given text.
Definition: io_ascii.hh:70
General exception.
Definition: Exception.hh:13
const char *const end_event_t
Definition: io_ascii.hh:40
const char *const start_run_t
Definition: io_ascii.hh:22
std::string trim(const std::string &s)
Remove leading and trailing white spaces.
Definition: io_ascii.hh:82
data_type v[N+1][M+1]
Definition: JPolint.hh:756
std::vector< std::string > splitstring(const std::string &str, char delim= ' ')
Split string at delimiter.
Definition: Head.hh:46
const char *const start_event_t
Definition: io_ascii.hh:23
bool write ( const Head hdr,
std::ostream &  os 
)
inline

Write header to a stream.

Parameters
hdrheader
osoutput stream
Returns
true if correctly written; else false

Definition at line 674 of file io_ascii.hh.

675 {
676  hdr.print(os);
677  return true;
678 }
void print(std::ostream &out=std::cout) const
Print header.
Definition: Head.hh:295