Ejemplo n.º 1
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)
# Contributors: Umberto Tamponi (October 2018)
# [email protected]
#
####################################################################


import basf2 as b2
import modularAnalysis as ma
import variables.collections

# create path
my_path = b2.create_path()

# load input ROOT file
ma.inputMdst(environmentType='default',
             filename=b2.find_file('B02D0pi0_D02pi0pi0.root', 'examples', False),
             path=my_path)


# Creates a list of all the good tracks (using the pion mass hypothesys)
# and good gammas with very minimal cuts
ma.fillParticleList(decayString='pi+:all',
                    cut='pt> 0.1',
                    path=my_path)
ma.fillParticleList(decayString='gamma:all',
                    cut='E > 0.1',
                    path=my_path)

# Builds the event shape enabling explicitly ALL the variables.
# Most of the are actually enabled by defoult, but here we prefer
# to list explicitly all the flags
Ejemplo n.º 3
0
#
######################################################

from basf2 import *
from modularAnalysis import inputMdst
from modularAnalysis import printDataStore
from modularAnalysis import printList
from modularAnalysis import fillParticleListsFromMC
from modularAnalysis import printPrimaryMCParticles
from modularAnalysis import printVariableValues
from modularAnalysis import analysis_main


# load input ROOT file
# inputMdst('B0_etapr-eta-gg2pi_KS-pi+pi-_gsim-BKGx0.root')
inputMdst('../root_files/B0_etapr-eta-gg2pi_KS-pi0pi0_gsim-BKGx0.root')
# inputMdst('B0_etapr-eta-gg2pi_KL-_gsim-BKGx0.root')
# inputMdst('B0_etapr-eta-3pi2pi_KS-pi+pi-_gsim-BKGx0.root')

printPrimaryMCParticles()
# print contents of the DataStore before loading MCParticles
printDataStore()

# create and fill gamma/e/mu/pi/K/p ParticleLists
# second argument are the selection criteria: '' means no cut, take all
photons = ('gamma:gen', '')
electrons = ('e-:gen', '')
muons = ('mu-:gen', '')
pions = ('pi-:gen', '')
kaons = ('K-:gen', '')
kaonsneu = ('K_S0:gen', '')
# the MC files contain the desired processes/decays.
#
# Contributors: A. Zupanc (June 2014)
#               I. Komarov (September 2018)
#
######################################################

import basf2 as b2
import modularAnalysis as ma

# create path
my_path = b2.create_path()

# load input ROOT file
ma.inputMdst(environmentType='default',
             filename=b2.find_file('B2pi0D_D2hh_D2hhh_B2munu.root', 'examples',
                                   False),
             path=my_path)

# create charged kaon and pion particle lists with names "K-:gen" and "pi-:gen"
# all generated kaons(pions) will be added to the kaon(pion) list
ma.fillParticleListFromMC(decayString='K-:gen', cut='', path=my_path)
ma.fillParticleListFromMC(decayString='pi-:gen', cut='', path=my_path)

# print charge, energy and total momentum of generated kaons
# and x,y,z components of momenta for generated pions
#
# the list of all available variables can be obtained by executing
# basf2 analysis/scripts/variables/print_variables.py
ma.printVariableValues(list_name='K-:gen',
                       var_names=['charge', 'E', 'p'],
                       path=my_path)
Ejemplo n.º 5
0
# Contributors: A. Zupanc (June 2014)
#
######################################################

from basf2 import *
from modularAnalysis import inputMdst
from modularAnalysis import printDataStore
from modularAnalysis import printList
from modularAnalysis import fillParticleListsFromMC
from modularAnalysis import printPrimaryMCParticles
from modularAnalysis import printVariableValues
from modularAnalysis import analysis_main

