Пример #1
0
 def create_path(self):
     path = basf2.create_path()
     modularAnalysis.inputMdstList(
         'default',
         self.get_input_file_names("reconstructed_output.root"),
         path=path)
     modularAnalysis.fillParticleLists([('K+', 'kaonID > 0.1'),
                                        ('pi+', 'pionID > 0.1')],
                                       path=path)
     modularAnalysis.reconstructDecay('D0 -> K- pi+',
                                      '1.7 < M < 1.9',
                                      path=path)
     modularAnalysis.matchMCTruth('D0', path=path)
     modularAnalysis.reconstructDecay('B- -> D0 pi-',
                                      '5.2 < Mbc < 5.3',
                                      path=path)
     try:  # treeFit is the new function name in light releases after release 4 (e.g. light-2002-janus)
         vertex.treeFit('B+', 0.1, update_all_daughters=True, path=path)
     except AttributeError:  # vertexTree is the function name in release 4
         vertex.vertexTree('B+', 0.1, update_all_daughters=True, path=path)
     modularAnalysis.matchMCTruth('B-', path=path)
     modularAnalysis.variablesToNtuple(
         'D0', [
             'M', 'p', 'E', 'useCMSFrame(p)', 'useCMSFrame(E)',
             'daughter(0, kaonID)', 'daughter(1, pionID)', 'isSignal',
             'mcErrors'
         ],
         filename=self.get_output_file_name("D_n_tuple.root"),
         path=path)
     modularAnalysis.variablesToNtuple(
         'B-', ['Mbc', 'deltaE', 'isSignal', 'mcErrors', 'M'],
         filename=self.get_output_file_name("B_n_tuple.root"),
         path=path)
     return path
Пример #2
0
 def create_path(self):
     path = basf2.create_path()
     modularAnalysis.inputMdstList(
         'default',
         self.get_input_file_names("reconstructed_output.root"),
         path=path)
     modularAnalysis.fillParticleLists([('K+', 'kaonID > 0.1'),
                                        ('pi+', 'pionID > 0.1')],
                                       path=path)
     modularAnalysis.reconstructDecay('D0 -> K- pi+',
                                      '1.7 < M < 1.9',
                                      path=path)
     modularAnalysis.fitVertex('D0', 0.1, path=path)
     modularAnalysis.matchMCTruth('D0', path=path)
     modularAnalysis.reconstructDecay('B- -> D0 pi-',
                                      '5.2 < Mbc < 5.3',
                                      path=path)
     modularAnalysis.fitVertex('B+', 0.1, path=path)
     modularAnalysis.matchMCTruth('B-', path=path)
     modularAnalysis.variablesToNtuple(
         'D0', [
             'M', 'p', 'E', 'useCMSFrame(p)', 'useCMSFrame(E)',
             'daughter(0, kaonID)', 'daughter(1, pionID)', 'isSignal',
             'mcErrors'
         ],
         filename=self.get_output_file_name("D_n_tuple.root"),
         path=path)
     modularAnalysis.variablesToNtuple(
         'B-', ['Mbc', 'deltaE', 'isSignal', 'mcErrors', 'M'],
         filename=self.get_output_file_name("B_n_tuple.root"),
         path=path)
     return path
Пример #3
0
def create_analysis_path(
        b_ntuple_filename="B_ntuple.root",
        d_ntuple_filename="D_ntuple.root",
        mbc_range=(5.2, 5.3),
):
    """
    Example of a minimal reconstruction with a cut as a changeable function
    parameter, adapted from code in the ``B2T_Basics_3_FirstAnalysis.ipynb``
    notebook from b2 starter kit.
    """
    path = basf2.create_path()
    # this local inputMdstList will only be used when this steerig file is run locally, gbasf2 overrides it
    local_input_files = [
        "/group/belle2/dataprod/MC/MC13a/prod00009434/s00/e1003/4S/r00000/mixed/mdst/sub00/mdst_000001_prod00009434_task10020000001.root"
    ]
    mA.inputMdstList(
        environmentType="default",
        filelist=local_input_files,
        path=path,
    )
    stdK("higheff", path=path)
    stdPi("higheff", path=path)
    mA.reconstructDecay('D0:Kpi -> K-:higheff pi+:higheff',
                        '1.7 < M < 1.9',
                        path=path)
    # use try except to have this code work for both the old and new function names for the tree fit
    mA.matchMCTruth('D0:Kpi', path=path)
    mA.reconstructDecay('B- -> D0:Kpi pi-:higheff',
                        f"{mbc_range[0]} < Mbc < {mbc_range[1]}",
                        path=path)
    try:
        vx.treeFit('B+', 0.1, path=path)
    except AttributeError:
        vx.vertexTree('B+', 0.1, path=path)
    mA.setAnalysisConfigParams({"mcMatchingVersion": "BelleII"}, path)
    mA.matchMCTruth('B-', path=path)
    vm.addAlias("p_cms",
                "useCMSFrame(p)")  # include aliases to test if they work
    vm.addAlias("E_cms", "useCMSFrame(E)")
    mA.variablesToNtuple('D0:Kpi', [
        'M', 'p', 'E', 'E_cms', 'p_cms', 'daughter(0, kaonID)',
        'daughter(1, pionID)', 'isSignal', 'mcErrors'
    ],
                         filename=d_ntuple_filename,
                         treename="D",
                         path=path)
    mA.variablesToNtuple('B-', ['Mbc', 'deltaE', 'isSignal', 'mcErrors', 'M'],
                         filename=b_ntuple_filename,
                         treename="B",
                         path=path)
    return path
