~christopher-hunt08/maus/beam_selection_development

« back to all changes in this revision

Viewing changes to src/reduce/ReducePyTOFPlot/ReducePyTOFPlot.py

  • Committer: Chris Rogers
  • Date: 2012-10-13 18:43:00 UTC
  • mfrom: (663.6.137 merge)
  • mto: (663.6.204 merge)
  • mto: This revision was merged to the branch mainline in revision 680.
  • Revision ID: chris.rogers@stfc.ac.uk-20121013184300-ry9q81m45dmtgejr
Bring control room branch into line with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
119
119
        self.refresh_rate = 5
120
120
        # Histogram initializations. they are defined explicitly in
121
121
        # init_histos.
 
122
        self.legend = None
122
123
        self._ht01 = None
123
124
        self._ht02 = None
124
125
        self._ht12 = None
186
187
                return self.get_histogram_images()
187
188
            else:
188
189
                return [{}]
189
 
        elif spill["daq_event_type"] != "physics_event":
190
 
            return spill
 
190
        # elif spill["daq_event_type"] != "physics_event":
 
191
        #    return spill
191
192
 
192
193
        # do not try to get data from start/end spill markers
193
194
        data_spill = True
198
199
 
199
200
        # Get TOF slab hits & fill the relevant histograms.
200
201
        if data_spill and not self.get_slab_hits(spill): 
201
 
            print "No space points recorded"
202
 
            #raise ValueError("slab_hits not in spill")
 
202
            raise ValueError("slab_hits not in spill")
203
203
 
204
204
        # Get TOF space points & fill histograms.
205
205
        if data_spill and not self.get_space_points(spill):
206
 
            print "No space points recorded"
207
 
            #raise ValueError("space_points not in spill")
 
206
            raise ValueError("space_points not in spill")
208
207
 
209
208
        # Refresh canvases at requested frequency.
210
209
        if self.spill_count % self.refresh_rate == 0:
222
221
        @return True if no errors or False if no "slab_hits" in
223
222
        the spill.
224
223
        """
225
 
        # Return if we cannot find slab_hits in the spill.
226
 
        if 'slab_hits' not in spill:
227
 
            return False
228
 
 
229
 
        slabhits = spill['slab_hits']
230
 
 
231
 
        # setup the detectors for which we want to look at hits
232
 
        dets = ['tof0', 'tof1', 'tof2']
 
224
        if 'recon_events' not in spill:
 
225
            raise ValueError("recon_events not in spill")
 
226
        # print 'nevt = ', len(spill['recon_events']), spill['recon_events']
 
227
        for evn in range(len(spill['recon_events'])):
 
228
            if 'tof_event' not in spill['recon_events'][evn]:
 
229
                # print 'no tof event'
 
230
                raise ValueError("tof_event not in recon_events")
 
231
            # Return if we cannot find slab_hits in the event.
 
232
            if 'tof_slab_hits' not in spill['recon_events'][evn]['tof_event']:
 
233
                return False
 
234
 
 
235
            slabhits = spill['recon_events'][evn]['tof_event']['tof_slab_hits']
 
236
 
 
237
            # setup the detectors for which we want to look at hits
 
238
            dets = ['tof0', 'tof1', 'tof2']
233
239
                   
234
 
        # loop over detector stations ie tof0,tof1,tof2
235
 
        for index, station in enumerate(dets):
236
 
            # leave if we cannot find slab hits for this detector
237
 
            if station not in slabhits:
238
 
                continue
239
 
            dethits = slabhits[station]
240
 
            # loop over all slab hits for this detector station
241
 
            for i in range(len(dethits)):
242
 
                # make sure it is not null
243
 
                if (dethits[i]):
244
 
                    for j in range(len(dethits[i])): #loop over planes
245
 
                        pos = dethits[i][j]['slab']
246
 
                        plane_num = dethits[i][j]["plane"]
 
240
            # loop over detector stations ie tof0,tof1,tof2
 
241
            for index, station in enumerate(dets):
 
242
                # leave if we cannot find slab hits for this detector
 
243
                if station not in slabhits:
 
244
                    continue
 
245
                dethits = slabhits[station]
 
246
                # print 'idx,stn: ',index,station,len(dethits),dethits
 
247
                # loop over all slab hits for this detector station
 
248
                if dethits == None:
 
249
                    continue
 
250
                for i in range(len(dethits)):
 
251
                    # make sure it is not null
 
252
                    if (dethits[i]):
 
253
                        # wrong. no further loop. ie no j
 
254
                        # for j in range(len(dethits[i])): #loop over planes
 
255
                        pos = dethits[i]['slab']
 
256
                        plane_num = dethits[i]["plane"]
247
257
                        # make sure the plane number is valid so 
248
258
                        # we don't overflow bounds
249
259
                        if plane_num < 0 or plane_num > 1:
250
260
                            return False
251
261
                        self.hslabhits[index][plane_num].Fill(pos)
252
 
                        #plane 0, pmt0 hit for this slab
253
 
                        if ("pmt0" in dethits[i][j]):
 
262
                        # plane 0, pmt0 hit for this slab
 
263
                        if ("pmt0" in dethits[i]):
254
264
                            self.hpmthits[index][plane_num][0].Fill(pos)
255
 
                        #plane 0, pmt1 hit for this slab
256
 
                        if ("pmt1" in dethits[i][j]):
 
265
                        # plane 0, pmt1 hit for this slab
 
266
                        if ("pmt1" in dethits[i]):
257
267
                            self.hpmthits[index][plane_num][1].Fill(pos)
258
268
        return True
259
269
 
273
283
        @return True if no errors or False if no "space_points" in
274
284
        the spill.
275
285
        """
