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