2
from ReducePyROOTHistogram import ReducePyROOTHistogram
4
class ReducePyCherenkov(ReducePyROOTHistogram): # pylint: disable=R0902
8
ReducePyROOTHistogram.__init__(self)
11
self.root_batch_mode = 0
22
self._hlight_Mu = None
25
self.canvas_charge = None
26
self.canvas_time = None
27
self.canvas_tof = None
28
self.canvas_tof_A = None
29
self.canvas_tof_B = None
30
self.canvas_hPMu = None
31
self.canvas_hPPi = None
32
self.canvas_hlight_Mu = None
33
self.canvas_hPMuA = None
34
self.canvas_hPPiA = None
36
def _configure_at_birth(self, config_doc):
38
if 'refresh_rate' in config_doc:
39
self.refresh_rate = int(config_doc["refresh_rate"])
43
def _update_histograms(self, spill):
45
if "END_OF_RUN" in spill:
47
return self.get_histogram_images()
49
if not self.get_space_points(spill):
50
raise ValueError("space points not in spill")
52
# Get charge points & fill histograms.
53
if not self.get_charge(spill):
54
raise ValueError("charge not in spill")
56
# Refresh canvases at requested frequency.
58
if self.spill_count % self.refresh_rate == 0:
60
return self.get_histogram_images()
64
def get_space_points(self, spill):
66
if 'space_points' not in spill:
69
# check for NoneType --there are events with no reconstructed SP
70
if spill['space_points'] is None:
73
space_points = spill['space_points']
75
if 'tof0' not in space_points:
77
sp_tof0 = space_points['tof0']
79
if 'tof1' not in space_points:
81
sp_tof1 = space_points['tof1']
83
if 'tof2' not in space_points:
85
sp_tof2 = space_points['tof2']
87
if 'digits' not in spill:
90
digits = spill['digits']
92
#The cuts on e and mu TOFs are made first by 'eyeing' the 1D TOF distributions.
97
d = 7.8241 #Distance between TOF1 and TOF0
102
CKOV_TURN_ON_107 = 2.6270345
103
CKOV_TURN_ON_112 = 1.9826290
108
#TOF vs. Total Charge
110
for i in range(len(sp_tof1)):
111
if sp_tof0[i] and sp_tof1[i] :
112
if len(sp_tof0[i])==1 and len(sp_tof1[i])==1:
113
if sp_tof0[i][0]["part_event_number"]==digits[i]['B']['part_event_number']:
114
t_0 = sp_tof0[i][0]["time"]
115
t_1 = sp_tof1[i][0]["time"]
116
self._htof.Fill(t_1-t_0)
118
charge_B = digits[i]["B"]["total_charge"] #This should be done pe and done in the mapper.
119
charge_A = digits[i]["A"]["total_charge"]
120
PE_B = charge_B/20.00 #Photoelectrons Normalized (can be done in mapper)
121
PE_A = charge_A/20.00 #Photoelectrons Normalized
123
self._htof_B.Fill(PE_B, (t_1 - t_0))
126
self._htof_A.Fill(PE_A, (t_1-t_0))
128
#Convert to momenta from TOF using m and d while making the appropriate cuts; fill momenta histograms
129
if ((t_1-t_0) < tof_cut_e):
132
if ((t_1-t_0) < tof_cut_mu):
136
if (((t_1-t_0)*0.3) > d):
137
p = m / sqrt(((t_1-t_0)*0.3/d)*((t_1-t_0)*0.3/d)-1)
141
if (m==MASS_MU and p > 0.0 and PE_A > 1):
143
self._hlight_Mu.Fill(p, PE_A)
145
if (m==MASS_PI and p > 0.0):
148
# if (p > CKOV_TURN_ON_107*MASS_MU):
149
# n_photons_est_ckov107 = 18*(1 - (CKOV_TURN_ON_107*MASS_MU/p)*(CKOV_TURN_ON_107*MASS_MU/p))
150
# self._hEstCkov.Fill(p, n_phtons_est_ckov107)
152
# n_photons_est_ckov107 = 0.0
153
# self._hEstCkov.Fill(p, n_photons_est_ckov107)
157
def get_charge(self, spill):
159
if 'digits' not in spill:
162
digits = spill['digits']
164
for i in range(len(digits)):
166
for pmt in range(1,9):
167
pulse = "pulse_%d" % (pmt)
168
arrival_time = "arrival_time_%d" % (pmt)
172
charge = digits[i]['B'][pulse]
174
self._hcharge[i-1].Fill(charge)
176
time = digits[i]['B'][arrival_time]
178
self._htime[i-1].Fill(time)
181
charge = digits[i]['A'][pulse]
183
self._hcharge[i-1].Fill(charge)
185
time = digits[i]['A'][arrival_time]
187
self._htime[1-i].Fill(time)
191
def __init_histos(self): #pylint: disable=R0201, R0914
192
# have root run quietly without verbose informationals
193
ROOT.gErrorIgnoreLevel = 1001
196
ROOT.gROOT.SetStyle("Plain")
199
ROOT.gStyle.SetOptStat(0)
201
#sensible color palette
202
ROOT.gStyle.SetPalette(1)
205
ROOT.gStyle.SetPadGridX(1)
206
ROOT.gStyle.SetPadGridY(1)
214
self.canvas_tof_A = ROOT.TCanvas("tof_A", "tof_A", 600, 600)
215
self._htof_A = ROOT.TH2F("tof_A", "tof_A", 100, 0, 50, 200, 15, 35)
216
self._htof_A.GetXaxis().SetTitle("#PE")
217
self._htof_A.GetYaxis().SetTitle("TOF(CKOVA) (ns)")
218
self.canvas_tof_A.cd()
221
self.canvas_tof_B = ROOT.TCanvas("tof_B", "tof_B", 600, 600)
222
self._htof_B = ROOT.TH2F("tof_B", "tof_B", 100, 0, 50, 200, 15, 35)
223
self._htof_B.GetXaxis().SetTitle("#PE")
224
self._htof_B.GetYaxis().SetTitle("TOF(CKOVB) (ns)")
225
self.canvas_tof_B.cd()
228
self.canvas_tof = ROOT.TCanvas("tof", "tof", 600, 600)
229
self._htof = ROOT.TH1F("htof", "htof", 100, 10, 40)
230
self._htof.GetXaxis().SetTitle("TOF(ns)")
235
#Make Canvas for PMT Charges
236
self.canvas_charge = ROOT.TCanvas("charge", "charge", 1200, 800)
237
self.canvas_charge.Divide(4,2)
242
hname = "hPMT%d" % (i)
243
htitle = "PMT%d" % (i)
248
self._hcharge.append(ROOT.TH1F(hname, htitle, nbins, x_lo, x_hi))
249
self._hcharge[i].GetXaxis().SetTitle("Charge")
250
self.canvas_charge.cd(i+1)
252
self._hcharge[i].Draw()
254
#Make Canvas for Arrival Times
258
self.canvas_time = ROOT.TCanvas("time", "time", 1200, 800)
259
self.canvas_time.Divide(4,2)
264
hname = "harr_time%d" % (i)
265
htitle = "Arrival Times%d" % (i)
270
self._htime.append(ROOT.TH1F(hname, htitle, nbins, x_lo, x_hi))
271
self._htime[i].GetXaxis().SetTitle("Time (ns)")
272
self.canvas_time.cd(i+1)
273
self._htime[i].Draw()
275
self.canvas_hPMu = ROOT.TCanvas("hPMu", "hPMu", 600, 600)
276
self._hPMu = ROOT.TH1F("hPMu", "hPMu", 500, 0, 500)
277
self._hPMu.GetXaxis().SetTitle("Momentum (MeV/c)")
278
self.canvas_hPMu.cd()
281
self.canvas_hPPi = ROOT.TCanvas("hPPi", "hPPi", 600, 600)
282
self._hPPi = ROOT.TH1F("hPPi", "hPPi", 500, 0, 500)
283
self._hPPi.GetXaxis().SetTitle("Momentum (MeV/c)")
284
self.canvas_hPPi.cd()
287
self.canvas_hlight_Mu = ROOT.TCanvas("PE_MOM", "PE_MOM", 600, 600)
288
self._hlight_Mu = ROOT.TH2F("hLight", "hLight", 500, 0, 500, 100, 0, 30)
289
self._hEstCkov = ROOT.TH2F("hLight", "hLight", 500, 0, 500, 100, 0, 30)
290
self._hlight_Mu.GetXaxis().SetTitle("Momentum (MeV/c)")
291
self._hlight_Mu.GetYaxis().SetTitle("#PE")
292
self.canvas_hlight_Mu.cd()
293
self._hlight_Mu.Draw()
294
self._hEstCkov.Draw("same")
297
def update_histos(self):
299
self.canvas_charge.Update()
300
self.canvas_time.Update()
301
self.canvas_tof.Update()
302
self.canvas_tof_A.Update()
303
self.canvas_tof_B.Update()
304
self.canvas_hPMu.Update()
305
self.canvas_hPPi.Update()
306
self.canvas_hlight_Mu.Update()
308
def get_histogram_images(self):
310
Get histograms as JSON documents.
311
@param self Object reference.
312
@returns list of 3 JSON documents containing the images.
317
# file label = PTM1-8.eps
319
content = "PMTCharge"
320
doc = ReducePyROOTHistogram.get_image_doc(self, content, tag, self.canvas_charge)
321
image_list.append(doc)
324
#file label = ArrivalTime.eps
326
content = "arrival_time"
327
doc = ReducePyROOTHistogram.get_image_doc(self, content, tag, self.canvas_time)
328
image_list.append(doc)
334
doc = ReducePyROOTHistogram.get_image_doc(self, content, tag, self.canvas_tof)
335
image_list.append(doc)
338
#file label = "TOF_A"
341
doc = ReducePyROOTHistogram.get_image_doc(self, content, tag, self.canvas_tof_A)
342
image_list.append(doc)
345
#file label = "TOF_B"
348
doc = ReducePyROOTHistogram.get_image_doc(self, content, tag, self.canvas_tof_B)
349
image_list.append(doc)
355
doc = ReducePyROOTHistogram.get_image_doc(self, content, tag, self.canvas_hPMu)
356
image_list.append(doc)
362
doc = ReducePyROOTHistogram.get_image_doc(self, content, tag, self.canvas_hPPi)
363
image_list.append(doc)
369
doc = ReducePyROOTHistogram.get_image_doc(self, content, tag, self.canvas_hlight_Mu)
370
image_list.append(doc)