-
Notifications
You must be signed in to change notification settings - Fork 0
/
HistogramFiller.py
407 lines (357 loc) · 17.3 KB
/
HistogramFiller.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
class filledHist: pass
def barMapLocation(id):
shortID = id-402654208
layer = int(shortID/1024)
bar = shortID%1024
if layer <=8:
bar+=2
return [layer,bar]
def autoBin(hist):
hist.BufferEmpty() #figures out the xrange
minX = hist.GetXaxis().GetBinLowEdge(1-1)
maxX = hist.GetXaxis().GetBinLowEdge(hist.GetNbinsX()+1)
# print(minX,maxX)
hist.SetBins(int(maxX)+1-int(minX),int(minX),int(maxX)+1) #makes it so there is one bin per event or ns, and the rightmost bin is still included
def fillHist(hist, plotVar, allData, processName="process" , minEDeposit=0, maxEDeposit=float('inf'), barID=False, angle=0, beamEnergy=0):
allowNoise= False
if plotVar == 'simX':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalSimHits_"+processName)):
if h.getEdep() > minEDeposit and h.getEdep() < maxEDeposit:
hist.Fill(h.getPosition()[0])
elif plotVar == 'simY':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalSimHits_"+processName)):
if h.getEdep() > minEDeposit and h.getEdep() < maxEDeposit:
hist.Fill(h.getPosition()[1])
elif plotVar == 'simZ':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalSimHits_"+processName)):
if h.getEdep() > minEDeposit and h.getEdep() < maxEDeposit:
hist.Fill(h.getPosition()[2])
elif plotVar == 'simE':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalSimHits_"+processName)):
if h.getEdep() > minEDeposit and h.getEdep() < maxEDeposit:
hist.Fill(h.getEdep())
# print("Sim id",h.getID()-4026e5)
elif plotVar == 'simEH1':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalSimHits_"+processName)):
if h.getPosition()[2] < 0: hist.Fill(h.getEdep())
elif plotVar == 'simEH2':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalSimHits_"+processName)):
if h.getPosition()[2] > 0: hist.Fill(h.getEdep())
elif plotVar == 'simEBar':
for event in allData:
bars={}
for ih,h in enumerate(getattr(event, "HcalSimHits_"+processName)):
try: bars[h.getID()]+=h.getEdep()
except: bars[h.getID()]=h.getEdep()
for bar in bars:
hist.Fill(bars[bar])
elif plotVar == 'recEBar':
for event in allData:
bars={}
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
try: bars[h.getID()]+=h.getPE()
except: bars[h.getID()]=h.getPE()
for bar in bars:
hist.Fill(bars[bar])
elif plotVar == 'recEventBar':
for event in allData:
bars={}
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
hist.Fill(h.getID())
#402654211:402668549
elif plotVar == 'recBarEvent': #redo with autobinning
layers={}
bars={}
for event in allData:
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
try: bars[h.getID()]+=1
except: bars[h.getID()]=1
barOrder=[]
for bar in bars:
barOrder.append(bar)
barOrder.sort()
hist = r.TH1F(plotVar,"Event counts in each bar", len(bars) ,0,len(bars))
for i in range(len(barOrder)):
hist.Fill(i,bars[barOrder[i]])
hist.SetYTitle('counts')
hist.SetXTitle('bar ranking in bar ID')
elif plotVar == 'recE':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
if h.isNoise() == allowNoise:
hist.Fill(h.getEnergy())
elif plotVar == 'recENoisy':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
hist.Fill(h.getEnergy())
elif plotVar == 'recX':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
if h.isNoise() == allowNoise: hist.Fill(h.getXPos())
elif plotVar == 'recY':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
if h.isNoise() == allowNoise: hist.Fill(h.getYPos())
elif plotVar == 'recZ':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
if h.isNoise() == allowNoise: hist.Fill(h.getZPos())
elif plotVar == 'recAmp':
eventCount=0
for event in allData:
eventCount+=1
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
if h.isNoise() == allowNoise: hist.Fill(h.getAmplitude())
#h.getID() repeats even in rec mode
# print("rec id",h.getID()-4026e5)
print(eventCount)
elif plotVar == 'recPE':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
if h.isNoise() == allowNoise: hist.Fill(h.getPE())
#the whole hcal F(x) thing is wrong, be careful
elif plotVar == 'simX(Z)':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalSimHits_"+processName)):
if h.getEdep() > minEDeposit and h.getEdep() < maxEDeposit:
hist.Fill(h.getPosition()[2],h.getPosition()[0])
# hist.Fill(h.getPosition()[2],h.getPosition()[0])
elif plotVar == 'simY(Z)':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalSimHits_"+processName)):
if h.getEdep() > minEDeposit and h.getEdep() < maxEDeposit:
hist.Fill(h.getPosition()[2],h.getPosition()[1])
elif plotVar == 'simY(X)':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalSimHits_"+processName)):
if h.getEdep() > minEDeposit and h.getEdep() < maxEDeposit:
hist.Fill(h.getPosition()[1],h.getPosition()[0])
elif plotVar == 'simE(X)':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalSimHits_"+processName)):
if h.getEdep() > minEDeposit and h.getEdep() < maxEDeposit:
hist.Fill(h.getPosition()[0],h.getEdep())
elif plotVar == 'simE(Z)':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalSimHits_"+processName)):
if h.getEdep() > minEDeposit and h.getEdep() < maxEDeposit:
hist.Fill(h.getPosition()[2],h.getEdep())
elif plotVar == 'recX(Z)':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
if h.isNoise() == allowNoise: hist.Fill(h.getZPos(),h.getXPos())
elif plotVar == 'recY(Z)':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
if h.isNoise() == allowNoise: hist.Fill(h.getZPos(),h.getYPos())
elif plotVar == 'recY(X)':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
if h.isNoise() == allowNoise: hist.Fill(h.getYPos(),h.getXPos())
elif plotVar == 'trigSimX': #unimplemented
for event in allData:
for ih,h in enumerate(getattr(event, "TriggerPadUpSimHits_"+processName)):
hist.Fill(h.getPosition()[0])
elif plotVar == 'trigSimE':
for event in allData:
for ih,h in enumerate(getattr(event, "TriggerPadUpSimHits_"+processName)):
hist.Fill(h.getEdep())
#trig f(x) works
elif plotVar == 'trigSimX(Z)':
for event in allData:
for ih,h in enumerate(getattr(event, "TriggerPadUpSimHits_"+processName)):
hist.Fill(h.getPosition()[2],h.getPosition()[0])
elif plotVar == 'trigSimY(Z)':
for event in allData:
for ih,h in enumerate(getattr(event, "TriggerPadUpSimHits_"+processName)):
hist.Fill(h.getPosition()[2],h.getPosition()[1])
elif plotVar == 'trigSimY(X)':
for event in allData:
for ih,h in enumerate(getattr(event, "TriggerPadUpSimHits_"+processName)):
hist.Fill(h.getPosition()[0],h.getPosition()[1])
elif plotVar == 'trigSimE(X)':
for event in allData:
for ih,h in enumerate(getattr(event, "TriggerPadUpSimHits_"+processName)):
hist.Fill(h.getPosition()[0],h.getEdep())
elif plotVar == 'trigSimE(Z)':
for event in allData:
for ih,h in enumerate(getattr(event, "TriggerPadUpSimHits_"+processName)):
hist.Fill(h.getPosition()[2],h.getEdep())
# elif plotVar == 'trigRecX':
# for event in allData:
# for ih,h in enumerate(getattr(event, "trigScintRecHitsUp_"+processName)):
# print(h.getYPos())
# hist.Fill(h.getXPos())
# print(h.items())
elif plotVar == 'trigRecT':
for event in allData:
for ih,h in enumerate(getattr(event, "trigScintRecHitsUp_"+processName)):
if h.getBarID() ==6: hist.Fill(h.getTime())
# print(h.getBarID())
# print(h.items())
#The testbeam functions
#1.1
elif plotVar == 'Mapped distribution of number of hits of each bar':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
LayerBar = barMapLocation(h.getID())
hist.Fill(LayerBar[0],LayerBar[1])
elif plotVar == 'Distribution of number of hits of each bar':
for event in allData:
hits=0
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
if h.getID() == barID:
hits+=1
hist.Fill(hits)
#1.2
elif plotVar == 'Distribution of pulse height of each bar':
for event in allData:
amplitude = 0
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
if h.getID() == barID:
amplitude += h.getAmplitude()
hist.Fill( amplitude)
autoBin(hist)
#1.3
elif plotVar == 'Total number of hits per event':
for event in allData:
totalCount=0
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
totalCount+=1
hist.Fill(totalCount)
autoBin(hist)
elif plotVar == 'Total number of hits per run':
runs={}
for event in allData:
run=event.EventHeader.getRun()
if run not in runs: runs[run]=0
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
runs[run]+=1
for run in runs:
hist.Fill(runs[run])
autoBin(hist)
elif plotVar == 'Sum of pulse height per event':
for event in allData:
totalAmplitude=0
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
totalAmplitude+=h.getAmplitude()
hist.Fill(totalAmplitude)
autoBin(hist)
elif plotVar == 'Sum of pulse height per run':
runs={}
for event in allData:
run=event.EventHeader.getRun()
if run not in runs: runs[run]=0
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
runs[run]+=h.getAmplitude()
for run in runs:
hist.Fill(runs[run])
print(runs[run])
autoBin(hist)
#1.4
elif plotVar == 'Distribution of number of hits for TS bars':
for event in allData:
for ih,h in enumerate(getattr(event, "trigScintRecHitsUp_"+processName)):
hist.Fill(h.getBarID())
elif plotVar == 'Distribution of signal amplitude for TS bars':
for event in allData:
for ih,h in enumerate(getattr(event, "trigScintRecHitsUp_"+processName)):
hist.Fill(h.getBarID(),h.getAmplitude())
elif plotVar == 'Distribution of signal amplitude for TS bars (individual bars)':
for event in allData:
for ih,h in enumerate(getattr(event, "trigScintRecHitsUp_"+processName)):
if h.getBarID() == barID:
hist.Fill(h.getAmplitude())
#1.5
elif plotVar == 'Time difference between TS and HCal':
for event in allData: #I define time difference based on the first event's time
trigTimes=[]
hcalTimes=[]
for ih,h in enumerate(getattr(event, "trigScintRecHitsUp_"+processName)):
trigTimes.append(h.getTime())
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
hcalTimes.append(h.getTime())
hist.Fill(min(hcalTimes)-min(trigTimes))
#2
elif plotVar == 'Reconstructed energy for tags': #might wanna make beam energy automatic
for event in allData:
energy=0
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
energy+=h.getEnergy()
hist.Fill(energy/beamEnergy)
elif plotVar == 'Energy as a function of the incoming particle angle':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
hist.Fill(angle,h.getEnergy())
#3
elif plotVar == 'Distribution of PEs per HCal bar':
for event in allData:
PEs = 0
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
if h.getID() == barID:
PEs += h.getPE()
hist.Fill(PEs)
autoBin(hist)
elif plotVar == 'Mapped Distribution of PEs per HCal bar':
for event in allData:
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
LayerBar = barMapLocation(h.getID())
hist.Fill(LayerBar[0],LayerBar[1],h.getPE())
elif plotVar == 'TS plots with muons (hit efficiency) (1 plot per bar)':
for event in allData:
hits=0
for ih,h in enumerate(getattr(event, "trigScintRecHitsUp_"+processName)):
if h.getBarID() == barID:
hits+=1
hist.Fill(hits)
autoBin(hist)
elif plotVar == 'TS plots with muons (hit efficiency)':
eventCount=allData.GetEntries()
for event in allData:
for ih,h in enumerate(getattr(event, "trigScintRecHitsUp_"+processName)):
# print(h.getBarID())
hist.Fill(h.getBarID(),1/eventCount)
# autoBin(hist)
# print(eventCount)
elif plotVar == 'TS plots with muons (light yield)':
for event in allData:
for ih,h in enumerate(getattr(event, "trigScintRecHitsUp_"+processName)):
if h.getBarID() == barID:
hist.Fill(h.getPE())
autoBin(hist)
elif plotVar == 'TS plots with muons (pulse shape)':
for event in allData:
for ih,h in enumerate(getattr(event, "trigScintRecHitsUp_"+processName)):
if h.getBarID() == barID:
# hist.Fill(h.getTime())
hist.Fill(h.getTime(),h.getAmplitude())
# if barID == 5:
# if h.getTime() !=2.5:
# print(h.getTime())
# autoBin(hist)
elif plotVar == 'energy response vs. energy':
for event in allData:
energy=0
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
energy+=h.getEnergy()
hist.Fill(energy/beamEnergy)
elif plotVar == 'rec vs sim':
recE=0
simE=0
for event in allData:
for ih,h in enumerate(getattr(event, "HcalRecHits_"+processName)):
recE+=h.getEnergy()
hist.Fill(h.getEnergy())
for ih,h in enumerate(getattr(event, "HcalSimHits_"+processName)):
simE+=h.getEdep()
hist.Fill(h.getEdep())
print ("Total simulated energy deposit:",simE)
print ("Total reconstructed energy deposit:",recE)
filledHist.hist = hist
return filledHist