Example #1
0
  def play(self): 
    
    maxhistos=0
    plots = {}
    for chan in self._work.keys():
      plots[chan] = {}
      if len(self._work[chan]["histograms"]) > maxhistos:
        maxhistos = len(self._work[chan]["histograms"])
      for plot in self._work[chan]["histograms"]:
        plots[chan][plot["name"]] = TH1F(plot["name"], plot["name"], plot['nbins'], plot['xmin'], plot['xmax'])
          


    if not self._batch:
      c=TCanvas();
      c.Divide(maxhistos+1,len(work.keys()));
    read=0
    for event in self.mainchain:
    #for event in self.mainchain:
      try:
        if read < self._first:
          read += 1 
          #print "moving forward"
          continue
        if self._last != -1 and read >= self._last:
          break
        if read%100== 0:
          print "-->read event", read
        waveforms = {}
        for channel in self._work.keys():
          theampl = eval("event."+self._work[channel]['branch_prefix']+"_ampl")
          thetime = eval("event."+self._work[channel]['branch_prefix']+"_time")
          waveforms[channel] = None
          if len(thetime) > 0:
            wf = Waveform(thetime, theampl, channel, 1, self._batch)
            wf.setBaselineLimits(self._work[channel]["baseline"]["limit_low"], self._work[channel]["baseline"]["limit_high"])
            wf.setMaxCalculatorLimits(self._work[channel]["maximum"]["limit_low"], self._work[channel]["maximum"]["limit_high"])
            wf.setAreaCalculatorLimits(self._work[channel]["area"]["limit_low"], self._work[channel]["area"]["limit_high"])
            #wf.setCrossingThresholdSlope(0.5, 'down')
            waveforms[channel] = wf
          del theampl
          del thetime
          
        plots_refs = []
        for i,channel in enumerate(self._work.keys()):
          if waveforms[channel] == None:
            continue
          if self._work[channel]["scaleBy"]!=None:
            waveforms[channel].scaleBy(self._work[channel]["scaleBy"])
          if self._work[channel]["scaleTo"]!="":
            waveforms[channel].scaleTo(waveforms[self._work[channel]["scaleTo"]])
          waveforms[channel].computeAll()
          self._channels[channel]['maximum'][0] = waveforms[channel].content['maximum']['value']
          self._channels[channel]['baseline'][0] = waveforms[channel].content['baseline']['value']
          self._channels[channel]['area'][0] = waveforms[channel].content['area']['value'] 
          self._channels[channel]['timecross'][0] = waveforms[channel].content['crossings']['value']
          
          for plot in self._work[channel]["histograms"]:
            plots[channel][plot["name"]].Fill(waveforms[channel].content[plot['what']]["value"])
        if not self._batch:
          if read%self.drawEvery == 0:    
            for i,channel in enumerate(self._work.keys()): 
              c.cd(i+i*maxhistos+1)
              if waveforms[channel] == None:
                continue;
              o=waveforms[channel].draw(gPad, self._work[channel]["graph"]["ymin"], self._work[channel]["graph"]["ymax"], "h"+str(read))
              plots_refs.append(o)
              for ip, plot in enumerate(self._work[channel]["histograms"]):
                c.cd(i+i*maxhistos+ip+2)
                plots[channel][plot["name"]].Draw()
            c.Update()
        for i,channel in enumerate(self._work.keys()):  
          if waveforms[channel] != None:
            waveforms[channel].clear()
            del waveforms[channel]
        read+=1
        self._summarytree.Fill()

      except KeyboardInterrupt:
        self._out.cd()
        self._summarytree.Write()
        a=raw_input("hit a key to continue...")  

  
       
    self._out.cd()
    self._summarytree.Write()
    if not self._batch:
      a=raw_input("hit a key to continue...")