Exemplo n.º 1
0
def plot_plots():

    # Load the fits
    fInFit = ROOT.TFile.Open(opt.inputFitFile,'READ')
    ACFits={}
    for iCut in cuts:
      fInFit.cd()
      ACFits[iCut] = {}
      for iVar in variables :
        ACFits[iCut][iVar] = {}
        for iDim in ['1D','2D'] :
          if iDim == '1D' : separator = '_par1_'
          if iDim == '2D' : separator = '_par2_'
          if iDim in acoupling['ScanConfig'] and len(acoupling['ScanConfig'][iDim]) > 0 :
            for iScan in acoupling['ScanConfig'][iDim]:
              ACFits[iCut][iVar][iScan.replace(":","_")] = {}
              fInFit.cd(iCut+'/'+iVar+'/'+iScan.replace(":","_"))
              keyList = ROOT.gDirectory.GetListOfKeys()
              for key in keyList:
                obj = key.ReadObj()
                if 'TF' in  obj.ClassName() : ACFits[iCut][iVar][iScan.replace(":","_")][int(obj.GetName().split(separator)[1])] = obj

    # And Read Plots + Create AC Plots
    fInPlot = ROOT.TFile.Open(opt.inputPlotFile,'READ')
    fOut    = ROOT.TFile.Open(opt.inputPlotFile.replace('.root','_ACPlots.root'),'RECREATE')

    # ... Get signal name
    sigName =''
    nSignal=0
    for iSample in structure:
      if structure[iSample]['isSignal'] == 1: 
        sigName = iSample
        nSignal+=1
    if nSignal == 1 : 
      print '---> sigName = ',sigName 
    else:
      print '---> No signal FOUND !!!!'
      exit()

    # ... Clone histograms 
    SigNames = {}
    for iCut in cuts:
      fOut.mkdir(iCut)
      for iVar in variables :
        print '-------------- ',iCut,iVar
        fOut.mkdir(iCut+'/'+iVar)
        fInPlot.cd(iCut+'/'+iVar)
        keyList = ROOT.gDirectory.GetListOfKeys()
        fOut.cd(iCut+'/'+iVar)
        foundSignal = False
        for key in keyList:
          obj = key.ReadObj()
          hclone = obj.Clone()
          hclone.Write()
          if obj.GetName() == 'histo_'+sigName :
            foundSignal = True
            sigObj      = obj
        if foundSignal :
          for iDim in ['1D','2D'] :
            if iDim in acoupling['PlotConfig'] and len(acoupling['PlotConfig'][iDim]) > 0 :
              for iPlot in acoupling['PlotConfig'][iDim]:
                print '---> Creating: ',iPlot,' : ',acoupling['PlotConfig'][iDim][iPlot]
                if iDim == '1D' : 
                   hName  = 'histo_ACSig_'+iPlot+str(acoupling['PlotConfig'][iDim][iPlot][0]).replace('.','p').replace('-','m')
                   Legend = acoupling['operatorLatex'][iPlot]+' = '+str(acoupling['PlotConfig'][iDim][iPlot][0])+' '+acoupling['operatorUnit'][iPlot]  
                   Color  = int(acoupling['PlotConfig'][iDim][iPlot][1]) 
                if iDim == '2D' : 
                   hName = 'histo_ACSig_'+iPlot.split(':')[0]+str(acoupling['PlotConfig'][iDim][iPlot][0]).replace('.','p').replace('-','m')+'_'+iPlot.split(':')[1]+str(acoupling['PlotConfig'][iDim][iPlot][1]).replace('.','p').replace('-','m')
                   Legend = acoupling['operatorLatex'][iPlot.split(':')[0]]+' = '+str(acoupling['PlotConfig'][iDim][iPlot][0])+' '+acoupling['operatorUnit'][iPlot.split(':')[0]]+' , '+ \
                            acoupling['operatorLatex'][iPlot.split(':')[1]]+' = '+str(acoupling['PlotConfig'][iDim][iPlot][1])+' '+acoupling['operatorUnit'][iPlot.split(':')[1]]  
                   Color  = int(acoupling['PlotConfig'][iDim][iPlot][2]) 
                SigNames[hName.replace('histo_','')] = {
                                                         'Legend' : Legend ,
                                                         'Color'  : Color
                                                       }
                hclone = sigObj.Clone(hName)
                hclone.SetName(hName)
                for iBin in range(1,hclone.GetNbinsX()+1):
                  ratio = 1
                  if iDim == '1D' : ratio = ACFits[iCut][iVar][iPlot.replace(":","_")][iBin].Eval(acoupling['PlotConfig'][iDim][iPlot][0])
                  if iDim == '2D' : ratio = ACFits[iCut][iVar][iPlot.replace(":","_")][iBin].Eval(acoupling['PlotConfig'][iDim][iPlot][0],acoupling['PlotConfig'][iDim][iPlot][1])
                  hclone.SetBinContent(iBin,hclone.GetBinContent(iBin)*(ratio-1.))
                  hclone.SetBinError(iBin,hclone.GetBinError(iBin)*(ratio-1.))
                hclone.Print()     
                hclone.Write() 
        fOut.cd()

    # Close All Files
    fInFit.Close()
    fInPlot.Close()
    fOut.Close()

    # (Re-)create dictionnary for plotting

    samples2plot   = {}
    plot2plot      = {}
    groupPlot2plot = OrderedDict()   
    
    for iSample in structure:
      samples2plot[iSample] = {}

    for iSample in plot:
      plot2plot[iSample] = plot[iSample]
      plot2plot[iSample]['isSignal'] = 0

    for iGroup in  groupPlot:
      groupPlot2plot[iGroup] = groupPlot[iGroup]
      groupPlot2plot[iGroup]['isSignal'] = 0

    
