Example #1
0
 def save(self, dbasename, prefix='', **args):
     """
     Save histograms to data base 
     """
     import KaliCalo.ZipShelve as ZipShelve
     dbase = ZipShelve.open(dbasename, **args)
     for key in self:
         pattern = prefix + 'Lambdas '
         dbase[pattern + str(key)] = (key, self[key])
     dbase.close()
     return len(self)
Example #2
0
 def save(self, dbasename, prefix='', **args):
     """
     Save histograms to data base 
     """
     import KaliCalo.ZipShelve as ZipShelve
     dbase = ZipShelve.open(dbasename, **args)
     for key in self:
         pattern = prefix + 'Histo '
         dbase[pattern + str(key)] = self[key]
     dbase.close()
     ##
     return len(self), self.entries()
Example #3
0
    def read(self, dbasename, prefix='', **args):
        """
        Read the histograms from zipped data base
        """
        ## reset all histos
        self._lambdas = {}
        ##
        import KaliCalo.ZipShelve as ZipShelve
        dbase = ZipShelve.open(dbasename, 'r', **args)
        for key in dbase:
            pattern = prefix + 'Lambdas '
            if 0 != key.find(pattern): continue
            o = dbase[key]
            self._lambdas[o[0]] = o[1]

        dbase.close()
        return len(self)
Example #4
0
    def updateFromDB(self, dbasenames, prefix='', **args):
        """
        Update the histograms from (zipped) data base
        """
        if issubclass(type(dbasenames), str):
            dbasenames = [dbasenames]

        import KaliCalo.ZipShelve as ZipShelve

        for dbasename in dbasenames:
            dbase = ZipShelve.open(dbasename, 'r', **args)
            for key in dbase:
                pattern = prefix + 'Histo '
                if 0 != key.find(pattern): continue
                o = dbase[key]
                if not issubclass(type(o), HistosBase): continue

                if self._histos.has_key(o.cellID()):
                    self._histos[o.cellID()] += o
                else:
                    self._histos[o.cellID()] = o
            dbase.close()

        return len(self), self.entries()
Example #5
0
            nHistos=60  ## number of histograms per core/machine
        )

        ## save the fitted histograms
        print 'SAVE fit_zdb.gz'
        if os.path.exists(FittedHistoPath % i):
            os.remove(FittedHistoPath % i)
        histos.save(FittedHistoPath % i)

        ## save the obtained coefficients
        print 'SAVE lambdas_zdb.gz'
        lambdas.save(LambdasPath % i)
        lambdas.save(LambdasPath % i)

        ## Report problematic cells:
        dbase = ZipShelve.open(ProblemsPath % i)

        ## Print out and save the problematic cells
        print 'BAD-CELLS : #', len(bad)
        dbase['BadCells'] = bad
        for b in bad:
            print 'BadCell : ', b, histos[b].entries()
            key = 'BadCell ' + str(b)
            dbase[key] = histos[b]

        print 'LOW-CELLS : #', len(low)
        dbase['LowCells'] = low
        for b in low:
            print 'LowCell : ', b, histos[b].entries()
            key = 'LowCell ' + str(b)
            dbase[key] = histos[b]
Example #6
0
    print ' Date    : %s ' %   __date__
    print '*'*120  


    ecal = getCalo()

    cp = ecal.cellParams()

    cells = []

    for p in cp :
        cell = p.cellID()
        if ecal.valid ( cell ) and not cell.isPin() :
            cells.append ( cell )

    cells.sort()
    
    import KaliCalo.ZipShelve as ZipShelve
    dbase = ZipShelve.open( 'ecal_db.gz' )
    dbase ['AllEcalCells'] = cells
    dbase.close()

    
    
    
# =============================================================================
# The END 
# =============================================================================


Example #7
0
def CollectLambdas():
    ## all the coefficients databases
    ToCollect = pt.getlambdamaps()
    PrevLams = []
    for i in range(1 + MaxIt / PassIt):
        if LambdasLocation % i in ToCollect:
            ToCollect.remove(LambdasLocation % i)
            PrevLams.append(LambdasLocation % i)
    ToCollect.sort()
    PrevLams.sort()

    ## total database for all of them
    lmap_tot = LambdaMap.LambdaMap()
    if PrevLams:
        lmap_tot.read(PrevLams[-1])
        print PrevLams[-1]
    print PrevLams, len(lmap_tot)

    for ldb in ToCollect:
        print "Adding the coefficients from", ldb
        lmap = LambdaMap.LambdaMap()
        lmap.read(ldb)
        for k in lmap:
            if lmap_tot.has_key(k):
                lmap_tot[k].append(lmap[k][-1] * lmap_tot[k][-1])
            else:
                lmap_tot[k].append(lmap[k][-1])
        print "Removing", ldb
        os.remove(ldb)

    ## find the last one saved and
    ## save current as the next one
    ih = 1
    Pass = 1
    while True:
        print ih, PassIt
        if ih > PassIt / 2:
            Pass += 1
            ih = 1
        if os.path.exists(StoredLambdaPath %
                          (Pass, ih)):  ## look through all the existing files
            print StoredLambdaPath % (Pass, ih), 'exists'
            ih += 1
            continue
        else:  ## write to the file next to the latest existing
            print 'Saving coefficients to ', StoredLambdaPath % (Pass, ih)
            lmap_tot.save(StoredLambdaPath % (Pass, ih))
            os.system('chmod a+rwx ' + StoredLambdaPath % (Pass, ih))
            break

    lmap_tot.save(LambdasLocation % Pass)
    os.system('chmod a+rwx ' + LambdasLocation % (Pass))
    print "Saving coefficients to ", LambdasLocation % Pass

    #lmap_tot.save(pt.lambdas_location_it())

    ## print out the statistics of the coefficients variation
    large = lmap_tot.large(0.15)
    print '# of >15% ', len(large)

    large = lmap_tot.large(0.10)
    print '# of >10% ', len(large)

    large = lmap_tot.large(0.05)
    print '# of > 5% ', len(large)

    large = lmap_tot.large(0.02)
    print '# of > 2% ', len(large)

    large = lmap_tot.large(0.01)
    print '# of > 1% ', len(large)

    #whole_list = {}
    #cf = FakeCells.SameCell()

    #from KaliCalo.Cells import CellID
    #for kk in RealPrsCoefs.keys():
    #    aa = CellID(kk[0],kk[1],kk[2],kk[3])
    #    ic = cf(aa)
    #    if not lmap_tot.has_key(ic): continue
    #    whole_list[aa] = lmap_tot.lambdas()[ic]

    ## create the database for the re-reconstruction
    dbase = zs.open(LambdasDBPath % Pass)
    dbase['ecal'] = lmap_tot.lambdas()
    dbase.close()
    os.system('chmod a+rwx ' + LambdasDBPath % Pass)
