Belle II Software development
fitValidation.py
1
8
9from tracking import modules
10from tracking.run.event_generation import StandardEventGenerationRun
11import sys
12import logging
13from tracking.harvest import refiners
14from tracking.harvest.harvesting import HarvestingModule
15import ROOT
16from ROOT import Belle2
17
18from ROOT import gSystem
19gSystem.Load('libtracking')
20gSystem.Load('libtracking_trackFindingCDC')
21
22
24 """Validate the track fit"""
25
27 self,
28 mc_track_cands_store_array_name,
29 legendre_track_cand_store_array_name,
30 output_file_name):
31 """Constructor"""
32 super().__init__(
33 foreach=legendre_track_cand_store_array_name,
34 output_file_name=output_file_name)
35
36
37 self.mc_track_cands_store_array_name = mc_track_cands_store_array_name
38
39 self.legendre_track_cand_store_array_name = legendre_track_cand_store_array_name
40
41
43
44 self.fast_fitter = Belle2.TrackFindingCDC.TrackFitter()
45
46 def prepare(self):
47 """ Initialize the harvester"""
48
49 self.cdcHits = Belle2.PyStoreArray("CDCHits")
50 return HarvestingModule.prepare(self)
51
52 def peel(self, legendre_track_cand):
53 """Aggregate the track and MC information for track-fit validation"""
54
55 cdc_hit_store_array = self.cdcHits
56
57 # observations_variance = Belle2.TrackFindingCDC.CDCObservations2D()
59 hits = ROOT.std.vector("Belle2::TrackFindingCDC::TrackHit*")()
60
61 cdc_hit_ids = legendre_track_cand.getHitIDs(Belle2.Const.CDC)
62 for cdc_hit_id in cdc_hit_ids:
63 cdc_hit = cdc_hit_store_array[cdc_hit_id]
64
65 # We will only use the axial hits here as the FastFit can only process axial hits too
66 if cdc_hit.getISuperLayer() % 2 == 0:
67 cdc_wire_hit = Belle2.TrackFindingCDC.CDCWireHit(cdc_hit)
68
69 wireRefPos2D = cdc_wire_hit.getRefPos2D()
70 drift_length = cdc_wire_hit.getRefDriftLength()
71 observations.append(wireRefPos2D.x(), wireRefPos2D.y(), 0, 1 / abs(drift_length))
72 hits.push_back(Belle2.TrackFindingCDC.TrackHit(cdc_wire_hit))
73
74 # Viktors method
75 track_par = ROOT.std.pair("double, double")()
76 ref_point = ROOT.std.pair("double, double")()
77 # Careful: viktors result is a reduced chi2
78 viktor_chi2 = self.fast_fitter.fitTrackCandidateFast(hits, track_par, ref_point, False) * (hits.size() - 4)
79
80 # Riemann without drift variances
82 self.circle_fitter.update(trajectory2D, observations)
83 riemann_chi2 = trajectory2D.getChi2()
84
85 return_dict = dict(
86 riemann_chi2=riemann_chi2,
87 viktor_chi2=viktor_chi2,
88 )
89
90 return return_dict
91
92
94 save_tree = refiners.save_tree(folder_name="tree")
95
96
98 """Read generated events or generate new events, simulate, fit the tracks and validate"""
99
100 def create_path(self):
101 """Create and populate the basf2 path"""
102
103 main_path = super().create_path()
104
105 main_path.add_module("TFCDC_WireHitPreparer")
106
107 main_path.add_module(modules.CDCMCFinder())
108
109 main_path.add_module(FitValidationModule(mc_track_cands_store_array_name="MCTrackCands",
110 legendre_track_cand_store_array_name="MCTrackCands",
111 output_file_name="fit_validation.root"))
112
113 return main_path
114
115
116def main():
117 run = FitValidation()
118 run.configure_and_execute_from_commandline()
119
120
121if __name__ == "__main__":
122 logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='%(levelname)s:%(message)s')
123 main()
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
Class serving as a storage of observed drift circles to present to the Riemann fitter.
static const CDCRiemannFitter & getFitter()
Static getter for a general Riemann fitter.
Particle trajectory as it is seen in xy projection represented as a circle.
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:55
mc_track_cands_store_array_name
cached name of the MCTrackCands StoreArray
circle_fitter
Use the Riemann fitter for circles.
fast_fitter
Use the standard track fitter for speed.
def __init__(self, mc_track_cands_store_array_name, legendre_track_cand_store_array_name, output_file_name)
def peel(self, legendre_track_cand)
legendre_track_cand_store_array_name
cached name of the LegendreTrackCands StoreArray
cdcHits
cached name of the CDCHits StoreArray
Definition: main.py:1