Public Member Functions | |
BLCMDbeam () | |
Constructor. | |
virtual G4String | commandName () |
commandName() returns "beam". | |
virtual int | command (BLArgumentVector &argv, BLArgumentMap &namedArgs) |
command() implements the beam command. | |
virtual void | printBeam () |
printBeam() will print a description. | |
virtual void | defineNamedArgs () |
defineNamedArgs() defines the named arguments for this command. | |
virtual int | getNEvents () const |
getNEvents() returns the # events to process. | |
virtual void | init () |
init() will initialize internal variables. | |
virtual bool | generateReferenceParticle (G4Event *event) |
generateReferenceParticle() generates the reference particle. | |
virtual bool | nextBeamEvent (G4Event *event) |
nextBeamEvent() generates the next beam event. | |
virtual void | summary () |
summary() will print a summary, if necessary. | |
Private Types | |
enum | BeamType { NONE, GAUSSIAN, RECTANGULAR, ASCII, ELLIPSE, ROOT } |
Private Member Functions | |
G4double | myrand (G4double mean, G4double sigma) |
Private Attributes | |
BeamType | type |
G4String | particle |
G4int | eventsGenerated |
G4int | nEvents |
G4int | eventID |
G4int | firstEvent |
G4int | lastEvent |
G4double | beamX |
G4double | beamY |
G4double | beamZ |
G4double | maxR |
G4String | rotation |
G4RotationMatrix * | rotationMatrix |
G4ThreeVector | position |
G4int | renumber |
G4double | weight |
G4int | secondaryTrackID |
G4double | meanMomentum |
G4double | sigmaX |
G4double | sigmaY |
G4double | sigmaXp |
G4double | sigmaYp |
G4double | sigmaP |
G4double | sigmaT |
G4double | sigmaE |
G4double | meanXp |
G4double | meanYp |
G4double | meanT |
G4double | beamHeight |
G4double | beamWidth |
G4String | filename |
G4String | directory |
G4int | uid |
G4String | name |
BLNTuple * | ntuple |
float * | data |
G4String | format |
G4int | index |
G4ParticleGun * | particleGun |
G4ParticleDefinition * | particleDefinition |
BLTrackFile * | trackFile |
G4int | nvar |
G4int | prevEventID |
enum BLCMDbeam::BeamType [private] |
BLCMDbeam::BLCMDbeam | ( | ) |
Constructor.
References ALL_EVENTS, beamHeight, beamWidth, beamX, beamY, beamZ, BLCMDTYPE_BEAM, data, directory, eventID, eventsGenerated, filename, firstEvent, format, index, lastEvent, maxR, meanMomentum, meanT, meanXp, meanYp, name, nEvents, NONE, ntuple, nvar, particle, particleDefinition, particleGun, prevEventID, BLCommand::registerCommand(), renumber, rotationMatrix, secondaryTrackID, BLCommand::setDescription(), BLCommand::setSynopsis(), sigmaE, sigmaP, sigmaT, sigmaX, sigmaXp, sigmaY, sigmaYp, trackFile, type, uid, UNDEFINED, and weight.
Referenced by command().
00135 : rotation() , position() 00136 { 00137 registerCommand(BLCMDTYPE_BEAM); 00138 setSynopsis("Define the Beam."); 00139 setDescription("The beam command is: beam type arg1=v1 ...\n\n" 00140 "Types are: gaussian, rectangular, ellipse, ascii, and root.\n\n" 00141 "Gaussian beams are randomly generated to emanate from " 00142 "beamX,beamY,beamZ with the given " 00143 "sigmas; negative sigma means flat with |sigma| as " 00144 "halfwidth.\n\n" 00145 "Rectangular beams are randomly generated to emanate " 00146 "from the rectangle beamHeight by beamWidth centered at " 00147 "beamX,beamY,beamZ. \n\n" 00148 "Ellipse beams are randomly generated on " 00149 "the ellipses in (X,Xp), (Y,Yp), (T,E), with meanE determined " 00150 "from meanP and the sigmas used as half-widths; tracks\n" 00151 "are generated on the ellipse with uniform density when " 00152 "plotted with scales such that the ellipse is a circle.\n\n" 00153 "ASCII beams are read from a file using the format " 00154 "specified; the formats supported are: BLTrackFile\n\n" 00155 "Root beams are read from a .root file using the " 00156 "TNtuple named directory/name in the file. It must have the " 00157 "same fields as used in BLTrackFile format. Note that EventIDs " 00158 "greater than 16,777,216 will be trncated.\n\n" 00159 "When reading a file (ascii or root), " 00160 "beamX and beamY are added to input tracks; if beamZ is set " 00161 "it will overwrite the z of the track, but if it is not set " 00162 "the z of the track in the file is kept.\n\n" 00163 "All coordinates are centerline coordinates.\n\n" 00164 "Multiple beam commands can be given, and they will generate\n" 00165 "events in the order they appear in input.file.\n\n" 00166 "Events are generated starting at firstEvent, until either\n" 00167 "nEvents have been generated or lastEvent would be exceeded.\n\n" 00168 "For gaussian, rectangular, and ellipse beams, the beam " 00169 "particle can be given as either a particle name or " 00170 "its integer PDGid. Some common beam particle names are: " 00171 "proton, anti_proton, pi+, pi-, mu+, mu-, e+, e-, kaon+, " 00172 "kaon-, kaon0, nu_e, anti_nu_e.\n" 00173 "See the User's Guide for a complete list of particle names."); 00174 // initial default values: 00175 type = NONE; 00176 particle = "mu+"; 00177 eventsGenerated = 0; 00178 nEvents = ALL_EVENTS; 00179 eventID = ALL_EVENTS; 00180 firstEvent = -1; 00181 lastEvent = ALL_EVENTS; 00182 meanMomentum = 200.0*MeV; 00183 beamX = 0.0; 00184 beamY = 0.0; 00185 beamZ = UNDEFINED; 00186 maxR = 1.0*kilometer; 00187 renumber = 0; 00188 weight = 1.0; 00189 secondaryTrackID = 1001; 00190 rotationMatrix = 0; 00191 sigmaX = 0.0; 00192 sigmaY = 0.0; 00193 sigmaXp = 0.0; 00194 sigmaYp = 0.0; 00195 sigmaP = 0.0; 00196 sigmaT = 0.0; 00197 sigmaE = UNDEFINED; 00198 meanXp = 0.0; 00199 meanYp = 0.0; 00200 meanT = 0.0; 00201 beamHeight = 0.0; 00202 beamWidth = 0.0; 00203 filename = ""; 00204 directory = ""; 00205 uid = 0; 00206 name = ""; 00207 ntuple = 0; 00208 data = 0; 00209 format = "BLTrackFile"; 00210 index = 0; 00211 particleDefinition = 0; 00212 particleGun = 0; 00213 trackFile = 0; 00214 nvar = 0; 00215 prevEventID = -9999; 00216 }
G4double BLCMDbeam::myrand | ( | G4double | mean, | |
G4double | sigma | |||
) | [inline, private] |
Referenced by nextBeamEvent().
00095 { 00096 if(sigma >= 0.0) return sigma*CLHEP::RandGauss::shoot() + mean; 00097 return mean+sigma-2.0*sigma*G4UniformRand(); 00098 }
virtual G4String BLCMDbeam::commandName | ( | ) | [inline, virtual] |
int BLCMDbeam::command | ( | BLArgumentVector & | argv, | |
BLArgumentMap & | namedArgs | |||
) | [virtual] |
command() implements the beam command.
Implements BLCommand.
References ALL_EVENTS, ASCII, beamX, beamY, beamZ, BLCMDbeam(), ELLIPSE, firstEvent, GAUSSIAN, BLCoordinates::getCurrentGlobal(), BLCoordinates::getCurrentRotation(), BLManager::getObject(), BLGroup::getWorld(), BLCommand::handleNamedArgs(), lastEvent, nEvents, position, printBeam(), BLCommand::printError(), RECTANGULAR, BLManager::registerBeam(), ROOT, rotation, rotationMatrix, BLGroup::setMinHeight(), BLGroup::setMinLength(), BLGroup::setMinWidth(), BLCommand::stringToRotationMatrix(), type, and UNDEFINED.
00219 { 00220 if(argv.size() != 1) { 00221 printError("Invalid beam command -- need beam type"); 00222 return -1; 00223 } 00224 00225 BLCMDbeam *b = new BLCMDbeam(*this); 00226 00227 if(argv[0] == "gaussian" || argv[0] == "gauss") { 00228 b->type = GAUSSIAN; 00229 b->nEvents = 1; 00230 } else if(argv[0] == "rectangular" || argv[0] == "rect") { 00231 b->type = RECTANGULAR; 00232 b->nEvents = 1; 00233 } else if(argv[0] == "ascii" || argv[0] == "ASCII") { 00234 b->type = ASCII; 00235 b->nEvents = ALL_EVENTS; 00236 } else if(argv[0] == "ellipse" || argv[0] == "ELLIPSE") { 00237 b->type = ELLIPSE; 00238 b->nEvents = 1; 00239 } else if(argv[0] == "root") { 00240 b->type = ROOT; 00241 b->nEvents = ALL_EVENTS; 00242 } else { 00243 printError("beam: invalid type '%s'",argv[0].c_str()); 00244 } 00245 00246 b->rotation = ""; 00247 int retval = b->handleNamedArgs(namedArgs); 00248 00249 if(b->firstEvent != -1 && b->lastEvent != ALL_EVENTS) 00250 b->nEvents = b->lastEvent - b->firstEvent + 1; 00251 00252 if(b->rotation != "") { 00253 b->rotationMatrix = stringToRotationMatrix(b->rotation); 00254 } else { 00255 b->rotationMatrix = new G4RotationMatrix(); 00256 } 00257 // as usual, the order seems backward because (C R C^-1) C = C R. 00258 *b->rotationMatrix = *BLCoordinates::getCurrentRotation() * 00259 *b->rotationMatrix; 00260 G4ThreeVector local(b->beamX,b->beamY, 00261 (b->beamZ==UNDEFINED ? 0.0 : b->beamZ)); 00262 BLCoordinates::getCurrentGlobal(local,b->position); 00263 00264 // ensure beam is within the world 00265 BLGroup::getWorld()->setMinWidth(fabs(b->position[0])*2.0); 00266 BLGroup::getWorld()->setMinHeight(fabs(b->position[1])*2.0); 00267 BLGroup::getWorld()->setMinLength(fabs(b->position[2])*2.0); 00268 00269 BLManager::getObject()->registerBeam(b); 00270 00271 b->printBeam(); 00272 00273 return retval; 00274 }
void BLCMDbeam::printBeam | ( | ) | [virtual] |
printBeam() will print a description.
References ASCII, beamHeight, beamWidth, beamX, beamY, beamZ, directory, ELLIPSE, filename, firstEvent, format, GAUSSIAN, lastEvent, maxR, meanMomentum, meanT, meanXp, meanYp, name, nEvents, NONE, particle, RECTANGULAR, renumber, ROOT, sigmaE, sigmaP, sigmaT, sigmaX, sigmaXp, sigmaY, sigmaYp, type, and weight.
Referenced by command().
00320 { 00321 switch(type) { 00322 case NONE: 00323 printf("beam NONE Invalid beam command\n"); 00324 break; 00325 case GAUSSIAN: 00326 printf("beam GAUSSIAN particle=%s ",particle.c_str()); 00327 printf("nEvents=%d ",nEvents); 00328 printf("firstEvent=%d ",firstEvent); 00329 printf("lastEvent=%d ",lastEvent); 00330 printf("beamX=%.1f ",beamX); 00331 printf("beamY=%.1f ",beamY); 00332 printf("beamZ=%.1f ",beamZ); 00333 printf("maxR=%.1f ",maxR); 00334 printf("\n\t\t"); 00335 printf("meanMomentum=%.1f ",meanMomentum); 00336 printf("weight=%1f ",weight); 00337 printf("\n\t\t"); 00338 printf("sigmaX=%.1f ",sigmaX); 00339 printf("sigmaY=%.1f ",sigmaY); 00340 printf("sigmaXp=%.5f ",sigmaXp); 00341 printf("sigmaYp=%.5f ",sigmaYp); 00342 printf("\n\t\t"); 00343 printf("sigmaP=%.1f ",sigmaP); 00344 printf("sigmaT=%.3f ",sigmaT); 00345 printf("meanXp=%.5f ",meanXp); 00346 printf("meanYp=%.5f ",meanYp); 00347 printf("meanT=%.3f ",meanT); 00348 printf("\n"); 00349 break; 00350 case RECTANGULAR: 00351 printf("beam RECTANGULAR particle=%s ",particle.c_str()); 00352 printf("nEvents=%d ",nEvents); 00353 printf("firstEvent=%d ",firstEvent); 00354 printf("lastEvent=%d ",lastEvent); 00355 printf("beamX=%.1f ",beamX); 00356 printf("beamY=%.1f ",beamY); 00357 printf("beamZ=%.1f ",beamZ); 00358 printf("maxR=%.1f ",maxR); 00359 printf("\n\t\t"); 00360 printf("meanMomentum=%.1f ",meanMomentum); 00361 printf("weight=%1f ",weight); 00362 printf("\n\t\t"); 00363 printf("beamHeight=%.1f ",beamHeight); 00364 printf("beamWidth=%.1f ",beamWidth); 00365 printf("sigmaXp=%.5f ",sigmaXp); 00366 printf("sigmaYp=%.5f ",sigmaYp); 00367 printf("\n\t\t"); 00368 printf("sigmaP=%.1f ",sigmaP); 00369 printf("sigmaT=%.3f ",sigmaT); 00370 printf("meanXp=%.5f ",meanXp); 00371 printf("meanYp=%.5f ",meanYp); 00372 printf("meanT=%.3f ",meanT); 00373 printf("\n"); 00374 break; 00375 case ROOT: 00376 printf("beam ROOT "); 00377 printf("nEvents=%d ",nEvents); 00378 printf("firstEvent=%d ",firstEvent); 00379 printf("lastEvent=%d ",lastEvent); 00380 printf("beamZ=%.1f ",beamZ); 00381 printf("maxR=%.1f ",maxR); 00382 printf("renumber=%d ",renumber); 00383 printf("weight=%1f ",weight); 00384 printf("\n\t\t"); 00385 printf("filename=%s ",filename.c_str()); 00386 printf("directory=%s ",directory.c_str()); 00387 printf("name=%s ",name.c_str()); 00388 printf("\n\t\t"); 00389 printf("\n"); 00390 break; 00391 case ASCII: 00392 printf("beam ASCII "); 00393 printf("nEvents=%d ",nEvents); 00394 printf("firstEvent=%d ",firstEvent); 00395 printf("lastEvent=%d ",lastEvent); 00396 printf("beamZ=%.1f ",beamZ); 00397 printf("maxR=%.1f ",maxR); 00398 printf("renumber=%d ",renumber); 00399 printf("weight=%1f ",weight); 00400 printf("\n\t\t"); 00401 printf("filename=%s ",filename.c_str()); 00402 printf("format=%s ",format.c_str()); 00403 printf("\n\t\t"); 00404 printf("\n"); 00405 break; 00406 case ELLIPSE: 00407 printf("beam ELLIPSE particle=%s ",particle.c_str()); 00408 printf("nEvents=%d ",nEvents); 00409 printf("firstEvent=%d ",firstEvent); 00410 printf("lastEvent=%d ",lastEvent); 00411 printf("beamX=%.1f ",beamX); 00412 printf("beamY=%.1f ",beamY); 00413 printf("beamZ=%.1f ",beamZ); 00414 printf("maxR=%.1f ",maxR); 00415 printf("\n\t\t"); 00416 printf("meanMomentum=%.1f ",meanMomentum); 00417 printf("weight=%1f ",weight); 00418 printf("\n\t\t"); 00419 printf("sigmaX=%.1f ",sigmaX); 00420 printf("sigmaY=%.1f ",sigmaY); 00421 printf("sigmaXp=%.5f ",sigmaXp); 00422 printf("sigmaYp=%.5f ",sigmaYp); 00423 printf("\n\t\t"); 00424 printf("sigmaE=%.1f ",sigmaE); 00425 printf("sigmaT=%.3f ",sigmaT); 00426 printf("meanXp=%.5f ",0.0); 00427 printf("meanYp=%.5f ",0.0); 00428 printf("meanT=%.3f ",0.0); 00429 printf("\n"); 00430 break; 00431 } 00432 }
void BLCMDbeam::defineNamedArgs | ( | ) | [virtual] |
defineNamedArgs() defines the named arguments for this command.
Reimplemented from BLCommand.
References BLCommand::argDouble(), BLCommand::argInt(), BLCommand::argString(), beamHeight, beamWidth, beamX, beamY, beamZ, directory, filename, firstEvent, format, lastEvent, maxR, meanMomentum, meanT, meanXp, meanYp, name, nEvents, particle, renumber, rotation, secondaryTrackID, sigmaE, sigmaP, sigmaT, sigmaX, sigmaXp, sigmaY, sigmaYp, uid, and weight.
00277 { 00278 argString(particle,"particle","Beam particle name"); 00279 argInt(nEvents,"nEvents","Number of events to process (default=1 " 00280 "for generating events, default=ALL for reading files) " 00281 "set to lastEvent-firstEvent+1 if both are set."); 00282 argInt(firstEvent,"firstEvent","First event # to process (default " 00283 "is the next sequential eventID, 1 if none)"); 00284 argInt(lastEvent,"lastEvent","Last (highest) event # to process"); 00285 argDouble(beamX,"beamX","Beam location in X (mm)"); 00286 argDouble(beamY,"beamY","Beam location in Y (mm)"); 00287 argDouble(beamZ,"beamZ","Beam location in Z (mm)"); 00288 argDouble(maxR,"maxR","Beam maximum radius (mm)"); 00289 argString(rotation,"rotation","Rotation of the beam"); 00290 argInt(renumber,"renumber","If nonzero, renumber events sequentially."); 00291 argDouble(weight,"weight","Weight for events, overwritten by value from input file (1.0)."); 00292 argInt(secondaryTrackID,"secondaryTrackID","The next TrackID for secondaries (1001)."); 00293 argDouble(meanMomentum,"meanMomentum", 00294 "Gaussian Beam mean momentum (MeV/c)"); 00295 argDouble(meanMomentum,"meanP","Synonym for meanMomentum."); 00296 argDouble(sigmaX,"sigmaX","Gaussian Beam sigma in X (mm)"); 00297 argDouble(sigmaY,"sigmaY","Gaussian Beam sigma in Y (mm)"); 00298 argDouble(sigmaXp,"sigmaXp","Gaussian Beam sigma in dxdz (slope)"); 00299 argDouble(sigmaYp,"sigmaYp","Gaussian Beam sigma in dydz (slope)"); 00300 argDouble(sigmaP,"sigmaP","Gaussian Beam sigma in P (MeV/c)"); 00301 argDouble(sigmaT,"sigmaT","Gaussian Beam sigma in T (ns)"); 00302 argDouble(sigmaE,"sigmaE","Elliptical Beam sigma in E (MeV)"); 00303 argDouble(meanXp,"meanXp","Gaussian Beam mean in Xp (slope)"); 00304 argDouble(meanYp,"meanYp","Gaussian Beam mean in Yp (slope)"); 00305 argDouble(meanT,"meanT","Gaussian Beam mean in T (ns)"); 00306 argDouble(beamHeight,"beamHeight","Rectangular Beam height (mm)"); 00307 argDouble(beamWidth,"beamWidth","Rectangular Beam width (mm)"); 00308 argString(filename,"filename","input file name"); 00309 argString(filename,"file","synonym for filename."); 00310 argString(directory,"directory","Root-file directory of NTuple"); 00311 argString(directory,"category","Deprecated synonym for directory."); 00312 argInt(uid,"uid","HistoScope uid of NTuple"); 00313 argString(name,"name","Root name of NTuple."); 00314 argString(format,"format","ASCII file format (Default=BLTrackFile)"); 00315 argDouble(meanXp,"beamXp","Synonym for meanXp."); 00316 argDouble(meanYp,"beamYp","Synonym for meanYp."); 00317 }
virtual int BLCMDbeam::getNEvents | ( | ) | const [inline, virtual] |
getNEvents() returns the # events to process.
Reimplemented from BLBeam.
References nEvents.
00118 { return nEvents; }
void BLCMDbeam::init | ( | ) | [virtual] |
init() will initialize internal variables.
Implements BLBeam.
References ASCII, data, directory, ELLIPSE, eventsGenerated, filename, format, GAUSSIAN, BLNTuple::getNData(), index, name, NONE, ntuple, nvar, particle, particleDefinition, particleGun, BLNTuple::read(), RECTANGULAR, ROOT, sigmaE, sigmaP, TrackFields, trackFile, type, and UNDEFINED.
00435 { 00436 eventsGenerated = 0; 00437 index = 0; 00438 if(particleDefinition != 0) return; 00439 00440 if(isdigit(particle(0)) || particle(0) == '-') 00441 particleDefinition = G4ParticleTable::GetParticleTable()-> 00442 FindParticle(atoi(particle.c_str())); 00443 else 00444 particleDefinition = G4ParticleTable::GetParticleTable()-> 00445 FindParticle(particle); 00446 if(!particleDefinition) 00447 G4Exception("beam command","UnknownParticle",FatalException, 00448 "Unknown particle type"); 00449 particleGun = new G4ParticleGun(1); 00450 particleGun->SetParticleDefinition(particleDefinition); 00451 00452 switch(type) { 00453 case NONE: 00454 break; 00455 case GAUSSIAN: 00456 case RECTANGULAR: 00457 break; 00458 case ELLIPSE: 00459 if(sigmaE == UNDEFINED) sigmaE = sigmaP; 00460 break; 00461 case ROOT: 00462 { ntuple = BLNTuple::read("Root",directory,name,TrackFields, 00463 filename); 00464 nvar = ntuple->getNData(); 00465 data = new float[nvar]; 00466 } 00467 break; 00468 case ASCII: 00469 if(format == "BLTrackFile") { 00470 trackFile = new BLTrackFile(filename,"","r"); 00471 } 00472 break; 00473 } 00474 }
bool BLCMDbeam::generateReferenceParticle | ( | G4Event * | event | ) | [virtual] |
bool BLCMDbeam::nextBeamEvent | ( | G4Event * | event | ) | [virtual] |
nextBeamEvent() generates the next beam event.
Implements BLBeam.
References ASCII, beamHeight, beamWidth, beamZ, BLTF_ERROR, BLTF_OK, BLManager::clearTrackIDMap(), data, E, ELLIPSE, eventID, eventsGenerated, firstEvent, format, GAUSSIAN, BLManager::getEventID(), BLManager::getObject(), lastEvent, M_PI, maxR, meanMomentum, meanT, meanXp, meanYp, myrand(), nEvents, NONE, ntuple, nvar, particleDefinition, particleGun, position, prevEventID, BLTrackFile::read(), BLNTuple::readRow(), RECTANGULAR, renumber, ROOT, rotationMatrix, secondaryTrackID, BLManager::setNextSecondaryTrackID(), BLManager::setPrimaryTrackID(), BLBeam::setRandomSeedToGenerate(), BLBeam::setRandomSeedToTrack(), sigmaE, sigmaP, sigmaT, sigmaX, sigmaXp, sigmaY, sigmaYp, trackFile, type, UNDEFINED, and weight.
00482 { 00483 G4double mass = particleDefinition->GetPDGMass(); 00484 G4ThreeVector pos; 00485 G4ThreeVector direction; 00486 G4double time = 0.0; 00487 G4double momentum = 0.0; 00488 G4double ke = 0.0; 00489 G4int PDGid, trackID, parentID; 00490 00491 BLManager *manager = BLManager::getObject(); 00492 00493 // default eventID -- changed when reading a file unless renumber!=0 00494 eventID = manager->getEventID(); 00495 if(eventsGenerated == 0 && firstEvent != -1) 00496 eventID = firstEvent; 00497 00498 if(++eventsGenerated > nEvents) return false; 00499 00500 // loop - must not generate any event with r > maxR 00501 // beam pos = (0,0,0), beam nominal direction = (0,0,1) 00502 // rotation and offset come later 00503 bool again=false; 00504 trackID = -1; 00505 parentID = 0; 00506 do { 00507 again = false; 00508 switch(type) { 00509 case NONE: 00510 return false; 00511 case GAUSSIAN: 00512 setRandomSeedToGenerate(eventID); 00513 // meanX=beamX, meanY=beamY (implicitly) 00514 pos[0] = myrand(0.0,sigmaX); 00515 pos[1] = myrand(0.0,sigmaY); 00516 pos[2] = 0.0; 00517 direction[0] = myrand(meanXp,sigmaXp); 00518 direction[1] = myrand(meanYp,sigmaYp); 00519 direction[2] = 1.0/sqrt(1.0 + direction[0]*direction[0] + 00520 direction[1]*direction[1]); 00521 direction[0] *= direction[2]; 00522 direction[1] *= direction[2]; 00523 momentum = myrand(meanMomentum,sigmaP); 00524 time = myrand(meanT,sigmaT); 00525 trackID = 1; 00526 break; 00527 case RECTANGULAR: 00528 setRandomSeedToGenerate(eventID); 00529 pos[0] = beamWidth*G4UniformRand()-beamWidth/2.0; 00530 pos[1] = beamHeight*G4UniformRand()-beamHeight/2.0; 00531 pos[2] = 0.0; 00532 direction[0] = myrand(meanXp,sigmaXp); 00533 direction[1] = myrand(meanYp,sigmaYp); 00534 direction[2] = 1.0/sqrt(1.0 + direction[0]*direction[0] + 00535 direction[1]*direction[1]); 00536 direction[0] *= direction[2]; 00537 direction[1] *= direction[2]; 00538 momentum = myrand(meanMomentum,sigmaP); 00539 time = myrand(meanT,sigmaT); 00540 trackID = 1; 00541 break; 00542 case ROOT: 00543 { do { 00544 if(!ntuple->readRow(data,nvar)) return false; 00545 // data[] = x, y, z, Px, Py, Pz, t, PDGid, EventID, 00546 // TrackID, ParentID, Weight 00547 if(renumber == 0) eventID = (G4int)data[8]; 00548 } while(renumber == 0 && eventID < firstEvent); 00549 particleDefinition = G4ParticleTable::GetParticleTable()-> 00550 FindParticle((G4int)data[7]); 00551 if(!particleDefinition) { 00552 char tmp[64]; 00553 sprintf(tmp,"Invalid PDGid=%d -- Track abandoned", 00554 (int)data[7]); 00555 G4Exception("beam command","Invalid PDGid", 00556 JustWarning, tmp); 00557 again = true; 00558 continue; 00559 } 00560 mass = particleDefinition->GetPDGMass(); 00561 particleGun->SetParticleDefinition(particleDefinition); 00562 pos[0] = data[0]*mm; 00563 pos[1] = data[1]*mm; 00564 pos[2] = data[2]*mm; 00565 data[3] *= MeV; 00566 data[4] *= MeV; 00567 data[5] *= MeV; 00568 momentum = sqrt(data[3]*data[3]+data[4]*data[4]+data[5]*data[5]); 00569 direction[0] = data[3]/momentum; 00570 direction[1] = data[4]/momentum; 00571 direction[2] = data[5]/momentum; 00572 time = data[6]*ns; 00573 trackID = (G4int)data[9]; 00574 parentID = (G4int)data[10]; 00575 if(nvar >= 12) weight = data[11]; 00576 } 00577 break; 00578 case ASCII: 00579 if(format == "BLTrackFile") { 00580 do { 00581 int tmpID=0; 00582 BLTrackFileStatus stat=trackFile->read(pos,time, 00583 direction,PDGid,tmpID,trackID,parentID, 00584 weight); 00585 if(stat == BLTF_ERROR) 00586 G4Exception("beam command", 00587 "Invalid BLTrackFile input", 00588 JustWarning, "File abandoned"); 00589 if(stat != BLTF_OK) 00590 return false; 00591 if(renumber == 0) eventID = tmpID; 00592 } while(renumber == 0 && eventID < firstEvent); 00593 particleDefinition = G4ParticleTable::GetParticleTable() 00594 ->FindParticle(PDGid); 00595 if(!particleDefinition) { 00596 char tmp[64]; 00597 sprintf(tmp,"Invalid PDGid=%d -- Track abandoned", 00598 PDGid); 00599 G4Exception("beam command","Invalid PDGid", 00600 JustWarning, tmp); 00601 again = true; 00602 continue; 00603 } 00604 mass = particleDefinition->GetPDGMass(); 00605 particleGun->SetParticleDefinition(particleDefinition); 00606 momentum = sqrt(direction[0]*direction[0]+ 00607 direction[1]*direction[1]+ 00608 direction[2]*direction[2]); 00609 direction[0] /= momentum; 00610 direction[1] /= momentum; 00611 direction[2] /= momentum; 00612 } 00613 break; 00614 case ELLIPSE: 00615 setRandomSeedToGenerate(eventID); 00616 // meanX=beamX, meanY=beamY (implicitly) 00617 double a = 2.0*M_PI*G4UniformRand(); 00618 double b = 2.0*M_PI*G4UniformRand(); 00619 double c = 2.0*M_PI*G4UniformRand(); 00620 pos[0] = sigmaX*cos(a); 00621 pos[1] = sigmaY*cos(b); 00622 pos[2] = 0.0; 00623 direction[0] = sigmaXp*sin(a); 00624 direction[1] = sigmaYp*sin(b); 00625 direction[2] = 1.0/sqrt(1.0 + direction[0]*direction[0] + 00626 direction[1]*direction[1]); 00627 direction[0] *= direction[2]; 00628 direction[1] *= direction[2]; 00629 double E = sqrt(meanMomentum*meanMomentum + mass*mass) + 00630 sigmaE*sin(c); 00631 momentum = sqrt(E*E - mass*mass); 00632 time = sigmaT*cos(c); 00633 trackID = 1; 00634 break; 00635 } 00636 } while(again || sqrt(pos[0]*pos[0]+pos[1]*pos[1]) > maxR); 00637 00638 assert(trackID >= 0); 00639 00640 if(eventID > lastEvent) return false; 00641 00642 if(beamZ != UNDEFINED) pos[2] = 0.0; 00643 00644 // apply rotation and offset 00645 if(rotationMatrix) { 00646 direction = *rotationMatrix * direction; 00647 pos = *rotationMatrix * pos; 00648 } 00649 pos += position; 00650 00651 ke = sqrt(momentum*momentum + mass*mass) - mass; 00652 particleGun->SetParticleTime(time); 00653 particleGun->SetParticlePosition(pos); 00654 particleGun->SetParticleEnergy(ke); 00655 particleGun->SetParticleMomentumDirection(direction); 00656 particleGun->GeneratePrimaryVertex(event); 00657 event->SetEventID(eventID); 00658 event->GetPrimaryVertex()->SetWeight(weight); 00659 if(eventID != prevEventID) { 00660 setRandomSeedToTrack(eventID); 00661 manager->clearTrackIDMap(); 00662 manager->setNextSecondaryTrackID(secondaryTrackID); 00663 prevEventID = eventID; 00664 } 00665 manager->setPrimaryTrackID(trackID,parentID); 00666 if(trackID >= secondaryTrackID) { 00667 G4Exception("beam command","Large Primary TrackID",JustWarning, 00668 "Confusion with secondary tracks is likely"); 00669 } 00670 return true; 00671 }
virtual void BLCMDbeam::summary | ( | ) | [inline, virtual] |
BeamType BLCMDbeam::type [private] |
Reimplemented from BLCommand.
Referenced by BLCMDbeam(), command(), init(), nextBeamEvent(), and printBeam().
G4String BLCMDbeam::particle [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), init(), and printBeam().
G4int BLCMDbeam::eventsGenerated [private] |
Referenced by BLCMDbeam(), init(), and nextBeamEvent().
G4int BLCMDbeam::nEvents [private] |
Reimplemented from BLBeam.
Referenced by BLCMDbeam(), command(), defineNamedArgs(), getNEvents(), nextBeamEvent(), and printBeam().
G4int BLCMDbeam::eventID [private] |
Referenced by BLCMDbeam(), and nextBeamEvent().
G4int BLCMDbeam::firstEvent [private] |
Referenced by BLCMDbeam(), command(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4int BLCMDbeam::lastEvent [private] |
Referenced by BLCMDbeam(), command(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::beamX [private] |
Referenced by BLCMDbeam(), command(), defineNamedArgs(), and printBeam().
G4double BLCMDbeam::beamY [private] |
Referenced by BLCMDbeam(), command(), defineNamedArgs(), and printBeam().
G4double BLCMDbeam::beamZ [private] |
Referenced by BLCMDbeam(), command(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::maxR [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4String BLCMDbeam::rotation [private] |
Referenced by command(), and defineNamedArgs().
G4RotationMatrix* BLCMDbeam::rotationMatrix [private] |
Referenced by BLCMDbeam(), command(), and nextBeamEvent().
G4ThreeVector BLCMDbeam::position [private] |
Referenced by command(), and nextBeamEvent().
G4int BLCMDbeam::renumber [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::weight [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4int BLCMDbeam::secondaryTrackID [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), and nextBeamEvent().
G4double BLCMDbeam::meanMomentum [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::sigmaX [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::sigmaY [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::sigmaXp [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::sigmaYp [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::sigmaP [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), init(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::sigmaT [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::sigmaE [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), init(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::meanXp [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::meanYp [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::meanT [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::beamHeight [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4double BLCMDbeam::beamWidth [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), nextBeamEvent(), and printBeam().
G4String BLCMDbeam::filename [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), init(), and printBeam().
G4String BLCMDbeam::directory [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), init(), and printBeam().
G4int BLCMDbeam::uid [private] |
Referenced by BLCMDbeam(), and defineNamedArgs().
G4String BLCMDbeam::name [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), init(), and printBeam().
BLNTuple* BLCMDbeam::ntuple [private] |
Referenced by BLCMDbeam(), init(), and nextBeamEvent().
float* BLCMDbeam::data [private] |
Referenced by BLCMDbeam(), init(), and nextBeamEvent().
G4String BLCMDbeam::format [private] |
Referenced by BLCMDbeam(), defineNamedArgs(), init(), nextBeamEvent(), and printBeam().
G4int BLCMDbeam::index [private] |
Referenced by BLCMDbeam(), and init().
G4ParticleGun* BLCMDbeam::particleGun [private] |
Referenced by BLCMDbeam(), init(), and nextBeamEvent().
G4ParticleDefinition* BLCMDbeam::particleDefinition [private] |
Referenced by BLCMDbeam(), init(), and nextBeamEvent().
BLTrackFile* BLCMDbeam::trackFile [private] |
Referenced by BLCMDbeam(), init(), and nextBeamEvent().
G4int BLCMDbeam::nvar [private] |
Referenced by BLCMDbeam(), init(), and nextBeamEvent().
G4int BLCMDbeam::prevEventID [private] |
Referenced by BLCMDbeam(), and nextBeamEvent().