示例#1
0
    def __init__(self, ddPath, noWWddAbove, shape=True, isssactive=False, statmode='unified'):
        self._common       = OrderedDict()
        self._0jetOnly     = OrderedDict()
        self._1jetOnly     = OrderedDict()
        self._ddEstimates  = OrderedDict()
        self._shape        = shape
        self._isssactive   = isssactive
        # to options
        self.statShapeVeto = []
        self.expShapeVeto  = OrderedDict()
        self._statmode     = statmode

        # data driven reader and filter for the ww
        self._ddreader      = datadriven.DDCardReader(ddPath)
        self._wwddfilter    = datadriven.DDWWFilter(self._ddreader, noWWddAbove)
示例#2
0
    def _addShapeNuisances(self, nuisances, effects, opts, suffix, yields):
        # local copy
        shapeNu = OrderedDict()

        self._addWWShapeNuisances(shapeNu, effects)
        self._addInterfShapeNuisances(shapeNu, effects)
        self._addExperimentalShapeNuisances(shapeNu, effects, suffix, yields)

        if 'shapeFlags' not in opts:
            sys.exit(-1)
        flags = opts['shapeFlags']

        nus = set(shapeNu.keys())
        dummy = nus.copy()
        for exp,flag in flags:
            subset = set(fnmatch.filter(nus,exp))
            if flag:
                dummy |= subset
            else:
                dummy -= subset

        for eff in shapeNu:
            if eff not in dummy: continue
            if eff in nuisances: del nuisances[eff]
            nuisances[eff] = shapeNu[eff]
示例#3
0
    def _build(self, paths):
        jsonDir = self.tmpDir+'jsons/'
        lumiDir = self.tmpDir+'lumi/'
        os.system('mkdir -p '+self.tmpDir)
        os.system('mkdir -p '+jsonDir)
        os.system('mkdir -p '+lumiDir)

        (jBase,jExt) = os.path.splitext(self.json)
        self.paths = OrderedDict()
        for p in paths:
            runMin,runMax,hlt = self.pRegex.match(p).group(1,2,3)
            # patch
            json = jsonDir+jBase+'.'+runMin+'-'+runMax+'.'+hlt.replace('*','X')+'.json' if self.splitJson else self.json
            lumi = lumiDir+jBase+'.'+runMin+'-'+runMax+'.'+hlt.replace('*','X')+'.lumi' if self.splitJson else lumiDir+jBase+'.'+hlt.replace('*','X')+'.lumi'
            self.paths[hlt] = dict(
                [('runMin',runMin),
                 ('runMax',runMax),
                 ('json',json),
                 ('lumi',lumi)
                ])
示例#4
0
    print '-'*screenlen(line)



if __name__ == '__main__':
    usage = 'usage: %prog [dir] [cmd]'
    parser = optparse.OptionParser(usage)
    parser.add_option('-a','--all',dest='all',action='store_true',default=False)
    parser.add_option('-d','--diff',dest='diff',action='store_true',help='check different histograms among the files',default=False)
    parser.add_option('-s','--stat',dest='stat',action='store_true',help='check statistics',default=False)
    parser.add_option('-o','--over',dest='over',action='store_true',help='show under/overflow',default=False)
    (opt, args) = parser.parse_args()

    sys.argv.append('-b')

    files = OrderedDict()

    
    entries = OrderedDict()
    for arg in args:
        (file,names,processes) = GetHistPaths(arg)

        if processes and not opt.all:
            hp = [ 'histo_'+p for p in processes]
            names = [ n for n in names if n in hp ]
        
        files[arg] = (file,names,processes)


    if opt.diff:
        for arg,(file,names,processes) in files.iteritems():
示例#5
0
            hPrescaledLumiFraction.Write()





