Belle II Software  release-08-01-10
fitValidation.py
1 
8 
9 from tracking import modules
10 from tracking.run.event_generation import StandardEventGenerationRun
11 import sys
12 import logging
13 from tracking.harvest import refiners
14 from tracking.harvest.harvesting import HarvestingModule
15 import ROOT
16 from ROOT import Belle2
17 
18 from ROOT import gSystem
19 gSystem.Load('libtracking')
20 gSystem.Load('libtracking_trackFindingCDC')
21 
22 
24  """Validate the track fit"""
25 
26  def __init__(
27  self,
28  mc_track_cands_store_array_name,
29  legendre_track_cand_store_array_name,
30  output_file_name):
31  """Constructor"""
32  super(
33  FitValidationModule,
34  self).__init__(
35  foreach=legendre_track_cand_store_array_name,
36  output_file_name=output_file_name)
37 
38 
39  self.mc_track_cands_store_array_namemc_track_cands_store_array_name = mc_track_cands_store_array_name
40 
41  self.legendre_track_cand_store_array_namelegendre_track_cand_store_array_name = legendre_track_cand_store_array_name
42 
43 
45 
46  self.fast_fitterfast_fitter = Belle2.TrackFindingCDC.TrackFitter()
47 
48  def prepare(self):
49  """ Initialize the harvester"""
50 
51  self.cdcHitscdcHits = Belle2.PyStoreArray("CDCHits")
52  return HarvestingModule.prepare(self)
53 
54  def peel(self, legendre_track_cand):
55  """Aggregate the track and MC information for track-fit validation"""
56 
57  cdc_hit_store_array = self.cdcHitscdcHits
58 
59  # observations_variance = Belle2.TrackFindingCDC.CDCObservations2D()
61  hits = ROOT.std.vector("Belle2::TrackFindingCDC::TrackHit*")()
62 
63  cdc_hit_ids = legendre_track_cand.getHitIDs(Belle2.Const.CDC)
64  for cdc_hit_id in cdc_hit_ids:
65  cdc_hit = cdc_hit_store_array[cdc_hit_id]
66 
67  # We will only use the axial hits here as the FastFit can only process axial hits too
68  if cdc_hit.getISuperLayer() % 2 == 0:
69  cdc_wire_hit = Belle2.TrackFindingCDC.CDCWireHit(cdc_hit)
70 
71  wireRefPos2D = cdc_wire_hit.getRefPos2D()
72  drift_length = cdc_wire_hit.getRefDriftLength()
73  observations.append(wireRefPos2D.x(), wireRefPos2D.y(), 0, 1 / abs(drift_length))
74  hits.push_back(Belle2.TrackFindingCDC.TrackHit(cdc_wire_hit))
75 
76  # Viktors method
77  track_par = ROOT.std.pair("double, double")()
78  ref_point = ROOT.std.pair("double, double")()
79  # Careful: viktors result is a reduced chi2
80  viktor_chi2 = self.fast_fitterfast_fitter.fitTrackCandidateFast(hits, track_par, ref_point, False) * (hits.size() - 4)
81 
82  # Riemann without drift variances
84  self.circle_fittercircle_fitter.update(trajectory2D, observations)
85  riemann_chi2 = trajectory2D.getChi2()
86 
87  return_dict = dict(
88  riemann_chi2=riemann_chi2,
89  viktor_chi2=viktor_chi2,
90  )
91 
92  return return_dict
93 
94 
96  save_tree = refiners.save_tree(folder_name="tree")
97 
98 
100  """Read generated events or generate new events, simulate, fit the tracks and validate"""
101 
102  def create_path(self):
103  """Create and populate the basf2 path"""
104 
105  main_path = super(FitValidation, self).create_path()
106 
107  main_path.add_module("TFCDC_WireHitPreparer")
108 
109  main_path.add_module(modules.CDCMCFinder())
110 
111  main_path.add_module(FitValidationModule(mc_track_cands_store_array_name="MCTrackCands",
112  legendre_track_cand_store_array_name="MCTrackCands",
113  output_file_name="fit_validation.root"))
114 
115  return main_path
116 
117 
118 def main():
119  run = FitValidation()
120  run.configure_and_execute_from_commandline()
121 
122 
123 if __name__ == "__main__":
124  logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='%(levelname)s:%(message)s')
125  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
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:91