-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnvaryminpe.py
211 lines (168 loc) · 6.92 KB
/
nvaryminpe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
### change in min_pe 1-10 and plots for each number of true electrons n= 1,2,3,4
import ROOT as r
from ts_digi_container import *
import pandas as pd
import numpy as np
from array import array
r.gStyle.SetOptStat(0)
r.gROOT.ProcessLine(".L tdrstyle.C")
r.gROOT.ProcessLine("setTDRStyle()")
r.gROOT.SetBatch(True)
## set configurable parameters
coll="TriggerPadTagger" #other options: "TriggerPadUpSimHits", "TriggerPadDownSimHits"
## intialize contain to read target input file
cont = ts_digi_container("~whitbeck/raid/LDMX/trigger_pad_sim/Dec18/trig_scin_digi_mip_respons_20_noise_0p001.root")
cont.setup()
stacks = [] # to keep hist in memory
Dict= dict()
Minpes = array("d")
for min_pe in np.arange(1.0,11.0,1.0):
Minpes.append(min_pe)
## initialize histograms
hist = r.TH2F("confusion_hist",coll+";True Electrons;Pred Electrons",8,-0.5,7.5,8,-0.5,7.5)
for i in range(cont.tin.GetEntries()):
#if i>100: break
## initialize container
cont.getEvent(i)
## get true number of electrons
true_num=cont.count_true(coll+"SimHits")
#### ALGORITHM 1: COUNT THE NUMBER HITS IN AN ARRAY
count_hits=cont.count_hits(coll+"Digi",min_pe)
count_hits_up=cont.count_hits("TriggerPadUpDigi",min_pe)
#### ALGORITHM 2: COUNT THE NUMBER OF HIT CLUSTERS
count_clusters=cont.count_clusters(coll+"Digi",min_pe)
count_clusters_up=cont.count_clusters("TriggerPadUpDigi",min_pe)
## fill histograms
#hist.Fill(true_num,count_hits)
hist.Fill(true_num, min(count_hits,count_hits_up))
#hist.Fill(true_num,count_clusters)
#hist.Fill(true_num, min(count_clusters,count_clusters_up))
for x in range(2,6): # four blocks in each histogram; x and y represent the histogram block number
values = [0]*3 #three variable list [eff,under,over]
for y in range(1,hist.GetNbinsY()+1): # 8 y's
if x==y : values[0] += hist.GetBinContent(x,y) # values on the diagonal
if y<x : values[1] += hist.GetBinContent(x,y) # values below the diagonal
if y>x : values[2] += hist.GetBinContent(x,y) # values above the diagonal
#print "values", values
total = reduce(lambda x,y : x+y, values)
#print "total", total
event_rate = map(lambda x: (x/total), values)
#print "event_rate", event_rate
Dict.setdefault(x,[]).append(event_rate)
#NOTE: All the dict keywords are +1 the number of true electrons
# Initializing all the canvas
c1 = r.TCanvas( 'c1', 'c1', 1000, 1000)
c1.SetGrid()
print "(Eff, Under, Over) values for 10 different min pe and for n=1", Dict[2]
print "\n"
for i in range(5,1,-1):
efficiency, under_prediction, over_prediction = array("d"),array("d"),array("d")
for x in np. arange(0,10,1):
for y in np.arange(0,3,1):
if y==0: efficiency.append(Dict[i][x][y])
if y==1: under_prediction.append(Dict[i][x][y])
if y==2: over_prediction.append(Dict[i][x][y])
gr = r.TGraph( 10, Minpes, efficiency)
stacks.append(gr)
gr.SetLineColor( i+4 )
gr.SetLineWidth( 4 )
gr.SetMarkerStyle( 21 )
gr.SetTitle( 'n = '+ str(i-1))
#gr.GetXaxis().SetNdivisions(505)
gr.GetXaxis().SetTitle( 'Min_Pe' )
gr.GetYaxis().SetTitle( 'Efficiency Rate' )
gr.GetYaxis().SetRangeUser(0, 1.3)
#gr.GetXaxis().SetLimits(0.0001,11)
gr.GetXaxis().SetLabelSize(0.03)
gr.GetYaxis().SetLabelSize(0.03)
if i-1 == 4: gr.Draw( 'ALP' )
else : gr.Draw('LP')
c1.BuildLegend(0.65,0.75,0.95,0.90,"Number of True Electrons (n):")
c1.SaveAs("minhits_response20_MinPevseff.png")
for i in range(5,1,-1):
efficiency, under_prediction, over_prediction = array("d"),array("d"),array("d")
for x in np. arange(0,10,1):
for y in np.arange(0,3,1):
if y==0: efficiency.append(Dict[i][x][y])
if y==1: under_prediction.append(Dict[i][x][y])
if y==2: over_prediction.append(Dict[i][x][y])
gr = r.TGraph( 10, Minpes, under_prediction)
stacks.append(gr)
gr.SetLineColor( i+4 )
gr.SetLineWidth( 4 )
gr.SetMarkerStyle( 21 )
gr.SetTitle( 'n = '+ str(i-1))
#gr.GetXaxis().SetNdivisions(505)
gr.GetXaxis().SetTitle( 'Min_Pe' )
gr.GetYaxis().SetTitle( 'Under Prediction Rate' )
gr.GetYaxis().SetRangeUser(0, 1.3)
#gr.GetXaxis().SetLimits(0.0001,11)
gr.GetXaxis().SetLabelSize(0.03)
gr.GetYaxis().SetLabelSize(0.03)
if i-1 == 4: gr.Draw( 'ALP' )
else : gr.Draw('LP')
c1.BuildLegend(0.65,0.75,0.95,0.90,"Number of True Electrons (n):")
c1.SaveAs("minhits_response20_MinPevsunder.png")
for i in range(5,1,-1):
efficiency, under_prediction, over_prediction = array("d"),array("d"),array("d")
for x in np. arange(0,10,1):
for y in np.arange(0,3,1):
if y==0: efficiency.append(Dict[i][x][y])
if y==1: under_prediction.append(Dict[i][x][y])
if y==2: over_prediction.append(Dict[i][x][y])
print "overprediction", over_prediction
print "efficiency", efficiency
print "\n"
maximum = Dict[2][0][2]
minimum = Dict[5][9][2]
print "mas,min", maximum, minimum
print "\n"
gr = r.TGraph( 10, Minpes, over_prediction)
stacks.append(gr)
gr.SetLineColor( i+4 )
gr.SetLineWidth( 4 )
gr.SetMarkerStyle( 21 )
gr.SetTitle( 'n = '+ str(i-1))
#gr.GetXaxis().SetNdivisions(505)
gr.GetXaxis().SetTitle( 'Min_Pe' )
gr.GetYaxis().SetTitle( 'Over Prediction Rate' )
#gr.GetYaxis().SetRangeUser(minimum, maximum)
#gr.GetXaxis().SetLimits(0.0001,11)
gr.GetXaxis().SetLabelSize(0.03)
gr.GetYaxis().SetLabelSize(0.03)
if i-1 == 4: gr.Draw( 'ALP' )
else : gr.Draw('LP')
#c1.SetLogy()
#c1.SetLogx()
c1.BuildLegend(0.65,0.75,0.95,0.9,"Number of True Electrons (n):")
c1.SaveAs("ch_response20_MinPevsOver.png")
for i in range(5,1,-1):
efficiency, under_prediction, over_prediction = array("d"),array("d"),array("d")
for x in np. arange(0,10,1):
for y in np.arange(0,3,1):
if y==0: efficiency.append(Dict[i][x][y])
if y==1: under_prediction.append(Dict[i][x][y])
if y==2: over_prediction.append(Dict[i][x][y])
print type(efficiency)
maximum = Dict[2][0][2]
print "Max", maximum
minimum = Dict[5][9][2]
gr = r.TGraph( 10, over_prediction, efficiency )
stacks.append(gr)
gr.SetLineColor( i+4 )
gr.SetLineWidth( 4 )
gr.SetMarkerStyle( 21 )
gr.SetTitle( 'n = '+ str(i-1))
gr.GetXaxis().SetNdivisions(505)
gr.GetXaxis().SetTitle( 'Overprediction Rate' )
gr.GetYaxis().SetTitle( 'Efficiency Rate' )
gr.GetYaxis().SetRangeUser(0,1)
#gr.GetXaxis().SetRangeUser(minimum, 0.07)
gr.GetXaxis().SetLabelSize(0.03)
gr.GetYaxis().SetLabelSize(0.03)
if i-1 == 4: gr.Draw( 'ALP' )
else : gr.Draw('LP')
#c1.SetLogx()
#c1.SetLogy()
c1.BuildLegend(0.2,0.75,0.5,0.9,"Number of True Electrons (n):")
c1.SaveAs("ch_response20_OvervsEff.png")