2 from ROOT
import Belle2
3 from ROOT
import TVector3
12 This class represents a dataset.
18 varnum[
"recoz"] = [0,
r'$Z_{Reco}$',
r'$[cm]$']
19 varnum[
"recotheta"] = [1,
r'$\theta_{Reco}$',
r'$[°]$']
20 varnum[
"recophi"] = [2,
r'$\phi_{Reco}$',
r'$[°]$']
21 varnum[
"recopt"] = [3,
r'$P_{t, Reco}$',
r'$[GeV]$']
22 varnum[
"recop"] = [4,
r'$P_{Reco}$',
r'$[GeV]$']
23 varnum[
"neuroz"] = [5,
r'$Z_{Neuro}$',
r'$[cm]$']
24 varnum[
"neurotheta"] = [6,
r'$\theta_{Neuro}$',
r'$[°]$']
25 varnum[
"neurophi"] = [7,
r'$\phi_{Neuro}$',
r'$[°]$']
26 varnum[
"neuropt"] = [8,
r'$P_{Neuro}$',
r'$[GeV]$']
27 varnum[
"neurop"] = [9,
r'$P_{t, Neuro}$',
r'$[GeV]$']
28 varnum[
"neuroval"] = [10,
r'Validity',
'']
29 varnum[
"neuroqual"] = [11,
r'Quality',
'']
30 varnum[
"neurots"] = [12,
r'TSVector',
'']
31 varnum[
"neuroexp"] = [13,
r'Expert Number',
'']
32 varnum[
"neurodriftth"] = [14,
r'Driftthreshold',
'']
33 varnum[
"neuroquad"] = [15,
r'Quadrant',
'']
34 varnum[
"neurofp"] = [16,
r'Fastestpriority Eventtime',
'clocks']
35 varnum[
"neuroetf"] = [17,
r'ETF Eventtime',
'clocks']
36 varnum[
"twodphi"] = [18,
r'$\phi_{2D}$',
r'$[°]$']
37 varnum[
"twodpt"] = [19,
r'$P_{t, 2D}$',
r'$[GeV]$']
38 varnum[
"twodfot"] = [20,
r'FoundOldTrack',
'']
39 varnum[
"hwneuroz"] = [21,
r'$Z_{HWNeuro}$',
r'$[cm]$']
40 varnum[
"hwneurotheta"] = [22,
r'$\theta_{HWNeuro}$',
r'$[°]$']
41 varnum[
"hwneurophi"] = [23,
r'$\phi_{HWNeuro}$',
r'$[°]$']
42 varnum[
"hwneuropt"] = [24,
r'$P_{t, HWNeuro}$',
r'$[GeV]$']
43 varnum[
"hwneurop"] = [25,
r'$P_{HWNeuro}$',
r'$[GeV]$']
44 varnum[
"hwneuroval"] = [26,
r'Validity',
'']
45 varnum[
"hwneuroqual"] = [27,
r'Quality',
'']
46 varnum[
"hwneurots"] = [28,
r'TSVector',
'']
47 varnum[
"hwneuroexp"] = [29,
r'Expert Number',
'']
48 varnum[
"hwneurodriftth"] = [30,
r'Driftthreshold',
'']
49 varnum[
"hwneuroquad"] = [31,
r'Quadrant',
'']
50 varnum[
"hwneurofp"] = [32,
r'Fastestpriority Eventtime',
'clocks']
51 varnum[
"hwneuroetf"] = [33,
r'ETF Eventtime',
'clocks']
52 varnum[
"swneuroz"] = [34,
r'$Z_{SWNeuro}$',
r'$[cm]$']
53 varnum[
"swneurotheta"] = [35,
r'$\theta_{SWNeuro}$',
r'$[°]$']
54 varnum[
"swneurophi"] = [36,
r'$\phi_{SWNeuro}$',
r'$[°]$']
55 varnum[
"swneuropt"] = [37,
r'$P_{t, SWNeuro}$',
r'$[GeV]$']
56 varnum[
"swneurop"] = [38,
r'$P_{SWNeuro}$',
r'$[GeV]$']
57 varnum[
"swneuroval"] = [39,
r'Validity',
'']
58 varnum[
"swneuroqual"] = [40,
r'Quality',
'']
59 varnum[
"swneurots"] = [41,
r'TSVector',
'']
60 varnum[
"swneuroexp"] = [42,
r'Expert Number',
'']
61 varnum[
"swneurodriftth"] = [43,
r'Driftthreshold',
'']
62 varnum[
"swneuroquad"] = [44,
r'Quadrant',
'']
63 varnum[
"swneurofp"] = [45,
r'Fastestpriority Eventtime',
'clocks']
64 varnum[
"swneuroetf"] = [46,
r'ETF Eventtime',
'clocks']
65 varnum[
"swtwodphi"] = [47,
r'$\phi_{SW2D}$',
r'$[°]$']
66 varnum[
"swtwodpt"] = [48,
r'$P_{t, SW2D}$',
r'$[GeV]$']
67 varnum[
"swtwodfot"] = [49,
r'FoundOldTrack',
'']
68 varnum[
"neuroats"] = [50,
r'NumberOfAxials',
'']
69 varnum[
"hwneuroats"] = [51,
r'NumberOfAxials',
'']
70 varnum[
"swneuroats"] = [52,
r'NumberOfAxials',
'']
71 varnum[
"neuroetfcc"] = [53,
r'ETF Eventtime from CC',
'clocks']
72 varnum[
"neurohwtime"] = [54,
r'Reconstructed HW Eventtime',
'clocks']
73 varnum[
"hwneuroetfcc"] = [55,
r'ETF Eventtime',
'clocks']
74 varnum[
"hwneurohwtime"] = [56,
r'Reconstructed HW Eventtime',
'clocks']
79 def param(self, params):
80 for key, value
in params.items():
81 setattr(self, key, value)
92 self.
datanamedataname =
"unspecified runs"
101 self.
twodtracksnametwodtracksname =
"CDCTriggerNNInput2DFinderTracks"
103 self.
etfnameetfname =
"CDCTriggerNeuroETFT0"
104 self.
tsnametsname =
"CDCTriggerNNInputSegmentHits"
143 def costotheta(self, x):
144 if isinstance(x, list):
156 return 180. / np.pi * np.arccos(x)
158 def getrecovalsold(self, evlist, fitres):
160 evlist[self.
varnumvarnumvarnum[
"recoz"][0]] = fitres.getPosition().Z()
161 evlist[self.
varnumvarnumvarnum[
"recotheta"][0]] = fitres.getMomentum().Theta()
162 evlist[self.
varnumvarnumvarnum[
"recophi"][0]] = fitres.getMomentum().Phi()
163 evlist[self.
varnumvarnumvarnum[
"recopt"][0]] = fitres.getTransverseMomentum()
164 evlist[self.
varnumvarnumvarnum[
"recop"][0]] = fitres.getMomentum().R()
167 def getrecovals(self, evlist, state):
169 evlist[self.
varnumvarnumvarnum[
"recoz"][0]] = state.getPos().Z()
170 evlist[self.
varnumvarnumvarnum[
"recotheta"][0]] = state.getMom().Theta()
171 evlist[self.
varnumvarnumvarnum[
"recophi"][0]] = state.getMom().Phi()
172 evlist[self.
varnumvarnumvarnum[
"recopt"][0]] = state.getMom().Pt()
173 evlist[self.
varnumvarnumvarnum[
"recop"][0]] = state.getMomMag()
176 def getneurovals(self, evlist, neuro, status=""):
180 evlist[self.
varnumvarnumvarnum[pre +
"neuroz"][0]] = neuro.getZ0()
181 evlist[self.
varnumvarnumvarnum[pre +
"neurotheta"][0]] = self.
costothetacostotheta(neuro.getCotTheta() / np.sqrt(1 + neuro.getCotTheta()**2))
182 evlist[self.
varnumvarnumvarnum[pre +
"neurophi"][0]] = neuro.getPhi0()
183 evlist[self.
varnumvarnumvarnum[pre +
"neuropt"][0]] = neuro.getPt()
184 evlist[self.
varnumvarnumvarnum[pre +
"neurop"][0]] = neuro.getPt()/np.sin(self.
costothetacostotheta(neuro.getCotTheta() /
185 np.sqrt(1 + neuro.getCotTheta()**2)))
186 evlist[self.
varnumvarnumvarnum[pre +
"neuroval"][0]] = neuro.getValidStereoBit()
187 evlist[self.
varnumvarnumvarnum[pre +
"neuroqual"][0]] = neuro.getQualityVector()
188 evlist[self.
varnumvarnumvarnum[pre +
"neurots"][0]] = int(
"".join([str(x)
for x
in neuro.getTSVector()]))
189 xx = sum([int(i != 0)
for i
in neuro.getTSVector()][::2])
192 evlist[self.
varnumvarnumvarnum[pre +
"neuroats"][0]] = xx
193 evlist[self.
varnumvarnumvarnum[pre +
"neuroexp"][0]] = neuro.getExpert()
194 evlist[self.
varnumvarnumvarnum[pre +
"neurodriftth"][0]] = int(
"".join([str(int(x))
for x
in neuro.getDriftThreshold()]))
195 evlist[self.
varnumvarnumvarnum[pre +
"neuroquad"][0]] = neuro.getQuadrant()
197 for ts
in neuro.getRelationsTo(self.
tsnametsname):
198 if ts.priorityTime() < fpt:
199 fpt = ts.priorityTime()
200 if self.
etfetf.hasBinnedEventT0(Belle2.Const.CDC):
201 eft = self.
etfetf.getBinnedEventT0(Belle2.Const.CDC)
207 evlist[self.
varnumvarnumvarnum[pre +
"neurofp"][0]] = fpt
208 evlist[self.
varnumvarnumvarnum[pre +
"neuroetf"][0]] = eft
210 evlist[self.
varnumvarnumvarnum[pre +
"neuroetfcc"][0]] = neuro.getETF_unpacked()
211 evlist[self.
varnumvarnumvarnum[pre +
"neurohwtime"][0]] = neuro.getETF_recalced()
214 def gettwodvals(self, evlist, twod):
216 evlist[self.
varnumvarnumvarnum[
"twodphi"][0]] = twod.getPhi0()
217 evlist[self.
varnumvarnumvarnum[
"twodpt"][0]] = twod.getPt()
221 def getswtwodvals(self, evlist, twod):
223 evlist[self.
varnumvarnumvarnum[
"swtwodphi"][0]] = twod.getPhi0()
224 evlist[self.
varnumvarnumvarnum[
"swtwodpt"][0]] = twod.getPt()
237 track = reco.getRelatedFrom(
"Tracks")
249 print(
"no track found for recotrack")
258 reps = reco.getRepresentations()
260 for irep, rep
in enumerate(reps):
261 if not reco.wasFitSuccessful(rep):
264 state = reco.getMeasuredStateOnPlaneClosestTo(XYZVector(0, 0, 0), rep)
265 rep.extrapolateToLine(state, TVector3(0, 0, -1000), TVector3(0, 0, 2000))
266 except BaseException:
274 event.append(self.
nonelistnonelist.copy())
277 except BaseException:
281 except BaseException:
285 except BaseException:
289 except BaseException:
294 event[-1] = self.
getrecovalsgetrecovals(event[-1], state)
295 event[-1] = self.
getneurovalsgetneurovals(event[-1], neuro)
296 event[-1] = self.
gettwodvalsgettwodvals(event[-1], twod)
297 event[-1] = self.
getneurovalsgetneurovals(event[-1], hwneuro, status=
"hw")
298 event[-1] = self.
getneurovalsgetneurovals(event[-1], swneuro, status=
"sw")
303 if len(neuro.getRelationsFrom(self.
recotracksnamerecotracksname)) > 0:
307 event.append(self.
nonelistnonelist.copy())
310 except BaseException:
314 except BaseException:
316 event[-1] = self.
getneurovalsgetneurovals(event[-1], neuro)
317 event[-1] = self.
gettwodvalsgettwodvals(event[-1], twod)
318 event[-1] = self.
getneurovalsgetneurovals(event[-1], hwneuro, status=
"hw")
322 if len(swneuro.getRelationsFrom(self.
recotracksnamerecotracksname)) > 0:
326 event.append(self.
nonelistnonelist.copy())
329 except BaseException:
331 event[-1] = self.
getneurovalsgetneurovals(event[-1], swneuro, status=
"sw")
332 event[-1] = self.
getswtwodvalsgetswtwodvals(event[-1], swtwod)
336 if len(twod.getRelationsFrom(self.
neurotracksnameneurotracksname)) > 0:
340 event.append(self.
nonelistnonelist.copy())
341 event[-1] = self.
gettwodvalsgettwodvals(event[-1], twod)
349 event.append(self.
nonelistnonelist.copy())
350 event[-1] = self.
getswtwodvalsgetswtwodvals(event[-1], swtwod)
355 elif len(event) < self.
maxtracksmaxtracks:
356 for i
in range(self.
maxtracksmaxtracks - len(event)):
357 event.append(self.
nonelistnonelist.copy())
368 def save(self, filename=None, netname=None, dataname=None):
370 filename = self.filename
372 netname = self.netname
378 savedict[
"eventlist"] = self.
eventlisteventlist
380 savedict[
"networkname"] = netname
381 savedict[
"dataname"] = dataname
382 savedict[
"version"] = nntd.version
383 f = open(filename,
'wb')
384 pickle.dump(savedict, f)
386 print(
'file ' + filename +
' has been saved. ')
388 def loadmore(self, filenames):
393 if "NNTD_EVLIMIT" in os.environ:
394 evlim = int(os.environ[
"NNTD_EVLIMIT"])
397 for i, x
in enumerate(filenames):
398 print(
"checking file: " + str(i) +
"/" + str(len(filenames)))
400 evnumber += len(pickle.load(f)[
"eventlist"])
402 print(
"total number of available events is " + str(evnumber))
403 skipev = int(evnumber/evlim)
404 print(
"Number of events more than " + str(evlim) +
" only taking every " + str(skipev) +
" event")
409 savedict = pickle.load(f)
411 if self.
versionversion != savedict[
"version"]:
412 print(
"Error! loaded file was made with different version of nntd! exiting ... ")
414 self.
networknamenetworkname = savedict[
"networkname"]
415 if "dataname" in savedict:
416 self.
datanamedataname = savedict[
"dataname"]
417 templim = evlim-len(self.
eventlisteventlist)
418 self.
eventlisteventlist += savedict[
"eventlist"][::skipev][:templim]
420 print(
"Loaded file: " + x)
421 print(
"length of eventlist: " + str(len(self.
eventlisteventlist)))
422 if evlim <= len(self.
eventlisteventlist):
423 print(
"stop loading, maximum event number reached")
426 print(
"all files loaded, array.size: " + str(self.
datadata.size) +
", array.shape: " + str(self.
datadata.shape))
428 def load(self, filename):
430 f = open(filename,
'rb')
431 savedict = pickle.load(f)
433 if self.
versionversion != savedict[
"version"]:
434 print(
"Error! loaded file was made with different version of nntd! exiting ... ")
436 self.
eventlisteventlist = savedict[
"eventlist"]
438 self.
networknamenetworkname = savedict[
"networkname"]
439 self.
datanamedataname = savedict[
"dataname"]
443 def makearray(self, evlist):
445 self.
datadata = np.array(evlist)
Provides a type-safe way to pass members of the chargedStableSet set.
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
def getswtwodvals(self, evlist, twod)
def getneurovals(self, evlist, neuro, status="")
def getrecovals(self, evlist, state)
def save(self, filename=None, netname=None, dataname=None)
def makearray(self, evlist)
def gettwodvals(self, evlist, twod)
def getrecovalsold(self, evlist, fitres)