def flatten(analysis,sample,**kwargs): histParams = kwargs.pop('histParams',{}) histSelections = kwargs.pop('histSelections',{}) inputFileList = kwargs.pop('inputFileList','') outputFile = kwargs.pop('outputFile','') shift = kwargs.pop('shift','') countOnly = kwargs.pop('countOnly',False) njobs = kwargs.pop('njobs',1) job = kwargs.pop('job',0) multi = kwargs.pop('multi',False) useProof = kwargs.pop('useProof',False) intLumi = kwargs.pop('intLumi',float(getLumi())) if hasProgress and multi: pbar = kwargs.pop('progressbar',ProgressBar(widgets=['{0}: '.format(sample),' ',SimpleProgress(),' histograms ',Percentage(),' ',Bar(),' ',ETA()])) else: pbar = None if outputFile: flat = outputFile proj = outputFile.replace('.root','_projection.root') flattener = FlattenTree(analysis,sample,inputFileList=inputFileList,flat=flat,proj=proj,shift=shift,countOnly=countOnly,useProof=useProof,intLumi=intLumi) else: flattener = FlattenTree(analysis,sample,inputFileList=inputFileList,shift=shift,countOnly=countOnly,useProof=useProof,intLumi=intLumi) for histName, params in histParams.iteritems(): flattener.addHistogram(histName,**params) for selName, sel in histSelections.iteritems(): if sel: flattener.addSelection(selName,**sel['kwargs']) flattener.flattenAll(progressbar=pbar,njobs=njobs,job=job,multi=multi)
def flatten(directory): wzFlatten = FlattenTree( ntupleDirectory = sourceDirectory, treeName = 'WZTree', ) for histName, params in histParameters.iteritems(): wzFlatten.addHistogram(histName,**params) sample = directory.split('/')[-1] nl = 3 for region in ['PPP','PPF','PFP','FPP','PFF','FPF','FFP','FFF']: scalefactor = '*'.join([scaleMap[region[x]][x] for x in range(3)]+['genWeight']) if isData(sample): scalefactor = '1' cut = ' && '.join(['{0}=={1}'.format(tightVar[x],1 if region[x]=='P' else 0) for x in range(3)]+[baseCut]) postfix = '' if region=='PPP' else region wzFlatten.flatten(sample,'flat/WZ/{0}.root'.format(sample),cut,scalefactor=scalefactor,postfix=postfix)
def flatten(directory): wzFlatten = FlattenTree( ntupleDirectory=sourceDirectory, treeName='WZTree', ) for histName, params in histParameters.iteritems(): wzFlatten.addHistogram(histName, **params) sample = directory.split('/')[-1] nl = 3 for region in ['PPP', 'PPF', 'PFP', 'FPP', 'PFF', 'FPF', 'FFP', 'FFF']: scalefactor = '*'.join([scaleMap[region[x]][x] for x in range(3)] + ['genWeight']) if isData(sample): scalefactor = '1' cut = ' && '.join([ '{0}=={1}'.format(tightVar[x], 1 if region[x] == 'P' else 0) for x in range(3) ] + [baseCut]) postfix = '' if region == 'PPP' else region wzFlatten.flatten(sample, 'flat/WZ/{0}.root'.format(sample), cut, scalefactor=scalefactor, postfix=postfix)
import os import sys import glob import logging from DevTools.Plotter.FlattenTree import FlattenTree logger = logging.getLogger("Hpp3lFlatten") logging.basicConfig(level=logging.INFO, stream=sys.stderr, format='%(asctime)s.%(msecs)03d %(levelname)s %(name)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S') myCut = "hpp1_passTight==1 && hpp2_passTight==1 && hm1_passTight==1" sourceDirectory = '/hdfs/store/user/dntaylor/2016-02-28_Hpp3lAnalysis_v1/' hpp3lFlatten = FlattenTree( ntupleDirectory=sourceDirectory, treeName='Hpp3lTree', ) for sDir in glob.glob('{0}/*'.format(sourceDirectory)): sample = sDir.split('/')[-1] hpp3lFlatten.flatten(sample,'flat/Hpp3l/{0}.root'.format(sample),myCut)
import os import sys import glob import logging from DevTools.Plotter.FlattenTree import FlattenTree logger = logging.getLogger("SingleElectronFlatten") logging.basicConfig(level=logging.INFO, stream=sys.stderr, format='%(asctime)s.%(msecs)03d %(levelname)s %(name)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S') myCut = 'l1_genMatch==1' sourceDirectory = '/hdfs/store/user/dntaylor/2016-03-02_SingleElectronAnalysis_v1/' eFlatten = FlattenTree( ntupleDirectory=sourceDirectory, treeName='ETree', ) histParams = { 'pt_v_dz' : {'xVariable': 'l1_pt', 'yVariable': 'fabs(l1_dz)', 'xBinning': [50,0,500], 'yBinning': [50,0,0.5]}, 'pt_v_dxy': {'xVariable': 'l1_pt', 'yVariable': 'fabs(l1_dxy)', 'xBinning': [50,0,500], 'yBinning': [50,0,0.3]}, } for histName, params in histParams.iteritems(): eFlatten.add2DHistogram(histName,**params) for sDir in glob.glob('{0}/*'.format(sourceDirectory)): sample = sDir.split('/')[-1] eFlatten.flatten2D(sample,'flat/SingleElectron/{0}.root'.format(sample),myCut)
def flatten(directory, **kwargs): sample = directory.split('/')[-1] if hasProgress: pbar = kwargs.pop( 'progressbar', ProgressBar(widgets=[ '{0}: '.format(sample), ' ', SimpleProgress(), ' histograms ', Percentage(), ' ', Bar(), ' ', ETA() ])) else: pbar = None eFlatten = FlattenTree( ntupleDirectory=sourceDirectory, treeName='ETree', ) eFlatten.initializeSample(sample, 'flat/Electron/{0}.root'.format(sample)) for histName, params in histParams.iteritems(): eFlatten.addHistogram(histName, **params) promptCut = 'e_genMatch==1 && e_genIsPrompt==1' fakeCut = '(e_genMatch==0 || (e_genMatch==1 && e_genIsFromHadron))' barrelCut = 'fabs(e_eta)<1.479' endcapCut = 'fabs(e_eta)>1.479' lowpt = 'e_pt<50' highpt = 'e_pt>100' eFlatten.addSelection(promptCut) eFlatten.addSelection(fakeCut, postfix='fake') eFlatten.addSelection(' && '.join([promptCut, barrelCut]), postfix='barrel') eFlatten.addSelection(' && '.join([fakeCut, barrelCut]), postfix='barrel_fake') eFlatten.addSelection(' && '.join([promptCut, endcapCut]), postfix='endcap') eFlatten.addSelection(' && '.join([fakeCut, endcapCut]), postfix='endcap_fake') eFlatten.addSelection(' && '.join([promptCut, lowpt]), postfix='lowpt') eFlatten.addSelection(' && '.join([fakeCut, lowpt]), postfix='lowpt_fake') eFlatten.addSelection(' && '.join([promptCut, highpt]), postfix='highpt') eFlatten.addSelection(' && '.join([fakeCut, highpt]), postfix='highpt_fake') eFlatten.flattenAll(progressbar=pbar)
def flatten(directory,**kwargs): sample = directory.split('/')[-1] if hasProgress: pbar = kwargs.pop('progressbar',ProgressBar(widgets=['{0}: '.format(sample),' ',SimpleProgress(),' histograms ',Percentage(),' ',Bar(),' ',ETA()])) else: pbar = None eFlatten = FlattenTree( ntupleDirectory=sourceDirectory, treeName='ETree', ) eFlatten.initializeSample(sample,'flat/Electron/{0}.root'.format(sample)) for histName, params in histParams.iteritems(): eFlatten.addHistogram(histName,**params) promptCut = 'e_genMatch==1 && e_genIsPrompt==1' fakeCut = '(e_genMatch==0 || (e_genMatch==1 && e_genIsFromHadron))' barrelCut = 'fabs(e_eta)<1.479' endcapCut = 'fabs(e_eta)>1.479' lowpt = 'e_pt<50' highpt = 'e_pt>100' eFlatten.addSelection(promptCut) eFlatten.addSelection(fakeCut,postfix='fake') eFlatten.addSelection(' && '.join([promptCut,barrelCut]),postfix='barrel') eFlatten.addSelection(' && '.join([fakeCut,barrelCut]),postfix='barrel_fake') eFlatten.addSelection(' && '.join([promptCut,endcapCut]),postfix='endcap') eFlatten.addSelection(' && '.join([fakeCut,endcapCut]),postfix='endcap_fake') eFlatten.addSelection(' && '.join([promptCut,lowpt]),postfix='lowpt') eFlatten.addSelection(' && '.join([fakeCut,lowpt]),postfix='lowpt_fake') eFlatten.addSelection(' && '.join([promptCut,highpt]),postfix='highpt') eFlatten.addSelection(' && '.join([fakeCut,highpt]),postfix='highpt_fake') eFlatten.flattenAll(progressbar=pbar)