#include <BLFOR009.hh>
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 |
RegionMap * | map |
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, map, mode, and status.
00046 { 00047 filename = _filename; 00048 status = BLTF_ERROR; 00049 file = 0; 00050 mode = _mode; 00051 map = new RegionMap(); 00052 00053 if(mode != "w") { 00054 fprintf(stderr,"BLFOR009: only write mode is implemented\n"); 00055 return; 00056 } 00057 00058 file = fopen(filename.c_str(),"w"); 00059 if(!file) { 00060 fprintf(stderr,"BLFOR009: Cannot open file '%s' for writing\n", 00061 filename.c_str()); 00062 return; 00063 } 00064 status = BLTF_OK; 00065 fprintf(file,"#%s\n",title.c_str()); 00066 fprintf(file,"#Units are ns, meters, GeV/c, Tesla, and V/m\n"); 00067 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"); 00068 00069 }
BLFOR009::~BLFOR009 | ( | ) |
void BLFOR009::close | ( | ) |
close() writes the data to the file and closes it.
References Track::Bfield, BLTF_OK, Track::Efield, Track::eventId, file, map, Track::momentum, Track::PDGid, Track::pos, status, Track::time, Track::trackId, and Track::weight.
Referenced by FOR009NTuple::close(), and ~BLFOR009().
00078 { 00079 if(status != BLTF_OK || !file) return; 00080 00081 RegionMap::iterator i; 00082 int jsrg; 00083 for(i=map->begin(),jsrg=1; i!=map->end(); ++i,++jsrg) { 00084 int ignored = 0; 00085 int n = i->second->track.size(); 00086 bool hasReference = false; 00087 for(int k=0; k<n; ++k) { 00088 Track t(i->second->track[k]); 00089 int iptyp=0; 00090 switch(t.PDGid) { 00091 case -11: iptyp = 1; break; 00092 case 11: iptyp = -1; break; 00093 case -13: iptyp = 2; break; 00094 case 13: iptyp = -2; break; 00095 case -211: iptyp = -3; break; 00096 case 211: iptyp = 3; break; 00097 case -321: iptyp = -4; break; 00098 case 321: iptyp = 4; break; 00099 case -2212: iptyp = -5; break; 00100 case 2212: iptyp = 5; break; 00101 default: 00102 ++ignored; 00103 continue; 00104 } 00105 if(t.eventId == 0) hasReference = true; 00106 fprintf(file,"%d %d %d %d %d" 00107 " %.6g" 00108 " %.6g %.6g %.6g" 00109 " %.6g %.6g %.6g" 00110 " %.6g %.6g %.6g" 00111 " %.4f" 00112 " %.6g %.6g %.6g" 00113 " 0 0 0 0\n", 00114 t.eventId,t.trackId,iptyp,0,jsrg, 00115 t.time/second, 00116 t.pos[0]/meter,t.pos[1]/meter,t.pos[2]/meter, 00117 t.momentum[0]/GeV,t.momentum[1]/GeV,t.momentum[2]/GeV, 00118 t.Bfield[0]/tesla,t.Bfield[1]/tesla,t.Bfield[2]/tesla, 00119 t.weight, 00120 t.Efield[0]/(volt/meter),t.Efield[1]/(volt/meter),t.Efield[2]/(volt/meter) 00121 ); 00122 } 00123 if(!hasReference) printf("*** WARNING: FOR009.DAT region %d" " has no reference particle\n",jsrg); 00124 printf("FOR009.DAT Region %d z=%.1f %d tracks, %d " 00125 "unsupported particles ignored\n", 00126 jsrg,i->second->Z,n,ignored); 00127 } 00128 00129 fclose(file); 00130 file = 0; 00131 }
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().
00137 { 00138 if(status != BLTF_OK) 00139 return status; 00140 00141 float z = pos[2]; 00142 Region *m = (*map)[z]; 00143 if(!m) { 00144 m = new Region(z); 00145 (*map)[z] = m; 00146 } 00147 00148 // eventId=-1 is the center particle, and eventId=0 is a real event. 00149 // in FOR009.DAT center must be event 0. 00150 if(eventId == 0) { 00151 // yes, one line per region is printed. 00152 printf("BLFOR009: beam event 0 omitted (0 must be reference)\n"); 00153 return BLTF_OK; 00154 } else if(eventId == -1) { 00155 eventId = 0; 00156 } 00157 00158 Track t; 00159 t.pos = pos; 00160 t.time = time; 00161 t.momentum = momentum; 00162 t.Bfield = Bfield; 00163 t.Efield = Efield; 00164 t.PDGid = PDGid; 00165 t.eventId = eventId; 00166 t.trackId = trackId; 00167 t.parentId = parentId; 00168 t.weight = weight; 00169 00170 m->addTrack(t); 00171 00172 return BLTF_OK; 00173 }
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.
00179 { 00180 return BLTF_ERROR; 00181 }
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.
00187 { 00188 return BLTF_ERROR; 00189 }
G4String BLFOR009::filename [private] |
Referenced by BLFOR009().
BLTrackFileStatus BLFOR009::status [private] |
Referenced by BLFOR009(), close(), and write().
FILE* BLFOR009::file [private] |
Referenced by BLFOR009(), and close().
G4String BLFOR009::mode [private] |
Referenced by BLFOR009().
RegionMap* BLFOR009::map [private] |
Referenced by BLFOR009(), and close().