Example #1
0
    def create_path(self):
        path = basf2.create_path()
        modularAnalysis.setupEventInfo(self.n_events, path)

        if self.event_type == SimulationType.y4s:
            # in current main branch and release 5 the Y(4S)decay file is moved, so try old and new locations
            find_file_ignore_error = True
            dec_file = Belle2.FileSystem.findFile(
                'analysis/examples/tutorials/B2A101-Y4SEventGeneration.dec',
                find_file_ignore_error)
            if not dec_file:
                dec_file = Belle2.FileSystem.findFile(
                    'analysis/examples/simulations/B2A101-Y4SEventGeneration.dec'
                )
        elif self.event_type == SimulationType.continuum:
            dec_file = Belle2.FileSystem.findFile(
                'analysis/examples/simulations/B2A102-ccbarEventGeneration.dec'
            )
        else:
            raise ValueError(
                f"Event type {self.event_type} is not valid. It should be either 'Y(4S)' or 'Continuum'!"
            )

        generators.add_evtgen_generator(path, 'signal', dec_file)
        modularAnalysis.loadGearbox(path)
        simulation.add_simulation(path)

        path.add_module('RootOutput',
                        outputFileName=self.get_output_file_name(
                            'simulation_full_output.root'))

        return path
Example #2
0
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)
Example #3
0
from reconstruction import add_mdst_output

import sys

# load input ROOT file

inputName = ['testSkimming_BBbar-10M-1.root']
outputName = 'reconstructedBBbar.root'

inputMdstList(inputName)

bkgdir = '/b2data/gaz/local_installation/bkg/bkg/'
bkgFiles = [bkgdir + '*.root']

# simulation
add_simulation(analysis_main)

# reconstruction
add_reconstruction(analysis_main)

# dump in MDST format
add_mdst_output(analysis_main, True,outputName)

# Show progress of processing
progress = register_module('Progress')
analysis_main.add_module(progress)

# Process the events
process(analysis_main)

# print out the summary
fragmentation.param('ListPYTHIAEvent', 0)
fragmentation.param('UseEvtGen', 1)
fragmentation.param(
    'DecFile',
    Belle2.FileSystem.findFile(
        'data/generators/modules/fragmentation/dec_belle2_qqbar.dec'))
fragmentation.param(
    'UserDecFile',
    os.path.expandvars('$BELLE2_EXTERNALS_DIR/share/evtgen/DECAY_2010.DEC'))
main.add_module(fragmentation)

# branch to an empty path if PYTHIA failed, this will change the number of events
# but the file meta data will contain the total number of generated events
"""generator_emptypath = create_path()
fragmentation.if_value('<1',generator_emptypath)"""
"""# detector simulation
add_simulation(main, bkgfiles=bg)

# remove the cache for background files to reduce memory
set_module_parameters(main, "BeamBkgMixer", cacheSize=0)

# trigger simulation
add_tsim(main)

# reconstruction
add_reconstruction(main)

# Finally add mdst output
add_mdst_output(main, filename=output_filename, additionalBranches=['KlIds', 'KLMClustersToKlIds'])
"""
#process events and print call statistics
Example #5
0
output_filename = "mdst.root"

# create path
main = b2.create_path()

# specify number of events to be generated
main.add_module("EventInfoSetter",
                expList=1003,
                runList=0,
                evtNumList=num_events)

# generate BBbar events
ge.add_evtgen_generator(main, finalstate='mixed')

# detector simulation
si.add_simulation(main)

# trigger simulation
l1.add_tsim(main, Belle2Phase="Phase3")

# reconstruction
#RJS
re.add_reconstruction(main)

# Finally add mdst output
#RJS re.add_mdst_output(main, filename=output_filename)

# process events and print call statistics
b2.process(main)
print(b2.statistics)
Example #6
0
eventinfosetter.param('evtNumList', [100])
eventinfosetter.param('runList', [1])
eventinfosetter.param('expList', [1])
main.add_module(eventinfosetter)

# Event generator (B0 -> K+pi- + cc, other B0 generic)
evtgeninput = register_module('EvtGenInput')
evtgeninput.param('userDECFile',
                  Belle2.FileSystem.findFile('top/examples/B2Kpi.dec'))
main.add_module(evtgeninput)

# Detector simulation
bg = None
if 'BELLE2_BACKGROUND_DIR' in os.environ:
    bg = glob.glob(os.environ['BELLE2_BACKGROUND_DIR'] + '/*.root')
add_simulation(main, bkgfiles=bg)
print("DISPLAY: " + os.environ['DISPLAY'])

# Reconstruction
add_reconstruction(main)

# Output to mdst
add_mdst_output(main, filename='evtgenB2Kpi.mdst.root')

