BLCMDbeam Class Reference

Inheritance diagram for BLCMDbeam:

BLBeam BLCommand

List of all members.


Detailed Description

class BLCMDbeam implements the beam command.

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 sigmaZ
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
BLNTuplentuple
float * data
G4String format
G4int index
G4ParticleGun * particleGun
G4ParticleDefinition * particleDefinition
BLTrackFiletrackFile
G4int nvar
G4int prevEventID

Member Enumeration Documentation

enum BLCMDbeam::BeamType [private]

Enumerator:
NONE 
GAUSSIAN 
RECTANGULAR 
ASCII 
ELLIPSE 
ROOT 


Constructor & Destructor Documentation

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, sigmaZ, trackFile, type, uid, UNDEFINED, and weight.

Referenced by command().

00138                      : rotation() , position()
00139 {
00140         registerCommand(BLCMDTYPE_BEAM);
00141         setSynopsis("Define the Beam.");
00142         setDescription("The beam command is: beam type arg1=v1 ...\n\n"
00143                 "Types are: gaussian, rectangular, ellipse, ascii, and root.\n\n"
00144                 "Gaussian beams are randomly generated to emanate from "
00145                 "beamX,beamY,beamZ with the given "
00146                 "sigmas; negative sigma means flat with |sigma| as "
00147                 "halfwidth.\n\n"
00148                 "Rectangular beams are randomly generated to emanate "
00149                 "from the rectangle beamHeight by beamWidth centered at "
00150                 "beamX,beamY,beamZ. \n\n"
00151                 "Ellipse beams are randomly generated on "
00152                 "the ellipses in (X,Xp), (Y,Yp), (T,E), with meanE determined "
00153                 "from meanP and the sigmas used as half-widths; tracks\n"
00154                 "are generated on the ellipse with uniform density when "
00155                 "plotted with scales such that the ellipse is a circle.\n\n"
00156                 "ASCII beams are read from a file using the format "
00157                 "specified; the formats supported are: BLTrackFile\n\n"
00158                 "Root beams are read from a .root file using the "
00159                 "TNtuple named directory/name in the file. It must have the "
00160                 "same fields as used in BLTrackFile format. Note that EventIDs "
00161                 "greater than 16,777,216 will be trncated.\n\n"
00162                 "When reading a file (ascii or root), "
00163                 "beamX and beamY are added to input tracks; if beamZ is set "
00164                 "it will overwrite the z of the track, but if it is not set "
00165                 "the z of the track in the file is kept.\n\n"
00166                 "All coordinates are centerline coordinates.\n\n"
00167                 "Multiple beam commands can be given, and they will generate\n"
00168                 "events in the order they appear in input.file.\n\n"
00169                 "Events are generated starting at firstEvent, until either\n"
00170                 "nEvents have been generated or lastEvent would be exceeded.\n\n"
00171                 "For gaussian, rectangular, and ellipse beams, the beam "
00172                 "particle can be given as either a particle name or "
00173                 "its integer PDGid. Some common beam particle names are: "
00174                 "proton, anti_proton, pi+, pi-, mu+, mu-, e+, e-, kaon+, "
00175                 "kaon-, kaon0, nu_e, anti_nu_e.\n"
00176                 "See the User's Guide for a complete list of particle names.");
00177         // initial default values:
00178         type = NONE;
00179         particle = "mu+";
00180         eventsGenerated = 0;
00181         nEvents = ALL_EVENTS;
00182         eventID = ALL_EVENTS;
00183         firstEvent = -1;
00184         lastEvent = ALL_EVENTS;
00185         meanMomentum = 200.0*MeV;
00186         beamX = 0.0;
00187         beamY = 0.0;
00188         beamZ = UNDEFINED;
00189         maxR = 1.0*kilometer;
00190         renumber = 0;
00191         weight = 1.0;
00192         secondaryTrackID = 1001;
00193         rotationMatrix = 0;
00194         sigmaX = 0.0;
00195         sigmaY = 0.0;
00196         sigmaZ = 0.0;
00197         sigmaXp = 0.0;
00198         sigmaYp = 0.0;
00199         sigmaP = 0.0;
00200         sigmaT = 0.0;
00201         sigmaE = UNDEFINED;
00202         meanXp = 0.0;
00203         meanYp = 0.0;
00204         meanT = 0.0;
00205         beamHeight = 0.0;
00206         beamWidth = 0.0;
00207         filename = "";
00208         directory = "";
00209         uid = 0;
00210         name = "";
00211         ntuple = 0;
00212         data = 0;
00213         format = "BLTrackFile";
00214         index = 0;
00215         particleDefinition = 0;
00216         particleGun = 0;
00217         trackFile = 0;
00218         nvar = 0;
00219         prevEventID = -9999;
00220 }


