BLCMDreference Class Reference

Inheritance diagram for BLCMDreference:

BLBeam BLCommand BLManager::TrackingAction BLManager::ZSteppingAction BLManager::RunAction

List of all members.


Detailed Description

class BLCMDreference implements the reference command to track the tune and reference particles.

Public Member Functions

 BLCMDreference ()
 Constructor.
 BLCMDreference (BLCMDreference &r)
 copy constructor
virtual G4String commandName ()
 commandName() returns "reference".
virtual int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
 command() implements the reference command.
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.
void PreUserTrackingAction (const G4Track *track)
void PostUserTrackingAction (const G4Track *track)
void UserZSteppingAction (const G4Track *track)
void BeginOfRunAction (const G4Run *run)
void EndOfRunAction (const G4Run *run)

Private Attributes

G4String particle
G4double referenceMomentum
G4double beamX
G4double beamY
G4double beamZ
G4double beamT
G4double beamXp
G4double beamYp
G4String rotation
G4double tuneZ
G4double tuneMomentum
G4double tolerance
G4RotationMatrix * rotationMatrix
G4ThreeVector position
G4ParticleGun * particleGun
G4ParticleDefinition * particleDefinition
G4Track saveTrack
State state
G4int count

Static Private Attributes

static BLCMDreferencelastGen = 0

Constructor & Destructor Documentation

BLCMDreference::BLCMDreference (  ) 

Constructor.

References beamT, beamX, beamXp, beamY, beamYp, beamZ, BLCMDTYPE_BEAM, count, INIT, particle, particleDefinition, particleGun, referenceMomentum, BLCommand::registerCommand(), rotationMatrix, BLCommand::setDescription(), BLCommand::setSynopsis(), state, tolerance, tuneMomentum, tuneZ, and UNDEFINED.

Referenced by command().

00103                                : BLBeam(), BLCommand(),
00104                         BLManager::TrackingAction(),
00105                         BLManager::ZSteppingAction(),
00106                         BLManager::RunAction(),
00107                         particle(), rotation(), position(), saveTrack()
00108 {
00109         registerCommand(BLCMDTYPE_BEAM);
00110         setSynopsis("Define a reference particle.");
00111         setDescription("The reference particle is nominally headed in the +Z direction.\n"
00112                 "Multiple reference particles can be defined, at different\n"
00113                 "positions, momenta, particle types, etc.\n"
00114                 "All coordinates are centerline coordinates.\n\n"
00115                 "If desired, the referenceMomentum will be tuned to a specific "
00116                 "value at a later z position in the beamline by giving values "
00117                 "for tuneZ, and tuneMomentum; tolerance can be set if desired. "
00118                 "\n\nNormally used in conjunction with a 'beam' command.");
00119         // initial default values:
00120         particle = "mu+";
00121         referenceMomentum = UNDEFINED;
00122         beamX = 0.0;
00123         beamY = 0.0;
00124         beamZ = 0.0;
00125         beamT = 0.0;
00126         beamXp = 0.0;
00127         beamYp = 0.0;
00128         tuneZ = UNDEFINED;
00129         tuneMomentum = UNDEFINED;
00130         tolerance = 0.001*MeV;
00131         rotationMatrix = 0;
00132         particleDefinition = 0;
00133         particleGun = 0;
00134         state = INIT;
00135         count = 0;
00136 }

BLCMDreference::BLCMDreference ( BLCMDreference r  ) 

copy constructor

References beamT, beamX, beamXp, beamY, beamYp, beamZ, count, INIT, particle, particleDefinition, particleGun, referenceMomentum, rotationMatrix, state, tolerance, tuneMomentum, and tuneZ.

