BLManager Class Reference

#include <BLManager.hh>

List of all members.


Detailed Description

BLManager is the overall manager for g4beamline, managing all aspects of the run.

Note it is uses all the G4 user action classes, implemented as classes under BLManager.

TrackID-s: It is non-trivial to preserve TrackID-s from input files, because Geant4 considers TrackID to be an internal variable, and it assigns them in a non-customizable manner. So BLManager keeps a trackIDMap[] that converts from internal (Geant4) to external (User) TrackID-s. It also uses BLTrackInfo to associate the external IDs with the track -- the external trackID is determined either in BLBeam (when the track is created), or in BLManager::PreUserTrackingAction for secondaries.

Public Member Functions

void delayedConstruction ()
 delayedConstruction() performs things which must wait until all static initializers have executed (e.g. in Geant4 routines).
 ~BLManager ()
 Destructor.
BLManagerState getState ()
 getState() returns the current state.
void setState (BLManagerState _state)
 setState sets the state
int getSteppingVerbose ()
 getSteppingVerbose() returns steppingVerbose. NOTE: use this during tracking instead of Param.getInt("steppingVerbose");
void setSteppingVerbose (int v)
 setSteppingVerbose() updates steppingVerbose. -- NOTE: many other classes relay on the Parameter, not the valud in this class.
int getEventTimeLimit ()
 getEventTimeLimit() returns the CPU time limit for events (seconds). -1 mean infinite.
void setEventTimeLimit (int sec)
 setEventTimeLimit() sets the CPU time limit for events (seconds). -1 mean infinite.
G4int getEventID () const
 getEventID() gets the current eventID;
void setEventID (int evId)
 setEventID() sets the current eventID;
bool skipEvent (int EventID)
 skipEvent() will check the eventList vector (which comes from the eventCut file).
void incrEventsProcessed (int eventID)
 incrEventsProcessed() will increment eventsProcessed. For special uses only (e.g.MPI).
void registerSteppingAction (SteppingAction *sa)
 registerSteppingAction() registers a SteppingAction to be called for each step (regardless of state).
void registerSteppingAction (G4VPhysicalVolume *physicalVol, SteppingAction *sa)
 registerSteppingAction() registers a SteppingAction to be called for each step (regardless of state), for every step involving the physicalVol. The callback will be called if physicalVol is either the pre- or post-step physical volume (once if both). If physicalVol==0 it is called every reference particle step. LIMITATION: only one callback can be registered for a given physicalVol (except 0).
void registerTuneParticleStep (G4VPhysicalVolume *physicalVol, SteppingAction *sa)
 registerTuneParticleStep() registers a SteppingAction to be called for every tune particle step involving the physicalVol. The callback will be called if physicalVol is either the pre- or post-step physical volume (once if both). If physicalVol==0 it is called every tune particle step. LIMITATION: only one callback can be registered for a given physicalVol (except 0).
void registerReferenceParticleStep (G4VPhysicalVolume *physicalVol, SteppingAction *sa)
 registerReferenceParticleStep() registers a SteppingAction to be called for every reference particle step involving the physicalVol. The callback will be called if physicalVol is either the pre- or post-step physical volume (once if both). If physicalVol==0 it is called every reference particle step. LIMITATION: only one callback can be registered for a given physicalVol (except 0).
void registerBeamStep (G4VPhysicalVolume *physicalVol, SteppingAction *sa)
 registerBeamStep() registers a SteppingAction to be called for every beam step involving the physicalVol. (beam particles are everything except reference and tune.) The callback will be called if physicalVol is either the pre- or post-step physical volume (once if both). if physicalVol==0 it is called every beam step. LIMITATION: only one callback can be registered for a given physicalVol (except 0).
void registerZStep (G4double z, ZSteppingAction *sa, G4int when=7)
 registerZStep() will force a step to occur near the given z position, and will call the ZSteppingAction for it, interpolating to the desired z value (Centerline coords). when is a bitwise OR of 1=tune, 2=reference, 4=beam.
void registerStackingAction (StackingAction *sa)
 registerStackingAction() registers a StackingAction to be called by the Geant4 stacking manager.
void setSteppingFormat ()
 setSteppingFormat() sets the verbose printing format according to parameter "steppingFormat".
G4String getFormatHelp ()
 getFormatHelp() returns a string with help text about valid format items.
void appendVerboseFormat (G4String fmt)
 appendVerboseFormat() appends fmt to the format for printing when param steppingVerbose is nonzero
void steppingVerbosePrint (const G4Step *step, const G4Track *track, int header=0)
 steppingVerbosePrint() will print this step according to the current verboseFormat. Prints header if header != 0).
void setSteppingManager (G4SteppingManager *p)
 setSteppingManager() sets the pointer to the current G4SteppingManager.
G4SteppingManager * getSteppingManager ()
 getSteppingManager() returns a pointer to the current G4SteppingManager.
void setTrackingManager (G4TrackingManager *p)
 setTrackingManager() sets the pointer to the current G4TrackingManager.
void initialize ()
 initialize() will initialize the BLManager object, and the geant4 kernel, thus constructing the geometry in the world group. Note that registerPhysics() must be called before initialize() (normally done by a "physics" command in the input file).
void trackTuneAndReferenceParticles ()
 trackTuneAndReferenceParticles() will generate and track the tune particle and then the reference particle.
void trackBeam ()
 trackBeam() will generate the defined beam and track each event.
void displayVisual ()
 displayVisual() will display the detector visually.
void displayGeometry (G4VPhysicalVolume *phys=0, int level=0)
 displayGeometry() will display the geant4 geometry. This is a hierarchical ASCII listing of all volumes. if phys==0 then use the worldPhysicalVolume.
void registerPhysics (BLPhysics *_physics)
 registerPhysics() registers the BLPhysics object. It also sets the physics list to the BLRunManager, so following commands can find particle by name.
BLPhysicsgetPhysics ()
 getPhysics returns the registered BLPhysics object.
void registerBeam (BLBeam *_beam)
 registerBeam() registers a BLBeam object for beam generation. Multiple BLBeam objects can be registered, used in order.
void registerReference (BLBeam *_beam)
 registerReference() registers a BLBeam object for reference particle generation. Multiple BLBeam objects can be registered, used in order.
int nReference ()
 nReference() returns the number of reference particles registered.
void registerRunAction (RunAction *a, G4bool beamOnly=true)
 registerRunAction() registers a UserRunAction. If beamOnly is true (the default), the callback is made only if state==BEAM.
void registerEventAction (EventAction *a, G4bool beamOnly=true)
 registerEventAction() registers a UserEventAction. If beamOnly is true (the default), the callback is made only if state==BEAM.
void registerTrackingAction (TrackingAction *a)
 registerTrackingAction() registers a UserTackingAction.
void registerUserCode (BLUserCode *instance)
 registerUserCode() registers a BLUserCode instance.
std::vector< BLUserCode * > getUserCodeInstances (G4String type)
 getUserCodeInstances() returns a vector of all registered instances of BLUserCode with the specified type.
void registerCallback (BLCallback *cb, int type)
 registerCallback() registers a BLCallback. type=0 for pre-Tune particle, type=1 for post-Reference (pre-beam tracking), type=2 for post-beam tracking. type=3 for replacing the main program loop. type=4 for visualization. NOTE: if there are type=3 callbacks, when the last one returns the closes up by summarizing NTuples and callng handleCallbacks(2), and then the program exits. This prevents the main program loop from executing. type=3 callbacks are called just after the type=1 callbacks (i.e. after the post-Reference callbacks).
void handleCallbacks (int type)
 handleCallbacks() calls all applicable registered callbacks. type=0 for pre-reference particle, type=1 for post-center (pre-beam tracking), type=2 for post-beam tracking (just before program exit). type=3 for replacing the main program loop. type=4 for visualization.
G4VPhysicalVolume * getWorldPhysicalVolume ()
 getWorldPhysicalVolume() returns a pointer to the world PV. Note that it must already have been consructed, so this function returns NULL before construct() is called (by main).
void setPRNGSeedMethod (PRNGSeedMethod method)
 setPRNGSeedMethod() will set the method used to seed the pseudo random number generator at the start of each event.
PRNGSeedMethod getPRNGSeedMethod ()
 getPRNGSeedMethod() will return the method used to seed the pseudo random number generator at the start of each event.
void setEventCutFile (G4String &f)
 setEventCutFile() will set the file containing event s for cutting. The file is ASCII, with one event number per line; lines beginning with # are ignored.
void UserSteppingAction (const G4Step *step)
 UserSteppingAction() from G4UserSteppingAction.
G4VPhysicalVolume * Construct ()
 Construct() from G4VUserDetectorConstruction.
void PreUserTrackingAction (const G4Track *track)
 PreUserTrackingAction() from G4UserTrackingAction.
void PostUserTrackingAction (const G4Track *track)
 PostUserTrackingAction() from G4UserTrackingAction.
void BeginOfRunAction (const G4Run *run)
 BeginOfRunAction() from G4UserRunAction.
void EndOfRunAction (const G4Run *run)
 EndOfRunAction() from G4UserRunAction.
void BeginOfEventAction (const G4Event *event)
 BeginOfEventAction() from G4UserEventAction.
void EndOfEventAction (const G4Event *event)
 EndOfEventAction() from G4UserEventAction.
void GeneratePrimaries (G4Event *event)
 GeneratePrimaries() from G4VUserPrimaryGeneratorAction.
G4ClassificationOfNewTrack ClassifyNewTrack (const G4Track *)
 ClassifyNewTrack() from G4UserStackingAction.
void NewStage ()
 NewStage() from G4userStackingAction.
void PrepareNewEvent ()
 PrepareNewEvent() from G4StackingAction.
void clearTrackIDMap ()
 clearTrackIDMap() clears the TrackID map.
void setNextSecondaryTrackID (int next)
 setNextSecondaryTrackID() sets the external TrackID for the next secondary track. Automatically incremented for subsequent secondaries.
int getNextSecondaryTrackID ()
int getExternalTrackID (const G4Track *track)
 getExternalTrackID() returns the external TrackID for the given track. In collective mode, internal and external trackID-s are the same.
int getExternalParentID (const G4Track *track)
 getExternalParentID() returns the external ParentID for the given track. In collective mode, internal and external trackID-s are the same.
void setExternalTrackID (G4Track *track, int trackID, int parentID)
 setExternalTrackID() will set the external trackID and parentID. if trackID<0 uses nextSecondarTrackID++.
int getPrimaryTrackID ()
 getPrimaryTrackID() returns the primaryTrackID set by the beam command
int getPrimaryParentID ()
 getPrimaryParentID() returns the primaryParentID set by the beam command
void setPrimaryTrackID (int t, int p)
 setPrimaryTrackID() sets track and parent IDs for a primary track.