# add rank variable aliases for easier use
va.variables.addAlias('dM_rank', 'extraInfo(abs_dM_rank)')
va.variables.addAlias('chiProb_rank', 'extraInfo(chiProb_rank)')

# perform MC matching (MC truth asociation)
ma.matchMCTruth(list_name='D0', path=my_path)

# Select variables that we want to store to ntuple
fs_hadron_vars = vu.create_aliases_for_selected(list_of_variables=vc.mc_truth,
                                                decay_string='D0 -> ^K- ^pi+')

d0_vars = vc.vertex + \
    vc.mc_vertex + \
    vc.mc_truth + \
    fs_hadron_vars + \
    ['dM', 'chiProb', 'dM_rank', 'chiProb_rank', 'D1_pi_p_rank', 'first_D_rank', 'second_D_rank']

# Saving variables to ntuple
output_file = 'B2A602-BestCandidateSelection.root'
ma.variablesToNtuple(decayString='D0',
                     variables=d0_vars,
                     filename=output_file,
                     treename='D0',
                     path=my_path)

# Process the events
b2.process(my_path)

# print out the summary
print(b2.statistics)
Пример #5
0
    ntuple = []
    # May have more feature than needed.
    features = [
        'dr', 'dz', 'cosaXY', 'min_dr', 'min_dz', 'pt', 'pz', 'chiProb', 'p'
    ]
    features += create_aliases_for_selected(['PIDppi', 'PIDpk', 'PIDkpi', 'p'],
                                            'Lambda0 -> ^p+ ^pi-',
                                            prefix=['proton', 'pi'])
    spectator = ['isSignal', 'isPrimarySignal', 'mcPDG', 'genMotherPDG']
    spectator += ['IPX', 'IPY', 'IPZ', 'M', 'p', 'goodBelleLambda', 'distance']
    ntuple = features + spectator
    return ntuple


if __name__ == '__main__':
    infile, outfile = sys.argv[1], sys.argv[2]
    mypath = b2.create_path()
    b2c.convertBelleMdstToBelleIIMdst(infile, path=mypath)
    reconstructLambda('Lambda0:belle',
                      match=True,
                      only='background',
                      path=mypath)
    ntuple = make_ntuple()
    ma.variablesToNtuple('Lambda0:belle',
                         ntuple,
                         'Lambda',
                         outfile,
                         path=mypath)

    b2.process(path=mypath)
ma.buildEventShape(inputListNames=['pi+:all', 'gamma:all'],
                   allMoments=True,
                   foxWolfram=True,
                   harmonicMoments=True,
                   cleoCones=True,
                   thrust=True,
                   collisionAxis=True,
                   jets=True,
                   sphericity=True,
                   checkForDuplicates=False,
                   path=my_path)

# Here we use the pre-defined collection 'event_shape', that contains
# thrust, sphericity, aplanarity, FW ratios up to 4, harmonic moments w/respect to
# the thrust axis up to 4 and all the cleo cones w/respect to the thrust axis.
# In addition, we will save also the forward and backward hemisphere (or "jet") energies,
# and the 2nd order harmonic moment calculate respect to the collision axis (i.e. the z axis)
ma.variablesToNtuple('',
                     variables=['event_shape',
                                'backwardHemisphereEnergy',
                                'forwardHemisphereEnergy',
                                'harmonicMoment(2, collision)'],
                     filename='B2A704-EventShape.root',
                     path=my_path)


# Process the events
b2.process(my_path)
# print out the summary
print(b2.statistics)
Пример #7
0
v0_vars = vc.kinematics + \
    vc.inv_mass + \
    vc.vertex +\
    vc.mc_truth + \
    ['chiProb'] +\
    vu.create_daughter_aliases(pi0_vars, 0) +\
    vu.create_daughter_aliases(pi0_vars, 1)

