Belle II Software development
cosmicsCAF.py
1#!/usr/bin/env python3
2
3
10
11
22
23import basf2 as b2
24import os
25import ROOT
26from ROOT.Belle2 import CDCDedxMomentumAlgorithm, CDCDedxCosineAlgorithm
27from ROOT.Belle2 import CDCDedxWireGainAlgorithm, CDCDedxRunGainAlgorithm
28from ROOT.Belle2 import CDCDedx2DCorrectionAlgorithm, CDCDedx1DCleanupAlgorithm
29from caf.framework import Calibration, CAF
30
31ROOT.gROOT.SetBatch(True)
32
33# Specify the input file(s)
34input_files = [os.path.abspath(
35 '/group/belle2/users/jbennett/GCR2/release-01-02-01/DB00000359/r00282/dst.cosmic.0002.0282.f00000.root')]
36
37# Modify the collector to apply other calibration constants
38momentum_col = b2.register_module('CDCDedxElectronCollector')
39momentum_col_params = {'cleanupCuts': False,
40 'scaleCor': False,
41 'momentumCor': False,
42 'momentumCorFromDB': False,
43 'cosineCor': False,
44 }
45momentum_col.param(momentum_col_params)
46
47mod_col = b2.register_module('CDCDedxElectronCollector')
48mod_col_params = {'cleanupCuts': True,
49 'scaleCor': False,
50 'momentumCor': False,
51 'momentumCorFromDB': False,
52 'cosineCor': False,
53 }
54mod_col.param(mod_col_params)
55
56# Define the calibration algorithms
57momentum_alg = CDCDedxMomentumAlgorithm()
58cosine_alg = CDCDedxCosineAlgorithm()
59run_gain_alg = CDCDedxRunGainAlgorithm()
60wire_gain_alg = CDCDedxWireGainAlgorithm()
61twod_alg = CDCDedx2DCorrectionAlgorithm()
62oned_alg = CDCDedx1DCleanupAlgorithm()
63
64# Create Calibration objects from Collector, Algorithm(s), and input files
65momentum_cal = Calibration(
66 name='MomentumCalibration',
67 collector=momentum_col,
68 algorithms=[momentum_alg],
69 input_files=input_files)
70
71cosine_cal = Calibration(
72 name='CosineCalibration',
73 collector=mod_col,
74 algorithms=[cosine_alg],
75 input_files=input_files)
76
77wire_gain_cal = Calibration(
78 name='WireGainCalibration',
79 collector=mod_col,
80 algorithms=[wire_gain_alg],
81 input_files=input_files)
82
83run_gain_cal = Calibration(
84 name='RunGainCalibration',
85 collector=mod_col,
86 algorithms=[run_gain_alg],
87 input_files=input_files)
88
89other_cal = Calibration(
90 name='OtherDedxCalibrations',
91 collector=mod_col,
92 algorithms=[twod_alg, oned_alg],
93 input_files=input_files)
94
95# Use the constants in the local databases
96momdb = 'calibration_results/MomentumCalibration/outputdb'
97cosdb = 'calibration_results/CosineCalibration/outputdb'
98wgdb = 'calibration_results/WireGainCalibration/outputdb'
99rgdb = 'calibration_results/RunGainCalibration/outputdb'
100localdb = '/home/belle2/jbennett/CRDATA/release-00-09-01/DB00000266/r03118/calib/localdb/database.txt'
101
102momentum_cal.use_local_database(localdb)
103
104cosine_cal.use_local_database(localdb)
105cosine_cal.use_local_database(momdb)
106
107wire_gain_cal.use_local_database(localdb)
108wire_gain_cal.use_local_database(momdb)
109wire_gain_cal.use_local_database(cosdb)
110
111run_gain_cal.use_local_database(localdb)
112run_gain_cal.use_local_database(momdb)
113run_gain_cal.use_local_database(cosdb)
114run_gain_cal.use_local_database(wgdb)
115
116other_cal.use_local_database(localdb)
117other_cal.use_local_database(momdb)
118other_cal.use_local_database(cosdb)
119other_cal.use_local_database(wgdb)
120other_cal.use_local_database(rgdb)
121
122# Add a pre-collector path to apply old calibration constants
123correct_for_mom = b2.create_path()
124correct_for_mom.add_module('CDCDedxCorrection', scaleCor=False, momentumCor=False,
125 momentumCorFromDB=False, cosineCor=True,
126 runGain=True, wireGain=True)
127momentum_cal.pre_collector_path = correct_for_mom
128
129correct_for_cos = b2.create_path()
130correct_for_cos.add_module('CDCDedxCorrection', scaleCor=False, momentumCor=True,
131 momentumCorFromDB=True, cosineCor=False,
132 runGain=True, wireGain=True)
133cosine_cal.pre_collector_path = correct_for_cos
134cosine_cal.depends_on(momentum_cal)
135
136correct_for_wire_gain = b2.create_path()
137correct_for_wire_gain.add_module('CDCDedxCorrection', scaleCor=False, momentumCor=True,
138 momentumCorFromDB=True, cosineCor=True,
139 runGain=True, wireGain=False)
140wire_gain_cal.pre_collector_path = correct_for_wire_gain
141wire_gain_cal.depends_on(momentum_cal)
142wire_gain_cal.depends_on(cosine_cal)
143
144correct_for_run_gain = b2.create_path()
145correct_for_run_gain.add_module('CDCDedxCorrection', scaleCor=False, momentumCor=True,
146 momentumCorFromDB=True, cosineCor=True,
147 runGain=False, wireGain=True)
148run_gain_cal.pre_collector_path = correct_for_run_gain
149run_gain_cal.depends_on(momentum_cal)
150run_gain_cal.depends_on(cosine_cal)
151run_gain_cal.depends_on(wire_gain_cal)
152
153correct_for_others = b2.create_path()
154correct_for_others.add_module('CDCDedxCorrection', scaleCor=False, momentumCor=True,
155 momentumCorFromDB=True, cosineCor=True,
156 runGain=True, wireGain=True)
157other_cal.pre_collector_path = correct_for_others
158other_cal.depends_on(momentum_cal)
159other_cal.depends_on(cosine_cal)
160other_cal.depends_on(wire_gain_cal)
161other_cal.depends_on(run_gain_cal)
162
163
164# Create a CAF instance and add calibrations
165caf_fw = CAF()
166caf_fw.add_calibration(momentum_cal)
167caf_fw.add_calibration(cosine_cal)
168caf_fw.add_calibration(wire_gain_cal)
169caf_fw.add_calibration(run_gain_cal)
170caf_fw.add_calibration(other_cal)
171
172# Run the calibration
173caf_fw.run() # Creates local database files when finished (no auto upload)