Belle II Software development
arichToAnalysisNtuple.py
1#!/usr/bin/env python3
2
3
10
11
24
25import basf2 as b2
26import modularAnalysis as ma
27import variables.collections as vc
28import variables.utils as vu
29import arich as arich
30from variables import variables
31import vertex as vx
32
33# create path
34my_path = b2.create_path()
35
36# load example input ROOT file (can override with -i option)
37fname = "/group/belle2/dataprod/Data/release-03-02-02/DB00000654/proc9/e0008/4S/GoodRuns/r00827/"\
38 "skim/hlt_hadron/cdst/sub00/cdst.physics.0008.00827.HLT1.hlt_hadron.f00000.root"
39ma.inputMdst(environmentType='default',
40 filename=fname,
41 path=my_path)
42
43
44# if you want re-run arich reconstruction uncomment lines below
45# ===========================
46# arichHits = b2.register_module('ARICHFillHits')
47# arichHits.param('MagFieldCorrection',1)
48# my_path.add_module(arichHits)
49# arichRecon = b2.register_module('ARICHReconstructor')
50# arichRecon.param('storePhotons', 1)
51# my_path.add_module(arichRecon)
52# ===========================
53
54# creates "pi+:loose" ParticleList (and c.c.)
55# includes all tracks with thetaInCDCAcceptance and nCDCHits>20
56ma.fillParticleList('pi+:loose', 'thetaInCDCAcceptance and nCDCHits>20', True, path=my_path)
57
58
59# define aliases for daughter particles
60# cosTheta
61variables.addAlias('pi0_cosTheta', 'daughter(0, cosTheta)')
62variables.addAlias('pi1_cosTheta', 'daughter(1, cosTheta)')
63# momentum
64variables.addAlias('pi0_p', 'daughter(0, p)')
65variables.addAlias('pi1_p', 'daughter(1, p)')
66
67# reconstruct ks -> pi+ pi- decay
68# keep only candidates with 0.45 < M(pi+pi-) < 0.55 GeV and with
69# at least one "forward" track with cosTheta>0.82 and p>0.5 GeV
70ma.reconstructDecay(decayString='K_S0 -> pi+:loose pi-:loose',
71 cut='0.45 < M < 0.55 and [[pi0_cosTheta > 0.82 and pi0_p > 0.5] or [pi1_cosTheta > 0.82 and pi1_p>0.5]]',
72 path=my_path)
73
74# do vertex fit
75# only keeps candidates with conf_level>0.001
76vx.kFit(list_name='K_S0',
77 conf_level=0.001,
78 path=my_path)
79
80# only keep K_S0 candidates with cosAngleBetweenMomentumAndVertexVector > 0.9
81# (i.e. momentum in the same direction as decay vertex position)
82ma.cutAndCopyLists("K_S0:good", "K_S0", "cosAngleBetweenMomentumAndVertexVector > 0.9", path=my_path)
83
84# Select variables that we want to store to ntuple
85# this follows exactly same scheme and syntax as used by variablesToNtuple!
86# make aliases for long PID variables
87variables.addAlias('dll_arich', 'pidDeltaLogLikelihoodValueExpert(211,321,ARICH)')
88variables.addAlias('R_Kpi_arich', 'pidPairProbabilityExpert(321, 211, ARICH)')
89variables.addAlias('kaonID_arich', 'pidProbabilityExpert(321, ARICH)')
90variables.addAlias('pionID_arich', 'pidProbabilityExpert(211, ARICH)')
91variables.addAlias('R_Kpi_all', 'pidPairProbabilityExpert(321, 211, ARICH,TOP,CDC)') # kaon/pion all
92variables.addAlias('R_Kpi_top', 'pidPairProbabilityExpert(321, 211, TOP)') # kaon/pion tion
93variables.addAlias('R_Kpi_cdc', 'pidPairProbabilityExpert(321,211,CDC)') # kaon/pion cdc
94variables.addAlias('R_ppi_woarich', 'pidPairProbabilityExpert(2212, 211,TOP,CDC,ECL)') # proton/pion w/o arich
95
96# variables to store for daughter pions
97pi_vars = vc.pid + vc.track + ['nCDCHits',
98 'cosTheta',
99 'clusterE',
100 'nMatchedKLMClusters',
101 'pt',
102 'minC2TDist',
103 'trackNECLClusters',
104 'dll_arich',
105 'R_Kpi_arich',
106 'kaonID_arich',
107 'pionID_arich',
108 'R_Kpi_all',
109 'R_Kpi_top',
110 'R_Kpi_cdc',
111 'R_ppi_woarich']
112# variables to store for K_S0
113ks_vars = vc.mc_truth + vc.kinematics + vc.vertex + vc.inv_mass + ['cosAngleBetweenMomentumAndVertexVector'] + \
114 vu.create_aliases_for_selected(list_of_variables=pi_vars,
115 decay_string='K_S0 -> ^pi+ ^pi-')
116
117
118# Save variables to ntuple
119# ===================================================
120# this is the main point of this example file
121# instead of using "variablesToNtuple" we use "arichVariablesToNtuple" which takes the same parameters,
122# but in addition one should specify string "arichSelector" which selects particles for which detailed arich information is stored
123# (like number of detected photons, track position on aerogel plane, distribution of Cherenkov photons, etc)
124# ===================================================
125rootOutputFile = 'arich_ks_reco.root'
126
127arich.arichVariablesToNtuple(decayString='K_S0:good', # list of particles to fill
128 variables=ks_vars, # list of all variables
129 arichSelector='K_S0 -> ^pi+ ^pi-', # select particles for which arich detail info should be stored
130 filename=rootOutputFile,
131 treename='ks',
132 path=my_path)
133
134# Process the events
135b2.process(my_path)
136
137# print out the summary
138print(b2.statistics)
def arichVariablesToNtuple(decayString, variables, arichSelector, treename='variables', filename='ntuple.root', path=None)
Definition: arich.py:19