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
G4int noEfield
G4int noEloss
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, noEfield, noEloss, particle, particleDefinition, particleGun, referenceMomentum, BLCommand::registerCommand(), rotationMatrix, BLCommand::setDescription(), BLCommand::setSynopsis(), state, tolerance, tuneMomentum, tuneZ, and UNDEFINED.

Referenced by command().

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

BLCMDreference::BLCMDreference ( BLCMDreference r  ) 

copy constructor

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

00143                                                 : BLBeam(), BLCommand(),
00144                         BLManager::TrackingAction(r),
00145                         BLManager::ZSteppingAction(r),
00146                         BLManager::RunAction(r),
00147                         particle(), rotation(), position(), saveTrack()
00148 {
00149         particle = r.particle;
00150         referenceMomentum = r.referenceMomentum;
00151         beamX = r.beamX;
00152         beamY = r.beamY;
00153         beamZ = r.beamZ;
00154         beamT = r.beamT;
00155         beamXp = r.beamXp;
00156         beamYp = r.beamYp;
00157         tuneZ = r.tuneZ;
00158         tuneMomentum = r.tuneMomentum;
00159         tolerance = r.tolerance;
00160         noEfield = r.noEfield;
00161         noEloss = r.noEloss;
00162         rotationMatrix = 0;
00163         particleDefinition = 0;
00164         particleGun = 0;
00165         state = INIT;
00166         count = 0;
00167 }


Member Function Documentation

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

commandName() returns "reference".

Implements BLCommand.

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

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

void BLCMDreference::defineNamedArgs (  )  [virtual]

defineNamedArgs() defines the named arguments for this command.

Reimplemented from BLCommand.

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

00211 {
00212         argString(particle,"particle","Reference particle name");
00213         argDouble(beamX,"beamX","Reference location in X (mm)");
00214         argDouble(beamY,"beamY","Reference location in Y (mm)");
00215         argDouble(beamZ,"beamZ","Reference location in Z (mm)");
00216         argDouble(beamT,"beamT","Reference time (ns)");
00217         argString(rotation,"rotation","Rotation of the beam");
00218         argDouble(referenceMomentum,"referenceMomentum",
00219                                 "Reference particle momentum (MeV/c)",MeV);
00220         argDouble(beamXp,"beamXp","Reference particle Xp (radians)");
00221         argDouble(beamYp,"beamYp","Reference particle Yp (radians)");
00222         argDouble(referenceMomentum,"meanMomentum", 
00223                                 "Synonymn for referenceMomentum",MeV);
00224         argDouble(beamXp,"meanXp","Synonym for beamXp.");
00225         argDouble(beamYp,"meanYp","Synonym for beamYp.");
00226         argDouble(tuneZ,"tuneZ","Z position for momentum tuning.");
00227         argDouble(tuneMomentum,"tuneMomentum","Desired momentum for momentum tuning.");
00228         argDouble(tolerance,"tolerance","tolerance for momentum tuning (0.001 MeV/c).",MeV);
00229         argInt(noEfield,"noEfield","Set nonzero to make this Tune and Reference"
00230             " particle not respond to E fields (ICOOL style)");
00231         argInt(noEloss,"noEloss","Set nonzero to make this Tune and Reference"
00232             " particle not respond to ionization energy loss (ICOOL style)");
00233 }

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

getNEvents() returns the # events to process.

Reimplemented from BLBeam.

References BLBeam::nEvents.

00081 { return nEvents; }

void BLCMDreference::init (  )  [virtual]

init() will initialize internal variables.

Implements BLBeam.

References particle, particleDefinition, and particleGun.

00236 {
00237         if(particleDefinition != 0) return;
00238 
00239         particleDefinition = G4ParticleTable::GetParticleTable()->FindParticle(particle);
00240         if(!particleDefinition)
00241                 G4Exception("reference command","UnknownParticle",
00242                                 FatalException, "Unknown particle type");
00243         particleGun = new G4ParticleGun(1);
00244         particleGun->SetParticleDefinition(particleDefinition);
00245 }

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

00248 {
00249         G4double mass = particleDefinition->GetPDGMass();
00250         G4double ke = sqrt(referenceMomentum*referenceMomentum + mass*mass)
00251                                                                 - mass;
00252         G4ThreeVector dir;
00253         dir[0] = beamXp;
00254         dir[1] = beamYp;
00255         dir[2] = 1.0/sqrt(1.0 + dir[0]*dir[0] + dir[1]*dir[1]);
00256         dir[0] *= dir[2];
00257         dir[1] *= dir[2];
00258         if(rotationMatrix)
00259                 dir = *rotationMatrix * dir;
00260 
00261         particleGun->SetParticleTime(beamT);
00262         particleGun->SetParticleEnergy(ke);
00263         particleGun->SetParticleMomentumDirection(dir);
00264         particleGun->SetParticlePosition(position);
00265         particleGun->GeneratePrimaryVertex(event);
00266         setRandomSeedToTrack(-1);
00267         lastGen = this;
00268 
00269         BLManager::getObject()->setPrimaryTrackID(1,0);
00270         BLManager::getObject()->clearTrackIDMap();
00271         BLManager::getObject()->setNextSecondaryTrackID(1000);
00272 
00273         return true;
00274 }

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