G4bool Notify (const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
 Notify() from G4VExceptionHandler.
void exceptionSummary ()
 exceptionSummary() prints a summary of all exceptions

Static Public Member Functions

static BLManagergetObject ()
 getObject() will return a pointer to the single BLManager object, creating it if necessary. Does only the immediate constructor, not delayedConstruction(). that means it is Ok to register capabilities, but not much else.
static bool isInitialized ()
 isInitialized() returns true if the BLManager has been initialized.

Private Member Functions

 BLManager ()
 private constructor -- immediate construction only.
void insertZStep (std::vector< ZStep > &vector, G4double z, ZSteppingAction *action)
void readEventCutFile ()

Private Attributes

BLRunManagerrunManager
BLManagerState state
G4int steppingVerbose
unsigned int beamIndex
G4int histoUpdate
time_t startRun
time_t startEvent
G4int eventTimeLimit
BLPhysicsphysics
G4VPhysicalVolume * worldPhysicalVolume
G4int eventID
G4int trackID
G4ParticleDefinition * trackParticleDef
G4int fatalExceptions
G4int eventsAborted
G4int tracksAborted
G4int warnings
G4int prevEventID
G4int eventsProcessed
bool endRun
PRNGSeedMethod seedMethod
G4String eventCutFile
std::set< int > eventList
G4SteppingManager * fpSteppingManager
G4TrackingManager * fpTrackingManager
std::vector< BLBeam * > beamVector
std::vector< BLBeam * > referenceVector
std::vector< RunAction * > runActionVector
std::vector< RunAction * > beamRunActionVector
std::vector< EventAction * > eventActionVector
std::vector< EventAction * > beamEventActionVector
std::vector< TrackingAction * > trackingActionVector
std::vector< BLCallback * > preReferenceCallbackVector
std::vector< BLCallback * > postReferenceCallbackVector
std::vector< BLCallback * > postTrackingCallbackVector
std::vector< BLCallback * > replaceMainLoopCallbackVector
std::vector< BLCallback * > visualizationCallbackVector
std::vector< SteppingAction * > allStepVector
std::map< G4VPhysicalVolume
*, SteppingAction * > 
allStepMap
std::map< G4VPhysicalVolume
*, SteppingAction * > 
tpStepMap
std::map< G4VPhysicalVolume
*, SteppingAction * > 
rpStepMap
std::vector< SteppingAction * > tpStepVector
std::vector< SteppingAction * > rpStepVector
std::map< G4VPhysicalVolume
*, SteppingAction * > 
beamStepMap
std::vector< SteppingAction * > beamStepVector
std::vector< int > verboseFormat
G4double zTolerance
std::vector< ZSteptuneZStep
std::vector< ZStepreferenceZStep
std::vector< ZStepbeamZStep
std::vector< ZStep > * currentZStep
unsigned indexZStep
G4double prevZ
G4int nStuck
std::vector< StackingAction * > stackingActionVector
int nextSecondaryTrackID
std::map< G4int, G4int > trackIDMap
int primaryTrackID
int primaryParentID
std::vector< BLUserCode * > userCodeVector
std::map< G4String, int > exceptionCount

Static Private Attributes

static BLManagerblManager = 0
static bool initialized = false

Classes

class  EventAction
class  PrimaryGeneratorAction
class  RunAction
class  StackingAction
class  SteppingAction
class  TrackingAction
struct  ZStep
class  ZSteppingAction


Constructor & Destructor Documentation

BLManager::BLManager (  )  [private]

private constructor -- immediate construction only.

References beamIndex, beamZStep, blManager, CL, currentZStep, endRun, EVENT_NUMBER, eventCutFile, eventID, eventsAborted, eventsProcessed, eventTimeLimit, fatalExceptions, BLParam::getDouble(), GLOBAL, histoUpdate, IDLE, indexZStep, BLAlarm::init(), KE, NEWLINE, nextSecondaryTrackID, NSTEP, nStuck, Param, physics, prevEventID, prevZ, primaryParentID, primaryTrackID, PROCESS, referenceZStep, runManager, seedMethod, startEvent, startRun, state, STEP, steppingVerbose, trackID, trackParticleDef, tracksAborted, tuneZStep, verboseFormat, VOL, warnings, worldPhysicalVolume, and zTolerance.

Referenced by getObject().

00198                      : G4VUserDetectorConstruction(), 
00199                 G4VExceptionHandler(), eventList(),
00200                 beamVector(), referenceVector(),
00201                 runActionVector(), beamRunActionVector(),
00202                 eventActionVector(), beamEventActionVector(),
00203                 trackingActionVector(), preReferenceCallbackVector(),
00204                 postReferenceCallbackVector(), postTrackingCallbackVector(),
00205                 replaceMainLoopCallbackVector(), visualizationCallbackVector(),
00206                 allStepVector(), allStepMap(), tpStepMap(), rpStepMap(),
00207                 tpStepVector(), rpStepVector(),
00208                 beamStepMap(), beamStepVector(), verboseFormat(),
00209                 tuneZStep(), referenceZStep(), beamZStep(), 
00210                 stackingActionVector(), trackIDMap(), userCodeVector(),
00211                 exceptionCount()
00212 {
00213         // Parameter definitions (variables are all unused):
00214         BLSetParam unused_1("histoFile","g4beamline",
00215                                 "Default (Root) NTuple output filename");
00216         BLSetParam unused_2("histoUpdate","0",
00217                                 "Output update interval (events)");
00218         BLSetParam unused_3("viewer","none",
00219                                 "Visualization driver selected (default=none)");
00220         BLSetParam unused_4("eventTimeLimit","30",
00221                                 "CPU Time Limit (sec)");
00222         BLSetParam unused_5("steppingVerbose","0",
00223                                 "Set nonzero to print each step");
00224         BLSetParam unused_6("steppingFormat", "N GLOBAL CL KE STEP VOL PROCESS",
00225                                 "Format for printing steps");
00226         BLSetParam unused_7("zTolerance","2.0",
00227                                 "Tolerance for Z steps (mm)");
00228 
00229         if(blManager)
00230                 G4Exception("BLManager","Object Already Exists",FatalException,
00231                                                                         "");
00232         blManager = this;
00233 
00234         state = IDLE;
00235         steppingVerbose = 0;
00236 
00237         // ensure ZStep vectors have bookends
00238         tuneZStep.push_back(ZStep(-DBL_MAX,0));
00239         tuneZStep.push_back(ZStep(DBL_MAX,0));
00240         referenceZStep.push_back(ZStep(-DBL_MAX,0));
00241         referenceZStep.push_back(ZStep(DBL_MAX,0));
00242         beamZStep.push_back(ZStep(-DBL_MAX,0));
00243         beamZStep.push_back(ZStep(DBL_MAX,0));
00244         currentZStep = &beamZStep;
00245         indexZStep = 1;
00246         zTolerance = Param.getDouble("zTolerance");
00247         prevZ = -DBL_MAX;
00248 
00249         // default verbose format
00250         verboseFormat.push_back(NSTEP);
00251         verboseFormat.push_back(GLOBAL);
00252         verboseFormat.push_back(CL);
00253         verboseFormat.push_back(KE);
00254         verboseFormat.push_back(STEP);
00255         verboseFormat.push_back(VOL);
00256         verboseFormat.push_back(PROCESS);
00257         verboseFormat.push_back(NEWLINE);
00258 
00259         runManager = 0;
00260         state = IDLE;
00261         beamIndex = 0;
00262         histoUpdate = 0;
00263         startRun = 0;
00264         startEvent = 0;
00265         eventTimeLimit = 30;
00266         physics = 0;
00267         worldPhysicalVolume = 0;
00268         eventID = 1;
00269         trackID=-9999;
00270         trackParticleDef = 0;
00271         fatalExceptions = 0;
00272         eventsAborted=0;
00273         tracksAborted = 0;
00274         warnings=0;
00275         prevEventID = 0;
00276         eventsProcessed = 0;
00277         endRun = false;
00278         seedMethod = EVENT_NUMBER;
00279         eventCutFile = "";
00280         nStuck = 0;
00281         primaryTrackID = -1;
00282         primaryParentID = -1;
00283         nextSecondaryTrackID = 1001;
00284 
00285         BLAlarm::init();
00286 
00287         G4StateManager * stateManager = G4StateManager::GetStateManager();
00288         stateManager->SetExceptionHandler(this);
00289 }

BLManager::~BLManager (  ) 

Destructor.

References blManager.

00299 {
00300         // cannot delete runManager, as it deletes the detector, 
00301         // steppingaction, eventaction, ..., and that becomes multiple
00302         // deletes of this object. But we are exiting, so we don't really
00303         // need to delete anything.
00304         //delete runManager;
00305 
00306         // Instead of deleting things, just open the geometry to avoid 
00307         // warnings when exit() is called.
00308         G4GeometryManager::GetInstance()->OpenGeometry();
00309 
00310         blManager = 0;
00311 }


Member Function Documentation

void BLManager::insertZStep ( std::vector< ZStep > &  vector,
G4double  z,
ZSteppingAction action 
) [private]

Referenced by registerZStep().

00385 {
00386         // the bookends in vector (see BLManager()) ensure this works
00387         std::vector<ZStep>::iterator i;
00388         for(i=vector.begin(); i<vector.end(); ++i) {
00389                 if(z < i->z) {  // preserve order for ==
00390                         ZStep zs(z,action);
00391                         vector.insert(i,zs);
00392                         break;
00393                 }
00394         }
00395 }

void BLManager::readEventCutFile (  )  [private]

References eventCutFile, and eventList.

Referenced by BeginOfRunAction().

01496 {
01497         eventList.clear();
01498         if(eventCutFile.size() == 0) return;
01499 
01500         FILE *in = fopen(eventCutFile.c_str(),"r");
01501         if(!in) {
01502                 printf("WARNING: Cannot read eventCutFile '%s' -- IGNORED\n",
01503                                                         eventCutFile.c_str());
01504                 return;
01505         }
01506 
01507         char line[1025];
01508         while(fgets(line,sizeof(line),in)) {
01509                 assert(strlen(line) < sizeof(line)-1);
01510                 if(line[0] == '#') continue;
01511                 long ev = strtol(line,0,0);
01512                 eventList.insert(ev);
01513         }
01514 
01515         fclose(in);
01516 
01517         // eventList is ignored if empty, so insert a crazy entry
01518         if(eventList.size() == 0) eventList.insert(0x80000000);
01519 }

BLManager * BLManager::getObject (  )  [static]

getObject() will return a pointer to the single BLManager object, creating it if necessary. Does only the immediate constructor, not delayedConstruction(). that means it is Ok to register capabilities, but not much else.

References BLManager(), and blManager.

Referenced by FOR009NTuple::appendRow(), TrackFileNTuple::appendRow(), BLRunManager::BeamOn(), BLRunManager::beamOnCollective(), BLCMDmovie::beamStep(), BLRunManager::beginEvent(), BLRunManager::beginRun(), BLVirtualDetectorNTuple::BLVirtualDetectorNTuple(), BLCMDzntuple::callback(), BLCMDtrackermode::callback(), BLCMDtotalenergy::callback(), BLCMDshowmaterial::callback(), BLCMDgeometry::callback(), BLCMDtrackcuts::ClassifyNewTrack(), BLCMDcollective::collectiveStep(), BLCMDzntuple::command(), BLCMDusertrackfilter::command(), BLCMDtune::command(), BLCMDtrackermode::command(), BLCMDtracker::command(), BLCMDtrackcuts::command(), BLCMDtrace::command(), BLCMDtotalenergy::command(), BLCMDtimentuple::command(), BLCMDshowmaterial::command(), BLCMDreference::command(), BLCMDrandomseed::command(), BLCMDprofile::command(), BLCMDprobefield::command(), BLCMDprintfield::command(), BLCMDprintf::command(), BLCMDphysics::command(), BLCMDparticlesource::command(), BLCMDparticlecolor::command(), BLCMDntuple::command(), BLCMDnewparticlentuple::command(), BLCMDmovie::command(), BLCMDlist::command(), BLCMDhelp::command(), BLCMDgeometry::command(), BLCMDg4ui::command(), BLCMDeventcuts::command(), BLCMDcosmicraybeam::command(), BLCMDbug1021::command(), BLCMDbeamlossntuple::command(), BLCMDbeam::command(), BLCMDvirtualdetector::construct(), BLCMDusertrackfilter::construct(), BLCMDtubs::construct(), BLCMDtrap::construct(), BLCMDtrackerplane::construct(), BLCMDtorus::construct(), BLCMDsphere::construct(), BLCMDsolenoid::construct(), BLCMDpolycone::construct(), BLCMDpillbox::construct(), BLCMDparticlefilter::construct(), BLCMDmultipole::construct(), BLCMDidealsectorbend::construct(), BLCMDhelicaldipole::construct(), BLCMDgenericquad::construct(), BLCMDgenericbend::construct(), BLCMDextrusion::construct(), BLCMDcorner::construct(), BLCMDbox::construct(), BLRunManager::endEvent(), BLCMDparticlecolor::EndOfEventAction(), BLRunManager::endRun(), BLCMDtracker::fitTrack(), BLCMDreference::generateReferenceParticle(), BLRunManager::getNextBeamEventAndTrack(), BLCMDparticlecolor::getVisAttributes(), BLCMDtracker::handlePreviousTracks(), BLCMDparam::help(), BLCoordinates::init(), BLCMDlist::listParticles(), main(), BLCMDparticlesource::nextBeamEvent(), BLCMDbeam::nextBeamEvent(), BLCMDtracker::operator()(), ParticleFilterPlacement::ParticleFilterPlacement(), BLCoordinates::ReferenceCoordinates::PostUserTrackingAction(), BLCMDtracker::PostUserTrackingAction(), BLCMDparticlecolor::PostUserTrackingAction(), BLCMDbeamlossntuple::PostUserTrackingAction(), BLCoordinates::ReferenceCoordinates::PreUserTrackingAction(), BLCMDtracker::PreUserTrackingAction(), BLCMDparticlecolor::PreUserTrackingAction(), BLCMDnewparticlentuple::PreUserTrackingAction(), BLCoordinates::ReferenceCoordinates::ReferenceCoordinates(), BLUserCode::registerUserCode(), BLBeam::setRandomSeedToGenerate(), BLEvaluator::setTrackVariables(), BLCoordinates::start(), steppingVerbosePrint(), Surface::Surface(), TraceNTuple::TraceNTuple(), BLCoordinates::ReferenceCoordinates::UserSteppingAction(), BLVirtualDetectorNTuple::UserSteppingAction(), BLCMDusertrackfilter::UserSteppingAction(), TrackerPlaneInstance::UserSteppingAction(), TimeNTuple::UserSteppingAction(), PillboxField::UserSteppingAction(), ParticleFilterPlacement::UserSteppingAction(), BLCMDzntuple::Entry::UserZSteppingAction(), BLCMDtune::UserZSteppingAction(), BLCMDtracker::UserZSteppingAction(), BLCMDreference::UserZSteppingAction(), BLCMDprofile::Entry::UserZSteppingAction(), and BLCMDprintf::UserZSteppingAction().

00378 {
00379         if(!blManager) new BLManager();
00380         return blManager;
00381 }

void BLManager::delayedConstruction (  ) 

delayedConstruction() performs things which must wait until all static initializers have executed (e.g. in Geant4 routines).

References runManager.

Referenced by main().

00292 {
00293         runManager = new BLRunManager();
00294         G4StateManager * stateManager = G4StateManager::GetStateManager();
00295         stateManager->SetExceptionHandler(this);
00296 }

BLManagerState BLManager::getState (  )  [inline]

void BLManager::setState ( BLManagerState  _state  )  [inline]

int BLManager::getSteppingVerbose (  )  [inline]

getSteppingVerbose() returns steppingVerbose. NOTE: use this during tracking instead of Param.getInt("steppingVerbose");

References steppingVerbose.

Referenced by BLVirtualDetectorNTuple::BLVirtualDetectorNTuple(), BLCoordinates::init(), and BLCoordinates::start().

00194 { return steppingVerbose; }

void BLManager::setSteppingVerbose ( int  v  )  [inline]

setSteppingVerbose() updates steppingVerbose. -- NOTE: many other classes relay on the Parameter, not the valud in this class.

References steppingVerbose.

00198 { steppingVerbose = v; }

int BLManager::getEventTimeLimit (  )  [inline]

getEventTimeLimit() returns the CPU time limit for events (seconds). -1 mean infinite.

References eventTimeLimit.

00202 { return eventTimeLimit; }

void BLManager::setEventTimeLimit ( int  sec  )  [inline]

setEventTimeLimit() sets the CPU time limit for events (seconds). -1 mean infinite.

References eventTimeLimit.

Referenced by BLRunManager::beamOnCollective().

00206 { eventTimeLimit = sec; }

G4int BLManager::getEventID (  )  const [inline]

void BLManager::setEventID ( int  evId  )  [inline]

bool BLManager::skipEvent ( int  EventID  )  [inline]

skipEvent() will check the eventList vector (which comes from the eventCut file).

References eventID, and eventList.

Referenced by GeneratePrimaries().

00217             { return eventList.size() > 0 && eventList.count(eventID) == 0; }

void BLManager::incrEventsProcessed ( int  eventID  ) 

incrEventsProcessed() will increment eventsProcessed. For special uses only (e.g.MPI).

References eventsProcessed, BLRunManager::getCollectiveMode(), runManager, startRun, and BLTime::time().

Referenced by EndOfEventAction().

01077 {
01078         // print event number, if appropriate
01079         ++eventsProcessed;
01080         if(!runManager->getCollectiveMode()) {
01081                 if(eventsProcessed <= 10 ||
01082                    (eventsProcessed < 100 && eventsProcessed%10 == 0) ||
01083                    (eventsProcessed < 1000 && eventsProcessed%100 == 0) ||
01084                    eventsProcessed%1000 == 0) {
01085                         printf("Event %d Completed",eventID);
01086                         int t = BLTime::time() - startRun;
01087                         if(t <= 0) t = 1;
01088                         printf("  %d events  realTime=%d sec  %.1f ev/sec",
01089                                 eventsProcessed,t,(double)eventsProcessed/t);
01090                         printf("\n");
01091                         fflush(stdout);
01092                 }
01093         }
01094 }

void BLManager::registerSteppingAction ( SteppingAction sa  )  [inline]

void BLManager::registerSteppingAction ( G4VPhysicalVolume *  physicalVol,
SteppingAction sa 
) [inline]

registerSteppingAction() registers a SteppingAction to be called for each step (regardless of state), for every step involving the physicalVol. The callback will be called if physicalVol is either the pre- or post-step physical volume (once if both). If physicalVol==0 it is called every reference particle step. LIMITATION: only one callback can be registered for a given physicalVol (except 0).

References allStepMap, and allStepVector.

00238                 { if(physicalVol != 0) allStepMap[physicalVol] = sa;
00239                   else allStepVector.push_back(sa); }

void BLManager::registerTuneParticleStep ( G4VPhysicalVolume *  physicalVol,
SteppingAction sa 
) [inline]

registerTuneParticleStep() registers a SteppingAction to be called for every tune particle step involving the physicalVol. The callback will be called if physicalVol is either the pre- or post-step physical volume (once if both). If physicalVol==0 it is called every tune particle step. LIMITATION: only one callback can be registered for a given physicalVol (except 0).

References tpStepMap, and tpStepVector.

Referenced by BLCMDpillbox::construct().

00250                 { if(physicalVol != 0) tpStepMap[physicalVol] = sa; 
00251                   else tpStepVector.push_back(sa); }

void BLManager::registerReferenceParticleStep ( G4VPhysicalVolume *  physicalVol,
SteppingAction sa 
) [inline]

registerReferenceParticleStep() registers a SteppingAction to be called for every reference particle step involving the physicalVol. The callback will be called if physicalVol is either the pre- or post-step physical volume (once if both). If physicalVol==0 it is called every reference particle step. LIMITATION: only one callback can be registered for a given physicalVol (except 0).

References rpStepMap, and rpStepVector.

Referenced by BLCMDmovie::command(), BLCMDvirtualdetector::construct(), BLCMDtrackerplane::construct(), and BLCoordinates::ReferenceCoordinates::ReferenceCoordinates().

00263                 { if(physicalVol != 0) rpStepMap[physicalVol] = sa; 
00264                   else rpStepVector.push_back(sa); }

void BLManager::registerBeamStep ( G4VPhysicalVolume *  physicalVol,
SteppingAction sa 
) [inline]

registerBeamStep() registers a SteppingAction to be called for every beam step involving the physicalVol. (beam particles are everything except reference and tune.) The callback will be called if physicalVol is either the pre- or post-step physical volume (once if both). if physicalVol==0 it is called every beam step. LIMITATION: only one callback can be registered for a given physicalVol (except 0).

References beamStepMap, and beamStepVector.

Referenced by BLCMDtotalenergy::command(), BLCMDtimentuple::command(), BLCMDmovie::command(), BLCMDvirtualdetector::construct(), and BLCMDtrackerplane::construct().

00276                 { if(physicalVol != 0) beamStepMap[physicalVol] = sa; 
00277                   else beamStepVector.push_back(sa); }

void BLManager::registerZStep ( G4double  z,
ZSteppingAction sa,
G4int  when = 7 
)

registerZStep() will force a step to occur near the given z position, and will call the ZSteppingAction for it, interpolating to the desired z value (Centerline coords). when is a bitwise OR of 1=tune, 2=reference, 4=beam.

References beamZStep, insertZStep(), referenceZStep, and tuneZStep.

Referenced by BLCMDzntuple::callback(), BLCMDtune::command(), BLCMDtracker::command(), BLCMDreference::command(), BLCMDprofile::command(), and BLCMDprintf::command().

00398 {
00399         if(when & 1) insertZStep(tuneZStep,z,sa);
00400         if(when & 2) insertZStep(referenceZStep,z,sa);
00401         if(when & 4) insertZStep(beamZStep,z,sa);
00402 }

void BLManager::registerStackingAction ( StackingAction sa  )  [inline]

registerStackingAction() registers a StackingAction to be called by the Geant4 stacking manager.

References stackingActionVector.

Referenced by BLCMDtrackcuts::command().

00288                 { stackingActionVector.push_back(sa); }

void BLManager::setSteppingFormat (  ) 

setSteppingFormat() sets the verbose printing format according to parameter "steppingFormat".

References appendVerboseFormat(), BLParam::getString(), Param, and BLCommand::parseArgs().

Referenced by initialize().

01202 {
01203         G4String fmt = Param.getString("steppingFormat");
01204         BLArgumentVector args;
01205         BLArgumentMap namedArgs;
01206         
01207         // convert "," to " "
01208         G4String s;
01209         for(unsigned i=0; i<fmt.size(); ++i)
01210                 s += (fmt[i]==',' ? ' ' : fmt[i]);
01211 
01212         BLCommand::parseArgs(s,args,namedArgs);
01213         appendVerboseFormat("");
01214         for(unsigned i=0; i<args.size(); ++i)
01215                 appendVerboseFormat(args[i]);
01216         appendVerboseFormat("NEWLINE");
01217 }

G4String BLManager::getFormatHelp (  ) 

getFormatHelp() returns a string with help text about valid format items.

01220 {
01221         G4String s = 
01222                 "        EXT       toggle extended precision (3 more digits)\n"
01223                 "        TAG       print a '>' (useful to grep output)\n"
01224                 "        N         step number\n"
01225                 "        NSTEP     Synonym of N\n"
01226                 "        GLOBAL    X,Y,Z,T in global coords\n"
01227                 "        XYZT      Synonym of GLOBAL\n"
01228                 "        CL        X,Y,Z,dxdz,dydz in CL coords\n"
01229                 "        CLX       extended precision CL\n"
01230                 "        KE        kinetic energy\n"
01231                 "        STEP      step length\n"
01232                 "        STEPLEN   Synonym of STEP\n"
01233                 "        VOL       volume name\n"
01234                 "        VOLNAME   Synonym of VOL\n"
01235                 "        PROCESS   process name\n"
01236                 "        B         magnetic field\n"
01237                 "        E         electric field\n"
01238                 "        P         3-momentum\n"
01239                 "        MAT       material name\n"
01240                 "        ID        event ID, track ID, parent ID\n"
01241                 "        PART      particle name\n"
01242                 "        SEG       centerline coord segment number\n"
01243                 "        WT        weight\n"
01244                 "        NL        <newline>\n"
01245                 "        NEWLINE   Synonym of NL\n"
01246                 "        \\n        Synonym of NL\n";
01247 
01248         return s;
01249 }

void BLManager::appendVerboseFormat ( G4String  fmt  ) 

appendVerboseFormat() appends fmt to the format for printing when param steppingVerbose is nonzero

References B, CL, CLX, E, EXT, GLOBAL, ID, KE, MAT, NEWLINE, NSTEP, P, PART, PROCESS, SEG, STEP, TAG, verboseFormat, VOL, and WT.

Referenced by setSteppingFormat().

01252 {
01253         G4String f;
01254         for(const char *p=fmt.c_str(); *p; ++p)
01255                 f += toupper(*p);
01256         if(f == "") verboseFormat.clear();
01257         else if(f == "TAG") verboseFormat.push_back(TAG);
01258         else if(f == "EXT") verboseFormat.push_back(EXT);
01259         else if(f == "N") verboseFormat.push_back(NSTEP);
01260         else if(f == "NSTEP") verboseFormat.push_back(NSTEP);
01261         else if(f == "GLOBAL") verboseFormat.push_back(GLOBAL);
01262         else if(f == "XYZT") verboseFormat.push_back(GLOBAL);
01263         else if(f == "CL") verboseFormat.push_back(CL);
01264         else if(f == "CLX") verboseFormat.push_back(CLX);
01265         else if(f == "KE") verboseFormat.push_back(KE);
01266         else if(f == "STEP") verboseFormat.push_back(STEP);
01267         else if(f == "STEPLEN") verboseFormat.push_back(STEP);
01268         else if(f == "VOL") verboseFormat.push_back(VOL);
01269         else if(f == "VOLNAME") verboseFormat.push_back(VOL);
01270         else if(f == "PROCESS") verboseFormat.push_back(PROCESS);
01271         else if(f == "B") verboseFormat.push_back(B);
01272         else if(f == "E") verboseFormat.push_back(E);
01273         else if(f == "P") verboseFormat.push_back(P);
01274         else if(f == "MAT") verboseFormat.push_back(MAT);
01275         else if(f == "ID") verboseFormat.push_back(ID);
01276         else if(f == "PART") verboseFormat.push_back(PART);
01277         else if(f == "SEG") verboseFormat.push_back(SEG);
01278         else if(f == "WT") verboseFormat.push_back(WT);
01279         else if(f == "\n") verboseFormat.push_back(NEWLINE);
01280         else if(f == "NL") verboseFormat.push_back(NEWLINE);
01281         else if(f == "NEWLINE") verboseFormat.push_back(NEWLINE);
01282         else printf("BLManager: invalid verbose format '%s'\n",
01283                 fmt.c_str());
01284 }

void BLManager::steppingVerbosePrint ( const G4Step *  step,
const G4Track *  track,
int  header = 0 
)

steppingVerbosePrint() will print this step according to the current verboseFormat. Prints header if header != 0).

