-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotEBeamFiles.py
148 lines (133 loc) · 7.88 KB
/
plotEBeamFiles.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
#### this code mixes the background tracks and signal tracks per bunch crossing
#### run: python3 getSigBkgTextFile.py <bxNumberWanted>
import os
import sys
import time
import pprint
import math, array
from ROOT import *
from collections import OrderedDict
import argparse
#### add diagonal vertex cut
#def checkVtxCut(vtxx, vtxz):
#if((-45.0 < vtxx <= -25.5 ) and (3800 < vtxz <= 4200)):
#return True
#elif((-55.0 < vtxx <= -35.0) and (4200 < vtxz <= 4500)):
#return True
#elif((-60.0 < vtxx <= -45.0) and (4500 < vtxz <= 5000)):
#return True
#elif((-70 < vtxx <= -50.0) and (5000 < vtxz <= 5500)):
#return True
#elif((-75 < vtxx <= -60.0) and (5500 < vtxz <= 6000)):
#return True
#elif((-80 < vtxx <= -65.0) and (5500 < vtxz <= 6000)):
#return True
#elif((-90 < vtxx <= -70.0) and (6000 < vtxz <= 6500)):
#return True
#elif((-100.0 < vtxx <= -80.0) and (6500 < vtxz <= 7000)):
#return True
#else:
#return False
### anything below x, remove it cut
def checkVtxCut(vtxx, vtxz):
if((vtxx <= -25.5 ) and (3800 < vtxz <= 4200)):
return True
elif((vtxx <= -35.0) and (4200 < vtxz <= 4500)):
return True
elif((vtxx <= -45.0) and (4500 < vtxz <= 5000)):
return True
elif((vtxx <= -50.0) and (5000 < vtxz <= 5500)):
return True
elif((vtxx <= -60.0) and (5500 < vtxz <= 6000)):
return True
elif((vtxx <= -65.0) and (5500 < vtxz <= 6000)):
return True
elif((vtxx <= -70.0) and (6000 < vtxz <= 6500)):
return True
elif((vtxx <= -80.0) and (6500 < vtxz <= 7000)):
return True
else:
return False
def energyBins():
#//// variable binned in X axis histograms
logmin = -6;
logmax = 1;
nbins = 450;
logbinwidth = (logmax-logmin)/float(nbins);
xpoints = []
for i in xrange(0, nbins+1):
#print((logmin + i*logbinwidth), pow( 10,(logmin + i*logbinwidth) ))
xpoints.append(pow( 10,(logmin + i*logbinwidth) ))
xpoints.append(2*pow( 10,1))
return xpoints
def main():
#outFile = TFile("AllBackground2DDistribution_WithVtxCut.root", "RECREATE")
outFile = TFile("AllGplusLaserBackground2DDistribution_WithoutVtxCut.root", "RECREATE")
outFile.cd()
xbins = energyBins()
xarray = array.array('d',xbins)
#print(xarray, " ", len(xarray))
allHistoDict = {}
for i in xrange(0, 16):
allHistoDict.update({"h2DVtxxVtxz_Electron_"+str(i):TH2D("tracking_planes_background_vtxz_vtxx_electrons_"+str(i),"Electron vertex for stave"+str(i)+"; vtxz [mm]; vtxx [mm]", 6000, 1000, 7000, 1000, -500, 500)})
allHistoDict.update({"h2DVtxxVtxz_Positron_"+str(i):TH2D("tracking_planes_background_vtxz_vtxx_positrons_"+str(i),"Positron vertex for stave"+str(i)+"; vtxz [mm]; vtxx [mm]", 6000, 1000, 7000, 1000, -500, 500)})
allHistoDict.update({"h2DVtxyVtxz_Electron_"+str(i):TH2D("tracking_planes_background_vtxz_vtxy_electrons_"+str(i),"Electron vertex for stave"+str(i)+"; vtxz [mm]; vtxy [mm]", 6000, 1000, 7000, 100, -50, 50)})
allHistoDict.update({"h2DVtxyVtxz_Positron_"+str(i):TH2D("tracking_planes_background_vtxz_vtxy_positrons_"+str(i),"Positron vertex for stave"+str(i)+"; vtxz [mm]; vtxy [mm]", 6000, 1000, 7000, 100, -50, 50)})
allHistoDict.update({"h2DVtxyVtxx_Electron_"+str(i):TH2D("tracking_planes_background_vtxx_vtxy_electrons_"+str(i),"Electron vertex for stave"+str(i)+"; vtxx [mm]; vtxy [mm]", 1000, -500, 500, 100, -50, 50)})
allHistoDict.update({"h2DVtxyVtxx_Positron_"+str(i):TH2D("tracking_planes_background_vtxx_vtxy_positrons_"+str(i),"Positron vertex for stave"+str(i)+"; vtxx [mm]; vtxy [mm]", 1000, -500, 500, 100, -50, 50)})
allHistoDict.update({"h2DEVtxx_Positron_"+str(i):TH2D("tracking_planes_background_vtx_x_track_e_positrons_log_"+str(i),"Positron E vs vtxx for stave"+str(i)+"; vtxx [mm]; E [GeV]", 1000, -500, 500, len(xbins)-1, xarray)})
allHistoDict.update({"h2DEVtxz_Positron_"+str(i):TH2D("tracking_planes_background_vtx_z_track_e_positrons_log_"+str(i),"Positron E vs vtxz for stave"+str(i)+"; vtxz [mm]; E [GeV]", 6000, 1000, 7000, len(xbins)-1, xarray)})
allHistoDict.update({"h2DEVtxx_Electron_"+str(i):TH2D("tracking_planes_background_vtx_x_track_e_electrons_log_"+str(i),"Electron E vs vtxx for stave"+str(i)+"; vtxx [mm]; E [GeV]", 1000, -500, 500, len(xbins)-1, xarray)})
allHistoDict.update({"h2DEVtxz_Electron_"+str(i):TH2D("tracking_planes_background_vtx_z_track_e_electrons_log_"+str(i),"Electron E vs vtxz for stave"+str(i)+"; vtxz [mm]; E [GeV]", 6000, 1000, 7000, len(xbins)-1, xarray)})
#allHistoDict.update({"h2DEVtxx_Positron_"+str(i):TH2D("h2DEVtxx_Positron_"+str(i),"Positron E vs vtxx for stave"+str(i)+"; vtxx [mm]; E [GeV]", 1000, 500, 500, 1000, 0, 10)})
#allHistoDict.update({"h2DEVtxz_Positron_"+str(i):TH2D("h2DEVtxz_Positron_"+str(i),"Positron E vs vtxz for stave"+str(i)+"; vtxz [mm]; E [GeV]", 6000, 1000, 7000, 1000, 0, 10)})
#allHistoDict.update({"h2DEVtxx_Electron_"+str(i):TH2D("h2DEVtxx_Electron_"+str(i),"Electron E vs vtxx for stave"+str(i)+"; vtxx [mm]; E [GeV]", 1000, 500, 500, 1000, 0, 10)})
#allHistoDict.update({"h2DEVtxz_Electron_"+str(i):TH2D("h2DEVtxz_Electron_"+str(i),"Electron E vs vtxz for stave"+str(i)+"; vtxz [mm]; E [GeV]", 6000, 1000, 7000, 1000, 0, 10)})
#bkgFileName = open("EBeamOnlyNewSamples_AllBX_trackInfoClean.txt")
bkgFileName = open("gPlusLaserBkgNewSamples_AllBX_trackInfoClean.txt")
lineCounter = 0
### write the bkg as it is
for lines in bkgFileName.readlines():
if '#' in lines:
continue
lineCounter += 1
if(lineCounter%10000==0): print("processed: ", lineCounter)
lines = lines.rstrip()
eachWord = lines.split()
bxNumber = int(eachWord[0])
trackId = int(eachWord[2])
pdgId = int(eachWord[1])
staveId = int(eachWord[3])-1000
xPos = float(eachWord[4])
yPos = float(eachWord[5])
energyVal = float(eachWord[6])
weight = float(eachWord[7])
vtx_x = float(eachWord[8])
vtx_y = float(eachWord[9])
vtx_z = float(eachWord[10])
failVtxCut = checkVtxCut(vtx_x, vtx_z)
#if(vtx_x < -25.5 and (vtx_z > 3600 and vtx_z < 4600)): continue
#if(failVtxCut): continue
if(pdgId == 11 and trackId!=1):
if(energyVal > 10): print("Electron: ", energyVal, " ", vtx_x, " ", vtx_z)
allHistoDict["h2DVtxxVtxz_Electron_"+str(staveId)].Fill(vtx_z, vtx_x, weight)
allHistoDict["h2DVtxyVtxz_Electron_"+str(staveId)].Fill(vtx_z, vtx_y, weight)
allHistoDict["h2DVtxyVtxx_Electron_"+str(staveId)].Fill(vtx_x, vtx_y, weight)
allHistoDict["h2DEVtxx_Electron_"+str(staveId)].Fill(vtx_x, energyVal, weight)
allHistoDict["h2DEVtxz_Electron_"+str(staveId)].Fill(vtx_z, energyVal, weight)
if(pdgId == -11 and trackId!=1):
if(energyVal > 10): print("Positron: ", energyVal, " ", vtx_x, " ", vtx_z)
allHistoDict["h2DVtxxVtxz_Positron_"+str(staveId)].Fill(vtx_z, vtx_x, weight)
allHistoDict["h2DVtxyVtxz_Positron_"+str(staveId)].Fill(vtx_z, vtx_y, weight)
allHistoDict["h2DVtxyVtxx_Positron_"+str(staveId)].Fill(vtx_x, vtx_y, weight)
allHistoDict["h2DEVtxx_Positron_"+str(staveId)].Fill(vtx_x, energyVal, weight)
allHistoDict["h2DEVtxz_Positron_"+str(staveId)].Fill(vtx_z, energyVal, weight)
for keys in allHistoDict:
#allHistoDict[keys].Scale(1./160.)
allHistoDict[keys].Scale(1./30.)
allHistoDict[keys].Write()
outFile.Close()
if __name__=="__main__":
start = time.time()
main()
print("--- The time taken: ", time.time() - start, " s")