10 i = bisect.bisect( quantList, val )
15 if math.fabs( val - quantList[i-1] ) < math.fabs( val - quantList[i] ):
20 if __name__==
'__main__':
22 parser = argparse.ArgumentParser(description=
'Process fiber brightness files')
23 parser.add_argument(
'-fd',
'--far-detector', action=
'store_true')
24 parser.add_argument(
'-nd',
'--near-detector', action=
'store_true')
25 args = parser.parse_args()
27 if args.far_detector
and args.near_detector:
28 print "Can only set --fd or --nd!" 31 if not args.far_detector
and not args.near_detector:
32 print "Must set either --fd or --nd!" 36 fIn =
open(
"FDModuleData.txt",
"r") 37 fOutName = "fdBrightness.root" 38 if args.near_detector:
39 fIn =
open(
"NDModuleData.txt",
"r") 40 fOutName = "ndBrightness.root" 45 grBright = ROOT.TGraph()
54 splitLine = line.split()
55 plane =
int(splitLine[0])
56 cell =
int(splitLine[1])
57 brightness =
float(splitLine[2])
60 if brightness > 20
and brightness < 180:
61 brightnessLst.append(brightness/100.)
67 if module > maxModule:
69 if brightness < minBrightness:
70 minBrightness = brightness
71 if brightness > maxBrightness:
72 maxBrightness = brightness
74 print "min brightness:", minBrightness,
"max brightness:", maxBrightness
76 brightness1D = ROOT.TH1D(
"brightness1D",
"Brightness Level;Brightness;Cells", 1200, -1, 5)
77 brightnessValue = ROOT.TH1D(
"brightnessValue",
"Brightness Level Bin Values;Brightness Bin Number;Values", 9, 0, 9)
78 brightness2D = ROOT.TH2D(
"brightness2D",
";Plane;Cell", maxPlane+1, 0, maxPlane+1, maxCell+1, 0, maxCell+1)
79 brightness2DX = ROOT.TH2D(
"brightness2DX",
";Plane;Cell", maxPlane/2+1, 0, maxPlane/2+1, maxCell+1, 0, maxCell+1)
80 brightness2DY = ROOT.TH2D(
"brightness2DY",
";Plane;Cell", maxPlane/2+1, 0, maxPlane/2+1, maxCell+1, 0, maxCell+1)
82 brightness2D_module = ROOT.TH2D(
"brightness2D_module",
";Plane;Module", maxPlane+1, 0, maxPlane+1, maxModule+1, 0, maxModule+1)
83 brightness2D_bin = ROOT.TH2C(
"brightness2D_bin",
"Brightness Level Bin Map;Plane;Cell", maxPlane+1, 0, maxPlane+1, maxCell+1, 0, maxCell+1)
84 brightness_byplane = ROOT.TH1D(
"brightness_plane",
";Plane", maxPlane+1, 0, maxPlane+1);
86 print "maxplane: {}".
format(maxPlane)
87 print "maxcell: {}".
format(maxCell)
90 brightnessArr = np.array(brightnessLst)
96 quantList = [10, 20, 30, 40, 50, 60, 70, 80, 90]
97 quantVals = np.percentile(brightnessArr, quantList)
99 brightnessValue.SetBinContent(1, 1)
100 for i
in range(len(quantVals)):
101 brightnessValue.SetBinContent(i+1, quantVals[i])
103 for i
in xrange(len(quantList)):
104 print str(quantList[i])+
"%:", quantVals[i]
106 for iX
in xrange(brightness2D.GetXaxis().GetNbins()):
107 for iY
in xrange(brightness2D.GetYaxis().GetNbins()):
108 brightness2D.SetBinContent(iX+1, iY+1, 1.0)
110 for iX
in xrange(brightness2D_module.GetXaxis().GetNbins()):
111 for iY
in xrange(brightness2D_module.GetYaxis().GetNbins()):
112 brightness2D_module.SetBinContent(iX+1, iY+1, 1.0)
114 for iX
in xrange(brightness2D_bin.GetXaxis().GetNbins()):
115 for iY
in xrange(brightness2D_bin.GetYaxis().GetNbins()):
116 brightness2D_bin.SetBinContent(iX+1, iY+1, 1)
118 position = fIn.seek(0, 0);
120 splitLine = line.split()
121 plane =
int(splitLine[0])
122 cell =
int(splitLine[1])
123 brightness =
float(splitLine[2])
127 brightness1D.Fill(brightness/100.0)
130 if brightness > 20
and brightness < 180:
132 quantBrightness = quantVals[iquantBrightness]
133 brightness2D.SetBinContent(plane+1, cell+1, quantBrightness)
136 brightness2DX.SetBinContent((plane/2)+1, cell+1, quantBrightness)
138 brightness2DY.SetBinContent((plane/2)+1, cell+1, quantBrightness)
139 if plane
in planeDict:
140 planeDict[plane][0] += 1
141 planeDict[plane][1] += brightness
143 planeDict[plane] = [1, brightness]
144 if (plane, module)
in plane_moduleDict:
145 plane_moduleDict[(plane,module)][0] += 1
146 plane_moduleDict[(plane,module)][1] += brightness
148 plane_moduleDict[(plane,module)] = [1, brightness]
151 for key
in planeDict:
152 grBright.SetPoint(key, key, planeDict[key][1]/planeDict[key][0])
153 brightness_byplane.SetBinContent(key+1, planeDict[key][1]/(100.0*planeDict[key][0]));
156 for key
in plane_moduleDict:
159 count =
float(plane_moduleDict[key][0])
160 totBrightness =
float(plane_moduleDict[key][1])/100.
161 brightness2D_module.SetBinContent(plane+1, module+1, totBrightness/count)
164 position = fIn.seek(0, 0);
166 splitLine = line.split()
167 plane =
int(splitLine[0])
168 cell =
int(splitLine[1])
169 brightness =
float(splitLine[2])
172 if brightness > 20
and brightness < 180:
174 brightness2D_bin.SetBinContent(plane+1, cell+1, iquantBrightness+1)
176 iquantBrightness =
findClosestVal(brightness_byplane.GetBinContent(plane+1, module+1), quantVals)
177 brightness2D_bin.SetBinContent(plane+1, cell+1, iquantBrightness+1)
179 fOut = ROOT.TFile(fOutName,
"recreate")
180 fOut.WriteTObject(brightness2D,
"BrightnessByCell")
181 fOut.WriteTObject(brightnessValue,
"BrightnessValue")
182 fOut.WriteTObject(brightness2D_module,
"BrightnessByModule")
183 fOut.WriteTObject(brightness_byplane,
"BrightnessByPlane")
184 fOut.WriteTObject(brightness2D_bin,
"BrightnessByBin")
def findClosestVal(val, quantList)
std::string format(const int32_t &value, const int &ndigits=8)
procfile open("FD_BRL_v0.txt")