References B, BLCOORD_CENTERLINE, CL, CLX, E, EXT, BLCoordinates::getCoords(), getExternalParentID(), getExternalTrackID(), BLGlobalField::GetFieldValue(), getObject(), BLGlobalField::getObject(), BLCoordinates::getRotation(), BLCoordinates::getSegmentCL(), GLOBAL, ID, BLCoordinates::isValid(), KE, MAT, NEWLINE, NSTEP, P, PART, PROCESS, runManager, SEG, STEP, TAG, verboseFormat, VOL, and WT.

Referenced by UserSteppingAction().

01288 {
01289         G4StepPoint *prePoint=0;
01290         G4VPhysicalVolume *preVol=0;
01291         G4StepPoint *postPoint=0;
01292         G4double time=0;
01293         G4ThreeVector position;
01294         G4Material *mat=0;
01295         int eventNum = -999;
01296         int nstep=0;
01297         const char *procName=0;
01298         BLCoordinates *coord = (track!=0 ? (BLCoordinates *)track->GetUserInformation() : 0);
01299         if(coord && !coord->isValid()) coord = 0;
01300 
01301         if(!header) {
01302                 prePoint = step->GetPreStepPoint();
01303                 preVol = prePoint->GetPhysicalVolume();
01304                 postPoint = step->GetPostStepPoint();
01305                 time = track->GetGlobalTime();
01306                 position = track->GetPosition();
01307                 mat = preVol->GetLogicalVolume()->GetMaterial();
01308                 nstep = track->GetCurrentStepNumber();
01309                 procName = (postPoint->GetProcessDefinedStep() ?
01310                   postPoint->GetProcessDefinedStep()->GetProcessName().c_str() :
01311                   "UserLimit"); 
01312                 const G4Event* event = runManager->GetCurrentEvent();
01313                 eventNum = event->GetEventID();
01314         }
01315 
01316         bool extended=false;
01317         for(unsigned i=0; i<verboseFormat.size(); ++i) {
01318                 switch(verboseFormat[i]) {
01319                 case EXT:
01320                         extended = !extended;
01321                         break;
01322                 case TAG:
01323                         if(header) printf(" ");
01324                         else printf(">");
01325                         break;
01326                 case NSTEP:
01327                         if(header) printf(" Step");
01328                         else printf(" %4d",nstep);
01329                         break;
01330                 case GLOBAL:
01331                     if(!extended) {
01332                         if(header) printf("   X(mm)   Y(mm)   Z(mm)    T(ns)");
01333                         else printf(" %7.1f %7.1f %7.1f %8.2f",
01334                                 position[0],position[1],position[2],
01335                                 time);
01336                     } else {
01337                         if(header) printf("      X(mm)      Y(mm)      Z(mm)      T(ns) ");
01338                         else printf(" %10.4f %10.4f %10.4f %11.5f",
01339                                 position[0],position[1],position[2],
01340                                 time);
01341                     }
01342                         break;
01343                 case CL:
01344                     if(extended) goto clx;
01345                     if(header) {
01346                         printf("   CL: X        Y        Z     dxdz    dydz");
01347                     } else {
01348                         G4ThreeVector dir = track->GetMomentumDirection();
01349                         // transform to centerline coordinates
01350                         G4ThreeVector clpos;
01351                         coord->getCoords(BLCOORD_CENTERLINE,clpos);
01352                         dir = coord->getRotation() * dir;
01353                         printf(" %8.1f %8.1f %8.1f %7.4f %7.4f",
01354                                         clpos[0],clpos[1],clpos[2],
01355                                         dir[0]/dir[2],dir[1]/dir[2]);
01356                     }
01357                         break;
01358                 case CLX:
01359 clx:                if(header) {
01360                         printf("   CL: X           Y           Z        dxdz       dydz   ");
01361                     } else {
01362                         G4ThreeVector dir = track->GetMomentumDirection();
01363                         // transform to centerline coordinates
01364                         G4ThreeVector clpos;
01365                         coord->getCoords(BLCOORD_CENTERLINE,clpos);
01366                         dir = coord->getRotation() * dir;
01367                         printf(" %11.4f %11.4f %11.4f %10.7f %10.7f",
01368                                         clpos[0],clpos[1],clpos[2],
01369                                         dir[0]/dir[2],dir[1]/dir[2]);
01370                     }
01371                         break;
01372                 case KE:
01373                     if(!extended) {
01374                         if(header) printf("  KE(MeV)");
01375                         else printf(" %8.1f",track->GetKineticEnergy());
01376                     } else {
01377                         if(header) printf("    KE(MeV) ");
01378                         else printf(" %11.4f",track->GetKineticEnergy());
01379                     }
01380                         break;
01381                 case STEP:
01382                     if(!extended) {
01383                         if(header) printf("  StepLen");
01384                         else printf(" %8.2f",step->GetStepLength());
01385                     } else {
01386                         if(header) printf("    StepLen ");
01387                         else printf(" %11.5f",step->GetStepLength());
01388                     }
01389                         break;
01390                 case VOL:
01391                         if(header) printf(" This Volume     ");
01392                         else printf(" %-16s",preVol->GetName().c_str());
01393                         break;
01394                 case PROCESS:
01395                         if(header) printf(" Process        ");
01396                         else printf(" %-16s",procName);
01397                         break;
01398                 case B:
01399                     if(header) {
01400                         printf("       Bx,By,Bz (Tesla)     ");
01401                     } else {
01402                         G4double point[4], field[6];
01403                         point[0]=position[0],point[1]=position[1],point[2]=position[2];
01404                         point[3]=time;
01405                         BLGlobalField::getObject()->GetFieldValue(point,field);
01406                         G4ThreeVector B(field[0],field[1],field[2]);
01407                         B = coord->getRotation(BLCOORD_CENTERLINE) * B;
01408                         printf(" %8.4f %8.4f %8.4f",
01409                                 B[0]/tesla,B[1]/tesla,B[2]/tesla);
01410                     }
01411                         break;
01412                 case E:
01413                     if(header) {
01414                         printf("      Ex,Ey,Ez (MV/meter)  ");
01415                     } else {
01416                         G4double point[4], field[6];
01417                         point[0]=position[0],point[1]=position[1],point[2]=position[2];
01418                         point[3]=time;
01419                         BLGlobalField::getObject()->GetFieldValue(point,field);
01420                         G4ThreeVector E(field[3],field[4],field[5]);
01421                         E = coord->getRotation(BLCOORD_CENTERLINE) * E;
01422                         printf(" %8.4f %8.4f %8.4f",E[0]/(megavolt/meter),
01423                                 E[1]/(megavolt/meter),E[2]/(megavolt/meter));
01424                     }
01425                         break;
01426                 case P:
01427                   if(!extended) {
01428                     if(header) {
01429                         printf("      Px,Py,Pz (MeV/c)     ");
01430                     } else {
01431                         G4ThreeVector P = track->GetMomentum();
01432                         P = coord->getRotation(BLCOORD_CENTERLINE) * P;
01433                         printf(" %8.1f %8.1f %8.1f",P[0]/(MeV),
01434                                 P[1]/(MeV),P[2]/(MeV));
01435                     }
01436                   } else {
01437                     if(header) {
01438                         printf("          Px,Py,Pz (MeV/c)          ");
01439                     } else {
01440                         G4ThreeVector P = track->GetMomentum();
01441                         P = coord->getRotation(BLCOORD_CENTERLINE) * P;
01442                         printf(" %11.4f %11.4f %11.4f",P[0]/(MeV),
01443                                 P[1]/(MeV),P[2]/(MeV));
01444                     }
01445                   }
01446                         break;
01447                 case MAT:
01448                     if(header) {
01449                         printf(" Material ");
01450                     } else {
01451                         printf(" %-9s",mat->GetName().c_str());
01452                     }
01453                         break;
01454                 case ID:
01455                     if(header) {
01456                         printf(" Event# Trk Prnt");
01457                     } else {
01458                         printf(" %6d %3d %4d",eventNum,
01459                                 BLManager::getObject()->
01460                                     getExternalTrackID(track),
01461                                 BLManager::getObject()->
01462                                     getExternalParentID(track));
01463                     }
01464                         break;
01465                 case PART:
01466                     if(header) {
01467                         printf(" Particle");
01468                     } else {
01469                         printf(" %8s",track->GetDefinition()->GetParticleName().c_str());
01470                     }
01471                         break;
01472                 case SEG:
01473                     if(header) {
01474                         printf(" Seg");
01475                     } else {
01476                         printf(" %3d",coord->getSegmentCL());
01477                     }
01478                         break;
01479                 case WT:
01480                         if(header) {
01481                             printf("  Wt  ");
01482                         } else {
01483                             printf(" %.3f",track->GetWeight());
01484                         }
01485                         break;
01486                 case NEWLINE:
01487                         printf("\n");
01488                         break;
01489                 }
01490         }
01491 
01492         fflush(stdout); // help debugging location of crashes
01493 }

