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, HISTO,
  HISTO_STUDY2, 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 category
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 
HISTO 
HISTO_STUDY2 
ASCII 
ELLIPSE 
ROOT 


Constructor & Destructor Documentation

BLCMDbeam::BLCMDbeam (  ) 

Constructor.

References ALL_EVENTS, beamHeight, beamWidth, beamX, beamY, beamZ, BLCMDTYPE_BEAM, category, data, 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().

00136                      : rotation() , position()
00137 {
00138         registerCommand(BLCMDTYPE_BEAM);
00139         setSynopsis("Define the Beam.");
00140         setDescription("The beam is nominally headed in the +Z direction.\n"
00141                 "There are these types of beam: gaussian, rectangular, \n"
00142                 "ascii, ellipse, root, and histo.\n"
00143                 "The command is 'beam type arg1=v1 ...'\n"
00144                 "Rectangular beams emanate from the\n"
00145                 "rectangle beamHeight by beamWidth located at beamX,beamY,beamZ.\n"
00146                 "When reading a file, "
00147                 "beamX and beamY are added to input tracks; if beamZ is set "
00148                 "it will overwrite the z of the track, but if it is not set "
00149                 "the z of the track is kept. "
00150                 "All coordinates are centerline coordinates.\n"
00151                 "Negative sigma means flat with -sigma as halfwidth.\n"
00152                 "For histo, format=Study2 uses the old format and units.\n"
00153                 "For ellipse beams, the sigmas are the half-axes, and tracks\n"
00154                 "are generated on the ellipse with uniform density when plotted\n"
00155                 "with scales such that the ellipse is a circle. The ellipses\n"
00156                 "are in X&Xp, Y&Yp, T&E (meanE determined from meanMomentum).\n"
00157                 "Multiple beam commands can be given, and they will generate\n"
00158                 "events in the order they were used.\n"
00159                 "Events are generated starting at firstEvent, until either\n"
00160                 "nEvents have been generated or lastEvent would be exceeded.\n\n"
00161                 "Some common beam particle names are: proton, anti_proton, pi+, "
00162                 "pi-, mu+, mu-, e+, e-, kaon+, kaon-, kaon0, nu_e, anti_nu_e.\n"
00163                 "See the User's Guide for a complete list of particle names.");
00164         // initial default values:
00165         type = NONE;
00166         particle = "mu+";
00167         eventsGenerated = 0;
00168         nEvents = ALL_EVENTS;
00169         eventID = ALL_EVENTS;
00170         firstEvent = -1;
00171         lastEvent = ALL_EVENTS;
00172         meanMomentum = 200.0*MeV;
00173         beamX = 0.0;
00174         beamY = 0.0;
00175         beamZ = UNDEFINED;
00176         maxR = 1.0*kilometer;
00177         renumber = 0;
00178         weight = 1.0;
00179         secondaryTrackID = 1001;
00180         rotationMatrix = 0;
00181         sigmaX = 0.0;
00182         sigmaY = 0.0;
00183         sigmaXp = 0.0;
00184         sigmaYp = 0.0;
00185         sigmaP = 0.0;
00186         sigmaT = 0.0;
00187         sigmaE = UNDEFINED;
00188         meanXp = 0.0;
00189         meanYp = 0.0;
00190         meanT = 0.0;
00191         beamHeight = 0.0;
00192         beamWidth = 0.0;
00193         filename = "";
00194         category = "";
00195         uid = 0;
00196         name = "";
00197         ntuple = 0;
00198         data = 0;
00199         format = "BLTrackFile";
00200         index = 0;
00201         particleDefinition = 0;
00202         particleGun = 0;
00203         trackFile = 0;
00204         nvar = 0;
00205         prevEventID = -9999;
00206 }


Member Function Documentation

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

Referenced by nextBeamEvent().

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

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

commandName() returns "beam".

Implements BLCommand.

