Exemplo n.º 1
0
def attachCounters(sample):

    m_nevt = 0
    m_sumw = 0

    #Go to the grid and get the metadata output
    sh_metadata = ROOT.SH.SampleHandler()
    discoverInput.discover(sh_metadata, search_directories,
                           sample.getMetaString("sample_name"))
    if len(sh_metadata) == 1:
        metadata_sample = sh_metadata[0]
        for myfile in [
                ROOT.TFile(ifilepath)
                for ifilepath in metadata_sample.makeFileList()
        ]:
            print myfile
            try:
                m_nevt += myfile.Get("cutflow").GetBinContent(
                    myfile.Get("cutflow").GetXaxis().FindBin("all"))
                m_sumw += myfile.Get("cutflow_weighted").GetBinContent(
                    myfile.Get("cutflow_weighted").GetXaxis().FindBin("all"))
            except:
                pass

    sample.setMetaDouble("nc_nevt", m_nevt)
    sample.setMetaDouble("nc_sumw", m_sumw)
Exemplo n.º 2
0
def attachCounters(sample):

		m_nevt = 0
		m_sumw = 0

		#Go to the grid and get the metadata output
		sh_metadata = ROOT.SH.SampleHandler()
		discoverInput.discover(sh_metadata, search_directories, sample.getMetaString("sample_name").replace("trees","metadata") )
		assert len(sh_metadata) == 1
		metadata_sample = sh_metadata[0]
		for myfile in [ROOT.TFile(ifilepath) for ifilepath in metadata_sample.makeFileList() ]:
			# print myfile 
			try:
				m_nevt += myfile.Get("MetaData_EventCount").GetBinContent(1)
				m_sumw += myfile.Get("MetaData_EventCount").GetBinContent(3)
			except:
				pass

		sample.setMetaDouble("nc_nevt",m_nevt)
		sample.setMetaDouble("nc_sumw",m_sumw)
Exemplo n.º 3
0
def attachCounters(sample):

		m_nevt = 0
		m_sumw = 0

		#Go to the grid and get the metadata output
		sh_metadata = ROOT.SH.SampleHandler()
		discoverInput.discover(sh_metadata, search_directories, sample.getMetaString("sample_name") )
		if len(sh_metadata) == 1:
			metadata_sample = sh_metadata[0]
			for myfile in [ROOT.TFile(ifilepath) for ifilepath in metadata_sample.makeFileList() ]:
				print myfile 
				try:
					m_nevt += myfile.Get("cutflow").GetBinContent(myfile.Get("cutflow").GetXaxis().FindBin("all"))
					m_sumw += myfile.Get("cutflow_weighted").GetBinContent(myfile.Get("cutflow_weighted").GetXaxis().FindBin("all"))
				except:
					pass

		sample.setMetaDouble("nc_nevt",m_nevt)
		sample.setMetaDouble("nc_sumw",m_sumw)
Exemplo n.º 4
0
    "wjets",
    "zjets",
    "diboson",
    "electroweak",
]

##
##
########### Gather input ######################################
##
##

logging.info("creating new sample handler")
sh_all = ROOT.SH.SampleHandler()

discoverInput.discover(sh_all, search_directories, "*%s*" % treeStream)
print len(sh_all)

logging.info("adding my tags defined in discoverInput.py")
discoverInput.addTags(sh_all)

ROOT.SH.readSusyMetaDir(sh_all, "$ROOTCOREBIN/data/SUSYTools")
ROOT.SH.readSusyMetaDir(sh_all, "$ROOTCOREBIN/data/SUSYTools/mc15_13TeV/")


def main():

    if int(ncores) > 1:
        pool = mp.Pool(processes=ncores)
        pool.map(processTheSH, outputSampleNames)
        pool.close()
Exemplo n.º 5
0
def main():

	##
	##
	########### Gather input ######################################
	##
	##

	logging.info("creating new sample handler")
	sh_all = ROOT.SH.SampleHandler()

	discoverInput.discover(sh_all, search_directories, "*%s*"%treePrefix  )
	print len(sh_all)

	logging.info("adding my tags defined in discoverInput.py")
	discoverInput.addTags(sh_all)

	ROOT.SH.readSusyMetaDir(sh_all,"$ROOTCOREBIN/data/SUSYTools")

	## Split up samplehandler into per-BG SH's based on tag metadata

	sh_data = sh_all.find("data")
	sh_signal = sh_all.find("signal")
	sh_bg = {}

	sh_bg["qcd"] = sh_all.find("qcd")
	sh_bg["top"] = sh_all.find("top")
	sh_bg["wjets"] = sh_all.find("wjets")
	sh_bg["zjets"] = sh_all.find("zjets")

	######This will be done per samplehandler ############################
	##
	##

	#Creation of output directory names
	outputFileNames = {   
		sh_all: "All",
		sh_data: "Data",
		sh_signal: "Signal",
		sh_bg["qcd"]: "QCD",
		sh_bg["top"]: "Top",
		sh_bg["wjets"]: "WJets",
		sh_bg["zjets"]: "ZJets",
		}

	treesToProcess = []

	for mysamplehandler in [	
								# sh_all,
								# sh_data,
								# sh_bg["qcd"],
								# sh_bg["top"],
								# sh_bg["wjets"],
								sh_bg["zjets"] 
							]:

		# print mysamplehandler

		filesToEventuallyHadd = []

		for sample in mysamplehandler:

			sample_name = sample.getMetaString("sample_name")
			# print sample_name
			dsid = sample_name.split(".")[2]

			if len(treesToProcess) == 0:
				treesToProcess = getListOfTreeNames(sample)

			attachCounters(sample)

			mydir = tmpOutputDirectory

			try:
				os.stat(mydir)
			except:
				os.mkdir(mydir)       

			outputSampleFileName = "%s/%s.root"%(tmpOutputDirectory, dsid)
			filesToEventuallyHadd.append(outputSampleFileName)

			outputSampleFile = ROOT.TFile(outputSampleFileName,"RECREATE")  

			for itree in treesToProcess:
				mysamplehandler.setMetaString("nc_tree", itree)
				mytree =  sample.makeTChain().Clone()
				outputTree = ROOT.addBranch( mytree, getNormFactor(sample) , selection)
				outputTree.Write()

			print "Saved tree %s with %s events . . ." % ( outputTree.GetName(), outputTree.GetEntries() )

			outputSampleFile.Close()


		mydir = outputDirectory
		try:
			os.stat(mydir)
		except:
			os.mkdir(mydir)  
		print 'hadd -O -f %s/%s.root %s'%(outputDirectory, outputFileNames[mysamplehandler], " ".join(filesToEventuallyHadd) )      
		os.system('hadd -O -f %s/%s.root %s'%
			(outputDirectory, outputFileNames[mysamplehandler], " ".join(filesToEventuallyHadd) ) 
			)
Exemplo n.º 6
0
	"zjets",
	"diboson",
	"electroweak",
]


##
##
########### Gather input ######################################
##
##

logging.info("creating new sample handler")
sh_all = ROOT.SH.SampleHandler()

discoverInput.discover(sh_all, search_directories, "*%s*"%treeStream  )
print len(sh_all)

logging.info("adding my tags defined in discoverInput.py")
discoverInput.addTags(sh_all)

ROOT.SH.readSusyMetaDir(sh_all,"$ROOTCOREBIN/data/SUSYTools")
ROOT.SH.readSusyMetaDir(sh_all,"$ROOTCOREBIN/data/SUSYTools/mc15_13TeV/")




def main():

	if int(ncores)>1:
		pool = mp.Pool(processes=ncores)