Primary Particle Generation, Tracking & Stacking

29
Primary Particle Generation, Primary Particle Generation, Tracking & Stacking Tracking & Stacking Makoto Asai (SLAC) Makoto Asai (SLAC) Geant4 Tutorial Course @ Bordeaux Geant4 Tutorial Course @ Bordeaux November 2005 November 2005 November 2005, Geant4 v7.1

Transcript of Primary Particle Generation, Tracking & Stacking

Page 1: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation,Primary Particle Generation,

Tracking & StackingTracking & Stacking

Makoto Asai (SLAC)Makoto Asai (SLAC)

Geant4 Tutorial Course @ BordeauxGeant4 Tutorial Course @ Bordeaux

November 2005November 2005

November 2005, Geant4 v7.1

Page 2: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 22

ContentsContents

�� Primary particle generationPrimary particle generation

�� G4VUserPrimaryGeneratorActionG4VUserPrimaryGeneratorAction

�� Primary vertex and primary particlePrimary vertex and primary particle

�� BuiltBuilt--in primary particle generatorsin primary particle generators

�� Tracking mechanism in Geant4Tracking mechanism in Geant4

�� Tracking mechanismTracking mechanism

�� Track and step statusesTrack and step statuses

�� Attaching user Attaching user informationinformation

�� StackingStacking mechanismmechanism

Page 3: Primary Particle Generation, Tracking & Stacking

Primary particle generationPrimary particle generation

Page 4: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 44

User classesUser classes�� Initialization classesInitialization classes

�� Use G4RunManager::SetUserInitialization() to define.Use G4RunManager::SetUserInitialization() to define.

�� Invoked at the initializationInvoked at the initialization

�� G4VUserDetectorConstructionG4VUserDetectorConstruction

�� G4VUserPhysicsListG4VUserPhysicsList

�� Action classesAction classes

�� Use G4RunManager::SetUserAction() to define.Use G4RunManager::SetUserAction() to define.

�� Invoked during an event loopInvoked during an event loop

�� G4VUserPrimaryGeneratorActionG4VUserPrimaryGeneratorAction

�� G4UserRunActionG4UserRunAction

�� G4UserEventActionG4UserEventAction

�� G4UserStackingActionG4UserStackingAction

�� G4UserTrackingActionG4UserTrackingAction

�� G4UserSteppingActionG4UserSteppingAction

�� main()main()

�� Geant4 does not provide Geant4 does not provide main().main().

Note : classes written in Note : classes written in yellowyellow are mandatory.are mandatory.

Page 5: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 55

G4VUserPrimaryGeneratorActionG4VUserPrimaryGeneratorAction�� This class is one of mandatory user action classes to This class is one of mandatory user action classes to control the generationcontrol the generation of of

primaries.primaries.

�� This class itself This class itself should NOTshould NOT generate primaries but generate primaries but invokeinvoke

GeneratePrimaryVertexGeneratePrimaryVertex ()() method of primary method of primary generator(sgenerator(s) to make ) to make

primaries.primaries.

�� ConstructorConstructor

�� Instantiate primary Instantiate primary generator(sgenerator(s))

�� Set default values to Set default values to it(themit(them))

�� GeneratePrimariesGeneratePrimaries() method() method

�� Randomize particleRandomize particle--byby--particle particle value(svalue(s))

�� Set them to primary Set them to primary generator(sgenerator(s))

�� Never use hardNever use hard--coded UI commandscoded UI commands

�� Invoke Invoke GeneratePrimaryVertexGeneratePrimaryVertex ()() method of primary method of primary generator(sgenerator(s))

Page 6: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 66

Primary vertices and particlesPrimary vertices and particles�� Primary vertices and primary particles should be stored in G4EvePrimary vertices and primary particles should be stored in G4Event before nt before

processing an event.processing an event.

�� G4PrimaryVertexG4PrimaryVertex and and G4PrimaryParticleG4PrimaryParticle classesclasses