#   for iSig in SigNames:
#     print iSig , ' ' , SigNames[iSig] 
#     samples2plot[iSig] = {}
#     plot2plot[iSig] = { 
#                        'color'    : SigNames[iSig]['Color'],
#                        'isSignal' : 2,
#                        'isData'   : 0,
#                        'scale'    : 1. 
#                       }
#     groupPlot2plot[iSig] = {
#                             'nameHR' : SigNames[iSig]['Legend'],
#                             'isSignal' : 2,
#                             'color': SigNames[iSig]['Color'],  #  kGreen+2
#                             'samples'  : [iSig]
#                            }

    print samples2plot
    print plot2plot
    print groupPlot2plot

    # Create the PlotFactory and execute it

    ROOT.gROOT.SetBatch()

    for iSig in SigNames:
      print iSig , ' ' , SigNames[iSig]
      samples2plot[iSig] = {}
      plot2plot[iSig] = {
                         'color'    : SigNames[iSig]['Color'],
                         'isSignal' : 2,
                         'isData'   : 0,
                         'scale'    : 1.
                        }
      groupPlot2plot[iSig] = {
                              'nameHR' : SigNames[iSig]['Legend'],
                              'isSignal' : 1,
                              'color': SigNames[iSig]['Color'],  #  kGreen+2
                              'samples'  : [iSig]
                             }

      factory = PlotFactory()
      factory._energy    = opt.energy
      factory._lumi      = opt.lumi
      factory._plotNormalizedDistributions = opt.plotNormalizedDistributions
      factory._showIntegralLegend = opt.showIntegralLegend

      factory._scaleToPlot = opt.scaleToPlot
      factory._minLogC = opt.minLogC
      factory._maxLogC = opt.maxLogC
      factory._minLogCratio = opt.minLogCratio
      factory._maxLogCratio = opt.maxLogCratio
      factory._maxLinearScale = opt.maxLinearScale

      factory._minLogCdifference = opt.minLogCratio
      factory._maxLogCdifference = opt.maxLogCratio

      factory._showRelativeRatio = opt.showRelativeRatio
      factory._showDataMinusBkgOnly = opt.showDataMinusBkgOnly

      factory._removeWeight = opt.removeWeight

      factory._invertXY = opt.invertXY

      factory._FigNamePF = '_'+iSig

      factory.makePlot( opt.inputPlotFile.replace('.root','_ACPlots.root') ,opt.outputDirPlots+'_ACPlots', variables, cuts, samples2plot, plot2plot, nuisances, legend, groupPlot2plot)

      del samples2plot[iSig]
      del plot2plot[iSig]
      del groupPlot2plot[iSig]
      del factory
