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 Ev# TrkId Parent 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  *      EV#, TrkId, and Parent are integers (but .00 can be appended).
00049  *      Common PDGid-s:
00050  *              e-      11              e+      -11
00051  *              mu-     13              mu+     -13
00052  *              pi+     211             pi-     -211
00053  *              proton  2212            anti_proton -2212
00054  *              neutron 2112            anti_neutron -2112
00055  *              gamma   22
00056  **/
00057 class BLTrackFile {
00058         BLTrackFileStatus status;
00059         FILE *file;
00060         G4String mode;
00061         G4double unit;
00062 public:
00063         /// Default constructor. Reads return immediate EOF; writes do nothing.
00064         BLTrackFile();
00065 
00066         /// Constructor. Opens the file; mode="r" or "w".
00067         /// comment is an identifying comment in the first line of the file
00068         /// (ignored for mode=r).
00069         BLTrackFile(G4String filename, G4String comment, G4String mode);
00070 
00071         /// Destructor. Closes the file.
00072         ~BLTrackFile();
00073 
00074         /// setLengthUnit() will select either mm or cm.
00075         /// default is mm.
00076         void setLengthUnit(G4double mmorcm) { unit = mmorcm; }
00077 
00078         /// write() will write one track to the file (mode must have been "w").
00079         /// Units are standard geant4 internal units.
00080         /// Note that weight is optional.
00081         BLTrackFileStatus write(G4ThreeVector& pos, G4double time,
00082                         G4ThreeVector& momentum, int PDGid, int eventId,
00083                         int trackId, int parentId, G4double weight=1.0);
00084 
00085         /// read() will read one track from the file (mode must have been "r").
00086         /// Units are standard geant4 internal units.
00087         /// Use the other version of read() if you want to use the weight.
00088         BLTrackFileStatus read(G4ThreeVector& pos, G4double& time,
00089                         G4ThreeVector& momentum, int& PDGid, int& eventId,
00090                         int& trackId, int& parentId);
00091         /// read() will read one track from the file (mode must have been "r").
00092         /// Units are standard geant4 internal units.
00093         BLTrackFileStatus read(G4ThreeVector& pos, G4double& time,
00094                         G4ThreeVector& momentum, int& PDGid, int& eventId,
00095                         int& trackId, int& parentId, G4double &weight);
00096 
00097         /// flush() will flush buffers to the file.
00098         void flush() { fflush(file); }
00099 };
00100 
00101 #endif // BLTRACKFILE_HH
g4beamline