BLFOR009 Class Reference

#include <BLFOR009.hh>

List of all members.


Detailed Description

class BLFOR009 creates an ASCII file containing tracks in ICOOL FOR009.DAT format.

NOTE: Because the FOR009.DAT format requires the particles be sorted by region (JSRG), all tracks are stored in memory until close() is called; the file is written at that time. The ICOOL region is determined from the Z position of the track, and is simply sequentially assigned as tracks at different Z positions are written. The region is +-REGION_SIZE in Z from the first track of each region.

XP[], PP[], BFLD[], and EFLD[] should all be converted to Centerline coordinates before calling write().

This data format comes from ICOOL v 2.77, User's Guide section 4.2.3. The first line of the file is the title. The second and third lines are comments, supposedly units and column labels. There follow the tracks, one per line, sorted by "region". The first track of each region should be the "reference" particle in ICOOL parlance; in g4beamline it is the reference particle -- if multiple reference particles intersect the region, the first will be "reference", and the following ones will be considered "beam". The variables for each track are: IEVT (I) event # IPNUM (I) track # for this event IPTYP (I) particle type: >0 for positive charge, <0 for negative 1=e, 2=mu, 3=pi, 4=K, 5=proton IPFLG (I) "flag", always 0 JSRG (I) region number (see above) TP (F) time (sec) XP[3] (F) position (meters) PP[3] (F) momentum (GeV/c) BFLD[3] (F) Magnetic field (Tesla) EVTWT (F) weight EFLD[3] (F) Electric field (V/meter) SARC (F) arclength (meter) -- set to 0.0 POL[3] (F) spin -- set to 0.0

Note that event 0 will be ignored, as that value of IEVT is reserved for the reference particle.

Public Member Functions

 BLFOR009 (G4String _filename, G4String title, G4String mode)
 Constructor. Opens the file; mode="r" or "w". title is an identifying title in the first line of the file (ignored for mode=r). READ MODE IS UNIMPLEMENTED.
 ~BLFOR009 ()
 Destructor. Writes any data and closes the file.
void close ()
 close() writes the data to the file and closes it.