Exemplo n.º 2
0
    opt.minLogC = float(opt.minLogC)
    opt.maxLogC = float(opt.maxLogC)

    opt.minLogCratio = float(opt.minLogCratio)
    opt.maxLogCratio = float(opt.maxLogCratio)

    if not opt.debug:
        pass
    elif opt.debug == 2:
        print 'Logging level set to DEBUG (%d)' % opt.debug
        logging.basicConfig(level=logging.DEBUG)
    elif opt.debug == 1:
        print 'Logging level set to INFO (%d)' % opt.debug
        logging.basicConfig(level=logging.INFO)

    factory = PlotFactory()
    factory._energy = opt.energy
    factory._lumi = opt.lumi
    factory._plotNormalizedDistributions = opt.plotNormalizedDistributions
    factory._showIntegralLegend = opt.showIntegralLegend

    factory._scaleToPlot = opt.scaleToPlot
    factory._minLogC = opt.minLogC
    factory._maxLogC = opt.maxLogC
    factory._minLogCratio = opt.minLogCratio
    factory._maxLogCratio = opt.maxLogCratio
    factory._maxLinearScale = opt.maxLinearScale

    factory._minLogCdifference = opt.minLogCratio
    factory._maxLogCdifference = opt.maxLogCratio
Exemplo n.º 3
0
def plot_plots():

    # Load the fits
    fInFit = ROOT.TFile.Open(opt.inputFitFile, 'READ')
    ACFits = {}
    for iCut in cuts:
        fInFit.cd()
        ACFits[iCut] = {}
        for iVar in variables:
            ACFits[iCut][iVar] = {}
            for iDim in ['1D', '2D']:
                if iDim == '1D': separator = '_par1_'
                if iDim == '2D': separator = '_par2_'
                if iDim in acoupling['ScanConfig'] and len(
                        acoupling['ScanConfig'][iDim]) > 0:
                    for iScan in acoupling['ScanConfig'][iDim]:
                        ACFits[iCut][iVar][iScan.replace(":", "_")] = {}
                        fInFit.cd(iCut + '/' + iVar + '/' +
                                  iScan.replace(":", "_"))
                        keyList = ROOT.gDirectory.GetListOfKeys()
                        for key in keyList:
                            obj = key.ReadObj()
                            if 'TF' in obj.ClassName():
                                ACFits[iCut][iVar][iScan.replace(
                                    ":", "_")][int(obj.GetName().split(
                                        separator)[1])] = obj

    # And Read Plots + Create AC Plots
    fInPlot = ROOT.TFile.Open(opt.inputPlotFile, 'READ')
    fOut = ROOT.TFile.Open(opt.inputPlotFile.replace('.root', '_ACPlots.root'),
                           'RECREATE')

    # ... Get signal name
    sigName = ''
    nSignal = 0
    for iSample in structure:
        if structure[iSample]['isSignal'] == 1:
            sigName = iSample
            nSignal += 1
    if nSignal == 1:
        print '---> sigName = ', sigName
    else:
        print '---> No signal FOUND !!!!'
        exit()

    # ... Clone histograms
    SigNames = {}
    for iCut in cuts:
        fOut.mkdir(iCut)
        for iVar in variables:
            print '-------------- ', iCut, iVar
            fOut.mkdir(iCut + '/' + iVar)
            fInPlot.cd(iCut + '/' + iVar)
            keyList = ROOT.gDirectory.GetListOfKeys()
            fOut.cd(iCut + '/' + iVar)
            foundSignal = False
            for key in keyList:
                obj = key.ReadObj()
                hclone = obj.Clone()
                hclone.Write()
                if obj.GetName() == 'histo_' + sigName:
                    foundSignal = True
                    sigObj = obj
            if foundSignal:
                for iDim in ['1D', '2D']:
                    if iDim in acoupling['PlotConfig'] and len(
                            acoupling['PlotConfig'][iDim]) > 0:
                        for iPlot in acoupling['PlotConfig'][iDim]:
                            print '---> Creating: ', iPlot, ' : ', acoupling[
                                'PlotConfig'][iDim][iPlot]
                            if iDim == '1D':
                                hName = 'histo_ACSig_' + iPlot + str(
                                    acoupling['PlotConfig'][iDim][iPlot]
                                    [0]).replace('.', 'p').replace('-', 'm')
                                Legend = acoupling['operatorLatex'][
                                    iPlot] + ' = ' + str(
                                        acoupling['PlotConfig'][iDim][iPlot][0]
                                    ) + ' ' + acoupling['operatorUnit'][iPlot]
                                Color = int(
                                    acoupling['PlotConfig'][iDim][iPlot][1])
                            if iDim == '2D':
                                hName = 'histo_ACSig_' + iPlot.split(
                                    ':')[0] + str(
                                        acoupling['PlotConfig'][iDim][iPlot][0]
                                    ).replace('.', 'p').replace(
                                        '-',
                                        'm') + '_' + iPlot.split(':')[1] + str(
                                            acoupling['PlotConfig']
                                            [iDim][iPlot][1]).replace(
                                                '.', 'p').replace('-', 'm')
                                Legend = acoupling['operatorLatex'][iPlot.split(':')[0]]+' = '+str(acoupling['PlotConfig'][iDim][iPlot][0])+' '+acoupling['operatorUnit'][iPlot.split(':')[0]]+' , '+ \
                                         acoupling['operatorLatex'][iPlot.split(':')[1]]+' = '+str(acoupling['PlotConfig'][iDim][iPlot][1])+' '+acoupling['operatorUnit'][iPlot.split(':')[1]]
                                Color = int(
                                    acoupling['PlotConfig'][iDim][iPlot][2])
                            SigNames[hName.replace('histo_', '')] = {
                                'Legend': Legend,
                                'Color': Color
                            }
                            hclone = sigObj.Clone(hName)
                            hclone.SetName(hName)
                            for iBin in range(1, hclone.GetNbinsX() + 1):
                                ratio = 1
                                if iDim == '1D':
                                    ratio = ACFits[iCut][iVar][iPlot.replace(
                                        ":", "_")][iBin].Eval(
                                            acoupling['PlotConfig'][iDim]
                                            [iPlot][0])
                                if iDim == '2D':
                                    ratio = ACFits[iCut][iVar][iPlot.replace(
                                        ":", "_")][iBin].Eval(
                                            acoupling['PlotConfig'][iDim]
                                            [iPlot][0], acoupling['PlotConfig']
                                            [iDim][iPlot][1])
                                hclone.SetBinContent(
                                    iBin,
                                    hclone.GetBinContent(iBin) * (ratio - 1.))
                                hclone.SetBinError(
                                    iBin,
                                    hclone.GetBinError(iBin) * (ratio - 1.))
                            hclone.Print()
                            hclone.Write()
            fOut.cd()

    # Close All Files
    fInFit.Close()
    fInPlot.Close()
    fOut.Close()

    # (Re-)create dictionnary for plotting

    samples2plot = {}
    plot2plot = {}
    groupPlot2plot = OrderedDict()

    for iSample in structure:
        samples2plot[iSample] = {}

    for iSample in plot:
        plot2plot[iSample] = plot[iSample]
        plot2plot[iSample]['isSignal'] = 0

    for iGroup in groupPlot:
        groupPlot2plot[iGroup] = groupPlot[iGroup]
        groupPlot2plot[iGroup]['isSignal'] = 0