void BLManager::setSteppingManager ( G4SteppingManager *  p  )  [inline]

setSteppingManager() sets the pointer to the current G4SteppingManager.

References fpSteppingManager.

Referenced by BLManager_UserSteppingAction::UserSteppingAction().

00310 { fpSteppingManager = p; }

G4SteppingManager* BLManager::getSteppingManager (  )  [inline]

getSteppingManager() returns a pointer to the current G4SteppingManager.

References fpSteppingManager.

Referenced by PillboxField::UserSteppingAction(), BLCMDtune::UserZSteppingAction(), and BLCMDreference::UserZSteppingAction().

00314 { return fpSteppingManager; }

void BLManager::setTrackingManager ( G4TrackingManager *  p  )  [inline]

setTrackingManager() sets the pointer to the current G4TrackingManager.

References fpTrackingManager.

Referenced by BLManager_UserTrackingAction::PreUserTrackingAction().

00318 { fpTrackingManager = p; }

void BLManager::initialize (  ) 

initialize() will initialize the BLManager object, and the geant4 kernel, thus constructing the geometry in the world group. Note that registerPhysics() must be called before initialize() (normally done by a "physics" command in the input file).

physics->getPhysicsList() is set in registerPhysicsList()

References beamIndex, beamVector, eventTimeLimit, BLParam::getDouble(), BLParam::getInt(), histoUpdate, initialized, Param, physics, referenceVector, runManager, setSteppingFormat(), steppingVerbose, and zTolerance.

Referenced by BLCMDlist::command(), and main().

00314 {
00315         if(initialized) {
00316                 G4Exception("BLManager","Already Initialized",FatalException,
00317                                                                         "");
00318         }
00319         initialized = true;
00320 
00321         G4UImanager* UI = G4UImanager::GetUIpointer();
00322 
00323         if(!physics) {
00324                 G4Exception("BLManager","No physics registered",FatalException,
00325                                                                         "");
00326         }
00327 
00328         setSteppingFormat();
00329 
00330         // set initialization and user classes
00331         runManager->SetUserInitialization((G4VUserDetectorConstruction*)this);
00332         /// physics->getPhysicsList() is set in registerPhysicsList()
00333         runManager->SetUserAction(new BLManager_UserSteppingAction(this));
00334         runManager->SetUserAction(new BLManager_UserTrackingAction(this));
00335         runManager->SetUserAction(new BLManager_UserRunAction(this));
00336         runManager->SetUserAction(new BLManager_UserEventAction(this));
00337         runManager->SetUserAction(new BLManager_PrimaryGeneratorAction(this));
00338         runManager->SetUserAction(new BLManager_UserStackingAction(this));
00339 
00340         // apply initial range cuts
00341         UI->ApplyCommand("/range/cutG 2 mm");
00342         UI->ApplyCommand("/range/cutE 2 mm");
00343 
00344         // initialize the RunManager, construct the apparatus, etc.
00345         runManager->Initialize();
00346 
00347         // set initial verbosities
00348         UI->ApplyCommand("/control/verbose 0");
00349         UI->ApplyCommand("/run/verbose 0");
00350         UI->ApplyCommand("/event/verbose 0");
00351         UI->ApplyCommand("/tracking/verbose 0");
00352         UI->ApplyCommand("/hits/verbose 0");
00353         UI->ApplyCommand("/material/verbose 0");
00354         UI->ApplyCommand("/process/setVerbose 0 all");
00355         UI->ApplyCommand("/process/verbose 0");
00356         UI->ApplyCommand("/process/eLoss/verbose 0");
00357         G4HadronicProcessStore::Instance()->SetVerbose(0);
00358 
00359         steppingVerbose = Param.getInt("steppingVerbose");
00360 
00361         // get various parameter values (may have changed since constructor)
00362         histoUpdate = Param.getInt("histoUpdate");
00363         eventTimeLimit = Param.getInt("eventTimeLimit");
00364         zTolerance = Param.getDouble("zTolerance");
00365 
00366         // initialize the beam
00367         for(beamIndex=0; beamIndex<beamVector.size(); ++beamIndex)
00368                 beamVector[beamIndex]->init();
00369         for(unsigned i=0; i<referenceVector.size(); ++i)
00370                 referenceVector[i]->init();
00371         beamIndex = 0;
00372 
00373         // create the ZStepLimiter
00374         new ZStepLimiter();
00375 }