276
 
        if 'space_points' not in spill:
277
 
            return False
278
 
 
279
 
        # check for NoneType --there are events with no reconstructed SP
280
 
        if spill['space_points'] is None:
281
 
            return False
282
 
 
283
 
        space_points = spill['space_points']
284
 
 
285
 
        # if there are no TOF0,1,2 space point objects, return false
286
 
        # not sure if we require all 3, 
287
 
        # -obviously this causes probs when eg. no TOF2 - fixed 3/24
288
 
        sp_tof0 = None
289
 
        sp_tof1 = None
290
 
        sp_tof2 = None
291
 
        if 'tof0' in space_points:
292
 
            sp_tof0 = space_points['tof0']
293
 
 
294
 
        if 'tof1' in space_points:
295
 
            sp_tof1 = space_points['tof1']
296
 
 
297
 
        if 'tof2' in space_points:
298
 
            sp_tof2 = space_points['tof2']
299
 
 
300
 
        
301
 
        # TOF0
302
 
        if sp_tof0:
303
 
            for i in range(len(sp_tof0)):
304
 
                if sp_tof0[i]:
305
 
                    self.hnsp_0.Fill(len(sp_tof0[i]))
306
 
                    spnt_x = sp_tof0[i][0]["slabX"]
307
 
                    spnt_y = sp_tof0[i][0]["slabY"]
308
 
                    self.hspxy[0].Fill(spnt_x, spnt_y)
309
 
                    self.hspslabx_0.Fill(spnt_x)
310
 
                    self.hspslaby_0.Fill(spnt_y)
311
 
                else:
312
 
                    self.hnsp_0.Fill(0)           
313
 
                if sp_tof0[i] and sp_tof1[i] :
314
 
                    if len(sp_tof0[i])==1 and len(sp_tof1[i])==1:
315
 
                        t_0 = sp_tof0[i][0]["time"]
316
 
                        t_1 = sp_tof1[i][0]["time"]
317
 
 
318
 
        # TOF 2
319
 
        if sp_tof2:
320
 
            for i in range(len(sp_tof2)):
321
 
                if sp_tof2[i]:
322
 
                    self.hnsp_2.Fill(len(sp_tof2[i]))
323
 
                    spnt_x = sp_tof2[i][0]["slabX"]
324
 
                    spnt_y = sp_tof2[i][0]["slabY"]
325
 
                    self.hspxy[2].Fill(spnt_x, spnt_y)
326
 
                    self.hspslabx_2.Fill(spnt_x)
327
 
                    self.hspslaby_2.Fill(spnt_y)
328
 
                else:
329
 
                    self.hnsp_2.Fill(0)
330
 
                if sp_tof2[i] and sp_tof1[i] :
331
 
                    if len(sp_tof2[i])==1 and len(sp_tof1[i])==1:
332
 
                        t_2 = sp_tof2[i][0]["time"]
333
 
                        t_1 = sp_tof1[i][0]["time"]
334
 
                        self._ht12.Fill(t_2-t_1)
335
 
                if sp_tof2[i] and sp_tof0[i] :