#   for iSig in SigNames:
#     print iSig , ' ' , SigNames[iSig]
#     samples2plot[iSig] = {}
#     plot2plot[iSig] = {
#                        'color'    : SigNames[iSig]['Color'],
#                        'isSignal' : 2,
#                        'isData'   : 0,
#                        'scale'    : 1.
#                       }
#     groupPlot2plot[iSig] = {
#                             'nameHR' : SigNames[iSig]['Legend'],
#                             'isSignal' : 2,
#                             'color': SigNames[iSig]['Color'],  #  kGreen+2
#                             'samples'  : [iSig]
#                            }

    print samples2plot
    print plot2plot
    print groupPlot2plot

    # Create the PlotFactory and execute it

    ROOT.gROOT.SetBatch()

    for iSig in SigNames:
        print iSig, ' ', SigNames[iSig]
        samples2plot[iSig] = {}
        plot2plot[iSig] = {
            'color': SigNames[iSig]['Color'],
            'isSignal': 2,
            'isData': 0,
            'scale': 1.
        }
        groupPlot2plot[iSig] = {
            'nameHR': SigNames[iSig]['Legend'],
            'isSignal': 1,
            'color': SigNames[iSig]['Color'],  #  kGreen+2
            'samples': [iSig]
        }

        factory = PlotFactory()
        factory._energy = opt.energy
        factory._lumi = opt.lumi
        factory._plotNormalizedDistributions = opt.plotNormalizedDistributions
        factory._showIntegralLegend = opt.showIntegralLegend

        factory._scaleToPlot = opt.scaleToPlot
        factory._minLogC = opt.minLogC
        factory._maxLogC = opt.maxLogC
        factory._minLogCratio = opt.minLogCratio
        factory._maxLogCratio = opt.maxLogCratio
        factory._maxLinearScale = opt.maxLinearScale

        factory._minLogCdifference = opt.minLogCratio
        factory._maxLogCdifference = opt.maxLogCratio

        factory._showRelativeRatio = opt.showRelativeRatio
        factory._showDataMinusBkgOnly = opt.showDataMinusBkgOnly

        factory._removeWeight = opt.removeWeight

        factory._invertXY = opt.invertXY

        factory._FigNamePF = '_' + iSig

        factory.makePlot(opt.inputPlotFile.replace('.root', '_ACPlots.root'),
                         opt.outputDirPlots + '_ACPlots', variables, cuts,
                         samples2plot, plot2plot, nuisances, legend,
                         groupPlot2plot)

        del samples2plot[iSig]
        del plot2plot[iSig]
        del groupPlot2plot[iSig]
        del factory
