Back to home page

EIC code displayed by LXR

 
 

    


Warning, /geant4/examples/extended/field/field04/README.md is written in an unsupported language. File is not indexed.

0001 \page Examplefield04 Example field04
0002 
0003 
0004  This example shows how to define/use OVERLAPPING field elements
0005  in Geant4. Fields might be either magnetic, electric or both.
0006 
0007  Credit goes to Tom Roberts and Muons Inc. since much of the code
0008  and ideas were taken at liberty from the (GNU GPL) source of
0009  G4BEAMLINE release 1.12.
0010 
0011  http://g4beamline.muonsinc.com
0012 
0013 ## Classes
0014 
0015 - main()
0016 
0017   See mains() in field04.cc.
0018   
0019   The example can be run with the following optional arguments:
0020   
0021   ```
0022   % ./field04 [-m macro ] [-p physicsList] [-r randomSeed] [-s preinit|idle]
0023   ```
0024   
0025   If a macro is provided with the option "-m", the program runs in a batch mode,
0026   otherwise the program open the interactive session after executing the
0027   default initialization macro init_vis.mac. The option "-s preinit" can be used
0028   to start the program without initialization in PreInit phase.
0029   
0030   For example:
0031   to assign the F04PhysicsList:
0032   ```
0033   % ./field04 -p QGSP_BERT
0034   ```
0035   
0036   an initial random number seed with:
0037   ```
0038   % ./field04 field04.in -r 12345
0039   ```
0040   
0041   to start with a macro file and an initial seed:
0042   ```
0043   % ./field04 -m field04.in -r 12345
0044   ```
0045 
0046 - F04DetectorConstruction
0047 
0048   The geometry consists of two solenoidal magnets: a "CaptureMgnt"
0049   followed by a (blue-colored "TransferMgnt". By definition, the
0050   axis and center of the "CaptureMgnt" coincide with the "World". The
0051   position of the "TransferMgnt" relative to the downstream end of the
0052   "CaptureMgnt", as well as its axis angle, both may vary. A cylindrical
0053   "Target" is positioned inside the "CaptureMgnt". Its axis can vary
0054   from 0 to 180 deg, and hence also the direction of the incoming
0055   proton beam wrt the "CaptureMgnt"'s axis. A "Degrader" is located
0056   inside the "TransferMgnt", its default position being at the
0057   upstream end of the "TransferMgnt". Finally, also a "TestPlane" is
0058   located inside the "TransferMgnt", by default at its downstream end.
0059 
0060   The "World" consists of a solid cylinder made of a given material.
0061   (It is the responsibility of the user to make the world
0062   large enough to contain the rest of the geometry!)
0063   
0064   Three parameters define the world :
0065   - the material of the world,
0066   - the world radius,
0067   - the world length.
0068   
0069   Example (default values):
0070   ```
0071   /field04/SetWorldMat G4_AIR
0072   /field04/SetWorldR  5.0 m
0073   /field04/SetWorldZ 50.0 m
0074   ```
0075   
0076   The "Target" is a solid cylinder made of a given material.
0077   Five parameters define the target:
0078   - the material of the target,
0079   - the target radius,
0080   - the target thickness,
0081   - the target position inside the "CaptureMgnt",
0082   - the target axis angle relative to that of the "CaptureMgnt".
0083   
0084   Example (default values):
0085   ```
0086   /field04/SetTgtMat G4_W
0087   /field04/SetTgtRad    0.4 cm
0088   /field04/SetTgtThick 16.0 cm
0089   /field04/SetTgtPos 0.0 cm
0090   /field04/SetTgtAng 170
0091   ```
0092   
0093   The "Degrader" is a solid cylinder made of a given material.
0094   
0095   Four parameters define the degrader:
0096   - the material of the degrader,
0097   - the degrader radius,
0098   - the degrader thickness,
0099   - the degrader position relative to the "TransferMgnt" center.
0100   
0101   Example (default values):
0102   ```
0103   /field04/SetDgrMat G4_Pb
0104   /field04/SetDgrRad  30.0 cm
0105   /field04/SetDgrThick 0.1 cm
0106   /field04/SetDgrPos -7.4 m
0107   ```
0108   
0109   The "CaptureMgnt" is a solenoid (vacuum cylinder). It is either
0110   a two-sided or a one-sided magnetic bottle with the B field
0111   varying linearly from the center value B1 to the edge value B2.
0112   The one-sided F04FocusSolenoid has the open end at +z and focuses
0113   on the z < 0 side.
0114   
0115   Four parameters define the "CaptureMgnt":
0116   - the magnet radius,
0117   - the magnet length,
0118   - the weaker magnetic field at the center B1
0119   - the stronger magnetic field at the edge B2
0120   
0121   Example (default values):
0122   ```
0123   /field04/SetCaptureR 0.6 m
0124   /field04/SetCaptureZ 4.0 m
0125   /field/SetCaptureB1 2.5 tesla
0126   /field/SetCaptureB2 5.0 tesla
0127   ```
0128   
0129   The "TransferMgnt" is a solenoid (vacuum cylinder) with a
0130   constant B-field. When the "TransferMgnt" follows immediately
0131   the "CaptureMgnt", its relative position is at 0 cm.
0132   
0133   Four parameters define the "TransferMgnt":
0134   - the magnet radius,
0135   - the magnet length,
0136   - the magnet field,
0137   - the magnet relative position
0138     (its upstream face wrt the downstream face of the "CaptureMgnt".)
0139   
0140   Example (default values):
0141   ```
0142   /field04/SetTransferR  0.3 m
0143   /field04/SetTransferZ 15.0 m
0144   /field/SetTransferB 5.0 tesla
0145   /field04/SetTransferP 0.0 m
0146   ```
0147   The default geometry is constructed in F04DetectorConstruction class,
0148   but all the parameters can be changed via the commands defined in
0149   the F04DetectorMessenger class.
0150   
0151 - F04Materials
0152   
0153   Material definitions are done through the singleton class F04Materials
0154   which keeps a pointer to the G4NistManager. It has a method
0155   GetMaterial by name (G4String) which in turn invokes the
0156   G4NistManager::FindOrBuildMaterial, and/or G4Material::GetMaterial
0157   methods. It has also a method CreateMaterials which, for materials
0158   absent from the NIST data base, shows how to create them using the
0159   G4NistManager::ConstructNewMaterial method.
0160   
0161   
0162 - F04PrimaryGeneratorAction
0163   
0164   The primary kinematic consists of a single particle which hits the
0165   target perpendicular to its upstream face. The type of the particle
0166   and its energy are set in the F04PrimaryGeneratorAction class, and can
0167   be changed via the G4 build-in commands of the G4ParticleGun class.
0168   In addition, there is a fRndmFlag, which once set allows the beam to
0169   explore randomly the whole cross section of the target. The default
0170   beam consists of 500 MeV protons, starting at the upstream face of
0171   the target, directed along dx = dy = 0, dz = 1 wrt the target frame.
0172   The default direction should NOT be changed! The arguments of the
0173   x/y/zvertex commands are relative to the target center.
0174   
0175   Example:
0176   ```
0177   /gun/random on
0178   #/gun/xvertex 0 mm
0179   #/gun/yvertex 0 mm
0180   #/gun/zvertex -100 mm
0181   ```
0182   
0183 - DETECTOR RESPONSE in F04SteppingAction
0184 
0185   Information is extracted from the program via F04SteppingAction
0186   at the TestPlane.
0187 
0188 - F04PhysicsList
0189 
0190   The F04PhysicsList extends a selected Geant4 physics list.
0191   The base physics list name is provided by its name in the F04PhysicsList
0192   constructor.
0193 
0194   In addition to processes defined in the base Geant4 physics list,
0195   there is added the F04StepMax process and the decay of pions can be assigned
0196   via dedicated commands in F04PhysicsListMessenger.
0197 
0198   The command to define maximum step:
0199   ```
0200   /exp/phys/stepMax value unit
0201   ```
0202 
0203   The decay of pions can be assigned via (pi -> e nu, pi -> mu nu):
0204   ```
0205   /decay/pienu
0206   /decay/pimunu
0207   ```
0208 
0209   The pienu assignment includes a small fraction of radiative decay:
0210   e nu gamma (G4PionRadiativeDecayChannel).
0211 
0212   The standard/default muon decay chain is modified to be 98.6%
0213   G4MuonDecayChannelWithSpin and 1.4% G4MuonRadiativeDecayChannelWithSpin
0214   in F04PhysicsList::ConstructParticle().
0215 
0216   The pion decay process G4PolDecay inherits from G4Decay and implements
0217   the virtual method - empty in the base class - DaughterPolarization
0218 
0219   The muon decay process is G4DecayWithSpin
0220 
0221   Furthermore, the following commands are also available, but
0222   may only be used AFTER /run/initialize
0223 
0224   ```
0225   /process/inactivate msc
0226   /process/activate msc
0227   ```
0228 
0229 ## Overlapping Fields
0230 
0231  The F04GlobalField (a singleton) is instantiated in
0232  F04DetectorConstruction() and assigned to the global field manager
0233  in UpdateField():
0234 ```cpp
0235 fFieldManager = GetGlobalFieldManager();
0236 fFieldManager->SetDetectorField(this);
0237 ```
0238  The F04GlobalField has a std::vector<ElementField*> FieldList
0239 
0240  The field from each individual beamline element is given by a
0241  F04ElementField object. Any number of overlapping F04ElementField
0242  objects can be added to the F04GlobalField. Any element that
0243  represents an element with an EM field must add the appropriate
0244  F04ElementField to the global F04GlobalField object.
0245 
0246  Of course, the F04GlobalField has the method GetFieldValue implemented.
0247 
0248  Before /run/initialize in the macro file or command, the update
0249  field command must have been issued if any of the other following
0250  field commands was employed:
0251 ```
0252 /field/update
0253 ```
0254 
0255  Other options are:
0256 ```
0257 /field/setStepperType 4
0258 /field/setMinStep 10 mm
0259 /field/setDeltaChord 3.0 mm
0260 /field/setDeltaOneStep 0.01 mm
0261 /field/setDeltaIntersection 0.1 mm
0262 /field/setEpsMin 2.5e-7 mm
0263 /field/setEpsMax 0.05 mm
0264 ```
0265  Each field element has a rectilinear bounding box in global
0266  coordinate space which is checked before a point is verified to
0267  actually be inside the F04ElementField (IsWithin and IsOutside).
0268  SetGlobalPoint is called 8 times for the corners of the local
0269  bounding box, after a local->global coordinate transform.
0270 
0271  The F04ElementField is the interface class used by F04GlobalField to
0272  compute the field value at a given point[].
0273 
0274  A beamline element, for example the F04SimpleSolenoid, will derive
0275  from F04ElementField and implement the computation for the element.
0276 ```cpp
0277 simpleSolenoid
0278   = new F04SimpleSolenoid(B, l, logicTransferMgnt,TransferMgntCenter);
0279 ```
0280  Besides the magnetic field and the length of the simple solenoid,
0281  the constructor needs the knowledge of the G4LogicalVolume for
0282  the beamline element and where its center is located in the
0283  'World'.
0284 
0285  The F04ElementField has a G4AffineTransform "fGlobal2local" which
0286  allows the quick computation of coordinate transformations. It can
0287  only be determined by knowing the element's coordinate origin in
0288  the global frame and after all of the geometry has been defined.
0289  For this reason, the object is prepared in two stages, through the
0290  constructor providing it with the coordinate center and a pointer
0291  to the G4LogicalVolume. Later the Construct() method is called to
0292  calculate the fGlobal2local and the bounding box. This can be done
0293  from the F04RunAction::BeginOfRunAction method, for only then are we
0294  certain that the geometry has been completely built:
0295 ```cpp
0296 FieldList* fields = F04GlobalField::GetObject()->GetFields();
0297 
0298 if (fields) {
0299    if (fields->size()>0) {
0300       FieldList::iterator i;
0301       for (i=fields->begin(); i!=fields->end(); ++i)(*i)->Construct();
0302    }
0303 }
0304 ```
0305  The F04ElementField constructor will also add the derived object into
0306  F04GlobalField. Finally, its AddFieldValue() will add the field value
0307  for this element to field[].
0308 
0309 ### User Action Classes
0310 
0311 - F04RunActionMessenger:
0312   ```
0313   /rndm/save freq - to save rndm status in external files
0314    0 not saved
0315          >0 saved on: beginOfRun.rndm
0316    1 saved on:   endOfRun.rndm
0317    2 saved on: endOfEvent.rndm
0318   /rndm/read random/run0evt8268.rndm
0319 ```
0320 
0321 - F04RunAction: \n
0322   BeginOfRunAction: Deal with random number storage,
0323   initialization etc. Call the Construct() method of
0324   F04ElementFields in the FieldList of F04GlobalField object.
0325   EndOfRunAction: random number storage/status printing.
0326 
0327 - F04EventActionMessenger:
0328   ```
0329   /event/setverbose
0330   ```
0331 
0332 - F04EventAction(F04RunAction* RA): \n
0333   Customized BeginOfEvent printing
0334   EndofEvent:
0335   saveEngingStatus and showEngineStatus according to flag
0336   in F04RunAction
0337 
0338 - F04TrackingAction: \n
0339   PreUserTrackingAction: Instantiate F04UserTrackInformation
0340   and set the application TrackStatus.
0341   PostUserTrackingAction: Retreive F04UserTrackInformation
0342   and decide to save random number status accordingly.
0343 
0344 - F04SteppingActionMessenger: \n
0345 
0346 - F04SteppingAction: \n
0347   UserSteppingAction: Kill primary if/when outside Target
0348   volume. Diagnostic/histogram filling for particles at a
0349   TestPlane. Find decay position and when particle
0350   FIRST reverses z-momentum component via using a
0351   F04UserTrackInformation object.
0352 
0353 - F04StackingAction: \n
0354   Track only primaries, pi+ or mu+
0355 
0356 - F04UserTrackInformation: \n
0357   Keep an application F04TrackStatus for the track: \n
0358   undefined, left, right, reverse
0359 
0360 - F04SteppingVerbose: \n
0361   Only print track header and step information for
0362   pi+ and mu+.
0363   Note: the information for primary protons is not printed.
0364 
0365 - F04Trajectory, F04TrajectoryPoint: \n
0366   Example of application specific implementations
0367 
0368 ## HOW TO START ?
0369 
0370  - Execute field04 in 'batch' mode from macro files e.g.
0371 ```
0372 % ./field04 -m field04.in
0373 ```
0374 
0375  - Execute field04 in 'interactive' mode with visualization
0376 ```
0377 % ./field04
0378 ....
0379 Idle> type your commands
0380 ....
0381 ```
0382 
0383  - Execute field04 in 'interactive' mode without initialization
0384 ```
0385 % ./field04 -s preinit
0386 ....
0387 Idle> type your commands, then
0388 Idle> /run/initialize
0389 Idle> /control/execute vis.mac
0390 ....
0391 ```