# ____________________________________________________________________________________________________________________________________________ ||
parser = argparse.ArgumentParser()
parser.add_argument("--inputDir",action="store")
parser.add_argument("--outputDir",action="store")
parser.add_argument("--verbose",action="store_true")

option = parser.parse_args()

# ____________________________________________________________________________________________________________________________________________ ||
outputInfo.outputDir    = option.inputDir
outputInfo.TFileName    = "ClosureTest.root"

# ____________________________________________________________________________________________________________________________________________ ||
collector = Collector()
collector.makeSampleList(componentList)
collector.makeMergedSampleList(componentList,mergeSampleDict)
collector.openFiles(collector.samples+collector.mergeSamples,outputInfo)

# ____________________________________________________________________________________________________________________________________________ ||
if not os.path.exists(os.path.abspath(option.outputDir)):
    os.makedirs(os.path.abspath(option.outputDir))
c = ROOT.TCanvas()
for var in variables:
    if option.verbose: print "*"*100
    dataHist = collector.getObj(dataSample,var)
    if option.verbose: print "Data: ",dataHist.Integral()
    outHist = dataHist.Clone(var+"_shape")
    outHist.Rebin(rebin)
    for ibin in range(1,outHist.GetNbinsX()+1):
        if outHist.GetBinContent(ibin):
            outHist.SetBinError(ibin,outHist.GetBinContent(ibin))
Exemplo n.º 2
0
class EndSequence(BaseModule):
    def __init__(self,
                 skipHadd=False,
                 haddAllSamples=False,
                 haddDataSamples=False,
                 skipComponentHadd=False):
        self.moduleList = []
        self.collector = Collector()
        self.hadder = Hadder()
        self.skipHadd = skipHadd
        self.haddAllSamples = haddAllSamples
        self.haddDataSamples = haddDataSamples
        self.allSampleName = "AllSample"
        self.allDataName = "Data"
        self.skipComponentHadd = skipComponentHadd

    def run(self,
            inputInfo,
            componentList,
            mergeSampleDict={},
            mergeSigSampleDict={}):
        self.collector.makeSampleList(componentList)
        self.collector.makeMergedSampleList(componentList, mergeSampleDict,
                                            mergeSigSampleDict)
        for sampleName in self.collector.mergeSamples + self.collector.mergeSigSamples:
            self.makedirs(inputInfo.outputDir + sampleName)
        if not self.skipHadd:
            if not self.skipComponentHadd:
                for sampleName in self.collector.samples:
                    print "Hadding " + sampleName
                    self.makedirs(inputInfo.outputDir + sampleName)
                    self.hadder.makeHaddScript(
                        inputInfo.outputDir + sampleName, [sampleName],
                        inputInfo)
                    self.hadder.haddSampleDir(inputInfo.outputDir + sampleName)
            if self.haddAllSamples:
                print "Hadding " + self.allSampleName
                self.makedirs(inputInfo.outputDir + self.allSampleName)
                self.hadder.makeHaddScript(
                    inputInfo.outputDir + self.allSampleName,
                    self.collector.samples, inputInfo)
                self.hadder.haddSampleDir(inputInfo.outputDir +
                                          self.allSampleName)
            if self.haddDataSamples and self.collector.dataSamples:
                print "Hadding " + self.allDataName
                self.makedirs(inputInfo.outputDir + self.allDataName)
                self.hadder.makeHaddScript(
                    inputInfo.outputDir + self.allDataName,
                    self.collector.dataSamples, inputInfo)
                self.hadder.haddSampleDir(inputInfo.outputDir +
                                          self.allDataName)
            for sampleName in self.collector.mergeSamples + self.collector.mergeSigSamples:
                print "Hadding (and merging) " + sampleName
                if sampleName in self.collector.mergeSamples:
                    tmpDict = self.collector.mergeSampleDict
                elif sampleName in self.collector.mergeSigSamples:
                    tmpDict = self.collector.mergeSigSampleDict
                self.hadder.makeHaddScript(inputInfo.outputDir + sampleName,
                                           tmpDict[sampleName], inputInfo)
                self.hadder.haddSampleDir(inputInfo.outputDir + sampleName)
        self.collector.openFiles(self.collector.samples, inputInfo)
        self.collector.openFiles(self.collector.mergeSamples, inputInfo)
        self.collector.openFiles(self.collector.mergeSigSamples, inputInfo)
        if self.haddAllSamples:
            self.collector.openFiles([
                self.allSampleName,
            ], inputInfo)
        if self.haddDataSamples:
            self.collector.openFiles([
                self.allDataName,
            ], inputInfo)
        for module in self.moduleList:
            module(self.collector)
        self.collector.closeFiles()

    def add(self, module):
        self.moduleList.append(module)

    def __len__(self):
        return len(self.moduleList)

    def __getitem__(self, index):
        if index >= len(self):
            raise IndexError
        else:
            return self.moduleList[index]