Index: fact/tools/pyscripts/tools/fbsl.py
===================================================================
--- fact/tools/pyscripts/tools/fbsl.py	(revision 12813)
+++ fact/tools/pyscripts/tools/fbsl.py	(revision 12813)
@@ -0,0 +1,110 @@
+#!/usr/bin/python
+#
+# Werner Lustermann
+# ETH Zurich
+#
+import numpy as np
+
+import pyfact
+from myhisto import *
+from hist import *
+
+year, month, day = 2011, 11, 24
+year, month, day = str(year), str(month), str(day)
+yyyymmdd = year + month + day
+dfile = '023'
+cfile = '012'
+
+path = '/data03/fact-construction/raw/'
+ext  = '.fits'
+dfname = path + year + '/' + month + '/' + day + '/' + yyyymmdd + '_' + dfile + ext
+
+calfname = path + year + '/' + month + '/' + day + '/' + yyyymmdd + '_' + cfile + '.drs' + ext
+
+resFileName =  yyyymmdd + '_' + dfile + '_' + cfile 
+
+print 'processing files:'
+print 'data:    ', dfname
+print 'drs-cal: ', calfname
+
+rd = pyfact.rawdata( dfname, calfname )
+
+# rd.ReadBaseline( 'histo.root', 'bls_sum/hplt_mean' )
+
+rd.NEvents = 725
+print 'processing N events ', rd.NEvents
+step     = 500
+nsteps   = rd.NEvents / step + 1
+evranges = range(0, (nsteps+1) * step, step)
+
+evranges[-1] = int( rd.NEvents )
+print 'nsteps', nsteps
+print evranges
+
+exit( -1 )
+
+bslMeanValues = np.zeros( ( nsteps, rd.NPIX) )
+
+
+def loopEvents( first, last, hist):
+    """
+    LOOP over all events: Do what you want, here!
+    """
+    for ev in range( first, last ):
+        print 'Event', ev
+        rd.next()
+        # rd.CorrectBaseline()
+        hist.fillall( rd.acalData )
+    
+
+def loopPixel( npix, phist ):
+    vmaxprob = np.zeros( npix )
+    v_rms    = np.zeros( npix )
+
+    for pix in range( npix ):
+    
+        hpix = phist.list[pix]
+    
+        vmaxprob[pix] = hpix.GetXaxis().GetBinCenter( hpix.GetMaximumBin() )
+        bslSummaryHistos.dict['hbsl_mean'].Fill( vmaxprob[pix] )
+        bslSummaryHistos.dict['hplt_mean'].SetBinContent(pix+1, vmaxprob[pix] )
+        
+        v_rms[pix] = hpix.GetRMS()
+        bslSummaryHistos.dict['hbsl_rms'].Fill( v_rms[pix] )
+        bslSummaryHistos.dict['hplt_rms'].SetBinContent( pix+1, v_rms[pix] );
+
+    return vmaxprob
+
+pixhist = hist_array( rd.NPIX, 400, -99.5, 100.5,
+                      'bsl_pix', 'Pixel Baseline',
+                      'sample value in mV', 'Entries / 0.5 mV' )  
+
+for step in range( nsteps ):
+    print step, 'processing events: ', evranges[step], 'to ', evranges[step+1]
+
+    pixstephist = hist_array( rd.NPIX, 400, -99.5, 100.5,
+                          'bsl_pix', 'Pixel Baseline',
+                          'sample value in mV', 'Entries / 0.5 mV' )  
+    loopEvents( evranges[step], evranges[step+1], pixstephist )
+    pixhist.y[:,:] += pixstephist.y[:,:] 
+    pixstephist.SetBinContent()
+
+    bslSummaryHistos = bslHistograms( 'bsl_sum' )
+    bslMeanValues[step,:] = loopPixel( rd.NPIX, pixstephist )
+    print bslMeanValues
+    
+    fname = 'h'+ str( evranges[step] ) + '_to_'+ str( evranges[step+1] ) + '.root'
+    SaveHistograms( [pixstephist, bslSummaryHistos], fname )
+
+    del pixstephist
+    del bslSummaryHistos
+
+pixhist.SetBinContent()
+bslSummaryHistos = bslHistograms( 'bsl_sum' )
+loopPixel( rd.NPIX, pixhist )
+
+fname = 'hbsl.root'
+SaveHistograms( [pixhist, bslSummaryHistos], resFileName + '_bsl.root' )
+
+np.savetxt( resFileName + '_bls.dat', bslMeanValues, fmt = '%8.3f' )
+np.save( resFileName + '_bsl.npy', bslMeanValues )
Index: fact/tools/pyscripts/tools/fbsl1.py
===================================================================
--- fact/tools/pyscripts/tools/fbsl1.py	(revision 12813)
+++ fact/tools/pyscripts/tools/fbsl1.py	(revision 12813)
@@ -0,0 +1,101 @@
+#!/usr/bin/python
+#
+# Werner Lustermann
+# ETH Zurich
+#
+import numpy as np
+
+import pyfact
+from myhisto import *
+from hist import *
+
+run_list = [
+    ['012', '020', '2011', '11', '24'],
+    ['012', '021', '2011', '11', '24'],
+    ['012', '022', '2011', '11', '24'],
+    ['012', '023', '2011', '11', '24'] ]
+
+
+for run in run_list:
+    files = pyfact.fnames( run )
+    print files.specifier
+    files.info()
+    
+exit( -1 )
+
+rd = pyfact.rawdata( dfname, calfname )
+
+# rd.ReadBaseline( 'histo.root', 'bls_sum/hplt_mean' )
+
+# rd.NEvents = 100
+step     = 500
+nsteps   = rd.NEvents / step
+evranges = range(0, (nsteps + 1) * step, step)
+
+evranges[-1] = int( rd.NEvents )
+
+bslMeanValues = np.zeros( ( nsteps, rd.NPIX) )
+
+def loopEvents( first, last, hist):
+    """
+    LOOP over all events: Do what you want, here!
+    """
+    for ev in range( first, last ):
+        print 'Event', ev
+        rd.next()
+        # rd.CorrectBaseline()
+        hist.fillall( rd.acalData )
+    
+
+def loopPixel( npix, phist ):
+    vmaxprob = np.zeros( npix )
+    v_rms    = np.zeros( npix )
+
+    for pix in range( npix ):
+    
+        hpix = phist.list[pix]
+    
+        vmaxprob[pix] = hpix.GetXaxis().GetBinCenter( hpix.GetMaximumBin() )
+        bslSummaryHistos.dict['hbsl_mean'].Fill( vmaxprob[pix] )
+        bslSummaryHistos.dict['hplt_mean'].SetBinContent(pix+1, vmaxprob[pix] )
+        
+        v_rms[pix] = hpix.GetRMS()
+        bslSummaryHistos.dict['hbsl_rms'].Fill( v_rms[pix] )
+        bslSummaryHistos.dict['hplt_rms'].SetBinContent( pix+1, v_rms[pix] );
+
+    return vmaxprob
+
+
+pixhist = hist_array( rd.NPIX, 400, -99.5, 100.5,
+                      'bsl_pix', 'Pixel Baseline',
+                      'sample value in mV', 'Entries / 0.5 mV' )  
+
+for step in range( nsteps ):
+    print step, 'processing events: ', evranges[step], 'to ', evranges[step+1]
+
+    pixstephist = hist_array( rd.NPIX, 400, -99.5, 100.5,
+                          'bsl_pix', 'Pixel Baseline',
+                          'sample value in mV', 'Entries / 0.5 mV' )  
+    loopEvents( evranges[step], evranges[step+1], pixstephist )
+    pixhist.y[:,:] += pixstephist.y[:,:] 
+    pixstephist.SetBinContent()
+
+    bslSummaryHistos = bslHistograms( 'bsl_sum' )
+    bslMeanValues[step,:] = loopPixel( rd.NPIX, pixstephist )
+    print bslMeanValues
+    
+    fname = 'h'+ str( evranges[step] ) + '_to_'+ str( evranges[step+1] ) + '.root'
+    pyfact.SaveHistograms( [pixstephist, bslSummaryHistos], fname )
+
+    del pixstephist
+    del bslSummaryHistos
+
+pixhist.SetBinContent()
+bslSummaryHistos = bslHistograms( 'bsl_sum' )
+loopPixel( rd.NPIX, pixhist )
+
+fname = 'hbsl.root'
+pyfact.SaveHistograms( [pixhist, bslSummaryHistos], resFileName + '_bsl.root' )
+
+np.savetxt( resFileName + '_bls.dat', bslMeanValues, fmt = '%8.3f' )
+np.save( resFileName + '_bsl.npy', bslMeanValues )
Index: fact/tools/pyscripts/tools/fbsl2.py
===================================================================
--- fact/tools/pyscripts/tools/fbsl2.py	(revision 12813)
+++ fact/tools/pyscripts/tools/fbsl2.py	(revision 12813)
@@ -0,0 +1,147 @@
+#!/usr/bin/python
+#
+# Werner Lustermann
+# ETH Zurich
+#
+import numpy as np
+
+import pyfact
+from   myhisto import *
+from   hist    import *
+
+class  baseline_ana( object):
+    """
+    """
+    def __init__( self, fnames = {}, step = 500, bsl_corr = True ):
+        """
+        fnames   : dictionary of strings : run file names
+        step     : integer : number of events to be used for the calculation of a baseline values
+        bsl_corr : bool : apply baseline correction
+
+        self:
+            blsMeanValues : np.array() to store computed baseline values
+        """
+
+        if fnames = {}:
+            print "no file names given for analysis!!!"
+            return (-1) 
+        else:
+            print "analysing data: "
+            fnames.info()
+
+        self.step = step
+        self.bsl_corr = True
+
+        if bsl_corr:
+            print 'apply baseline correction'
+        else:
+            print 'no baseline correction'
+
+        self.bslMeanValues = np.zeros( ( nsteps, rd.NPIX) )
+
+        # create the object providing the rawdata
+        rd = pyfact.rawdata( fnames['data'], fnames['drscal'] )
+        self.nevents = rd.NEvents
+
+        self.steps()
+        
+        # rd.ReadBaseline( 'histo.root', 'bls_sum/hplt_mean' )
+
+        def steps( self ):
+            """ compute the ranges of events
+
+            self:
+                nsteps   : integer : number of ranges the events are devided into
+                evranges : list of range boundaries of length nsteps + 1
+            """
+            
+            nsteps   = self.nevents / self.step
+            evranges = range(0, (nsteps + 1) * self.step, self.step)
+            
+            # add the events of the last incomplete step to the previous once
+            evranges[-1] = int( rd.NEvents )
+
+            self.nsteps   = nsteps
+            self.evranges = evranges
+
+            print 'nevents: ', self.nevents
+            print 'ranges:  ', self.evranges
+
+        def loopEvents( first, last, hist):
+            """
+            LOOP over all events: Do what you want, here!
+            """
+            for ev in range( first, last ):
+                print 'Event', ev
+                rd.next()
+                # rd.CorrectBaseline()
+                hist.fillall( rd.acalData )
+                
+                
+        def loopPixel( npix, phist ):
+            
+            vmaxprob = np.zeros( npix )
+            v_rms    = np.zeros( npix )
+
+            for pix in range( npix ):
+    
+                hpix = phist.list[pix]
+    
+                vmaxprob[pix] = hpix.GetXaxis().GetBinCenter( hpix.GetMaximumBin() )
+                bslSummaryHistos.dict['hbsl_mean'].Fill( vmaxprob[pix] )
+                bslSummaryHistos.dict['hplt_mean'].SetBinContent(pix+1, vmaxprob[pix] )
+                
+                v_rms[pix] = hpix.GetRMS()
+                bslSummaryHistos.dict['hbsl_rms'].Fill( v_rms[pix] )
+                bslSummaryHistos.dict['hplt_rms'].SetBinContent( pix+1, v_rms[pix] );
+                
+            return vmaxprob
+
+
+        def run( self ):
+            """ run the analysis
+            """
+            
+            pixhist = hist_array( rd.NPIX, 400, -99.5, 100.5,
+                                  'bsl_pix', 'Pixel Baseline',
+                                  'sample value in mV', 'Entries / 0.5 mV' )  
+
+            for step in range( self.nsteps ):
+                
+                print self.step, 'processing events: ', self.evranges[ self.step], 'to ',
+                      self.evranges[self.step+1]
+            
+                pixstephist = hist_array( rd.NPIX, 400, -99.5, 100.5,
+                                          'bsl_pix', 'Pixel Baseline',
+                                          'sample value in mV', 'Entries / 0.5 mV' )
+                
+                self.loopEvents( evranges[step], evranges[step+1], pixstephist )
+
+                pixhist.y[:,:] += pixstephist.y[:,:] 
+                pixstephist.SetBinContent()
+            
+                bslSummaryHistos = bslHistograms( 'bsl_sum' )
+                self.bslMeanValues[step,:] = loopPixel( rd.NPIX, pixstephist )
+                # print self.bslMeanValues
+                
+                fname = 'h'+ str( evranges[step] ) + '_to_'+ str( evranges[step+1] ) + '.root'
+                pyfact.SaveHistograms( [pixstephist, bslSummaryHistos], fname )
+    
+                del pixstephist
+                del bslSummaryHistos
+
+            pixhist.SetBinContent()
+
+            bslSummaryHistos = bslHistograms( 'bsl_sum' )    
+            loopPixel( rd.NPIX, pixhist )
+
+            self.save()
+            # fname = 'hbsl.root'
+
+        def save( self ):
+            """ save data after completion of analysis
+            """
+            pyfact.SaveHistograms( [pixhist, bslSummaryHistos], resFileName + '_bsl.root' )
+
+            np.savetxt( resFileName + '_bls.dat', self.bslMeanValues, fmt = '%8.3f' )
+            np.save( resFileName + '_bsl.npy', self.bslMeanValues )
