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