1 #ifndef IO_ASCII_INCLUDED
2 #define IO_ASCII_INCLUDED
17 #include "TDatabasePDG.h"
24 const char*
const hit_t =
"hit:";
61 namespace io_stringutil
72 if ( a.find( b ) == 0 )
return true;
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 );
113 if ( geant3_code == -1 )
return -1;
114 if ( geant3_code < 0 )
return pdg_code( -geant3_code );
116 return TDatabasePDG::Instance()->ConvertGeant3ToPdg( geant3_code );
127 if (pdg_code == -1 )
return -1;
131 return TDatabasePDG::Instance()->ConvertPdgToGeant3( pdg_code );
144 is >> v.
x >> v.
y >> v.
z;
157 os << v.
x <<
' ' << v.
y <<
' ' << v.
z;
169 inline 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 );
254 inline 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());
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' );
521 inline 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 ) {
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 );
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");
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
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter= ' ')
Read test summary.
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
#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 or km3net-dataformat/definitions) ...
const char *const muon_decay_t
const char *const track_fit_t
const char *const muon_decay_y
double E
Energy [GeV] (either MC truth or reconstructed)
int origin
track id of the track that created this hit (mc only)
void clearusr()
Clear user data.
const char *const hourangle
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.
const char *const eventtime_t
static const int PDG_MUONBUNDLE
muon bundle reached the can level (mupage)
static const int W2LIST_GSEAGEN_ICHAN
Interaction channel.
int mc_id
identifier of the MC event (as found in ascii or antcc file).
TTimeStamp mc_event_time
MC: true generation time (UTC) of the event, (default: 01 Jan 1970 00:00:00)
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]
static const int TRK_ST_PRIMARYNEUTRINO
initial state neutrino ('neutrino' tag in evt files from gseagen and genhen).
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).
std::string set_line(std::string tag, std::string line, bool ensure_unique=true)
Set data with the given tag.
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 ...
const char *const track_bundle_t
int type
MC: particle type in PDG encoding.
int status
MC status code, see km3net-dataformat/definitions/trkmembers.csv for values.
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.
static const int TRK_ST_FINALSTATE
for MC: the particle must be processed by detector simulation ('track_in' tag in evt files)...
const char *const center_on_can_x
Vec pos
postion [m] of the track at time t
const char *const track_in_t
const char *const track_t
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 tdc+calibration or MC truth)
int dom_id
module identifier from the data (unique in the detector).
then fatal Wrong number of arguments fi set_variable ARCHIVE $argv[1] set_variable VERSION $argv[2] set_variable DIR $argv[3] source JAcousticsToolkit sh set_variable DETECTOR $DIR $ACOUSTICS_DETECTOR if[[!-f $DETECTOR]]
const char *const muon_decay_z
void copy(const Head &from, JHead &to)
Copy header from from to to.
void push_front(std::vector< T > &vec, const T &value)
Put value in front of data.
int id
offline event identifier
unsigned int channel_id
PMT channel id {0,1, .., 30} 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 or km3net-dataformat/definitions) ...
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.