// BLTrackFile.hh /* This source file is part of G4beamline, http://g4beamline.muonsinc.com Copyright (C) 2003,2004,2005,2006 by Tom Roberts, all rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/copyleft/gpl.html */ #ifndef BLTRACKFILE_HH #define BLTRACKFILE_HH #include #include "globals.hh" #include "G4ThreeVector.hh" enum BLTrackFileStatus { BLTF_OK=0, BLTF_ENDOFFILE=1, BLTF_ERROR=2 , BLTF_DUMMY=3}; /** class BLTrackFile creates or reads an ASCII file containing tracks. * * The file format is ASCII: * Lines begining with # are comments * First line is a structured comment (if not present the input * routine issues a warning): * #BLTrackFile ... user comment... * Second line is a comment giving the column names: * #x y z Px Py Pz t PDGid EventID TrackID ParentID weight * Third line is a comment giving the units: * #cm cm cm MeV/c MeV/c MeV/c ns - - - - - * OR: * #mm mm mm MeV/c MeV/c MeV/c ns - - - - - * (When writing, mm are used; on reading, mm are assumed, but a * comment line containing "cm cm cm" switches to cm.) * Thereafter follow the tracks, one per line. While the input * routine can handle initial spaces in the first column, it is * STRONGLY suggested you not put any there (so cut/grep will * work). Any fixed or floating-point format will do; PDGid, * EventID, TrackID, and ParentID are integers (but are read as doubles, * so .00 can be appended). * Common PDGid-s: * e- 11 e+ -11 * mu- 13 mu+ -13 * pi+ 211 pi- -211 * proton 2212 anti_proton -2212 * neutron 2112 anti_neutron -2112 * gamma 22 **/ class BLTrackFile { BLTrackFileStatus status; FILE *file; G4String mode; G4double unit; public: /// Default constructor. Reads return immediate EOF; writes do nothing. BLTrackFile(); /// Constructor. Opens the file; mode="r" or "w". /// comment is an identifying comment in the first line of the file /// (ignored for mode=r). BLTrackFile(G4String filename, G4String comment, G4String mode); /// Destructor. Closes the file. ~BLTrackFile(); /// setLengthUnit() will select either mm or cm. /// default is mm. void setLengthUnit(G4double mmorcm) { unit = mmorcm; } /// write() will write one track to the file (mode must have been "w"). /// Units are standard geant4 internal units. /// Note that weight is optional. BLTrackFileStatus write(G4ThreeVector& pos, G4double time, G4ThreeVector& momentum, int PDGid, int eventId, int trackId, int parentId, G4double weight=1.0); /// read() will read one track from the file (mode must have been "r"). /// Units are standard geant4 internal units. /// Use the other version of read() if you want to use the weight. BLTrackFileStatus read(G4ThreeVector& pos, G4double& time, G4ThreeVector& momentum, int& PDGid, int& eventId, int& trackId, int& parentId); /// read() will read one track from the file (mode must have been "r"). /// Units are standard geant4 internal units. BLTrackFileStatus read(G4ThreeVector& pos, G4double& time, G4ThreeVector& momentum, int& PDGid, int& eventId, int& trackId, int& parentId, G4double &weight); /// flush() will flush buffers to the file. void flush() { fflush(file); } }; #endif // BLTRACKFILE_HH