336
 
                    if len(sp_tof2[i])==1 and len(sp_tof0[i])==1:
337
 
                        t_2 = sp_tof2[i][0]["time"]
338
 
                        t_0 = sp_tof0[i][0]["time"]
339
 
                        self._ht02.Fill(t_2-t_0)
340
 
 
341
 
        # TOF 1
342
 
        if sp_tof1:
343
 
            for i in range(len(sp_tof1)):
344
 
                if sp_tof1[i]:
345
 
                    self.hnsp_1.Fill(len(sp_tof1[i]))
346
 
                    spnt_x = sp_tof1[i][0]["slabX"]
347
 
                    spnt_y = sp_tof1[i][0]["slabY"]
348
 
                    self.hspxy[1].Fill(spnt_x, spnt_y)
349
 
                    self.hspslabx_1.Fill(spnt_x)
350
 
                    self.hspslaby_1.Fill(spnt_y)
351
 
                else:
352
 
                    self.hnsp_1.Fill(0)           
353
 
                if sp_tof0[i] and sp_tof1[i] :
354
 
                    if len(sp_tof0[i])==1 and len(sp_tof1[i])==1:
355
 
                        t_0 = sp_tof0[i][0]["time"]
356
 
                        t_1 = sp_tof1[i][0]["time"]
357
 
                        self._ht01.Fill(t_1-t_0)
 
286
        if 'recon_events' not in spill:
 
287
            # print 'no reco'
 
288
            return False
 
289
 
 
290
        for evn in range(len(spill['recon_events'])):
 
291
            if 'tof_event' not in spill['recon_events'][evn]:
 
292
                # print 'no tof event'
 
293
                return False
 
294
                # print spill['recon_events'][evn]['tof_event']
 
295
                # Return if we cannot find slab_hits in the spill.
 
296
            if 'tof_space_points' not in \
 
297
                  spill['recon_events'][evn]['tof_event']:
 
298
                return False
 
299
            space_points = \
 
300
                  spill['recon_events'][evn]['tof_event']['tof_space_points']
 
301
 
 
302
            # print 'evt: ', evn, ' nsp: ',len(space_points)
 
303
            # if there are no TOF0,1,2 space point objects, return false
 
304
            sp_tof0 = None
 
305
            sp_tof1 = None
 
306
            sp_tof2 = None
 
307
 
 
308
            if 'tof0' in space_points:
 
309
                sp_tof0 = space_points['tof0']
 
310
 
 
311
            if 'tof1' in space_points:
 
312
                sp_tof1 = space_points['tof1']
 
313
 
 
314
            if 'tof2' in space_points:
 
315
                sp_tof2 = space_points['tof2']
 
316
 
 
317
            # print 'nsp012= ', len(sp_tof0), len(sp_tof1), len(sp_tof2)
 
318
         
 
319
            # TOF0
 
320
            if sp_tof0:
 
321
                # print '..evt ',evn,' nsp0: ',len(sp_tof0)
 
322
                self.hnsp_0.Fill(len(sp_tof0))
 
323
                for i in range(len(sp_tof0)):
 
324
                    if sp_tof0[i]:
 
325
                        # print 'nsp0: ',i,sp_tof0[i]
 
326
                        spnt_x = sp_tof0[i]["slabX"]
 
327
                        spnt_y = sp_tof0[i]["slabY"]
 
328
                        self.hspxy[0].Fill(spnt_x, spnt_y)
 
329
                        self.hspslabx_0.Fill(spnt_x)
 
330
                        self.hspslaby_0.Fill(spnt_y)
 
331
                        # print '... ', i
 
332
                        if sp_tof1 is not None :
 
333
                            if len(sp_tof0)==1 and len(sp_tof1)==1:
 
334
                                t_0 = sp_tof0[i]["time"]
 
335
                                t_1 = sp_tof1[i]["time"]
 
336
            else:
 
337
                self.hnsp_0.Fill(0)           
 
338
 
 
339
            # TOF 2
 
340
            if sp_tof2:
 
341
                # print '..evt ', evn, ' nsp2: ', len(sp_tof2)
 
342
                self.hnsp_2.Fill(len(sp_tof2))
 
343
                for i in range(len(sp_tof2)):
 
344
                    if sp_tof2[i]:
 
345
                        spnt_x = sp_tof2[i]["slabX"]
 
346
                        spnt_y = sp_tof2[i]["slabY"]
 
