Jpp
 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 "Evt.hh"
#include "Hit.hh"
#include "Trk.hh"
#include "Head.hh"
#include "Exception.hh"
#include "../definitions/w2list_gseagen.hh"
#include "../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...
 
bool read (Trk &t, Evt &evt, std::istream &is, const std::string &tag=mc_keys::track_in_t)
 Read track from a stream. More...
 
bool write (const Trk &t, const Evt &evt, std::ostream &os, std::string tag=mc_keys::track_in_t)
 Write track 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, 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::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 110 of file io_ascii.hh.

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

Convert PDG to Geant3 particle type.

Parameters
pdg_codePDG code
Returns
Geant3 code

Definition at line 124 of file io_ascii.hh.

125 {
126  if (pdg_code == -1 ) return -1;
127  if (pdg_code == +311 ) return geant3_code( 130 ); // K0 -> K0long
128  if (pdg_code == -311 ) return geant3_code( 130 ); // K0bar -> K0long
129 
130  return TDatabasePDG::Instance()->ConvertPdgToGeant3( pdg_code );
131 }
int pdg_code(int geant3_code)
Convert Geant3 to PDG particle type.
Definition: io_ascii.hh:110
int geant3_code(int pdg_code)
Convert PDG to Geant3 particle type.
Definition: io_ascii.hh:124
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 141 of file io_ascii.hh.

142 {
143  is >> v.x >> v.y >> v.z;
144  return !is.fail();
145 }
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 154 of file io_ascii.hh.

155 {
156  os << v.x << ' ' << v.y << ' ' << v.z;
157  return !os.fail();
158 }
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 168 of file io_ascii.hh.

169 {
170  h.dom_id = 0; // need a proper det file to
171  h.channel_id = 0; // set these.
172 
173  is >> h.id >> h.pmt_id >> h.a >> h.t;
174  if ( !read_mc )
175  {
176  return !is.fail();
177  }
178  else
179  {
180  is >> h.type >> h.origin;
181  }
182 
183  // at this point, an additional pure_a and pure_t may be present,
184  // but we do not read them.
185 
186  return !is.fail();
187 }
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 198 of file io_ascii.hh.

199 {
200  int om_id = h.pmt_id; // todo: deal with this better.
201 
202  os << tag << ' ' << h.id << ' ' << om_id << ' ' << h.a << ' ' << h.t;
203  if ( tag != mc_keys::hit_raw_t ) {
204  os << ' ' << h.type << ' ' << h.origin; // not writing pure_a and pure_t
205  }
206  os << std::endl;
207  return !os.fail();
208 }
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
bool read ( Trk t,
Evt evt,
std::istream &  is,
const std::string &  tag = mc_keys::track_in_t 
)
inline

Read track from a stream.

Parameters
ttrack
evtevent (for storing nu info in w2list)
isinput stream
tagtag
Returns
true if correctly read; else false

Definition at line 220 of file io_ascii.hh.

