Belle II Software  release-06-02-00
cosmicsExtrapolationPlots.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 """
13 <header>
14  <contact>software-tracking@belle2.org</contact>
15  <input>CosmicsExtrapolation.root</input>
16  <output>CosmicsExtrapolationPlots.root</output>
17  <description>Validation of cosmic track extrapolation.</description>
18 </header>
19 """
20 
21 from ROOT import Belle2, TNamed
22 import ROOT
23 contact = 'Kirill Chilikin (chilikin@lebedev.ru)'
24 
25 
26 input_file = ROOT.TFile('../CosmicsExtrapolation.root')
27 output_file = ROOT.TFile('CosmicsExtrapolationPlots.root', 'recreate')
28 
29 bklm_numbers = Belle2.BKLMElementNumbers()
31 
32 # X resolution histogram.
33 hist_xres = ROOT.TH1F('xres', 'Extrapolated hit X resolution', 100, -20, 20)
34 hist_xres.SetXTitle('cm')
35 hist_xres.SetYTitle('Events')
36 function_list = hist_xres.GetListOfFunctions()
37 function_list.Add(TNamed('Description', 'X resolution'))
38 function_list.Add(TNamed('Check', 'No bias, resolution ~ 2 cm.'))
39 function_list.Add(TNamed('Contact', contact))
40 function_list.Add(TNamed('MetaOptions', 'shifter'))
41 # Y resolution histogram.
42 hist_yres = ROOT.TH1F('yres', 'Extrapolated hit Y resolution', 100, -20, 20)
43 hist_yres.SetXTitle('cm')
44 hist_yres.SetYTitle('Events')
45 function_list = hist_yres.GetListOfFunctions()
46 function_list.Add(TNamed('Description', 'Y resolution'))
47 function_list.Add(TNamed('Check', 'No bias, resolution ~ 2 cm.'))
48 function_list.Add(TNamed('Contact', contact))
49 function_list.Add(TNamed('MetaOptions', 'shifter'))
50 # Z resolution histogram.
51 hist_zres = ROOT.TH1F('zres', 'Extrapolated hit Z resolution', 100, -20, 20)
52 hist_zres.SetXTitle('cm')
53 hist_zres.SetYTitle('Events')
54 function_list = hist_zres.GetListOfFunctions()
55 function_list.Add(TNamed('Description', 'Z resolution'))
56 function_list.Add(TNamed('Check', 'No bias, resolution ~ 2 cm.'))
57 function_list.Add(TNamed('Contact', contact))
58 function_list.Add(TNamed('MetaOptions', 'shifter'))
59 
60 for event in input_file.tree:
61  bklmhit2ds = event.BKLMHit2ds
62  eklmhit2ds = event.EKLMHit2ds
63  exthits = event.ExtHits
64  for bklmhit2d in bklmhit2ds:
65  section = bklmhit2d.getSection()
66  sector = bklmhit2d.getSector()
67  layer = bklmhit2d.getLayer()
68  for exthit in exthits:
69  if exthit.getDetectorID() != Belle2.Const.BKLM:
70  continue
71  module = exthit.getCopyID()
72  section_ext = bklm_numbers.getSectionByModule(module)
73  sector_ext = bklm_numbers.getSectorByModule(module)
74  layer_ext = bklm_numbers.getLayerByModule(module)
75  if (section_ext != section or sector_ext != sector or
76  layer_ext != layer):
77  continue
78  ext_position = exthit.getPosition()
79  hist_xres.Fill(ext_position.X() - bklmhit2d.getGlobalPositionX())
80  hist_yres.Fill(ext_position.Y() - bklmhit2d.getGlobalPositionY())
81  hist_zres.Fill(ext_position.Z() - bklmhit2d.getGlobalPositionZ())
82  for eklmhit2d in eklmhit2ds:
83  section = eklmhit2d.getSection()
84  sector = eklmhit2d.getSector()
85  layer = eklmhit2d.getLayer()
86  for exthit in exthits:
87  if exthit.getDetectorID() != Belle2.Const.EKLM:
88  continue
89  strip_global = exthit.getCopyID()
90  section_ext = eklm_numbers.getSectionByGlobalStrip(strip_global)
91  sector_ext = eklm_numbers.getSectorByGlobalStrip(strip_global)
92  layer_ext = eklm_numbers.getLayerByGlobalStrip(strip_global)
93  if (section_ext != section or sector_ext != sector or
94  layer_ext != layer):
95  continue
96  ext_position = exthit.getPosition()
97  hist_xres.Fill(ext_position.X() - eklmhit2d.getPositionX())
98  hist_yres.Fill(ext_position.Y() - eklmhit2d.getPositionY())
99  hist_zres.Fill(ext_position.Z() - eklmhit2d.getPositionZ())
100 
101 output_file.cd()
102 hist_xres.Write()
103 hist_yres.Write()
104 hist_zres.Write()
105 output_file.Close()
106 input_file.Close()
BKLM element numbers.
static const EKLMElementNumbers & Instance()
Instantiation.