�� These classes donThese classes don’’t have any dependency to G4ParticleDefinition nor t have any dependency to G4ParticleDefinition nor

G4Track.G4Track.

�� Capability of bookkeeping decay chainsCapability of bookkeeping decay chains

�� Primary particles Primary particles may notmay not necessarily be particles which can be tracked necessarily be particles which can be tracked

by Geant4.by Geant4.

�� Geant4 provides some concrete implementations of Geant4 provides some concrete implementations of G4VPrimaryGeneratorG4VPrimaryGenerator..

�� G4ParticleGunG4ParticleGun

�� G4HEPEvtInterfaceG4HEPEvtInterface

�� G4HEPMCInterfaceG4HEPMCInterface

�� G4GeneralParticleSourceG4GeneralParticleSource

Page 7: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 77

G4ParticleGunG4ParticleGun�� Concrete implementations of G4VPrimaryGeneratorConcrete implementations of G4VPrimaryGenerator

�� A good example for experimentA good example for experiment--specific primary generator implementationspecific primary generator implementation

�� It shoots one primary particle of a certain energy from a certaiIt shoots one primary particle of a certain energy from a certain point at a n point at a certain time to a certain direction.certain time to a certain direction.

�� Various set methods are availableVarious set methods are available

�� Intercoms commands are also availableIntercoms commands are also available

�� One of most frequently asked questions is :One of most frequently asked questions is :

I want I want ““particle shotgunparticle shotgun””, , ““particle machinegunparticle machinegun””, etc. , etc.

�� Instead of implementing such a fancy weapon, in your implementatInstead of implementing such a fancy weapon, in your implementation of ion of

UserPrimaryGeneratorActionUserPrimaryGeneratorAction, you can, you can

�� Shoot random numbers in arbitrary distributionShoot random numbers in arbitrary distribution

�� Use set methods of G4ParticleGunUse set methods of G4ParticleGun

�� Use G4ParticleGun as many times as you wantUse G4ParticleGun as many times as you want

�� Use any other primary generators as many times as you want to maUse any other primary generators as many times as you want to make ke

overlapping eventsoverlapping events

Page 8: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 88

G4VUserPrimaryGeneratorActionG4VUserPrimaryGeneratorActionvoid T01PrimaryGeneratorAction::void T01PrimaryGeneratorAction::

GeneratePrimaries(G4Event* GeneratePrimaries(G4Event* anEventanEvent )){ G4ParticleDefinition* particle;{ G4ParticleDefinition* particle;

G4int i = (int)(5.*G4UniformRand());G4int i = (int)(5.*G4UniformRand());switch(i)switch(i){ case 0: particle = positron; break; ... }{ case 0: particle = positron; break; ... }particleGunparticleGun -- >>SetParticleDefinition(particleSetParticleDefinition(particle ););G4double pp =G4double pp =

momentum+(G4UniformRand()momentum+(G4UniformRand() -- 0.5)*0.5)* sigmaMomentumsigmaMomentum ;;G4double mass = particleG4double mass = particle -- >>GetPDGMassGetPDGMass();();G4double G4double EkinEkin = = sqrt(ppsqrt(pp *pp+mass*mass)*pp+mass*mass) -- mass;mass;particleGunparticleGun -- >>SetParticleEnergy(EkinSetParticleEnergy(Ekin ););G4double angle = (G4UniformRand()G4double angle = (G4UniformRand() -- 0.5)*0.5)* sigmaAnglesigmaAngle ;;particleGunparticleGun -- >>SetParticleMomentumDirectionSetParticleMomentumDirection

(G4ThreeVector(sin(angle),0.,cos(angle)));(G4ThreeVector(sin(angle),0.,cos(angle)));particleGunparticleGun -- >>GeneratePrimaryVertex(anEventGeneratePrimaryVertex(anEvent ););

}}

�� You can repeat this for generating more than one primary particlYou can repeat this for generating more than one primary particles.es.

Page 9: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 99

Interfaces to Interfaces to HEPEvtHEPEvt and and HepMCHepMC