00138                                                 : BLBeam(), BLCommand(),
00139                         BLManager::TrackingAction(r),
00140                         BLManager::ZSteppingAction(r),
00141                         BLManager::RunAction(r),
00142                         particle(), rotation(), position(), saveTrack()
00143 {
00144         particle = r.particle;
00145         referenceMomentum = r.referenceMomentum;
00146         beamX = r.beamX;
00147         beamY = r.beamY;
00148         beamZ = r.beamZ;
00149         beamT = r.beamT;
00150         beamXp = r.beamXp;
00151         beamYp = r.beamYp;
00152         tuneZ = r.tuneZ;
00153         tuneMomentum = r.tuneMomentum;
00154         tolerance = r.tolerance;
00155         rotationMatrix = 0;
00156         particleDefinition = 0;
00157         particleGun = 0;
00158         state = INIT;
00159         count = 0;
00160 }


Member Function Documentation

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

commandName() returns "reference".

Implements BLCommand.

00069 { return "reference"; }

int BLCMDreference::command ( BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

command() implements the reference command.

Implements BLCommand.

References beamX, beamY, beamZ, BLCMDreference(), BLCoordinates::getCurrentGlobal(), BLCoordinates::getCurrentRotation(), BLManager::getObject(), BLGroup::getWorld(), BLCommand::handleNamedArgs(), position, BLCommand::print(), BLCommand::printError(), referenceMomentum, BLManager::registerReference(), BLManager::registerRunAction(), BLManager::registerTrackingAction(), BLManager::registerZStep(), rotation, rotationMatrix, BLGroup::setMinHeight(), BLGroup::setMinLength(), BLGroup::setMinWidth(), BLCommand::stringToRotationMatrix(), tuneMomentum, tuneZ, and UNDEFINED.

00163 {
00164         BLCMDreference *b = new BLCMDreference(*this);
00165 
00166         b->rotation = "";
00167         int retval = b->handleNamedArgs(namedArgs);
00168 
00169         if(b->referenceMomentum == UNDEFINED)
00170                 printError("reference: error - need referenceMomentum");
00171 
00172         if(b->rotation != "") {
00173                 b->rotationMatrix = stringToRotationMatrix(b->rotation);
00174         } else {
00175                 b->rotationMatrix = new G4RotationMatrix();
00176         }
00177         // as usual, the order seems backward because (C R C^-1) C = C R.
00178         *b->rotationMatrix = *BLCoordinates::getCurrentRotation() * 
00179                                                         *b->rotationMatrix;
00180         G4ThreeVector local(b->beamX,b->beamY,b->beamZ);
00181         BLCoordinates::getCurrentGlobal(local,b->position);
00182 
00183         // ensure beam is within the world
00184         BLGroup::getWorld()->setMinWidth(fabs(b->position[0])*2.0);
00185         BLGroup::getWorld()->setMinHeight(fabs(b->position[1])*2.0);
00186         BLGroup::getWorld()->setMinLength(fabs(b->position[2])*2.0);
00187 
00188         BLManager::getObject()->registerReference(b);
00189 
00190         // setup for tuning
00191         if(b->tuneZ != UNDEFINED && b->tuneMomentum != UNDEFINED) {
00192                 BLManager::getObject()->registerTrackingAction(b);
00193                 BLManager::getObject()->registerZStep(b->tuneZ,b,1);
00194                 BLManager::getObject()->registerRunAction(b,false);
00195         }
00196 
00197         b->print("");
00198 
00199         return retval;
00200 }

void BLCMDreference::defineNamedArgs (  )  [virtual]

defineNamedArgs() defines the named arguments for this command.

Reimplemented from BLCommand.

References BLCommand::argDouble(), BLCommand::argString(), beamT, beamX, beamXp, beamY, beamYp, beamZ, particle, referenceMomentum, rotation, tolerance, tuneMomentum, and tuneZ.

00203 {
00204         argString(particle,"particle","Reference particle name");
00205         argDouble(beamX,"beamX","Reference location in X (mm)");
00206         argDouble(beamY,"beamY","Reference location in Y (mm)");
00207         argDouble(beamZ,"beamZ","Reference location in Z (mm)");
00208         argDouble(beamT,"beamT","Reference time (ns)");
00209         argString(rotation,"rotation","Rotation of the beam");
00210         argDouble(referenceMomentum,"referenceMomentum",
00211                                 "Reference particle momentum (MeV/c)",MeV);
00212         argDouble(beamXp,"beamXp","Reference particle Xp (radians)");
00213         argDouble(beamYp,"beamYp","Reference particle Yp (radians)");
00214         argDouble(referenceMomentum,"meanMomentum", 
00215                                 "Synonymn for referenceMomentum",MeV);
00216         argDouble(beamXp,"meanXp","Synonym for beamXp.");
00217         argDouble(beamYp,"meanYp","Synonym for beamYp.");
00218         argDouble(tuneZ,"tuneZ","Z position for momentum tuning.");
00219         argDouble(tuneMomentum,"tuneMomentum","Desired momentum for momentum tuning.");
00220         argDouble(tolerance,"tolerance","tolerance for momentum tuning (0.001 MeV/c).",MeV);
00221 }

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

getNEvents() returns the # events to process.

Reimplemented from BLBeam.

References BLBeam::nEvents.

00078 { return nEvents; }

void BLCMDreference::init (  )  [virtual]

init() will initialize internal variables.

Implements BLBeam.

References particle, particleDefinition, and particleGun.

00224 {
00225         if(particleDefinition != 0) return;
00226 
00227         particleDefinition = G4ParticleTable::GetParticleTable()->FindParticle(particle);
00228         if(!particleDefinition)
00229                 G4Exception("reference command","UnknownParticle",
00230                                 FatalException, "Unknown particle type");
00231         particleGun = new G4ParticleGun(1);
00232         particleGun->SetParticleDefinition(particleDefinition);
00233 }

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

generateReferenceParticle() generates the reference particle.

Implements BLBeam.

References beamT, beamXp, beamYp, BLManager::clearTrackIDMap(), BLManager::getObject(), lastGen, particleDefinition, particleGun, position, referenceMomentum, rotationMatrix, BLManager::setNextSecondaryTrackID(), BLManager::setPrimaryTrackID(), and BLBeam::setRandomSeedToTrack().

00236 {
00237         G4double mass = particleDefinition->GetPDGMass();
00238         G4double ke = sqrt(referenceMomentum*referenceMomentum + mass*mass)
00239                                                                 - mass;
00240         G4ThreeVector dir;
00241         dir[0] = beamXp;
00242         dir[1] = beamYp;
00243         dir[2] = 1.0/sqrt(1.0 + dir[0]*dir[0] + dir[1]*dir[1]);
00244         dir[0] *= dir[2];
00245         dir[1] *= dir[2];
00246         if(rotationMatrix)
00247                 dir = *rotationMatrix * dir;
00248 
00249         particleGun->SetParticleTime(beamT);
00250         particleGun->SetParticleEnergy(ke);
00251         particleGun->SetParticleMomentumDirection(dir);
00252         particleGun->SetParticlePosition(position);
00253         particleGun->GeneratePrimaryVertex(event);
00254         setRandomSeedToTrack(-1);
00255         lastGen = this;
00256 
00257         BLManager::getObject()->setPrimaryTrackID(1,0);
00258         BLManager::getObject()->clearTrackIDMap();
00259         BLManager::getObject()->setNextSecondaryTrackID(1000);
00260 
00261         return true;
00262 }

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

nextBeamEvent() generates the next beam event.

Implements BLBeam.

00265 {
00266         return false;
00267 }

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

summary() will print a summary, if necessary.

Reimplemented from BLBeam.

00090 { }

void BLCMDreference::PreUserTrackingAction ( const G4Track *  track  )  [virtual]

Implements BLManager::TrackingAction.

References count, INIT, lastGen, referenceMomentum, saveTrack, state, and TUNING.

00270 {
00271         if(state == INIT && lastGen == this) {
00272                 saveTrack.CopyTrackInfo(*track);
00273                 saveTrack.SetUserInformation(0);
00274                 state = TUNING;
00275                 count = 0;
00276                 printf("reference: tune begun  referenceMomentum=%.4f\n",
00277                                         referenceMomentum);
00278         }
00279 }

void BLCMDreference::PostUserTrackingAction ( const G4Track *  track  )  [virtual]

Implements BLManager::TrackingAction.

00282 {
00283 }

void BLCMDreference::UserZSteppingAction ( const G4Track *  track  )  [virtual]

Implements BLManager::ZSteppingAction.

References count, DONE, BLManager::getObject(), BLManager::getSteppingManager(), MAX_COUNT, particleDefinition, referenceMomentum, saveTrack, state, tolerance, tuneMomentum, and TUNING.

00286 {
00287         if(state != TUNING) return;
00288         if(++count > MAX_COUNT)
00289                 G4Exception("reference","Tuning Iteration Limit",
00290                                                         FatalException,"");
00291 
00292         G4double ke = track->GetKineticEnergy();
00293         G4double mass = particleDefinition->GetPDGMass();
00294         G4double ptot = sqrt((ke+mass)*(ke+mass) - mass*mass);
00295         G4double want = sqrt(tuneMomentum*tuneMomentum+mass*mass) - mass;
00296         printf("reference: tune step %d  got momentum=%.6f (K.E.=%.6f)\n",
00297                                                         count,ptot,ke);
00298         if(fabs(ke-want) < tolerance) {
00299                 state = DONE;
00300                 G4double e = saveTrack.GetKineticEnergy() + mass;
00301                 referenceMomentum = sqrt(e*e-mass*mass);
00302                 printf("reference: tune Complete   new referenceMomentum=%.4f\n",
00303                                         referenceMomentum);
00304                 goto quit;
00305         }
00306         saveTrack.SetKineticEnergy(saveTrack.GetKineticEnergy()+(want-ke));
00307         // restore saveTrack and kill the current track
00308         BLManager::getObject()->getSteppingManager()->GetSecondary()->
00309                                         push_back(new G4Track(saveTrack));
00310         ((G4Track *)track)->SetTrackStatus(fStopAndKill);
00311 
00312 quit:   ;
00313 }

void BLCMDreference::BeginOfRunAction ( const G4Run *  run  )  [inline, virtual]

Implements BLManager::RunAction.

00096 { }

void BLCMDreference::EndOfRunAction ( const G4Run *  run  )  [virtual]

Implements BLManager::RunAction.

References DONE, and state.

00316 {
00317         if(state != DONE)
00318                 G4Exception("reference","Tuning failed to converge",
00319                                                         FatalException,"");
00320 }


Member Data Documentation

G4String BLCMDreference::particle [private]

G4double BLCMDreference::beamX [private]

G4double BLCMDreference::beamY [private]

G4double BLCMDreference::beamZ [private]

G4double BLCMDreference::beamT [private]

G4double BLCMDreference::beamXp [private]

G4double BLCMDreference::beamYp [private]

G4String BLCMDreference::rotation [private]

Referenced by command(), and defineNamedArgs().

G4double BLCMDreference::tuneZ [private]

G4double BLCMDreference::tuneMomentum [private]

G4double BLCMDreference::tolerance [private]

G4RotationMatrix* BLCMDreference::rotationMatrix [private]

G4ThreeVector BLCMDreference::position [private]

G4ParticleGun* BLCMDreference::particleGun [private]

G4ParticleDefinition* BLCMDreference::particleDefinition [private]

G4Track BLCMDreference::saveTrack [private]

G4int BLCMDreference::count [private]

BLCMDreference * BLCMDreference::lastGen = 0 [static, private]


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