347
                        self.hspxy[2].Fill(spnt_x, spnt_y)
 
348
                        self.hspslabx_2.Fill(spnt_x)
 
349
                        self.hspslaby_2.Fill(spnt_y)
 
350
                        if sp_tof1 is not None :
 
351
                            # print '2&1: ', len(sp_tof1)
 
352
                            if len(sp_tof2)==1 and len(sp_tof1)==1:
 
353
                                t_2 = sp_tof2[i]["time"]
 
354
                                t_1 = sp_tof1[i]["time"]
 
355
                                self._ht12.Fill(t_2-t_1)
 
356
                                # print 'tof: ', t_2-t_1
 
357
 
 
358
                        if sp_tof0 is not None :
 
359
                            if len(sp_tof2)==1 and len(sp_tof0)==1:
 
360
                                t_2 = sp_tof2[i]["time"]
 
361
                                t_0 = sp_tof0[i]["time"]
 
362
                                self._ht02.Fill(t_2-t_0)
 
363
            else:
 
364
                self.hnsp_2.Fill(0)
 
365
            # TOF 1
 
366
            if sp_tof1:
 
367
                # print '..evt ',evn,' nsp1: ',len(sp_tof1)
 
368
                self.hnsp_1.Fill(len(sp_tof1))
 
369
                for i in range(len(sp_tof1)):
 
370
                    if sp_tof1[i]:
 
371
                        # print 'nsp1: ', i, sp_tof1[i]
 
372
                        spnt_x = sp_tof1[i]["slabX"]
 
373
                        spnt_y = sp_tof1[i]["slabY"]
 
374
                        self.hspxy[1].Fill(spnt_x, spnt_y)
 
375
                        self.hspslabx_1.Fill(spnt_x)
 
376
                        self.hspslaby_1.Fill(spnt_y)
 
377
                        # print '... ', i
 
378
                        if sp_tof0 is not None :
 
379
                            if len(sp_tof1)==1 and len(sp_tof0)==1:
 
380
                                # print '>>>> ok'
 
381
                                t_0 = sp_tof0[i]["time"]
 
382
                                t_1 = sp_tof1[i]["time"]
 
383
                                self._ht01.Fill(t_1-t_0)
 
384
                                # print 'tof01: ', t_1-t_0
 
385
            else:
 
386
                self.hnsp_1.Fill(0)           
358
387
        return True
359
388
 
360
389
    def __init_histos(self): #pylint: disable=R0201, R0914
378
407
        # xy grid on canvas
379
408
        ROOT.gStyle.SetPadGridX(1)
380
409
        ROOT.gStyle.SetPadGridY(1)
381
 
        
 
410
        self.legend = ROOT.TLegend(0.6, 0.7, 0.89, 0.89)
 
411
        ROOT.SetOwnership( self.legend, 1 ) 
 
412
        ROOT.gStyle.SetFillColor(0)
382
413
        # define histograms
383
414
        self._ht01 = ROOT.TH1F("ht01", "TOF0->1;Time (ns);;", 200, 20, 40)
384
415
        self._ht12 = ROOT.TH1F("ht12", "TOF1->2;Time (ns);;", 200, 0, 20)
385
416
        self._ht02 = ROOT.TH1F("ht02", "TOF0->2;Time (ns);;", 200, 30, 50)
386
417
        
387
418
        
388
 
        self.hspslabx_0 = ROOT.TH1F("spx0", "SpacePoints X slabs hit;SlabX;",
389
 
                                     10, -0.5, 9.5)
390
 
        self.hspslaby_0 = ROOT.TH1F("spy0", "SpacePoints Y slabs hit;SlabY;",
391
 
                                     10, -0.5, 9.5)
392
 
        self.hspslabx_1 = ROOT.TH1F("spx1", "SpacePoints X slabs hit;SlabX;",
393
 
                                     10, -0.5, 9.5)
