1 |
#!/usr/bin/env python
|
2 |
|
3 |
import sys
|
4 |
import os
|
5 |
from array import *
|
6 |
from optparse import OptionParser
|
7 |
from DisplacedSUSY.Configuration.configurationOptions import *
|
8 |
|
9 |
parser = OptionParser()
|
10 |
|
11 |
parser.add_option("-l", "--localConfig", dest="localConfig",
|
12 |
help="local configuration file")
|
13 |
|
14 |
parser.add_option("-c", "--condorDir", dest="condorDir",
|
15 |
help="condor output directory")
|
16 |
|
17 |
(options, args) = parser.parse_args()
|
18 |
|
19 |
if options.localConfig:
|
20 |
sys.path.append(os.getcwd())
|
21 |
exec("from " + options.localConfig.rstrip('.py') + " import *")
|
22 |
|
23 |
if options.condorDir:
|
24 |
condor_dir = "condor/%s" % options.condorDir
|
25 |
else: #get most recent condor submission directory
|
26 |
dir_list = []
|
27 |
for directory in os.listdir("./condor/"):
|
28 |
if directory.find("condor_") is not -1:
|
29 |
dir_list.append(directory)
|
30 |
if len(dir_list) is 0:
|
31 |
sys.exit("Cannot find last condor working directory")
|
32 |
dir_list.sort(reverse=True)
|
33 |
condor_dir = "condor/%s" % dir_list[0]
|
34 |
|
35 |
from ROOT import TFile, gROOT, gStyle, gDirectory, TStyle, THStack, TH1F, TCanvas, TString, TLegend, TArrow, THStack, TIter, TKey, TPaveLabel
|
36 |
|
37 |
gROOT.SetBatch()
|
38 |
outputFile = TFile(condor_dir + "/pu.root", "RECREATE")
|
39 |
|
40 |
processed_datasets = []
|
41 |
|
42 |
#### check which input datasets have valid output files
|
43 |
for sample in datasets:
|
44 |
fileName = condor_dir + "/" + sample + ".root"
|
45 |
if not os.path.exists(fileName):
|
46 |
continue
|
47 |
testFile = TFile(fileName)
|
48 |
if not (testFile.IsZombie()):
|
49 |
processed_datasets.append(sample)
|
50 |
|
51 |
if len(processed_datasets) is 0:
|
52 |
sys.exit("No datasets have been processed")
|
53 |
|
54 |
#### open first input file and re-make its directory structure in the output file
|
55 |
testFile = TFile(condor_dir + "/" + processed_datasets[0] + ".root")
|
56 |
testFile.cd()
|
57 |
for key in testFile.GetListOfKeys():
|
58 |
if (key.GetClassName() != "TDirectoryFile"):
|
59 |
continue
|
60 |
rootDirectory = key.GetName()
|
61 |
|
62 |
for sample in processed_datasets: # loop over different samples as listed in configurationOptions.py
|
63 |
inputFile = TFile(condor_dir + "/" + sample + ".root")
|
64 |
if(inputFile.IsZombie()):
|
65 |
continue
|
66 |
Histogram = inputFile.Get(rootDirectory+"/pu").Clone()
|
67 |
Histogram.SetDirectory(0)
|
68 |
outputFile.cd()
|
69 |
Histogram.Write (sample)
|
70 |
|
71 |
outputFile.Close()
|