Belle II Software  release-08-01-10
test6_CPVAnalysisTools.py
1 #!/usr/bin/env python
2 
3 
10 
11 """
12 <header>
13  <output>CPVToolsOutput.root</output>
14  <contact>Thibaud Humair; thumair@mpp.mpg.de</contact>
15  <description>This file employs all the time dependent CPV analysis tools. It reconstructs B0sig->J/PsiKs on the signal side
16  and applies the flavor tagger on the ROE. The vertex of B0sig is reconstructed and the vertex of B0tag is reconstructed
17  with the TagV module. </description>
18 </header>
19 """
20 
21 import basf2 as b2
22 import modularAnalysis as ma
23 import flavorTagger as ft
24 import vertex as vx
25 import variables.collections as vc
26 import variables.utils as vu
27 
28 # create path
29 cp_val_path = b2.Path()
30 
31 inputFile = b2.find_file(filename='analysis/mdst11_BGx1_b2jpsiks.root', data_type='validation')
32 ma.inputMdst(filename=inputFile, path=cp_val_path)
33 
34 # Reconstruction of signal side and MC match
35 ma.fillParticleList(decayString='pi+:all', cut='', path=cp_val_path)
36 ma.fillParticleList(decayString='mu+:all', cut='', path=cp_val_path)
37 
38 ma.reconstructDecay(decayString='K_S0:pipi -> pi+:all pi-:all', cut='dM<0.25', path=cp_val_path)
39 ma.reconstructDecay(decayString='J/psi:mumu -> mu+:all mu-:all', cut='dM<0.11', path=cp_val_path)
40 ma.reconstructDecay(decayString='B0:jpsiks -> J/psi:mumu K_S0:pipi', cut='Mbc > 5.2 and abs(deltaE)<0.2', path=cp_val_path)
41 
42 ma.matchMCTruth(list_name='B0:jpsiks', path=cp_val_path)
43 
44 # build the rest of the event associated to the B0
45 ma.buildRestOfEvent(target_list_name='B0:jpsiks', fillWithMostLikely=True, path=cp_val_path)
46 
47 # Get Special GT for the flavor tagger weight files
48 b2.conditions.append_globaltag(ma.getAnalysisGlobaltag())
49 
50 # Flavor Tagger, Vertex of Signal Side and TagV
51 ft.flavorTagger(
52  particleLists=['B0:jpsiks'],
53  weightFiles='B2nunubarBGx1',
54  path=cp_val_path)
55 
56 vx.treeFit(list_name='B0:jpsiks', conf_level=1e-10, ipConstraint=True, path=cp_val_path)
57 vx.TagV(list_name='B0:jpsiks', MCassociation='breco', constraintType='tube', path=cp_val_path)
58 
59 # Select variables that will be stored to ntuple
60 fs_vars = vc.pid + vc.track + vc.track_hits + vc.mc_truth
61 jpsiandk0s_vars = vc.mc_truth
62 vertex_vars = vc.vertex + vc.mc_vertex + vc.kinematics + vc.mc_kinematics
63 bvars = vc.reco_stats + \
64  vc.deltae_mbc + \
65  vc.mc_truth + \
66  vc.roe_multiplicities + \
67  ft.flavor_tagging + \
68  vc.tag_vertex + \
69  vc.mc_tag_vertex + \
70  vertex_vars + \
71  vu.create_aliases_for_selected(list_of_variables=fs_vars,
72  decay_string='B0 -> [J/psi -> ^mu+ ^mu-] [K_S0 -> ^pi+ ^pi-]') + \
73  vu.create_aliases_for_selected(list_of_variables=jpsiandk0s_vars,
74  decay_string='B0 -> [^J/psi -> mu+ mu-] [^K_S0 -> pi+ pi-]') + \
75  vu.create_aliases_for_selected(list_of_variables=vertex_vars,
76  decay_string='B0 -> [^J/psi -> ^mu+ ^mu-] [^K_S0 -> ^pi+ ^pi-]')
77 
78 # Saving variables to ntuple
79 ma.variablesToNtuple(decayString='B0:jpsiks',
80  variables=bvars,
81  filename='../CPVToolsOutput.root',
82  treename='B0tree',
83  path=cp_val_path)
84 
85 ma.summaryOfLists(particleLists=['B0:jpsiks'], path=cp_val_path)
86 
87 cp_val_path.add_module('Progress')
88 # Process the events
89 b2.process(cp_val_path)
90 
91 # print out the summary
92 print(b2.statistics)