00107 { 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, format, GAUSSIAN, BLCoordinates::getCurrentGlobal(), BLCoordinates::getCurrentRotation(), BLManager::getObject(), BLGroup::getWorld(), BLCommand::handleNamedArgs(), HISTO, HISTO_STUDY2, lastEvent, nEvents, position, printBeam(), BLCommand::printError(), RECTANGULAR, BLManager::registerBeam(), ROOT, rotation, rotationMatrix, BLGroup::setMinHeight(), BLGroup::setMinLength(), BLGroup::setMinWidth(), BLCommand::stringToRotationMatrix(), type, and UNDEFINED.

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

void BLCMDbeam::printBeam (  )  [virtual]

printBeam() will print a description.

References ASCII, beamHeight, beamWidth, beamX, beamY, beamZ, category, ELLIPSE, filename, firstEvent, format, GAUSSIAN, HISTO, HISTO_STUDY2, lastEvent, maxR, meanMomentum, meanT, meanXp, meanYp, name, nEvents, NONE, particle, RECTANGULAR, renumber, ROOT, sigmaE, sigmaP, sigmaT, sigmaX, sigmaXp, sigmaY, sigmaYp, type, uid, and weight.

Referenced by command().

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

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, category, 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.

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

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

getNEvents() returns the # events to process.

Reimplemented from BLBeam.

References nEvents.

00119 { return nEvents; }

void BLCMDbeam::init (  )  [virtual]

init() will initialize internal variables.

Implements BLBeam.

References ASCII, category, data, ELLIPSE, eventsGenerated, filename, format, GAUSSIAN, BLNTuple::getNData(), HISTO, HISTO_STUDY2, index, name, NONE, ntuple, nvar, particle, particleDefinition, particleGun, BLNTuple::read(), RECTANGULAR, ROOT, sigmaE, sigmaP, TrackFields, trackFile, type, uid, and UNDEFINED.

00446 {
00447         eventsGenerated = 0;
00448         index = 0;
00449         if(particleDefinition != 0) return;
00450 
00451         if(isdigit(particle(0)) || particle(0) == '-')
00452                 particleDefinition = G4ParticleTable::GetParticleTable()->
00453                                         FindParticle(atoi(particle.c_str()));
00454         else
00455                 particleDefinition = G4ParticleTable::GetParticleTable()->
00456                                         FindParticle(particle);
00457         if(!particleDefinition)
00458                 G4Exception("beam command","UnknownParticle",FatalException,
00459                                                 "Unknown particle type");
00460         particleGun = new G4ParticleGun(1);
00461         particleGun->SetParticleDefinition(particleDefinition);
00462 
00463         switch(type) {
00464         case NONE:
00465                 break;
00466         case GAUSSIAN:
00467         case RECTANGULAR:
00468                 break;
00469         case ELLIPSE:
00470                 if(sigmaE == UNDEFINED) sigmaE = sigmaP;
00471                 break;
00472         case HISTO_STUDY2:
00473         case HISTO:
00474                 { char tmp[16];
00475                   sprintf(tmp,"%d",uid);
00476                   ntuple = BLNTuple::read("HistoScope",category,tmp,TrackFields,
00477                                                                 filename);
00478                   nvar = ntuple->getNData();
00479                   data = new float[nvar];
00480                 }
00481                 break;
00482         case ROOT:
00483                 { ntuple = BLNTuple::read("Root",category,name,TrackFields,
00484                                                                 filename);
00485                   nvar = ntuple->getNData();
00486                   data = new float[nvar];
00487                 }
00488                 break;
00489         case ASCII:
00490                 if(format == "BLTrackFile") {
00491                         trackFile = new BLTrackFile(filename,"","r");
00492                 }
00493                 break;
00494         }
00495 }

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

generateReferenceParticle() generates the reference particle.

Implements BLBeam.

00498 {
00499         return false;
00500 }

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

nextBeamEvent() generates the next beam event.

Implements BLBeam.

References ASCII, beamHeight, beamWidth, beamZ, BLTF_OK, BLManager::clearTrackIDMap(), data, E, ELLIPSE, eventID, eventsGenerated, firstEvent, format, GAUSSIAN, BLManager::getEventID(), BLManager::getObject(), HISTO, HISTO_STUDY2, 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.

00503 {
00504         G4double mass = particleDefinition->GetPDGMass();
00505         G4ThreeVector pos;
00506         G4ThreeVector direction;
00507         G4double time = 0.0;
00508         G4double momentum = 0.0;
00509         G4double ke = 0.0;
00510         G4int PDGid, trackID, parentID;
00511 
00512         BLManager *manager = BLManager::getObject();
00513 
00514         // default eventID -- changed when reading a file unless renumber!=0
00515         eventID = manager->getEventID();
00516         if(eventsGenerated == 0 && firstEvent != -1)
00517                 eventID = firstEvent;
00518 
00519         if(++eventsGenerated > nEvents) return false;
00520 
00521         // loop - must not generate any event with r > maxR
00522         // beam pos = (0,0,0), beam nominal direction = (0,0,1)
00523         // rotation and offset come later
00524         bool again=false;
00525         trackID = -1;
00526         parentID = 0;
00527         do {
00528             again = false;
00529             switch(type) {
00530             case NONE:
00531                 return false;
00532             case GAUSSIAN:
00533                 setRandomSeedToGenerate(eventID);
00534                 // meanX=beamX, meanY=beamY (implicitly)
00535                 pos[0] = myrand(0.0,sigmaX);
00536                 pos[1] = myrand(0.0,sigmaY);
00537                 pos[2] = 0.0;
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 RECTANGULAR:
00549                 setRandomSeedToGenerate(eventID);
00550                 pos[0] = beamWidth*G4UniformRand()-beamWidth/2.0;
00551                 pos[1] = beamHeight*G4UniformRand()-beamHeight/2.0;
00552                 pos[2] = 0.0;
00553                 direction[0] = myrand(meanXp,sigmaXp);
00554                 direction[1] = myrand(meanYp,sigmaYp);
00555                 direction[2] = 1.0/sqrt(1.0 + direction[0]*direction[0] +
00556                                                 direction[1]*direction[1]);
00557                 direction[0] *= direction[2];
00558                 direction[1] *= direction[2];
00559                 momentum = myrand(meanMomentum,sigmaP);
00560                 time = myrand(meanT,sigmaT);
00561                 trackID = 1;
00562                 break;
00563         case HISTO_STUDY2:
00564                 { do {
00565                         if(!ntuple->readRow(data,nvar)) return false;
00566                         // data[] = x, y, z, dxdz, dydz, P, t, PDGencoding, EvNum, ParentID
00567                         if(renumber == 0) eventID = (G4int)data[8];
00568                   } while(renumber == 0 && eventID < firstEvent);
00569                   particleDefinition = G4ParticleTable::GetParticleTable()->
00570                                                 FindParticle((G4int)data[7]);
00571                   if(!particleDefinition) {
00572                           printf("BLCMDbeam::nextBeamEvent Cannot find Particle"
00573                                 " with PDGencoding=%.0f\n",data[7]);
00574                           again = true;
00575                           continue;
00576                   }
00577                   mass = particleDefinition->GetPDGMass();
00578                   particleGun->SetParticleDefinition(particleDefinition);
00579                   pos[0] = data[0]*cm;
00580                   pos[1] = data[1]*cm;
00581                   pos[2] = data[2]*cm;
00582                   momentum = data[5]*GeV;
00583                   double norm = 1.0/sqrt(1.0+data[3]*data[3]+data[4]*data[4]);
00584                   direction[0] = data[3]*norm;
00585                   direction[1] = data[4]*norm;
00586                   direction[2] = norm;
00587                   time = data[6];
00588                   trackID = (G4int)data[9];
00589                   parentID = (G4int)data[10];
00590                 }
00591                 break;
00592             case HISTO:
00593                 { do {
00594                         if(!ntuple->readRow(data,nvar)) return false;
00595                         // data[] = x, y, z, Px, Py, Pz, t, PDGencoding, EvNum, 
00596                         // TrackID, ParentID, Weight
00597                         if(renumber == 0) eventID = (G4int)data[8];
00598                   } while(renumber == 0 && eventID < firstEvent);
00599                   particleDefinition = G4ParticleTable::GetParticleTable()->
00600                                                 FindParticle((G4int)data[7]);
00601                   if(!particleDefinition) {
00602                           printf("BLCMDbeam::nextBeamEvent Cannot find Particle"
00603                                 " with PDGencoding=%.0f\n",data[7]);
00604                           again = true;
00605                           continue;
00606                   }
00607                   mass = particleDefinition->GetPDGMass();
00608                   particleGun->SetParticleDefinition(particleDefinition);
00609                   pos[0] = data[0]*mm;
00610                   pos[1] = data[1]*mm;
00611                   pos[2] = data[2]*mm;
00612                   data[3] *= MeV;
00613                   data[4] *= MeV;
00614                   data[5] *= MeV;
00615                   momentum = sqrt(data[3]*data[3]+data[4]*data[4]+data[5]*data[5]);
00616                   direction[0] = data[3]/momentum;
00617                   direction[1] = data[4]/momentum;
00618                   direction[2] = data[5]/momentum;
00619                   time = data[6]*ns;
00620                   trackID = (G4int)data[9];
00621                   parentID = (G4int)data[10];
00622                   if(nvar >= 12) weight = data[11];
00623                 }
00624                 break;
00625             case ROOT:
00626                 { do {
00627                         if(!ntuple->readRow(data,nvar)) return false;
00628                         // data[] = x, y, z, Px, Py, Pz, t, PDGencoding, EvNum, 
00629                         // TrackID, ParentID, Weight
00630                         if(renumber == 0) eventID = (G4int)data[8];
00631                   } while(renumber == 0 && eventID < firstEvent);
00632                   particleDefinition = G4ParticleTable::GetParticleTable()->
00633                                                 FindParticle((G4int)data[7]);
00634                   if(!particleDefinition) {
00635                           printf("BLCMDbeam::nextBeamEvent Cannot find Particle"
00636                                 " with PDGencoding=%.0f\n",data[7]);
00637                           again = true;
00638                           continue;
00639                   }
00640                   mass = particleDefinition->GetPDGMass();
00641                   particleGun->SetParticleDefinition(particleDefinition);
00642                   pos[0] = data[0]*mm;
00643                   pos[1] = data[1]*mm;
00644                   pos[2] = data[2]*mm;
00645                   data[3] *= MeV;
00646                   data[4] *= MeV;
00647                   data[5] *= MeV;
00648                   momentum = sqrt(data[3]*data[3]+data[4]*data[4]+data[5]*data[5]);
00649                   direction[0] = data[3]/momentum;
00650                   direction[1] = data[4]/momentum;
00651                   direction[2] = data[5]/momentum;
00652                   time = data[6]*ns;
00653                   trackID = (G4int)data[9];
00654                   parentID = (G4int)data[10];
00655                   if(nvar >= 12) weight = data[11];
00656                 }
00657                 break;
00658             case ASCII:
00659                 if(format == "BLTrackFile") {
00660                         do {
00661                                 int tmpID=0;
00662                                 if(trackFile->read(pos,time,direction,PDGid,
00663                                    tmpID,trackID,parentID,weight) != BLTF_OK)
00664                                         return false;
00665                                 if(renumber == 0) eventID = tmpID;
00666                         } while(renumber == 0 && eventID < firstEvent);
00667                         particleDefinition = G4ParticleTable::GetParticleTable()
00668                                                         ->FindParticle(PDGid);
00669                         if(!particleDefinition) {
00670                           printf("BLCMDbeam::nextBeamEvent Cannot find Particle"
00671                                 " with PDGencoding=%d\n",PDGid);
00672                           again = true;
00673                           continue;
00674                         }
00675                         mass = particleDefinition->GetPDGMass();
00676                         particleGun->SetParticleDefinition(particleDefinition);
00677                         momentum = sqrt(direction[0]*direction[0]+
00678                                         direction[1]*direction[1]+
00679                                         direction[2]*direction[2]);
00680                         direction[0] /= momentum;
00681                         direction[1] /= momentum;
00682                         direction[2] /= momentum;
00683                 }
00684                 break;
00685             case ELLIPSE:
00686                 setRandomSeedToGenerate(eventID);
00687                 // meanX=beamX, meanY=beamY (implicitly)
00688                 double a = 2.0*M_PI*G4UniformRand();
00689                 double b = 2.0*M_PI*G4UniformRand();
00690                 double c = 2.0*M_PI*G4UniformRand();
00691                 pos[0] = sigmaX*cos(a);
00692                 pos[1] = sigmaY*cos(b);
00693                 pos[2] = 0.0;
00694                 direction[0] = sigmaXp*sin(a);
00695                 direction[1] = sigmaYp*sin(b);
00696                 direction[2] = 1.0/sqrt(1.0 + direction[0]*direction[0] +
00697                                                 direction[1]*direction[1]);
00698                 direction[0] *= direction[2];
00699                 direction[1] *= direction[2];
00700                 double E = sqrt(meanMomentum*meanMomentum + mass*mass) +
00701                                                                 sigmaE*sin(c);
00702                 momentum = sqrt(E*E - mass*mass);
00703                 time = sigmaT*cos(c);
00704                 trackID = 1;
00705                 break;
00706             }
00707         } while(again || sqrt(pos[0]*pos[0]+pos[1]*pos[1]) > maxR);
00708 
00709         assert(trackID >= 0);
00710 
00711         if(eventID > lastEvent) return false;
00712 
00713         if(beamZ != UNDEFINED) pos[2] = 0.0;
00714 
00715         // apply rotation and offset
00716         if(rotationMatrix) {
00717                 direction = *rotationMatrix * direction;
00718                 pos = *rotationMatrix * pos;
00719         }
00720         pos += position;
00721 
00722         ke = sqrt(momentum*momentum + mass*mass) - mass;
00723         particleGun->SetParticleTime(time);
00724         particleGun->SetParticlePosition(pos);
00725         particleGun->SetParticleEnergy(ke);
00726         particleGun->SetParticleMomentumDirection(direction);
00727         particleGun->GeneratePrimaryVertex(event);
00728         event->SetEventID(eventID);
00729         event->GetPrimaryVertex()->SetWeight(weight);
00730         if(eventID != prevEventID) {
00731                 setRandomSeedToTrack(eventID);
00732                 manager->clearTrackIDMap();
00733                 manager->setNextSecondaryTrackID(secondaryTrackID);
00734                 prevEventID = eventID;
00735         }
00736         manager->setPrimaryTrackID(trackID,parentID);
00737         if(trackID >= secondaryTrackID) {
00738                 G4Exception("beam command","Large Primary TrackID",JustWarning,
00739                         "Confusion with secondary tracks is likely");
00740         }
00741         return true;
00742 }

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

summary() will print a summary, if necessary.

Reimplemented from BLBeam.

00131 { }


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::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::category [private]

G4int BLCMDbeam::uid [private]

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