Member Function Documentation

G4double BLCMDbeam::myrand ( G4double  mean,
G4double  sigma 
) [inline, private]

Referenced by nextBeamEvent().

00098                                                        {
00099                 if(sigma >= 0.0) return sigma*CLHEP::RandGauss::shoot() + mean;
00100                 return mean+sigma-2.0*sigma*G4UniformRand();
00101         }

virtual G4String BLCMDbeam::commandName (  )  [inline, virtual]

commandName() returns "beam".

Implements BLCommand.

00109 { return "beam"; }

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.

00223 {
00224         if(argv.size() != 1) {
00225                 printError("Invalid beam command -- need beam type");
00226                 return -1;
00227         }
00228 
00229         BLCMDbeam *b = new BLCMDbeam(*this);
00230 
00231         if(argv[0] == "gaussian" || argv[0] == "gauss") {
00232                 b->type = GAUSSIAN;
00233                 b->nEvents = 1;
00234         } else if(argv[0] == "rectangular" || argv[0] == "rect") {
00235                 b->type = RECTANGULAR;
00236                 b->nEvents = 1;
00237         } else if(argv[0] == "ascii" || argv[0] == "ASCII") {
00238                 b->type = ASCII;
00239                 b->nEvents = ALL_EVENTS;
00240         } else if(argv[0] == "ellipse" || argv[0] == "ELLIPSE") {
00241                 b->type = ELLIPSE;
00242                 b->nEvents = 1;
00243         } else if(argv[0] == "root") {
00244                 b->type = ROOT;
00245                 b->nEvents = ALL_EVENTS;
00246         } else {
00247                 printError("beam: invalid type '%s'",argv[0].c_str());
00248         }
00249 
00250         b->rotation = "";
00251         int retval = b->handleNamedArgs(namedArgs);
00252 
00253         if(b->firstEvent != -1 && b->lastEvent != ALL_EVENTS)
00254                 b->nEvents = b->lastEvent - b->firstEvent + 1;
00255 
00256         if(b->rotation != "") {
00257                 b->rotationMatrix = stringToRotationMatrix(b->rotation);
00258         } else {
00259                 b->rotationMatrix = new G4RotationMatrix();
00260         }
00261         // as usual, the order seems backward because (C R C^-1) C = C R.
00262         *b->rotationMatrix = *BLCoordinates::getCurrentRotation() * 
00263                                                         *b->rotationMatrix;
00264         G4ThreeVector local(b->beamX,b->beamY,
00265                                         (b->beamZ==UNDEFINED ? 0.0 : b->beamZ));
00266         BLCoordinates::getCurrentGlobal(local,b->position);
00267 
00268         // ensure beam is within the world
00269         BLGroup::getWorld()->setMinWidth(fabs(b->position[0])*2.0);
00270         BLGroup::getWorld()->setMinHeight(fabs(b->position[1])*2.0);
00271         BLGroup::getWorld()->setMinLength(fabs(b->position[2])*2.0);
00272 
00273         BLManager::getObject()->registerBeam(b);
00274 
00275         b->printBeam();
00276 
00277         return retval;
00278 }

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, sigmaZ, type, and weight.

Referenced by command().

