1#ifndef IO_ASCII_INCLUDED 
    2#define IO_ASCII_INCLUDED 
   17#include "TDatabasePDG.h" 
   24const char* 
const  hit_t           =  
"hit:";
 
 
   70inline bool startswith( 
const std::string& a, 
const std::string& b )
 
   72  if ( a.find( b ) == 0 ) 
return true;
 
 
   82inline std::string 
trim(
const std::string& s)
 
   86  if ( s == 
"" ) 
return s;
 
   91  for (i1 = 0; i1 < s.length(); i1++)
 
   93    if ( !isspace (s[i1]) ) 
break;
 
   95  for (i2 = s.length() - 1 ; i2 > i1 ; i2--)
 
   97    if ( !isspace (s[i2]) ) 
break;
 
   99  return s.substr( i1, i2 - i1 + 1 );
 
 
 
  116  return TDatabasePDG::Instance()->ConvertGeant3ToPdg( 
geant3_code );
 
 
  131  return TDatabasePDG::Instance()->ConvertPdgToGeant3( 
pdg_code );
 
 
  144  is >> v.
x >> v.
y >> v.
z;
 
 
  157  os << v.
x << 
' ' << v.
y << 
' ' << v.
z;
 
 
  169inline bool read ( 
Hit& h, std::istream& is, 
bool read_mc = 
false  )
 
 
  203  os << tag << 
' ' << h.
id << 
' ' << om_id << 
' ' << h.
a << 
' ' << h.
t;
 
 
  226  istringstream il(ss);
 
  227  for ( 
double x; il >> x ; ) r.push_back( x );
 
 
  242  vec.insert( vec.begin(), value );
 
 
  254inline bool read ( 
Evt& evt, std::istream& is, 
bool skip_hits = 
false )
 
  265  is >> evt.
mc_id >> mc_event_type;
 
  267  Trk trk_nu, trk_primary;
 
  268  bool have_trk_nu(
false), have_trk_primary(
false);
 
  285      is.ignore( 1000, 
'\n' );
 
  297      evt.
hits.push_back( h );
 
  312      istringstream ii(line);
 
  358          evt.
trks.push_back( t );
 
  381          ii >> t.
t >> trk_primary.
type; 
 
  384          have_trk_primary = 
true;
 
  396          out << 
"Unknown tag " << w << 
" for trk ";
 
  398          throw Exception(
static_cast<ostringstream&
>(out).str());
 
  404        out << 
"Error reading trk ";
 
  406        throw Exception(
static_cast<ostringstream&
>(out).str());
 
  416      evt.
