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