if __name__ == '__main__':
    motherJson='certifiedToScan.json'
    cwd = os.getcwd()
    tmpDir  = cwd+'/psdata/'


    allPaths = OrderedDict([
        ('singleMu',singleMuDataPaths),
#         ('singleEl',singleElDataPaths),
#         ('doubleEl',doubleElDataPaths),
#         ('doubleMu',doubleMuDataPaths),
#         ('muEg',muEGDataPaths),
    ])

    out = ROOT.TFile.Open('psPlots.root','recreate')
    for p,list in allPaths.iteritems():
        s = Scanner(p,list,motherJson,tmpDir)
        s.analyze()
        s.details(p)
        s.summarize(p)
        s.makeplots(out)
    out.Close()
    sys.exit(0)

示例#6
0
                      default=None)
    parser.add_option('-o',
                      '--out',
                      dest='out',
                      help='Output directory',
                      default=None)

    (opt, args) = parser.parse_args()
    if not opt.tag:
        parser.print_help()
        parser.error('Tag not defined, check the usage')

    sys.argv.append('-b')
    ROOT.gROOT.SetBatch()

    decks = OrderedDict()
    for arg in args:
        if '=' not in arg:
            decks[os.path.basename(arg if arg[-1] != '/' else arg[:-1])] = arg
            continue

        i = arg.index('=')
        decks[arg[:i]] = arg[i + 1:]

    print decks
    doexist = zip(map(os.path.exists, decks.itervalues()), decks.itervalues())

    dontexist = filter(lambda x: not x[0], doexist)

    if dontexist:
        raise ValueError('workareas not found:' +
示例#7
0
    def nuisances(self, yields, effects, mass, channel, jetcat, flavor, opts ):
        '''Add the nuisances according to the options'''
        allNus = OrderedDict()

        optMatt = mattOpts()
        optMatt.WJadd = 0.36
        optMatt.WJsub = 0.0

        qqWWfromData = self._wwddfilter.haswwdd(mass, channel)

        # vh and vbf and wwewk mapped to "2j" category
        if (jetcat == 'vh2j' or jetcat == 'whsc' or jetcat == '2jtche05' or jetcat == '2jtche05CJ' or jetcat == '2jtche05FJ') :
           jetcat = '2j'

        # vh : remove some nuisances, typical of vbf only
        if (jetcat == 'vh2j' or jetcat == 'whsc') :
           optMatt.VH = 1
        else :
           optMatt.VH = 0

        optMatt.HWidth = 0
        if 'SpecialSettings' in opts:
           if opts['SpecialSettings'] == 'HWidth' :
             optMatt.HWidth = 1

        optMatt.WWxsec = 0
        if 'SpecialSettings' in opts:
           if opts['SpecialSettings'] == 'WWxsec' :
             optMatt.WWxsec = 1




        if jetcat not in ['0j','1j','2j','2jex','01j']: raise ValueError('Unsupported jet category found: %s')

#         suffix = '_8TeV'
#         if '2011' in opt.dataset: suffix = '_7TeV'

        suffix = '_'+opt.energy
        CutBased = getCommonSysts(int(mass),flavor,int(jetcat[0]),qqWWfromData, self._shape, optMatt, suffix, self._isssactive, opt.energy,opts['newInterf'],opt.YRSysVer,opt.mHSM,125.0,opts['ewksinglet'])
        if self._shape:
            # float WW+ggWW background normalisation float together
#             for p in opts['floatN'].split(' '):
            for p in opts['floatN']:
                print p
                floatN = floatNorm(p,jetcat)
                CutBased.update( floatN )

        common = OrderedDict()
        for k in sorted(CutBased):
            common[k] = CutBased[k]
        allNus.update( common )


        # only if not bin-by-bin, then add statistical uncertainty
        # for bbb it is already included
        if self._statmode != 'bybin':
            self._addStatisticalNuisances(allNus, yields, channel, suffix)

        self._addDataDrivenNuisances(allNus, yields, mass, channel, jetcat, suffix, opts)

        if self._shape:
            self._addShapeNuisances(allNus,effects, opts, suffix, yields)

        if 'nuisFlags' not in opts:
            raise RuntimeError('nuisFlags not found among the allNus options')

        flags = opts['nuisFlags']

        finalNuisances = OrderedDict()
        nus = set(allNus.keys())
        dummy = nus.copy()
        for exp,flag in flags:
            subset = set(fnmatch.filter(nus,exp))
            if flag:
                dummy |= subset
            else:
                dummy -= subset

        nuisances = OrderedDict()
        for eff in allNus:
            if eff not in dummy: continue
            nuisances[eff] = allNus[eff]

        return nuisances
示例#8
0
 def __init__(self, path):
     self._src = ROOT.TFile.Open(path)
     self._yields = OrderedDict()
示例#9
0
    #             for flavor in flavors:
                print '- Processing',mass, ch
                loader = ShapeLoader(shapeTmpl.format(mass = mass, channel=ch) ) 
                loader.load()
    
                writer = ShapeDatacardWriter( mass, ch, opt.shape, opt.dataset )
                print '   + loading yields'
                yields = loader.yields()
    
                # reshuffle the order
                #order = [ 'vbfH', 'ggH', 'wzttH', 'ggWW', 'Vg', 'WJet', 'Top', 'WW', 'DYLL', 'VV', 'DYTT', 'Data']
                order = [ 'ggH','ggH_ALT','qqH','qqH_ALT', 'wzttH','wzttH_ALT', 'WH', 'ZH', 'ttH', 'ggWW', 'VgS', 'Vg', 'WJet', 'Top', 'TopPt0', 'TopPt1', 'TopPt2', 'TopPt3', 'TopPt4', 'TopPt5', 'TopPt6', 'TopPt7', 'TopPt8', 'WW', 'WWlow', 'WWhigh', 'WW1', 'WW2', 'WW3', 'WW4', 'WW5', 'WW6',  'WWewk', 'DYLL', 'VV', 'DYTT', 'DYee', 'DYmm', 'DYee05', 'DYmm05', 'Other', 'VVV', 'Data','ggH_SM', 'qqH_SM', 'WH_SM','ZH_SM' , 'wzttH_SM', 'ggH_sbi', 'ggH_s', 'ggH_b', 'qqH_sbi', 'qqH_s', 'qqH_b' ]
    
   
                oldYields = yields.copy()
                yields = OrderedDict([ (k,oldYields[k]) for k in order if k in oldYields])
                
                # lista systematiche sperimentali (dal file. root)
                effects = loader.effects()

                print '   + making nuisance map'
                nuisances = builder.nuisances( yields, effects , mass, ch, jcat, fl, optsNuis)
    
                for n,(pdf, eff) in nuisances.iteritems():
                    if 'ggH' in eff and 'shape' not in pdf[0] and 'stat_bin' not in n :
                        eff['ggH_ALT'] =  eff['ggH']
                    if 'qqH' in eff and 'shape' not in pdf[0] and 'stat_bin' not in n :
                        eff['qqH_ALT'] =  eff['qqH']
                    if 'wzttH' in eff and 'shape' not in pdf[0] and 'stat_bin' not in n :
                        eff['wzttH_ALT'] =  eff['wzttH']
    
示例#10
0
            # nominal shapes
            print factory.makeNominals(variable,selection,nomInputDir,nomOutDir+nominalOutFile)

        if opt.makeSyst:
            class Systematics:
                def __init__(self,name,nick,indir,mask):
                    pass
            # systematic shapes
            systematics = OrderedDict([
                ('electronResolution'      , 'p_res_e'),
                ('electronScale_down'      , 'p_scale_eDown'),
                ('electronScale_up'        , 'p_scale_eUp'),
                ('jetEnergyScale_down'     , 'p_scale_jDown'),
                ('jetEnergyScale_up'       , 'p_scale_jUp'),
                ('leptonEfficiency_down'   , 'eff_lDown'),
                ('leptonEfficiency_up'     , 'eff_lUp'),
                ('puW_up'                  , 'puModelUp'),
                ('puW_down'                , 'puModelDown'),
                ('metResolution'           , 'met'),
                ('muonScale_down'          , 'p_scale_mDown'),
                ('muonScale_up'            , 'p_scale_mUp'),
                ('chargeResolution'        , 'ch_res'),
            ])

            # remove skip-syst list
#             if opt.skipSyst!='':
#                for s in opt.skipSyst.split(','):
            for s in opt.skipSyst:
              print 'skipping systematics: '+s
              systematics.pop(s)