394
 
        self.hspslaby_1 = ROOT.TH1F("spy1", "SpacePoints Y slabs hit;SlabY;",
 
419
        self.hspslabx_0 = ROOT.TH1F("spx0", "SpacePoints X-plane;SlabX;",
 
420
                                     10, -0.5, 9.5)
 
421
        self.hspslaby_0 = ROOT.TH1F("spy0", "SpacePoints Y-plane;SlabY;",
 
422
                                     10, -0.5, 9.5)
 
423
        self.hspslabx_1 = ROOT.TH1F("spx1", "SpacePoints X-plane;SlabX;",
 
424
                                     10, -0.5, 9.5)
 
425
        self.hspslaby_1 = ROOT.TH1F("spy1", "SpacePoints Y-plane;SlabY;",
395
426
                                     10, -0.5, 9.5)
396
427
        self.hspslabx_1.SetFillColor(2)
 
428
        self.hspslabx_1.SetLineColor(2)
397
429
        self.hspslaby_1.SetFillColor(2) 
398
 
        self.hspslabx_2 = ROOT.TH1F("spx2", "SpacePoints X slabs hit;SlabX;",
 
430
        self.hspslaby_1.SetLineColor(2) 
 
431
        self.hspslabx_2 = ROOT.TH1F("spx2", "SpacePoints X-plane;SlabX;",
399
432
                                     10, -0.5, 9.5)
400
 
        self.hspslaby_2 = ROOT.TH1F("spy2", "SpacePoints Y slabs hit;SlabY;",
 
433
        self.hspslaby_2 = ROOT.TH1F("spy2", "SpacePoints Y-plane;SlabY;",
401
434
                                     10, -0.5, 9.5)
402
435
        self.hspslabx_2.SetFillColor(4)
 
436
        self.hspslabx_2.SetLineColor(4)
403
437
        self.hspslaby_2.SetFillColor(4) 
 
438
        self.hspslaby_2.SetLineColor(4) 
404
439
        
405
 
        self.hnsp_0 = ROOT.TH1F("hnsp_0", ";#space points in particle event;;",
 
440
        self.hnsp_0 = ROOT.TH1F("hnsp_0", 
 
441
                                "#Space Points;#space points in event;;",
406
442
                                 4, -0.5, 3.5)
407
 
        self.hnsp_1 = ROOT.TH1F("hnsp_1", ";#space points in particle event;;",
 
443
        self.hnsp_0.SetLineColor(1)
 
444
        self.hnsp_1 = ROOT.TH1F("hnsp_1", 
 
445
                                "#Space Points;#space points in event;;",
408
446
                                 4, -0.5, 3.5)
409
447
        self.hnsp_1.SetFillColor(2)
410
 
        self.hnsp_2 = ROOT.TH1F("hnsp_2", ";#space points in particle event;;",
 
448
        self.hnsp_1.SetLineColor(2)
 
449
        #self.hnsp_1.SetFillStyle(4000)
 
450
        self.hnsp_2 = ROOT.TH1F("hnsp_2", 
 
451
                                 "#Space Points;#space points in event;;",
411
452
                                 4, -0.5, 3.5)
412
453
        self.hnsp_2.SetFillColor(4)
 
454
        self.hnsp_2.SetLineColor(4)
413
455
 
414
456
        self.hslabhits = [[]]
415
457
        for i in range (0, 3):
417
459
            for j in range (0, 2):
418
460
                histname = "hslabhits%d%d" % (i, j)
419
461
                if (j == 0): 
420
 
                    title = "Raw Slab Hits X; SlabX;"
 
462
                    title = "Slab Hits X-plane; SlabX;"
421
463
                if (j == 1): 
422
 
                    title = "Raw Slab Hits Y;SlabY;"
 
464
                    title = "Slab Hits Y-plane;SlabY;"
423
465
                nbins = 10
424
466
                xlo = -0.5
425
467
                xhi = 9.5
426
468
                self.hslabhits[i].append(ROOT.TH1F(histname,
427
469
                                                   title,
428
470
                                                   nbins, xlo, xhi))
429
 
                self.hslabhits[i][j].SetFillColor(2*i)
 
471
                if i == 0:
 
472
                    self.hslabhits[i][j].SetLineColor(i+1)
 
473
                else:
 
474
                    self.hslabhits[i][j].SetFillColor(2*i)
 
475
                    self.hslabhits[i][j].SetLineColor(2*i)
430
476
 
431
477
        self.hpmthits = [[[]]]
432
478
        for i in range (0, 3):
442
488
                    self.hpmthits[i][j].append(ROOT.TH1F(histname, 
443
489
                                                         title,
444
490
                                                         nbins, xlo, xhi))
445
 
                    self.hpmthits[i][j][k].SetFillColor(2*i)
446
 
 
 
491
                    if i == 0:
 
492
                        self.hpmthits[i][j][k].SetLineColor(i+1)
 
493
                    else:
 
494
                        self.hpmthits[i][j][k].SetFillColor(2*i)
 
495
                        self.hpmthits[i][j][k].SetLineColor(2*i)
447
496
 
448
497
        # Create canvases
449
498
        #
462
511
        self._ht12.Draw()
463
512
        self.canvas_tof[2].cd()
464
513
        self._ht02.Draw()
 
514
 
465
515
        
466
516
        # Slab Hits x
467
517
        self.canvas_hits_x = ROOT.TCanvas("hits_x", "hits_x", 800, 800)
540
590
        number of spills is divisible by the refresh rate.
541
591
        @param self Object reference.
542
592
        """
 
593
 
 
594
        #ll = ROOT.TLegend(0.6, 0.7, 0.89, 0.89)
 
595
        self.canvas_hits_x.cd()
 
596
        leg = self.canvas_hits_x.BuildLegend(0.6, 0.7, 0.89, 0.89)
 
597
        leg.Clear()
 
598
        leg.AddEntry(self.hslabhits[0][0], "TOF0", "l")
 
599
        leg.AddEntry(self.hslabhits[1][0], "TOF1", "l")
 
600
        leg.AddEntry(self.hslabhits[2][0], "TOF2", "l")
 
601
        leg.SetBorderSize(0)
 
602
        leg.SetFillColor(0)
 
603
        leg.Draw()
543
604
        self.canvas_hits_x.Update()
 
605
 
 
606
        self.canvas_hits_y.cd()
 
607
        leg = self.canvas_hits_y.BuildLegend(0.6, 0.7, 0.89, 0.89)
 
608
        leg.Clear()
 
609
        leg.AddEntry(self.hslabhits[0][1], "TOF0", "l")
 
610
        leg.AddEntry(self.hslabhits[1][1], "TOF1", "l")
 
611
        leg.AddEntry(self.hslabhits[2][1], "TOF2", "l")
 
612
        leg.SetBorderSize(0)
 
613
        leg.SetFillColor(0)
 
614
        leg.Draw()
544
615
        self.canvas_hits_y.Update()
 
616
 
545
617
        for plane in range (2):
546
618
            for pmt in range (2):
547
619
                ind = 2*plane + pmt
 
620
                leg = self.canvas_pmt[ind].BuildLegend(0.6, 0.7, 0.89, 0.89)
 
621
                leg.Clear()
 
622
                
 
623
                pnum = "Plane%d,PMT%d" % (plane, pmt)
 
624
                leg.AddEntry(self.hpmthits[0][plane][pmt], "TOF0,"+pnum, "l")
 
625
                leg.AddEntry(self.hpmthits[1][plane][pmt], "TOF1,"+pnum, "l")
 
626
                leg.AddEntry(self.hpmthits[2][plane][pmt], "TOF2,"+pnum, "l")
548
627
                self.canvas_pmt[ind].Update()
 
628
 
 
629
        leg = self.canvas_nsp.BuildLegend(0.6, 0.7, 0.89, 0.89)
 
630
        leg.Clear()
 
631
        leg.AddEntry(self.hnsp_0, "TOF0", "l")
 
632
        leg.AddEntry(self.hnsp_1, "TOF1", "l")
 
633
        leg.AddEntry(self.hnsp_2, "TOF2", "l")
549
634
        self.canvas_nsp.Update()
 
635
 
 
636
        leg = self.canvas_sp_x.BuildLegend(0.6, 0.7, 0.89, 0.89)
 
637
        leg.Clear()
 
638
        leg.AddEntry(self.hspslabx_0, "TOF0", "l")
 
639
        leg.AddEntry(self.hspslabx_1, "TOF1", "l")
 
640
        leg.AddEntry(self.hspslabx_2, "TOF2", "l")
550
641
        self.canvas_sp_x.Update()
 
642
        leg = self.canvas_sp_y.BuildLegend(0.6, 0.7, 0.89, 0.89)
 
643
        leg.Clear()
 
644
        leg.AddEntry(self.hspslaby_0, "TOF0", "l")
 
645
        leg.AddEntry(self.hspslaby_1, "TOF1", "l")
 
646
        leg.AddEntry(self.hspslaby_2, "TOF2", "l")
551
647
        self.canvas_sp_y.Update()
552
648
        for i in range (3):
553
649
            self.canvas_sp_xy[i].Update()
557
653
    def get_histogram_images(self):       
558
654
        """
559
655
        Get histograms as JSON documents.
560
 
        @param self Object reference.
561
656
        @returns list of 3 JSON documents containing the images.
562
657
        """
563
658
        image_list = []
564
659
 
565
 
        # Raw Hits X
 
660
        # Slab Hits X
566
661
        # file label = tof_hit_x.eps
567
 
        tag = "tof_hit_x"
 
662
        tag = "tof_SlabHits_X"
568
663
        keywords = ["TOF", "raw", "hits"]
569
 
        description = "TOF Raw Hits X"
 
664
        description = "TOF Slab Hits X"
570
665
        doc = ReducePyROOTHistogram.get_image_doc( \
571
666
            self, keywords, description, tag, self.canvas_hits_x)
572
667
        image_list.append(doc)
573
668
 
574
 
        # Raw Hits Y
 
669
        # Slab Hits Y
575
670
        # file label = tof_hit_y.eps
576
 
        tag = "tof_hit_y"
577
 
        description = "TOF Raw Hits Y"
 
671
        tag = "tof_SlabHits_Y"
 
672
        description = "TOF Slab Hits Y"
578
673
        doc = ReducePyROOTHistogram.get_image_doc( \
579
674
            self, keywords, description, tag, self.canvas_hits_y)
580
675
        image_list.append(doc)
586
681
        for plane in range (2):
587
682
            for pmt in range (2):
588
683
                ind = 2*plane + pmt
589
 
                tag = "tof_pmt%d%d" % (plane, pmt)
 
684
                tag = "tof_pmtHits_Plane%dPMT%d" % (plane, pmt)
590
685
                description = "TOF PMT Plane%d PMT%d" % (plane, pmt)
591
686
                doc = ReducePyROOTHistogram.get_image_doc( \
592
687
                    self, keywords, description, tag, self.canvas_pmt[ind])
594
689
 
595
690
        # number of space points
596
691
        # file label = tof_nsp.eps
597
 
        tag = "tof_nsp"
 
692
        tag = "tof_nSpacePoints"
598
693
        keywords = ["TOF", "space", "points"]
599
694
        description = "TOF Number of Space Points"
600
695
        doc = ReducePyROOTHistogram.get_image_doc( \
603
698
 
604
699
        # Spacepoints X
605
700
        # file label = tof_sp_x.eps
606
 
        tag = "tof_sp_x"
 
701
        tag = "tof_SpacePoints_X"
607
702
        description = "TOF Space Points X"
608
703
        doc = ReducePyROOTHistogram.get_image_doc( \
609
704
            self, keywords, description, tag, self.canvas_sp_x)
611
706
 
612
707
        # Spacepoints Y
613
708
        # file label = tof_sp_y.eps
614
 
        tag = "tof_sp_y"
 
709
        tag = "tof_SpacePoints_Y"
615
710
        description = "TOF Space Points Y"
616
711
        doc = ReducePyROOTHistogram.get_image_doc( \
617
712
            self, keywords, description, tag, self.canvas_sp_y)
620
715
        # space point 2d output
621
716
        # the files are labeled: tof_xy_0, tof_xy_1, tof_xy_2 .eps
622
717
        for i in range (3):
623
 
            tag = "tof_xy_%d" % (i)
 
718
            tag = "tof_SpacePoints_XY_tof%d" % (i)
624
719
            description = "TOF%d Space Points 2d" % (i)
625
720
            doc = ReducePyROOTHistogram.get_image_doc( \
626
721
                self, keywords, description, tag, self.canvas_sp_xy[i])
631
726
        keywords = ["TOF", "time", "flight"]
632
727
        for i in range (3):
633
728
            if (i < 2):
634
 
                tag = "tof_time_%d%d" % (i, i+1)
635
 
                description = "TOF%d%d Time" % (i, i+1)
 
729
                tag = "tof_time_tof%d-tof%d" % (i, i+1)
 
730
                description = "TOF%d->TOF%d Time" % (i, i+1)
636
731
            else:
637
 
                tag = "tof_time_02"
638
 
                description = "TOF02 Time"
 
732
                tag = "tof_time_tof0-tof2"
 
733
                description = "TOF0->TOF2 Time"
639
734
            doc = ReducePyROOTHistogram.get_image_doc( \
640
735
                self, keywords, description, tag, self.canvas_tof[i])
641
736
            image_list.append(doc)