def main():
    datasetsEmb = DatasetsMany(dirEmbs, analysisEmb+"Counters", normalizeMCByLuminosity=False)
    datasetsSig = dataset.getDatasetsFromMulticrabCfg(cfgfile=dirSig+"/multicrab.cfg", counters=analysisSig+"Counters")
    datasetsEmb.forEach(lambda d: d.mergeData())
    datasetsEmb.setLumiFromData()

#    nonDyMc = ["QCD_Pt20_MuEnriched", "WJets", "TTJets", "SingleTop", "Diboson"]
#    datasetsEmb.remove(nonDyMc)
#    datasetsSig.remove(nonDyMc)

    tauEmbedding.normalize=True
    tauEmbedding.era = "Run2011A"


    taskDir = multicrab.createTaskDir("embedded")

    f = open(os.path.join(taskDir, "codeVersion.txt"), "w")
    f.write(git.getCommitId()+"\n")
    f.close()
    f = open(os.path.join(taskDir, "codeStatus.txt"), "w")
    f.write(git.getStatus()+"\n")
    f.close()
    f = open(os.path.join(taskDir, "codeDiff.txt"), "w")
    f.write(git.getDiff()+"\n")
    f.close()
    f = open(os.path.join(taskDir, "inputInfo.txt"), "w")
    f.write("Embedded directories:\n%s\n\nNormal directory:\n%s\n" % ("\n".join(dirEmbs), dirSig))
    f.write("\nEmbedded analysis: %s\nNormal analysis: %s\n" % (analysisEmb, analysisSig))
    f.close()

    operate = lambda dn: operateDataset(taskDir, datasetsEmb, datasetsSig, dn)

    operate("Data")
    operate("DYJetsToLL_M50_TuneZ2_Summer11")
    operate("WW_TuneZ2_Summer11")
Esempio n. 2
0
def main(opts):
    mc_conf_file = opts.cfgfile
    crab_conf_file = None
    py_conf_file = None
    json_files = []

    if not os.path.exists(mc_conf_file):
        print "Multicrab configuration file %s doesn't exist!" % mc_conf_file
        return 1

    mc_parser = ConfigParser.ConfigParser()
    mc_parser.read(mc_conf_file)
    crab_conf_file = mc_parser.get("MULTICRAB", "cfg")
    try:
        py_conf_file = mc_parser.get("COMMON", "CMSSW.pset")
    except ConfigParser.NoOptionError:
        pass
    for s in mc_parser.sections():
        try:
            json_files.append(mc_parser.get(s, "CMSSW.lumi_mask"))
        except ConfigParser.NoOptionError:
            pass

    crab_parser = ConfigParser.ConfigParser()
    crab_parser.read(crab_conf_file)
    if py_conf_file == None:
        py_conf_file = crab_parser.get("CMSSW", "pset")
    try:
        json_files.append(crab_parser.get("CMSSW", "lumi_mask"))
    except ConfigParser.NoOptionError:
        pass

    # Unique list of json files
    keys = {}
    for f in json_files:
        keys[f] = 1
    json_files = keys.keys()   

    if crab_conf_file == None:
        print "Did not find crab configuration file"
        return 1
    if py_conf_file == None:
        print "Did not find CMSSW python configuration file"
        return 1

    # Check crab environment
    multicrab.checkCrabInPath()
    dirname = multicrab.createTaskDir(prefix=opts.prefix)

    shutil.copy(mc_conf_file, os.path.join(dirname, "multicrab.cfg"))
    flist = [crab_conf_file, py_conf_file]
    if len(json_files) > 0:
        flist.extend(json_files)
    for f in flist:
        shutil.copy(f, dirname)

    print "Copied %s to %s" % (", ".join(flist), dirname)
    print "Creating multicrab task"
    print
    print "############################################################"
    print

    os.chdir(dirname)
    subprocess.call(["multicrab", "-create"])

    print
    print "############################################################"
    print
    print "Created multicrab task to subdirectory "+dirname
    print
    print "Jobs can be submitted by e.g. 'cd %s; multicrab -submit" % dirname
    print
   
    return 0
Esempio n. 3
0
 def CreateMultiCrabDir(self):
     self.dirname = multicrab.createTaskDir(prefix="LandSMultiCrab")
            tmp = eras[0]
            for e in eras[1:]:
                if len(e) > len(tmp):
                    tmp = e
            eras = [tmp]

    # Create pseudo multicrab directory
    
    dirname = "embedding"
    if opts.outputName != None:
        dirname += opts.outputName
    if datasetCreatorMC is not None:
        dirname += "_mc"
    if opts.midfix is not None:
        dirname += "_"+opts.midfix
    taskDir = multicrab.createTaskDir(dirname)

    f = open(os.path.join(taskDir, "codeVersion.txt"), "w")
    f.write(git.getCommitId()+"\n")
    f.close()
    f = open(os.path.join(taskDir, "codeStatus.txt"), "w")
    f.write(git.getStatus()+"\n")
    f.close()
    f = open(os.path.join(taskDir, "codeDiff.txt"), "w")
    f.write(git.getDiff()+"\n")
    f.close()
    # A bit of a kludgy way to indicate for datacard generator that this directory is from embedding (this can be obsolete way)
    f = open(os.path.join(taskDir, "multicrab.cfg"), "w")
    f.write("[Data]\n")
    f.write("dummy = embedded\n\n")
    residualPrefix = ""
