1 #ifndef IO_ASCII_INCLUDED
2 #define IO_ASCII_INCLUDED
14 #include "../definitions/w2list_gseagen.hh"
16 #include "TDatabasePDG.h"
23 const char*
const hit_t =
"hit:";
58 namespace io_stringutil
67 inline bool startswith(
const std::string&
a,
const std::string& b )
69 if ( a.find( b ) == 0 )
return true;
79 inline std::string
trim(
const std::string& s)
83 if ( s ==
"" )
return s;
88 for (i1 = 0; i1 < s.length(); i1++)
90 if ( !isspace (s[i1]) )
break;
92 for (i2 = s.length() - 1 ; i2 > i1 ; i2--)
94 if ( !isspace (s[i2]) )
break;
96 return s.substr( i1, i2 - i1 + 1 );
110 if ( geant3_code == -1 )
return -1;
111 if ( geant3_code < 0 )
return pdg_code( -geant3_code );
113 return TDatabasePDG::Instance()->ConvertGeant3ToPdg( geant3_code );
124 if (pdg_code == -1 )
return -1;
128 return TDatabasePDG::Instance()->ConvertPdgToGeant3( pdg_code );
141 is >> v.
x >> v.
y >> v.
z;
154 os << v.
x <<
' ' << v.
y <<
' ' << v.
z;
166 inline bool read (
Hit& h, std::istream&
is,
bool read_mc =
false )
208 os << tag <<
' ' << h.
id <<
' ' << om_id <<
' ' << h.
a <<
' ' << h.
t;
232 istringstream ii(line);
236 if (!ii)
return false;
244 ii >> t.
type;
if (!ii)
return false;
247 if (!ii)
return true;
251 if (!ii)
return true;
276 out <<
"Error reading trk ";
278 throw Exception(static_cast<ostringstream&>(out).str());
303 os << tag <<
' ' << t.
id <<
' ' << t.
pos <<
' ' << t.
dir <<
' ' << t.
E <<
' ' << t.
t;
318 os <<
' ' << t.
type << endl;
363 istringstream il(ss);
364 for (
double x; il >> x ; )
r.push_back( x );
379 vec.insert( vec.begin(), value );
391 inline bool read (
Evt& evt, std::istream&
is,
bool skip_hits =
false )
402 is >> evt.
mc_id >> mc_event_type;
404 Trk trk_nu, trk_primary;
405 bool have_trk_nu(
false), have_trk_primary(
false);
423 is.ignore( 1000,
'\n' );
435 evt.
hits.push_back( h );
439 read( t, evt, is , w);
445 evt.
trks.push_back( t );
449 read( trk_nu ,evt, is, w );
454 read( trk_primary, evt, is, w );
455 have_trk_primary =
true;
523 if ( have_trk_primary && have_trk_nu )
525 bool same = trk_nu.pos == trk_primary.pos &&
526 trk_nu.dir == trk_primary.dir &&
527 trk_nu.E == trk_primary.E;
539 else if ( have_trk_primary )
545 else if ( have_trk_nu )
555 is.ignore( 1000,
'\n' );
576 inline bool write(
const Evt& evt, std::ostream& os)
633 if (!start)
continue;
638 THROW(
Exception,
"Invalid line found when reading header at " << line);
644 for (
int i = 1; hdr.find(key) != hdr.end() ; i++)
654 THROW(
Exception,
"Reading of MC header terminated before finding a start_run: tag. Please check your file");
void setusr(const std::string &key, double value)
Set user data item with given key.
const char *const energy_lost_in_can
static const int W2LIST_GSEAGEN_BX
Bjorken x.
const char *const w2list_t
const char *const center_on_can_y
const char *const weights_t
const char *const muon_decay_x
double t
track time [ns] (when the particle is at pos )
int pdg_code(int geant3_code)
Convert Geant3 to PDG particle type.
const char *const neutrino_t
const char *const center_on_can_z
bool read(Vec &v, std::istream &is)
Read a Vec(tor) from a stream.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
std::string comment
use as you like
const char *const w3list_t
int pmt_id
global PMT identifier as found in evt files
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]]=w3 (see e.g. Tag list)
const char *const muon_decay_t
const char *const track_fit_t
const char *const muon_decay_y
fi JEventTimesliceWriter a
double E
Energy [GeV] (either MC truth or reconstructed)
int origin
track id of the track that created this hit
void clearusr()
Clear user data.
const char *const hourangle
double pure_t
photon time before pmt simultion (MC only)
double a
hit amplitude (in p.e.)
The Vec class is a straightforward 3-d vector, which also works in pyroot.
int geant3_code(int pdg_code)
Convert PDG to Geant3 particle type.
static const int W2LIST_GSEAGEN_ICHAN
Interaction channel.
int mc_id
identifier of the MC event (as found in ascii or antcc file).
do set_variable OUTPUT_DIRECTORY $WORKDIR T
const char *const hourangle_t
void print(std::ostream &out=std::cout) const
Print header.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
double len
length, if applicable [m]
double pure_a
amptitude before pmt simution (MC only)
void push_front(std::vector< T > &vec, T &value)
Put value in front of data.
bool startswith(const std::string &a, const std::string &b)
Check if string starts with given text.
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
double getusr(const std::string &key) const
Get user data item with given key.
int type
MC: particle type in PDG encoding.
const char *const center_on_can_t
static const int W2LIST_GSEAGEN_CC
Charged current interaction flag.
static const int W2LIST_GSEAGEN_BY
Bjorken y.
const char *const center_on_can_x
Vec pos
postion of the track at time t [m]
const char *const track_in_t
const char *const track_t
bool haveusr(const std::string &key) const
Check availability of user data of the item with given key.
std::vector< Trk > trks
list of reconstructed tracks (can be several because of prefits,showers, etc).
bool write(const Vec &v, std::ostream &os)
Write a Vec(tor) to a stream.
std::vector< Hit > mc_hits
MC: list of MC truth hits.
double t
hit time (from calibration or MC truth)
int dom_id
module identifier from the data (unique in the detector).
const char *const muon_decay_z
std::string to_string(const T &value)
Convert value to string.
void copy(const Head &from, JHead &to)
Copy header from from to to.
int id
offline event identifier
unsigned int channel_id
PMT channel id {0,1, .., 31} local to moduke.
void print(std::ostream &out=std::cout) const
Print track.
const char *const track_primary_t
const char *const end_event_t
std::vector< double > read_line_to_vector(std::istream &is)
Read data.
std::vector< Hit > hits
list of hits
const char *const start_run_t
std::string trim(const std::string &s)
Remove leading and trailing white spaces.
static std::ostream & getOstream()
Get output stream for conversion of exception.
const char *const hit_raw_t
std::vector< std::string > splitstring(const std::string &str, char delim= ' ')
Split string at delimiter.
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
const char *const start_event_t
int type
particle type or parametrisation used for hit (mc only)
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list)
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
std::vector< double > w3list
MC: atmospheric flux information.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.