00325 {
00326         switch(type) {
00327         case NONE:
00328                 printf("beam    NONE    Invalid beam command\n");
00329                 break;
00330         case GAUSSIAN:
00331                 printf("beam    GAUSSIAN particle=%s ",particle.c_str());
00332                 printf("nEvents=%d ",nEvents);
00333                 printf("firstEvent=%d ",firstEvent);
00334                 printf("lastEvent=%d ",lastEvent);
00335                 printf("beamX=%.1f ",beamX);
00336                 printf("beamY=%.1f ",beamY);
00337                 printf("beamZ=%.1f ",beamZ);
00338                 printf("maxR=%.1f ",maxR);
00339                 printf("\n\t\t");
00340                 printf("meanMomentum=%.1f ",meanMomentum);
00341                 printf("weight=%1f ",weight);
00342                 printf("\n\t\t");
00343                 printf("sigmaX=%.1f ",sigmaX);
00344                 printf("sigmaY=%.1f ",sigmaY);
00345                 printf("sigmaZ=%.1f ",sigmaZ);
00346                 printf("sigmaXp=%.5f ",sigmaXp);
00347                 printf("sigmaYp=%.5f ",sigmaYp);
00348                 printf("\n\t\t");
00349                 printf("sigmaP=%.1f ",sigmaP);
00350                 printf("sigmaT=%.3f ",sigmaT);
00351                 printf("meanXp=%.5f ",meanXp);
00352                 printf("meanYp=%.5f ",meanYp);
00353                 printf("meanT=%.3f ",meanT);
00354                 printf("\n");
00355                 break;
00356         case RECTANGULAR:
00357                 printf("beam    RECTANGULAR particle=%s ",particle.c_str());
00358                 printf("nEvents=%d ",nEvents);
00359                 printf("firstEvent=%d ",firstEvent);
00360                 printf("lastEvent=%d ",lastEvent);
00361                 printf("beamX=%.1f ",beamX);
00362                 printf("beamY=%.1f ",beamY);
00363                 printf("beamZ=%.1f ",beamZ);
00364                 printf("maxR=%.1f ",maxR);
00365                 printf("\n\t\t");
00366                 printf("meanMomentum=%.1f ",meanMomentum);
00367                 printf("weight=%1f ",weight);
00368                 printf("\n\t\t");
00369                 printf("beamHeight=%.1f ",beamHeight);
00370                 printf("beamWidth=%.1f ",beamWidth);
00371                 printf("sigmaXp=%.5f ",sigmaXp);
00372                 printf("sigmaYp=%.5f ",sigmaYp);
00373                 printf("\n\t\t");
00374                 printf("sigmaP=%.1f ",sigmaP);
00375                 printf("sigmaT=%.3f ",sigmaT);
00376                 printf("meanXp=%.5f ",meanXp);
00377                 printf("meanYp=%.5f ",meanYp);
00378                 printf("meanT=%.3f ",meanT);
00379                 printf("\n");
00380                 break;
00381         case ROOT:
00382                 printf("beam    ROOT   ");
00383                 printf("nEvents=%d ",nEvents);
00384                 printf("firstEvent=%d ",firstEvent);
00385                 printf("lastEvent=%d ",lastEvent);
00386                 printf("beamZ=%.1f ",beamZ);
00387                 printf("maxR=%.1f ",maxR);
00388                 printf("renumber=%d ",renumber);
00389                 printf("weight=%1f ",weight);
00390                 printf("\n\t\t");
00391                 printf("filename=%s ",filename.c_str());
00392                 printf("directory=%s ",directory.c_str());
00393                 printf("name=%s ",name.c_str());
00394                 printf("\n\t\t");
00395                 printf("\n");
00396                 break;
00397         case ASCII:
00398                 printf("beam    ASCII   ");
00399                 printf("nEvents=%d ",nEvents);
00400                 printf("firstEvent=%d ",firstEvent);
00401                 printf("lastEvent=%d ",lastEvent);
00402                 printf("beamZ=%.1f ",beamZ);
00403                 printf("maxR=%.1f ",maxR);
00404                 printf("renumber=%d ",renumber);
00405                 printf("weight=%1f ",weight);
00406                 printf("\n\t\t");
00407                 printf("filename=%s ",filename.c_str());
00408                 printf("format=%s ",format.c_str());
00409                 printf("\n\t\t");
00410                 printf("\n");
00411                 break;
00412         case ELLIPSE:
00413                 printf("beam    ELLIPSE particle=%s ",particle.c_str());
00414                 printf("nEvents=%d ",nEvents);
00415                 printf("firstEvent=%d ",firstEvent);
00416                 printf("lastEvent=%d ",lastEvent);
00417                 printf("beamX=%.1f ",beamX);
00418                 printf("beamY=%.1f ",beamY);
00419                 printf("beamZ=%.1f ",beamZ);
00420                 printf("maxR=%.1f ",maxR);
00421                 printf("\n\t\t");
00422                 printf("meanMomentum=%.1f ",meanMomentum);
00423                 printf("weight=%1f ",weight);
00424                 printf("\n\t\t");
00425                 printf("sigmaX=%.1f ",sigmaX);
00426                 printf("sigmaY=%.1f ",sigmaY);
00427                 printf("sigmaXp=%.5f ",sigmaXp);
00428                 printf("sigmaYp=%.5f ",sigmaYp);
00429                 printf("\n\t\t");
00430                 printf("sigmaE=%.1f ",sigmaE);
00431                 printf("sigmaT=%.3f ",sigmaT);
00432                 printf("meanXp=%.5f ",0.0);
00433                 printf("meanYp=%.5f ",0.0);
00434                 printf("meanT=%.3f ",0.0);
00435                 printf("\n");
00436                 break;
00437         }
00438 }

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, sigmaZ, uid, and weight.