# load input ROOT file
# inputMdst('B0_etapr-eta-gg2pi_KS-pi+pi-_gsim-BKGx0.root')
inputMdst('../root_files/B0_etapr-eta-gg2pi_KS-pi0pi0_gsim-BKGx0.root')
# inputMdst('B0_etapr-eta-gg2pi_KL-_gsim-BKGx0.root')
# inputMdst('B0_etapr-eta-3pi2pi_KS-pi+pi-_gsim-BKGx0.root')

printPrimaryMCParticles()
# print contents of the DataStore before loading MCParticles
printDataStore()

# create and fill gamma/e/mu/pi/K/p ParticleLists
# second argument are the selection criteria: '' means no cut, take all
photons = ('gamma:gen', '')
electrons = ('e-:gen', '')
muons = ('mu-:gen', '')
pions = ('pi-:gen', '')
kaons = ('K-:gen', '')
kaonsneu = ('K_S0:gen', '')
Ejemplo n.º 6
0
variables.addAlias('B0_hso02','KSFWVariables(hso02)')
#variables.addAlias('MCTagBFlavor','internalTagVMCFlavor')
variables.addAlias('CSMVA','extraInfo(CSMVA)')
variables.addAlias('XsdM','daughterInvM(0,1,2)')
variables.addAlias('pi0Likeness','extraInfo(Pi0_Prob)')
variables.addAlias('etaLikeness','extraInfo(Eta_Prob)')
variables.addAlias('cosThetaCMS','useCMSFrame(cosTheta)')
variables.addAlias('pCMS','useCMSFrame(p)')
variables.addAlias('ECMS','useCMSFrame(E)')
variables.addAlias('m12','daughterInvariantMass(0,1)')
variables.addAlias('m13','daughterInvariantMass(0,2)')
variables.addAlias('m23','daughterInvariantMass(1,2)')

main_path = b2.create_path() # Declaration of main path
bp.add_beamparameters(main_path,'Y4S')
ma.inputMdst('MC10', inputFilename, path=main_path)
sv.goodBelleKshort(path=main_path)
sg.stdPhotons('loose', path=main_path)
sc.stdPi('95eff', path=main_path)
ma.applyCuts('gamma:loose','1.4 < E < 4', path=main_path)
krescuts = " and daughterInvM(0,1,2) < 2 and daughterInvM(0,1) > 0.6 and daughterInvM(0,1) < 0.9"
#reconstructDecay(Kres+":all -> pi+:good pi-:good K_S0:all", krescuts)
ma.reconstructDecay("B0:signal -> pi+:95eff pi-:95eff K_S0:legacyGoodKS gamma:loose",
        "Mbc > 5.2 and deltaE < 0.2 and deltaE > -0.2 and  -0.65 < daughter(1, cosTheta) < 0.85"+krescuts, path=main_path)
ma.vertexRave('B0:signal',0.0001, 'B0 -> ^pi+ ^pi- ^K_S0 gamma', path=main_path)
#vertexTree('B0:signal',0.0001)

ma.rankByHighest('B0:signal',ratingVar, 1, outputVariable='myRating', path=main_path)

ma.buildRestOfEvent('B0:signal', path=main_path)
Ejemplo n.º 7
0
#
################################################################################

import basf2 as b2
import modularAnalysis as ma
import variables.collections as vc
import variables.utils as vu
from stdPhotons import stdPhotons
import stdCharged as stdc

# create path
my_path = b2.create_path()

# load input ROOT file
ma.inputMdst(environmentType='default',
             filename=b2.find_file('B2rhogamma_rho2pipi.root', 'examples',
                                   False),
             path=my_path)

#
# creates "gamma:tight" ParticleList
stdPhotons(listtype='tight', path=my_path)

# creates "pi+:loose" ParticleList (and c.c.)
stdc.stdPi(listtype='loose', path=my_path)

# reconstruct rho -> pi+ pi- decay
# keep only candidates with 0.6 < M(pi+pi-) < 1.0 GeV
ma.reconstructDecay(decayString='rho0 -> pi+:loose pi-:loose',
                    cut='0.6 < M < 1.0',
                    path=my_path)