# Output to a flat ntuple with TOP likelihoods, track info and MC truth
ntuple = register_module('TOPNtuple')
ntuple.param('outputFileName', 'ntupleB2Kpi.root')
main.add_module(ntuple)

dqmmodule = register_module("TOPDataQualityOnline")
dqmmodule.param('framesPerEvent',1)
Example #7
0
#!/usr/bin/env python3

import basf2
from modularAnalysis import outputMdst
from reconstruction import add_reconstruction
from simulation import add_simulation

path = basf2.create_path()

# Add modules to the root basf2 path; Parameters can be retrieved using basf2.print_params(`moduleVar`)
setter = path.add_module("EventInfoSetter", evtNumList=[100000])
generator = path.add_module("EvtGenInput", userDECFile='b2_mc_event.dec')

add_simulation(path)
add_reconstruction(path)

outputMdst('b2_mc_events.mdst.root', path=path)

basf2.process(path)
Example #8
0
from reconstruction import add_mdst_output

import sys

# load input ROOT file

inputName = ['testSkimming_2-7.root', 'testSkimming_8-10.root']
outputName = 'reconstructedContinuum.root'

inputMdstList(inputName)

bkgdir = '/b2data/gaz/local_installation/bkg/bkg/'
bkgFiles = [bkgdir + '*.root']

# simulation
add_simulation(analysis_main)

# reconstruction
add_reconstruction(analysis_main)

# dump in MDST format
add_mdst_output(analysis_main, True, outputName)

# Show progress of processing
progress = register_module('Progress')
analysis_main.add_module(progress)

# Process the events
process(analysis_main)

# print out the summary
Example #9
0
from basf2 import *
from modularAnalysis import generateY4S
from modularAnalysis import analysis_main
from simulation import add_simulation
from reconstruction import add_reconstruction
from reconstruction import add_mdst_output
from ROOT import Belle2

# generate signal MC
generateY4S(
    10000,
    Belle2.FileSystem.findFile('../dec_files/B0_phi-K+K-_KS-pi+pi-.dec'))

bkgdir = '/sw/belle2/bkg/'
bkgFiles = [bkgdir + '*.root']

# simulation
add_simulation(analysis_main, None, bkgFiles)  # WITH beam background

# reconstruction
add_reconstruction(analysis_main)

# dump in MDST format
add_mdst_output(analysis_main, True, 'B0_Phi-KK_Ks-pi+pi-_gsim-BKGx1.root')

# Process the events
process(analysis_main)

# print out the summary
print statistics
Example #10
0
# create path
my_path = b2.create_path()

# 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)
Example #11
0
# for model, model_type in zip(args.model, args.model_type):
#     NNApplyModule_m = NNApplyModule(
#         model_file=model,
#         model_type=model_type,
#         threshold=args.threshold,
#     )
#     dead_path = b2.create_path()
#     NNApplyModule_m.if_false(dead_path)

#     main.add_module(NNApplyModule_m)
#     # Do I need this here?
#     # c1.set_property_flags(b2.ModulePropFlags.PARALLELPROCESSINGCERTIFIED)

# ma.loadGearbox(path=main)
# main.add_module('Geometry', ignoreIfPresent=True, components=['MagneticField'])
simulation.add_simulation(path=main,
                          bkgfiles=glob.glob(args.bkg_dir + '/*.root'))
reconstruction.add_reconstruction(path=main)

# dump generated events in MDST format to the output ROOT file
reconstruction.add_mdst_output(
    path=main,
    mc=True,
    filename='RootOutput.root',
    additionalBranches=['EventExtraInfo'],
)

# Begin processing
################################################################################
main.add_module('ProgressBar')
b2.process(path=main)
evtgen = register_module('EvtGenInput')

# Sets evtgen only in a more verbose mode
evtgen.set_log_level(LogLevel.INFO)
# Gets the user-defined decay file 
evtgen.param('userDECFile', sys.argv[1]) 

# These lines are needed to generate non-Upsilon(4S) events.
# As example we report here the Upsilon(3S) case
#evtgen.param('ParentParticle', 'Upsilon(3S)') 
#beamparameters = add_beamparameters(main, "Y3S")

# run
main.add_module("Progress")
main.add_module("Gearbox")
main.add_module("Geometry")
main.add_module(evtgen)
add_simulation(main)
add_reconstruction(main)

# Shows immediately what is being generated as text output on the terminal
#main.add_module("PrintMCParticles", logLevel=LogLevel.DEBUG, onlyPrimaries=True)
# sets the output name
main.add_module("RootOutput", outputFileName=sys.argv[2]) 

# Process the events
process(main)

# show call statistics
print(statistics)
	outputFilename = sys.argv[2]

add_beamparameters(analysis_main, 'Y4S')