w2list.resize( std::max( evt.
w2list.size(), v.size()));
 
  417      std::copy( v.begin(), v.end() , evt.
w2list.begin() );
 
  438      if ( v.size() > 3 ) {
 
  446      unsigned nsec, n16ns_ticks;
 
  447      is >> nsec >> n16ns_ticks;
 
  472      if ( have_trk_primary && have_trk_nu ) {
 
  474        bool same = trk_nu.
pos == trk_primary.
pos &&
 
  475                    trk_nu.
dir == trk_primary.
dir &&
 
  476                    trk_nu.
E   == trk_primary.
E;
 
  486      } 
else if ( have_trk_primary  ) {
 
  491      } 
else if ( have_trk_nu ) {
 
  500      is.ignore( 1000, 
'\n' );
 
 
  521inline bool write( 
const Evt& evt, std::ostream& os )
 
  526  const int precision = 12;
 
  527  auto old_flags = os.flags();
 
  528  auto old_precision = os.precision( precision );
 
  529  os.unsetf( std::ios_base::scientific | std::ios_base::fixed ); 
 
  533  for ( 
auto& trk : evt.
mc_trks ) {
 
  535    const std::string& tag = trk.comment;
 
  545      os << 
' ' << trk.t << 
' ' << 
geant3_code(trk.type) << 
' ' << trk.len;
 
  555      os << 
' ' << trk.t << 
' ' << trk.type << endl;
 
  583  for ( 
auto& trk : evt.
trks    ) {
 
  584    os << 
mc_keys::track_fit_t << 
' ' << trk.id << 
' ' << trk.pos << 
' ' << trk.dir << 
' ' << trk.E << 
' ' << trk.t << endl;
 
  600  os.flags( old_flags );
 
  601  os.precision( old_precision );
 
 
  627  while (getline( is, line ))
 
  644    if (!start) 
continue;
 
  649      std::cout << 
"Warning: line with empty tag found when reading header" << endl;
 
  650      std::cout << 
"        "<< line << endl;
 
  651      std::cout << 
"         will be skipped" << endl;
 
  662    THROW(
Exception, 
"Reading of MC header terminated before finding a start_run: tag. Please check your file");
 
 
std::vector< std::string > splitstring(const std::string &str, char delim=' ')
Split string at delimiter.
 
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
 
static std::ostream & getOstream()
Get output stream for conversion of exception.
 
int pdg_code(int geant3_code)
Convert Geant3 to PDG particle type.
 
bool write(const Vec &v, std::ostream &os)
Write a Vec(tor) to a stream.
 
void push_front(std::vector< T > &vec, const T &value)
Put value in front of data.
 
int geant3_code(int pdg_code)
Convert PDG to Geant3 particle type.
 
std::vector< double > read_line_to_vector(std::istream &is)
Read data.
 
bool read(Vec &v, std::istream &is)
Read a Vec(tor) from a stream.
 
bool startswith(const std::string &a, const std::string &b)
Check if string starts with given text.
 
std::string trim(const std::string &s)
Remove leading and trailing white spaces.
 
const char *const w3list_t
 
const char *const neutrino_t
 
const char *const weights_t
 
const char *const center_on_can_t
 
const char *const eventtime_t
 
const char *const track_in_t
 
const char *const track_t
 
const char *const muon_decay_t
 
const char *const start_event_t
 
const char *const start_run_t
 
const char *const hourangle_t
 
const char *const track_bundle_t
 
const char *const end_event_t
 
const char *const track_fit_t
 
const char *const w2list_t
 
const char *const hit_raw_t
 
const char *const track_primary_t
 
const char *const center_on_can_y
 
const char *const muon_decay_y
 
const char *const energy_lost_in_can
 
const char *const center_on_can_x
 
const char *const muon_decay_z
 
const char *const muon_decay_x
 
const char *const hourangle
 
const char *const center_on_can_z
 
void clearusr()
Clear user data.
 
void setusr(const std::string &key, double value)
Set user data item with given key.
 
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
 
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]=w3 (see e.g. Tag list or km3net-dataformat/definitions)
 
int mc_id
identifier of the MC event (as found in ascii or antcc file).
 
std::vector< Hit > hits
list of hits
 
std::vector< Hit > mc_hits
MC: list of MC truth hits.
 
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
 
int id
offline event identifier
 
TTimeStamp mc_event_time
MC: true generation time (UTC) of the event, (default: 01 Jan 1970 00:00:00)
 
std::vector< double > w3list
MC: atmospheric flux information.
 
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list or km3net-dataformat/definitions)
 
std::vector< Trk > trks
list of reconstructed tracks (can be several because of prefits,showers, etc).
 
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
 
std::string set_line(std::string tag, std::string line, bool ensure_unique=true)
Set data with the given tag.
 
void print(std::ostream &out=std::cout) const
Print header.
 
int pmt_id
global PMT identifier as found in evt files
 
int dom_id
module identifier from the data (unique in the detector).
 
int origin
track id of the track that created this hit (mc only)
 
double a
hit amplitude (in p.e.)
 
int type
particle type or parametrisation used for hit (mc only)
 
unsigned int channel_id
PMT channel id {0,1, .., 30} local to moduke.
 
double t
hit time (from tdc+calibration or MC truth)
 
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
 
void print(std::ostream &out=std::cout) const
Print track.
 
int status
MC status code, see km3net-dataformat/definitions/trkmembers.csv for values.
 
int type
MC: particle type in PDG encoding.
 
std::string comment
use as you like
 
double E
Energy [GeV] (either MC truth or reconstructed)
 
double t
track time [ns] (when the particle is at pos )
 
double len
length, if applicable [m]
 
Vec pos
postion [m] of the track at time t
 
The Vec class is a straightforward 3-d vector, which also works in pyroot.
 
static const int PDG_MUONBUNDLE
muon bundle reached the can level (mupage)
 
static const int TRK_ST_FINALSTATE
for MC: the particle must be processed by detector simulation ('track_in' tag in evt files)....
 
static const int TRK_ST_MUONBUNDLE
initial state muon bundle (mupage)
 
static const int TRK_ST_PRIMARYCOSMIC
initial state cosmic ray ('track_primary' tag in evt files from corant).
 
static const int TRK_ST_PRIMARYNEUTRINO
initial state neutrino ('neutrino' tag in evt files from gseagen and genhen).
 
static const int W2LIST_GSEAGEN_BX
Bjorken x.
 
static const int W2LIST_GSEAGEN_CC
Charged current interaction flag.
 
static const int W2LIST_GSEAGEN_ICHAN
Interaction channel.
 
static const int W2LIST_GSEAGEN_BY
Bjorken y.