static bool BLManager::isInitialized (  )  [inline, static]

isInitialized() returns true if the BLManager has been initialized.

References initialized.

Referenced by BLCMDlist::command().

00328 { return initialized; }

void BLManager::trackTuneAndReferenceParticles (  ) 

trackTuneAndReferenceParticles() will generate and track the tune particle and then the reference particle.

References beamIndex, BLRunManager::BeamOn(), FORCE_OFF, BLRunManager::getCollectiveMode(), IDLE, NORMAL, physics, REFERENCE, referenceVector, runManager, BLRunManager::setCollectiveMode(), BLPhysics::setDoStochastics(), setEventID(), state, and TUNE.

Referenced by main().

00405 {
00406         if(referenceVector.size() == 0)
00407                 return;
00408 
00409         if(!physics) {
00410                 G4Exception("BLManager","No physics registered",FatalException,
00411                                                                         "");
00412         }
00413 
00414         // Tune and Reference particles cannot use collective mode
00415         bool collectiveMode = runManager->getCollectiveMode();
00416         runManager->setCollectiveMode(false);
00417 
00418         printf("================= Prepare Tune Particle(s) ===========\n");
00419         physics->setDoStochastics(FORCE_OFF);
00420         runManager->Initialize();
00421 
00422         printf("================= Begin Tune Particle(s) =============\n");
00423         state = TUNE;
00424         setEventID(-2);
00425         beamIndex = 0;
00426         runManager->BeamOn(referenceVector.size());
00427         state = IDLE;
00428 
00429         // now track center particle
00430         printf("================== Begin Reference Particle(s) ===============\n");
00431         state = REFERENCE;
00432         setEventID(-1);
00433         beamIndex = 0;
00434         runManager->BeamOn(referenceVector.size());
00435         state = IDLE;
00436         beamIndex = 0;
00437 
00438         physics->setDoStochastics(NORMAL);
00439         runManager->setCollectiveMode(collectiveMode);
00440 }

void BLManager::trackBeam (  ) 

trackBeam() will generate the defined beam and track each event.

References BEAM, beamIndex, BLRunManager::BeamOn(), beamVector, IDLE, NORMAL, physics, runManager, BLPhysics::setDoStochastics(), setEventID(), and state.

Referenced by main().

00443 {
00444         if(beamVector.size() == 0) {
00445                 G4Exception("BLManager","No beam registered",FatalException,
00446                                                                         "");
00447         }
00448         if(!physics) {
00449                 G4Exception("BLManager","No physics registered",FatalException,
00450                                                                         "");
00451         }
00452 
00453         printf("================== Prepare Tracking Beam ==================\n");
00454         physics->setDoStochastics(NORMAL);
00455         runManager->Initialize();
00456 
00457         printf("================== Begin Tracking Beam ===============\n");
00458         state = BEAM;
00459         setEventID(1);
00460         beamIndex = 0;
00461         runManager->BeamOn(0x7FFFFFFF);
00462         for(beamIndex=0; beamIndex<beamVector.size(); ++beamIndex)
00463                 beamVector[beamIndex]->summary();
00464         beamIndex = 0;
00465         state = IDLE;
00466 }

void BLManager::displayVisual (  ) 

displayVisual() will display the detector visually.

References beamIndex, BLParam::getString(), handleCallbacks(), IDLE, BLVisManager::init(), NORMAL, Param, physics, runManager, BLPhysics::setDoStochastics(), setEventID(), state, and VISUAL.

Referenced by main().

00469 {
00470 #ifdef G4VIS_USE
00471         printf("================== Prepare Visualization ==================\n");
00472         state = VISUAL;
00473         physics->setDoStochastics(NORMAL);
00474         runManager->Initialize();
00475         setEventID(1);
00476         beamIndex = 0;
00477 
00478         BLVisManager *visManager = new BLVisManager(Param.getString("viewer"));
00479         visManager->init();
00480 
00481         handleCallbacks(4);
00482 
00483         printf("To display a run with 10 events in the viewer, type '/run/beamOn 10<cr>'\n");
00484         G4UIterminal *terminal = new G4UIterminal(0,false);
00485         terminal->SessionStart();
00486         
00487         delete terminal;
00488         delete visManager;
00489         state = IDLE;
00490         beamIndex = 0;
00491 #else
00492         G4Exception("BLManager","G4VIS_USE not defined",FatalException,"");
00493 #endif
00494 }

void BLManager::displayGeometry ( G4VPhysicalVolume *  phys = 0,
int  level = 0 
)

displayGeometry() will display the geant4 geometry. This is a hierarchical ASCII listing of all volumes. if phys==0 then use the worldPhysicalVolume.

References BLCommand::dumpRotation(), and worldPhysicalVolume.

Referenced by BLCMDgeometry::callback().

00497 {
00498         if(phys == 0) phys = worldPhysicalVolume;
00499         for(int i=0; i<level; ++i) printf("  ");
00500         G4ThreeVector pos = phys->GetObjectTranslation();
00501         printf("%s x=%.3f y=%.3f z=%.3f\n",phys->GetName().c_str(),
00502                         pos[0],pos[1],pos[2]);
00503         G4RotationMatrix rot = phys->GetObjectRotationValue();
00504         if(!rot.isIdentity()) {
00505                 for(int i=0; i<level; ++i) printf("  ");
00506                 BLCommand::dumpRotation(&rot,"");
00507         }
00508         G4LogicalVolume *log = phys->GetLogicalVolume();
00509         int n = log->GetNoDaughters();
00510         for(int i=0; i<n; ++i) {
00511                 G4VPhysicalVolume *p = log->GetDaughter(i);
00512                 if(p)
00513                         displayGeometry(p,level+1);
00514         }
00515 }

void BLManager::registerPhysics ( BLPhysics _physics  )  [inline]

registerPhysics() registers the BLPhysics object. It also sets the physics list to the BLRunManager, so following commands can find particle by name.

References BLPhysics::getPhysicsList(), physics, and runManager.

Referenced by BLCMDphysics::command().

00349                 { physics = _physics;
00350                   runManager->SetUserInitialization(physics->getPhysicsList());
00351                 }

BLPhysics* BLManager::getPhysics (  )  [inline]

getPhysics returns the registered BLPhysics object.

References physics.

Referenced by BLCMDtrackermode::callback(), and BLCMDtracker::fitTrack().

00354 { return physics; }

void BLManager::registerBeam ( BLBeam _beam  )  [inline]

registerBeam() registers a BLBeam object for beam generation. Multiple BLBeam objects can be registered, used in order.

References beamVector.

Referenced by BLCMDparticlesource::command(), BLCMDcosmicraybeam::command(), and BLCMDbeam::command().

00358 { beamVector.push_back(_beam); }

void BLManager::registerReference ( BLBeam _beam  )  [inline]

registerReference() registers a BLBeam object for reference particle generation. Multiple BLBeam objects can be registered, used in order.

References referenceVector.

Referenced by BLCMDreference::command().

00364                 { referenceVector.push_back(_beam); }

int BLManager::nReference (  )  [inline]

nReference() returns the number of reference particles registered.

References referenceVector.

Referenced by main().

00367 { return referenceVector.size(); }

void BLManager::registerRunAction ( RunAction a,
G4bool  beamOnly = true 
) [inline]

registerRunAction() registers a UserRunAction. If beamOnly is true (the default), the callback is made only if state==BEAM.

References beamRunActionVector, and runActionVector.

Referenced by BLCMDtune::command(), BLCMDreference::command(), and BLCMDhelicaldipole::construct().

00373                 { if(beamOnly)
00374                         beamRunActionVector.push_back(a);
00375                   else
00376                         runActionVector.push_back(a);
00377                 }

void BLManager::registerEventAction ( EventAction a,
G4bool  beamOnly = true 
) [inline]

registerEventAction() registers a UserEventAction. If beamOnly is true (the default), the callback is made only if state==BEAM.

References beamEventActionVector, and eventActionVector.

Referenced by BLCMDparticlecolor::command(), and BLCMDntuple::command().

00383                 { if(beamOnly)
00384                         beamEventActionVector.push_back(a);
00385                   else
00386                         eventActionVector.push_back(a);
00387                 }

void BLManager::registerTrackingAction ( TrackingAction a  )  [inline]

void BLManager::registerUserCode ( BLUserCode instance  )  [inline]

registerUserCode() registers a BLUserCode instance.

References userCodeVector.

Referenced by BLUserCode::registerUserCode().

00395                 { userCodeVector.push_back(instance); }

std::vector<BLUserCode*> BLManager::getUserCodeInstances ( G4String  type  )  [inline]

getUserCodeInstances() returns a vector of all registered instances of BLUserCode with the specified type.

References userCodeVector.

00400                 { std::vector<BLUserCode*> ret;
00401                   for(unsigned i=0; i<userCodeVector.size(); ++i) {
00402                         if(type == userCodeVector[i]->getType())
00403                                 ret.push_back(userCodeVector[i]);
00404                   }
00405                   return ret;
00406                 }

void BLManager::registerCallback ( BLCallback cb,
int  type 
) [inline]

registerCallback() registers a BLCallback. type=0 for pre-Tune particle, type=1 for post-Reference (pre-beam tracking), type=2 for post-beam tracking. type=3 for replacing the main program loop. type=4 for visualization. NOTE: if there are type=3 callbacks, when the last one returns the closes up by summarizing NTuples and callng handleCallbacks(2), and then the program exits. This prevents the main program loop from executing. type=3 callbacks are called just after the type=1 callbacks (i.e. after the post-Reference callbacks).

References postReferenceCallbackVector, postTrackingCallbackVector, preReferenceCallbackVector, replaceMainLoopCallbackVector, and visualizationCallbackVector.

Referenced by BLCMDzntuple::command(), BLCMDusertrackfilter::command(), BLCMDtrackermode::command(), BLCMDtracker::command(), BLCMDtotalenergy::command(), BLCMDshowmaterial::command(), BLCMDprofile::command(), BLCMDprobefield::command(), BLCMDprintfield::command(), BLCMDprintf::command(), BLCMDphysics::command(), BLCMDmovie::command(), BLCMDgeometry::command(), BLCMDg4ui::command(), BLCMDbug1021::command(), ParticleFilterPlacement::ParticleFilterPlacement(), and Surface::Surface().

00420                                                         {
00421                 if(type==0) preReferenceCallbackVector.push_back(cb);
00422                 else if(type==1) postReferenceCallbackVector.push_back(cb);
00423                 else if(type==2) postTrackingCallbackVector.push_back(cb);
00424                 else if(type==3) replaceMainLoopCallbackVector.push_back(cb);
00425                 else if(type==4) visualizationCallbackVector.push_back(cb);
00426         }

void BLManager::handleCallbacks ( int  type  ) 

handleCallbacks() calls all applicable registered callbacks. type=0 for pre-reference particle, type=1 for post-center (pre-beam tracking), type=2 for post-beam tracking (just before program exit). type=3 for replacing the main program loop. type=4 for visualization.

References blManager, BLRunManager::callback(), BLNTuple::closeAll(), exceptionSummary(), g4bl_exit(), BLRunManager::getObject(), postReferenceCallbackVector, postTrackingCallbackVector, preReferenceCallbackVector, replaceMainLoopCallbackVector, BLNTuple::summary(), and visualizationCallbackVector.

Referenced by displayVisual(), main(), and Notify().

