def __init__(self, module, standalone=True): """ Init with a module as a string or a registered one. """ if isinstance(module, str): import basf2 self.module = basf2.register_module(module) else: self.module = module self.standalone = standalone #: Template for the table beginning self.table_beginning_html = """<table style="margin-left: auto; margin-right: auto; border-collapse: separate; border-spacing: 0px;">""" #: Template for the table cell self.td_html = "style=\"padding: 10px;\"" #: Template for the row of parameters self.table_row_parameters = """<tr><td {td_style}>{param.name}</td> <td{color_text} {td_style}>{param.values}</td> <td style="color: gray; {td_style}>{param.default}</td></tr>""" #: Template for the row with help self.table_row_help = """<tr><td {td_style}>{param.name}</td> <td {td_style}>{param.type}</td> <td {td_style}>{param.values}</td> <td style="color: gray; {td_style}>{param.description}</td></tr>""" #: Template for the simple row self.table_row_html_single = """<tr><td colspan="4" {td_style}>{text}</td></tr>""" #: Template for the table title self.table_title_html = """<thead><td colspan="4" style="text-align: center;
def prepare(self): """ A function to prepare a path with the modules given in path. """ if self.path: # Append the needed ToFileLogger module created_path = basf2.create_path() file_logger_module = basf2.register_module("ToFileLogger") file_logger_module.param("fileName", self.log_file_name) created_path.add_module(file_logger_module) # Copy the modules from the path for module in self.path.modules(): created_path.add_module(module) # Add the progress python module created_path.add_module( python_modules.ProgressPython(self.progress_queue_remote)) # Add the print collections python module created_path.add_module( python_modules.PrintCollections(self.result_queue)) self.path = created_path else: self.is_valid = False
def prepare(self): """ A function to prepare a path with the modules given in path. """ if self.path: # Append the needed ToFileLogger module created_path = basf2.create_path() file_logger_module = basf2.register_module("ToFileLogger") file_logger_module.param("fileName", self.log_file_name) created_path.add_module(file_logger_module) # Copy the modules from the path for module in self.path.modules(): created_path.add_module(module) # Add the progress python module created_path.add_module(python_modules.ProgressPython(self.progress_queue_remote)) # Add the print collections python module created_path.add_module(python_modules.PrintCollections(self.result_queue)) self.path = created_path else: self.is_valid = False
def simulation(input_file, output_file): my_path = b2.create_path() print(f"Number of processes: {b2.get_nprocesses()}") # load input ROOT file ma.inputMdst(environmentType="default", filename=input_file, path=my_path) """ Loads the specified ROOT (DST/mDST/muDST) files with the RootInput module. The correct environment (e.g. magnetic field settings) are determined from the specified environment type. The currently available environments are: - 'MC5': for analysis of Belle II MC samples produced with releases prior to build-2016-05-01. This environment sets the constant magnetic field (B = 1.5 T) - 'MC6': for analysis of Belle II MC samples produced with build-2016-05-01 or newer but prior to release-00-08-00 - 'MC7': for analysis of Belle II MC samples produced with build-2016-05-01 or newer but prior to release-00-08-00 - 'MC8', for analysis of Belle II MC samples produced with release-00-08-00 or newer but prior to release-02-00-00 - 'MC9', for analysis of Belle II MC samples produced with release-00-08-00 or newer but prior to release-02-00-00 - 'MC10', for analysis of Belle II MC samples produced with release-00-08-00 or newer but prior to release-02-00-00 - 'default': for analysis of Belle II MC samples produced with releases with release-02-00-00 or newer. This environment sets the default magnetic field (see geometry settings) - 'Belle': for analysis of converted (or during of conversion of) Belle MC/DATA samples - 'None': for analysis of generator level information or during simulation/my_reconstruction of previously generated events Note that there is no difference between MC6 and MC7. Both are given for sake of completion. The same is true for MC8, MC9 and MC10 Parameters: environmentType (str): type of the environment to be loaded filename (str): the name of the file to be loaded path (basf2.Path): modules are added to this path skipNEvents (int): N events of the input files are skipped entrySequences (list(str)): The number sequences (e.g. 23:42,101) defining the entries which are processed for each inputFileName. parentLevel (int): Number of generations of parent files (files used as input when creating a file) to be read """ # In case of conflict with geometry, you may use this line instead: # analysis_main.add_module("RootInput", inputFileName='B2A101-Y4SEventGeneration-evtgen.root') # simulation si.add_simulation(path=my_path) # my_reconstruction re.add_reconstruction(path=my_path) # dump in MDST format mdst.add_mdst_output(path=my_path, mc=True, filename=output_file) # Show progress of processing progress = b2.register_module("ProgressBar") my_path.add_module(progress) # Process the events b2.process(my_path) print(b2.statistics)
if binID < 46: binID += 1 weightInfo = {} weightInfo["Weight"] = float(random.randint(0, 100)) / 100 weightInfo["StatErr"] = float(random.randint(100, 200)) / 100 weightInfo["SystErr"] = float(10) tableIDSpec.append([[weightInfo, make_2D_bin(xbin, ybin)], binID]) # And of course let's define out-of-range bin info outOfRangeWeightInfo = {} outOfRangeWeightInfo["Weight"] = -1 outOfRangeWeightInfo["StatErr"] = -1 outOfRangeWeightInfo["SystErr"] = -1 # Now, let's configure table creator addtable = b2.register_module('ParticleWeightingLookUpCreator') addtable.param('tableIDSpec', tableIDSpec) addtable.param('outOfRangeWeight', outOfRangeWeightInfo) addtable.param('experimentHigh', 1000) addtable.param('experimentLow', 0) addtable.param('runHigh', 1000) addtable.param('runLow', 0) addtable.param('tableName', "ParticleReweighting:TestMomentum") addtable2 = b2.register_module('ParticleWeightingLookUpCreator') addtable2.param('tableIDNotSpec', tableIDNotSpec) addtable2.param('outOfRangeWeight', outOfRangeWeightInfo) addtable2.param('experimentHigh', 1000) addtable2.param('experimentLow', 0) addtable2.param('runHigh', 1000) addtable2.param('runLow', 0)
) db_location = os.getenv('BELLE2_EXAMPLES_DATA_DIR') + '/database/' b2.use_local_database(db_location + 'database.txt', directory=db_location, readonly=True) # We know what weight info will be added (see B2A904), # so we add aliases and add it ot tools va.variables.addAlias('Weight', 'extraInfo(' + weight_table_id + '_Weight)') va.variables.addAlias('StatErr', 'extraInfo(' + weight_table_id + '_StatErr)') va.variables.addAlias('SystErr', 'extraInfo(' + weight_table_id + '_SystErr)') va.variables.addAlias('binID', 'extraInfo(' + weight_table_id + '_binID)') # We configure weighing module reweighter = b2.register_module('ParticleWeighting') reweighter.param('tableName', weight_table_id) reweighter.param('particleList', 'pi+:gen') my_path.add_module(reweighter) pivars = ['p', 'pz', 'Weight', 'StatErr', 'SystErr', 'binID'] # Saving variables to ntuple output_file = 'B2A905-ApplyWeightsToTracks.root' ma.variablesToNtuple(decayString='pi+:gen', variables=pivars, treename='pion', filename=output_file, path=my_path) # Process the events
# load input ROOT file # ma.inputMdst(environmentType='default', # filename=b2.find_file('B2pi0D_D2hh_D2hhh_B2munu_evtgen.root', 'examples', False), # path=my_path) my_path.add_module("RootInput", inputFileName='event_gen.root') # Without loadGearbox the program will run just fine. # ma.loadGearbox(path=my_path) # simulation si.add_simulation(path=my_path) # reconstruction # Not sure what is reconstructed here. re.add_reconstruction(path=my_path) # dump in MDST format mdst.add_mdst_output(path=my_path, mc=True, filename='sim_recon.root') # Show progress of processing progress = b2.register_module('ProgressBar') my_path.add_module(progress) # Process the events b2.process(my_path) # print out the summary print(b2.statistics)