Exemplo n.º 4
0
    opt.minLogC = float(opt.minLogC)
    opt.maxLogC = float(opt.maxLogC)

    opt.minLogCratio = float(opt.minLogCratio)
    opt.maxLogCratio = float(opt.maxLogCratio)

    if not opt.debug:
        pass
    elif opt.debug == 2:
        print 'Logging level set to DEBUG (%d)' % opt.debug
        logging.basicConfig(level=logging.DEBUG)
    elif opt.debug == 1:
        print 'Logging level set to INFO (%d)' % opt.debug
        logging.basicConfig(level=logging.INFO)

    factory = PlotFactory()
    factory._tag = opt.tag
    factory._energy = opt.energy
    factory._lumi = opt.lumi
    factory._plotNormalizedDistributions = opt.plotNormalizedDistributions
    factory._plotNormalizedIncludeData = opt.plotNormalizedIncludeData
    factory._plotNormalizedDistributionsTHstack = opt.plotNormalizedDistributionsTHstack
    factory._showIntegralLegend = opt.showIntegralLegend

    if opt.onlyPlot is not None:
        factory._plotsToWrite = opt.onlyPlot.split(',')
    factory._plotLinear = opt.linearOnly or not opt.logOnly
    factory._plotLog = opt.logOnly or not opt.linearOnly

    factory._scaleToPlot = opt.scaleToPlot
    factory._minLogC = opt.minLogC
Exemplo n.º 5
0
    opt.maxLogC = float(opt.maxLogC)

    opt.minLogCratio = float(opt.minLogCratio)
    opt.maxLogCratio = float(opt.maxLogCratio)

    if not opt.debug:
        pass
    elif opt.debug == 2:
        print 'Logging level set to DEBUG (%d)' % opt.debug
        logging.basicConfig( level=logging.DEBUG )
    elif opt.debug == 1:
        print 'Logging level set to INFO (%d)' % opt.debug
        logging.basicConfig( level=logging.INFO )

      
    factory = PlotFactory()
    factory._tag       = opt.tag
    factory._energy    = opt.energy
    factory._lumi      = opt.lumi
    factory._plotNormalizedDistributions = opt.plotNormalizedDistributions
    factory._showIntegralLegend = opt.showIntegralLegend
    
    factory._scaleToPlot = opt.scaleToPlot 
    factory._minLogC = opt.minLogC 
    factory._maxLogC = opt.maxLogC 
    factory._minLogCratio = opt.minLogCratio
    factory._maxLogCratio = opt.maxLogCratio
    factory._maxLinearScale = opt.maxLinearScale

    factory._minLogCdifference = opt.minLogCratio
    factory._maxLogCdifference = opt.maxLogCratio