def direction(self, val): """ make sure the direction is parseable by boost, i.e. (1.0, 1.0, 1.0) """ self._direction = ConfigHelper.makeTuple(val) if len(self._direction) != 3: raise RuntimeError( " gun.direction: malformed input '%s', needs to be a string representing a three vector " % val)
def position(self, val): """check that the position is a three vector and can be parsed by ddg4""" self._position = ConfigHelper.makeTuple(val) if len(self._position) != 3: raise RuntimeError( " gun.position: malformed input '%s', needs to be a string representing a three vector " % val)
def isotrop( self, val ): """check that value is equivalent to bool""" try: self._isotrop = ConfigHelper.makeBool( val ) except RuntimeError: raise RuntimeError( "malformed input '%s' for gun.isotrop " % val) if val and self.distribution is None: self.distribution = 'uniform'
def setupFilters( self, kernel): """ attach all filters to the kernel """ import DDG4 setOfFilters = set() for name, filt in self.filters.iteritems(): setOfFilters.add(name) ddFilt = DDG4.Filter(kernel,filt['name']) for para, value in filt['parameter'].iteritems(): setattr( ddFilt, para, value ) kernel.registerGlobalFilter(ddFilt) filt['filter'] = ddFilt from itertools import chain listOfFilters = [] for val in self.mapDetFilter.values(): listOfFilters += ConfigHelper.makeList(val) requestedFilter = set(chain( ConfigHelper.makeList(self.tracker), ConfigHelper.makeList(self.calo), listOfFilters)) print "ReqFilt",requestedFilter if requestedFilter - setOfFilters: raise RuntimeError(" Filter(s) '%s' are not registered!" % str(requestedFilter - setOfFilters) )
def _buildInputStage(self, simple, generator_input_modules, output_level=None, have_mctruth=True): """ Generic build of the input stage with multiple input modules. Actions executed are: 1) Register Generation initialization action 2) Append all modules to build the complete input record These modules are readers/particle sources, boosters and/or smearing actions. 3) Merge all existing interaction records 4) Add the MC truth handler """ from DDG4 import GeneratorAction ga = simple.kernel().generatorAction() # Register Generation initialization action gen = GeneratorAction(simple.kernel(), "Geant4GeneratorActionInit/GenerationInit") if output_level is not None: gen.OutputLevel = output_level ga.adopt(gen) # Now append all modules to build the complete input record # These modules are readers/particle sources, boosters and/or smearing actions for gen in generator_input_modules: gen.enableUI() if output_level is not None: gen.OutputLevel = output_level ga.adopt(gen) # Merge all existing interaction records gen = GeneratorAction(simple.kernel(), "Geant4InteractionMerger/InteractionMerger") gen.enableUI() if output_level is not None: gen.OutputLevel = output_level ga.adopt(gen) # Finally generate Geant4 primaries if have_mctruth: gen = GeneratorAction(simple.kernel(), "Geant4PrimaryHandler/PrimaryHandler") gen.RejectPDGs = ConfigHelper.makeString(self.physics.rejectPDGs) gen.enableUI() if output_level is not None: gen.OutputLevel = output_level ga.adopt(gen) # Puuuhh! All done. return None
def __makeMapDetList(self): """ create the values of the mapDetFilters a list of filters """ for pattern, filters in self._mapDetFilter.iteritems(): self._mapDetFilter[pattern] = ConfigHelper.makeList(filters)
def parseOptions(self, argv=None): """parse the command line options""" if argv is None: self._argv = list(sys.argv) parser = argparse.ArgumentParser( "Running DD4hep Simulations:", formatter_class=argparse.RawTextHelpFormatter) parser.add_argument("--steeringFile", "-S", action="store", default=self.steeringFile, help="Steering file to change default behaviour") #first we parse just the steering file, but only if we don't want to see the help message if not any(opt in self._argv for opt in ('-h', '--help')): parsed, _unknown = parser.parse_known_args() self.steeringFile = parsed.steeringFile self.readSteeringFile() ## readSteeringFile will set self._argv to None if there is a steering file if self._argv is None: self._argv = list(argv) if argv else list(sys.argv) parser.add_argument("--compactFile", action="store", default=self.compactFile, help="The compact XML file") parser.add_argument( "--runType", action="store", choices=("batch", "vis", "run", "shell"), default=self.runType, help= "The type of action to do in this invocation" ##Note: implicit string concatenation "\nbatch: just simulate some events, needs numberOfEvents, and input file or gun" "\nvis: enable visualisation, run the macroFile if it is set" "\nrun: run the macroFile and exit" "\nshell: enable interactive session") parser.add_argument( "--inputFiles", "-I", nargs='+', action="store", default=self.inputFiles, help="InputFiles for simulation %s files are supported" % ", ".join(POSSIBLEINPUTFILES)) parser.add_argument( "--outputFile", "-O", action="store", default=self.outputFile, help="Outputfile from the simulation,only lcio output is supported" ) parser.add_argument( "-v", "--printLevel", action="store", default=self.printLevel, dest="printLevel", choices=(1, 2, 3, 4, 5, 6, 7, 'VERBOSE', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'FATAL', 'ALWAYS'), help="Verbosity use integers from 1(most) to 7(least) verbose" "\nor strings: VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL, ALWAYS" ) parser.add_argument( "--numberOfEvents", "-N", action="store", dest="numberOfEvents", default=self.numberOfEvents, type=int, help="number of events to simulate, used in batch mode") parser.add_argument("--skipNEvents", action="store", dest="skipNEvents", default=self.skipNEvents, type=int, help="Skip first N events when reading a file") parser.add_argument("--physicsList", action="store", dest="physicsList", default=self.physicsList, help="Physics list to use in simulation") parser.add_argument( "--crossingAngleBoost", action="store", dest="crossingAngleBoost", default=self.crossingAngleBoost, type=float, help="Lorentz boost for the crossing angle, in radian!") parser.add_argument( "--vertexSigma", nargs=4, action="store", dest="vertexSigma", default=self.vertexSigma, metavar=('X', 'Y', 'Z', 'T'), type=float, help= "FourVector of the Sigma for the Smearing of the Vertex position: x y z t" ) parser.add_argument( "--vertexOffset", nargs=4, action="store", dest="vertexOffset", default=self.vertexOffset, metavar=('X', 'Y', 'Z', 'T'), type=float, help= "FourVector of translation for the Smearing of the Vertex position: x y z t" ) parser.add_argument( "--macroFile", "-M", action="store", dest="macroFile", default=self.macroFile, help="Macro file to execute for runType 'run' or 'vis'") parser.add_argument("--enableGun", "-G", action="store_true", dest="enableGun", default=self.enableGun, help="enable the DDG4 particle gun") parser.add_argument( "--enableG4GPS", action="store_true", dest="enableG4GPS", default=self.enableG4GPS, help= "enable the Geant4 GeneralParticleSource. Needs a macroFile (runType run) or use it with the shell (runType shell)" ) parser.add_argument( "--enableG4Gun", action="store_true", dest="enableG4Gun", default=self.enableG4Gun, help= "enable the Geant4 particle gun. Needs a macroFile (runType run) or use it with the shell (runType shell)" ) parser.add_argument("--dumpParameter", "--dump", action="store_true", dest="dumpParameter", default=self._dumpParameter, help="Print all configuration Parameters and exit") parser.add_argument("--enableDetailedShowerMode", action="store_true", dest="enableDetailedShowerMode", default=self.enableDetailedShowerMode, help="use detailed shower mode") parser.add_argument("--dumpSteeringFile", action="store_true", dest="dumpSteeringFile", default=self._dumpSteeringFile, help="print an example steering file to stdout") #output, or do something smarter with fullHelp only for example ConfigHelper.addAllHelper(self, parser) ## now parse everything. The default values are now taken from the ## steeringFile if they were set so that the steering file parameters can be ## overwritten from the command line if ARGCOMPLETEENABLED: argcomplete.autocomplete(parser) parsed = parser.parse_args() self._dumpParameter = parsed.dumpParameter self._dumpSteeringFile = parsed.dumpSteeringFile self.compactFile = parsed.compactFile self.inputFiles = parsed.inputFiles self.inputFiles = self.__checkFileFormat(self.inputFiles, POSSIBLEINPUTFILES) self.outputFile = parsed.outputFile self.__checkFileFormat(self.outputFile, ('.root', '.slcio')) self.runType = parsed.runType self.printLevel = self.__checkOutputLevel(parsed.printLevel) self.numberOfEvents = parsed.numberOfEvents self.skipNEvents = parsed.skipNEvents self.physicsList = parsed.physicsList self.crossingAngleBoost = parsed.crossingAngleBoost self.macroFile = parsed.macroFile self.enableGun = parsed.enableGun self.enableG4Gun = parsed.enableG4Gun self.enableG4GPS = parsed.enableG4GPS self.enableDetailedShowerMode = parsed.enableDetailedShowerMode self.vertexOffset = parsed.vertexOffset self.vertexSigma = parsed.vertexSigma self._consistencyChecks() #self.__treatUnknownArgs( parsed, unknown ) self.__parseAllHelper(parsed) if self._errorMessages and not (self._dumpParameter or self._dumpSteeringFile): parser.epilog = "\n".join(self._errorMessages) parser.print_help() exit(1) if self._dumpParameter: from pprint import pprint print "=" * 80 pprint(vars(self)) print "=" * 80 exit(1) if self._dumpSteeringFile: self.__printSteeringFile(parser) exit(1)
def __makeMapDetList( self ): """ create the values of the mapDetFilters a list of filters """ for pattern, filters in self._mapDetFilter.iteritems(): self._mapDetFilter[pattern] = ConfigHelper.makeList(filters)
def saveProcesses(self, stringVal): self._saveProcesses = ConfigHelper.makeList(stringVal)
def trackerSDTypes(self, val): self._trackerSDTypes = ConfigHelper.makeList(val)
def calorimeterSDTypes(self, val): self._calorimeterSDTypes = ConfigHelper.makeList(val)
def saveProcesses(self, stringVal): self._saveProcesses = ConfigHelper.makeList( stringVal )
def position( self, val ): """check that the position is a three vector and can be parsed by ddg4""" self._position = ConfigHelper.makeTuple( val ) if len(self._position) != 3: raise RuntimeError(" gun.position: malformed input '%s', needs to be a string representing a three vector " % val )
def direction( self, val ): """ make sure the direction is parseable by boost, i.e. (1.0, 1.0, 1.0) """ self._direction = ConfigHelper.makeTuple( val ) if len(self._direction) != 3: raise RuntimeError(" gun.direction: malformed input '%s', needs to be a string representing a three vector " % val )