19 from ROOT
import Belle2
21 from ROOT
import gROOT, addressof
30 ''' shift digits in time by timeShift'''
33 ''' event processing '''
37 digit.setTime(digit.getTime() + timeShift)
40 gROOT.ProcessLine(
'struct TreeStruct {\
41 int slot; /* slot number */ \
42 int nfot; /* number of photons in the slot */ \
43 int pdg; /* PDG code from barHit */ \
44 float x; /* local x from barHit */ \
45 float y; /* local y from barHit */ \
46 float z; /* local z from barHit */ \
47 float t; /* time from barHit */ \
48 float p; /* momentum from barHit */ \
49 float theta; /* momentum theta [deg] from barHit */ \
50 float phi; /* momentum local phi [deg] from barHit */ \
51 float dx; /* extHit - barHit difference in local x */ \
52 float dy; /* extHit - barHit difference in local y */ \
53 float dz; /* extHit - barHit difference in local z */ \
54 float dt; /* extHit - barHit difference in time */ \
55 float dp; /* extHit - barHit difference in momentum */ \
56 float dtheta; /* extHit - barHit difference in theta [deg] */ \
57 float dphi; /* extHit - barHit difference in local phi [deg] */ \
58 float t0; /* t0 determined by TOPCosmicT0Finder */ \
59 float t0err; /* error on t0 */ \
60 float timeShift; /* time shift applied to TOPDigits */ \
61 float dt0; /* difference: dt + t0 - timeShift */ \
64 from ROOT
import TreeStruct
68 ''' makes ntuple for MC studies of TOPCosmicT0Finder performance '''
74 self.
filefile = ROOT.TFile(
'cosmicT0FinderNtuple.root',
'recreate')
76 self.
treetree = ROOT.TTree(
'tree',
'')
78 self.
datadata = TreeStruct()
80 for key
in TreeStruct.__dict__.keys():
83 if isinstance(self.
datadata.__getattribute__(key), int):
85 self.
treetree.Branch(key, addressof(self.
datadata, key), key + formstring)
88 self.
resoreso = TH1F(
'reso',
'T0 residuals', 200, -1.0, 1.0)
89 self.
resoreso.SetXTitle(
'#Delta t0 [ns]')
91 self.
pullpull = TH1F(
'pull',
'T0 pulls', 200, -10.0, 10.0)
94 ''' event processing: fill ntuple and histograms '''
99 for timeZero
in timeZeros:
100 extHit = timeZero.getRelated(
'ExtHits')
102 b2.B2WARNING(
'no related extHits')
105 for barhit
in mcParticles[0].getRelationsWith(
'TOPBarHits'):
106 if barhit.getModuleID() == extHit.getCopyID():
109 b2.B2WARNING(
'no corresponding TOPBarHit')
112 moduleID = timeZero.getModuleID()
113 if extHit.getCopyID() != moduleID:
114 b2.B2ERROR(
'moduleID in extHit differs: ' + str(extHit.getCopyID()) +
116 if barHit.getModuleID() != moduleID:
117 b2.B2ERROR(
'moduleID in barHit differs: ' + str(barHit.getModuleID()) +
120 self.
datadata.slot = moduleID
121 self.
datadata.nfot = timeZero.getNumPhotons()
122 self.
datadata.pdg = barHit.getPDG()
123 pos = barHit.getLocalPosition()
124 self.
datadata.x = pos.X()
125 self.
datadata.y = pos.Y()
126 self.
datadata.z = pos.Z()
127 self.
datadata.t = barHit.getTime()
128 module = geo.getModule(moduleID)
129 mom = module.momentumToLocal(barHit.getMomentum())
130 self.
datadata.p = mom.R()
131 self.
datadata.theta = math.degrees(mom.Theta())
132 self.
datadata.phi = math.degrees(mom.Phi())
133 dr = module.momentumToLocal(extHit.getPosition() - XYZVector(barHit.getPosition()))
134 self.
datadata.dx = dr.X()
135 self.
datadata.dy = dr.Y()
136 self.
datadata.dz = dr.Z()
137 self.
datadata.dt = extHit.getTOF() - self.
datadata.t
138 momExt = module.momentumToLocal(extHit.getMomentum())
139 self.
datadata.dp = momExt.R() - self.
datadata.p
140 self.
datadata.dtheta = math.degrees(momExt.Theta()) - self.
datadata.theta
141 self.
datadata.dphi = math.degrees(momExt.Phi()) - self.
datadata.phi
142 self.
datadata.t0 = timeZero.getTime()
143 self.
datadata.t0err = timeZero.getError()
144 self.
datadata.timeShift = timeShift
145 self.
datadata.dt0 = self.
datadata.dt + self.
datadata.t0 - self.
datadata.timeShift
148 self.
resoreso.Fill(self.
datadata.dt0)
149 self.
pullpull.Fill(self.
datadata.dt0/self.
datadata.t0err)
150 if timeZero.getChi2().GetEntries() > 0:
151 timeZero.getChi2().Write()
152 timeZero.getPDF().Write()
153 timeZero.getHits().Write()
156 ''' terminate: write and close root file '''
159 self.
filefile.Write()
160 self.
filefile.Close()
164 b2.set_log_level(b2.LogLevel.WARNING)
167 main = b2.create_path()
170 roinput = b2.register_module(
'RootInput')
171 main.add_module(roinput)
174 main.add_module(
'TOPGeometryParInitializer')
180 finder = b2.register_module(
'TOPCosmicT0Finder')
181 finder.param(
'useIncomingTrack',
False)
183 main.add_module(finder)
189 main.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