Belle II Software  release-08-01-10
test6_CPVFlavorTaggerSkim.py
1 #!/usr/bin/env python
2 
3 
10 
11 """
12  This file skims events that are useful to test the time dependent CPV analysis tools,
13  i.e. those events where the signal B0 meson is correctly MC matched and where no tracks on the tag side
14  belong to the signal side. The variable used for skimming is isRelatedRestOfEventB0Flavor.
15  As input one needs a MC mdst file for the signal channel B0sig->J/PsiKs.
16  The script reconstructs B0sig->J/PsiKs on the signal side
17  and applies the flavor tagger on the ROE.
18  The vertex of B0sig is reconstructed (JPsi vertex) and the vertex of B0tag is reconstructed
19  with the TagV module.
20 """
21 
22 import basf2 as b2
23 import modularAnalysis as ma
24 import os
25 import sys
26 
27 from mdst import add_mdst_output
28 
29 if len(sys.argv) != 3:
30  sys.exit('Must provide three input parameters: [Belle_Belle2] [output_root_file_name]'
31  )
32 
33 belleOrBelle2Flag = sys.argv[1]
34 outRootFileName = sys.argv[2]
35 
36 
37 # create path
38 cp_val_path = b2.Path()
39 
40 environmentType = "default"
41 
42 if belleOrBelle2Flag == "Belle":
43  os.environ['BELLE_POSTGRES_SERVER'] = 'can51'
44  os.environ['USE_GRAND_REPROCESS_DATA'] = '1'
45 
46  environmentType = "Belle"
47 
48 ma.inputMdstList(environmentType=environmentType, filelist=[], path=cp_val_path)
49 
50 ma.fillParticleList(decayString='mu+:all', cut='', path=cp_val_path)
51 ma.reconstructDecay(decayString='J/psi:mumu -> mu+:all mu-:all', cut='abs(dM) < 0.11', path=cp_val_path)
52 ma.matchMCTruth(list_name='J/psi:mumu', path=cp_val_path)
53 
54 if belleOrBelle2Flag == "Belle":
55 
56  # use the existent K_S0:mdst list
57  ma.matchMCTruth(list_name='K_S0:mdst', path=cp_val_path)
58 
59  # reconstruct B0 -> J/psi Ks decay
60  ma.reconstructDecay(decayString='B0:sig -> J/psi:mumu K_S0:mdst', cut='Mbc > 5.2 and abs(deltaE) < 0.15', path=cp_val_path)
61 
62 if belleOrBelle2Flag == "Belle2":
63 
64  # reconstruct Ks from standard pi+ particle list
65  ma.fillParticleList(decayString='pi+:all', cut='', path=cp_val_path)
66  ma.reconstructDecay(decayString='K_S0:pipi -> pi+:all pi-:all', cut='abs(dM) < 0.25', path=cp_val_path)
67 
68  # reconstruct B0 -> J/psi Ks decay
69  ma.reconstructDecay(decayString='B0:sig -> J/psi:mumu K_S0:pipi', cut='Mbc > 5.2 and abs(deltaE) < 0.15', path=cp_val_path)
70 
71 ma.matchMCTruth(list_name='B0:sig', path=cp_val_path)
72 
73 ma.buildRestOfEvent(target_list_name='B0:sig', path=cp_val_path)
74 
75 ma.applyCuts(list_name='B0:sig', cut='abs(isRelatedRestOfEventB0Flavor) == 1', path=cp_val_path)
76 
77 # Skim 1
78 # The new algorithm
79 skimfilter = b2.register_module('SkimFilter')
80 skimfilter.set_name('SkimFilter_B2JPsiKs_NoTargetOfFT')
81 # Provide the particle lists that will be used as an event/skim filter
82 skimfilter.param('particleLists', ['B0:sig'])
83 cp_val_path.add_module(skimfilter)
84 # ------------------> summaryOfLists -----------------------------------------------------------------
85 
86 
87 # Create a new path for the skim output
88 B0skim_path = b2.Path()
89 # The filter provides a boolean, which is true if any of the argument particle lists are not empty
90 # skimfilter.if_value('=1', B0skim_path, AfterConditionPath.CONTINUE)
91 skimfilter.if_value('=0', B0skim_path)
92 
93 # dump in MDST format
94 add_mdst_output(cp_val_path, True, outRootFileName)
95 
96 ma.summaryOfLists(particleLists=['B0:sig'], path=cp_val_path)
97 
98 # Process the events
99 ma.process(cp_val_path)
100 
101 # print out the summary
102 print(b2.statistics)