221 {
222  using namespace std;
223 
224  string line;
225  getline( is, line );
226  istringstream ii(line);
227 
228  ii >> t.id >> t.pos >> t.dir >> t.E >> t.t;
229 
230  if (!ii) return false;
231 
232  t.len = 0.0;
233  t.clearusr();
234  t.comment = tag;
235 
236  if ( tag == mc_keys::track_in_t)
237  {
239  ii >> t.type; if (!ii) return false;
240  t.type = pdg_code( t.type );
241  ii >> t.len;
242  if (!ii) return true; // missing length is not an error
243 
244  double eloss = 0;
245  ii >> eloss;
246  if (!ii) return true; // missing eloss is not an error
247 
249  }
250 
251  if ( tag == mc_keys::neutrino_t )
252  {
254  // the last item we will read is W2LIST_GSEAGEN_CC, make enough space;
255 
256  if (evt.w2list.size() < W2LIST_GSEAGEN_CC+1 ) evt.w2list.resize(W2LIST_GSEAGEN_CC+1);
257 
258 
259  ii >> evt.w2list[W2LIST_GSEAGEN_BX] >>
260  evt.w2list[W2LIST_GSEAGEN_BY] >>
262  t.type >>
264  }
265 
266  if ( tag == mc_keys::track_primary_t )
267  {
269  ii >> t.type; // nucleus id (in pdg format or not?)
270  }
271 
272  if ( ii.fail() )
273  {
274  ostream& out = Exception::getOstream();
275  out << "Error reading trk ";
276  t.print(out);
277  throw Exception(static_cast<ostringstream&>(out).str());
278  }
279 
280  return !ii.fail();
281 }
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:45
static const int W2LIST_GSEAGEN_BX
Bjorken x.
double t
track time [ns] (when the particle is at pos )
Definition: Trk.hh:18
int pdg_code(int geant3_code)
Convert Geant3 to PDG particle type.
Definition: io_ascii.hh:110
const char *const neutrino_t
Definition: io_ascii.hh:29
Vec dir
track direction
Definition: Trk.hh:17
std::string comment
use as you like
Definition: Trk.hh:33
is
Definition: JDAQCHSM.chsm:167
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:19
void clearusr()
Clear user data.
Definition: AAObject.hh:139
static const int W2LIST_GSEAGEN_ICHAN
Interaction channel.
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:21
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_PRIMARYCOSMIC
initial state cosmic ray (&#39;track_primary&#39; tag in evt files from corant).
Definition: trkmembers.hh:17
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:23
int id
track identifier
Definition: Trk.hh:15
int status
MC status code.
Definition: Trk.hh:27
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
Vec pos
postion of the track at time t [m]
Definition: Trk.hh:16
const char *const track_in_t
Definition: io_ascii.hh:26
General exception.
Definition: Exception.hh:13
void print(std::ostream &out=std::cout) const
Print track.
Definition: Trk.hh:158
const char *const track_primary_t
Definition: io_ascii.hh:30
static std::ostream & getOstream()
Get output stream for conversion of exception.
Definition: Exception.hh:63
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list)
Definition: Evt.hh:40
bool write ( const Trk t,
const Evt evt,
std::ostream &  os,
std::string  tag = mc_keys::track_in_t 
)
inline

Write track to a stream.

Parameters
ttrack
osoutput stream
tagtag
Returns
true if correctly read; else false

Definition at line 291 of file io_ascii.hh.

292 {
293  using namespace std;
294 
295  int type = t.type;
296 
297  if ( tag == mc_keys::auto_t )
298  {
299  tag = t.comment;
300  }
301 
302  os << tag << ' ' << t.id << ' ' << t.pos << ' ' << t.dir << ' ' << t.E << ' ' << t.t;
303 
304  if ( tag == mc_keys::track_in_t)
305  {
306  os << ' ' << geant3_code(type) << ' ' << t.len;
307 
309  {
310  os << ' ' << t.getusr( mc_usr_keys::energy_lost_in_can );
311  }
312  os << endl;
313  }
314 
315  else if (tag == mc_keys::track_primary_t)
316  {
317  os << ' ' << t.type << endl;
318  }
319 
320 
321  else if ( tag == mc_keys::neutrino_t )
322  {
323  double bx(0), by(0);
324  int ichan(0), cc(0);
325 
326  if ( evt.w2list.size() > W2LIST_GSEAGEN_CC ) {
327  bx = evt.w2list[W2LIST_GSEAGEN_BX];
328  by = evt.w2list[W2LIST_GSEAGEN_BY];
329  ichan = evt.w2list[W2LIST_GSEAGEN_ICHAN];
330  cc = evt.w2list[W2LIST_GSEAGEN_CC];
331  }
332 
333  os << ' ' << bx
334  << ' ' << by
335  << ' ' << ichan
336  << ' ' << t.type
337  << ' ' << cc
338  << endl;
339  }
340 
341  else
342  os << endl;
343 
344  return !os.fail();
345 }
const char *const energy_lost_in_can
Definition: io_ascii.hh:45
static const int W2LIST_GSEAGEN_BX
Bjorken x.
double t
track time [ns] (when the particle is at pos )
Definition: Trk.hh:18
const char *const neutrino_t
Definition: io_ascii.hh:29
Vec dir
track direction
Definition: Trk.hh:17
std::string comment
use as you like
Definition: Trk.hh:33
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:19
int geant3_code(int pdg_code)
Convert PDG to Geant3 particle type.
Definition: io_ascii.hh:124
static const int W2LIST_GSEAGEN_ICHAN
Interaction channel.
double len
length, if applicable [m]
Definition: Trk.hh:21
double getusr(const std::string &key) const
Get user data item with given key.
Definition: AAObject.hh:72
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:23
int id
track identifier
Definition: Trk.hh:15
static const int W2LIST_GSEAGEN_CC
Charged current interaction flag.
static const int W2LIST_GSEAGEN_BY
Bjorken y.
Vec pos
postion of the track at time t [m]
Definition: Trk.hh:16
const char *const track_in_t
Definition: io_ascii.hh:26
bool haveusr(const std::string &key) const
Check availability of user data of the item with given key.
Definition: AAObject.hh:42
const char *const track_primary_t
Definition: io_ascii.hh:30
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list)
Definition: Evt.hh:40
const char *const auto_t
Definition: io_ascii.hh:21
std::vector<double> read_line_to_vector ( std::istream &  is)
inline

