18from ROOT
import Belle2
20from ROOT
import gROOT, addressof
29 ''' shift digits in time by timeShift'''
32 ''' event processing '''
36 digit.setTime(digit.getTime() + timeShift)
39gROOT.ProcessLine(
'struct TreeStruct {\
40 int slot; /* slot number */ \
41 int nfot; /* number of photons in the slot */ \
42 int pdg; /* PDG code from barHit */ \
43 float x; /* local x from barHit */ \
44 float y; /* local y from barHit */ \
45 float z; /* local z from barHit */ \
46 float t; /* time from barHit */ \
47 float p; /* momentum from barHit */ \
48 float theta; /* momentum theta [deg] from barHit */ \
49 float phi; /* momentum local phi [deg] from barHit */ \
50 float dx; /* extHit - barHit difference in local x */ \
51 float dy; /* extHit - barHit difference in local y */ \
52 float dz; /* extHit - barHit difference in local z */ \
53 float dt; /* extHit - barHit difference in time */ \
54 float dp; /* extHit - barHit difference in momentum */ \
55 float dtheta; /* extHit - barHit difference in theta [deg] */ \
56 float dphi; /* extHit - barHit difference in local phi [deg] */ \
57 float t0; /* t0 determined by TOPCosmicT0Finder */ \
58 float t0err; /* error on t0 */ \
59 float timeShift; /* time shift applied to TOPDigits */ \
60 float dt0; /* difference: dt + t0 - timeShift */ \
63from ROOT
import TreeStruct
67 ''' makes ntuple for MC studies of TOPCosmicT0Finder performance '''
73 self.
file = ROOT.TFile(
'cosmicT0FinderNtuple.root',
'recreate')
75 self.
tree = ROOT.TTree(
'tree',
'')
79 for key
in TreeStruct.__dict__.keys():
82 if isinstance(self.
data.__getattribute__(key), int):
84 self.
tree.Branch(key, addressof(self.
data, key), key + formstring)
87 self.
reso = TH1F(
'reso',
'T0 residuals', 200, -1.0, 1.0)
88 self.
reso.SetXTitle(
'#Delta t0 [ns]')
90 self.
pull = TH1F(
'pull',
'T0 pulls', 200, -10.0, 10.0)
93 ''' event processing: fill ntuple and histograms '''
98 for timeZero
in timeZeros:
99 extHit = timeZero.getRelated(
'ExtHits')
101 b2.B2WARNING(
'no related extHits')
104 for barhit
in mcParticles[0].getRelationsWith(
'TOPBarHits'):
105 if barhit.getModuleID() == extHit.getCopyID():
108 b2.B2WARNING(
'no corresponding TOPBarHit')
111 moduleID = timeZero.getModuleID()
112 if extHit.getCopyID() != moduleID:
113 b2.B2ERROR(
'moduleID in extHit differs: ' + str(extHit.getCopyID()) +
115 if barHit.getModuleID() != moduleID:
116 b2.B2ERROR(
'moduleID in barHit differs: ' + str(barHit.getModuleID()) +
119 self.
data.slot = moduleID
120 self.
data.nfot = timeZero.getNumPhotons()
121 self.
data.pdg = barHit.getPDG()
122 pos = barHit.getLocalPosition()
123 self.
data.x = pos.X()
124 self.
data.y = pos.Y()
125 self.
data.z = pos.Z()
126 self.
data.t = barHit.getTime()
127 module = geo.getModule(moduleID)
128 mom = module.momentumToLocal(barHit.getMomentum())
129 self.
data.p = mom.R()
130 self.
data.theta = math.degrees(mom.Theta())
131 self.
data.phi = math.degrees(mom.Phi())
132 dr = module.momentumToLocal(extHit.getPosition() - XYZVector(barHit.getPosition()))
133 self.
data.dx = dr.X()
134 self.
data.dy = dr.Y()
135 self.
data.dz = dr.Z()
136 self.
data.dt = extHit.getTOF() - self.
data.t
137 momExt = module.momentumToLocal(extHit.getMomentum())
138 self.
data.dp = momExt.R() - self.
data.p
139 self.
data.dtheta = math.degrees(momExt.Theta()) - self.
data.theta
140 self.
data.dphi = math.degrees(momExt.Phi()) - self.
data.phi
141 self.
data.t0 = timeZero.getTime()
142 self.
data.t0err = timeZero.getError()
143 self.
data.timeShift = timeShift
149 if timeZero.getChi2().GetEntries() > 0:
150 timeZero.getChi2().Write()
151 timeZero.getPDF().Write()
152 timeZero.getHits().Write()
155 ''' terminate: write and close root file '''
163b2.set_log_level(b2.LogLevel.WARNING)
166main = b2.create_path()
169roinput = b2.register_module(
'RootInput')
170main.add_module(roinput)
173main.add_module(
'TOPGeometryParInitializer')
179finder = b2.register_module(
'TOPCosmicT0Finder')
180finder.param(
'useIncomingTrack',
False)
182main.add_module(finder)
188main.add_module(
'Progress')
A (simplified) python wrapper for StoreArray.
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
data
data structure to be written to tree
reso
histogram of t0 residuals
pull
histogram of t0 pulls