1 |
biliu |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
from array import *
|
3 |
|
|
import sys
|
4 |
|
|
import os
|
5 |
|
|
import math
|
6 |
|
|
from OSUT3Analysis.Configuration.configurationOptions import *
|
7 |
|
|
|
8 |
|
|
sys.path.append(os.getcwd())
|
9 |
|
|
sys.argv.pop(0)
|
10 |
|
|
|
11 |
|
|
for arg in sys.argv:
|
12 |
|
|
exec("from " + arg.rstrip('.py') + " import *")
|
13 |
|
|
|
14 |
|
|
from ROOT import TFile, gROOT, gStyle, gDirectory, TStyle, THStack, TH1F, TCanvas, TString, TLegend, TArrow, THStack, TIter, TKey, TGraphErrors, Double
|
15 |
|
|
|
16 |
|
|
def calculator(DenominatorIntegral,DenominatorIntegralError,MiddleIntegral,MiddleIntegralError):
|
17 |
|
|
out = []
|
18 |
|
|
if not (DenominatorIntegral == 0 or MiddleIntegral == 0):
|
19 |
|
|
Ratio = round(MiddleIntegral/DenominatorIntegral,4)
|
20 |
|
|
Error = round(math.sqrt((DenominatorIntegralError**2)/(DenominatorIntegral**2)+(MiddleIntegralError**2)/(MiddleIntegral**2)),4)
|
21 |
|
|
out.append(Ratio)
|
22 |
|
|
out.append(Error)
|
23 |
|
|
return out
|
24 |
|
|
else:
|
25 |
|
|
print "T_T!!! Zeros in denominator detected!!"
|
26 |
|
|
out.append(0)
|
27 |
|
|
out.append(0)
|
28 |
|
|
return out
|
29 |
|
|
for upperValue in upperValues:
|
30 |
|
|
|
31 |
|
|
controlChannels = []
|
32 |
|
|
preChannels = []
|
33 |
|
|
print "Integrate up to " + str(upperValue)
|
34 |
|
|
|
35 |
|
|
testFile = TFile(preSelectionFile +".root")
|
36 |
|
|
testFile.cd()
|
37 |
|
|
for key in testFile.GetListOfKeys():
|
38 |
|
|
if (key.GetClassName() != "TDirectoryFile"):
|
39 |
|
|
continue
|
40 |
|
|
rootDirectory = key.GetName()
|
41 |
|
|
testFile.cd(key.GetName())
|
42 |
|
|
for key2 in gDirectory.GetListOfKeys():
|
43 |
|
|
if (key2.GetClassName() != "TDirectoryFile"):
|
44 |
|
|
continue
|
45 |
|
|
preChannels.append(key2.GetName())
|
46 |
|
|
|
47 |
|
|
for channel in preChannels: # loop over final states, which each have their own directory
|
48 |
|
|
|
49 |
|
|
testFile.cd(rootDirectory+"/"+channel)
|
50 |
|
|
subDirectories = []
|
51 |
|
|
for key in gDirectory.GetListOfKeys():
|
52 |
|
|
if (key.GetClassName() != "TDirectoryFile"):
|
53 |
|
|
continue
|
54 |
|
|
subDirectories.append(key.GetName())
|
55 |
|
|
|
56 |
|
|
DenominatorIntegral = 0
|
57 |
|
|
DenominatorIntegralError = 0
|
58 |
|
|
MiddleIntegral = 0
|
59 |
|
|
MiddleIntegralError = 0
|
60 |
|
|
inputFile = TFile(preSelectionFile+".root")
|
61 |
|
|
if(inputFile.IsZombie()):
|
62 |
|
|
continue
|
63 |
|
|
if (len(subDirectories) != 0):
|
64 |
|
|
Histogram = inputFile.Get(rootDirectory+"/"+channel+"/"+subDirectories[len(subDirectories)-1]+"/"+preHistogramName).Clone()
|
65 |
|
|
else:
|
66 |
|
|
Histogram = inputFile.Get(rootDirectory+"/"+channel+"/"+preHistogramName).Clone()
|
67 |
|
|
Histogram.SetDirectory(0)
|
68 |
|
|
inputFile.Close()
|
69 |
|
|
|
70 |
|
|
upperBin = Histogram.FindBin (upperValue)
|
71 |
|
|
DenominatorIntegralError = Double (0.0)
|
72 |
|
|
middleBin = Histogram.FindBin (criticalValue)
|
73 |
|
|
MiddleIntegralError = Double (0.0)
|
74 |
|
|
DenominatorIntegral = Histogram.IntegralAndError(middleBin, upperBin + 1,DenominatorIntegralError)
|
75 |
|
|
MiddleIntegral = Histogram.IntegralAndError(0,middleBin,MiddleIntegralError)
|
76 |
|
|
print channel
|
77 |
|
|
preOut = calculator(DenominatorIntegral,DenominatorIntegralError,MiddleIntegral,MiddleIntegralError)
|
78 |
|
|
print "Pre Below Critical/Above Critical = " + str(preOut[0]) + " +- " + str(preOut[1]*100) +"%"
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
testFile = TFile(controlFile +".root")
|
82 |
|
|
testFile.cd()
|
83 |
|
|
for key in testFile.GetListOfKeys():
|
84 |
|
|
if (key.GetClassName() != "TDirectoryFile"):
|
85 |
|
|
continue
|
86 |
|
|
rootDirectory = key.GetName()
|
87 |
|
|
testFile.cd(key.GetName())
|
88 |
|
|
for key2 in gDirectory.GetListOfKeys():
|
89 |
|
|
if (key2.GetClassName() != "TDirectoryFile"):
|
90 |
|
|
continue
|
91 |
|
|
controlChannels.append(key2.GetName())
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
for channel in controlChannels: # loop over final states, which each have their own directory
|
96 |
|
|
|
97 |
|
|
testFile.cd(rootDirectory+"/"+channel)
|
98 |
|
|
subDirectories = []
|
99 |
|
|
for key in gDirectory.GetListOfKeys():
|
100 |
|
|
if (key.GetClassName() != "TDirectoryFile"):
|
101 |
|
|
continue
|
102 |
|
|
subDirectories.append(key.GetName())
|
103 |
|
|
|
104 |
|
|
DenominatorIntegral = 0
|
105 |
|
|
DenominatorIntegralError = 0
|
106 |
|
|
MiddleIntegral = 0
|
107 |
|
|
MiddleIntegralError = 0
|
108 |
|
|
inputFile = TFile(controlFile+".root")
|
109 |
|
|
if(inputFile.IsZombie()):
|
110 |
|
|
continue
|
111 |
|
|
if (len(subDirectories) != 0):
|
112 |
|
|
Histogram = inputFile.Get(rootDirectory+"/"+channel+"/"+subDirectories[len(subDirectories)-1]+"/"+histogramName).Clone()
|
113 |
|
|
else:
|
114 |
|
|
Histogram = inputFile.Get(rootDirectory+"/"+channel+"/"+histogramName).Clone()
|
115 |
|
|
Histogram.SetDirectory(0)
|
116 |
|
|
inputFile.Close()
|
117 |
|
|
|
118 |
|
|
nBins = Histogram.GetNbinsX()
|
119 |
|
|
upperBin = Histogram.FindBin (upperValue)
|
120 |
|
|
DenominatorIntegralError = Double (0.0)
|
121 |
|
|
middleBin = Histogram.FindBin (criticalValue)
|
122 |
|
|
MiddleIntegralError = Double (0.0)
|
123 |
|
|
DenominatorIntegral = Histogram.IntegralAndError(middleBin, upperBin-1,DenominatorIntegralError)
|
124 |
|
|
MiddleIntegral = Histogram.IntegralAndError(0,middleBin-1,MiddleIntegralError)
|
125 |
|
|
print channel
|
126 |
|
|
controlOut = calculator(DenominatorIntegral,DenominatorIntegralError,MiddleIntegral,MiddleIntegralError)
|
127 |
|
|
print "Control Below Critical/Above Critical = " + str(controlOut[0]) + " +- " + str(controlOut[1]*100) +"%"
|
128 |
|
|
|