9 |
|
from OSUT3Analysis.Configuration.configurationOptions import * |
10 |
|
from OSUT3Analysis.Configuration.processingUtilities import * |
11 |
|
|
12 |
+ |
|
13 |
|
parser = OptionParser() |
14 |
|
parser = set_commandline_arguments(parser) |
15 |
|
(arguments, args) = parser.parse_args() |
51 |
|
gROOT.ForceStyle() |
52 |
|
outputFile = TFile(condor_dir + "/" + outputFileName, "RECREATE") |
53 |
|
|
53 |
– |
channels = [] |
54 |
– |
processed_datasets = [] |
54 |
|
|
55 |
+ |
channels = {} |
56 |
+ |
processed_datasets = [] |
57 |
|
#### check which input datasets have valid output files |
58 |
|
for sample in datasets: |
59 |
|
fileName = condor_dir + "/" + sample + ".root" |
70 |
|
#### open first input file and re-make its directory structure in the output file |
71 |
|
testFile = TFile(condor_dir + "/" + processed_datasets[0] + ".root") |
72 |
|
testFile.cd() |
73 |
+ |
|
74 |
+ |
#To find whether there are a third layer in directories. |
75 |
+ |
GetPlotsAfterEachCut = True |
76 |
+ |
|
77 |
|
for key in testFile.GetListOfKeys(): |
78 |
< |
if (key.GetClassName() != "TDirectoryFile"): |
79 |
< |
continue |
80 |
< |
outputFile.cd() |
81 |
< |
outputFile.mkdir(key.GetName()) |
82 |
< |
rootDirectory = key.GetName() |
78 |
> |
if (key.GetClassName() != "TDirectoryFile"): |
79 |
> |
continue |
80 |
> |
testFile.cd(key.GetName()) |
81 |
> |
for key2 in gDirectory.GetListOfKeys(): |
82 |
> |
if (key2.GetClassName() != "TDirectoryFile"): |
83 |
> |
continue |
84 |
> |
testFile.cd(key.GetName()+"/"+key2.GetName()) |
85 |
> |
for key3 in gDirectory.GetListOfKeys(): |
86 |
> |
if (key3.GetClassName() != "TDirectoryFile"): |
87 |
> |
GetPlotsAfterEachCut = False |
88 |
> |
|
89 |
> |
if GetPlotsAfterEachCut: |
90 |
> |
for key in testFile.GetListOfKeys(): |
91 |
> |
if (key.GetClassName() != "TDirectoryFile"): |
92 |
> |
continue |
93 |
> |
outputFile.cd() |
94 |
> |
outputFile.mkdir(key.GetName()) |
95 |
> |
rootDirectory = key.GetName() |
96 |
|
|
97 |
< |
testFile.cd(key.GetName()) |
98 |
< |
for key2 in gDirectory.GetListOfKeys(): |
99 |
< |
if (key2.GetClassName() != "TDirectoryFile"): |
97 |
> |
testFile.cd(key.GetName()) |
98 |
> |
for key2 in gDirectory.GetListOfKeys(): |
99 |
> |
if (key2.GetClassName() != "TDirectoryFile"): |
100 |
> |
continue |
101 |
> |
outputFile.cd(key.GetName()) |
102 |
> |
gDirectory.mkdir(key2.GetName()) |
103 |
> |
channels[key2.GetName()] = [] |
104 |
> |
testFile.cd(key.GetName()+"/"+key2.GetName()) |
105 |
> |
for key3 in gDirectory.GetListOfKeys(): |
106 |
> |
if (key3.GetClassName() != "TDirectoryFile"): |
107 |
> |
continue |
108 |
> |
outputFile.cd(key.GetName()+"/"+key2.GetName()) |
109 |
> |
gDirectory.mkdir(key3.GetName()) |
110 |
> |
channels[key2.GetName()].append("/"+key3.GetName()) |
111 |
> |
else: |
112 |
> |
for key in testFile.GetListOfKeys(): |
113 |
> |
if (key.GetClassName() != "TDirectoryFile"): |
114 |
|
continue |
115 |
< |
outputFile.cd(key.GetName()) |
116 |
< |
gDirectory.mkdir(key2.GetName()) |
117 |
< |
channels.append(key2.GetName()) |
118 |
< |
|
119 |
< |
|
115 |
> |
outputFile.cd() |
116 |
> |
outputFile.mkdir(key.GetName()) |
117 |
> |
rootDirectory = key.GetName() |
118 |
> |
|
119 |
> |
testFile.cd(key.GetName()) |
120 |
> |
for key2 in gDirectory.GetListOfKeys(): |
121 |
> |
if (key2.GetClassName() != "TDirectoryFile"): |
122 |
> |
continue |
123 |
> |
outputFile.cd(key.GetName()) |
124 |
> |
gDirectory.mkdir(key2.GetName()) |
125 |
> |
channels[key2.GetName()] = [] |
126 |
> |
|
127 |
|
## weight = intLumi / 10000.0 |
128 |
|
## for dataset in processed_datasets: |
129 |
|
## dataset_file = "%s/%s.root" % (condor_dir,dataset) |
136 |
|
## os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", weight)) |
137 |
|
## else: |
138 |
|
## os.system("mergeTFileServiceHistograms -i %s -o %s -w %g" % (dataset_file, dataset_file + "_tmp", 1.0)) |
139 |
< |
|
101 |
< |
|
102 |
< |
for channel in channels: # loop over final states, which each have their own directory |
103 |
< |
|
104 |
< |
testFile.cd(rootDirectory+"/"+channel) |
105 |
< |
|
106 |
< |
for key in gDirectory.GetListOfKeys(): # loop over histograms in the current directory |
107 |
< |
histogramName = key.GetName() |
108 |
< |
|
109 |
< |
if re.match ('TH1', key.GetClassName()): # plot a 1-D histogram |
110 |
< |
|
139 |
> |
def MakeOneDHist(histogramname,channel,cut): |
140 |
|
numBgMCSamples = 0 |
141 |
|
numDataSamples = 0 |
142 |
|
numSignalSamples = 0 |
170 |
|
SignalMCLegend.SetFillColor(0) |
171 |
|
SignalMCLegend.SetFillStyle(0) |
172 |
|
|
173 |
< |
outputFile.cd(rootDirectory+"/"+channel) |
173 |
> |
outputFile.cd(rootDirectory+"/"+channel+cut) |
174 |
|
Canvas = TCanvas(histogramName) |
175 |
|
BgMCHistograms = [] |
176 |
|
BgMCLegendEntries = [] |
187 |
|
for sample in processed_datasets: # loop over different samples as listed in configurationOptions.py |
188 |
|
dataset_file = "%s/%s.root" % (condor_dir,sample) |
189 |
|
inputFile = TFile(dataset_file) |
190 |
< |
Histogram = inputFile.Get(rootDirectory+"/"+channel+"/"+histogramName).Clone() |
190 |
> |
Histogram = inputFile.Get(rootDirectory+"/"+channel+cut+"/"+histogramName).Clone() |
191 |
|
Histogram.SetDirectory(0) |
192 |
|
if arguments.rebinFactor: |
193 |
|
RebinFactor = int(arguments.rebinFactor) |
323 |
|
### Drawing histograms to canvas |
324 |
|
|
325 |
|
|
326 |
< |
outputFile.cd(rootDirectory+"/"+channel) |
326 |
> |
outputFile.cd(rootDirectory+"/"+channel+cut) |
327 |
|
|
328 |
|
makeRatioPlots = arguments.makeRatioPlots |
329 |
|
makeDiffPlots = arguments.makeDiffPlots |
483 |
|
Comparison.Draw() |
484 |
|
Canvas.Write() |
485 |
|
|
486 |
< |
if re.match ('TH2', key.GetClassName()) and arguments.draw2DPlots: # plot a 2-D histogram |
458 |
< |
|
486 |
> |
def MakeTwoDHist(histogramname,channel,cut): |
487 |
|
numBgMCSamples = 0 |
488 |
|
numDataSamples = 0 |
489 |
|
numSignalSamples = 0 |
511 |
|
SignalMCLegend.SetFillColor(0) |
512 |
|
SignalMCLegend.SetFillStyle(0) |
513 |
|
|
514 |
< |
outputFile.cd(rootDirectory+"/"+channel) |
514 |
> |
outputFile.cd(rootDirectory+"/"+channel+cut) |
515 |
|
Canvas = TCanvas(histogramName) |
516 |
|
Canvas.SetRightMargin(0.2413793); |
517 |
|
BgMCHistograms = [] |
521 |
|
for sample in processed_datasets: # loop over different samples as listed in configurationOptions.py |
522 |
|
dataset_file = "%s/%s.root" % (condor_dir,sample) |
523 |
|
inputFile = TFile(dataset_file) |
524 |
< |
Histogram = inputFile.Get(rootDirectory+"/"+channel+"/"+histogramName).Clone() |
524 |
> |
Histogram = inputFile.Get(rootDirectory+"/"+channel+"/"+cut+"/"+histogramName).Clone() |
525 |
|
Histogram.SetDirectory(0) |
526 |
|
RebinFactor = int(arguments.rebinFactor) |
527 |
|
if arguments.rebinFactor and Histogram.GetNbinsX() >= RebinFactor*10 and Histogram.GetNbinsY() >= RebinFactor*10: |
556 |
|
DataHistograms.append(Histogram) |
557 |
|
|
558 |
|
|
559 |
< |
outputFile.cd(rootDirectory+"/"+channel) |
559 |
> |
outputFile.cd(rootDirectory+"/"+channel+cut) |
560 |
|
|
561 |
|
if(numBgMCSamples is not 0): |
562 |
|
BgMCHistograms[0].SetTitle(histoTitle) |
597 |
|
LumiLabel.Draw() |
598 |
|
|
599 |
|
Canvas.Write() |
600 |
+ |
|
601 |
+ |
for channel in channels: # loop over final states, which each have their own directory |
602 |
+ |
if GetPlotsAfterEachCut: |
603 |
+ |
for cut in channels[channel]: |
604 |
+ |
testFile.cd(rootDirectory+"/"+channel+cut) |
605 |
+ |
|
606 |
+ |
for key in gDirectory.GetListOfKeys(): # loop over histograms in the current directory |
607 |
+ |
histogramName = key.GetName() |
608 |
|
|
609 |
+ |
if re.match ('TH1', key.GetClassName()): # plot a 1-D histogram |
610 |
+ |
MakeOneDHist(histogramName,channel,cut) |
611 |
+ |
if re.match ('TH2', key.GetClassName()) and arguments.draw2DPlots: # plot a 2-D histogram |
612 |
+ |
MakeTwoDHist(histogramName,channel,cut) |
613 |
+ |
else: |
614 |
+ |
testFile.cd(rootDirectory+"/"+channel) |
615 |
+ |
|
616 |
+ |
for key in gDirectory.GetListOfKeys(): # loop over histograms in the current directory |
617 |
+ |
histogramName = key.GetName() |
618 |
+ |
|
619 |
+ |
if re.match ('TH1', key.GetClassName()): # plot a 1-D histogram |
620 |
+ |
MakeOneDHist(histogramName,channel,"") |
621 |
+ |
if re.match ('TH2', key.GetClassName()) and arguments.draw2DPlots: # plot a 2-D histogram |
622 |
+ |
MakeTwoDHist(histogramName,channel,"") |
623 |
|
|
624 |
|
#for dataset in processed_datasets: |
625 |
|
# dataset_file = "%s/%s.root_tmp" % (condor_dir,dataset) |