16from ROOT
import Belle2
17from ROOT
import gSystem
18from generators
import add_cosmics_generator
21gSystem.Load(
'libtracking')
22gSystem.Load(
'libtracking_trackFindingCDC')
29 path = basf2.create_path()
32 path.add_module(
'EventInfoSetter',
38 path.add_module(
'Progress')
41 gearbox_module = path.add_module(
'Gearbox')
44 geometry_module = path.add_module(
'Geometry')
48 cdc_top_geometry =
False
50 gearbox_module.param(dict(fileName=
"geometry/CDCcosmicTests.xml"))
55 gearbox_module.param(dict(overrideMultiple=[
57 (
"/DetectorComponent[@name='MagneticField']//Component/Z",
"0",
""),
63 geometry_module.param(dict(components=[
"CDC"],))
65 gearbox_module.param(dict(
69 (
"/Global/length",
"8.",
"m"),
70 (
"/Global/width",
"8.",
"m"),
71 (
"/Global/height",
"1.5",
"m"),
74 (
"/DetectorComponent[@name='CDC']//t0FileName",
"t0.dat",
""),
75 (
"/DetectorComponent[@name='CDC']//xtFileName",
"xt_noB_v1.dat",
""),
77 (
"/DetectorComponent[@name='CDC']//GlobalPhiRotation",
"1.875",
"deg"),
84 generator_module =
"cosmics"
87 if generator_module ==
"cry":
88 add_cosmics_generator(path, accept_box=[0.5, 0.5, 0.5], keep_box=[0.5, 0.5, 0.5])
90 elif generator_module ==
"cosmics":
91 path.add_module(
"Cosmics",
98 elif generator_module ==
"particle_gun":
105 phiBounds = [240 + 60.0 * sector % 360.0, 300 + 60.0 * sector % 360.0]
107 path.add_module(
"ParticleGun",
108 pdgCodes=[muon_pdg_code, -muon_pdg_code],
111 momentumGeneration=
'uniform',
112 momentumParams=[2.0, 4.0],
113 phiGeneration=
'uniform',
115 thetaGeneration=
'uniform',
116 thetaParams=[70., 110.])
119 raise ValueError(
"Unknown generator module key " + generator_module)
129 use_tof_relative_to_trigger_plane =
True
130 use_tof_relative_to_trigger_point =
not use_tof_relative_to_trigger_plane
131 if use_tof_relative_to_trigger_plane:
133 elif use_tof_relative_to_trigger_point:
137 use_cry_generator = generator_module ==
"cry"
139 path.add_module(
'CDCCosmicSelector',
151 cryGenerator=use_cry_generator,
155 path.add_module(
'FullSim',
156 ProductionCut=1000000.
159 path.add_module(
'CDCDigitizer',
162 AddTimeOfFlight=
True,
163 AddInWirePropagationDelay=
True,
164 CorrectForWireSag=
True,
167 tracking.add_cdc_cr_track_finding(path,
168 trigger_point=(0.3744, 0, -1.284),
175 if use_tof_relative_to_trigger_plane:
176 path.add_module(
"PlaneTriggerTrackTimeEstimator",
177 triggerPlanePosition=[0.3744, 0, -1.284],
178 triggerPlaneDirection=[0, 1, 0],
179 useFittedInformation=
False)
181 path.add_module(
"SetupGenfitExtrapolation")
182 path.add_module(
"DAFRecoFitter")
185 @save_pull_analysis(part_name="time", aux_names=["wire_idx", ], groupby=["layer_sidx"], outlier_z_score=3,)
186 @save_pull_analysis(part_name="time", aux_names=["layer_sidx", "time_truth", ], outlier_z_score=3,)
187 @save_pull_analysis(part_name="drift_length", aux_names=["layer_sidx", ], outlier_z_score=3,)
188 @save_tree(name="tree")
189 @harvest(foreach="RecoTracks", show_results=True)
190 def harvest_cdc_cr(reco_track):
191 fit_status = reco_track.getTrackFitStatus()
192 if not fit_status
or not fit_status.isFitConverged():
195 track_points = reco_track.getHitPointsWithMeasurement()
196 for track_point
in track_points:
197 kalman_fitter_info = track_point.getKalmanFitterInfo()
199 measurement_on_plane = kalman_fitter_info.getFittedState()
200 except BaseException:
204 abs_measurement = track_point.getRawMeasurement(0)
205 daf_weight = kalman_fitter_info.getWeights().at(0)
206 cdc_hit = abs_measurement.getCDCHit()
208 layer_cidx = wire_id.getICLayer()
209 wire_idx = wire_id.getIWire()
210 cdc_sim_hit = cdc_hit.getRelated(
"CDCSimHits")
212 fit_data = get_fit_data(measurement_on_plane)
214 flight_time = fit_data[
"flight_time_estimate"]
215 drift_time = DriftTimeUtil.getDriftTime(fit_data[
"drift_length_estimate"],
218 fit_data[
"alpha_estimate"],
219 fit_data[
"theta_estimate"],
222 prop_time = DriftTimeUtil.getPropTime(wire_id, fit_data[
"z_estimate"])
223 time_walk = DriftTimeUtil.getTimeWalk(wire_id, cdc_hit.getADCCount())
225 reco_time = flight_time + drift_time + prop_time + time_walk
227 measured_time = DriftTimeUtil.getMeasuredTime(wire_id, cdc_hit.getTDCCount(), smear)
230 flight_time_truth = cdc_sim_hit.getFlightTime()
231 drift_length_truth = cdc_sim_hit.getDriftLength()
232 incoming_arm = -1
if flight_time_truth < 0
else 1
234 if drift_time > 1000:
237 if drift_length_truth < 0.1
or drift_length_truth > 0.5:
242 yield dict(drift_length_estimate=fit_data[
"drift_length_estimate"],
243 drift_length_variance=fit_data[
"drift_length_variance"],
244 drift_length_truth=drift_length_truth,
245 time_truth=reco_time,
246 time_estimate=measured_time,
247 time_delta=reco_time - measured_time,
249 flight_time_estimate=flight_time,
250 drift_time_estimate=drift_time,
251 prop_time_estimate=prop_time,
252 time_walk_estimate=time_walk,
254 rl_estimate=fit_data[
"rl"],
255 alpha_estimate=fit_data[
"alpha_estimate"],
256 theta_estimate=fit_data[
"theta_estimate"],
257 daf_weight=daf_weight,
258 flight_time_truth=flight_time_truth,
259 incoming_arm=incoming_arm,
260 layer_sidx=incoming_arm * layer_cidx,
262 tdc=cdc_hit.getTDCCount(),
265 path.add_module(harvest_cdc_cr)
268 @save_pull_analysis(part_name="flight_time", groupby=[None, "incoming_arm"], outlier_z_score=5,)
269 @save_tree(name="tree")
270 @harvest(foreach="RecoTracks", show_results=True)
271 def harvest_flight_times(reco_track):
272 track_points = reco_track.getHitPointsWithMeasurement()
273 for track_point
in track_points:
274 kalman_fitter_info = track_point.getKalmanFitterInfo()
276 measurement_on_plane = kalman_fitter_info.getFittedState()
277 except BaseException:
280 abs_measurement = track_point.getRawMeasurement(0)
281 cdc_hit = abs_measurement.getCDCHit()
282 cdc_sim_hit = cdc_hit.getRelated(
"CDCSimHits")
284 flight_time_estimate = measurement_on_plane.getTime()
285 flight_time_truth = cdc_sim_hit.getFlightTime()
286 incoming_arm = flight_time_truth < 0
288 yield dict(flight_time_estimate=flight_time_estimate,
289 flight_time_truth=flight_time_truth,
290 incoming_arm=incoming_arm)
295 basf2.print_path(path)
299 print(basf2.statistics)
304def get_fit_data(measurement_on_plane):
305 flight_time = measurement_on_plane.getTime()
306 pos = measurement_on_plane.getPos()
307 mom = measurement_on_plane.getMom()
308 wirepos = measurement_on_plane.getPlane().getO()
309 alpha = wirepos.DeltaPhi(mom)
312 state_on_plane = measurement_on_plane.getState()
313 cov_on_plane = measurement_on_plane.getCov()
316 drift_length = abs(state_on_plane(3))
317 drift_length_var = abs(cov_on_plane(3, 3))
318 rl_sign = 1
if state_on_plane(3) > 0
else -1
319 rl = 1
if state_on_plane(3) > 0
else 0
321 return dict(flight_time_estimate=flight_time,
328 wire_x_estimate=wirepos.X(),
329 wire_y_estimate=wirepos.Y(),
330 wire_z_estimate=wirepos.Z(),
331 alpha_estimate=alpha,
332 theta_estimate=theta,
333 drift_length_estimate=drift_length,
334 drift_length_variance=drift_length_var,
340if __name__ ==
"__main__":
Class to identify a wire inside the CDC.
Structure to expose some drift time and length functions from the CDCGeometryPar to Python.