# saving variables to ntuple
rootOutputFile = 'load_v0.root'

# K_S0 from V0s
ma.variablesToNtuple(treename='kshort_v0',
                     decayString='K_S0:V0',
                     variables=v0_vars,
                     filename=rootOutputFile,
                     path=my_path)

# K_S0 from reconstructDecay
ma.variablesToNtuple(treename='kshort_rd',
                     decayString='K_S0:RD',
                     variables=v0_vars,
                     filename=rootOutputFile,
                     path=my_path)

# K_S0 from standard list (=V0s, see stdV0s.py)
ma.variablesToNtuple(treename='kshort_std',
                     decayString='K_S0:all',
                     variables=v0_vars,
                     filename=rootOutputFile,
Пример #8
0
                                         'B0 -> [J/psi -> ^e+ ^e-] K_S0',
                                         prefix=['ep', 'em'])
b_vars += vu.create_aliases_for_selected(fs_vars,
                                         'B0 -> J/psi [K_S0 -> ^pi+ ^pi-]',
                                         prefix=['pip', 'pim'])
b_vars += vu.create_aliases_for_selected(jpsi_ks_vars, 'B0 -> ^J/psi ^K_S0')

cmskinematics = vu.create_aliases(vc.kinematics, 'useCMSFrame({variable})',
                                  'CMS')
b_vars += vu.create_aliases_for_selected(
    cmskinematics, '^B0 -> [^J/psi -> ^e+ ^e-] [^K_S0 -> ^pi+ ^pi-]')

variables.addAlias(
    'withBremsCorrection',
    'passesCut(passesCut(ep_isBremsCorrected == 1) or passesCut(em_isBremsCorrected == 1))'
)
b_vars += ['withBremsCorrection']

# save variables to an ntuple
ma.variablesToNtuple('B0',
                     variables=b_vars,
                     filename='Bd2JpsiKS_ee.root',
                     treename='tree',
                     path=main)

# process the events
b2.process(main)

# print out the summary
print(b2.statistics)
Пример #9
0
    ]
    ntuple += ['ppi0_angle', 'p_decayAngle', 'pi0_decayAngle']
    ntuple += ['IPX', 'IPY', 'IPZ']

    ntuple += create_aliases_for_selected(
        ['pid_ppi', 'pid_pk', 'pid_kpi', 'dr', 'dz', 'p', 'isSignal'],
        'Sigma+ -> ^p+ pi0',
        prefix=['p'])
    ntuple += create_aliases_for_selected(
        ['mcP', 'p', 'M', 'distance', 'isSignal', 'genMotherPDG'],
        'Sigma+ -> p+ ^pi0',
        prefix=['pi0'])
    ntuple += create_aliases_for_selected(
        ['E', 'theta', 'phi'],
        'Sigma+ -> p+ [pi0 -> ^gamma ^gamma]',
        prefix=['gamma1', 'gamma2'])

    ma.variablesToNtuple('Sigma+:std',
                         ntuple,
                         treename='sigma_std',
                         filename=outfile,
                         path=mp)

    ma.fillParticleListFromMC('Sigma+:gen', '', path=mp)
    ma.variablesToNtuple('Sigma+:gen', ['distance', 'p', 'M'],
                         treename='sigma_gen',
                         filename=outfile,
                         path=mp)

    b2.process(path=mp)
    print(b2.statistics)
Пример #10
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)
def reconstruct(infile='default.root', outfile='output_beta.root', path=None):
    """

    Args:
        infile: Input file name (use overwrite from basf2)
        outfile: output file name (use overwrite from basf2)
        path: (optional) basf2 path

    Returns:
        path
    """

    setup()

    # EXAMPE RECONSTRUCTION CODE
    # DELETE OR MODIFY FROM HERE
    just_an_example = True
    if just_an_example:
        with open(outfile, 'w') as f:
            f.write("Proccessed example input " + infile)
    else:
        path = b2.create_path() if path is None else path

        # Input file
        ma.inputMdstList("default", infile, path=path)

        # Event level cuts examples
        ma.applyEventCuts('R2EventLevel<0.6 and nTracks>=3', path=path)

        #
        # Load Primary particles
        #
        from stdPhotons import stdPhotons
        stdPhotons('cdc', path)
        ma.cutAndCopyList('gamma:sig', 'gamma:cdc',
                          'clusterNHits > 1.5 and E > 1.5', True, path)

        from stdPi0s import stdPi0s
        stdPi0s('eff20', path)

        # Loading charged tracks
        good_track = 'thetaInCDCAcceptance and nCDCHits>20 and dr < 0.5 and abs(dz) < 2'
        ma.fillParticleList("pi+:sig",
                            good_track + " and pionID > 0.0",
                            path=path)
        ma.fillParticleList("K+:sig",
                            good_track + " and kaonID > 0.0",
                            path=path)

        #
        # Combine particles
        #
        ma.reconstructDecay('K*0:sig  -> K+:sig pi-:sig',
                            '0.6 < M < 1.6',
                            path=path)

        ma.reconstructDecay('B0:sig ->  K*0:sig gamma:sig',
                            '5.22 < Mbc < 5.3 and  abs(deltaE)< 1',
                            path=path)

        # Final Calculateions
        ma.rankByHighest("B0:ch1",
                         "formula(-1*abs(deltaE))",
                         outputVariable='Rank_deltaE',
                         path=path)

        ma.buildEventShape(allMoments=True, path=path)

        ma.matchMCTruth("B0:sig", path=path)

        #
        # Write out Ntuples
        #
        all_vars = get_variables()
        ma.variablesToNtuple('B0:ch1',
                             all_vars,
                             filename=outfile,
                             treename="B0",
                             path=path)
    # TO HERE

    #ma.printMCParticles(path=path)
    return path