00529 {
00530         // startup sequencing prevents RunManager from registering
00531         BLRunManager::getObject()->callback(type);
00532 
00533         if(type == 0) {
00534                 for(unsigned i=0; i<preReferenceCallbackVector.size(); ++i)
00535                         preReferenceCallbackVector[i]->callback(type);
00536         } else if(type == 1) {
00537                 for(unsigned i=0; i<postReferenceCallbackVector.size(); ++i)
00538                         postReferenceCallbackVector[i]->callback(type);
00539         } else if(type == 2) {
00540                 for(unsigned i=0; i<postTrackingCallbackVector.size(); ++i)
00541                         postTrackingCallbackVector[i]->callback(type);
00542                 exceptionSummary();
00543         } else if(type == 3) {
00544                 for(unsigned i=0; i<replaceMainLoopCallbackVector.size(); ++i)
00545                         replaceMainLoopCallbackVector[i]->callback(type);
00546                 if(replaceMainLoopCallbackVector.size() > 0) {
00547                         // we have replaced the main loop, so closeup and exit
00548                         BLNTuple::summary();
00549                         BLNTuple::closeAll();
00550                         // handle post-tracking callbacks
00551                         handleCallbacks(2);
00552                         // Instead of deleting things, just open the geometry
00553                         // to avoid warnings when exit() is called.
00554                         G4GeometryManager::GetInstance()->OpenGeometry();
00555                         blManager = 0;
00556                         extern void g4bl_exit(int);
00557                         g4bl_exit(0);
00558                 }
00559         } else if(type == 4) {
00560                 for(unsigned i=0; i<visualizationCallbackVector.size(); ++i)
00561                         visualizationCallbackVector[i]->callback(type);
00562         }
00563 }

G4VPhysicalVolume* BLManager::getWorldPhysicalVolume (  )  [inline]

getWorldPhysicalVolume() returns a pointer to the world PV. Note that it must already have been consructed, so this function returns NULL before construct() is called (by main).

References worldPhysicalVolume.

Referenced by BLCMDtotalenergy::callback(), BLCMDshowmaterial::callback(), and BLCMDmovie::callback().

00440                 { return worldPhysicalVolume; }

void BLManager::setPRNGSeedMethod ( PRNGSeedMethod  method  )  [inline]

setPRNGSeedMethod() will set the method used to seed the pseudo random number generator at the start of each event.

References seedMethod.

Referenced by BLCMDrandomseed::command(), and BLBeam::setRandomSeedToGenerate().

00445                 { seedMethod = method; }

PRNGSeedMethod BLManager::getPRNGSeedMethod (  )  [inline]

getPRNGSeedMethod() will return the method used to seed the pseudo random number generator at the start of each event.

References seedMethod.

00449 { return seedMethod; }

void BLManager::setEventCutFile ( G4String &  f  )  [inline]

setEventCutFile() will set the file containing event s for cutting. The file is ASCII, with one event number per line; lines beginning with # are ignored.

References eventCutFile.

Referenced by BLCMDeventcuts::command().

00454 { eventCutFile = f; }

void BLManager::UserSteppingAction ( const G4Step *  step  ) 

UserSteppingAction() from G4UserSteppingAction.

References allStepMap, allStepVector, BEAM, beamStepMap, beamStepVector, currentZStep, eventTimeLimit, BLCoordinates::getCLZ(), indexZStep, BLCoordinates::isValid(), nStuck, prevZ, REFERENCE, rpStepMap, rpStepVector, ZStepLimiter::setMaxStep(), startEvent, state, steppingVerbose, steppingVerbosePrint(), BLTime::time(), tpStepMap, tpStepVector, tracksAborted, TUNE, BLCoordinates::update(), and zTolerance.

Referenced by BLManager_UserSteppingAction::UserSteppingAction().

00758 {
00759         G4Track *track = step->GetTrack();
00760         G4StepPoint *prePoint = step->GetPreStepPoint();
00761         G4StepPoint *postPoint = step->GetPostStepPoint();
00762         G4VPhysicalVolume *preVol=0;
00763         G4VPhysicalVolume *postVol=0;
00764         if(prePoint) preVol = prePoint->GetPhysicalVolume();
00765         if(postPoint) postVol = postPoint->GetPhysicalVolume();
00766 
00767         // need to update BLCoordinates before steppingVerbose print.
00768         // So BLCoordinates is not registered with SteppingAction, it
00769         // is handled specially, right here.
00770         BLCoordinates::update(track);
00771         BLCoordinates *coord = (BLCoordinates *)track->GetUserInformation();
00772         if(!coord || !coord->isValid()) {
00773                 G4Exception("BLManager","Coordinates Got Lost",FatalException,
00774                                                                         "");
00775         }
00776 
00777         // steppingVerbose print moved to the top of this routine
00778         if(steppingVerbose > 0) { 
00779                 static bool first=true;
00780                 int nstep = track->GetCurrentStepNumber();
00781                 if(first || (nstep <= 1 && !runManager->getCollectiveMode()))
00782                         steppingVerbosePrint(0,0,1);
00783                 steppingVerbosePrint(step,track,0);
00784                 first = false;
00785         }
00786 
00787         /* check for stuck track */
00788         if(step->GetStepLength() > 0.0001*mm ||
00789            step->GetDeltaTime() > 0.0001*ns) {
00790                 nStuck = 0;
00791         } else {
00792                 if(++nStuck >= 100) {
00793                     G4Exception("BLManager Stepping Action",
00794                     "Stuck Track -- Killed",JustWarning,
00795                     "100 steps in a row, each less than 0.1 micron and 0.1 ps");
00796                     ++tracksAborted;
00797                     track->SetTrackStatus(fStopAndKill);
00798                 }
00799         }
00800 
00801         G4TrackStatus status = track->GetTrackStatus();
00802         if(status == fStopAndKill || status == fKillTrackAndSecondaries)
00803                 goto quit;
00804 
00805         // check event time limit
00806         if(eventTimeLimit > 0 && BLTime::time()-startEvent > eventTimeLimit) {
00807                 G4Exception("BLManager","Event Time Limit",EventMustBeAborted,"");
00808                 goto quit;
00809         }
00810 
00811         // call ZStep actions
00812         // NOTE: indexZstep points to the next entry in the +Z direction.
00813         // Note also the bookends constrain indexZStep to always be valid.
00814         if(currentZStep->size() > 2) { // i.e. not just 2 bookends
00815                 G4double thisZ = coord->getCLZ();
00816                 if(thisZ == prevZ) goto noZstep;
00817                 G4double minZ = (thisZ<prevZ ? thisZ : prevZ);
00818                 G4double maxZ = (thisZ>prevZ ? thisZ : prevZ);
00819                 // find first entry that might be spanned by the step
00820                 while(indexZStep > 0 && minZ <= (*currentZStep)[indexZStep-1].z)
00821                         --indexZStep;
00822                 while(minZ > (*currentZStep)[indexZStep].z)
00823                         ++indexZStep;
00824                 int indexPrev = indexZStep-1;
00825                 // loop over all entries actually spanned by this step
00826                 for( ; indexZStep<currentZStep->size()-1; ++indexZStep) {
00827                         G4double z=(*currentZStep)[indexZStep].z;
00828                         if(maxZ <= z) break;
00829                         if((*currentZStep)[indexZStep].action == 0) continue;
00830                         // save current values from track
00831                         G4ThreeVector pos = track->GetPosition();
00832                         G4ThreeVector mom = track->GetMomentum();
00833                         G4double time = track->GetGlobalTime();
00834                         G4double ke = track->GetKineticEnergy();
00835                         // interpolate linearly to z, global coords
00836                         G4ThreeVector deltaPos=step->GetDeltaPosition();
00837                         G4ThreeVector deltaMom=step->GetDeltaMomentum();
00838                         G4double deltaTime=step->GetDeltaTime();
00839                         G4double deltaE=step->GetDeltaEnergy();
00840                         G4double f=(z-thisZ)/(prevZ-thisZ);
00841                         track->SetPosition(pos-f*deltaPos);
00842                         track->SetMomentumDirection((mom-f*deltaMom).unit());
00843                         track->SetGlobalTime(time-f*deltaTime);
00844                         track->SetKineticEnergy(ke-f*deltaE);
00845                         BLCoordinates::update(track);
00846                         (*currentZStep)[indexZStep].action->
00847                                                 UserZSteppingAction(track);
00848                         // restore current values to track
00849                         track->SetPosition(pos);
00850                         track->SetMomentumDirection(mom.unit());
00851                         track->SetGlobalTime(time);
00852                         track->SetKineticEnergy(ke);
00853                         BLCoordinates::update(track);
00854                 }
00855                 double dz = (thisZ>prevZ ? (*currentZStep)[indexZStep].z-thisZ : 
00856                                            thisZ-(*currentZStep)[indexPrev].z);
00857                 dz = (dz>zTolerance*2.0 ? dz : zTolerance*2.0);
00858                 ZStepLimiter::setMaxStep(dz);
00859                 prevZ = thisZ;
00860         }
00861 noZstep:
00862 
00863         // call all-state stepping actions before per-state actions.
00864         { std::vector<BLManager::SteppingAction*>::iterator i;
00865           for(i=allStepVector.begin(); i!=allStepVector.end(); ++i) {
00866                   (*i)->UserSteppingAction(step);
00867                   if(track->GetTrackStatus() != fAlive)
00868                           goto quit;
00869           }
00870           if(preVol && allStepMap.count(preVol) > 0) {
00871                 allStepMap[preVol]->UserSteppingAction(step);
00872                 if(track->GetTrackStatus() != fAlive)
00873                         goto quit;
00874           }
00875           if(postVol  && preVol != postVol && allStepMap.count(postVol) > 0) {
00876                 allStepMap[postVol]->UserSteppingAction(step);
00877                 if(track->GetTrackStatus() != fAlive)
00878                         goto quit;
00879           }
00880         }
00881 
00882         // call Tune Particle stepping actions
00883         if(state == TUNE) {
00884                 std::vector<BLManager::SteppingAction*>::iterator i;
00885                 for(i=tpStepVector.begin(); i!=tpStepVector.end(); ++i) {
00886                         (*i)->UserSteppingAction(step);
00887                         if(track->GetTrackStatus() != fAlive)
00888                                 goto quit;
00889                 }
00890                 if(preVol && tpStepMap.count(preVol) > 0) {
00891                         tpStepMap[preVol]->UserSteppingAction(step);
00892                         if(track->GetTrackStatus() != fAlive)
00893                                 goto quit;
00894                 }
00895                 if(postVol && preVol != postVol && 
00896                                                 tpStepMap.count(postVol) > 0) {
00897                         tpStepMap[postVol]->UserSteppingAction(step);
00898                         if(track->GetTrackStatus() != fAlive)
00899                                 goto quit;
00900                 }
00901         }
00902 
00903         // call Reference Particle stepping actions
00904         if(state == REFERENCE) {
00905                 std::vector<BLManager::SteppingAction*>::iterator i;
00906                 for(i=rpStepVector.begin(); i!=rpStepVector.end(); ++i) {
00907                         (*i)->UserSteppingAction(step);
00908                         if(track->GetTrackStatus() != fAlive)
00909                                 goto quit;
00910                 }
00911                 if(preVol && rpStepMap.count(preVol) > 0) {
00912                         rpStepMap[preVol]->UserSteppingAction(step);
00913                         if(track->GetTrackStatus() != fAlive)
00914                                 goto quit;
00915                 }
00916                 if(postVol && preVol != postVol && 
00917                                                 rpStepMap.count(postVol) > 0) {
00918                         rpStepMap[postVol]->UserSteppingAction(step);
00919                         if(track->GetTrackStatus() != fAlive)
00920                                 goto quit;
00921                 }
00922         }
00923 
00924         // call beam stepping actions
00925         if(state == BEAM) {
00926                 std::vector<BLManager::SteppingAction*>::iterator i;
00927                 for(i=beamStepVector.begin(); i!=beamStepVector.end(); ++i) {
00928                         (*i)->UserSteppingAction(step);
00929                         if(track->GetTrackStatus() != fAlive)
00930                                 goto quit;
00931                 }
00932                 if(preVol && beamStepMap.count(preVol) > 0) {
00933                         beamStepMap[preVol]->UserSteppingAction(step);
00934                         if(track->GetTrackStatus() != fAlive)
00935                                 goto quit;
00936                 }
00937                 if(postVol  && preVol != postVol && 
00938                                              beamStepMap.count(postVol) > 0) {
00939                         beamStepMap[postVol]->UserSteppingAction(step);
00940                         if(track->GetTrackStatus() != fAlive)
00941                                 goto quit;
00942                 }
00943         }
00944 
00945 quit:   ;
00946 }

