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
G4int trackID
G4RotationMatrix * rotationMatrix
G4ThreeVector position
G4ParticleGun * particleGun
G4ParticleDefinition * particleDefinition
G4Track saveTrack
State state
G4int count

Static Private Attributes

static BLCMDreferencelastGen = 0
static int referenceID = 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, trackID, tuneMomentum, tuneZ, and UNDEFINED.

Referenced by command().

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

BLCMDreference::BLCMDreference ( BLCMDreference r  ) 

copy constructor

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

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


Member Function Documentation

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

commandName() returns "reference".

Implements BLCommand.

00074 { 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(), referenceID, referenceMomentum, BLManager::registerReference(), BLManager::registerRunAction(), BLManager::registerTrackingAction(), BLManager::registerZStep(), rotation, rotationMatrix, BLGroup::setMinHeight(), BLGroup::setMinLength(), BLGroup::setMinWidth(), BLCommand::stringToRotationMatrix(), trackID, tuneMomentum, tuneZ, and UNDEFINED.

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

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.

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

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

getNEvents() returns the # events to process.

Reimplemented from BLBeam.

References BLBeam::nEvents.

00083 { return nEvents; }

void BLCMDreference::init (  )  [virtual]

init() will initialize internal variables.

Implements BLBeam.

References particle, particleDefinition, and particleGun.

00243 {
00244         if(particleDefinition != 0) return;
00245 
00246         particleDefinition = G4ParticleTable::GetParticleTable()->FindParticle(particle);
00247         if(!particleDefinition)
00248                 G4Exception("reference command","UnknownParticle",
00249                                 FatalException, "Unknown particle type");
00250         particleGun = new G4ParticleGun(1);
00251         particleGun->SetParticleDefinition(particleDefinition);
00252 }

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(), BLBeam::setRandomSeedToTrack(), and trackID.

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

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

nextBeamEvent() generates the next beam event.

Implements BLBeam.

00284 {
00285         return false;
00286 }

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

summary() will print a summary, if necessary.

Reimplemented from BLBeam.

00095 { }

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

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

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

Implements BLManager::TrackingAction.

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

00315 {
00316         BLManagerState mgrState = BLManager::getObject()->getState();
00317         if((mgrState == TUNE || mgrState == REFERENCE) && lastGen == this) {
00318                 BLGlobalField::getObject()->zeroEfield(false);
00319                 BLManager::getObject()->getPhysics()->
00320                                                 setProcessEnable("Ioni",true);
00321         }
00322 }

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.

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

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

Implements BLManager::RunAction.

00101 { }

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

Implements BLManager::RunAction.

References DONE, lastGen, and state.

00355 {
00356         if(state != DONE)
00357                 G4Exception("reference","Tuning failed to converge",
00358                                                         FatalException,"");
00359 
00360         lastGen = 0;
00361 }


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]

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

int BLCMDreference::referenceID = 0 [static, private]

Referenced by command().


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