�� Concrete implementations of G4VPrimaryGeneratorConcrete implementations of G4VPrimaryGenerator

�� A good example for experimentA good example for experiment--specific primary generator implementationspecific primary generator implementation

�� G4HEPEvtInterfaceG4HEPEvtInterface

�� Suitable to /HEPEVT/ common block, which many of (FORTRAN) HEP Suitable to /HEPEVT/ common block, which many of (FORTRAN) HEP

physics generators are compliant to.physics generators are compliant to.

�� ASCII file inputASCII file input

�� G4HepMCInterfaceG4HepMCInterface

�� An interface to An interface to HepMCHepMC class, which a few new (C++) HEP physics class, which a few new (C++) HEP physics

generators are compliant to.generators are compliant to.

�� ASCII file input or direct linking to a generator through ASCII file input or direct linking to a generator through HepMCHepMC..

Page 10: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 1010

G4GeneralParticleSourceG4GeneralParticleSource

�� A concrete implementation of G4VPrimaryGeneratorA concrete implementation of G4VPrimaryGenerator

�� Suitable especially to space applicationsSuitable especially to space applications

MyPrimaryGeneratorActionMyPrimaryGeneratorAction ::::

MyPrimaryGeneratorActionMyPrimaryGeneratorAction ()()

{ { generator = new G4GeneralParticleSource;generator = new G4GeneralParticleSource; }}

void void MyPrimaryGeneratorActionMyPrimaryGeneratorAction ::::

GeneratePrimaries(G4Event* GeneratePrimaries(G4Event* anEventanEvent ))

{ { generatorgenerator -- >>GeneratePrimaryVertex(anEventGeneratePrimaryVertex(anEvent ); ); }}

�� Detailed descriptionDetailed description

http://http://reat.space.qinetiq.com/gpsreat.space.qinetiq.com/gps//

Page 11: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 1111

G4GeneralParticleSourceG4GeneralParticleSource

�� Primary vertex can be randomly chosen on the surface of a certaiPrimary vertex can be randomly chosen on the surface of a certain volume.n volume.

�� Momentum direction and kinetic energy of the primary particle caMomentum direction and kinetic energy of the primary particle can also be n also be

randomized.randomized.

�� Distribution could be set by UI commands.Distribution could be set by UI commands.

�� Capability of event biasing (variance reduction).Capability of event biasing (variance reduction).

�� By enhancing particle type, distribution of vertex point, energyBy enhancing particle type, distribution of vertex point, energy and/or and/or

directiondirection

Square plane, cosine-law direction, linear energy Spherical surface, isotropic radiation, black-body energy Cylindrical surface, cosine-law radiation, Cosmic diffuse

energy Spherical volume with z biasing, isotropic radiation with theta and phi biasing, integral arbitrary point-wise energy distribution with linear interpolation.

Page 12: Primary Particle Generation, Tracking & Stacking

Tracking mechanismTracking mechanism

in Geant4in Geant4

Page 13: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 1313

Tracking and processesTracking and processes

�� Geant4 tracking is general. Geant4 tracking is general.

�� It is independent to It is independent to

�� the particle type the particle type

�� the physics processes involving to a particlethe physics processes involving to a particle

�� It gives the chance to all processes It gives the chance to all processes

�� To contribute to determining the step lengthTo contribute to determining the step length

�� To contribute any possible changes in physical quantities of theTo contribute any possible changes in physical quantities of the

tracktrack

�� To generate secondary particlesTo generate secondary particles

�� To suggest changes in the state of the trackTo suggest changes in the state of the track

�� e.g. to suspend, postpone or kill it.e.g. to suspend, postpone or kill it.

Page 14: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 1414

Processes in Geant4Processes in Geant4�� In Geant4, particle transportation is a process as well, by whicIn Geant4, particle transportation is a process as well, by which a h a

particle interacts with geometrical volume boundaries and field particle interacts with geometrical volume boundaries and field of any of any

kind.kind.

