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