Пример #12
0
# variables to ntuple
vars = ['combinationID',
        'deltaPhi',
        'deltaPhiCMS',
        'deltaTheta',
        'charge_0',
        'charge_1',
        'clusterE_0',
        'clusterE_1',
        'clusterTheta_0',
        'clusterTheta_1',
        'clusterPhi_0',
        'clusterPhi_1',
        'clusterECMS_0',
        'clusterECMS_1',
        'clusterPhiCMS_0',
        'clusterPhiCMS_1',
        'clusterThetaCMS_0',
        'clusterThetaCMS_1'
        ]

# store variables
variablesToNtuple('vpho:bhabha', vars, filename='bhabha.root', path=mypath)

# Process the events
b2.process(mypath)

# print out the summary
print(b2.statistics)
Пример #13
0
                      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
b2.process(my_path)

# print out the summary
print(b2.statistics)
Пример #14
0
mcVariables = [
    'p', 'px', 'py', 'pz', 'E', 'PDG', 'pt', 'invMS1', 'invMS2', 'invMS3'
]

#tauVariables = vc.inv_mass

variableList = vu.create_aliases_for_selected(list_of_variables=mcVariables,
                                              decay_string='^e-')  #+ #\
#vu.create_aliases_for_selected(list_of_variables=tauVariables,
#decay_string='^tau- -> ^e- ^anti-nu_e ^nu_tau')
#output_file = 'mcparticles.root'
#ma.variablesToNtuple(decayString='e+:gen',
#                    variables=mcVariables,
#                   treename='electron',
#                  filename=output_file,
#                 path=my_path)

output_file = 'GeneratorLevel-MCparticles.root'

ma.variablesToNtuple(decayString='e-:gen',
                     variables=variableList,
                     treename='electron',
                     filename=output_file,
                     path=my_path)
#ma.variablesToNtuple(decayString='mu-:gen', variables=variableList, treename='tree2', filename=output_file, path=my_path)

b2.process(my_path)

# print out the summary
print(b2.statistics)
        decay_string='B0 -> ^D0 ^pi0') + \
    vu.create_aliases_for_selected(
        list_of_variables=vc.cluster,
        decay_string='B0 -> D0 [pi0 -> ^gamma ^gamma]')

pi0_vars = vc.mc_truth + \
    vc.kinematics + \
    ['extraInfo(BDT)', 'decayAngle(0)'] + \
    vu.create_aliases_for_selected(
        list_of_variables=vc.cluster + vc.kinematics,
        decay_string='pi0 -> ^gamma ^gamma')

# Saving variables to ntuple
output_file = 'B2A302-B02D0Pi0-D02Pi0Pi0-Reconstruction.root'
ma.variablesToNtuple('B0:all',
                     B0_vars,
                     filename=output_file,
                     treename='b0',
                     path=my_path)
ma.variablesToNtuple('pi0:looseFit',
                     pi0_vars,
                     filename=output_file,
                     treename='pi0',
                     path=my_path)

# Process the events
b2.process(my_path)

# print out the summary
print(b2.statistics)
#####################################################
# -- event based variables
##################################################
var.addAlias('nDaug', 'countDaughters(1>0)')
#var.addAlias('InvMass', '')

eventVariables = ['thrust', 'M', 'tauPlusMCMode', 'tauMinusMCMode', 'nDaug']

tauVariables = ['p', 'px', 'py', 'pz', 'E', 'PDG', 'pt', 'M', 'EoverP']

