Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:42

0001 from DDSim.DD4hepSimulation import DD4hepSimulation
0002 from g4units import mm, GeV, MeV
0003 SIM = DD4hepSimulation()
0004 
0005 ## The compact XML file, or multiple compact files, if the last one is the closer.
0006 SIM.compactFile = []
0007 ## Lorentz boost for the crossing angle, in radian!
0008 SIM.crossingAngleBoost = 0.0
0009 SIM.enableDetailedShowerMode = False
0010 SIM.enableG4GPS = False
0011 SIM.enableG4Gun = False
0012 SIM.enableGun = False
0013 ## InputFiles for simulation .stdhep, .slcio, .HEPEvt, .hepevt, .pairs, .hepmc, .hepmc.gz, .hepmc.xz, .hepmc.bz2, .hepmc3, .hepmc3.gz, .hepmc3.xz, .hepmc3.bz2, .hepmc3.tree.root files are supported
0014 SIM.inputFiles = []
0015 ## Macro file to execute for runType 'run' or 'vis'
0016 SIM.macroFile = ""
0017 ## number of events to simulate, used in batch mode
0018 SIM.numberOfEvents = 0
0019 ## Outputfile from the simulation: .slcio, edm4hep.root and .root output files are supported
0020 SIM.outputFile = "dummyOutput.slcio"
0021 ## Physics list to use in simulation
0022 SIM.physicsList = None
0023 ## Verbosity use integers from 1(most) to 7(least) verbose
0024 ## or strings: VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL, ALWAYS
0025 SIM.printLevel = 3
0026 ## The type of action to do in this invocation
0027 ## batch: just simulate some events, needs numberOfEvents, and input file or gun
0028 ## vis: enable visualisation, run the macroFile if it is set
0029 ## qt: enable visualisation in Qt shell, run the macroFile if it is set
0030 ## run: run the macroFile and exit
0031 ## shell: enable interactive session
0032 SIM.runType = "batch"
0033 ## Skip first N events when reading a file
0034 SIM.skipNEvents = 0
0035 ## Steering file to change default behaviour
0036 SIM.steeringFile = None
0037 ## FourVector of translation for the Smearing of the Vertex position: x y z t
0038 SIM.vertexOffset = [0.0, 0.0, 0.0, 0.0]
0039 ## FourVector of the Sigma for the Smearing of the Vertex position: x y z t
0040 SIM.vertexSigma = [0.0, 0.0, 0.0, 0.0]
0041 
0042 
0043 ################################################################################
0044 ## Helper holding sensitive detector actions.
0045 ## 
0046 ##   The default tracker and calorimeter actions can be set with
0047 ## 
0048 ##   >>> SIM = DD4hepSimulation()
0049 ##   >>> SIM.action.tracker=('Geant4TrackerWeightedAction', {'HitPositionCombination': 2, 'CollectSingleDeposits': False})
0050 ##   >>> SIM.action.calo = "Geant4CalorimeterAction"
0051 ## 
0052 ##   The default sensitive actions for calorimeters and trackers are applied based on the sensitive type.
0053 ##   The list of sensitive types can be changed with
0054 ## 
0055 ##   >>> SIM = DD4hepSimulation()
0056 ##   >>> SIM.action.trackerSDTypes = ['tracker', 'myTrackerSensType']
0057 ##   >>> SIM.calor.calorimeterSDTypes = ['calorimeter', 'myCaloSensType']
0058 ## 
0059 ##   For specific subdetectors specific sensitive detectors can be set based on patterns in the name of the subdetector.
0060 ## 
0061 ##   >>> SIM = DD4hepSimulation()
0062 ##   >>> SIM.action.mapActions['tpc'] = "TPCSDAction"
0063 ## 
0064 ##   and additional parameters for the sensitive detectors can be set when the map is given a tuple
0065 ## 
0066 ##   >>> SIM = DD4hepSimulation()
0067 ##   >>> SIM.action.mapActions['ecal'] =( "CaloPreShowerSDAction", {"FirstLayerNumber": 1} )
0068 ## 
0069 ##    
0070 ################################################################################
0071 
0072 ##  set the default calorimeter action 
0073 SIM.action.calo = "Geant4ScintillatorCalorimeterAction"
0074 
0075 ## List of patterns matching sensitive detectors of type Calorimeter.
0076 SIM.action.calorimeterSDTypes = ['calorimeter']
0077 
0078 ## Create a map of patterns and actions to be applied to sensitive detectors.
0079 ## 
0080 ##     Example: if the name of the detector matches 'tpc' the TPCSDAction is used.
0081 ## 
0082 ##       SIM.action.mapActions['tpc'] = "TPCSDAction"
0083 ##     
0084 SIM.action.mapActions = {}
0085 
0086 ##  set the default tracker action 
0087 SIM.action.tracker = ('Geant4TrackerWeightedAction', {'HitPositionCombination': 2, 'CollectSingleDeposits': False})
0088 
0089 ## List of patterns matching sensitive detectors of type Tracker.
0090 SIM.action.trackerSDTypes = ['tracker']
0091 
0092 
0093 ################################################################################
0094 ## Configuration for the magnetic field (stepper) 
0095 ################################################################################
0096 SIM.field.delta_chord = 0.25
0097 SIM.field.delta_intersection = 0.001
0098 SIM.field.delta_one_step = 0.01
0099 SIM.field.eps_max = 0.001
0100 SIM.field.eps_min = 5e-05
0101 SIM.field.equation = "Mag_UsualEqRhs"
0102 SIM.field.largest_step = 10000.0
0103 SIM.field.min_chord_step = 0.01
0104 SIM.field.stepper = "ClassicalRK4"
0105 
0106 
0107 ################################################################################
0108 ## Configuration for sensitive detector filters
0109 ## 
0110 ##   Set the default filter for 'tracker'
0111 ##   >>> SIM.filter.tracker = "edep1kev"
0112 ##   Use no filter for 'calorimeter' by default
0113 ##   >>> SIM.filter.calo = ""
0114 ## 
0115 ##   Assign a filter to a sensitive detector via pattern matching
0116 ##   >>> SIM.filter.mapDetFilter['FTD'] = "edep1kev"
0117 ## 
0118 ##   Or more than one filter:
0119 ##   >>> SIM.filter.mapDetFilter['FTD'] = ["edep1kev", "geantino"]
0120 ## 
0121 ##   Don't use the default filter or anything else:
0122 ##   >>> SIM.filter.mapDetFilter['TPC'] = None ## or "" or []
0123 ## 
0124 ##   Create a custom filter. The dictionary is used to instantiate the filter later on
0125 ##   >>> SIM.filter.filters['edep3kev'] = dict(name="EnergyDepositMinimumCut/3keV", parameter={"Cut": 3.0*keV} )
0126 ## 
0127 ##    
0128 ################################################################################
0129 
0130 ## 
0131 ##     default filter for calorimeter sensitive detectors;
0132 ##     this is applied if no other filter is used for a calorimeter
0133 ##     
0134 SIM.filter.calo = "edep0"
0135 
0136 ##  list of filter objects: map between name and parameter dictionary 
0137 SIM.filter.filters = {'geantino': {'name': 'GeantinoRejectFilter/GeantinoRejector', 'parameter': {}}, 'edep1kev': {'name': 'EnergyDepositMinimumCut', 'parameter': {'Cut': 0.001}}, 'edep0': {'name': 'EnergyDepositMinimumCut/Cut0', 'parameter': {'Cut': 0.0}}}
0138 
0139 ##  a map between patterns and filter objects, using patterns to attach filters to sensitive detector 
0140 SIM.filter.mapDetFilter = {}
0141 
0142 ##  default filter for tracking sensitive detectors; this is applied if no other filter is used for a tracker
0143 SIM.filter.tracker = "edep1kev"
0144 
0145 
0146 ################################################################################
0147 ## Configuration for the Detector Construction. 
0148 ################################################################################
0149 SIM.geometry.dumpGDML = ""
0150 SIM.geometry.dumpHierarchy = 0
0151 
0152 ## Print Debug information about Elements
0153 SIM.geometry.enableDebugElements = False
0154 
0155 ## Print Debug information about Materials
0156 SIM.geometry.enableDebugMaterials = False
0157 
0158 ## Print Debug information about Placements
0159 SIM.geometry.enableDebugPlacements = False
0160 
0161 ## Print Debug information about Reflections
0162 SIM.geometry.enableDebugReflections = False
0163 
0164 ## Print Debug information about Regions
0165 SIM.geometry.enableDebugRegions = False
0166 
0167 ## Print Debug information about Shapes
0168 SIM.geometry.enableDebugShapes = False
0169 
0170 ## Print Debug information about Surfaces
0171 SIM.geometry.enableDebugSurfaces = False
0172 
0173 ## Print Debug information about Volumes
0174 SIM.geometry.enableDebugVolumes = False
0175 
0176 ## Print information about placements
0177 SIM.geometry.enablePrintPlacements = False
0178 
0179 ## Print information about Sensitives
0180 SIM.geometry.enablePrintSensitives = False
0181 
0182 
0183 ################################################################################
0184 ## Configuration for the GuineaPig InputFiles 
0185 ################################################################################
0186 
0187 ## Set the number of pair particles to simulate per event.
0188 ##     Only used if inputFile ends with ".pairs"
0189 ##     If "-1" all particles will be simulated in a single event
0190 ##     
0191 SIM.guineapig.particlesPerEvent = "-1"
0192 
0193 
0194 ################################################################################
0195 ## Configuration for the DDG4 ParticleGun 
0196 ################################################################################
0197 
0198 ##  direction of the particle gun, 3 vector 
0199 SIM.gun.direction = (0, 0, 1)
0200 
0201 ## choose the distribution of the random direction for theta
0202 ## 
0203 ##     Options for random distributions:
0204 ## 
0205 ##     'uniform' is the default distribution, flat in theta
0206 ##     'cos(theta)' is flat in cos(theta)
0207 ##     'eta', or 'pseudorapidity' is flat in pseudorapity
0208 ##     'ffbar' is distributed according to 1+cos^2(theta)
0209 ## 
0210 ##     Setting a distribution will set isotrop = True
0211 ##     
0212 SIM.gun.distribution = None
0213 
0214 ## Total energy (including mass) for the particle gun.
0215 ## 
0216 ## If not None, it will overwrite the setting of momentumMin and momentumMax
0217 SIM.gun.energy = None
0218 
0219 ## Maximal pseudorapidity for random distibution (overrides thetaMin)
0220 SIM.gun.etaMax = None
0221 
0222 ## Minimal pseudorapidity for random distibution (overrides thetaMax)
0223 SIM.gun.etaMin = None
0224 
0225 ##  isotropic distribution for the particle gun
0226 ## 
0227 ##     use the options phiMin, phiMax, thetaMin, and thetaMax to limit the range of randomly distributed directions
0228 ##     if one of these options is not None the random distribution will be set to True and cannot be turned off!
0229 ##     
0230 SIM.gun.isotrop = False
0231 
0232 ## Maximal momentum when using distribution (default = 0.0)
0233 SIM.gun.momentumMax = 10000.0
0234 
0235 ## Minimal momentum when using distribution (default = 0.0)
0236 SIM.gun.momentumMin = 0.0
0237 SIM.gun.multiplicity = 1
0238 SIM.gun.particle = "mu-"
0239 
0240 ## Maximal azimuthal angle for random distribution
0241 SIM.gun.phiMax = None
0242 
0243 ## Minimal azimuthal angle for random distribution
0244 SIM.gun.phiMin = None
0245 
0246 ##  position of the particle gun, 3 vector 
0247 SIM.gun.position = (0.0, 0.0, 0.0)
0248 
0249 ## Maximal polar angle for random distribution
0250 SIM.gun.thetaMax = None
0251 
0252 ## Minimal polar angle for random distribution
0253 SIM.gun.thetaMin = None
0254 
0255 
0256 ################################################################################
0257 ## Configuration for the hepmc3 InputFiles 
0258 ################################################################################
0259 
0260 ## Set the name of the attribute contraining color flow information index 0.
0261 SIM.hepmc3.Flow1 = "flow1"
0262 
0263 ## Set the name of the attribute contraining color flow information index 1.
0264 SIM.hepmc3.Flow2 = "flow2"
0265 
0266 ## Set to false if the input should be opened with the hepmc2 ascii reader.
0267 ## 
0268 ##     If ``True`` a  '.hepmc' file will be opened with the HEPMC3 Reader Factory.
0269 ## 
0270 ##     Defaults to true if DD4hep was build with HEPMC3 support.
0271 ##     
0272 SIM.hepmc3.useHepMC3 = False
0273 
0274 
0275 ################################################################################
0276 ## Configuration for Input Files. 
0277 ################################################################################
0278 
0279 ## Set one or more functions to configure input steps.
0280 ## 
0281 ##     The functions must take a ``DD4hepSimulation`` object as their only argument and return the created generatorAction
0282 ##     ``gen`` (for example).
0283 ## 
0284 ##     For example one can add this to the ddsim steering file:
0285 ## 
0286 ##       def exampleUserPlugin(dd4hepSimulation):
0287 ##         '''Example code for user created plugin.
0288 ## 
0289 ##         :param DD4hepSimulation dd4hepSimulation: The DD4hepSimulation instance, so all parameters can be accessed
0290 ##         :return: GeneratorAction
0291 ##         '''
0292 ##         from DDG4 import GeneratorAction, Kernel
0293 ##         # Geant4InputAction is the type of plugin, Cry1 just an identifier
0294 ##         gen = GeneratorAction(Kernel(), 'Geant4InputAction/Cry1' , True)
0295 ##         # CRYEventReader is the actual plugin, steeringFile its constructor parameter
0296 ##         gen.Input = 'CRYEventReader|' + 'steeringFile'
0297 ##         # we can give a dictionary of Parameters that has to be interpreted by the setParameters function of the plugin
0298 ##         gen.Parameters = {'DataFilePath': '/path/to/files/data'}
0299 ##         gen.enableUI()
0300 ##         return gen
0301 ## 
0302 ##       SIM.inputConfig.userInputPlugin = exampleUserPlugin
0303 ## 
0304 ##     Repeat function definition and assignment to add multiple input steps
0305 ## 
0306 ##     
0307 SIM.inputConfig.userInputPlugin = []
0308 
0309 
0310 ################################################################################
0311 ## Configuration for the generator-level InputFiles 
0312 ################################################################################
0313 
0314 ## Set the name of the collection containing the MCParticle input.
0315 ##     Default is "MCParticle".
0316 ##     
0317 SIM.lcio.mcParticleCollectionName = "MCParticle"
0318 
0319 
0320 ################################################################################
0321 ## Configuration for the LCIO output file settings 
0322 ################################################################################
0323 
0324 ## The event number offset to write in slcio output file. E.g setting it to 42 will start counting events from 42 instead of 0
0325 SIM.meta.eventNumberOffset = 0
0326 
0327 ## Event parameters to write in every event. Use C/F/I ids to specify parameter type. E.g parameterName/F=0.42 to set a float parameter
0328 SIM.meta.eventParameters = []
0329 
0330 ## The run number offset to write in slcio output file. E.g setting it to 42 will start counting runs from 42 instead of 0
0331 SIM.meta.runNumberOffset = 0
0332 
0333 
0334 ################################################################################
0335 ## Configuration for the output levels of DDG4 components 
0336 ################################################################################
0337 
0338 ## Output level for geometry.
0339 SIM.output.geometry = 2
0340 
0341 ## Output level for input sources
0342 SIM.output.inputStage = 3
0343 
0344 ## Output level for Geant4 kernel
0345 SIM.output.kernel = 3
0346 
0347 ## Output level for ParticleHandler
0348 SIM.output.part = 3
0349 
0350 ## Output level for Random Number Generator setup
0351 SIM.output.random = 6
0352 
0353 
0354 ################################################################################
0355 ## Configuration for Output Files. 
0356 ################################################################################
0357 
0358 ## Set a function to configure the outputFile.
0359 ## 
0360 ##     The function must take a ``DD4hepSimulation`` object as its only argument and return ``None``.
0361 ## 
0362 ##     For example one can add this to the ddsim steering file:
0363 ## 
0364 ##       def exampleUserPlugin(dd4hepSimulation):
0365 ##         '''Example code for user created plugin.
0366 ## 
0367 ##         :param DD4hepSimulation dd4hepSimulation: The DD4hepSimulation instance, so all parameters can be accessed
0368 ##         :return: None
0369 ##         '''
0370 ##         from DDG4 import EventAction, Kernel
0371 ##         dd = dd4hepSimulation  # just shorter variable name
0372 ##         evt_root = EventAction(Kernel(), 'Geant4Output2ROOT/' + dd.outputFile, True)
0373 ##         evt_root.HandleMCTruth = True or False
0374 ##         evt_root.Control = True
0375 ##         if not dd.outputFile.endswith(dd.outputConfig.myExtension):
0376 ##           output = dd.outputFile + dd.outputConfig.myExtension
0377 ##         evt_root.Output = output
0378 ##         evt_root.enableUI()
0379 ##         Kernel().eventAction().add(evt_root)
0380 ##         return None
0381 ## 
0382 ##       SIM.outputConfig.userOutputPlugin = exampleUserPlugin
0383 ##       # arbitrary options can be created and set via the steering file or command line
0384 ##       SIM.outputConfig.myExtension = '.csv'
0385 ##     
0386 
0387 def outputPlugin(dd4hepSimulation):
0388   from DDG4 import EventAction, Kernel
0389   dd = dd4hepSimulation  # just shorter variable name
0390   evt_root = EventAction(Kernel(), 'Geant4Output2ROOT/' + dd.outputFile, True)
0391   evt_root.HandleMCTruth = True or False
0392   evt_root.Control = True
0393   output = dd.outputFile
0394   if not dd.outputFile.endswith(dd.outputConfig.myExtension):
0395     output = dd.outputFile + dd.outputConfig.myExtension
0396   evt_root.Output = output
0397   evt_root.enableUI()
0398   Kernel().eventAction().add(evt_root)
0399   return None
0400 
0401 SIM.outputConfig.myExtension = '.root'
0402 SIM.outputConfig.userOutputPlugin = outputPlugin
0403 
0404 
0405 ################################################################################
0406 ## Configuration for the Particle Handler/ MCTruth treatment 
0407 ################################################################################
0408 
0409 ## Enable lots of printout on simulated hits and MC-truth information
0410 SIM.part.enableDetailedHitsAndParticleInfo = False
0411 
0412 ##  Keep all created particles 
0413 SIM.part.keepAllParticles = False
0414 
0415 ## Minimal distance between particle vertex and endpoint of parent after
0416 ##     which the vertexIsNotEndpointOfParent flag is set
0417 ##     
0418 SIM.part.minDistToParentVertex = 2.2e-14
0419 
0420 ## MinimalKineticEnergy to store particles created in the tracking region
0421 SIM.part.minimalKineticEnergy = 1.0
0422 
0423 ##  Printout at End of Tracking 
0424 SIM.part.printEndTracking = False
0425 
0426 ##  Printout at Start of Tracking 
0427 SIM.part.printStartTracking = False
0428 
0429 ## List of processes to save, on command line give as whitespace separated string in quotation marks
0430 SIM.part.saveProcesses = ['Decay']
0431 
0432 ## Optionally enable an extended Particle Handler
0433 SIM.part.userParticleHandler = "Geant4TCUserParticleHandler"
0434 
0435 
0436 ################################################################################
0437 ## Configuration for the PhysicsList 
0438 ################################################################################
0439 
0440 ## If true, add decay processes for all particles.
0441 ## 
0442 ##     Only enable when creating a physics list not based on an existing Geant4 list!
0443 ##     
0444 SIM.physics.decays = False
0445 
0446 ## The name of the Geant4 Physics list.
0447 SIM.physics.list = "FTFP_BERT"
0448 
0449 ##  location of particle.tbl file containing extra particles and their lifetime information
0450 ## 
0451 ##     For example in $DD4HEP/examples/DDG4/examples/particle.tbl
0452 ##     
0453 SIM.physics.pdgfile = None
0454 
0455 ##  The global geant4 rangecut for secondary production
0456 ## 
0457 ##     Default is 0.7 mm as is the case in geant4 10
0458 ## 
0459 ##     To disable this plugin and be absolutely sure to use the Geant4 default range cut use "None"
0460 ## 
0461 ##     Set printlevel to DEBUG to see a printout of all range cuts,
0462 ##     but this only works if range cut is not "None"
0463 ##     
0464 SIM.physics.rangecut = 0.7
0465 
0466 ## Set of PDG IDs that will not be passed from the input record to Geant4.
0467 ## 
0468 ##     Quarks, gluons and W's Z's etc should not be treated by Geant4
0469 ##     
0470 SIM.physics.rejectPDGs = {1, 2, 3, 4, 5, 6, 3201, 3203, 4101, 4103, 21, 23, 24, 5401, 25, 2203, 5403, 3101, 3103, 4403, 2101, 5301, 2103, 5303, 4301, 1103, 4303, 5201, 5203, 3303, 4201, 4203, 5101, 5103, 5503}
0471 
0472 ## Set of PDG IDs for particles that should not be passed to Geant4 if their properTime is 0.
0473 ## 
0474 ##     The properTime of 0 indicates a documentation to add FSR to a lepton for example.
0475 ##     
0476 SIM.physics.zeroTimePDGs = {17, 11, 13, 15}
0477 
0478 def setupCerenkovScint(kernel):
0479      from DDG4 import PhysicsList
0480      seq = kernel.physicsList()
0481 
0482      scint = PhysicsList(kernel, 'Geant4ScintillationPhysics/ScintillationPhys')
0483      scint.VerboseLevel = 0
0484      scint.TrackSecondariesFirst = True
0485      scint.enableUI()
0486      seq.adopt(scint)
0487 
0488      cerenkov = PhysicsList(kernel, 'Geant4CerenkovPhysics/CerenkovPhys')
0489      cerenkov.VerboseLevel = 0
0490      cerenkov.MaxNumPhotonsPerStep = 10
0491      cerenkov.MaxBetaChangePerStep = 10.0
0492      cerenkov.TrackSecondariesFirst = True
0493      cerenkov.enableUI()
0494      seq.adopt(cerenkov)
0495 
0496      ph = PhysicsList(kernel, 'Geant4OpticalPhotonPhysics/OpticalGammaPhys')
0497      ph.addParticleConstructor('G4OpticalPhoton')
0498      ph.VerboseLevel = 0
0499      ph.enableUI()
0500      seq.adopt(ph)
0501 
0502      return None
0503 
0504 
0505 SIM.physics.setupUserPhysics(setupCerenkovScint)
0506 
0507 
0508 ################################################################################
0509 ## Properties for the random number generator 
0510 ################################################################################
0511 
0512 ## If True, calculate random seed for each event basedon eventID and runID
0513 ## Allows reproducibility even whenSkippingEvents
0514 SIM.random.enableEventSeed = False
0515 SIM.random.file = None
0516 SIM.random.luxury = 1
0517 SIM.random.replace_gRandom = True
0518 SIM.random.seed = None
0519 SIM.random.type = None