Belle II Software development
ecl_utils.py
1
8
9"""
10Python utilities for the ECL.
11"""
12
13import basf2 as b2
14
15
16class ECLDumpGeometry(b2.Module):
17 """Print the location and direction of the axis of every ECL crystal, once.
18
19 The numbers come from ECL::ECLGeometryPar, i.e. from the
20 ECLCrystalsShapeAndPosition payload valid for the experiment and run being
21 processed, so the geometry has to be built by the Gearbox and Geometry modules
22 first.
23
24 The table is printed in the first event, because the crystal positions are
25 read from a conditions payload and are therefore only known once the run is
26 started.
27 """
28
29 def __init__(self):
30 """Constructor: load the ECL library and look up the number of crystals."""
31 super().__init__()
32 self.set_name("ECLDumpGeometry")
33
34 import ROOT
35 ROOT.gSystem.Load("libecl.so")
36 ROOT.gInterpreter.Declare("#include <ecl/dataobjects/ECLElementNumbers.h>")
37
38
39 self.root = ROOT
40
41 self.n_crystals = ROOT.Belle2.ECLElementNumbers.c_NCrystals
42
43 self.first_event = True
44
45 def event(self):
46 """Print the table of crystal positions in the first event."""
47 if not self.first_event:
48 return
49 self.first_event = False
50
52 print("\nLocation and direction of the axis of each ECL crystal")
53 print("cellID x [cm] y [cm] z [cm] axisTheta axisPhi [rad]")
54 for cell_id in range(1, self.n_crystals + 1):
55 position = geometry.GetCrystalPos(cell_id - 1)
56 direction = geometry.GetCrystalVec(cell_id - 1)
57 print(f"{cell_id:6d} {position.X():9.4f} {position.Y():9.4f} {position.Z():9.4f} "
58 f"{direction.Theta():9.6f} {direction.Phi():9.6f}")
59 print("\n")
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
bool first_event
print the geometry in the first event only
Definition ecl_utils.py:43
n_crystals
number of ECL crystals; cellID runs from 1 to this value
Definition ecl_utils.py:41
root
ROOT module, kept so that event() does not have to import it again.
Definition ecl_utils.py:39