Example #8
0
def CollectLambdas():
    ## all the coefficients databases
    ToCollect = pt.getlambdamaps()
    PrevLams = []
    for i in range(1+MaxIt/PassIt):
        if LambdasLocation%i in ToCollect:
            ToCollect.remove(LambdasLocation%i)
            PrevLams.append(LambdasLocation%i)
    ToCollect.sort()
    PrevLams.sort()

    ## total database for all of them
    lmap_tot  = LambdaMap.LambdaMap()
    if PrevLams: lmap_tot.read(PrevLams[-1]); print PrevLams[-1]
    print PrevLams, len(lmap_tot)

    for ldb in ToCollect:
        print "Adding the coefficients from", ldb
        lmap      = LambdaMap.LambdaMap()
        lmap.read(ldb)
        for k in lmap:
            if lmap_tot.has_key(k):
                lmap_tot[k].append(lmap[k][-1]*lmap_tot[k][-1])
            else:
                lmap_tot[k].append(lmap[k][-1])
        print "Removing", ldb
        os.remove(ldb)

    ## find the last one saved and
    ## save current as the next one
    ih   = 1
    Pass = 1
    while True:
        print ih, PassIt
        if ih > PassIt/2:
            Pass += 1
            ih    = 1
        if os.path.exists(StoredLambdaPath%(Pass,ih)): ## look through all the existing files
            print StoredLambdaPath%(Pass,ih), 'exists'
            ih += 1
            continue
        else:                                  ## write to the file next to the latest existing
            print 'Saving coefficients to ', StoredLambdaPath%(Pass,ih)
            lmap_tot.save(StoredLambdaPath%(Pass,ih))
            os.system('chmod a+rwx '+StoredLambdaPath%(Pass,ih))
            break

    lmap_tot.save(LambdasLocation%Pass)
    print "Saving coefficients to ", LambdasLocation%Pass

    #lmap_tot.save(pt.lambdas_location_it())

    ## Print statistics
    #print 'BAD-CELLS : #', len ( bad  ) 
    #print 'LOW-CELLS : #', len ( low  ) 
    #print 'NFIT-CELLS: #', len ( nfit ) 
    ## print out the statistics of the coefficients variation
    large = lmap_tot.large ( 0.15 )
    print '# of >15% ' , len(large)

    large = lmap_tot.large ( 0.10 )
    print '# of >10% ' , len(large)
    
    large = lmap_tot.large ( 0.05 )
    print '# of > 5% ' , len(large)
    
    large = lmap_tot.large ( 0.02 )
    print '# of > 2% ' , len(large)
    
    large = lmap_tot.large ( 0.01 )
    print '# of > 1% ' , len(large)

    ## create the database for the re-reconstruction
    dbase = zs.open(LambdasDBPath%Pass)
    dbase['ecal'] = lmap_tot.lambdas()
    dbase.close()
Example #9
0
                print ' S/B  : %.20s %.20s %.20s ' % (
                    r0[0] / r0[3], r1[0] / r1[3], r2[0] / r2[3]), key
                continue

            print ' %-25s %9.4g  ' % (key, lams[key]), [
                ' %.3f ' % l for l in lambdas[key]
            ]

    dbase_name = 'Ecal_2k+9-Loose-details-zdb'
    histos.save(dbase_name)
    lambdas.save(dbase_name)

    celldb = shelve.open('cells_db', 'r')
    cells = celldb['AllCells']

    lams = lambdas.lambdas()
    map = buildTable(lams, cells, fakeCell)
    prsdbase = ZipShelve.open('prs-2k+9_zdb')
    prs = prsdbase['Prs-2k+9']

    dbase_r_name = 'Ecal_2k+9-Loose-results-zdb'
    dbase = ZipShelve.open(dbase_r_name)
    dbase['Ecal'] = map
    dbase['Prs'] = prs
    dbase['BadCells'] = bad
    dbase['LowCells'] = low

# =============================================================================
# The END
# =============================================================================