Ejemplo n.º 8
0
def reconstruction(input_file, output_file):
    my_path = b2.create_path()
    ma.inputMdst("default", input_file, my_path)

    # Find decay name from the input file name
    decay_name = "_".join(input_file.split("/")[-1].split("_")[0:2])

    # Load configuration file
    config = yaml.safe_load(open("config/reco_config.yaml"))
    options = config[decay_name]

    # Parse list of subdecays in decay chain
    decays = options["sub_decays"]
    decays = DecayList(decays)

    # Create particle lists for final state particles
    fsps = decays.get_fsps()
    for particle in fsps:
        ma.fillParticleList(particle, "", path=my_path)

    # Reconstruct requested decay chains
    for decay in decays:
        ma.reconstructDecay(str(decay), "", path=my_path)

    # Perform truth matching for requested particles
    truth_match_particles = decays.mothers
    for truth_match_particle in truth_match_particles:
        ma.looseMCTruth(truth_match_particle, path=my_path)

    # Perform vertex fitting
    head = decays.get_head()
    vtx_decay_string = decays.get_chain()
    print(vtx_decay_string)

    vx.vertexRave(head, 0, vtx_decay_string, constraint="iptube", path=my_path)

    # ma.rankByLowest("B0", 'chiProb', numBest=3, outputVariable='B_vtx_rank', path=my_path)
    # ma.variables.addAlias('B_vtx_rank', 'extraInfo(B_vtx_rank)')
    ma.buildRestOfEvent(head, path=my_path)

    # Tag-side
    vx.TagV(head, "breco", 0.001, path=my_path)

    ma.buildEventKinematics(path=my_path)
    ma.buildEventShape(path=my_path)

    # Create centre-of-mass frame variables
    cms_kinematics = vu.create_aliases(
        vc.kinematics, "useCMSFrame({variable})", prefix="CMS"
    )

    variables = [
        item
        for sublist in [
            vc.kinematics,
            cms_kinematics,
            vc.deltae_mbc,
            vc.inv_mass,
            vc.event_shape,
            vc.vertex,
            vc.mc_truth,
            vc.mc_kinematics,
            vc.mc_vertex,
            vc.mc_tag_vertex,
        ]
        for item in sublist
    ]

    trees = yaml.safe_load(open("config/tree_names.yaml"))
    for particle in decays.all_particles:
        ma.variablesToNtuple(
            particle,
            variables,
            filename=output_file,
            treename=trees[particle],
            path=my_path,
        )

    b2.process(my_path)
    print(b2.statistics)
Ejemplo n.º 9
0
import basf2 as b2
import modularAnalysis as ma
import variables.collections as vc
import variables.utils as vu
from variables import variables as var
import os

# create path
my_path = b2.create_path()

# load input ROOT file
ma.inputMdst(environmentType='default',
             filename='kkmc_tautau_3.root',
             path=my_path)

ma.printDataStore(path=my_path)

photons = ('gamma:gen', '')
electrons = ('e-:gen', 'charge == -1')
muons = ('mu-:gen', '')
taus = ('tau-:gen', '')
pions = ('pi-:gen', '')
nue = ('nu_e:gen', '')
numu = ('nu_mu:gen', '')
nutau = ('nu_tau:gen', '')
#anti_nu_mu = ('anti-nu_mu:gen','')
#anti_nu_e = ('anti-nu_me:gen','')

ma.fillParticleListsFromMC(
    [photons, electrons, muons, taus, pions, nue, numu, nutau], path=my_path)
if step == 'signal':
    input_file = [path + 'Bd_KsPi0_expert/*']
elif step == 'qqbar':
    input_file = [path + '*bar_expert/*']
else:
    sys.exit(
        'Step does not match any of the available samples: `signal` or `qqbar`'
    )

outfile = 'MVAExpert_fullNTuple_' + step + '.root'
# ---------------------------------------------------------------------------------------------

# Perform analysis.
main = b2.create_path()

ma.inputMdst(environmentType='default', filename=input_file, path=main)