�� Because of this, shower parameterization process can take over fBecause of this, shower parameterization process can take over from rom

the ordinary transportation without modifying the transportationthe ordinary transportation without modifying the transportation

process.process.

�� Each particle type has its own list of applicable processes. At Each particle type has its own list of applicable processes. At each step, each step,

all processes listed are invoked to get proposed physical interaall processes listed are invoked to get proposed physical interaction ction

lengths.lengths.

�� The process which requires the shortest interaction length (in sThe process which requires the shortest interaction length (in spacepace--

time) limits the step. time) limits the step.

�� All processes are derived from All processes are derived from G4VProcessG4VProcess abstract base class. Each abstract base class. Each

particle type has its individual particle type has its individual G4ProcessManagerG4ProcessManager class object which class object which

holds a vector of assigned processes.holds a vector of assigned processes.

Page 15: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 1515

Process and stepProcess and step�� Each process has one or combination of the following natures.Each process has one or combination of the following natures.

�� AtRestAtRest

�� e.g. e.g. muonmuon decay at restdecay at rest

�� AlongStepAlongStep (a.k.a. continuous process)(a.k.a. continuous process)

�� e.g. e.g. CelenkovCelenkov processprocess

�� PostStepPostStep (a.k.a. discrete process)(a.k.a. discrete process)

�� e.g. decay on the flye.g. decay on the fly

�� Continuous processes contribute cumulatively along the step, whiContinuous processes contribute cumulatively along the step, while le

discrete processes contribute selectively (if not exclusively) adiscrete processes contribute selectively (if not exclusively) at the end t the end

point of the step. point of the step.

�� A special process, e.g. shower parameterization process, may takA special process, e.g. shower parameterization process, may take e

over all continuous and discrete processes.over all continuous and discrete processes.

Page 16: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 1616

How Geant4 runs (one step)How Geant4 runs (one step)

Stepping Manager

Physics Process

Particle Change

Step Track Logical Volume

Sensitive Detector

GetPhysicalInteractionLengthGetPhysicalInteractionLengthGetPhysicalInteractionLengthGetPhysicalInteractionLength

SelectShortestSelectShortestSelectShortestSelectShortest

DoItDoItDoItDoItFillFillFillFill

UpdateUpdateUpdateUpdate

UpdateUpdateUpdateUpdate

IsSensitiveIsSensitiveIsSensitiveIsSensitive

GenerateHitsGenerateHitsGenerateHitsGenerateHits

Page 17: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 1717

Track statusTrack status�� At the end of each step, according to the processes involved, thAt the end of each step, according to the processes involved, the state of a e state of a

track may be changed.track may be changed.

�� The user can also change the status in The user can also change the status in UserSteppingActionUserSteppingAction..

�� Statuses shown in Statuses shown in yellowyellow are artificial, i.e. Geant4 kernel wonare artificial, i.e. Geant4 kernel won’’t set them, t set them, but the user can set.but the user can set.

�� fAlivefAlive

�� Continue the tracking.Continue the tracking.

�� fStopButAlivefStopButAlive

�� The track has come to zero kinetic energy, but still The track has come to zero kinetic energy, but still AtRestAtRest process to occur.process to occur.

�� fStopAndKillfStopAndKill

�� The track has lost its identity because it has decayed, interactThe track has lost its identity because it has decayed, interacted or gone ed or gone beyond the world boundary.beyond the world boundary.

�� SecondariesSecondaries will be pushed to the stack.will be pushed to the stack.

�� fKillTrackAndSecondariesfKillTrackAndSecondaries

�� Kill the current track and also associated Kill the current track and also associated secondariessecondaries..

�� fSuspendfSuspend

�� Suspend processing of the current track and push it and its Suspend processing of the current track and push it and its secondariessecondaries to to the stack.the stack.

�� fPostponeToNextEventfPostponeToNextEvent

�� Postpone processing of the current track to the next event. Postpone processing of the current track to the next event.

�� SecondariesSecondaries are still being processed within the current event.are still being processed within the current event.

