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 BLCMDreference * | lastGen = 0 |
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().
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 rotationMatrix = 0; 00138 particleDefinition = 0; 00139 particleGun = 0; 00140 state = INIT; 00141 count = 0; 00142 }
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.
00144 : BLBeam(), BLCommand(), 00145 BLManager::TrackingAction(r), 00146 BLManager::ZSteppingAction(r), 00147 BLManager::RunAction(r), 00148 particle(), rotation(), position(), saveTrack() 00149 { 00150 particle = r.particle; 00151 referenceMomentum = r.referenceMomentum; 00152 beamX = r.beamX; 00153 beamY = r.beamY; 00154 beamZ = r.beamZ; 00155 beamT = r.beamT; 00156 beamXp = r.beamXp; 00157 beamYp = r.beamYp; 00158 tuneZ = r.tuneZ; 00159 tuneMomentum = r.tuneMomentum; 00160 tolerance = r.tolerance; 00161 rotationMatrix = 0; 00162 particleDefinition = 0; 00163 particleGun = 0; 00164 state = INIT; 00165 count = 0; 00166 }
virtual G4String BLCMDreference::commandName | ( | ) | [inline, virtual] |
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.
00169 { 00170 BLCMDreference *b = new BLCMDreference(*this); 00171 00172 b->rotation = ""; 00173 int retval = b->handleNamedArgs(namedArgs); 00174 00175 if(b->referenceMomentum == UNDEFINED) 00176 printError("reference: error - need referenceMomentum"); 00177 00178 if(b->rotation != "") { 00179 b->rotationMatrix = stringToRotationMatrix(b->rotation); 00180 } else { 00181 b->rotationMatrix = new G4RotationMatrix(); 00182 } 00183 // as usual, the order seems backward because (C R C^-1) C = C R. 00184 *b->rotationMatrix = *BLCoordinates::getCurrentRotation() * 00185 *b->rotationMatrix; 00186 G4ThreeVector local(b->beamX,b->beamY,b->beamZ); 00187 BLCoordinates::getCurrentGlobal(local,b->position); 00188 00189 // ensure beam is within the world 00190 BLGroup::getWorld()->setMinWidth(fabs(b->position[0])*2.0); 00191 BLGroup::getWorld()->setMinHeight(fabs(b->position[1])*2.0); 00192 BLGroup::getWorld()->setMinLength(fabs(b->position[2])*2.0); 00193 00194 BLManager::getObject()->registerReference(b); 00195 00196 // setup for tuning 00197 if(b->tuneZ != UNDEFINED && b->tuneMomentum != UNDEFINED) { 00198 BLManager::getObject()->registerTrackingAction(b); 00199 BLManager::getObject()->registerZStep(b->tuneZ,b,1); 00200 BLManager::getObject()->registerRunAction(b,false); 00201 } 00202 00203 b->print(""); 00204 00205 return retval; 00206 }
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.
00209 { 00210 argString(particle,"particle","Reference particle name"); 00211 argDouble(beamX,"beamX","Reference location in X (mm)"); 00212 argDouble(beamY,"beamY","Reference location in Y (mm)"); 00213 argDouble(beamZ,"beamZ","Reference location in Z (mm)"); 00214 argDouble(beamT,"beamT","Reference time (ns)"); 00215 argString(rotation,"rotation","Rotation of the beam"); 00216 argDouble(referenceMomentum,"referenceMomentum", 00217 "Reference particle momentum (MeV/c)",MeV); 00218 argDouble(beamXp,"beamXp","Reference particle Xp (radians)"); 00219 argDouble(beamYp,"beamYp","Reference particle Yp (radians)"); 00220 argDouble(referenceMomentum,"meanMomentum", 00221 "Synonymn for referenceMomentum",MeV); 00222 argDouble(beamXp,"meanXp","Synonym for beamXp."); 00223 argDouble(beamYp,"meanYp","Synonym for beamYp."); 00224 argDouble(tuneZ,"tuneZ","Z position for momentum tuning."); 00225 argDouble(tuneMomentum,"tuneMomentum","Desired momentum for momentum tuning."); 00226 argDouble(tolerance,"tolerance","tolerance for momentum tuning (0.001 MeV/c).",MeV); 00227 }
virtual int BLCMDreference::getNEvents | ( | ) | const [inline, virtual] |
getNEvents() returns the # events to process.
Reimplemented from BLBeam.
References BLBeam::nEvents.
00084 { return nEvents; }
void BLCMDreference::init | ( | ) | [virtual] |
init() will initialize internal variables.
Implements BLBeam.
References particle, particleDefinition, and particleGun.
00230 { 00231 if(particleDefinition != 0) return; 00232 00233 particleDefinition = G4ParticleTable::GetParticleTable()->FindParticle(particle); 00234 if(!particleDefinition) 00235 G4Exception("reference command","UnknownParticle", 00236 FatalException, "Unknown particle type"); 00237 particleGun = new G4ParticleGun(1); 00238 particleGun->SetParticleDefinition(particleDefinition); 00239 }
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().
00242 { 00243 G4double mass = particleDefinition->GetPDGMass(); 00244 G4double ke = sqrt(referenceMomentum*referenceMomentum + mass*mass) 00245 - mass; 00246 G4ThreeVector dir; 00247 dir[0] = beamXp; 00248 dir[1] = beamYp; 00249 dir[2] = 1.0/sqrt(1.0 + dir[0]*dir[0] + dir[1]*dir[1]); 00250 dir[0] *= dir[2]; 00251 dir[1] *= dir[2]; 00252 if(rotationMatrix) 00253 dir = *rotationMatrix * dir; 00254 00255 particleGun->SetParticleTime(beamT); 00256 particleGun->SetParticleEnergy(ke); 00257 particleGun->SetParticleMomentumDirection(dir); 00258 particleGun->SetParticlePosition(position); 00259 particleGun->GeneratePrimaryVertex(event); 00260 setRandomSeedToTrack(-1); 00261 lastGen = this; 00262 00263 BLManager::getObject()->setPrimaryTrackID(1,0); 00264 BLManager::getObject()->clearTrackIDMap(); 00265 BLManager::getObject()->setNextSecondaryTrackID(1000); 00266 00267 return true; 00268 }
bool BLCMDreference::nextBeamEvent | ( | G4Event * | event | ) | [virtual] |
virtual void BLCMDreference::summary | ( | ) | [inline, virtual] |
void BLCMDreference::PreUserTrackingAction | ( | const G4Track * | track | ) | [virtual] |
Implements BLManager::TrackingAction.
References count, INIT, lastGen, referenceMomentum, saveTrack, state, and TUNING.
00276 { 00277 if(state == INIT && lastGen == this) { 00278 saveTrack.CopyTrackInfo(*track); 00279 saveTrack.SetUserInformation(0); 00280 state = TUNING; 00281 count = 0; 00282 printf("reference: tune begun referenceMomentum=%.4f\n", 00283 referenceMomentum); 00284 } 00285 }
void BLCMDreference::PostUserTrackingAction | ( | const G4Track * | track | ) | [virtual] |
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.
00292 { 00293 if(state != TUNING) return; 00294 if(++count > MAX_COUNT) 00295 G4Exception("reference","Tuning Iteration Limit", 00296 FatalException,""); 00297 00298 G4double ke = track->GetKineticEnergy(); 00299 G4double mass = particleDefinition->GetPDGMass(); 00300 G4double ptot = sqrt((ke+mass)*(ke+mass) - mass*mass); 00301 G4double want = sqrt(tuneMomentum*tuneMomentum+mass*mass) - mass; 00302 printf("reference: tune step %d got momentum=%.6f (K.E.=%.6f)\n", 00303 count,ptot,ke); 00304 if(fabs(ke-want) < tolerance) { 00305 state = DONE; 00306 G4double e = saveTrack.GetKineticEnergy() + mass; 00307 referenceMomentum = sqrt(e*e-mass*mass); 00308 printf("reference: tune Complete new referenceMomentum=%.4f\n", 00309 referenceMomentum); 00310 goto quit; 00311 } 00312 saveTrack.SetKineticEnergy(saveTrack.GetKineticEnergy()+(want-ke)); 00313 // restore saveTrack and kill the current track 00314 BLManager::getObject()->getSteppingManager()->GetSecondary()-> 00315 push_back(new G4Track(saveTrack)); 00316 ((G4Track *)track)->SetTrackStatus(fStopAndKill); 00317 00318 quit: ; 00319 }
void BLCMDreference::BeginOfRunAction | ( | const G4Run * | run | ) | [inline, virtual] |
void BLCMDreference::EndOfRunAction | ( | const G4Run * | run | ) | [virtual] |
Implements BLManager::RunAction.
00322 { 00323 if(state != DONE) 00324 G4Exception("reference","Tuning failed to converge", 00325 FatalException,""); 00326 }
G4String BLCMDreference::particle [private] |
Referenced by BLCMDreference(), defineNamedArgs(), and init().
G4double BLCMDreference::referenceMomentum [private] |
Referenced by BLCMDreference(), command(), defineNamedArgs(), generateReferenceParticle(), PreUserTrackingAction(), and UserZSteppingAction().
G4double BLCMDreference::beamX [private] |
Referenced by BLCMDreference(), command(), and defineNamedArgs().
G4double BLCMDreference::beamY [private] |
Referenced by BLCMDreference(), command(), and defineNamedArgs().
G4double BLCMDreference::beamZ [private] |
Referenced by BLCMDreference(), command(), and defineNamedArgs().
G4double BLCMDreference::beamT [private] |
Referenced by BLCMDreference(), defineNamedArgs(), and generateReferenceParticle().
G4double BLCMDreference::beamXp [private] |
Referenced by BLCMDreference(), defineNamedArgs(), and generateReferenceParticle().
G4double BLCMDreference::beamYp [private] |
Referenced by BLCMDreference(), defineNamedArgs(), and generateReferenceParticle().
G4String BLCMDreference::rotation [private] |
Referenced by command(), and defineNamedArgs().
G4double BLCMDreference::tuneZ [private] |
Referenced by BLCMDreference(), command(), and defineNamedArgs().
G4double BLCMDreference::tuneMomentum [private] |
Referenced by BLCMDreference(), command(), defineNamedArgs(), and UserZSteppingAction().
G4double BLCMDreference::tolerance [private] |
Referenced by BLCMDreference(), defineNamedArgs(), and UserZSteppingAction().
G4RotationMatrix* BLCMDreference::rotationMatrix [private] |
Referenced by BLCMDreference(), command(), and generateReferenceParticle().
G4ThreeVector BLCMDreference::position [private] |
Referenced by command(), and generateReferenceParticle().
G4ParticleGun* BLCMDreference::particleGun [private] |
Referenced by BLCMDreference(), generateReferenceParticle(), and init().
G4ParticleDefinition* BLCMDreference::particleDefinition [private] |
Referenced by BLCMDreference(), generateReferenceParticle(), init(), and UserZSteppingAction().
G4Track BLCMDreference::saveTrack [private] |
Referenced by PreUserTrackingAction(), and UserZSteppingAction().
State BLCMDreference::state [private] |
Referenced by BLCMDreference(), EndOfRunAction(), PreUserTrackingAction(), and UserZSteppingAction().
G4int BLCMDreference::count [private] |
Referenced by BLCMDreference(), PreUserTrackingAction(), and UserZSteppingAction().
BLCMDreference * BLCMDreference::lastGen = 0 [static, private] |
Referenced by generateReferenceParticle(), and PreUserTrackingAction().