def reconstruct_B(path, lepton, kstar): # lepton if lepton == 'e': lep_list = ' e+:corrected e-:corrected' lepbrem_list = ' e+:all e-:all' elif lepton == 'mu': lep_list = ' mu+:all mu-:all' # K* if kstar == 'kst0': charge = '0' kstlist = 'K*0:all' elif kstar == 'kst_ks': charge = '+' kstlist = 'K*+:ks' elif kstar == 'kst_pi0': charge = '+' kstlist = 'K*+:pi0' Jpsi = ' J/psi' + ':' +lepton+lepton chain = Jpsi+' -> ' + lep_list print(purple, 'reconstruct decay:', end, cyan, chain, end) reconstructDecay(decayString=chain,cut='dM<0.11', path=path) # combine J/psi and Kst candidates to form B0 candidates Bmeson = 'B'+charge+':'+kstar+'Jpsi' chain = Bmeson+' -> ' + kstlist + Jpsi print(purple, 'reconstruct decay:', end, cyan, chain, end) # reconstruction reconstructDecay(decayString=chain, cut='Mbc > 5.2 and abs(deltaE) < 0.3', path=path) matchMCTruth(list_name=Bmeson, path=path) # variablesToNtuple(chain, ['M', 'p', 'E', 'useCMSFrame(p)', 'useCMSFrame(E)', 'daughter(0, kaonID)', # 'daughter(1, pionID)', 'isSignal', 'mcErrors'], # filename='ntuple.root', treename="D", path=path) # ROE and vfit continuum(Bmeson, path) Apply_VerTexFit(path, lepton, kstar) vertex.TagV(list_name=Bmeson, maskName='cleanMask'+Bmeson, path=path)
def reconstruct_B(path, lepton, kstar): # lepton if lepton == 'e': lep_list = ' e+:corrected e-:corrected' lepbrem_list = ' e+:all e-:all' elif lepton == 'mu': lep_list = ' mu+:all mu-:all' # K* if kstar == 'kst0': charge = '0' kstlist = 'K*0:all' elif kstar == 'kst_ks': charge = '+' kstlist = 'K*+:ks' elif kstar == 'kst_pi0': charge = '+' kstlist = 'K*+:pi0' Bmeson = 'B'+charge+':'+kstar+lepton+lepton chain = Bmeson+' -> ' + kstlist + lep_list print(purple, 'reconstruct decay:', end, cyan, chain, end) # reconstruction reconstructDecay(decayString=chain, cut='5.2 < Mbc < 5.29 and -0.3 < deltaE < 0.3', path=path) matchMCTruth(list_name=Bmeson, path=path) # ROE and vfit continuum(Bmeson, path) Apply_VerTexFit(path, lepton, kstar) vertex.TagV(list_name=Bmeson, maskName='cleanMask'+Bmeson, path=path) if lepton == 'e': Bmeson = 'B'+charge+':'+kstar+lepton+lepton + '_brem' chain = Bmeson+' -> ' + kstlist + lep_list + lepbrem_list print(purple, 'reconstruct decay:', end, cyan, chain, end) reconstructDecay(decayString=chain, cut='5.2 < Mbc < 5.3 and -0.3 < deltaE < 0.3', path=path)
path=main) # match reconstructed with MC particles ma.matchMCTruth('B0', path=main) # build the rest of the event ma.buildRestOfEvent('B0', fillWithMostLikely=True, path=main) # call flavor tagging ft.flavorTagger('B0', path=main) # remove B0 candidates without a valid flavor information ma.applyCuts('B0', 'qrOutput(FBDT) > -2', path=main) # fit B vertex on the tag-side vertex.TagV('B0', constraintType='tube', fitAlgorithm='Rave', path=main) # perform best candidate selection #b2.set_random_seed('USBelleIISummerSchool') #ma.rankByHighest('B0', variable='random', numBest=1, path=main) # create list of variables for output ntuple standard_vars = vc.kinematics + vc.mc_kinematics + vc.mc_truth fs_vars = vc.pid + vc.track + vc.track_hits + standard_vars jpsi_ks_vars = vc.inv_mass + vc.vertex + vc.mc_vertex + standard_vars b_vars = vc.deltae_mbc + vc.tag_vertex + vc.mc_tag_vertex + ft.flavor_tagging + standard_vars b_vars += vu.create_aliases_for_selected([*fs_vars, 'isBremsCorrected'], 'B0 -> [J/psi -> ^e+ ^e-] K_S0', prefix=['ep', 'em']) b_vars += vu.create_aliases_for_selected(fs_vars,
# 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) ma.matchMCTruth('B0:signal', path=main_path) vtx.TagV('B0:signal', 'internal', path=main_path) ft.flavorTagger(particleLists = 'B0:signal', weightFiles='B2nunubarBGx1', path=main_path) #matchMCTruth('pi+:all') #matchMCTruth(Kres+':all') #matchMCTruth('gamma:loose') main_path.add_module('MVAExpert', listNames=['B0:signal'], extraInfoName='CSMVA', identifier='./mva-addition/MyTMVA.xml') ma.writePi0EtaVeto('B0:signal', 'B0 -> pi+:good pi-:good K_S0:all ^gamma', path=main_path) #myVetoVariables() kin_variables = vc.mc_truth + ['p', 'E', 'pCMS', 'ECMS', 'cosTheta', 'phi', 'M', 'dM', 'chiProb','charge', 'PDG'] ft_variables = makePretty(['qrOutput(FBDT)', 'qrOutput(FANN)', 'isRelatedRestOfEventB0Flavor', 'qOutput(FANN)', 'rBinBelle(FANN)', 'qOutput(FBDT)', 'rBinBelle(FBDT)', 'EW90', 'pMissCMS', 'cosThetaMissCMS'])
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)
# 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 + \ 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') + \