# -- track level variables
#trackVariables = vc.kinematics #+ vc.pid + vc.track + vc.track_hits + vc.vertex
#trackVariables += ['theta','cosTheta','phi', 'charge', 'clusterE','EoverP', 'mcPDG']



variableList = vu.create_aliases_for_selected(list_of_variables=eventVariables,
                                              decay_string='^vpho') + \
               vu.create_aliases_for_selected(list_of_variables=tauVariables + ['charge'],
                                              decay_string='vpho -> ^tau+ ^tau-') #+ \
#vu.create_aliases_for_selected(list_of_variables=trackVariables,
# decay_string= decay_chain)

ma.variablesToNtuple('vpho:photon_B2SS',
                     variables=variableList,
                     treename='tree',
                     filename='tau_Generator_analysis_4.root',
                     path=my_path)

b2.process(my_path, max_event=50000)
    vc.inv_mass + \
    vc.vertex + \
    vc.mc_vertex + \
    vc.pid + \
    vc.mc_truth + \
    ['dr', 'dz', 'isSignal', 'chiProb']

pi0_variables = vc.mc_truth + \
    vc.kinematics + \
    ['extraInfo(BDT)', 'decayAngle(0)']

# Saving variables to ntuple
output_file = 'load_recon.root'
ma.variablesToNtuple(decayString='pi+:all',
                     variables=charged_particle_variables,
                     treename='pion',
                     filename=output_file,
                     path=my_path)
ma.variablesToNtuple(decayString='K+:all',
                     variables=charged_particle_variables,
                     treename='kaon',
                     filename=output_file,
                     path=my_path)
ma.variablesToNtuple(decayString='e+:all',
                     variables=charged_particle_variables,
                     treename='elec',
                     filename=output_file,
                     path=my_path)
ma.variablesToNtuple(decayString='mu+:all',
                     variables=charged_particle_variables,
                     treename='muon',
Пример #18
0
                    path=my_path)

# perform MC matching (MC truth asociation)
ma.matchMCTruth(list_name='D*+', path=my_path)

# Select variables that we want to store to ntuple
dstar_vars = vc.inv_mass + vc.mc_truth

fs_hadron_vars = vu.create_aliases_for_selected(
    list_of_variables=vc.pid + vc.track + vc.mc_truth,
    decay_string='D*+ -> [D0 -> ^K- ^pi+] ^pi+')

d0_vars = vu.create_aliases_for_selected(list_of_variables=vc.inv_mass +
                                         vc.mc_truth,
                                         decay_string='D*+ -> ^D0 pi+',
                                         prefix='D0')

# Saving variables to ntuple
output_file = 'B2A301-Dstar2D0Pi-Reconstruction.root'
ma.variablesToNtuple('D*+',
                     dstar_vars + d0_vars + fs_hadron_vars,
                     filename=output_file,
                     treename='dsttree',
                     path=my_path)

# Process the events
b2.process(my_path)

# print out the summary
print(b2.statistics)
    # need to be flattened before training to 0 or 1
    NNApplyModule_m = NNApplyModule(
        model_file=args.model,
        model_type='combined-wideCNN',
        threshold=0.,
        # threshold=args.threshold,
        extra_info_var='smartBKG')
    # dead_path = b2.create_path()
    # NNApplyModule_m.if_false(dead_path)

    path.add_module(NNApplyModule_m)

    # We'll keep just one Btag per event and train on that
    ma.rankByHighest(particle_list,
                     'extraInfo(SignalProbability)',
                     outputVariable='FEIProbabilityRank',
                     numBest=1,
                     path=path)

    # Write output
    # ma.variablesToNTuple(
    ma.variablesToNtuple(
        decayString=particle_list,
        variables=B_vars,
        filename=args.out_file,
        path=path,
    )

    b2.process(path)
    print(b2.statistics)
Пример #20
0
ma.matchMCTruth(list_name='B0', path=my_path)

# Select variables that we want to store to ntuple

gamma_vars = vc.cluster + vc.mc_truth + vc.kinematics
rho_vars = vc.cluster + vc.mc_truth + vc.kinematics + vc.inv_mass
pi_vars = vc.pid + vc.track
b_vars = vc.kinematics + \
    vc.deltae_mbc + \
    vc.mc_truth + \
    vu.create_aliases_for_selected(list_of_variables=gamma_vars,
                                   decay_string='B0 -> rho0 ^gamma') + \
    vu.create_aliases_for_selected(list_of_variables=rho_vars,
                                   decay_string='B0 -> ^rho0 gamma') + \
    vu.create_aliases_for_selected(list_of_variables=rho_vars,
                                   decay_string='B0 -> [rho0 -> ^pi+ ^pi-] gamma')