# check if the required input file exists (from B2A101 example)
#if not os.path.isfile('B2A101-Y4SEventGeneration-evtgen.root'):
#if not os.path.isfile('evtgen.root'):
#    sys.exit('Required input file (B2A101-Y4SEventGeneration-evtgen.root) does not exist. '
#             'Please run B2A101-Y4SEventGeneration.py tutorial script first.')

# load input ROOT file
#inputMdst('None', 'B2A101-Y4SEventGeneration-evtgen.root')
inputMdst('None', inputFilename)

# simulation
add_simulation(analysis_main, use_vxdtf2 = True)

# reconstruction
add_reconstruction(analysis_main, use_vxdtf2 = True)

# dump in MDST format
add_mdst_output(analysis_main, True, outputFilename)

# Show progress of processing
progress = register_module('ProgressBar')
analysis_main.add_module(progress)

# Process the events
process(analysis_main)

# print out the summary
from ROOT import Belle2
import glob

# generate signal MC
generateY4S(
    100,
    Belle2.FileSystem.findFile(
        '../dec_files/B0_etapr-eta-gg2pi_KS-pi+pi-.dec'
        #'../dec_files/B0_etapr-eta-gg2pi_KS-pi0pi0.dec'
        #'../dec_files/B0_etapr-eta-gg2pi_KL.dec'
        #'../dec_files/B0_etapr-eta-3pi2pi_KS-pi+pi-.dec'
        #'../dec_files/B0_etapr-eta-3pi2pi_KS-pi0pi0.dec'
    ))

# simulation
add_simulation(analysis_main)  # WITHOUT beam background

# reconstruction
add_reconstruction(analysis_main)

# dump in MDST format
add_mdst_output(
    analysis_main, True, 'B0_etapr-eta-gg2pi_KS-pi+pi-_gsim-BKGx0.root'
    #'B0_etapr-eta-gg2pi_KS-pi0pi0_gsim-BKGx0.root'
    #'B0_etapr-eta-gg2pi_KL_gsim-BKGx0.root'
    #'B0_etapr-eta-3pi2pi_KS-pi+pi-_gsim-BKGx0.root'
    #'B0_etapr-eta-3pi2pi_KS-pi0pi0_gsim-BKGx0.root'
)

# Process the events
process(analysis_main)
    )

outFile = str(sys.argv[1])

from basf2 import *
from modularAnalysis import generateY4S
from modularAnalysis import analysis_main
from simulation import add_simulation
from reconstruction import add_reconstruction
from reconstruction import add_mdst_output
from ROOT import Belle2
import glob

# generate signal MC
generateY4S(10000, Belle2.FileSystem.findFile('../dec_files/B0_phi-K+K-_KS-pi+pi-.dec'))

# simulation
add_simulation(analysis_main)      # WITHOUT beam background

# reconstruction
add_reconstruction(analysis_main)

# dump in MDST format
add_mdst_output(analysis_main, True, outFile)

# Process the events
process(analysis_main)

# print out the summary
print (statistics)
fragmentation.param(
    'DecFile',
    Belle2.FileSystem.findFile(
        'data/generators/modules/fragmentation/dec_belle2_qqbar.dec'))
fragmentation.param(
    'UserDecFile',
    os.path.expandvars('$BELLE2_EXTERNALS_DIR/share/evtgen/DECAY_2010.DEC'))
main.add_module(fragmentation)

# branch to an empty path if PYTHIA failed, this will change the number of events
# but the file meta data will contain the total number of generated events
generator_emptypath = create_path()
fragmentation.if_value('<1', generator_emptypath)

# detector simulation
add_simulation(main, bkgfiles=bg)

# remove the cache for background files to reduce memory
set_module_parameters(main, "BeamBkgMixer", cacheSize=0)

# trigger simulation
add_tsim(main)

# reconstruction
add_reconstruction(main)

# Finally add mdst output
add_mdst_output(main,
                filename=output_filename,
                additionalBranches=['KlIds', 'KLMClustersToKlIds'])
from basf2 import *
from modularAnalysis import generateY4S
from modularAnalysis import analysis_main
from simulation import add_simulation
from reconstruction import add_reconstruction
from reconstruction import add_mdst_output
from ROOT import Belle2

# generate signal MC
generateY4S(1000, Belle2.FileSystem.findFile('../dec_files/B0_phi-K+K-_KS-pi+pi-.dec'))

bkgdir = '/sw/belle2/bkg/'
bkgFiles = [bkgdir + '*.root']

# simulation
add_simulation(analysis_main, None, bkgFiles)     # WITH beam background

# reconstruction
add_reconstruction(analysis_main)

# dump in MDST format
add_mdst_output(analysis_main, True,
                'B0_Phi-KK_Ks-pi+pi-_gsim-BKGx1.root')

# Process the events
process(analysis_main)

# print out the summary
print statistics