def main():

    if len(sys.argv) == 1:
        usage()

    if not QCDInvertedDir(sys.argv[1:]):
        print "No QCD inverted dir recognized from input",sys.argv[1:]
        usage()

    dirQCDInv = sys.argv[1]
    dirs = []
    dirs.append(dirQCDInv)

    print "QCDInverted multicrab directory",dirQCDInv
    print 

                                        
    taskDir = multicrab.createTaskDir("QCDInverted")

    f = open(os.path.join(taskDir, "codeVersion.txt"), "w")
    f.write(git.getCommitId()+"\n")
    f.close()
    f = open(os.path.join(taskDir, "codeStatus.txt"), "w")
    f.write(git.getStatus()+"\n")
    f.close()
    f = open(os.path.join(taskDir, "codeDiff.txt"), "w")
    f.write(git.getDiff()+"\n")
    f.close()
    f = open(os.path.join(taskDir, "inputInfo.txt"), "w")
    f.write("Original directory:\n%s\n\n" % "\n".join(dirQCDInv))
    f.write("\nQCDInverted analysis: %s\n" % analysis)
    f.close()
    f = open(os.path.join(taskDir, "multicrab.cfg"), "w")
    f.write("[Data]\n")
    f.write("CMSSW.pset = signalAnalysisInvertedTau_cfg.py\n")
    f.close()

        
    creator = dataset.readFromMulticrabCfg(directory=dirQCDInv)
    optModes = []#creator.getOptimizationModes()
    optModes.append("")
    dataEras = creator.getDataEras()
    dataEras = []
#    dataEras.append("Run2011A")
#    dataEras.append("Run2011AB")
    dataEras.append("Run2011B")
    print "optModes",optModes
    print "dataEras",dataEras

    directory = os.path.join(taskDir, "Data", "res")
    os.makedirs(directory)

    fOUT = ROOT.TFile.Open(os.path.join(directory, "histograms-Data.root"), "RECREATE")

    lumiSaved = False    
    for optMode in optModes:
	for dataEra in dataEras:

            datasetsQCDInv = creator.createDatasetManager(dataEra=dataEra, searchMode=searchMode, analysisName=analysis, optimizationMode=optMode)
            datasetsQCDInv.loadLuminosities()
            datasetsQCDInv.updateNAllEventsToPUWeighted()

            plots.mergeRenameReorderForDataMC(datasetsQCDInv)
            
            datasetsQCDInv.mergeData()
            datasetsQCDInv.merge("EWK", ["WJets", "DYJetsToLL", "SingleTop", "Diboson","TTJets"], keepSources=True)
            
            if not lumiSaved:
                # Save luminosity
                data = {"Data": datasetsQCDInv.getDataset("Data").getLuminosity()}
                f = open(os.path.join(taskDir, "lumi.json"), "w")
                json.dump(data, f, indent=2)
                f.close()
		lumiSaved = True
    
            anadir = fOUT.mkdir(analysis+searchMode+dataEra+optMode)

            anadir.cd()
            integrals = []
            for massPlot in massPlots:
                print "Processing",massPlot
                massPlotDir = anadir.mkdir(massPlot)
                anadir.cd(massPlot)
                integral = write(fOUT,datasetsQCDInv,[massPlot])
                integrals.append(integral[0])

  	    for controlPlot in controlPlots:
                print "Processing",controlPlot
                controlPlotDir = anadir.mkdir(controlPlot)
                anadir.cd(controlPlot)
                controlPlotNames = datasetsQCDInv.getDataset("Data").getDirectoryContent(controlPlot)
                controlPlotNamesWithPaths = []
                for controlPlotName in controlPlotNames:
                    controlPlotNamesWithPaths.append(os.path.join(controlPlot,controlPlotName))
                write(fOUT,datasetsQCDInv,controlPlotNamesWithPaths)
                anadir.cd()

    	    counterdir = anadir.mkdir("counters")
            anadir.cd("counters")
            counter = ROOT.TH1D("counter","counter",len(integrals),0,len(integrals))
            for i,integral in enumerate(integrals):
                binLabel = "integral_"+massPlots[i]
                counter.SetBinContent(i+1,integral)
                counter.GetXaxis().SetBinLabel(i+1,binLabel)
            counter.Write()
            weighteddir = counterdir.mkdir("weighted")
            weighteddir.cd()
            counter.Write()

    addConfigInfo(fOUT, datasetsQCDInv.getDataset("Data"))
    
    fOUT.Close()

    print "Created multicrab-like dir for LandS:",taskDir