Read data.

Parameters
isinput stream
Returns
data

Definition at line 354 of file io_ascii.hh.

355 {
356  using namespace std;
357 
359 
360  string ss;
361  getline(is, ss);
362  istringstream il(ss);
363  for ( double x; il >> x ; ) r.push_back( x );
364 
365  return r;
366 }
data_type r[M+1]
Definition: JPolint.hh:742
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,
T value 
)
inline

Put value in front of data.

Parameters
vecdata
valuevalue

Definition at line 376 of file io_ascii.hh.

377 {
378  vec.insert( vec.begin(), value );
379 }
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 390 of file io_ascii.hh.

391 {
392  using namespace std;
393 
394  string w;
395 
396  // find next start_event
397 
398  while ( w != mc_keys::start_event_t && is.good() ) is >> w;
399 
400  int mc_event_type; // dummy - this is always 1 in all files.
401  is >> evt.mc_id >> mc_event_type;
402 
403  Trk trk_nu, trk_primary;
404  bool have_trk_nu(false), have_trk_primary(false);
405 
406 
407  evt.mc_trks.clear();
408  evt.hits.clear();
409  evt.mc_hits.clear();
410 
411  string w_old;
412 
413  while ( is )
414  {
415  static Hit h;
416  static Trk t;
417 
418  is >> w;
419 
420  if (skip_hits && ( w == mc_keys::hit_t || w == mc_keys::hit_raw_t) )
421  {
422  is.ignore( 1000, '\n' );
423  continue;
424  }
425 
426  if ( w == mc_keys::hit_t )
427  {
428  read( h, is, true );
429  evt.mc_hits.push_back( h );
430  }
431  else if ( w == mc_keys::hit_raw_t )
432  {
433  read( h, is, false);
434  evt.hits.push_back( h );
435  }
436  else if ( w == mc_keys::track_in_t )
437  {
438  read( t, evt, is , w);
439  evt.mc_trks.push_back( t );
440  }
441  else if ( w == mc_keys::track_t )
442  {
443  read( t, evt, is );
444  evt.trks.push_back( t );
445  }
446  else if ( w == mc_keys::neutrino_t)
447  {
448  read( trk_nu , evt, is, w );
449  have_trk_nu = true;
450  }
451  else if ( w == mc_keys::track_primary_t)
452  {
453  read( trk_primary, evt, is, w );
454  have_trk_primary = true;
455  }
456  // else if ( w == mc_keys::primarylepton_t)
457  // {
458  // read( trk_primary_lepton, is, w);
459  // have_trk_primary_lepton = true;
460  // }
461  else if ( w == mc_keys::weights_t)
462  {
463  evt.w = read_line_to_vector( is );
464  }
465  else if ( w == mc_keys::w2list_t)
466  {
467  auto v = read_line_to_vector( is );
468  evt.w2list.resize( std::max( evt.w2list.size(), v.size()));
469  std::copy( v.begin(), v.end() , evt.w2list.begin() );
470  }
471  else if ( w == mc_keys::w3list_t)
472  {
473  evt.w3list = read_line_to_vector( is );
474  }
475  else if ( w == mc_keys::hourangle_t )
476  {
477  double ha;
478  is >> ha;
479  evt.setusr(mc_usr_keys::hourangle, ha );
480  }
481 
482 
483  else if ( w == mc_keys::center_on_can_t)
484  {
485  // in corsika files, there is the (undocumented?) center_on_can tag,
486  // which denoets the projection of the primary on the can. The direction
487  // of the center_on_can 'track' is by defintion the direction of the
488  // primary. We record the position in the usr data.
489 
491  if ( v.size() > 3 )
492  {
496  }
497  }
498 
499  else if ( w == mc_keys::eventtime_t )
500  {
501  unsigned nsec, n16ns_ticks;
502  is >> nsec >> n16ns_ticks;
503  evt.mc_event_time.SetSec( nsec );
504  evt.mc_event_time.SetNanoSec( n16ns_ticks * 16 );
505  }
506 
507 
508  else if ( w == mc_keys::muon_decay_t)
509  {
510  // in km3sim files, there are additional tags, including this one
512  if ( v.size() > 4 )
513  {
514  evt.setusr(mc_usr_keys::muon_decay_x, v[2] );
515  evt.setusr(mc_usr_keys::muon_decay_y, v[3] );
516  evt.setusr(mc_usr_keys::muon_decay_z, v[4] );
517  }
518  }
519 
520  else if ( w == mc_keys::end_event_t)
521  {
522  // finalize the mc_tracks -- as best we can.
523 
524  // If there is both a primary, and a neutrino, then the primary
525  // will go second (mc_trks[1]) with id=-1 and the neutrino will
526  // be mc_trks[0] with id=0. Unless they are same particle (identical
527  // pos,dir,E); in that case the primary is skipped.
528  // The primarylepton tag is not stored as a seperate Trk.
529 
530  if ( have_trk_primary && have_trk_nu )
531  {
532  bool same = trk_nu.pos == trk_primary.pos &&
533  trk_nu.dir == trk_primary.dir &&
534  trk_nu.E == trk_primary.E;
535 
536  if (!same)
537  {
538  trk_primary.id = -1;
539  push_front( evt.mc_trks, trk_primary);
540  }
541 
542  trk_nu.id = 0;
543  push_front( evt.mc_trks, trk_nu);
544  }
545 
546  else if ( have_trk_primary )
547  {
548  trk_primary.id = 0;
549  push_front( evt.mc_trks, trk_primary);
550  }
551 
552  else if ( have_trk_nu )
553  {
554  trk_nu.id = 0;
555  push_front( evt.mc_trks, trk_nu);
556  }
557 
558  return true;
559  }
560  else
561  {
562  is.ignore( 1000, '\n' );
563  }
564  w_old = w;
565  }
566 
567  if (!is.eof())
568  {
569  THROW(Exception, "Error while reading ascii event" << w << ' ' << evt.id);
570  }
571 
572  return false;
573 }
void setusr(const std::string &key, double value)
Set user data item with given key.
Definition: AAObject.hh:95
data_type w[N+1][M+1]
Definition: JPolint.hh:741
const char *const w2list_t
Definition: io_ascii.hh:33
const char *const center_on_can_y
Definition: io_ascii.hh:54
const char *const weights_t
Definition: io_ascii.hh:32
const char *const muon_decay_x
Definition: io_ascii.hh:49
const char *const neutrino_t
Definition: io_ascii.hh:29
const char *const center_on_can_z
Definition: io_ascii.hh:55
bool read(Vec &v, std::istream &is)
Read a Vec(tor) from a stream.
Definition: io_ascii.hh:141
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
const char *const w3list_t
Definition: io_ascii.hh:34
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:38
const char *const muon_decay_y
Definition: io_ascii.hh:50
is
Definition: JDAQCHSM.chsm:167
const char *const hourangle
Definition: io_ascii.hh:56
const char *const eventtime_t
Definition: io_ascii.hh:36
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:35
void push_front(std::vector< T > &vec, T &value)
Put value in front of data.
Definition: io_ascii.hh:376
const char *const center_on_can_t
Definition: io_ascii.hh:37
const char *const center_on_can_x
Definition: io_ascii.hh:53
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:51
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
const char *const hit_t
Definition: io_ascii.hh:24
int id
offline event identifier
Definition: Evt.hh:21
const char *const track_primary_t
Definition: io_ascii.hh:30
const char *const end_event_t
Definition: io_ascii.hh:39
std::vector< double > read_line_to_vector(std::istream &is)
Read data.
Definition: io_ascii.hh:354
std::vector< Hit > hits
list of hits
Definition: Evt.hh:35
data_type v[N+1][M+1]
Definition: JPolint.hh:740
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:13
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 583 of file io_ascii.hh.

