"""Class to convert genie Monte Carlo for SimG4. Genie is run as a program external to the main comet code. This module follows on from the genieMC module. """ import cometModule import cometGeometry import cometRun import os class genieConvert(cometModule.cometModule): """A class to convert genie Monte Carlo for SimG4 """ ########################################################### def checkConfig(self): """Check and fix the Monte Carlo type.""" # The Monte Carlo type must be set to Genie if self.config.options.has_option("SimG4","mc_type"): if (self.config.options.get("SimG4","mc_type") == "Genie"): return True else: self.config.log.error("The config option SimG4/mc_type is not set to Genie, but running genieMC module. Reset this option to Genie") self.config.options.set("SimG4","mc_type","Genie") else: # The option doesn't exist, set it. self.config.log.error("The config option SimG4/mc_type is not set, but running genieMC module. Setting this option to Genie") # Create the section if it doesn't exist. if not self.config.options.has_section("SimG4"): self.config.options.add_section("SimG4") # Set the option self.config.options.set("SimG4","mc_type","Genie") ########################################################### def getOutputFilename(self): """Get the output filename""" self.outname = self.createFileName("root") return self.outname ########################################################### def getModuleName(self): """Return module name""" return "genieConvert" ########################################################### def getShortModuleName(self): """Return module name""" return "numc" ####################################################################### def checkModuleConfig(self): """Checks the configuration""" # Make sure that the enviromnet setup script exists. if self.config.options.has_option("software","genie_setup_script"): script = self.config.options.get("software","genie_setup_script") if not os.path.isfile(script): self.config.log.error("Cannot locate specified Genie setup script "+script) return False else: self.config.log.error("Genie MC being run, but setup script not set in the config file. Please use the software/genie_setup_script option") return False return True ########################################################### def process(self): """Run the jobs for Genie Convert""" # Setup the job commands. # Start by executing the setup script, and unsetting LD_LIBRARY_PATH. job = "unset LD_LIBRARY_PATH\n" script = self.config.options.get("software","genie_setup_script") job += "source "+script+"\n" # What is the run number. We want to remove leading zeros. # run = int(self.config.runnumber.split("-")[0]) # Cut down on Genie verbosity if self.config.options.has_option("neutrino","verbose"): if not self.config.options.getboolean("neutrino","verbose"): job += "export GPRODMODE=YES\n" else: job += "export GPRODMODE=YES\n" # Run the conversion. job += "$GENIE/bin/gntpc" job += " -i "+self.inputname job += " -o "+self.getOutputFilename() job += " -f t2k_rootracker" job += "\n" self.run = cometRun.cometRun(job,self.config) self.run.setCallName(self.getModuleName()) # We don't want to configure cmt programs this time. self.run.setup = False self.run.run() self.config.log.output(self.run.stdout) self.config.log.error(self.run.stderr)