# 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)
Beispiel #2
0
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)


# define the "cleaner" mask
eclCut = '[E > 0.062 and abs(clusterTiming) < 18 and clusterReg==1] or \
[E>0.060 and abs(clusterTiming) < 20 and clusterReg==2] or \
[E>0.056 and abs(clusterTiming) < 44 and clusterReg==3]'
cleanMask = ('cleanMask', 'abs(d0) < 10.0 and abs(z0) < 20.0', eclCut)

# append both masks to ROE
ma.appendROEMasks('B0:signal', [cleanMask], path=main_path)

# choose one mask which is applied
ma.buildContinuumSuppression('B0:signal', 'cleanMask', path=main_path)
    list_name='D0',
    conf_level=
    -1,  # keep all cadidates, 0:keep only fit survivors, optimise this cut for your need
    ipConstraint=True,
    # pins the B0 PRODUCTION vertex to the IP (increases SIG and BKG rejection) use for better vertex resolution
    updateAllDaughters=True,  # update momenta off ALL particles
    path=my_path)

# smaller |M_rec - M| is better, add here a different output variable name, due to parentheses
ma.rankByLowest(particleList='D0',
                variable='abs(dM)',
                outputVariable='abs_dM_rank',
                path=my_path)

# maybe not the best idea, but might cut away candidates with failed fits
ma.rankByHighest(particleList='D0', variable='chiProb', path=my_path)

# Now let's do mixed ranking:
# First, we want to rank D candiadtes by the momentum of the pions
# Second, we want to rank those D candidates that were built with the highest-p by the vertex Chi2
# This doesn't have any sense, but shows how to work with consequetive rankings
#
# Let's add alias for the momentum rank of pions in D
va.variables.addAlias('D1_pi_p_rank', 'daughter(1,pi_p_rank)')
# Ranking D candidates by this variable.
# Candidates built with the same pion get the same rank (allowMultiRank=True).
ma.rankByHighest(particleList='D0',
                 variable='D1_pi_p_rank',
                 allowMultiRank=True,
                 outputVariable="first_D_rank",
                 path=my_path)
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
Beispiel #5
0
# It is also possible to train different combiners consecutively using the same weightFiles name.
# You just need always to specify the desired category combination while using the expert mode as:
#
# flavorTagger(particleLists=['B0:jspipi0'], mode = 'Expert', weightFiles='B2JpsiKs_mu',
# categories=['Electron', 'Muon', 'Kaon', ... etc.])
#
# Another possibility is to train a combiner for a specific category combination using the default weight files

# You can apply cuts using the flavor Tagger: qrOutput(FBDT) > -2 rejects all events which do not
# provide flavor information using the tag side
ma.applyCuts(list_name='B0:jspipi0', cut='qrOutput(FBDT) > -2', path=my_path)

# If you applied the cut on qrOutput(FBDT) > -2 before then you can rank by highest r- factor
ma.rankByHighest(particleList='B0:jspipi0',
                 variable='abs(qrOutput(FBDT))',
                 numBest=0,
                 outputVariable='Dilution_rank',
                 path=my_path)

# Fit Vertex of the B0 on the tag side
vx.TagV(list_name='B0:jspipi0',
        MCassociation='breco',
        confidenceLevel=0.001,
        useFitAlgorithm='standard_PXD',
        path=my_path)

# Select variables that we want to store to ntuple
fs_vars = vc.pid + vc.track + vc.mc_truth
jpsiandk0s_vars = vc.mc_truth
bvars = vc.reco_stats + \
    vc.deltae_mbc + \