Belle II Software  release-06-00-14
test6_CPVFlavorTaggerSkim.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 """
13  This file skims events that are useful to test the time dependent CPV analysis tools,
14  i.e. those events where the signal B0 meson is correctly MC matched and where no tracks on the tag side
15  belong to the signal side. The variable used for skimming is isRelatedRestOfEventB0Flavor.
16  As input one needs a MC mdst file for the signal channel B0sig->J/PsiKs.
17  The script reconstructs B0sig->J/PsiKs on the signal side
18  and applies the flavor tagger on the ROE.
19  The vertex of B0sig is reconstructed (JPsi vertex) and the vertex of B0tag is reconstructed
20  with the TagV module.
21 """
22 
23 import basf2 as b2
24 import modularAnalysis as ma
25 import os
26 import sys
27 
28 from mdst import add_mdst_output
29 
30 if len(sys.argv) != 3:
31  sys.exit('Must provide three input parameters: [Belle_Belle2] [output_root_file_name]'
32  )
33 
34 belleOrBelle2Flag = sys.argv[1]
35 outRootFileName = sys.argv[2]
36 
37 
38 # create path
39 cp_val_path = b2.Path()
40 
41 environmentType = "default"
42 
43 if belleOrBelle2Flag == "Belle":
44  os.environ['BELLE_POSTGRES_SERVER'] = 'can51'
45  os.environ['USE_GRAND_REPROCESS_DATA'] = '1'
46 
47  environmentType = "Belle"
48 
49 ma.inputMdstList(environmentType=environmentType, filelist=[], path=cp_val_path)
50 
51 ma.fillParticleList(decayString='mu+:all', cut='', path=cp_val_path)
52 ma.reconstructDecay(decayString='J/psi:mumu -> mu+:all mu-:all', cut='abs(dM) < 0.11', path=cp_val_path)
53 ma.matchMCTruth(list_name='J/psi:mumu', path=cp_val_path)
54 
55 if belleOrBelle2Flag == "Belle":
56 
57  # use the existent K_S0:mdst list
58  ma.matchMCTruth(list_name='K_S0:mdst', path=cp_val_path)
59 
60  # reconstruct B0 -> J/psi Ks decay
61  ma.reconstructDecay(decayString='B0:sig -> J/psi:mumu K_S0:mdst', cut='Mbc > 5.2 and abs(deltaE) < 0.15', path=cp_val_path)
62 
63 if belleOrBelle2Flag == "Belle2":
64 
65  # reconstruct Ks from standard pi+ particle list
66  ma.fillParticleList(decayString='pi+:all', cut='', path=cp_val_path)
67  ma.reconstructDecay(decayString='K_S0:pipi -> pi+:all pi-:all', cut='abs(dM) < 0.25', path=cp_val_path)
68 
69  # reconstruct B0 -> J/psi Ks decay
70  ma.reconstructDecay(decayString='B0:sig -> J/psi:mumu K_S0:pipi', cut='Mbc > 5.2 and abs(deltaE) < 0.15', path=cp_val_path)
71 
72 ma.matchMCTruth(list_name='B0:sig', path=cp_val_path)
73 
74 ma.buildRestOfEvent(target_list_name='B0:sig', path=cp_val_path)
75 
76 ma.applyCuts(list_name='B0:sig', cut='abs(isRelatedRestOfEventB0Flavor) == 1', path=cp_val_path)
77 
78 # # Get Special GT for the flavor tagger weight files
79 # b2.conditions.append_globaltag("analysis_tools_release-04-00")
80 #
81 # # Flavor Tagger, Vertex of Signal Side and TagV
82 # ft.flavorTagger(
83 # particleLists=['B0:sig'],
84 # weightFiles='B2JpsiKs_muBGx1',
85 # belleOrBelle2=belleOrBelle2Flag,
86 # path=cp_val_path)
87 #
88 # cutString = "qpCategory(FastPion) > 0.4 and qpCategory(FastPion) < 0.5 " + \
89 # "and hasTrueTargets(FastPion) < 1 and isRelatedRestOfEventB0Flavor == 1"
90 # cutString = "qpCategory(Kaon) > -1 and qpCategory(Kaon) < -0.8 and hasTrueTargets(Kaon) == 0 "
91 # cutString = "qpCategory(KinLepton) > 0.8 and qpCategory(KinLepton) < 1 and hasTrueTargets(KinLepton) == 0 "
92 # cutString = "qpCategory(SlowPion)> -1 and qpCategory(SlowPion) < -0.8 and hasTrueTargets(SlowPion) == 0 "
93 # cutString = "qrOutput(FBDT) > 0.4 and qrOutput(FBDT) < 0.65"
94 
95 # printVariablesList = []
96 # for (particleList, category, combinerVariable) in eventLevelParticleLists:
97 # if category != "MaximumPstar":
98 # cutString = cutString + " and hasTrueTargets(" + category + ") == 0 "
99 # printVariablesList.append("qpCategory(" + category + ")")
100 # printVariablesList.append("hasTrueTargets(" + category + ")")
101 
102 # applyCuts('B0:sig', cutString)
103 
104 # printVariableValues('B0:sig', printVariablesList)
105 
106 # Skim 1
107 # The new algorithm
108 skimfilter = b2.register_module('SkimFilter')
109 skimfilter.set_name('SkimFilter_B2JPsiKs_NoTargetOfFT')
110 # Provide the particle lists that will be used as an event/skim filter
111 skimfilter.param('particleLists', ['B0:sig'])
112 cp_val_path.add_module(skimfilter)
113 # ------------------> summaryOfLists -----------------------------------------------------------------
114 
115 
116 # Create a new path for the skim output
117 B0skim_path = b2.Path()
118 # The filter provides a boolean, which is true if any of the argument particle lists are not empty
119 # skimfilter.if_value('=1', B0skim_path, AfterConditionPath.CONTINUE)
120 skimfilter.if_value('=0', B0skim_path)
121 
122 # dump in MDST format
123 add_mdst_output(cp_val_path, True, outRootFileName)
124 
125 ma.summaryOfLists(particleLists=['B0:sig'], path=cp_val_path)
126 
127 # Process the events
128 ma.process(cp_val_path)
129 
130 # print out the summary
131 print(b2.statistics)