00281 {
00282         argString(particle,"particle","Beam particle name");
00283         argInt(nEvents,"nEvents","Number of events to process (default=1 "
00284                 "for generating events, default=ALL for reading files) "
00285                 "set to lastEvent-firstEvent+1 if both are set.");
00286         argInt(firstEvent,"firstEvent","First event # to process (default "
00287                 "is the next sequential eventID, 1 if none)");
00288         argInt(lastEvent,"lastEvent","Last  (highest) event # to process");
00289         argDouble(beamX,"beamX","Beam location in X (mm)");
00290         argDouble(beamY,"beamY","Beam location in Y (mm)");
00291         argDouble(beamZ,"beamZ","Beam location in Z (mm)");
00292         argDouble(maxR,"maxR","Beam maximum radius (mm)");
00293         argString(rotation,"rotation","Rotation of the beam");
00294         argInt(renumber,"renumber","If nonzero, renumber events sequentially."); 
00295         argDouble(weight,"weight","Weight for events, overwritten by value from input file (1.0)."); 
00296         argInt(secondaryTrackID,"secondaryTrackID","The next TrackID for secondaries (1001)."); 
00297         argDouble(meanMomentum,"meanMomentum",
00298                                 "Gaussian Beam mean momentum (MeV/c)");
00299         argDouble(meanMomentum,"meanP","Synonym for meanMomentum.");
00300         argDouble(sigmaX,"sigmaX","Gaussian Beam sigma in X (mm)");
00301         argDouble(sigmaY,"sigmaY","Gaussian Beam sigma in Y (mm)");
00302         argDouble(sigmaZ,"sigmaZ","Gaussian Beam sigma in Z (mm)");
00303         argDouble(sigmaXp,"sigmaXp","Gaussian Beam sigma in dxdz (slope)");
00304         argDouble(sigmaYp,"sigmaYp","Gaussian Beam sigma in dydz (slope)");
00305         argDouble(sigmaP,"sigmaP","Gaussian Beam sigma in P (MeV/c)");
00306         argDouble(sigmaT,"sigmaT","Gaussian Beam sigma in T (ns)");
00307         argDouble(sigmaE,"sigmaE","Elliptical Beam sigma in E (MeV)");
00308         argDouble(meanXp,"meanXp","Gaussian Beam mean in Xp (slope)");
00309         argDouble(meanYp,"meanYp","Gaussian Beam mean in Yp (slope)");
00310         argDouble(meanT,"meanT","Gaussian Beam mean in T (ns)");
00311         argDouble(beamHeight,"beamHeight","Rectangular Beam height (mm)");
00312         argDouble(beamWidth,"beamWidth","Rectangular Beam width (mm)");
00313         argString(filename,"filename","input file name");
00314         argString(filename,"file","synonym for filename.");
00315         argString(directory,"directory","Root-file directory of NTuple");
00316         argString(directory,"category","Deprecated synonym for directory.");
00317         argInt(uid,"uid","HistoScope uid of NTuple");
00318         argString(name,"name","Root name of NTuple.");
00319         argString(format,"format","ASCII file format (Default=BLTrackFile)");
00320         argDouble(meanXp,"beamXp","Synonym for meanXp.");
00321         argDouble(meanYp,"beamYp","Synonym for meanYp.");
00322 }

virtual int BLCMDbeam::getNEvents (  )  const [inline, virtual]

getNEvents() returns the # events to process.

Reimplemented from BLBeam.

References nEvents.

