2 from ROOT
import Belle2
3 from ROOT
import gSystem
4 from generators
import add_cosmics_generator
7 gSystem.Load(
'libtracking')
8 gSystem.Load(
'libtracking_trackFindingCDC')
23 path = basf2.create_path()
26 path.add_module(
'EventInfoSetter',
32 path.add_module(
'Progress')
35 gearbox_module = path.add_module(
'Gearbox')
38 geometry_module = path.add_module(
'Geometry')
42 cdc_top_geometry =
False
44 gearbox_module.param(dict(fileName=
"geometry/CDCcosmicTests.xml"))
49 gearbox_module.param(dict(overrideMultiple=[
51 (
"/DetectorComponent[@name='MagneticField']//Component/Z",
"0",
""),
57 geometry_module.param(dict(components=[
"CDC"],))
59 gearbox_module.param(dict(
63 (
"/Global/length",
"8.",
"m"),
64 (
"/Global/width",
"8.",
"m"),
65 (
"/Global/height",
"1.5",
"m"),
68 (
"/DetectorComponent[@name='CDC']//t0FileName",
"t0.dat",
""),
69 (
"/DetectorComponent[@name='CDC']//xtFileName",
"xt_noB_v1.dat",
""),
71 (
"/DetectorComponent[@name='CDC']//GlobalPhiRotation",
"1.875",
"deg"),
78 generator_module =
"cosmics"
81 if generator_module ==
"cry":
82 add_cosmics_generator(path, accept_box=[0.5, 0.5, 0.5], keep_box=[0.5, 0.5, 0.5])
84 elif generator_module ==
"cosmics":
85 path.add_module(
"Cosmics",
92 elif generator_module ==
"particle_gun":
99 phiBounds = [240 + 60.0 * sector % 360.0, 300 + 60.0 * sector % 360.0]
101 path.add_module(
"ParticleGun",
102 pdgCodes=[muon_pdg_code, -muon_pdg_code],
105 momentumGeneration=
'uniform',
106 momentumParams=[2.0, 4.0],
107 phiGeneration=
'uniform',
109 thetaGeneration=
'uniform',
110 thetaParams=[70., 110.])
113 raise ValueError(
"Unknown generator module key " + generator_module)
123 use_tof_relative_to_trigger_plane =
True
124 use_tof_relative_to_trigger_point =
not use_tof_relative_to_trigger_plane
125 if use_tof_relative_to_trigger_plane:
127 elif use_tof_relative_to_trigger_point:
131 use_cry_generator = generator_module ==
"cry"
133 path.add_module(
'CDCCosmicSelector',
145 cryGenerator=use_cry_generator,
149 path.add_module(
'FullSim',
150 ProductionCut=1000000.
153 path.add_module(
'CDCDigitizer',
156 AddTimeOfFlight=
True,
157 AddInWirePropagationDelay=
True,
158 CorrectForWireSag=
True,
161 tracking.add_cdc_cr_track_finding(path,
162 trigger_point=(0.3744, 0, -1.284),
169 if use_tof_relative_to_trigger_plane:
170 path.add_module(
"PlaneTriggerTrackTimeEstimator",
171 triggerPlanePosition=[0.3744, 0, -1.284],
172 triggerPlaneDirection=[0, 1, 0],
173 useFittedInformation=
False)
175 path.add_module(
"SetupGenfitExtrapolation")
176 path.add_module(
"DAFRecoFitter")
179 @save_pull_analysis(part_name=
"time", aux_names=[
"wire_idx", ], groupby=[
"layer_sidx"], outlier_z_score=3,)
180 @save_pull_analysis(part_name=
"time", aux_names=[
"layer_sidx",
"time_truth", ], outlier_z_score=3,)
181 @save_pull_analysis(part_name=
"drift_length", aux_names=[
"layer_sidx", ], outlier_z_score=3,)
182 @save_tree(name=
"tree")
183 @harvest(foreach=
"RecoTracks", show_results=
True)
184 def harvest_cdc_cr(reco_track):
185 fit_status = reco_track.getTrackFitStatus()
186 if not fit_status
or not fit_status.isFitConverged():
189 track_points = reco_track.getHitPointsWithMeasurement()
190 for track_point
in track_points:
191 kalman_fitter_info = track_point.getKalmanFitterInfo()
193 measurement_on_plane = kalman_fitter_info.getFittedState()
198 abs_measurement = track_point.getRawMeasurement(0)
199 daf_weight = kalman_fitter_info.getWeights().at(0)
200 cdc_hit = abs_measurement.getCDCHit()
202 layer_cidx = wire_id.getICLayer()
203 wire_idx = wire_id.getIWire()
204 cdc_sim_hit = cdc_hit.getRelated(
"CDCSimHits")
206 fit_data = get_fit_data(measurement_on_plane)
208 flight_time = fit_data[
"flight_time_estimate"]
209 drift_time = DriftTimeUtil.getDriftTime(fit_data[
"drift_length_estimate"],
212 fit_data[
"alpha_estimate"],
213 fit_data[
"theta_estimate"],
216 prop_time = DriftTimeUtil.getPropTime(wire_id, fit_data[
"z_estimate"])
217 time_walk = DriftTimeUtil.getTimeWalk(wire_id, cdc_hit.getADCCount())
219 reco_time = flight_time + drift_time + prop_time + time_walk
221 measured_time = DriftTimeUtil.getMeasuredTime(wire_id, cdc_hit.getTDCCount(), smear)
224 flight_time_truth = cdc_sim_hit.getFlightTime()
225 drift_length_truth = cdc_sim_hit.getDriftLength()
226 incoming_arm = -1
if flight_time_truth < 0
else 1
228 if drift_time > 1000:
231 if drift_length_truth < 0.1
or drift_length_truth > 0.5:
236 yield dict(drift_length_estimate=fit_data[
"drift_length_estimate"],
237 drift_length_variance=fit_data[
"drift_length_variance"],
238 drift_length_truth=drift_length_truth,
239 time_truth=reco_time,
240 time_estimate=measured_time,
241 time_delta=reco_time - measured_time,
243 flight_time_estimate=flight_time,
244 drift_time_estimate=drift_time,
245 prop_time_estimate=prop_time,
246 time_walk_estimate=time_walk,
248 rl_estimate=fit_data[
"rl"],
249 alpha_estimate=fit_data[
"alpha_estimate"],
250 theta_estimate=fit_data[
"theta_estimate"],
251 daf_weight=daf_weight,
252 flight_time_truth=flight_time_truth,
253 incoming_arm=incoming_arm,
254 layer_sidx=incoming_arm * layer_cidx,
256 tdc=cdc_hit.getTDCCount(),
259 path.add_module(harvest_cdc_cr)
262 @save_pull_analysis(part_name=
"flight_time", groupby=[
None,
"incoming_arm"], outlier_z_score=5,)
263 @save_tree(name=
"tree")
264 @harvest(foreach=
"RecoTracks", show_results=
True)
265 def harvest_flight_times(reco_track):
266 track_points = reco_track.getHitPointsWithMeasurement()
267 for track_point
in track_points:
268 kalman_fitter_info = track_point.getKalmanFitterInfo()
270 measurement_on_plane = kalman_fitter_info.getFittedState()
274 abs_measurement = track_point.getRawMeasurement(0)
275 cdc_hit = abs_measurement.getCDCHit()
276 cdc_sim_hit = cdc_hit.getRelated(
"CDCSimHits")
278 flight_time_estimate = measurement_on_plane.getTime()
279 flight_time_truth = cdc_sim_hit.getFlightTime()
280 incoming_arm = flight_time_truth < 0
282 yield dict(flight_time_estimate=flight_time_estimate,
283 flight_time_truth=flight_time_truth,
284 incoming_arm=incoming_arm)
289 basf2.print_path(path)
293 print(basf2.statistics)
298 def get_fit_data(measurement_on_plane):
299 flight_time = measurement_on_plane.getTime()
300 pos = measurement_on_plane.getPos()
301 mom = measurement_on_plane.getMom()
302 wirepos = measurement_on_plane.getPlane().getO()
303 alpha = wirepos.DeltaPhi(mom)
306 state_on_plane = measurement_on_plane.getState()
307 cov_on_plane = measurement_on_plane.getCov()
310 drift_length = abs(state_on_plane(3))
311 drift_length_var = abs(cov_on_plane(3, 3))
312 rl_sign = 1
if state_on_plane(3) > 0
else -1
313 rl = 1
if state_on_plane(3) > 0
else 0
315 return dict(flight_time_estimate=flight_time,
322 wire_x_estimate=wirepos.X(),
323 wire_y_estimate=wirepos.Y(),
324 wire_z_estimate=wirepos.Z(),
325 alpha_estimate=alpha,
326 theta_estimate=theta,
327 drift_length_estimate=drift_length,
328 drift_length_variance=drift_length_var,
334 if __name__ ==
"__main__":