# Saving variables to ntuple
rootOutputFile = 'B2A304-B02RhoGamma-Reconstruction.root'
ma.variablesToNtuple(decayString='B0',
                     variables=b_vars,
                     filename=rootOutputFile,
                     treename='b0',
                     path=my_path)

# Process the events
b2.process(my_path)

# print out the summary
print(b2.statistics)
    print(event_vars)

    # Apply the smartBKG NN model
    # Will use extraInfo saved as training labels later,
    # need to be flattened before training to 0 or 1
    NNApplyModule_m = NNApplyModule(
        model_file=args.model,
        model_type='combined-wideCNN',
        threshold=0.,
        # threshold=args.threshold,
        extra_info_var='smartBKG'

    )
    # dead_path = b2.create_path()
    # NNApplyModule_m.if_false(dead_path)

    path.add_module(NNApplyModule_m)

    # Write output
    # ma.variablesToNTuple(
    ma.variablesToNtuple(
        decayString='',
        variables=event_vars,
        filename=args.out_file,
        path=path,
    )

    b2.process(path)
    print(b2.statistics)
Пример #22
0
    ntuple = [
        'M', 'p', 'chiProb', 'cosa', 'cosaXY', 'dr', 'dz', 'distance',
        'isSignal', 'genMotherPDG'
    ]
    ntuple += ['IPX', 'IPY', 'IPZ']
    ntuple += create_aliases_for_selected(
        ['protonID', 'pionID', 'dr', 'dz', 'p', 'isSignal'],
        'Sigma+ -> ^p+ pi0',
        prefix=['p'])
    ntuple += create_aliases_for_selected([
        'mcP', 'p', 'M', 'distance', 'isSignal', 'genMotherPDG', 'M_noupdate',
        'p_noupdate'
    ],
                                          'Sigma+ -> p+ ^pi0',
                                          prefix=['pi0'])

    ma.variablesToNtuple('Sigma+:loose',
                         ntuple,
                         treename='sigma',
                         filename=outfile,
                         path=mp)

    ma.fillParticleListFromMC('Sigma+:gen', '', path=mp)
    ma.variablesToNtuple('Sigma+:gen', ['cosa', 'cosaXY', 'p', 'M'],
                         treename='sigma_gen',
                         filename=outfile,
                         path=mp)

    b2.process(path=mp)
    print(b2.statistics)
Пример #23
0
        outfile = sys.argv[2]
    
    print(f"Input = {infile}")
    print(f"Output = {outfile}")
    
    ma.inputMdstList('default', [infile], path = mp)

    eff = 60
    stdSigmas(f'pi0eff{eff}', path = mp)
    ma.matchMCTruth('Sigma+:std', path = mp)
    
    va.addAlias('cosa', 'cosAngleBetweenMomentumAndVertexVector')
    va.addAlias('cosaXY', 'cosAngleBetweenMomentumAndVertexVectorInXYPlane')
    va.addAlias('abs_dM', 'abs(dM)')
    va.addAlias('M_noupdate', 'extraInfo(M_noupdate)')
    va.addAlias('p_noupdate', 'extraInfo(p_noupdate)')
    
    ntuple = ['M', 'p', 'chiProb', 'cosa', 'cosaXY', 'dr', 'dz', 'distance', 'isSignal', 'genMotherPDG']
    ntuple += ['IPX', 'IPY', 'IPZ']
    ntuple += create_aliases_for_selected(['protonID', 'pionID', 'dr', 'dz', 'p', 'isSignal'],
                                          'Sigma+ -> ^p+ pi0', prefix = ['p'])
    ntuple += create_aliases_for_selected(['mcP', 'p', 'M', 'distance', 'isSignal', 'genMotherPDG', 'M_noupdate', 'p_noupdate'],
                                          'Sigma+ -> p+ ^pi0', prefix = ['pi0'])
    
    ma.variablesToNtuple('Sigma+:std', ntuple, treename = f'sigma_eff{eff}', filename = outfile, path = mp)
    
    ma.fillParticleListFromMC('Sigma+:gen', '', path = mp)
    ma.variablesToNtuple('Sigma+:gen', ['cosa', 'cosaXY', 'p', 'M'], treename = 'sigma_gen', filename = outfile, path = mp)
    
    b2.process(path = mp)
    print(b2.statistics)
                      prefix="D")
mu_vars = vc.mc_truth

u4s_vars = vc.mc_truth + \
    vc.roe_multiplicities + \
    vc.recoil_kinematics + \
    vc.kinematics + \
    vu.create_aliases_for_selected(list_of_variables=b_vars,
                                   decay_string='Upsilon(4S) -> ^B- mu+') + \
    vu.create_aliases_for_selected(list_of_variables=mu_vars,
                                   decay_string='Upsilon(4S) -> B- ^mu+')

