Esempio n. 1
0
        print "WARNING: you are trying to hadd more than 1000 files. hadd will proceed by steps of 500 files (otherwise it may silently fail)."
        for istart in range(0,int(float(number)/500+1)):
          command = ""
          command += "hadd "+opt.outputDir+"/plots_"+opt.tag+"_temp"+str(istart)+".root"
          for i in range(istart*500,(istart+1)*500):
            if i>=number: break
            command += " "+opt.outputDir+"/plots_"+opt.tag+"_"+str(i)+".root"
          print command
          os.system(command)
        os.system("hadd "+opt.outputDir+'/plots_'+opt.tag+".root "+opt.outputDir+"/plots_"+opt.tag+"_temp*")


      if not opt.doNotCleanup:
        os.system("rm "+opt.outputDir+'/plots_'+opt.tag+"_temp*.root")
        for i in xrange(number):
          os.system("rm sub"+str(i)+".py")
          os.system("rm "+opt.outputDir+'/plots_'+opt.tag+"_"+str(i)+".root")


    else:
      print "~~~~~~~~~~~ Running mkShape in normal mode..."
      factory = ShapeFactory()
      factory._treeName  = opt.treeName
      factory._energy    = opt.energy
      factory._lumi      = opt.lumi
      factory._tag       = opt.tag
      factory._nThreads  = opt.numThreads
      factory.aliases    = aliases

      factory.makeNominals( opt.inputDir ,opt.outputDir, variables, cuts, samples, nuisances, supercut)
Esempio n. 2
0
        else:
            command.extend(['-j', str(nThreads)])
        command.append(finalpath)
        command.extend(fileList)
        print ' '.join(command)
        if not opt.dryRun:
            subprocess.Popen(command,
                             cwd=os.path.join(os.getcwd(),
                                              opt.outputDir)).communicate()

            outFile = ROOT.TFile.Open(finalpath, 'update')
            for nuisance in nuisances.itervalues():
                if 'kind' in nuisance and (
                        nuisance['kind'].endswith('_envelope')
                        or nuisance['kind'].endswith('_rms')):
                    ShapeFactory.postprocess_nuisance_variations(
                        nuisance, samples, cuts, variables, outFile)
            outFile.Close()

            if not opt.doNotCleanup:
                for fname in fileList:
                    os.unlink(opt.outputDir + '/' + fname)

    elif opt.doHadd != 0 or opt.redoStat != 0:
        ## Fix the MC stat nuisances that are not treated correctly in case of AsMuchAsPossible option
        if ('AsMuchAsPossible' in opt.batchSplit
                and opt.doHadd != 0) or opt.redoStat != 0:
            ## do this only if we want to add the MC stat nuisances in the old way
            if 'stat' in nuisances.keys(
            ) and not nuisances['stat']['samples'] == {}:
                os.chdir(os.getcwd() + "/" + opt.outputDir)
                filein = ROOT.TFile('plots_' + opt.tag + '.root', 'update')
Esempio n. 3
0
            ### Display hadd info
            stoppedForExistingRootfile = False
            while True:
                output = proc.stdout.readline()
                if output == '' and proc.poll() is not None: break
                if output:
                    if 'exists' in output.lower():
                        stoppedForExistingRootfile = True
                    print(output.strip())

            outFile = ROOT.TFile.Open(finalpath, 'update')
            for nuisance in nuisances.itervalues():
                if 'kind' in nuisance and (
                        nuisance['kind'].endswith('_envelope')
                        or nuisance['kind'].endswith('_rms')):
                    ShapeFactory.postprocess_nuisance_variations(
                        nuisance, samples, cuts, variables, outFile)
            outFile.Close()

            if opt.FixNegativeAfterHadd:
                for sampleName, sample in samples.iteritems():
                    if 'suppressNegative' in sample or 'suppressNegativeNuisances' in sample:
                        outFile = ROOT.TFile.Open(finalpath, 'update')
                        ShapeFactory.postprocess_NegativeBinAndError(
                            nuisances, sampleName, sample, cuts, variables,
                            outFile)
                        outFile.Close()

            ### Modded to avoid cleaning all partial shapes if hadd quits because the target rootfile already exists
            if not opt.doNotCleanup and not stoppedForExistingRootfile:
                for fname in fileList:
                    os.unlink(opt.outputDir + '/' + fname)