12 from basf2
import B2INFO, B2ERROR
14 import modularAnalysis
as ma
16 from variables
import utils
19 def add_default_ks_Selector_aliases():
21 This function is used to set up variables aliases for ks Selector variables.
23 B2INFO(
'KsSelector: creating variables alias.')
24 variables.variables.addAlias(
'M_lambda_p',
'useAlternativeDaughterHypothesis(M, 0:p+)')
25 variables.variables.addAlias(
'M_lambda_antip',
'useAlternativeDaughterHypothesis(M, 1:anti-p-)')
26 variables.variables.addAlias(
'daughtersDeltaZ',
'daughterDiffOf(0, 1, dz)')
27 variables.variables.addAlias(
'cosVertexMomentum',
'cosAngleBetweenMomentumAndVertexVector')
28 variables.variables.addAlias(
'pip_nPXDHits',
'daughter(0,nPXDHits)')
29 variables.variables.addAlias(
'pin_nPXDHits',
'daughter(1,nPXDHits)')
30 variables.variables.addAlias(
'pip_nSVDHits',
'daughter(0,nSVDHits)')
31 variables.variables.addAlias(
'pin_nSVDHits',
'daughter(1,nSVDHits)')
32 variables.variables.addAlias(
'daughterAngleDiffInMother',
'useRestFrame(daughterAngle(0, 1))')
33 variables.variables.addAlias(
'pip_p',
'daughter(0,p)')
34 variables.variables.addAlias(
'pin_p',
'daughter(1,p)')
35 variables.variables.addAlias(
'pip_dr',
'daughter(0,dr)')
36 variables.variables.addAlias(
'pin_dr',
'daughter(1,dr)')
37 variables.variables.addAlias(
'pip_cosTheta',
'daughter(0,cosTheta)')
38 variables.variables.addAlias(
'pin_cosTheta',
'daughter(1,cosTheta)')
39 variables.variables.addAlias(
'pip_protonID',
'daughter(0,protonID)')
40 variables.variables.addAlias(
'pin_protonID',
'daughter(1,protonID)')
43 def add_variable_collection():
45 Call this function to add variable collection for ksSelector.
47 add_default_ks_Selector_aliases()
48 inputVariablesList = [
51 'significanceOfDistance',
52 'cosHelicityAngleMomentum',
56 'daughterAngleDiffInMother',
58 'pip_nSVDHits',
'pip_nPXDHits',
59 'pin_nSVDHits',
'pin_nPXDHits',
61 'pip_protonID',
'pin_protonID',
62 'M_lambda_p',
'M_lambda_antip',
64 'pip_cosTheta',
'pin_cosTheta',
66 utils.add_collection(inputVariablesList,
'ks_selector_info')
69 def V0Selector_Training(
72 mva_identifier="MVAFastBDT_V0Selector.root",
73 target_variable="isSignal"
76 Defines the configuration of V0Selector Training.
77 The training data should contain K_S0 and misreconstructed K_S0 without Lambda0.
79 @param train_data Root file containing Ks information to be trained.
80 @param tree_name Tree name for variables.
81 @param mva_identifier Name for output MVA weight file.
82 @param target_variable Target variable for MVA training.
87 'significanceOfDistance',
88 'cosHelicityAngleMomentum',
92 'daughterAngleDiffInMother',
94 'pip_nSVDHits',
'pip_nPXDHits',
95 'pin_nSVDHits',
'pin_nPXDHits',
99 general_options = basf2_mva.GeneralOptions()
100 general_options.m_datafiles = basf2_mva.vector(train_data)
101 general_options.m_treename = tree_name
102 general_options.m_identifier = mva_identifier
103 general_options.m_variables = basf2_mva.vector(*trainVars)
104 general_options.m_target_variable = target_variable
105 fastbdt_options = basf2_mva.FastBDTOptions()
106 basf2_mva.teacher(general_options, fastbdt_options)
109 def LambdaVeto_Training(
112 mva_identifier="MVAFastBDT_LambdaVeto.root",
113 target_variable="isSignal"
116 Defines the configuration of LambdaVeto Training.
117 The training data should contain only K_S0 and Lambda0.
119 @param train_data Root file containing Ks information to be trained.
120 @param tree_name Tree name for variables.
121 @param mva_identifier Name for output MVA weight file.
122 @param target_variable Target variable for MVA training.
134 general_options = basf2_mva.GeneralOptions()
135 general_options.m_datafiles = basf2_mva.vector(train_data)
136 general_options.m_treename = tree_name
137 general_options.m_identifier = mva_identifier
138 general_options.m_variables = basf2_mva.vector(*trainVars)
139 general_options.m_target_variable = target_variable
140 fastbdt_options = basf2_mva.FastBDTOptions()
141 basf2_mva.teacher(general_options, fastbdt_options)
152 output_label_name='',
153 extraInfoName_V0Selector='KsSelector_V0Selector',
154 extraInfoName_LambdaVeto='KsSelector_LambdaVeto',
155 useCustomThreshold=False,
156 threshold_V0Selector=0.90,
157 threshold_LambdaVeto=0.11,
161 This function will apply K_S0 selection MVA on the given particleList.
162 By default this function appends MVA output as a extraInfo for the given particleList.
163 You can apply preset cut or custom cut by giving parameters. In this case,
164 a new particleList is created from the original particleList applying cuts on the MVA output.
166 @param particleLists Reconstructed Ks -> pi+ pi- list.
167 @param output_label_name Label of the returned Ks particleList.
168 When empty '', no cut is applied and new particleList is not created.
169 When custom name, the custom threshold is used, and useCustomThreshold
171 When 'standard', 'tight', or 'loose', a cut with Ks efficiency
172 90%, 95%, and 85% is applied.
173 @param extraInfoName_V0Selector Variable name for V0Selector MVA output.
174 @param extraInfoName_LambdaVeto Variable name for LambdaVeto MVA output.
175 @param identifier_Ks Identifier name for V0Selector weight file.
176 @param identifier_vLambda Identifier name for LambdaVeto weight file.
177 @param useCustomThreshold Flag whether threshold_V0Selector and threshold_LambdaVeto are used.
178 @param threshold_V0Selector Threshold for V0Selector.
179 @param threshold_LambdaVeto Threshold for LambdaVeto.
180 @param path Basf2 path to execute.
184 add_default_ks_Selector_aliases()
186 path.add_module(
'MVAMultipleExperts',
187 listNames=[particleListName],
188 extraInfoNames=[extraInfoName_V0Selector, extraInfoName_LambdaVeto],
189 identifiers=[identifier_Ks, identifier_vLambda])
191 _effnames = [
'standard',
'tight',
'loose']
194 if useCustomThreshold:
195 if output_label_name
in _effnames:
196 B2ERROR(
'KsSelector: Specify label name except for \'standard\', \'tight\', and \'loose\' '
197 'when you use custom threshold.')
198 elif output_label_name ==
'':
199 B2ERROR(
'KsSelector: Specify label name when you use custom threshold.')
201 outputListName = particleListName.split(
':')[0] +
':' + output_label_name
202 B2INFO(
'KsSelector: Custom Cut is applied on '+outputListName+
'.')
203 V0_thr = threshold_V0Selector
204 Lambda_thr = threshold_LambdaVeto
205 B2INFO(
'KsSelector: Threshold is (' + str(V0_thr) +
', ' + str(Lambda_thr) +
')')
206 cut_string =
'extraInfo('+extraInfoName_V0Selector+
')>'+str(V0_thr) + \
207 ' and extraInfo('+extraInfoName_LambdaVeto+
')>'+str(Lambda_thr)
208 ma.cutAndCopyLists(outputListName, particleListName, cut=cut_string, path=path)
210 if output_label_name
in _effnames:
211 outputListName = particleListName.split(
':')[0] +
':' + output_label_name
214 if output_label_name ==
'standard':
215 B2INFO(
'KsSelector: Standard Cut is applied on '+outputListName+
'.')
218 elif output_label_name ==
'tight':
219 B2INFO(
'KsSelector: Tight Cut is applied on '+outputListName+
'.')
222 elif output_label_name ==
'loose':
223 B2INFO(
'KsSelector: Loose Cut is applied on '+outputListName+
'.')
226 B2INFO(
'KsSelector: Threshold is (' + str(V0_thr) +
', ' + str(Lambda_thr) +
')')
227 cut_string =
'extraInfo('+extraInfoName_V0Selector+
')>'+str(V0_thr) + \
228 ' and extraInfo('+extraInfoName_LambdaVeto+
')>'+str(Lambda_thr)
229 ma.cutAndCopyLists(outputListName, particleListName, cut=cut_string, path=path)
230 elif output_label_name ==
'':
231 outputListName = particleListName
233 B2ERROR(
'KsSelector: Label should be \'\', \'standard\', \'tight\', or \'loose\' if you do'
234 'not apply custom threshold')
236 B2INFO(
'KsSelector: ParticleList '+outputListName+
' is returned.')