# 7. Saving variables to ntuple
rootOutputFile = 'B2A305-Btag+SingleMuon-Reconstruction.root'
ma.variablesToNtuple(decayString='B-:tag',
                     variables=b_vars,
                     filename=rootOutputFile,
                     treename='btag',
                     path=my_path)
ma.variablesToNtuple(decayString='Upsilon(4S)',
                     variables=u4s_vars,
                     filename=rootOutputFile,
                     treename='btagbsig',
                     path=my_path)

# Process the events
b2.process(my_path)

# print out the summary
print(b2.statistics)
Пример #25
0
ft_variables = makePretty(['qrOutput(FBDT)', 'qrOutput(FANN)', 'isRelatedRestOfEventB0Flavor', 'qOutput(FANN)', 'rBinBelle(FANN)',  'qOutput(FBDT)', 'rBinBelle(FBDT)',  'EW90', 'pMissCMS', 'cosThetaMissCMS'])
deltat_variables = ['DeltaT', 'DeltaTErr', 'MCDeltaT', 'TagVz', 'TagVzErr','mcTagVz', 'DeltaZ', 'MCTagBFlavor']
cs_variables = makePretty(['R2', 'cosTBTO', 'cosTBz','CleoConeCS(2)','KSFWVariables(hso02)', 'CleoConeCS(4)', 'CleoConeCS(9)','KSFWVariables(hso10)', 'KSFWVariables(hso12)', 'KSFWVariables(hso14)', 'thrustBm', 'thrustOm'])
roe_vars_clean = makePretty(['ROE_E(cleanMask)','ROE_P(cleanMask)', 'ROE_M(cleanMask)', 'ROE_deltae(cleanMask)', 'ROE_mbc(cleanMask)', 'nROE_Tracks(cleanMask)', 'nROE_NeutralECLClusters(cleanMask)', 'ROE_PTheta(cleanMask)', 'ROE_MC_MissFlags(cleanMask)'])
vtx_variables = ['z', 'z_uncertainty', 'pValue']
dalitz_vars = ['m12', 'm13', 'm23']
mix_variables = []#['mixFBDT', 'mixFANN', 'mixTrue']
cluster_variables = ['clusterReg','clusterTiming',
        'clusterErrorTiming','clusterE1E9',
        'clusterE9E21','clusterAbsZernikeMoment40',
        'clusterAbsZernikeMoment51','minC2TDist',
        'clusterTheta','clusterZernikeMVA',
        'clusterSecondMoment','clusterNHits']

track_variables = vc.track + vc.track_hits + vc.pid 

ma.variablesToNtuple('B0:signal',  
        vc.deltae_mbc+kin_variables+ft_variables+deltat_variables+cs_variables+vtx_variables+mix_variables+roe_vars_clean+dalitz_vars+
        ['CSMVA','isContinuumEvent','isNotContinuumEvent','pi0Likeness','etaLikeness']+
        vu.create_aliases_for_selected(list_of_variables=kin_variables, decay_string=  'B0 -> ^pi+ ^pi- [ ^K_S0 -> ^pi+ ^pi- ] ^gamma')+
        vu.create_aliases_for_selected(list_of_variables=track_variables, decay_string=  'B0 -> ^pi+ ^pi- [ K_S0 -> ^pi+ ^pi- ] gamma')+
        vu.create_aliases_for_selected(list_of_variables=cluster_variables, decay_string=  'B0 -> pi+ pi- [ K_S0 -> pi+ pi- ] ^gamma'),
    	filename = outputFilename, path=main_path)
# Process the events

b2.process(main_path)

# print out the summary
print(b2.statistics)
Пример #26
0
    # Load the input skim file
    path = ma.create_path()
    ma.inputMdstList('MC9', filelist=[], path=path)

    # Build some event specific ROE and continuum vars
    ma.buildRestOfEvent(particle_list, path=path)
    ROEMask = ('ROE', IPtrack_cut, gamma_cut)
    ma.appendROEMasks(particle_list, [ROEMask], path=path)
    ma.buildContinuumSuppression(particle_list, roe_mask='ROE', path=path)

    B_vars += ROE_vars
    print(B_vars)

    # Then choose one candidate per event
    # Dont' need to, want to view changes to candidates overall
    # But let's try for fun
    ma.rankByHighest(particle_list, 'extraInfo(SignalProbability)',
                     outputVariable='FEIProbabilityRank', path=path)
    ma.applyCuts(particle_list, 'extraInfo(FEIProbabilityRank) == 1', path=path)

    # Write output
    ma.variablesToNtuple(
        particle_list,
        B_vars,
        filename=args.out_file,
        path=path,
    )

    b2.process(path)
    print(b2.statistics)
    'KSFWVariables(hso22)',
    'KSFWVariables(hso24)',
    'KSFWVariables(hoo0)',
    'KSFWVariables(hoo1)',
    'KSFWVariables(hoo2)',
    'KSFWVariables(hoo3)',
    'KSFWVariables(hoo4)',
    'cleoConeThrust0',
    'cleoConeThrust1',
    'cleoConeThrust2',
    'cleoConeThrust3',
    'cleoConeThrust4',
    'cleoConeThrust5',
    'cleoConeThrust6',
    'cleoConeThrust7',
    'cleoConeThrust8',
]