00121 { 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.

00441 {
00442         eventsGenerated = 0;
00443         index = 0;
00444         if(particleDefinition != 0) return;
00445 
00446         if(isdigit(particle(0)) || particle(0) == '-')
00447                 particleDefinition = G4ParticleTable::GetParticleTable()->
00448                                         FindParticle(atoi(particle.c_str()));
00449         else
00450                 particleDefinition = G4ParticleTable::GetParticleTable()->
00451                                         FindParticle(particle);
00452         if(!particleDefinition)
00453                 G4Exception("beam command","UnknownParticle",FatalException,
00454                                                 "Unknown particle type");
00455         particleGun = new G4ParticleGun(1);
00456         particleGun->SetParticleDefinition(particleDefinition);
00457 
00458         switch(type) {
00459         case NONE:
00460                 break;
00461         case GAUSSIAN:
00462         case RECTANGULAR:
00463                 break;
00464         case ELLIPSE:
00465                 if(sigmaE == UNDEFINED) sigmaE = sigmaP;
00466                 break;
00467         case ROOT:
00468                 { ntuple = BLNTuple::read("Root",directory,name,TrackFields,
00469                                                                 filename);
00470                   nvar = ntuple->getNData();
00471                   data = new float[nvar];
00472                 }
00473                 break;
00474         case ASCII:
00475                 if(format == "BLTrackFile") {
00476                         trackFile = new BLTrackFile(filename,"","r");
00477                 }
00478                 break;
00479         }
00480 }

bool BLCMDbeam::generateReferenceParticle ( G4Event *  event  )  [virtual]

generateReferenceParticle() generates the reference particle.

Implements BLBeam.

00483 {
00484         return false;
00485 }

bool BLCMDbeam::nextBeamEvent ( G4Event *  event  )  [virtual]

nextBeamEvent() generates the next beam event.

Implements BLBeam.

References ASCII, beamHeight, beamWidth, beamZ, BLAssert, 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, sigmaZ, trackFile, type, UNDEFINED, and weight.

00488 {
00489         G4double mass = particleDefinition->GetPDGMass();
00490         G4ThreeVector pos;
00491         G4ThreeVector direction;
00492         G4double time = 0.0;
00493         G4double momentum = 0.0;
00494         G4double ke = 0.0;
00495         G4int PDGid, trackID, parentID;
00496 
00497         BLManager *manager = BLManager::getObject();
00498 
00499         // default eventID -- changed when reading a file unless renumber!=0
00500         eventID = manager->getEventID();
00501         if(eventsGenerated == 0 && firstEvent != -1)
00502                 eventID = firstEvent;
00503 
00504         if(++eventsGenerated > nEvents) return false;
00505 
00506         // loop - must not generate any event with r > maxR
00507         // beam pos = (0,0,0), beam nominal direction = (0,0,1)
00508         // rotation and offset come later
00509         bool again=false;
00510         trackID = -1;
00511         parentID = 0;
00512         do {
00513             again = false;
00514             switch(type) {
00515             case NONE:
00516                 return false;
00517             case GAUSSIAN:
00518                 setRandomSeedToGenerate(eventID);
00519                 // meanX=beamX, meanY=beamY (implicitly)
00520                 pos[0] = myrand(0.0,sigmaX);
00521                 pos[1] = myrand(0.0,sigmaY);
00522                 pos[2] = myrand(0.0,sigmaZ);
00523                 direction[0] = myrand(meanXp,sigmaXp);
00524                 direction[1] = myrand(meanYp,sigmaYp);
00525                 direction[2] = 1.0/sqrt(1.0 + direction[0]*direction[0] +
00526                                                 direction[1]*direction[1]);
00527                 direction[0] *= direction[2];
00528                 direction[1] *= direction[2];
00529                 momentum = myrand(meanMomentum,sigmaP);
00530                 time = myrand(meanT,sigmaT);
00531                 trackID = 1;
00532                 break;
00533             case RECTANGULAR:
00534                 setRandomSeedToGenerate(eventID);
00535                 pos[0] = beamWidth*G4UniformRand()-beamWidth/2.0;
00536                 pos[1] = beamHeight*G4UniformRand()-beamHeight/2.0;
00537                 pos[2] = myrand(0.0,sigmaZ);
00538                 direction[0] = myrand(meanXp,sigmaXp);
00539                 direction[1] = myrand(meanYp,sigmaYp);
00540                 direction[2] = 1.0/sqrt(1.0 + direction[0]*direction[0] +
00541                                                 direction[1]*direction[1]);
00542                 direction[0] *= direction[2];
00543                 direction[1] *= direction[2];
00544                 momentum = myrand(meanMomentum,sigmaP);
00545                 time = myrand(meanT,sigmaT);
00546                 trackID = 1;
00547                 break;
00548             case ROOT:
00549                 { do {
00550                         if(!ntuple->readRow(data,nvar)) return false;
00551                         // data[] = x, y, z, Px, Py, Pz, t, PDGid, EventID, 
00552                         // TrackID, ParentID, Weight
00553                         if(renumber == 0) eventID = (G4int)data[8];
00554                   } while(renumber == 0 && eventID < firstEvent);
00555                   particleDefinition = G4ParticleTable::GetParticleTable()->
00556                                                 FindParticle((G4int)data[7]);
00557                   if(!particleDefinition) {
00558                         char tmp[64];
00559                         sprintf(tmp,"Invalid PDGid=%d -- Track abandoned",
00560                                                                 (int)data[7]);
00561                         G4Exception("beam command","Invalid PDGid",
00562                                                         JustWarning, tmp);
00563                         again = true;
00564                         continue;
00565                   }
00566                   mass = particleDefinition->GetPDGMass();
00567                   particleGun->SetParticleDefinition(particleDefinition);
00568                   pos[0] = data[0]*mm;
00569                   pos[1] = data[1]*mm;
00570                   pos[2] = data[2]*mm;
00571                   data[3] *= MeV;
00572                   data[4] *= MeV;
00573                   data[5] *= MeV;
00574                   momentum = sqrt(data[3]*data[3]+data[4]*data[4]+data[5]*data[5]);
00575                   direction[0] = data[3]/momentum;
00576                   direction[1] = data[4]/momentum;
00577                   direction[2] = data[5]/momentum;
00578                   time = data[6]*ns;
00579                   trackID = (G4int)data[9];
00580                   parentID = (G4int)data[10];
00581                   if(nvar >= 12) weight = data[11];
00582                 }
00583                 break;
00584             case ASCII:
00585                 if(format == "BLTrackFile") {
00586                         do {
00587                                 int tmpID=0;
00588                                 BLTrackFileStatus stat=trackFile->read(pos,time,
00589                                         direction,PDGid,tmpID,trackID,parentID,
00590                                         weight);
00591                                 if(stat == BLTF_ERROR)
00592                                         G4Exception("beam command",
00593                                                 "Invalid BLTrackFile input",
00594                                                 JustWarning, "File abandoned");
00595                                 if(stat != BLTF_OK)
00596                                         return false;
00597                                 if(renumber == 0) eventID = tmpID;
00598                         } while(renumber == 0 && eventID < firstEvent);
00599                         particleDefinition = G4ParticleTable::GetParticleTable()
00600                                                         ->FindParticle(PDGid);
00601                         if(!particleDefinition) {
00602                             char tmp[64];
00603                             sprintf(tmp,"Invalid PDGid=%d -- Track abandoned",
00604                                                                         PDGid);
00605                             G4Exception("beam command","Invalid PDGid",
00606                                                         JustWarning, tmp);
00607                             again = true;
00608                             continue;
00609                         }
00610                         mass = particleDefinition->GetPDGMass();
00611                         particleGun->SetParticleDefinition(particleDefinition);
00612                         momentum = sqrt(direction[0]*direction[0]+
00613                                         direction[1]*direction[1]+
00614                                         direction[2]*direction[2]);
00615                         direction[0] /= momentum;
00616                         direction[1] /= momentum;
00617                         direction[2] /= momentum;
00618                 }
00619                 break;
00620             case ELLIPSE:
00621                 setRandomSeedToGenerate(eventID);
00622                 // meanX=beamX, meanY=beamY (implicitly)
00623                 double a = 2.0*M_PI*G4UniformRand();
00624                 double b = 2.0*M_PI*G4UniformRand();
00625                 double c = 2.0*M_PI*G4UniformRand();
00626                 pos[0] = sigmaX*cos(a);
00627                 pos[1] = sigmaY*cos(b);
00628                 pos[2] = myrand(0.0,sigmaZ);
00629                 direction[0] = sigmaXp*sin(a);
00630                 direction[1] = sigmaYp*sin(b);
00631                 direction[2] = 1.0/sqrt(1.0 + direction[0]*direction[0] +
00632                                                 direction[1]*direction[1]);
00633                 direction[0] *= direction[2];
00634                 direction[1] *= direction[2];
00635                 double E = sqrt(meanMomentum*meanMomentum + mass*mass) +
00636                                                                 sigmaE*sin(c);
00637                 momentum = sqrt(E*E - mass*mass);
00638                 time = sigmaT*cos(c);
00639                 trackID = 1;
00640                 break;
00641             }
00642         } while(again || sqrt(pos[0]*pos[0]+pos[1]*pos[1]) > maxR);
00643 
00644         BLAssert(trackID >= 0);
00645 
00646         if(eventID > lastEvent) return false;
00647 
00648         if(beamZ != UNDEFINED) pos[2] = 0.0;
00649 
00650         // apply rotation and offset
00651         if(rotationMatrix) {
00652                 direction = *rotationMatrix * direction;
00653                 pos = *rotationMatrix * pos;
00654         }
00655         pos += position;
00656 
00657         ke = sqrt(momentum*momentum + mass*mass) - mass;
00658         particleGun->SetParticleTime(time);
00659         particleGun->SetParticlePosition(pos);
00660         particleGun->SetParticleEnergy(ke);
00661         particleGun->SetParticleMomentumDirection(direction);
00662         particleGun->GeneratePrimaryVertex(event);
00663         event->SetEventID(eventID);
00664         event->GetPrimaryVertex()->SetWeight(weight);
00665         if(eventID != prevEventID) {
00666                 setRandomSeedToTrack(eventID);
00667                 manager->clearTrackIDMap();
00668                 manager->setNextSecondaryTrackID(secondaryTrackID);
00669                 prevEventID = eventID;
00670         }
00671         manager->setPrimaryTrackID(trackID,parentID);
00672         if(trackID >= secondaryTrackID) {
00673                 G4Exception("beam command","Large Primary TrackID",JustWarning,
00674                         "Confusion with secondary tracks is likely");
00675         }
00676         return true;
00677 }

virtual void BLCMDbeam::summary (  )  [inline, virtual]

summary() will print a summary, if necessary.

Reimplemented from BLBeam.

00133 { }


Member Data Documentation

Reimplemented from BLCommand.

Referenced by BLCMDbeam(), command(), init(), nextBeamEvent(), and printBeam().

G4String BLCMDbeam::particle [private]

G4int BLCMDbeam::eventsGenerated [private]

Referenced by BLCMDbeam(), init(), and nextBeamEvent().

G4int BLCMDbeam::nEvents [private]

G4int BLCMDbeam::eventID [private]

Referenced by BLCMDbeam(), and nextBeamEvent().

G4int BLCMDbeam::firstEvent [private]

G4int BLCMDbeam::lastEvent [private]

G4double BLCMDbeam::beamX [private]

G4double BLCMDbeam::beamY [private]

G4double BLCMDbeam::beamZ [private]

G4double BLCMDbeam::maxR [private]

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]