Page 18: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 1818

Set the track statusSet the track status�� In In UserSteppingActionUserSteppingAction, user can change the status of a track., user can change the status of a track.

void void MySteppingAction::UserSteppingActionMySteppingAction::UserSteppingAction

(const G4Step * (const G4Step * theSteptheStep ))

{{

G4Track* G4Track* theTracktheTrack = = theSteptheStep -- >>GetTrackGetTrack ();();

if(if( ……) ) theTracktheTrack -- >>SetTrackStatusSetTrackStatus (fSuspend(fSuspend ););

}}

�� If a track is killed in If a track is killed in UserSteppingActionUserSteppingAction, physics quantities of the track (energy, , physics quantities of the track (energy,

charge, etc.) are not conserved but completely lost.charge, etc.) are not conserved but completely lost.

Page 19: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 1919

Step statusStep status�� Step status is attached to G4StepPoint to indicate why that partStep status is attached to G4StepPoint to indicate why that particular step was icular step was

determined.determined.

�� Use Use ““PostPostStepPointStepPoint”” to get the status of this step.to get the status of this step.

�� ““PrePreStepPointStepPoint”” has the status of the previous step.has the status of the previous step.

�� fWorldBoundaryfWorldBoundary

�� Step reached the world boundaryStep reached the world boundary

�� fGeomBoundaryfGeomBoundary

�� Step is limited by a volume boundary except the worldStep is limited by a volume boundary except the world

�� fAtRestDoItProcfAtRestDoItProc, , fAlongStepDoItProcfAlongStepDoItProc, , fPostStepDoItProcfPostStepDoItProc

�� Step is limited by a Step is limited by a AtRestAtRest, , AlongStepAlongStep or or PostStepPostStep processprocess

�� fUserDefinedLimitfUserDefinedLimit

�� Step is limited by the user Step limitStep is limited by the user Step limit

�� fExclusivelyForcedProcfExclusivelyForcedProc

�� Step is limited by an exclusively forced (e.g. shower parameteriStep is limited by an exclusively forced (e.g. shower parameterization) zation) process process

�� fUndefinedfUndefined

�� Step not defined yetStep not defined yet

�� If you want to identify If you want to identify the first step in a volumethe first step in a volume, pick , pick fGeomBoudaryfGeomBoudary status in status in PreStepPointPreStepPoint. .

�� If you want to identify If you want to identify a step getting out of a volumea step getting out of a volume, pick , pick fGeomBoundaryfGeomBoundarystatus in status in PostStepPointPostStepPoint

Page 20: Primary Particle Generation, Tracking & Stacking

Attaching user information to Attaching user information to

some kernel classessome kernel classes

Page 21: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 2121

Attaching user informationAttaching user information

�� Abstract classesAbstract classes

�� User can use his/her own class derived from the provided base clUser can use his/her own class derived from the provided base classass

�� G4Run, G4VHit, G4VDigit, G4VTrajectory, G4VTrajectoryPointG4Run, G4VHit, G4VDigit, G4VTrajectory, G4VTrajectoryPoint

�� Concrete classesConcrete classes

�� User can attach a user information class objectUser can attach a user information class object

�� G4Event G4Event -- G4VUserEventInformationG4VUserEventInformation

�� G4Track G4Track -- G4VUserTrackInformationG4VUserTrackInformation

�� G4PrimaryVertex G4PrimaryVertex -- G4VUserPrimaryVertexInformationG4VUserPrimaryVertexInformation

�� G4PrimaryParticle G4PrimaryParticle -- G4VUserPrimaryParticleInformationG4VUserPrimaryParticleInformation

�� G4Region G4Region -- G4VUserRegionInformationG4VUserRegionInformation

�� User information class object is deleted when associated Geant4 User information class object is deleted when associated Geant4 class class

object is deleted.object is deleted.

Page 22: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 2222

Trajectory and trajectory pointTrajectory and trajectory point�� Trajectory and trajectory point class objects persist until the Trajectory and trajectory point class objects persist until the end of an event.end of an event.

