/*############################################################# *# # *# Author: C. Distefano # *# # *# Date: 31 May 2021 # *# Class to write different format output files # *# # *############################################################# */ #include "OutputWriter.hh" OutputWriter::OutputWriter(){ std::cout<Branch("Evt", &fEvt, 32000, 4 ); } #endif else { std::cout<<"Unknown oputput format, exiting..."; exit(1); } } /////////////////////////////////////////////////////////////////////////// OutputWriter::~OutputWriter(){ #ifdef _KM3NET_ENABLED__ if (OutputFormat=="km3net") { h.Write("Head"); fOutFile->Write(); fOutFile->Close(); delete fOutFile; delete fEvt; } #endif } /////////////////////////////////////////////////////////////////////////// void OutputWriter::WriteHeader(){ // unsigned int nrun = atoi(&numrun[0]); if(OutputFormat=="native") /* write info in a formatted ASCII table */ { fOutStream.setf(std::ios::showpoint|std::ios::fixed); fOutStream <<"Run Number: " < 0) { std::cerr << "run number should be more than 0"; exit(1); } } #endif #ifdef _KM3NET_ENABLED__ if(OutputFormat=="km3net") { tag << numrun; h.set_line("start_run",tag.str()); tag.str(""); } #endif /* set date and hour of execution */ Date d; std::string date_clock1; std::string dc = d.date_clock(date_clock1); tag << setiosflags(std::ios::showpoint) << setiosflags(std::ios::fixed) << std::setprecision(3); tag.str(""); tag << "MUPAGE "<0 and are on the can { /* fill the tag "track_in" */ std::ostringstream ch_track; ch_track << setiosflags(std::ios::showpoint) << setiosflags(std::ios::fixed) << std::setprecision(3) << std::setw(3) << mc << std::setw(10) << xMuOnCAN[ll]+can_center_x << std::setw(10) << yMuOnCAN[ll]+can_center_y << std::setw(10) << zMuOnCAN[ll] << std::setiosflags(std::ios::fixed) << std::setprecision(6) << std::setw(12) << uBundle.x << std::setw(12) << uBundle.y << std::setw(12) << uBundle.z << setiosflags(std::ios::fixed) << std::setprecision(3) << std::setw(14) << E[ll]*TeVtoGeV() << std::setw(10) << delaytime[ll] << std::setw(4) << GEANTid; fEvtAntares.taga("track_in", ch_track.str() ); mc++; } } std::ostringstream ch_bundle; ch_bundle << setiosflags(std::ios::showpoint) << setiosflags(std::ios::fixed) << std::setprecision(3) << std::setw(3) << m << std::setw(10) << posBundle.x+can_center_x << std::setw(10) << posBundle.y+can_center_y << std::setw(10) << posBundle.z << std::setiosflags(std::ios::fixed) << std::setprecision(6) << std::setw(12) << uBundle.x << std::setw(12) << uBundle.y << std::setw(12) << uBundle.z << std::setprecision(3) << std::setw(14) << bundle_energy*TeVtoGeV(); //VK 20/05/2021 fEvtAntares.taga("track_bundle", ch_bundle.str() ); std::ostringstream ch_evttime; ch_evttime << TimeStampSec << " " << TimeStampNs/16; fEvtAntares.taga("eventtime", ch_evttime.str() ); int ierr = fEvtAntares.write(fOutStream); if (ierr != 0) std::cout << "Error : Writing header event " << ierr << std::endl; } #endif #ifdef _KM3NET_ENABLED__ else if (OutputFormat=="km3net") /* write event in ANTARES format */ { int mc=1; fEvt -> id = nev; fEvt -> mc_id = nev; // check what it is and change it fEvt -> mc_run_id = numrun; fEvt -> mc_event_time.SetSec(TimeStampSec); // TTimeStamp mc_event_time; fEvt -> mc_event_time.SetNanoSec(TimeStampNs); fEvt -> mc_trks.clear(); int bundle_id = TRK_MOTHER_NONE; Trk trk; // add bundle in the track vector trk.id = mc; trk.status = 300; // to be changed in TRK_ST_MUONBUNDLE define status for track_bundle trk.type = 81; // to be changed in PDG_MUONBUNDLE set a MC pdg code trk.mother_id = TRK_MOTHER_NONE; trk.E = bundle_energy*TeVtoGeV(); trk.pos = Vec( posBundle.x+can_center_x, posBundle.y+can_center_y, posBundle.z ); trk.dir = Vec( uBundle.x, uBundle.y, uBundle.z ); trk.len = 0; trk.t = 0; bundle_id = trk.id; mc++; fEvt->mc_trks.push_back(trk); for (unsigned int ll = 0; ll < m; ++ll) { if((float)E[ll] != 0 && MuOnCAN[ll]==0) // writes muons if they have E>0 and are on the can { trk.id = mc; trk.status = TRK_ST_FINALSTATE; trk.type = kMuonMinus; trk.mother_id = bundle_id; trk.E = E[ll]*TeVtoGeV(); trk.pos = Vec( xMuOnCAN[ll]+can_center_x, yMuOnCAN[ll]+can_center_y, zMuOnCAN[ll] ); trk.dir = Vec( uBundle.x, uBundle.y, uBundle.z ); trk.len = 0; trk.t = delaytime[ll] ; mc++; fEvt->mc_trks.push_back(trk); } } fEvt->mc_trks.shrink_to_fit(); fTree->Fill(); fEvt->clear(); } #endif } /////////////////////////////////////////////////////////////////////////// void OutputWriter::WriteLiveTime(double avlivetime, double eavlivetime){ // if the selected format is antares and we are here, antares i/o is linked! if(OutputFormat=="native" || OutputFormat=="antares") { std::string line; std::ifstream file(OutputFileName.c_str()); unsigned int position=0; while (getline(file, line)) { if (line.find("livetime") != std::string::npos)break; position = file.tellg(); } file.close(); position+=10; fOutStream.setf(std::ios::fixed|std::ios::floatfield); fOutStream.seekp(position) << std::setprecision(3) << avlivetime << " " << std::setprecision(1) << eavlivetime; } #ifdef _KM3NET_ENABLED__ else if (OutputFormat=="km3net") { std::ostringstream tag; tag << std::setprecision(3) << avlivetime << " " << std::setprecision(1) << eavlivetime; h.set_line("livetime",tag.str()); } #endif }