BLTrackFileStatus write (G4ThreeVector &pos, G4double time, G4ThreeVector &momentum, G4ThreeVector &Bfield, G4ThreeVector &Efield, int PDGid, int eventId, int trackId, int parentId, G4double weight=1.0)
 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 read (G4ThreeVector &pos, G4double &time, G4ThreeVector &momentum, G4ThreeVector &Bfield, G4ThreeVector &Efield, 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. Use the other version of read() if you want to use the weight. UNIMPLEMENTED.
BLTrackFileStatus read (G4ThreeVector &pos, G4double &time, G4ThreeVector &momentum, G4ThreeVector &Bfield, G4ThreeVector &Efield, int &PDGid, int &eventId, int &trackId, int &parentId, G4double &weight)
 read() will read one track from the file (mode must have been "r"). Units are standard geant4 internal units. UNIMPLEMENTED.

Private Attributes

G4String filename
BLTrackFileStatus status
FILE * file
G4String mode
RegionMapmap


Constructor & Destructor Documentation

BLFOR009::BLFOR009 ( G4String  _filename,
G4String  title,
G4String  mode 
)

Constructor. Opens the file; mode="r" or "w". title is an identifying title in the first line of the file (ignored for mode=r). READ MODE IS UNIMPLEMENTED.

References BLTF_ERROR, BLTF_OK, file, filename, BLAsciiFile::fopen(), map, mode, and status.

00047 {
00048         filename = _filename;
00049         status = BLTF_ERROR;
00050         file = 0;
00051         mode = _mode;
00052         map = new RegionMap();
00053 
00054         if(mode != "w") {
00055                 fprintf(stderr,"BLFOR009: only write mode is implemented\n");
00056                 return;
00057         }
00058 
00059         file = BLAsciiFile::fopen(filename);
00060         if(!file) {
00061                 fprintf(stderr,"BLFOR009: Cannot open file '%s' for writing\n",
00062                         filename.c_str());
00063                 return;
00064         }
00065         status = BLTF_OK;
00066         fprintf(file,"#%s\n",title.c_str());
00067         fprintf(file,"#Units are ns, meters, GeV/c, Tesla, and V/m\n");
00068         fprintf(file,"#IEVT IPNUM IPTYP IPFLG JSRG T X Y Z Px Py Pz Bx By Bz Weight Ex Ey Ez SARC POLx POLy POLz\n");
00069 
00070 }

BLFOR009::~BLFOR009 (  ) 

Destructor. Writes any data and closes the file.

References close().

00073 {
00074         close();
00075         // no attempt to delete map (too complicated, and unnecessary)
00076 }


Member Function Documentation

void BLFOR009::close (  ) 

close() writes the data to the file and closes it.

References Track::Bfield, BLTF_OK, Track::Efield, Track::eventId, BLAsciiFile::fclose(), file, map, Track::momentum, Track::PDGid, Track::pos, status, Track::time, Track::trackId, and Track::weight.

Referenced by FOR009NTuple::close(), and ~BLFOR009().

00079 {
00080         if(status != BLTF_OK || !file) return;
00081 
00082         RegionMap::iterator i;
00083         int jsrg;
00084         for(i=map->begin(),jsrg=1; i!=map->end(); ++i,++jsrg) {
00085                 int ignored = 0;
00086                 int n = i->second->track.size();
00087                 bool hasReference = false;
00088                 for(int k=0; k<n; ++k) {
00089                         Track t(i->second->track[k]);
00090                         int iptyp=0;
00091                         switch(t.PDGid) {
00092                         case -11:       iptyp =  1;     break;
00093                         case  11:       iptyp = -1;     break;
00094                         case -13:       iptyp =  2;     break;
00095                         case  13:       iptyp = -2;     break;
00096                         case -211:      iptyp = -3;     break;
00097                         case  211:      iptyp =  3;     break;
00098                         case -321:      iptyp = -4;     break;
00099                         case  321:      iptyp =  4;     break;
00100                         case -2212:     iptyp = -5;     break;
00101                         case  2212:     iptyp =  5;     break;
00102                         default:
00103                                 ++ignored;
00104                                 continue;
00105                         }
00106                         if(t.eventId == 0) hasReference = true;
00107                         fprintf(file,"%d %d %d %d %d"
00108                                         " %.6g"
00109                                         " %.6g %.6g %.6g"
00110                                         " %.6g %.6g %.6g"
00111                                         " %.6g %.6g %.6g"
00112                                         " %.4f"
00113                                         " %.6g %.6g %.6g"
00114                                         " 0   0 0 0\n",
00115                                 t.eventId,t.trackId,iptyp,0,jsrg,
00116                                 t.time/second,
00117                                 t.pos[0]/meter,t.pos[1]/meter,t.pos[2]/meter,
00118                                 t.momentum[0]/GeV,t.momentum[1]/GeV,t.momentum[2]/GeV,
00119                                 t.Bfield[0]/tesla,t.Bfield[1]/tesla,t.Bfield[2]/tesla,
00120                                 t.weight,
00121                                 t.Efield[0]/(volt/meter),t.Efield[1]/(volt/meter),t.Efield[2]/(volt/meter)
00122                         );
00123                 }
00124                 if(!hasReference) 
00125                         G4Exception("FOR009.DAT output","No reference",
00126                                                         JustWarning, "");
00127                 printf("FOR009.DAT Region %d z=%.1f  %d tracks,  %d "
00128                                 "unsupported particles ignored\n",
00129                                                 jsrg,i->second->Z,n,ignored);
00130         }
00131         
00132         BLAsciiFile::fclose(file);
00133         file = 0;
00134 }

BLTrackFileStatus BLFOR009::write ( G4ThreeVector &  pos,
G4double  time,
G4ThreeVector &  momentum,
G4ThreeVector &  Bfield,
G4ThreeVector &  Efield,
int  PDGid,
int  eventId,
int  trackId,
int  parentId,
G4double  weight = 1.0 
)

write() will write one track to the file (mode must have been "w"). Units are standard geant4 internal units. Note that weight is optional.

References Region::addTrack(), Track::Bfield, BLTF_OK, Track::Efield, Track::eventId, Track::momentum, Track::parentId, Track::PDGid, Track::pos, status, Track::time, Track::trackId, and Track::weight.

Referenced by FOR009NTuple::appendRow().

00140 {
00141         if(status != BLTF_OK)
00142                 return status;
00143 
00144         double z = pos[2];
00145         Region *m = (*map)[z];
00146         if(!m) {
00147                 m = new Region(z);
00148                 (*map)[z] = m;
00149         }
00150 
00151         // eventId=-1 is the center particle, and eventId=0 is a real event.
00152         // in FOR009.DAT center must be event 0.
00153         if(eventId == 0) {
00154                 // yes, one line per region is printed.
00155                 printf("BLFOR009: beam event 0 omitted (0 must be reference)\n");
00156                 return BLTF_OK;
00157         } else if(eventId == -1) {
00158                 eventId = 0;
00159         }
00160 
00161         Track t;
00162         t.pos = pos;
00163         t.time = time;
00164         t.momentum = momentum;
00165         t.Bfield = Bfield;
00166         t.Efield = Efield;
00167         t.PDGid = PDGid;
00168         t.eventId = eventId;
00169         t.trackId = trackId;
00170         t.parentId = parentId;
00171         t.weight = weight;
00172 
00173         m->addTrack(t);
00174 
00175         return BLTF_OK;
00176 }

BLTrackFileStatus BLFOR009::read ( G4ThreeVector &  pos,
G4double &  time,
G4ThreeVector &  momentum,
G4ThreeVector &  Bfield,
G4ThreeVector &  Efield,
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. Use the other version of read() if you want to use the weight. UNIMPLEMENTED.

References BLTF_ERROR.

00182 {
00183         return BLTF_ERROR;
00184 }

BLTrackFileStatus BLFOR009::read ( G4ThreeVector &  pos,
G4double &  time,
G4ThreeVector &  momentum,
G4ThreeVector &  Bfield,
G4ThreeVector &  Efield,
int &  PDGid,
int &  eventId,
int &  trackId,
int &  parentId,
G4double &  weight 
)

read() will read one track from the file (mode must have been "r"). Units are standard geant4 internal units. UNIMPLEMENTED.

References BLTF_ERROR.

00190 {
00191         return BLTF_ERROR;
00192 }


Member Data Documentation

G4String BLFOR009::filename [private]

Referenced by BLFOR009().

Referenced by BLFOR009(), close(), and write().

FILE* BLFOR009::file [private]

Referenced by BLFOR009(), and close().

G4String BLFOR009::mode [private]

Referenced by BLFOR009().

Referenced by BLFOR009(), and close().


The documentation for this class was generated from the following files:
g4beamline