BLTrackFile.hh

Go to the documentation of this file.
00001 //      BLTrackFile.hh
00002 /*
00003 This source file is part of G4beamline, http://g4beamline.muonsinc.com
00004 Copyright (C) 2003,2004,2005,2006 by Tom Roberts, all rights reserved.
00005 
00006 This program is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU General Public License
00008 as published by the Free Software Foundation; either version 2
00009 of the License, or (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 http://www.gnu.org/copyleft/gpl.html
00017 */
00018 
00019 #ifndef BLTRACKFILE_HH
00020 #define BLTRACKFILE_HH
00021 
00022 #include <stdio.h>
00023 #include "globals.hh"
00024 #include "G4ThreeVector.hh"
00025 
00026 enum BLTrackFileStatus { BLTF_OK=0, BLTF_ENDOFFILE=1, BLTF_ERROR=2 , 
00027                         BLTF_DUMMY=3};
00028 
00029 /**     class BLTrackFile creates or reads an ASCII file containing tracks.
00030  *
00031  *      The file format is ASCII:
00032  *      Lines begining with # are comments
00033  *      First line is a structured comment (if not present the input
00034  *      routine issues a warning):
00035  *              #BLTrackFile ... user comment...
00036  *      Second line is a comment giving the column names:
00037  *              #x y z Px Py Pz t PDGid EventID TrackID ParentID weight
00038  *      Third line is a comment giving the units:
00039  *              #cm cm cm MeV/c MeV/c MeV/c ns - - - - -
00040  *      OR:
00041  *              #mm mm mm MeV/c MeV/c MeV/c ns - - - - -
00042  *      (When writing, mm are used; on reading, mm are assumed, but a
00043  *      comment line containing "cm cm cm" switches to cm.)
00044  *      Thereafter follow the tracks, one per line. While the input
00045  *      routine can handle initial spaces in the first column, it is
00046  *      STRONGLY suggested you not put any there (so cut/grep will
00047  *      work). Any fixed or floating-point format will do; PDGid,
00048  *      EventID, TrackID, and ParentID are integers (but are read as doubles,
00049  *      so .00 can be appended).
00050  *      Common PDGid-s:
00051  *              e-      11              e+      -11
00052  *              mu-     13              mu+     -13
00053  *              pi+     211             pi-     -211
00054  *              proton  2212            anti_proton -2212
00055  *              neutron 2112            anti_neutron -2112
00056  *              gamma   22
00057  **/
00058 class BLTrackFile {
00059         BLTrackFileStatus status;
00060         FILE *file;
00061         G4String mode;
00062         G4double unit;
00063 public:
00064         /// Default constructor. Reads return immediate EOF; writes do nothing.
00065         BLTrackFile();
00066 
00067         /// Constructor. Opens the file; mode="r" or "w".
00068         /// comment is an identifying comment in the first line of the file
00069         /// (ignored for mode=r).
00070         BLTrackFile(G4String filename, G4String comment, G4String mode);
00071 
00072         /// Destructor. Closes the file.
00073         ~BLTrackFile();
00074 
00075         /// setLengthUnit() will select either mm or cm.
00076         /// default is mm.
00077         void setLengthUnit(G4double mmorcm) { unit = mmorcm; }
00078 
00079         /// write() will write one track to the file (mode must have been "w").
00080         /// Units are standard geant4 internal units.
00081         /// Note that weight is optional.
00082         BLTrackFileStatus write(G4ThreeVector& pos, G4double time,
00083                         G4ThreeVector& momentum, int PDGid, int eventId,
00084                         int trackId, int parentId, G4double weight=1.0);
00085 
00086         /// read() will read one track from the file (mode must have been "r").
00087         /// Units are standard geant4 internal units.
00088         /// Use the other version of read() if you want to use the weight.
00089         BLTrackFileStatus read(G4ThreeVector& pos, G4double& time,
00090                         G4ThreeVector& momentum, int& PDGid, int& eventId,
00091                         int& trackId, int& parentId);
00092         /// read() will read one track from the file (mode must have been "r").
00093         /// Units are standard geant4 internal units.
00094         BLTrackFileStatus read(G4ThreeVector& pos, G4double& time,
00095                         G4ThreeVector& momentum, int& PDGid, int& eventId,
00096                         int& trackId, int& parentId, G4double &weight);
00097 
00098         /// flush() will flush buffers to the file.
00099         void flush() { fflush(file); }
00100 };
00101 
00102 #endif // BLTRACKFILE_HH
g4beamline