nextBeamEvent() generates the next beam event.

Implements BLBeam.

00277 {
00278         return false;
00279 }

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

summary() will print a summary, if necessary.

Reimplemented from BLBeam.

00093 { }

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

Implements BLManager::TrackingAction.

References count, BLGlobalField::getObject(), BLManager::getObject(), BLManager::getPhysics(), BLManager::getState(), INIT, lastGen, noEfield, noEloss, REFERENCE, referenceMomentum, saveTrack, state, TUNE, tuneMomentum, tuneZ, TUNING, UNDEFINED, and BLGlobalField::zeroEfield().

00282 {
00283         if(state == INIT && lastGen == this && 
00284                         tuneZ != UNDEFINED && tuneMomentum != UNDEFINED) {
00285                 saveTrack.CopyTrackInfo(*track);
00286                 saveTrack.SetUserInformation(0);
00287                 state = TUNING;
00288                 count = 0;
00289                 printf("reference: tune begun  referenceMomentum=%.4f\n",
00290                                         referenceMomentum);
00291         }
00292 
00293         BLManagerState mgrState = BLManager::getObject()->getState();
00294         if(mgrState == TUNE || mgrState == REFERENCE) {
00295             if(noEfield != 0) {
00296                 BLGlobalField::getObject()->zeroEfield(true);
00297                 printf("***  Tune and Reference Particles ignore E fields.\n");
00298             }
00299             if(noEloss != 0) {
00300                 BLManager::getObject()->getPhysics()->
00301                                                 setProcessEnable("Ioni",false);
00302                 printf("***  Tune and Reference Particles ignore Energy loss.\n");
00303             }
00304         }
00305 }

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

Implements BLManager::TrackingAction.

References BLGlobalField::getObject(), BLManager::getObject(), BLManager::getPhysics(), BLManager::getState(), noEloss, REFERENCE, TUNE, and BLGlobalField::zeroEfield().

00308 {
00309         BLManagerState mgrState = BLManager::getObject()->getState();
00310         if(mgrState == TUNE || mgrState == REFERENCE) {
00311                 BLGlobalField::getObject()->zeroEfield(false);
00312                 if(noEloss != 0)
00313                         BLManager::getObject()->getPhysics()->
00314                                                 setProcessEnable("Ioni",true);
00315         }
00316 }

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.

00319 {
00320         if(state != TUNING) return;
00321         if(++count > MAX_COUNT)
00322                 G4Exception("reference","Tuning Iteration Limit",
00323                                                         FatalException,"");
00324 
00325         G4double ke = track->GetKineticEnergy();
00326         G4double mass = particleDefinition->GetPDGMass();
00327         G4double ptot = sqrt((ke+mass)*(ke+mass) - mass*mass);
00328         G4double want = sqrt(tuneMomentum*tuneMomentum+mass*mass) - mass;
00329         printf("reference: tune step %d  got momentum=%.6f (K.E.=%.6f)\n",
00330                                                         count,ptot,ke);
00331         if(fabs(ke-want) < tolerance) {
00332                 state = DONE;
00333                 G4double e = saveTrack.GetKineticEnergy() + mass;
00334                 referenceMomentum = sqrt(e*e-mass*mass);
00335                 printf("reference: tune Complete   new referenceMomentum=%.4f\n",
00336                                         referenceMomentum);
00337                 goto quit;
00338         }
00339         saveTrack.SetKineticEnergy(saveTrack.GetKineticEnergy()+(want-ke));
00340         // restore saveTrack and kill the current track
00341         BLManager::getObject()->getSteppingManager()->GetSecondary()->
00342                                         push_back(new G4Track(saveTrack));
00343         ((G4Track *)track)->SetTrackStatus(fStopAndKill);
00344 
00345 quit:   ;
00346 }

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

Implements BLManager::RunAction.

00099 { }

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

Implements BLManager::RunAction.

References DONE, and state.

00349 {
00350         if(state != DONE)
00351                 G4Exception("reference","Tuning failed to converge",
00352                                                         FatalException,"");
00353 }


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]

G4int BLCMDreference::noEfield [private]

G4int BLCMDreference::noEloss [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