G4VPhysicalVolume * BLManager::Construct (  ) 

Construct() from G4VUserDetectorConstruction.

References BLGroup::constructWorld(), BLGlobalField::getObject(), and worldPhysicalVolume.

00518 {
00519         // ensure the global field is initialized
00520         (void)BLGlobalField::getObject();
00521 
00522         // construct the world
00523         worldPhysicalVolume =  BLGroup::constructWorld();
00524 
00525         return worldPhysicalVolume;
00526 }

void BLManager::PreUserTrackingAction ( const G4Track *  track  ) 

PreUserTrackingAction() from G4UserTrackingAction.

References beamZStep, currentZStep, eventID, fpTrackingManager, BLCoordinates::getCLZ(), BLRunManager::getCollectiveMode(), getExternalParentID(), BLTrackInfo::getExternalTrackID(), indexZStep, BLCoordinates::isValid(), nextSecondaryTrackID, nStuck, prevZ, primaryParentID, primaryTrackID, REFERENCE, referenceZStep, runManager, BLTrackInfo::setExternalParentID(), BLTrackInfo::setExternalTrackID(), BLCoordinates::setGlobal(), ZStepLimiter::setMaxStep(), state, steppingVerbose, trackID, trackIDMap, trackingActionVector, trackParticleDef, TUNE, tuneZStep, and zTolerance.

Referenced by BLManager_UserTrackingAction::PreUserTrackingAction().

00668 {
00669         static bool first=true;
00670         if(first) {
00671                 first=false;
00672                 std::vector<BLManager::TrackingAction*>::iterator i;
00673                 for(i=trackingActionVector.begin(); 
00674                                          i<trackingActionVector.end(); ++i) {
00675                         (*i)->SetTrackingManagerPointer(fpTrackingManager);
00676                 }
00677         }
00678 
00679         nStuck = 0;
00680 
00681         // link a BLTrackInfo into the track (called coord -- historical)
00682         BLTrackInfo *coord = (BLTrackInfo *)track->GetUserInformation();
00683         if(!coord || !coord->isValid()) {
00684                 coord = new BLTrackInfo();
00685                 ((G4Track *)track)->SetUserInformation(coord);
00686         }
00687         coord->setGlobal(track->GetPosition(),track->GetGlobalTime());
00688 
00689         // set the external trackID and parentID
00690         trackID = coord->getExternalTrackID();
00691         if(trackID <= 0) {
00692                 if(primaryTrackID >= 0) {
00693                         trackID = primaryTrackID;
00694                         coord->setExternalTrackID(trackID);
00695                         coord->setExternalParentID(primaryParentID);
00696                         primaryTrackID = primaryParentID = -1;
00697                 } else {
00698                         trackID = nextSecondaryTrackID++;
00699                         coord->setExternalTrackID(trackID);
00700                         coord->setExternalParentID(
00701                                         trackIDMap[track->GetParentID()]);
00702                 }
00703         }
00704         trackIDMap[track->GetTrackID()] = trackID;
00705         trackParticleDef = track->GetDefinition();
00706 
00707         // print header, if appropriate
00708         if(steppingVerbose && !runManager->getCollectiveMode()) {
00709             printf("=========== Event %d Track %d %s    Parent %d =========\n",
00710                         eventID,trackID,
00711                         trackParticleDef->GetParticleName().c_str(),
00712                         getExternalParentID(track));
00713         }
00714 
00715         // set currentZStep
00716         if(state == TUNE)
00717                 currentZStep = &tuneZStep;
00718         else if(state == REFERENCE)
00719                 currentZStep = &referenceZStep;
00720         else
00721                 currentZStep = &beamZStep;
00722         indexZStep = 1;
00723         prevZ = coord->getCLZ();
00724         while(prevZ > (*currentZStep)[indexZStep].z) {
00725                 ++indexZStep;
00726         }
00727         assert(indexZStep < currentZStep->size());
00728         G4double dz = (*currentZStep)[indexZStep].z - prevZ;
00729         if(dz < zTolerance) dz = zTolerance;
00730         ZStepLimiter::setMaxStep(dz);
00731 
00732         // loop over all registered user tracking actions
00733         std::vector<BLManager::TrackingAction*>::iterator i;
00734         for(i=trackingActionVector.begin(); i<trackingActionVector.end(); ++i) {
00735                 (*i)->PreUserTrackingAction(track);
00736         }
00737 }

void BLManager::PostUserTrackingAction ( const G4Track *  track  ) 

PostUserTrackingAction() from G4UserTrackingAction.

References BLRunManager::getCollectiveMode(), runManager, trackID, trackingActionVector, and trackParticleDef.

Referenced by BLManager_UserTrackingAction::PostUserTrackingAction().

00740 {
00741         std::vector<BLManager::TrackingAction*>::iterator i;
00742         for(i=trackingActionVector.begin(); i<trackingActionVector.end(); ++i) {
00743                 (*i)->PostUserTrackingAction(track);
00744         }
00745 
00746         // delete the BLcoordinates
00747         G4VUserTrackInformation *ti = track->GetUserInformation();
00748         if(ti && !runManager->getCollectiveMode()) {
00749                 delete ti;
00750                 ((G4Track *)track)->SetUserInformation(0);
00751         }
00752 
00753         trackID = -9999;
00754         trackParticleDef = 0;
00755 }

void BLManager::BeginOfRunAction ( const G4Run *  run  ) 

BeginOfRunAction() from G4UserRunAction.

References BEAM, beamRunActionVector, endRun, eventsProcessed, readEventCutFile(), runActionVector, startEvent, startRun, state, and BLTime::time().

Referenced by BLManager_UserRunAction::BeginOfRunAction().

00566 {
00567         readEventCutFile();
00568 
00569         startEvent = startRun = BLTime::time();
00570         eventsProcessed = 0;
00571         endRun = false;
00572 
00573         G4UImanager* UI = G4UImanager::GetUIpointer();
00574         UI->ApplyCommand("/control/verbose 0");
00575         UI->ApplyCommand("/run/verbose 0");
00576         UI->ApplyCommand("/event/verbose 0");
00577         UI->ApplyCommand("/tracking/verbose 0");
00578         UI->ApplyCommand("/hits/verbose 0");
00579         UI->ApplyCommand("/material/verbose 0");
00580         UI->ApplyCommand("/process/setVerbose 0 all");
00581         UI->ApplyCommand("/process/verbose 0");
00582         UI->ApplyCommand("/process/eLoss/verbose 0");
00583 
00584         for(unsigned int i=0; i<runActionVector.size(); ++i)
00585                 runActionVector[i]->BeginOfRunAction(run);
00586 
00587         if(state == BEAM) {
00588                 for(unsigned int i=0; i<beamRunActionVector.size(); ++i)
00589                         beamRunActionVector[i]->BeginOfRunAction(run);
00590         }
00591 }

void BLManager::EndOfRunAction ( const G4Run *  run  ) 

EndOfRunAction() from G4UserRunAction.

References BEAM, beamRunActionVector, eventsProcessed, runActionVector, startRun, state, and BLTime::time().

Referenced by BLManager_UserRunAction::EndOfRunAction().

00594 {
00595         if(state == BEAM) {
00596                 for(unsigned int i=0; i<beamRunActionVector.size(); ++i)
00597                         beamRunActionVector[i]->EndOfRunAction(run);
00598         }
00599 
00600         for(unsigned int i=0; i<runActionVector.size(); ++i)
00601                 runActionVector[i]->EndOfRunAction(run);
00602 
00603         printf("Run complete  %d Events  %ld seconds\n",
00604                         eventsProcessed,(long)(BLTime::time()-startRun));
00605 }

void BLManager::BeginOfEventAction ( const G4Event *  event  ) 

BeginOfEventAction() from G4UserEventAction.

References BEAM, beamEventActionVector, endRun, eventActionVector, eventTimeLimit, BLRunManager::getCollectiveMode(), runManager, BLAlarm::set(), startEvent, state, steppingVerbose, and BLTime::time().

Referenced by BLRunManager::beamOnCollective(), BLRunManager::beginEvent(), and BLManager_UserEventAction::BeginOfEventAction().

00608 {
00609         if(endRun || event->IsAborted()) return;
00610 
00611         if(state == BEAM) {
00612 
00613             int evId = event->GetEventID();
00614             if(steppingVerbose && !runManager->getCollectiveMode()) 
00615                 printf("\n\n=================== Event %d ==================\n",
00616                                                                 evId);
00617 
00618             // call all registered action-s
00619             std::vector<BLManager::EventAction*>::iterator i;
00620             for(i=beamEventActionVector.begin(); i<beamEventActionVector.end(); ++i) {
00621                 (*i)->BeginOfEventAction(event);
00622             }
00623         }
00624 
00625         // call all registered action-s
00626         std::vector<BLManager::EventAction*>::iterator i;
00627         for(i=eventActionVector.begin(); i<eventActionVector.end(); ++i) {
00628                 (*i)->BeginOfEventAction(event);
00629         }
00630 
00631         startEvent = BLTime::time();
00632         // add 2 seconds so the test in UserSteppingAction() can try first
00633         // (it kills 1 event, BLAlarm kills the entire job).
00634         if(eventTimeLimit > 0) BLAlarm::set(eventTimeLimit+2);
00635 }

void BLManager::EndOfEventAction ( const G4Event *  event  ) 

EndOfEventAction() from G4UserEventAction.

References BEAM, beamEventActionVector, BLAlarm::clear(), endRun, eventActionVector, eventsProcessed, BLNTuple::flushAll(), histoUpdate, incrEventsProcessed(), state, and BLNTuple::update().

Referenced by BLRunManager::endEvent(), and BLManager_UserEventAction::EndOfEventAction().

00638 {
00639         BLAlarm::clear();
00640 
00641         if(endRun || event->IsAborted()) return;
00642 
00643         // call all registered action-s
00644         std::vector<BLManager::EventAction*>::iterator i;
00645         for(i=eventActionVector.begin(); i<eventActionVector.end(); ++i) {
00646                 (*i)->EndOfEventAction(event);
00647         }
00648 
00649         if(state != BEAM) return;
00650 
00651         // call all registered action-s
00652         for(i=beamEventActionVector.begin(); i<beamEventActionVector.end(); ++i) {
00653                 (*i)->EndOfEventAction(event);
00654         }
00655         BLNTuple::update();
00656 
00657         if(endRun) return;
00658 
00659         incrEventsProcessed(event->GetEventID());
00660 
00661         // update histogram file, if appropriate
00662         if(histoUpdate > 0 && eventsProcessed%histoUpdate == 0 && 
00663            eventsProcessed > 0)
00664                 BLNTuple::flushAll();
00665 }

void BLManager::GeneratePrimaries ( G4Event *  event  ) 

GeneratePrimaries() from G4VUserPrimaryGeneratorAction.

References BEAM, beamIndex, beamVector, endRun, eventID, IDLE, prevEventID, REFERENCE, referenceVector, runManager, setEventID(), skipEvent(), SPECIAL, state, TUNE, and VISUAL.

Referenced by BLCMDtrackermode::callback(), and BLManager_PrimaryGeneratorAction::GeneratePrimaries().

00949 {
00950         if(beamVector.size() == 0) {
00951                 G4Exception("BLManager","No beam registered",FatalException,
00952                                                                         "");
00953         }
00954 
00955         switch(state) {
00956         case IDLE:
00957         case SPECIAL:
00958                 G4Exception("BLManager","Erroneous call to GeneratePrimaries",
00959                                                         FatalException,"");
00960         case TUNE:
00961                 setEventID(-2);
00962                 event->SetEventID(-2);
00963                 while(beamIndex < referenceVector.size()) {
00964                         if(referenceVector[beamIndex++]->
00965                                         generateReferenceParticle(event))
00966                                 return;
00967                 }
00968                 goto end_run;
00969         case REFERENCE:
00970                 setEventID(-1);
00971                 event->SetEventID(-1);
00972                 while(beamIndex < referenceVector.size()) {
00973                         if(referenceVector[beamIndex++]->
00974                                         generateReferenceParticle(event))
00975                                 return;
00976                 }
00977                 goto end_run;
00978         case VISUAL:
00979         case BEAM:
00980                 for(;;) {
00981                         // use tempEvent so we can skip events when necessary
00982                         G4Event *tempEvent = new G4Event(*event);
00983                         // default event # (nextBeamEvent() can change it)
00984                         eventID = prevEventID + 1;
00985                         event->SetEventID(eventID);
00986                         // generate the tempEvent, indexing through beamVector[]
00987                         if(beamIndex >= beamVector.size()) {
00988                                 goto end_run;
00989                         }
00990                         while(!beamVector[beamIndex]->nextBeamEvent(tempEvent)){
00991                                 if(++beamIndex >= beamVector.size())
00992                                         goto end_run;
00993                         }
00994                         // update eventID (may have changed)
00995                         eventID = tempEvent->GetEventID();
00996                         prevEventID = eventID; // (this increments it, too)
00997                         // skip events when necessary
00998                         if(!skipEvent(eventID)) {
00999                                 *event = *tempEvent;
01000                                 delete tempEvent;
01001                                 break;
01002                         }
01003                         delete tempEvent;
01004                 }
01005                 break;
01006         }
01007         return;
01008 end_run:
01009         // RunManager cannot abort the event from inside
01010         // UserGeneratePrimaries(), so we do a soft abort
01011         // to the RunManager, and abort the event ourself.
01012         // The result is the same as a hard abort.
01013         runManager->AbortRun(true);
01014         event->SetEventAborted();
01015         beamIndex = 0;
01016         endRun = true;
01017 }