ma.fillParticleList(decayString='gamma:all', cut='', path=main)
ma.fillParticleList(decayString='pi+:good',
                    cut='chiProb > 0.001 and pionID > 0.5',
                    path=main)
ma.fillParticleList(decayString='pi-:good',
                    cut='chiProb > 0.001 and pionID > 0.5',
                    path=main)

ma.reconstructDecay(decayString='K_S0 -> pi+:good pi-:good',
                    cut='0.480<=M<=0.516',
                    dmID=1,
                    path=main)
ma.reconstructDecay(decayString='pi0  -> gamma:all gamma:all',
                    cut='0.115<=M<=0.152',
	inputFilename = sys.argv[1]
if len(sys.argv)==3:
	inputFilename = sys.argv[1]
	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
Ejemplo n.º 12
0
import basf2 as b2
import modularAnalysis as ma
import flavorTagger as ft
import vertex as vx
import variables.collections as vc
import variables.utils as vu
import stdCharged as stdc
from stdPi0s import stdPi0s

# create path
my_path = b2.create_path()

# load input ROOT file
ma.inputMdst(environmentType='default',
             filename=b2.find_file('B2JPsipi0_JPsi2mumu.root', 'examples',
                                   False),
             path=my_path)

# use standard final state particle lists
#
# creates "pi0:looseFit" ParticleList
# https://confluence.desy.de/display/BI/Physics+StandardParticles
stdPi0s(listtype='looseFit', path=my_path)
# creates "highPID" ParticleLists (and c.c.)
ma.fillParticleList(decayString='mu+:highPID',
                    cut='muonID > 0.2 and d0 < 2 and abs(z0) < 4',
                    path=my_path)

# reconstruct J/psi -> mu+ mu- decay
# keep only candidates with dM<0.11
ma.reconstructDecay(decayString='J/psi:mumu -> mu+:highPID mu-:highPID',
Ejemplo n.º 13
0
#               I. Komarov (Demeber 2017)
#               I. Komarov (September 2018)
#
################################################################################

import basf2 as b2
import modularAnalysis as ma
import variables.collections as vc
import variables.utils as vu

# create path
my_path = b2.create_path()

# load input ROOT file
ma.inputMdst(environmentType='default',
             filename=b2.find_file('JPsi2ee_e2egamma.root', 'examples', False),
             path=my_path)

# fill particleLists
ma.fillParticleList(decayString='e+:uncorrected',
                    cut='electronID > 0.2 and d0 < 2 and abs(z0) < 4',
                    path=my_path)
ma.fillParticleList(decayString='gamma:all',
                    cut='E < 1.0',
                    writeOut=False,
                    path=my_path)

# loose mc matching (recommended)
ma.looseMCTruth(list_name='e+:uncorrected', path=my_path)
ma.looseMCTruth(list_name='gamma:all', path=my_path)
Ejemplo n.º 14
0
from stdCharged import *

#from stdFSParticles import goodPi0
from stdFSParticles import stdPi0s

# check if the required input file exists (from B2A101 example)
import os.path
import sys
if not os.path.isfile('reco.root'):
    sys.exit(
        'Required input file (B2A101-Y4SEventGeneration-gsim-BKGx0.root) does not exist. '
        'Please run B2A101-Y4SEventGeneration.py and B2A103-SimulateAndReconstruct-withoutBeamBkg.py '
        'tutorial scripts first.')

# load input ROOT file
inputMdst('default', 'reco.root')

# print contents of the DataStore before loading Particles
printDataStore()

# create and fill gamma/e/mu/pi/K/p ParticleLists
# second argument are the selection criteria: '' means no cut, take all
# fillParticleList('gamma:all', '')
fillParticleList('e-:all', '')
fillParticleList('mu-:all', '')
fillParticleList('pi-:all', '')
fillParticleList('K-:all', '')
fillParticleList('anti-p-:all', '')

# alternatively, we can create and fill final state Particle lists only
# with candidates that pass certain PID requirements