""" Ckov Online Plots """ # This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus # # MAUS is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # MAUS is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with MAUS. If not, see . #Turns off errors generated by ROOT #pylint: disable = E1101 #pylint: disable=C0103,E1101,C0301 import ROOT from ReducePyROOTHistogram import ReducePyROOTHistogram class ReducePyCkovPlot(ReducePyROOTHistogram): # pylint: disable=R0902 """Class Plots for Ckovs""" def __init__(self): ReducePyROOTHistogram.__init__(self) self._refresh_rate = 1 self.root_batch_mode = 1 ROOT.gErrorIgnoreLevel = 1001 self._tof_cut_e = 27.00 self._tof_cut_mu = 30.00 self._hcharge = None self._htime = None self._htof = None self._htof_A = None self._htof_B = None self.canvas_charge = None self.canvas_time = None self.canvas_tof = None self.canvas_tof_A = None self.canvas_tof_B = None self.run_ended = False def _configure_at_birth(self, config_doc): """Set refresh for Online """ if config_doc: keys = [] keys.append("tof_cut_e") keys.append("tof_cut_mu") keys.append("reduce_plot_refresh_rate") for i in range(len(keys)): if keys[i] in config_doc: self._tof_cut_e = -1e4 self._tof_cut_mu = -1e4 self._refresh_rate = int(config_doc[str(keys[2])]) #if "refresh_rate" in config_doc: # self._refresh_rate = int(config_doc["refresh_rate"]) self.__init_histos() self.run_ended = False return True def _update_histograms(self, data): """Update the Histograms """ daq_evtype = data.GetSpill().GetDaqEventType() if daq_evtype == "end_of_run": if (not self.run_ended): self.update_histos() self.run_ended = True return self.get_histogram_images() else: return [] # do not try to get data from start/end spill markers data_spill = True if daq_evtype == "start_of_run" \ or daq_evtype == "start_of_burst" \ or daq_evtype == "end_of_burst": data_spill = False if data_spill and not self.get_space_points(data): raise ValueError("space points not in spill") # Get charge points & fill histograms. if data_spill and not self.get_charge(data): raise ValueError("charge not in spill") # Refresh canvases at requested frequency. if self.spill_count % self._refresh_rate == 0: self.update_histos() return self.get_histogram_images() else: return [] def get_space_points(self, data):#pylint: disable=R0911,R0912,R0914 """Get space points from Data""" if data.GetSpill().GetReconEventSize() == 0: raise ValueError("recon_events not in spill") reconevents = data.GetSpill().GetReconEvents() # print '# recon events = ',reconevents[0].GetPartEventNumber() for evn in range(data.GetSpill().GetReconEventSize()): # Get the tof event and tof0/tof1 spacepoints tof_event = reconevents[evn].GetTOFEvent() if tof_event is None: raise ValueError("tof_event not in recon_events") # Return if we cannot find slab_hits in the event. tof_spoints = tof_event.GetTOFEventSpacePoint() if tof_spoints is None: return False sp_tof0 = tof_spoints.GetTOF0SpacePointArray() sp_tof1 = tof_spoints.GetTOF1SpacePointArray() # Get ckov event ckov_event = reconevents[evn].GetCkovEvent() if ckov_event is None: raise ValueError("ckov event not in recon events") # Get the ckov digits ckov_digs = ckov_event.GetCkovDigitArray() # Number of photoelectrons in CKOVa and CKOVb PE_B = ckov_digs[0].GetCkovB().GetNumberOfPes() PE_A = ckov_digs[0].GetCkovA().GetNumberOfPes() # npe vs tof-time if sp_tof0 is None or sp_tof1 is None: continue if sp_tof0.size() == 1 and sp_tof1.size() == 1: t_0 = sp_tof0[0].GetTime() t_1 = sp_tof1[0].GetTime() TOF = t_1 - t_0 self._htof.Fill(TOF) #fill Histos if PE_B > 0: self._htof_B.Fill(PE_B, TOF) if PE_A > 0: self._htof_A.Fill(PE_A, TOF) return True def get_charge(self, data): # pylint: disable = R0912, R0915 """Get Ckov digits """ if data.GetSpill().GetReconEventSize() == 0: raise ValueError("recon_events not in spill") reconevents = data.GetSpill().GetReconEvents() # print '# recon events = ',reconevents[0].GetPartEventNumber() for evn in range(data.GetSpill().GetReconEventSize()): # Get ckov event ckov_event = reconevents[evn].GetCkovEvent() if ckov_event is None: raise ValueError("ckov event not in recon events") # Get the ckov digits ckov_digs = ckov_event.GetCkovDigitArray() charge = ckov_digs[0].GetCkovA().GetPulse0() time = ckov_digs[0].GetCkovA().GetArrivalTime0() if charge > -1000: self._hcharge[0].Fill(charge) if time < 255: self._htime[0].Fill(time) charge = ckov_digs[0].GetCkovA().GetPulse1() time = ckov_digs[0].GetCkovA().GetArrivalTime1() if charge > -1000: self._hcharge[1].Fill(charge) if time < 255: self._htime[1].Fill(time) charge = ckov_digs[0].GetCkovA().GetPulse2() time = ckov_digs[0].GetCkovA().GetArrivalTime2() if charge > -1000: self._hcharge[2].Fill(charge) if time < 255: self._htime[2].Fill(time) charge = ckov_digs[0].GetCkovA().GetPulse3() time = ckov_digs[0].GetCkovA().GetArrivalTime3() if charge > -1000: self._hcharge[3].Fill(charge) if time < 255: self._htime[3].Fill(time) charge = ckov_digs[0].GetCkovB().GetPulse4() time = ckov_digs[0].GetCkovB().GetArrivalTime4() if charge > -1000: self._hcharge[4].Fill(charge) if time < 255: self._htime[4].Fill(time) charge = ckov_digs[0].GetCkovB().GetPulse5() time = ckov_digs[0].GetCkovB().GetArrivalTime5() if charge > -1000: self._hcharge[5].Fill(charge) if time < 255: self._htime[5].Fill(time) charge = ckov_digs[0].GetCkovB().GetPulse6() time = ckov_digs[0].GetCkovB().GetArrivalTime6() if charge > -1000: self._hcharge[6].Fill(charge) if time < 255: self._htime[6].Fill(time) charge = ckov_digs[0].GetCkovB().GetPulse7() time = ckov_digs[0].GetCkovB().GetArrivalTime7() if charge > -1000: self._hcharge[7].Fill(charge) if time < 255: self._htime[7].Fill(time) return True def __init_histos(self): #pylint: disable=R0201,R0914,R0915 """Draw Canvases and Histograms """ # have root run quietly without verbose informationals ROOT.gErrorIgnoreLevel = 1001 # white canvas ROOT.gROOT.SetStyle("Plain") #turn off stat box ROOT.gStyle.SetOptStat(0) #sensible color palette ROOT.gStyle.SetPalette(1) # xy grid on canvas ROOT.gStyle.SetPadGridX(1) ROOT.gStyle.SetPadGridY(1) self._hcharge = [] #c_x = 800 #Make Canvas for TOF self.canvas_tof_A = ROOT.TCanvas("tof_A", "tof_A", 600, 600) self._htof_A = ROOT.TH2F("tof_A", "tof_A", 100, 0, 50, 200, 15, 35) self._htof_A.GetXaxis().SetTitle("CkovA PE") self._htof_A.GetYaxis().SetTitle("t(TOF0 to TOF1) (ns)") self.canvas_tof_A.cd() self._htof_A.Draw() self.canvas_tof_B = ROOT.TCanvas("tof_B", "tof_B", 600, 600) self._htof_B = ROOT.TH2F("tof_B", "tof_B", 100, 0, 50, 200, 15, 35) self._htof_B.GetXaxis().SetTitle("CkovB PE") self._htof_B.GetYaxis().SetTitle("t(TOF0 to TOF1) (ns)") self.canvas_tof_B.cd() self._htof_B.Draw() self.canvas_tof = ROOT.TCanvas("tof", "tof", 600, 600) self._htof = ROOT.TH1F("htof", "htof", 100, 10, 40) self._htof.GetXaxis().SetTitle("TOF(ns)") self.canvas_tof.cd() self._htof.Draw() #Make Canvas for PMT Charges self.canvas_charge = ROOT.TCanvas("charge", "charge", 1200, 800) self.canvas_charge.Divide(4, 2) for j in range(0, 8): #ROOT.gPad.SetLogy() hname = "hPMT%d" % (j+1) htitle = "PMT%d" % (j+1) nbins = 500 x_lo = -50 x_hi = 500 self._hcharge.append(ROOT.TH1F(hname, htitle, nbins, x_lo, x_hi)) self._hcharge[j].GetXaxis().SetTitle("Charge") self.canvas_charge.cd(j+1) ROOT.gPad.SetLogy() self._hcharge[j].Draw() #Make Canvas for Arrival Times self._htime = [] self.canvas_time = ROOT.TCanvas("time", "time", 1200, 800) self.canvas_time.Divide(4, 2) for j in range(0, 8): #ROOT.gPad.SetLogy() hname = "harr_time%d" % (j+1) htitle = "Arrival Times%d" % (j+1) nbins = 200 x_lo = 0 x_hi = 200 self._htime.append(ROOT.TH1F(hname, htitle, nbins, x_lo, x_hi)) self._htime[j].GetXaxis().SetTitle("Uncalibrated Time (ns)") self.canvas_time.cd(j+1) self._htime[j].Draw() def update_histos(self): """Update Online Histos """ self.canvas_charge.Update() self.canvas_time.Update() self.canvas_tof.Update() self.canvas_tof_A.Update() self.canvas_tof_B.Update() def get_histogram_images(self): """ Get histograms as JSON documents. @param self Object reference. @returns list of 3 JSON documents containing the images. """ image_list = [] # ROOT # file label = PTM1-8.eps histos = [self._htof, self._htof_A, self._htof_B]+\ self._hcharge+self._htime tag = __name__ content = __name__ doc = ReducePyROOTHistogram.get_root_doc(self, [], content, tag, histos) image_list.append(doc) # PMT Charge # file label = PTM1-8.eps keywords = ['ckov', 'charge', 'pmt'] tag = "CkovCharge_PMT1-8" content = "CkovCharge_PMT1-8" doc = ReducePyROOTHistogram.get_image_doc(self, keywords, content, tag, self.canvas_charge) image_list.append(doc) #ArrivalTimes #file label = ArrivalTime.eps keywords = ['ckov', 'time', 'pmt'] tag = "CkovArrivalTimes_PMT1-8" content = "CkovArrivalTimes_PMT1-8" doc = ReducePyROOTHistogram.get_image_doc(self, keywords, content, tag, self.canvas_time) image_list.append(doc) #Rogers - disabled; duplicates tof reducer output #TOF #file label = "TOF" #keywords = ['ckov', 'tof', 'tof1-tof0'] #tag = "TOF1-TOF0" #content = "TOF1-TOF0" #doc = ReducePyROOTHistogram.get_image_doc(self, keywords, content, tag, self.canvas_tof) #image_list.append(doc) #TOFA and Charge #file label = "TOF_A" keywords = ['ckov', 'tof', 'ckova'] tag = "CkovPE_A_vs_TOF_0_to_1" content = "CkovPE_A_vs_TOF_0_to_1" doc = ReducePyROOTHistogram.get_image_doc(self, keywords, content, tag, self.canvas_tof_A) image_list.append(doc) #TOFB and Charge #file label = "TOF_B" keywords = ['ckov', 'tof', 'ckovb'] tag = "CkovPE_B_vs_TOF_0_to_1" content = "CkovPE_B_vs_TOF_0_to_1" doc = ReducePyROOTHistogram.get_image_doc(self, keywords, content, tag, self.canvas_tof_B) image_list.append(doc) return image_list def _cleanup_at_death(self): """ Reinitialise histograms at death and print out new (empty) images """ self.__init_histos() self.get_histogram_images()