G4ClassificationOfNewTrack BLManager::ClassifyNewTrack ( const G4Track *  track  ) 

ClassifyNewTrack() from G4UserStackingAction.

References stackingActionVector.

Referenced by BLManager_UserStackingAction::ClassifyNewTrack().

01020 {
01021         std::vector<BLManager::StackingAction*>::iterator i;
01022         for(i=stackingActionVector.begin(); i<stackingActionVector.end(); ++i) {
01023                 G4ClassificationOfNewTrack c = (*i)->ClassifyNewTrack(track);
01024                 if(c == fKill) return c;
01025         }
01026         return fUrgent;
01027 }

void BLManager::NewStage (  ) 

NewStage() from G4userStackingAction.

References stackingActionVector.

Referenced by BLManager_UserStackingAction::NewStage().

01030 {
01031         std::vector<BLManager::StackingAction*>::iterator i;
01032         for(i=stackingActionVector.begin(); i<stackingActionVector.end(); ++i) {
01033                 (*i)->NewStage();
01034         }
01035 }

void BLManager::PrepareNewEvent (  ) 

PrepareNewEvent() from G4StackingAction.

References stackingActionVector.

Referenced by BLManager_UserStackingAction::PrepareNewEvent().

01038 {
01039         std::vector<BLManager::StackingAction*>::iterator i;
01040         for(i=stackingActionVector.begin(); i<stackingActionVector.end(); ++i) {
01041                 (*i)->PrepareNewEvent();
01042         }
01043 }

void BLManager::clearTrackIDMap (  )  [inline]

void BLManager::setNextSecondaryTrackID ( int  next  )  [inline]

setNextSecondaryTrackID() sets the external TrackID for the next secondary track. Automatically incremented for subsequent secondaries.

References nextSecondaryTrackID.

Referenced by BLCMDreference::generateReferenceParticle(), BLCMDparticlesource::nextBeamEvent(), and BLCMDbeam::nextBeamEvent().

00504 { nextSecondaryTrackID = next; }

int BLManager::getNextSecondaryTrackID (  )  [inline]

References nextSecondaryTrackID.

Referenced by BLRunManager::beamOnCollective().

00505 { return nextSecondaryTrackID; }

int BLManager::getExternalTrackID ( const G4Track *  track  ) 

int BLManager::getExternalParentID ( const G4Track *  track  ) 

void BLManager::setExternalTrackID ( G4Track *  track,
int  trackID,
int  parentID 
)

setExternalTrackID() will set the external trackID and parentID. if trackID<0 uses nextSecondarTrackID++.

References BLCoordinates::isValid(), nextSecondaryTrackID, BLTrackInfo::setExternalParentID(), and BLTrackInfo::setExternalTrackID().

01064 {
01065         if(trackID < 0) trackID = nextSecondaryTrackID++;
01066 
01067         BLTrackInfo *ti = (BLTrackInfo *)track->GetUserInformation();
01068         if(!ti || !ti->isValid()) {
01069                 ti = new BLTrackInfo();
01070                 track->SetUserInformation(ti);
01071         }
01072         ti->setExternalTrackID(trackID);
01073         ti->setExternalParentID(parentID);
01074 }

int BLManager::getPrimaryTrackID (  )  [inline]

getPrimaryTrackID() returns the primaryTrackID set by the beam command

References primaryTrackID.

Referenced by BLRunManager::beamOnCollective(), and BLRunManager::getNextBeamEventAndTrack().

00522 { return primaryTrackID; }

int BLManager::getPrimaryParentID (  )  [inline]

getPrimaryParentID() returns the primaryParentID set by the beam command

References primaryParentID.

Referenced by BLRunManager::getNextBeamEventAndTrack().

00525 { return primaryParentID; }

void BLManager::setPrimaryTrackID ( int  t,
int  p 
) [inline]

G4bool BLManager::Notify ( const char *  originOfException,
const char *  exceptionCode,
G4ExceptionSeverity  severity,
const char *  description 
)

Notify() from G4VExceptionHandler.

References BLNTuple::closeAll(), eventID, eventsAborted, exceptionCount, fatalExceptions, g4bl_exit(), handleCallbacks(), BLMPI::isMPI(), runManager, BLNTuple::summary(), trackID, trackParticleDef, and warnings.

01099 {
01100         FILE *out=(BLMPI::isMPI() ? stderr : stdout);   // originally was stderr
01101         fflush(stdout);
01102 
01103         G4bool toBeAborted = false;
01104         const char *p="UNKNOWN";
01105         switch(severity) {
01106         case FatalException:
01107                 p = "Fatal Exception";          
01108                 toBeAborted = true;
01109                 ++fatalExceptions;
01110                 break;
01111         case FatalErrorInArgument:
01112                 p = "Fatal Error in Argument";  
01113                 toBeAborted = true;
01114                 ++fatalExceptions;
01115                 break;
01116         case RunMustBeAborted:
01117                 p = "Run Must Be Aborted";
01118                 runManager->AbortRun(false);
01119                 toBeAborted = false;
01120                 ++fatalExceptions;
01121                 break;
01122         case EventMustBeAborted:
01123                 p = "Event must be Aborted";
01124                 runManager->AbortEvent();
01125                 toBeAborted = false;
01126                 ++eventsAborted;
01127                 break;
01128         default:
01129                 p = "Warning";
01130                 toBeAborted = false;
01131                 ++warnings;
01132                 break;
01133         }
01134 
01135         // thin out the printing of many similar exceptions
01136         int n = ++exceptionCount[exceptionCode];
01137         int interval = 1;
01138         if(n >= 1000)
01139                 interval = 1000;
01140         else if(n >= 100)
01141                 interval = 100;
01142         else if(n >= 10)
01143                 interval = 10;
01144         if(n%interval != 0)
01145                 return toBeAborted;
01146 
01147         fprintf(out,"**************************************************************************\n");
01148         fprintf(out,"*** G4Exception: %s\n",exceptionCode);
01149         fprintf(out,"***    severity: %s\n",p);
01150         fprintf(out,"***   issued by: %s\n",originOfException);
01151         if(strlen(description) > 0)
01152                 fprintf(out,"*** description: %s\n",description);
01153         if(strstr(description,"Missing mandatory data")) {
01154                 // brief description already printed, just URL is missing
01155                 const char *p = getenv("G4BL_DIR");
01156                 if(!p) p = "Installation_Directory";
01157                 fprintf(out,
01158                     "***              The URL is http://geant4.cern.ch\n"
01159                     "***              If you unpack it into %s/data\n"
01160                     "***              then the g4bl and g4blgui scripts will"
01161                     " automatically find it.\n",p);
01162         } else if(G4StateManager::GetStateManager()->GetCurrentState() ==
01163                                 G4State_EventProc && trackParticleDef != 0) {
01164                 fprintf(out,"***     EventID: %d     TrackID: %d   %s\n",
01165                                 eventID,trackID,
01166                                 trackParticleDef->GetParticleName().c_str());
01167         }
01168         if(interval > 1)
01169                 fprintf(out,"***    printing: every %d-th occurrence\n",
01170                         interval);
01171         fprintf(out,"**************************************************************************\n");
01172 
01173         fflush(out); // (could be stdout)
01174 
01175         if(toBeAborted) {
01176                 fprintf(out,"g4beamline: attempting to close up after fatal G4Exception...\n");
01177                 BLNTuple::summary();
01178                 BLNTuple::closeAll();
01179                 handleCallbacks(2);
01180                 fprintf(out,"g4beamline: simulation aborted\n");
01181                 extern void g4bl_exit(int);
01182                 g4bl_exit(99);
01183         }
01184 
01185         return toBeAborted;
01186 }

void BLManager::exceptionSummary (  ) 

exceptionSummary() prints a summary of all exceptions

References eventsAborted, exceptionCount, fatalExceptions, tracksAborted, and warnings.

Referenced by handleCallbacks().

01189 {
01190         printf("\nException Summary: %d Fatal, %d Events Aborted, "
01191                         "%d Tracks Aborted, %d Warnings\n",
01192                         fatalExceptions,eventsAborted,tracksAborted,warnings);
01193         std::map<G4String,int>::iterator it;
01194         for(it=exceptionCount.begin(); it!=exceptionCount.end(); ++it) {
01195                 G4String except = it->first;
01196                 int count = it->second;
01197                 printf(" %6d times: %s\n",count,except.c_str());
01198         }
01199 }


Member Data Documentation

BLManager * BLManager::blManager = 0 [static, private]

bool BLManager::initialized = false [static, private]

Referenced by initialize(), and isInitialized().

G4int BLManager::steppingVerbose [private]

unsigned int BLManager::beamIndex [private]

G4int BLManager::histoUpdate [private]

time_t BLManager::startRun [private]

time_t BLManager::startEvent [private]

G4int BLManager::eventTimeLimit [private]

G4VPhysicalVolume* BLManager::worldPhysicalVolume [private]

G4int BLManager::eventID [private]

G4int BLManager::trackID [private]

G4ParticleDefinition* BLManager::trackParticleDef [private]

G4int BLManager::fatalExceptions [private]

Referenced by BLManager(), exceptionSummary(), and Notify().

G4int BLManager::eventsAborted [private]

Referenced by BLManager(), exceptionSummary(), and Notify().

G4int BLManager::tracksAborted [private]

G4int BLManager::warnings [private]

Referenced by BLManager(), exceptionSummary(), and Notify().

G4int BLManager::prevEventID [private]

G4int BLManager::eventsProcessed [private]

bool BLManager::endRun [private]

G4String BLManager::eventCutFile [private]

std::set<int> BLManager::eventList [private]

Referenced by readEventCutFile(), and skipEvent().

G4SteppingManager* BLManager::fpSteppingManager [private]

G4TrackingManager* BLManager::fpTrackingManager [private]

std::vector<BLBeam*> BLManager::beamVector [private]

std::vector<BLBeam*> BLManager::referenceVector [private]

std::vector<RunAction*> BLManager::runActionVector [private]

std::vector<RunAction*> BLManager::beamRunActionVector [private]

std::vector<EventAction*> BLManager::eventActionVector [private]

std::vector<SteppingAction*> BLManager::allStepVector [private]

std::map<G4VPhysicalVolume*,SteppingAction*> BLManager::allStepMap [private]

std::map<G4VPhysicalVolume*,SteppingAction*> BLManager::tpStepMap [private]

std::map<G4VPhysicalVolume*,SteppingAction*> BLManager::rpStepMap [private]

std::vector<SteppingAction*> BLManager::tpStepVector [private]

std::vector<SteppingAction*> BLManager::rpStepVector [private]

std::map<G4VPhysicalVolume*,SteppingAction*> BLManager::beamStepMap [private]

std::vector<SteppingAction*> BLManager::beamStepVector [private]

std::vector<int> BLManager::verboseFormat [private]

G4double BLManager::zTolerance [private]

std::vector<ZStep> BLManager::tuneZStep [private]

std::vector<ZStep> BLManager::referenceZStep [private]

std::vector<ZStep> BLManager::beamZStep [private]

std::vector<ZStep>* BLManager::currentZStep [private]

unsigned BLManager::indexZStep [private]

G4double BLManager::prevZ [private]

G4int BLManager::nStuck [private]

std::map<G4int,G4int> BLManager::trackIDMap [private]

std::vector<BLUserCode*> BLManager::userCodeVector [private]

std::map<G4String,int> BLManager::exceptionCount [private]

Referenced by exceptionSummary(), and Notify().


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