584 {
585  using namespace std;
586 
587 
588  // set precision to 12 digits.
589  const int precision = 12;
590  auto old_flags = os.flags();
591  auto old_precision = os.precision( precision );
592  os.unsetf( std::ios_base::scientific | std::ios_base::fixed ); // default behaviour
593 
594 
595  os << mc_keys::start_event_t << ' ' << evt.mc_id << ' ' << 1 << endl;
596 
597  for ( auto& trk : evt.mc_trks ) write ( trk, evt, os, mc_keys::auto_t );
598  for ( auto& trk : evt.trks ) write ( trk, evt, os, mc_keys::track_fit_t );
599  for ( auto& hit : evt.mc_hits ) write ( hit, os, mc_keys::hit_t);
600  for ( auto& hit : evt.hits ) write ( hit, os, mc_keys::hit_raw_t);
601 
602  os << mc_keys::weights_t; for (auto& w : evt.w ) os << ' ' << w; os << endl;
603  os << mc_keys::w2list_t; for (auto& w : evt.w2list ) os << ' ' << w; os << endl;
604  os << mc_keys::w3list_t; for (auto& w : evt.w3list ) os << ' ' << w; os << endl;
605 
606  os << mc_keys::eventtime_t << evt.mc_event_time.GetSec() << " "
607  << evt.mc_event_time.GetNanoSec() / 16 << endl;
608 
609  os << mc_keys::end_event_t << endl;
610 
611  // restore os to how we found it.
612  os.flags( old_flags );
613  os.precision( old_precision );
614 
615  return true;
616 }
data_type w[N+1][M+1]
Definition: JPolint.hh:741
const char *const w2list_t
Definition: io_ascii.hh:33
const char *const weights_t
Definition: io_ascii.hh:32
const char *const w3list_t
Definition: io_ascii.hh:34
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
const char *const eventtime_t
Definition: io_ascii.hh:36
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
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:154
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 end_event_t
Definition: io_ascii.hh:39
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
const char *const auto_t
Definition: io_ascii.hh:21
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 631 of file io_ascii.hh.