# Save target variable necessary for training.
targetVar = ['isNotContinuumEvent']

# Create output file.
ma.variablesToNtuple(decayString='B0',
                     variables=trainVars + targetVar,
                     treename='tree',
                     filename=outfile,
                     path=my_path)

b2.process(my_path)
print(b2.statistics)
Пример #28
0
vm.addAlias('dxDstar',  'dx')
vm.addAlias('dyDstar',  'dy')
vm.addAlias('dzDstar',  'dz')

vm.addAlias('pDstar',  'p')
vm.addAlias('eDstar',  'E')
vm.addAlias('eCmsDstar',  'useCMSFrame(E)')
vm.addAlias('mDstar',  'M')
vm.addAlias('mD', 'daughter(0,M)')
vm.addAlias('slowPiID', 'daughter(1,pionID)')


Vars = [ 'xDstar',  'yDstar',  'zDstar',  'xGenDstar', 'yGenDstar', 'zGenDstar', 'dxDstar', 'dyDstar', 'dzDstar', 'pDstar',  'eDstar',  'eCmsDstar', 'mDstar',  'mD', 'slowPiID']
Vars.append('isSignal')
Vars.append('IPX')
Vars.append('IPCov(0,0)')



# Match to the MC truth information
ma.matchMCTruth('D*+:my', path=path)


ma.variablesToNtuple('D*+:my', Vars, 
                     filename='nTupleNo.root', treename="Dstar", path=path)


b2.process(path, max_event=100000)
print(b2.statistics)
Пример #29
0
tauVariables += ['mcErrors', 'genMotherPDG', 'mcPDG', 'isSignal']

# -- track level variables
trackVariables = vc.kinematics + vc.pid + vc.track + vc.track_hits + vc.vertex
trackVariables += [
    'theta', 'cosTheta', 'phi', 'charge', 'clusterE', 'EoverP', 'mcPDG'
]



variableList = vu.create_aliases_for_selected(list_of_variables=eventVariables,
                                              decay_string='^vpho') + \
               vu.create_aliases_for_selected(list_of_variables=tauVariables + ['charge'],
                                              decay_string='vpho -> ^tau+ ^tau-') + \
               vu.create_aliases_for_selected(list_of_variables=trackVariables,
                                              decay_string= decay_chain)

if tauMinus == '1':
    Outputfile = "tautau_mctruthsel_21_test.root"

if tauMinus == '3':
    Outputfile = "tautau_mctruthsel_23_test.root"

ma.variablesToNtuple('vpho:photon_B2SS',
                     variables=variableList,
                     treename='tree',
                     filename=Outputfile,
                     path=my_path)

b2.process(my_path, max_event=50000)
Пример #30
0
    vc.deltae_mbc + \
    vc.mc_truth + \
    vc.roe_multiplicities + \
    vc.flavor_tagging + \
    vc.tag_vertex + \
    vc.mc_tag_vertex + \
    vu.create_aliases_for_selected(list_of_variables=fs_vars,
                                   decay_string='B0 -> [J/psi -> ^mu+ ^mu-] pi0') + \
    vu.create_aliases_for_selected(list_of_variables=jpsiandk0s_vars,
                                   decay_string='B0 -> [^J/psi -> mu+ mu-] ^pi0')

# Saving variables to ntuple
output_file = 'B2A801-FlavorTagger.root'
ma.variablesToNtuple(decayString='B0:jspipi0',
                     variables=bvars,
                     filename=output_file,
                     treename='B0tree',
                     path=my_path)

# Summary of created Lists
ma.summaryOfLists(particleLists=['J/psi:mumu', 'pi0:looseFit', 'B0:jspipi0'],
                  path=my_path)

# Process the events
b2.process(my_path)

# print out the summary
print(b2.statistics)

# If you want to calculate the efficiency of the FlavorTagger on your own
# File use the script analysis/examples/FlavorTaggerEfficiency.py giving