�� And some cases stored to disk as "simulation truth"And some cases stored to disk as "simulation truth"

�� G4VTrajectoryG4VTrajectory is the abstract base class to represent a trajectory, and is the abstract base class to represent a trajectory, and

G4VTrajectoryPointG4VTrajectoryPoint is the abstract base class to represent a point which makes is the abstract base class to represent a point which makes

up the trajectory.up the trajectory.

�� In general, trajectory class is expected to have a vector of traIn general, trajectory class is expected to have a vector of trajectory points.jectory points.

�� Geant4 provides Geant4 provides G4TrajectoyG4Trajectoy and and G4TrajectoryPointG4TrajectoryPoint concrete classes as defaults. concrete classes as defaults.

These classes keep only the most common quantities.These classes keep only the most common quantities.

�� If the user wants to keep some additional information and/or wanIf the user wants to keep some additional information and/or wants to ts to

change the drawing style of a trajectory, he/she is encouraged tchange the drawing style of a trajectory, he/she is encouraged to implement o implement

his/her own concrete classes deriving from G4VTrajectory and his/her own concrete classes deriving from G4VTrajectory and

G4VTrajectoryPoint base classes.G4VTrajectoryPoint base classes.

�� Do not use G4Trajectory nor G4TrajectoryPoint concrete class as Do not use G4Trajectory nor G4TrajectoryPoint concrete class as base base

classes unless you are sure not to add any additional data membeclasses unless you are sure not to add any additional data member. r.

Page 23: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 2323

Creation of trajectoriesCreation of trajectories� Naïve creation of trajectories occasionally causes a memory consumption

concern, especially for high energy EM showers.

� In UserTrackingAction, you can switch on/off the creation of a trajectory for the particular track.

void MyTrackingAction

::PreUserTrackingAction(const G4Track* aTrack)

{

if(...)

{ fpTrackingManager-> SetStoreTrajectory ( true ); }

else

{ fpTrackingManager-> SetStoreTrajectory ( false ); }

}

�� If you want to use userIf you want to use user--defined trajectory, object should be instantiated in this defined trajectory, object should be instantiated in this method and set to G4TrackingManager by method and set to G4TrackingManager by SetTrajectorySetTrajectory()() method.method.

fpTrackingManager->SetTrajectory(new MyTrajectory(…) );

Page 24: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 2424

RE01RegionInformationRE01RegionInformation�� This RE01 example has three regions, i.e. default world region, This RE01 example has three regions, i.e. default world region, tracker region tracker region

and calorimeter region.and calorimeter region.

�� Each region has its unique object of RE01RegionInformation classEach region has its unique object of RE01RegionInformation class..

class RE01RegionInformation : public G4VUserRegionI nformationclass RE01RegionInformation : public G4VUserRegionI nformation{{

……public:public:

G4bool G4bool IsWorldIsWorld () const;() const;G4bool G4bool IsTrackerIsTracker () const;() const;G4bool G4bool IsCalorimeterIsCalorimeter () const;() const;

……};};

�� Through stepThrough step-->>preStepPointpreStepPoint-->>physicalVolumephysicalVolume-->>logicalVolumelogicalVolume-->region>region--> > regionInformationregionInformation, you can easily identify in which region the current step , you can easily identify in which region the current step belongs.belongs.

�� DonDon’’t use volume name to identify.t use volume name to identify.

Page 25: Primary Particle Generation, Tracking & Stacking

Stack managementStack management

Page 26: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 2626

Track stacks in Geant4Track stacks in Geant4� By default, Geant4 has three track stacks.

� "Urgent", "Waiting" and "PostponeToNextEvent"

� Each stack is a simple "last-in-first-out" stack.

� User can arbitrary increase the number of stacks.

� ClassifyNewTrack() method of UserStackingAction decides which stack each

newly storing track to be stacked (or to be killed).

� By default, all tracks go to Urgent stack.