G4double BLCMDbeam::weight [private]

G4int BLCMDbeam::secondaryTrackID [private]

G4double BLCMDbeam::meanMomentum [private]

G4double BLCMDbeam::sigmaX [private]

G4double BLCMDbeam::sigmaY [private]

G4double BLCMDbeam::sigmaZ [private]

G4double BLCMDbeam::sigmaXp [private]

G4double BLCMDbeam::sigmaYp [private]

G4double BLCMDbeam::sigmaP [private]

G4double BLCMDbeam::sigmaT [private]

G4double BLCMDbeam::sigmaE [private]

G4double BLCMDbeam::meanXp [private]

G4double BLCMDbeam::meanYp [private]

G4double BLCMDbeam::meanT [private]

G4double BLCMDbeam::beamHeight [private]

G4double BLCMDbeam::beamWidth [private]

G4String BLCMDbeam::filename [private]

G4String BLCMDbeam::directory [private]

G4int BLCMDbeam::uid [private]

Referenced by BLCMDbeam(), and defineNamedArgs().

G4String BLCMDbeam::name [private]

Referenced by BLCMDbeam(), init(), and nextBeamEvent().

float* BLCMDbeam::data [private]

Referenced by BLCMDbeam(), init(), and nextBeamEvent().

G4String BLCMDbeam::format [private]

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().

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().


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