632 {
633  using namespace std;
634 
635  string line;
636 
637  bool start = false;
638 
639  while (getline( is, line ))
640  {
642  {
643  break;
644  }
645 
647  {
648  start = true;
649  }
650 
652  {
653  THROW(Exception, "Unexpected tag " << mc_keys::start_event_t << " found while reading header at " << line << " (could mean the evt file has no header)");
654  }
655 
656  if (!start) continue;
657 
658  vector<string> v = splitstring( line, ':' );
659  if (v.size() < 2 )
660  {
661  std::cout << "Warning: line with empty tag found when reading header" << endl;
662  std::cout << " "<< line << endl;
663  std::cout << " will be skipped" << endl;
664  continue;
665  }
666 
667  // the following with unsure key in the map is unique by adding _1 _2 etc.
669 
670  }
671 
672  if (!start)
673  {
674  THROW(Exception, "Reading of MC header terminated before finding a start_run: tag. Please check your file");
675  }
676 
677  return start;
678 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
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:69
General exception.
Definition: Exception.hh:13
const char *const end_event_t
Definition: io_ascii.hh:39
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:81
data_type v[N+1][M+1]
Definition: JPolint.hh:740
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 688 of file io_ascii.hh.

689 {
690  hdr.print(os);
691  return true;
692 }
void print(std::ostream &out=std::cout) const
Print header.
Definition: Head.hh:295