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