Exemplo n.º 1
0
######################################################
# event based cut - ==  2 tracks in event
######################################################

var.addAlias('nCleanedTracks', 'nCleanedTracks(' + cleanTrack + ')')
ma.applyEventCuts(cut='nCleanedTracks == 2', path=my_path)

#######################################################
# EventShape and EventKinamatics modules
#######################################################
ma.buildEventShape(['e-:good', 'mu+:mugood', 'pi-:good'],
                   foxWolfram=False,
                   cleoCones=False,
                   jets=False,
                   harmonicMoments=False,
                   allMoments=False,
                   collisionAxis=False,
                   sphericity=False,
                   thrust=True,
                   path=my_path)
ma.buildEventKinematics(['e-:good', 'pi-:good', 'mu+:mugood'], path=my_path)

# Get information of the generated decay mode calling labelTauPairMC from modular analysis
ma.labelTauPairMC(path=my_path)

######################################################
# Signal and tag sides
#######################################################

ma.reconstructDecay('tau+:signal -> mu+:mugood', '', path=my_path)
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
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',
Exemplo n.º 3
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)
ma.fillParticleListFromMC('tau+:gen', '', path=my_path)

####################################################
# track cuts
######################################################

var.addAlias('EoverP', 'formula( ifNANgiveX( clusterE, -1 )/p )')

#######################################################
# EventShape and EventKinamatics modules
#######################################################
ma.buildEventShape(['tau-:gen', 'tau+:gen'],
                   foxWolfram=False,
                   cleoCones=False,
                   jets=False,
                   harmonicMoments=False,
                   allMoments=False,
                   collisionAxis=False,
                   sphericity=False,
                   thrust=True,
                   path=my_path)
ma.buildEventKinematics(['tau-:gen', 'tau+:gen'], path=my_path)

# Get information of the generated decay mode calling labelTauPairMC from modular analysis
ma.labelTauPairMC(path=my_path)

######################################################
# Signal and tag sides
#######################################################

ma.reconstructDecay('vpho:photon_B2SS -> tau+:gen tau-:gen', '', 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