� A Track is popped up only from Urgent stack.

� Once Urgent stack becomes empty, all tracks in Waiting stack are transferred to

Urgent stack.

� And NewStage() method of UsetStackingAction is invoked.

� Utilizing more than one stacks, user can control the priorities of processing

tracks without paying the overhead of "scanning the highest priority track"

which was the only available way in Geant3.

� Proper selection/abortion of tracks/events with well designed stack

management provides significant efficiency increase of the entire simulation.

Page 27: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 2727

G4UserStackingActionG4UserStackingAction�� User has to implement three methods.User has to implement three methods.

�� G4ClassificationOfNewTrack G4ClassificationOfNewTrack ClassifyNewTrack(constClassifyNewTrack(const G4Track*)G4Track*)

�� Invoked every time a new track is pushed to G4StackManager.Invoked every time a new track is pushed to G4StackManager.

�� ClassificationClassification

�� fUrgentfUrgent -- pushed into Urgent stackpushed into Urgent stack

�� fWaitingfWaiting -- pushed into Waiting stackpushed into Waiting stack

�� fPostponefPostpone -- pushed into pushed into PostponeToNextEventPostponeToNextEvent stackstack

�� fKillfKill -- killedkilled

�� void void NewStageNewStage()()

�� Invoked when Urgent stack becomes empty and all tracks in WaitinInvoked when Urgent stack becomes empty and all tracks in Waiting stack g stack

are transferred to Urgent stack.are transferred to Urgent stack.

�� All tracks which had been transferred from Waiting stack to UrgeAll tracks which had been transferred from Waiting stack to Urgent stack nt stack

can be reclassified by invoking can be reclassified by invoking stackManagerstackManager-->>ReClassifyReClassify()()

�� void void PrepareNewEventPrepareNewEvent()()

�� Invoked at the beginning of each event for resetting the classifInvoked at the beginning of each event for resetting the classification ication

scheme. scheme.

Page 28: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 2828

Stacking mechanismStacking mechanism

Event Manager

Tracking

Manager

Stacking

Manager

User Stacking

Action

Urgent

Stack

Waiting

Stack

Postpone To

Next Event

Stack

Push

PopPush

Push

Push

Pop

Classify

secondary

and suspended

tracks

Process

One

Track

primary

tracks

RIP

Deleted

Transfer

NewStageUrgent

Stack

Waiting

Stack

Temporary

Stack

Reclassify

Pop

End Of

Event

Postpone To

Next Event

Stack

Transfer

Prepare

New Event

Page 29: Primary Particle Generation, Tracking & Stacking

Primary Particle Generation, Tracking & StackingPrimary Particle Generation, Tracking & Stacking 2929

Tips of stacking manipulations Tips of stacking manipulations

1.1. Classify all Classify all secondariessecondaries as as fWaitingfWaiting until until ReclassifyReclassify() method is invoked.() method is invoked.

�� You can simulate all primaries before any You can simulate all primaries before any secondariessecondaries..

2.2. SuspendSuspend a track on its fly. Then this track and all of already generatea track on its fly. Then this track and all of already generated d

secondariessecondaries are pushed to the stack.are pushed to the stack.

�� Given a stack is Given a stack is "last-in-first-out”, secondaries are tracked prior to the

original suspended track.

� Quite effective for Cherenkov lights

3. Suspend all tracks that are leaving from a region, and classify these suspended

tracks as fWaitingfWaiting until Reclassify() method is invoked.until Reclassify() method is invoked.

�� You can simulate all tracks in this region prior to other regionYou can simulate all tracks in this region prior to other regions.s.

�� Note that some back splash tracks may come back into this regionNote that some back splash tracks may come back into this region later.later.

4.4. Classify tracks below a certain energy as Classify tracks below a certain energy as fWaitingfWaiting until Reclassify() method is until Reclassify() method is

invoked.invoked.

�� You can simulate the event roughly before being bothered by low You can simulate the event roughly before being bothered by low energy energy

EM showers.EM showers.