Physics.py 4.27 KB
Newer Older
1
2
3
4
5
6
7
"""Helper object for physicslist properties"""

from __future__ import absolute_import, unicode_literals
import os

from DDSim.Helper.ConfigHelper import ConfigHelper
from g4units import mm
8
import logging
9
10
import ddsix as six

11
logger = logging.getLogger(__name__)
12
13
14
15
16
17
18
19
20
21

class Physics(ConfigHelper):
  """Configuration for the PhysicsList"""

  def __init__(self):
    super(Physics, self).__init__()
    self._rangecut = 0.7 * mm
    self._list = "FTFP_BERT"
    self._decays = False
    self._pdgfile = None
22
    self._rejectPDGs = {1, 2, 3, 4, 5, 6, 21, 23, 24, 25, 431, 433, 2101}
23
    self._zeroTimePDGs = {11, 13, 15, 17}
24
    self._trackSecondariesFirst = False
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

  @property
  def rejectPDGs(self):
    """Set of PDG IDs that will not be passed from the input record to Geant4.

    Quarks, gluons and W's Z's etc should not be treated by Geant4
    """
    return self._rejectPDGs

  @rejectPDGs.setter
  def rejectPDGs(self, val):
    self._rejectPDGs = self.makeSet(val)

  @property
  def zeroTimePDGs(self):
    """Set of PDG IDs for particles that should not be passed to Geant4 if their properTime is 0.

    The properTime of 0 indicates a documentation to add FSR to a lepton for example.
    """
    return self._zeroTimePDGs

  @zeroTimePDGs.setter
  def zeroTimePDGs(self, val):
    self._zeroTimePDGs = self.makeSet(val)

  @property
  def rangecut(self):
    """ The global geant4 rangecut for secondary production

    Default is 0.7 mm as is the case in geant4 10

    To disable this plugin and be absolutely sure to use the Geant4 default range cut use "None"

    Set printlevel to DEBUG to see a printout of all range cuts,
    but this only works if range cut is not "None"
    """
    return self._rangecut

  @rangecut.setter
  def rangecut(self, val):
    if val is None:
      self._rangecut = None
      return
    if isinstance(val, six.string_types):
      if val == "None":
        self._rangecut = None
        return
    self._rangecut = val

  @property
  def pdgfile(self):
    """ location of particle.tbl file containing extra particles and their lifetime information

    For example in $DD4HEP/examples/DDG4/examples/particle.tbl
    """
    return self._pdgfile

  @pdgfile.setter
  def pdgfile(self, val):
    if not val:
      self._pdgfile = None
      return
    if not os.path.exists(val):
      raise RuntimeError("PDGFile: %s not found" % os.path.abspath(val))
    self._pdgfile = os.path.abspath(val)

  @property
  def decays(self):
    """If true, add decay processes for all particles.

    Only enable when creating a physics list not based on an existing Geant4 list!
    """
    return self._decays

  @decays.setter
  def decays(self, val):
    self._decays = val

  @property
  def list(self):
    """The name of the Geant4 Physics list."""
    return self._list

  @list.setter
  def list(self, val):
    self._list = val

112
113
114
115
116
117
118
119
120
  @property
  def trackSecondariesFirst(self):
    """Track Cerenkov and scintillation secondaries first (potentially large memory use)."""
    return self._trackSecondariesFirst

  @trackSecondariesFirst.setter
  def trackSecondariesFirst(self, val):
    self._trackSecondariesFirst = self.makeBool(val)

121
122
123
124
125
126
127
128
  def setupPhysics(self, kernel, name=None):
    seq = kernel.physicsList()
    seq.extends = name if name is not None else self.list
    seq.decays = self.decays
    seq.enableUI()
    seq.dump()
    from DDG4 import PhysicsList

129
130
131
    logger.info(" Setting up Optical Photon Physics")
    ph = PhysicsList(kernel, 'EICOpticalPhotonPhysics/OpticalPhotonPhys')
    ph.VerboseLevel = 0
Whitney Armstrong's avatar
Whitney Armstrong committed
132
133
134
    ph.enableUI()
    seq.adopt(ph)

135
136
137
    logger.info(" Setting up Cerenkov Physics")
    cer = PhysicsList(kernel, 'EICCerenkovPhysics/CerenkovPhys')
    cer.VerboseLevel = 0
Whitney Armstrong's avatar
Whitney Armstrong committed
138
139
    cer.MaxNumPhotonsPerStep = 10
    cer.MaxBetaChangePerStep = 10.0
140
    cer.TrackSecondariesFirst = self.trackSecondariesFirst
Whitney Armstrong's avatar
Whitney Armstrong committed
141
142
    cer.enableUI()
    seq.adopt(cer)
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

    # Add special particle types from specialized physics constructor
    if self.pdgfile:
      part = PhysicsList(kernel, 'Geant4ExtraParticles/ExtraParticles')
      part.enableUI()
      seq.adopt(part)
      part.pdgfile = self.pdgfile

    # Add global range cut
    if self.rangecut is not None:
      rg = PhysicsList(kernel, 'Geant4DefaultRangeCut/GlobalRangeCut')
      rg.enableUI()
      seq.adopt(rg)
      rg.RangeCut = self.rangecut

    return seq