-
Notifications
You must be signed in to change notification settings - Fork 3
/
DataConversion_THLcalibration.py
138 lines (94 loc) · 3.78 KB
/
DataConversion_THLcalibration.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
import sys
from ROOT import *
import ROOT
from array import array
import math
import os
import numpy as np
from scipy.cluster.hierarchy import fclusterdata
from os import environ
from itertools import product # SimpleClustering
def SimpleClustering(matrix):
frame=matrix
for i,j in [[i,j] for i,j in product(xrange(256),xrange(256)) if matrix[i][j]!=0] :
for u,v in [[u,v] for u,v in product([-1,0,1],[-1,0,1]) if (((i+u>=0 and i+u<=255) and (j+v>=0 and j+v<=255)) and (u!=0 or v!=0))]:
if(matrix[i+u][j+v]!=0):
frame[i][j]=0
frame[i+u][j+v]=0
return sum(sum(frame, []))
def writeFile(THL, Counts, OutputFile):
txtfile = open(OutputFile, "w")
for i in range (0, len(THL)):
txtfile.write(str(THL[i])+" "+str(Counts[i]))
txtfile.close()
def usage():
print 'THL calibration'
print 'Usage:\n python %s <assembly> <frames> <THLmin> <THLmax> <source>' % ( sys.argv[0] )
if __name__ == '__main__':
if (len(sys.argv)<6 or len(sys.argv)>6):
usage()
sys.exit( 1 )
assembly=sys.argv[1]
frames=int(sys.argv[2])
THLmin=int(sys.argv[3])
THLmax=int(sys.argv[4])
source=sys.argv[5]
gROOT.ProcessLine(".L ~/CLICdpStyle/rootstyle/CLICdpStyle.C");
CLICdpStyle();
gStyle.SetOptFit()
gStyle.SetOptTitle(1);
mg=TMultiGraph()
leg=TLegend(0.65, 0.7, 0.8, 0.85)
leg.SetFillStyle(0)
mg_deriv=TMultiGraph()
leg_deriv=TLegend(0.65, 0.7, 0.8, 0.85)
leg_deriv.SetFillStyle(0)
colors=[kGreen+2, kRed, kBlue, kBlack, kViolet, kMagenta]
home = environ['HOME']
path=home+"/eos/clicdp/data/VertexCalibration/ThresholdScan/"
directory=path+assembly+"/"
path=directory+source
THLstep=2
THLs=[]
counts=[]
txtfile = open( assembly+"_"+source+".txt", "w")
for thl in range(THLmin, THLmax, THLstep):
THLs.append(thl)
count=0
for frame in range(0, frames):
filename="%s_THL%03i_%d"%(source, thl, frame)
f = open(path+"/"+filename,'r')
matrix = [ map(int,line.split(' ')) for line in f ]
# print "Occupancy: %d pixels"%(np.count_nonzero(matrix))
# ============ Without clustering ============ #
count+=sum(sum(matrix, []))
# ============ End without clustering ============ #
# # ====== fclusterdata used for clustering ====== #
# coords=np.array(np.transpose(np.nonzero(matrix))) # coordinate of non-zero elements
# row=[]
# col=[]
# countForThisFrame=[]
# for i in range(0, len(coords)):
# x=coords[i][0]
# y=coords[i][1]
# row.append(x)
# col.append(y)
# countForThisFrame.append(matrix[x][y])
# ClusteringResult=fclusterdata(coords, sqrt(2.), criterion="distance") #clustering
# NbOfOccurance=np.bincount(ClusteringResult) # occurance of each value
# for i in range(1, len(NbOfOccurance)):
# if (NbOfOccurance[i]!=1):
# multiHitClusters=np.where(ClusteringResult==i)
# for j in range(0, len(multiHitClusters)):
# row.pop(j)
# col.pop(j)
# countForThisFrame.pop(j)
# count+=sum(countForThisFrame)
# # ============ End fclusterdata ============== #
# # ===== using simple clustering ==== #
# count+=SimpleClustering(matrix)
# # ============ End using simple clustering ==== #
counts.append(count)
txtfile.write(str(thl)+" "+str(count)+"\n")
print "Processing THL="+str(thl)+", Counts="+str(count)
txtfile.close()