mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-22 14:38:14 +02:00
Added sebastians python script for interpolation - final debug version
This commit is contained in:
parent
545c5530e3
commit
fd42fad045
393
slsDetectorCalibration/etaVEL/EtaVELTr.py
Normal file
393
slsDetectorCalibration/etaVEL/EtaVELTr.py
Normal file
@ -0,0 +1,393 @@
|
||||
import numpy as np
|
||||
import math
|
||||
|
||||
maxf = 2
|
||||
minf = 0.5
|
||||
|
||||
class EtaVELTr:
|
||||
def __init__(self, numberOfPixels = 25, minn=0., maxx=1.):
|
||||
self.nPixels = numberOfPixels
|
||||
self.nCorners = self.nPixels + 1
|
||||
self.minEta = minn
|
||||
self.maxEta = maxx
|
||||
#self.corners = []
|
||||
self.edgesX = []
|
||||
self.edgesY = []
|
||||
self.edgesE = []
|
||||
self.edgesF = []
|
||||
self.edgesG = []
|
||||
self.edgesH = []
|
||||
self.counts = []
|
||||
self.pOffset = (self.maxEta-self.minEta)/self.nPixels
|
||||
|
||||
self.cPosX = []
|
||||
self.cPosY = []
|
||||
self.zPosX = []
|
||||
self.zPosY = []
|
||||
|
||||
self.sqSums = []
|
||||
self.cIteration = 0
|
||||
self.bSqSum = 0
|
||||
|
||||
self.initGrid()
|
||||
#self.calculatePixelCorners()
|
||||
self.update()
|
||||
|
||||
def initGrid(self):
|
||||
dd = 1 / math.sqrt(2)
|
||||
|
||||
#self.corners = [ [self.minEta + x * pOffset, self.minEta + y * pOffset] for y in range(self.nPixels)] for x in range(self.nPixels)
|
||||
self.cPosX = [ [self.minEta + x * self.pOffset for x in range(self.nCorners)] for y in range(self.nCorners) ]
|
||||
self.cPosY = [ [self.minEta + y * self.pOffset for x in range(self.nCorners)] for y in range(self.nCorners) ]
|
||||
self.counts = [ [ [0,0,0,0] for x in range(self.nPixels) ] for y in range(self.nPixels) ]
|
||||
self.edgesX = [ [ 1 for x in range(self.nCorners) ] for y in range(self.nCorners + 1) ]
|
||||
self.edgesY = [ [ 1 for x in range(self.nCorners+1) ] for y in range(self.nCorners) ]
|
||||
self.edgesE = [ [ dd for x in range(self.nPixels) ] for y in range(self.nPixels) ]
|
||||
self.edgesF = [ [ dd for x in range(self.nPixels) ] for y in range(self.nPixels) ]
|
||||
self.edgesG = [ [ dd for x in range(self.nPixels) ] for y in range(self.nPixels) ]
|
||||
self.edgesH = [ [ dd for x in range(self.nPixels) ] for y in range(self.nPixels) ]
|
||||
|
||||
|
||||
|
||||
def update(self):
|
||||
self.normalizeEdgeLengths()
|
||||
self.calculateEdgeLengths2()
|
||||
self.calculatePixelCorners2()
|
||||
conv = False
|
||||
out = 0
|
||||
outList = []
|
||||
tot = self.nPixels*self.nPixels*4
|
||||
sqSum = 0
|
||||
avg = self.getAvgCounts()
|
||||
avgPS = self.getAvgCounts() + 1*math.sqrt(self.getAvgCounts())
|
||||
avgMS = self.getAvgCounts() - 1*math.sqrt(self.getAvgCounts())
|
||||
for y in range(self.nPixels):
|
||||
for x in range(self.nPixels):
|
||||
for t in range(4):
|
||||
sqSum += (avg -self.counts[y][x][t]) * (avg -self.counts[y][x][t])
|
||||
if self.counts[y][x][t] > avgPS or self.counts[y][x][t] < avgMS:
|
||||
|
||||
out += 1
|
||||
outList.append([y,x,t,self.counts[y][x][t]])
|
||||
|
||||
outList = sorted(outList,key=lambda t: abs(self.counts[t[0]][t[1]][t[2]]/self.getAvgCounts()))
|
||||
self.counts = [ [ [0,0,0,0] for x in range(self.nPixels) ] for y in range(self.nPixels) ]
|
||||
print("There are {} of {} triangles out of 1 std ({} %)".format(out,tot,out/tot*100))
|
||||
print("Total Sq Err: {}".format(sqSum))
|
||||
|
||||
self.sqSums.append(sqSum)
|
||||
|
||||
if len(self.sqSums) > 2 and np.diff(self.sqSums)[-1] > 0:
|
||||
print("converged after {} steps: sqSums {} diff(sqSums) {}".format(self.cIteration,self.sqSums,np.diff(self.sqSums)))
|
||||
conv = True
|
||||
self.bSqSum = self.sqSums[-2]
|
||||
|
||||
self.cIteration += 1
|
||||
return [conv,outList,sqSum]
|
||||
|
||||
def normalizeEdgeLengths(self):
|
||||
sumL = 0
|
||||
sumL += sum(map(sum,zip(*self.edgesX)))
|
||||
sumL += sum(map(sum,zip(*self.edgesY)))
|
||||
sumL += sum(map(sum,zip(*self.edgesE)))
|
||||
sumL += sum(map(sum,zip(*self.edgesF)))
|
||||
sumL += sum(map(sum,zip(*self.edgesG)))
|
||||
sumL += sum(map(sum,zip(*self.edgesH)))
|
||||
avgL = sumL/(4*self.nPixels*self.nPixels+2*self.nCorners*(self.nCorners+1))
|
||||
print("total Sum is {} avg: {}".format(sumL,avgL))
|
||||
self.edgesX = [ [ x/avgL for x in y ] for y in self.edgesX ]
|
||||
self.edgesY = [ [ x/avgL for x in y ] for y in self.edgesY ]
|
||||
self.edgesE = [ [ x/avgL for x in y ] for y in self.edgesE ]
|
||||
self.edgesF = [ [ x/avgL for x in y ] for y in self.edgesF ]
|
||||
self.edgesG = [ [ x/avgL for x in y ] for y in self.edgesG ]
|
||||
self.edgesH = [ [ x/avgL for x in y ] for y in self.edgesH ]
|
||||
|
||||
def _shapeF(self,f):
|
||||
f = (f - 1) * 0.6 + 1
|
||||
if f > maxf:
|
||||
return maxf
|
||||
if f < minf:
|
||||
return minf
|
||||
return f
|
||||
|
||||
def calculateEdgeLengths2(self):
|
||||
if self.getTotalCounts() == 0:
|
||||
return
|
||||
avg = self.getAvgCounts()
|
||||
|
||||
for y in range(self.nPixels):
|
||||
for x in range(self.nPixels):
|
||||
for t in range(4):
|
||||
pc = self.counts[y][x][t]
|
||||
if pc == 0:
|
||||
f = maxf
|
||||
else:
|
||||
f = math.sqrt(avg/pc)
|
||||
if pc > avg-math.sqrt(avg) and pc < avg+math.sqrt(avg):
|
||||
f = 1.
|
||||
sf = self._shapeF(f)
|
||||
if t == 0:
|
||||
self.edgesX[y][x] = self.edgesX[y][x] / sf
|
||||
self.edgesE[y][x] = self.edgesE[y][x] / sf
|
||||
self.edgesF[y][x] = self.edgesF[y][x] / sf
|
||||
if t == 1:
|
||||
self.edgesY[y][x+1] = self.edgesY[y][x+1] / sf
|
||||
self.edgesF[y][x] = self.edgesF[y][x] / sf
|
||||
self.edgesH[y][x] = self.edgesH[y][x] / sf
|
||||
if t == 2:
|
||||
self.edgesX[y+1][x] = self.edgesX[y+1][x] / sf
|
||||
self.edgesH[y][x] = self.edgesH[y][x] / sf
|
||||
self.edgesG[y][x] = self.edgesG[y][x] / sf
|
||||
if t == 3:
|
||||
self.edgesY[y][x] = self.edgesY[y][x] / sf
|
||||
self.edgesG[y][x] = self.edgesG[y][x] / sf
|
||||
self.edgesE[y][x] = self.edgesE[y][x] / sf
|
||||
|
||||
|
||||
def calculatePixelCorners2(self):
|
||||
w = 20
|
||||
posMat = []
|
||||
CrVx = np.zeros((self.nCorners,self.nCorners))
|
||||
CrVy = np.zeros((self.nCorners,self.nCorners))
|
||||
ZrVx = np.zeros((self.nPixels,self.nPixels))
|
||||
ZrVy = np.zeros((self.nPixels,self.nPixels))
|
||||
|
||||
#boundary conditions matrix/vectors
|
||||
BCposMatX = []
|
||||
BCposMatY = []
|
||||
BCrVx = []
|
||||
BCrVy = []
|
||||
|
||||
for y in range(self.nCorners):
|
||||
for x in range(self.nCorners):
|
||||
BClineX = np.zeros((self.nCorners,self.nCorners))
|
||||
BClineY = np.zeros((self.nCorners,self.nCorners))
|
||||
if (x == 0 and y == 0) or \
|
||||
(x == 0 and y == self.nPixels) or \
|
||||
(x == self.nPixels and y == 0) or \
|
||||
(x == self.nPixels and y == self.nPixels):
|
||||
BClineX[y][x] = w
|
||||
BClineY[y][x] = w
|
||||
BCrVx.append(self.getCornerPos(y,x)[0] * w)
|
||||
BCrVy.append(self.getCornerPos(y,x)[1] * w)
|
||||
#print("bclinex shape {} zeros shape {}".format( BClineX.reshape((self.nCorners*self.nCorners,)).shape , np.zeros((self.nPixels*self.nPixels)).shape ))
|
||||
BCposMatX.append(np.hstack((BClineX.reshape((self.nCorners*self.nCorners,)),np.zeros((self.nPixels*self.nPixels,)) )) )
|
||||
BCposMatY.append(np.hstack((BClineY.reshape((self.nCorners*self.nCorners,)),np.zeros((self.nPixels*self.nPixels,)) )) )
|
||||
|
||||
elif x == 0 or x == self.nPixels:
|
||||
BClineX[y][x] = w
|
||||
#BClineY[y][x] = 1
|
||||
BCrVx.append(self.getCornerPos(y,x)[0] * w)
|
||||
#BCrVy.append(self.getCornerPos(y,x)[1])
|
||||
BCposMatX.append(np.hstack((BClineX.reshape((self.nCorners*self.nCorners,)),np.zeros((self.nPixels*self.nPixels,)) )) )
|
||||
#BCposMatY.append(np.hstack((BClineY.reshape((self.nCorners*self.nCorners,)),np.zeros((self.nPixels*self.nPixels,)) )) )
|
||||
elif y == 0 or y == self.nPixels:
|
||||
#BClineX[y][x] = 1
|
||||
BClineY[y][x] = w
|
||||
#BCrVx.append(self.getCornerPos(y,x)[0])
|
||||
BCrVy.append(self.getCornerPos(y,x)[1] * w)
|
||||
#BCposMatX.append(np.hstack((BClineX.reshape((self.nCorners*self.nCorners,)),np.zeros((self.nPixels*self.nPixels,)) )) )
|
||||
BCposMatY.append(np.hstack((BClineY.reshape((self.nCorners*self.nCorners,)),np.zeros((self.nPixels*self.nPixels,)) )) )
|
||||
|
||||
|
||||
eLength = 0
|
||||
|
||||
if x != 0:
|
||||
eLength += self.edgesX[y][x-1]
|
||||
if y != 0:
|
||||
eLength += self.edgesY[y-1][x]
|
||||
if x != self.nPixels:
|
||||
eLength += self.edgesX[y][x]
|
||||
if y != self.nPixels:
|
||||
eLength += self.edgesY[y][x]
|
||||
|
||||
if y != 0 and x != 0:
|
||||
eLength += self.edgesH[y-1][x-1]
|
||||
if y != self.nPixels and x != 0:
|
||||
eLength += self.edgesF[y][x-1]
|
||||
if y != 0 and x != self.nPixels:
|
||||
eLength += self.edgesG[y-1][x]
|
||||
if y != self.nPixels and x != self.nPixels:
|
||||
eLength += self.edgesE[y][x]
|
||||
|
||||
line = np.zeros((self.nCorners,self.nCorners))
|
||||
lineZ = np.zeros((self.nPixels,self.nPixels))
|
||||
|
||||
|
||||
if x != 0:
|
||||
line[y][x-1] = - self.edgesX[y][x-1]/eLength
|
||||
if y != 0:
|
||||
line[y-1][x] = - self.edgesY[y-1][x]/eLength
|
||||
if x != self.nPixels:
|
||||
line[y][x+1] = - self.edgesX[y][x]/eLength
|
||||
if y != self.nPixels:
|
||||
line[y+1][x] = - self.edgesY[y][x]/eLength
|
||||
|
||||
if y != 0 and x != 0:
|
||||
lineZ[y-1][x-1] = -self.edgesH[y-1][x-1]/eLength
|
||||
if y != self.nPixels and x != 0:
|
||||
lineZ[y][x-1] = -self.edgesF[y][x-1]/eLength
|
||||
if y != 0 and x != self.nPixels:
|
||||
lineZ[y-1][x] = -self.edgesG[y-1][x]/eLength
|
||||
if y != self.nPixels and x != self.nPixels:
|
||||
lineZ[y][x] = -self.edgesE[y][x]/eLength
|
||||
|
||||
|
||||
line[y][x] = 1
|
||||
CrVx[y][x] = 0
|
||||
CrVy[y][x] = 0
|
||||
posMat.append( \
|
||||
np.hstack(( \
|
||||
line.reshape((self.nCorners*self.nCorners,)), \
|
||||
lineZ.reshape((self.nPixels*self.nPixels,)) \
|
||||
)) \
|
||||
)
|
||||
|
||||
for y in range(self.nPixels):
|
||||
for x in range(self.nPixels):
|
||||
line = np.zeros((self.nCorners,self.nCorners))
|
||||
lineZ = np.zeros((self.nPixels,self.nPixels))
|
||||
|
||||
eLength = self.edgesE[y][x] + self.edgesF[y][x] +self.edgesG[y][x] +self.edgesH[y][x]
|
||||
line[y][x] = -self.edgesE[y][x] / eLength
|
||||
line[y][x+1] = -self.edgesF[y][x] / eLength
|
||||
line[y+1][x] = -self.edgesG[y][x] / eLength
|
||||
line[y+1][x+1] = -self.edgesH[y][x] / eLength
|
||||
|
||||
lineZ[y][x] = 1
|
||||
ZrVx[y][x] = 0
|
||||
ZrVy[y][x] = 0
|
||||
posMat.append( \
|
||||
np.hstack(( \
|
||||
line.reshape((self.nCorners*self.nCorners,)), \
|
||||
lineZ.reshape((self.nPixels*self.nPixels,)) \
|
||||
)) \
|
||||
)
|
||||
|
||||
CrVxFlat = CrVx.reshape((self.nCorners*self.nCorners,))
|
||||
CrVyFlat = CrVy.reshape((self.nCorners*self.nCorners,))
|
||||
ZrVxFlat = ZrVx.reshape((self.nPixels*self.nPixels,))
|
||||
ZrVyFlat = ZrVy.reshape((self.nPixels*self.nPixels,))
|
||||
posMat = np.asarray(posMat)
|
||||
|
||||
BCrVyFlat = np.asarray(BCrVy)
|
||||
BCrVxFlat = np.asarray(BCrVx)
|
||||
BCposMatX = np.asarray(BCposMatX)
|
||||
BCposMatY = np.asarray(BCposMatY)
|
||||
|
||||
print ("BCposMatY vy {} shape posMat {}".format(BCposMatY.shape,posMat.shape))
|
||||
|
||||
FinalrVy = np.hstack((CrVyFlat,ZrVyFlat,BCrVyFlat))
|
||||
FinalrVx = np.hstack((CrVxFlat,ZrVxFlat,BCrVxFlat))
|
||||
FinalposMatX = np.vstack((posMat,BCposMatX))
|
||||
FinalposMatY = np.vstack((posMat,BCposMatY))
|
||||
|
||||
print("posMat shape {}".format(posMat.shape))
|
||||
print("posMatX shape {}".format(FinalposMatX.shape))
|
||||
print("rVxFlat shape {}".format(FinalrVx.shape))
|
||||
|
||||
#print("posMat {}".format(FinalposMat))
|
||||
#print("rVxFlat {}".format(FinalrVx))
|
||||
|
||||
xPos = np.linalg.lstsq(FinalposMatX,FinalrVx)[0]
|
||||
yPos = np.linalg.lstsq(FinalposMatY,FinalrVy)[0]
|
||||
|
||||
print("xPosShape {} cutXPosShape {}".format(xPos.shape,xPos[:self.nCorners][:self.nCorners].shape))
|
||||
|
||||
self.cPosX = xPos[:self.nCorners*self.nCorners].reshape((self.nCorners,self.nCorners))
|
||||
self.cPosY = yPos[:self.nCorners*self.nCorners].reshape((self.nCorners,self.nCorners))
|
||||
|
||||
self.zPosX = xPos[self.nCorners*self.nCorners:].reshape((self.nPixels,self.nPixels))
|
||||
self.zPosY = yPos[self.nCorners*self.nCorners:].reshape((self.nPixels,self.nPixels))
|
||||
|
||||
|
||||
|
||||
def fill(self,yy,xx,count = 1):
|
||||
[y,x,t] = self.getPixel(yy,xx)
|
||||
self.counts[y][x][t] += count
|
||||
|
||||
def getCountDist(self):
|
||||
c = []
|
||||
for y in range(self.nPixels):
|
||||
for x in range(self.nPixels):
|
||||
c.append(self.counts[y][x])
|
||||
return c
|
||||
|
||||
def getPixel(self,yy,xx, debug = False):
|
||||
for y in range(self.nPixels):
|
||||
for x in range(self.nPixels):
|
||||
for t in range(4):
|
||||
[v1x,v1y,v2x,v2y,v3x,v3y] = self.getTriangleCorner(y,x,t)
|
||||
if self.pointInTriangle([xx,yy],[v1x,v1y],[v2x,v2y],[v3x,v3y]):
|
||||
return [y,x,t]
|
||||
|
||||
if not debug:
|
||||
raise Exception("not inside a pixel")
|
||||
else:
|
||||
print("no pixel found")
|
||||
return [0,0]
|
||||
|
||||
#http://stackoverflow.com/questions/2049582/how-to-determine-a-point-in-a-2d-triangle
|
||||
def trSign (self, p1, p2, p3):
|
||||
return (p1[0] - p3[0]) * (p2[1] - p3[1]) - (p2[0] - p3[0]) * (p1[1] - p3[1]);
|
||||
|
||||
def pointInTriangle (self,pt, v1, v2, v3):
|
||||
b1 = self.trSign(pt, v1, v2) < 0.0
|
||||
b2 = self.trSign(pt, v2, v3) < 0.0
|
||||
b3 = self.trSign(pt, v3, v1) < 0.0
|
||||
return ((b1 == b2) and (b2 == b3));
|
||||
|
||||
def getAvgCounts(self):
|
||||
return self.getTotalCounts() / self.nPixels/self.nPixels/4.
|
||||
|
||||
def getTotalCounts(self):
|
||||
tot = 0
|
||||
for y in range(self.nPixels):
|
||||
for x in range(self.nPixels):
|
||||
for t in range(4):
|
||||
tot += self.counts[y][x][t]
|
||||
return tot
|
||||
|
||||
#tl tr bl br
|
||||
def getPixelCorners(self,iy,ix):
|
||||
return self.getCornerPos(iy,ix) + self.getCornerPos(iy,ix+1) + self.getCornerPos(iy+1,ix) + self.getCornerPos(iy+1,ix+1)
|
||||
|
||||
def getTriangleCorner(self,iy,ix,tr):
|
||||
if tr == 0:
|
||||
return self.getCornerPos(iy,ix) + self.getCornerPos(iy,ix+1) + [self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
if tr == 1:
|
||||
return self.getCornerPos(iy,ix+1) + self.getCornerPos(iy+1,ix+1) + [self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
if tr == 2:
|
||||
return self.getCornerPos(iy+1,ix+1) + self.getCornerPos(iy+1,ix) + [self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
if tr == 3:
|
||||
return self.getCornerPos(iy+1,ix) + self.getCornerPos(iy,ix) + [self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
|
||||
def getCornerPos(self,iy,ix):
|
||||
return [self.cPosX[iy][ix],self.cPosY[iy][ix]]
|
||||
|
||||
def getXEdgePos(self,iy,ix):
|
||||
p1 = self.getCornerPos(iy,ix)
|
||||
p2 = self.getCornerPos(iy,ix+1)
|
||||
return [p1[0],p1[1],p2[0],p2[1]]
|
||||
|
||||
def getYEdgePos(self,iy,ix):
|
||||
p1 = self.getCornerPos(iy,ix)
|
||||
p2 = self.getCornerPos(iy+1,ix)
|
||||
return [p1[0],p1[1],p2[0],p2[1]]
|
||||
|
||||
def getEEdgePos(self,iy,ix):
|
||||
p1 = self.getCornerPos(iy,ix)
|
||||
return [p1[0],p1[1],self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
|
||||
def getFEdgePos(self,iy,ix):
|
||||
p1 = self.getCornerPos(iy,ix+1)
|
||||
return [p1[0],p1[1],self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
|
||||
def getGEdgePos(self,iy,ix):
|
||||
p1 = self.getCornerPos(iy+1,ix)
|
||||
return [p1[0],p1[1],self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
|
||||
def getHEdgePos(self,iy,ix):
|
||||
p1 = self.getCornerPos(iy+1,ix+1)
|
||||
return [p1[0],p1[1],self.zPosX[iy][ix],self.zPosY[iy][ix]]
|
||||
|
448
slsDetectorCalibration/etaVEL/imageMacro.C
Normal file
448
slsDetectorCalibration/etaVEL/imageMacro.C
Normal file
@ -0,0 +1,448 @@
|
||||
void imageMacro(char *name){
|
||||
//TH2D *makeNorm(){
|
||||
|
||||
//TFile ff("/local_zfs_raid/tomcat_20160528/trees/img_blank_eta_gmap.root");
|
||||
//TH2D *hff=(TH2D*)ff.Get("imgHR");
|
||||
TFile ff("/local_zfs_raid/tomcat_20160528/trees/img_blank_eta_nb25.root");
|
||||
// TFile ff("/local_zfs_raid/tomcat_20160528/trees/img_blank_eta_gcorr_nb25.root");
|
||||
TH2D *hff=(TH2D*)ff.Get("blankHR");
|
||||
hff->SetName("imgBlank");
|
||||
TH2D *hpixel=new TH2D("hpixel","hpixel",25,0,25,25,0,25);
|
||||
for (int ibx=10*25; ibx<hff->GetNbinsX()-10*25; ibx++) {
|
||||
for (int iby=20*25; iby<hff->GetNbinsY()-20*25; iby++) {
|
||||
hpixel->Fill((ibx-12)%25,(iby-12)%25,hff->GetBinContent(ibx+1,iby+1));
|
||||
}
|
||||
}
|
||||
hpixel->Scale(1./hpixel->GetBinContent(13,13));
|
||||
|
||||
// new TCanvas();
|
||||
// hpixel->Draw("colz");
|
||||
|
||||
// TH2D *hraw=(TH2D*)hff->Clone("hraw");
|
||||
TH2D *hpix=(TH2D*)hff->Clone("hpix");
|
||||
|
||||
for (int ibx=0; ibx<hff->GetNbinsX(); ibx++) {
|
||||
for (int iby=0; iby<hff->GetNbinsY(); iby++) {
|
||||
hpix->SetBinContent(ibx+1,iby+1,hpixel->GetBinContent(hpixel->GetXaxis()->FindBin((ibx-12)%25),hpixel->GetXaxis()->FindBin((iby-12)%25)));
|
||||
}
|
||||
}
|
||||
// return hpix;
|
||||
//}
|
||||
|
||||
//void imageMacro(char *name,TH2D *hpix=NULL){
|
||||
// hff->Divide(hpix);
|
||||
|
||||
// new TCanvas();
|
||||
// hff->Draw("colz");
|
||||
|
||||
// if (hpix==NULL)
|
||||
// hpix=makeNorm();
|
||||
TH2D *hg;
|
||||
|
||||
char nn[1000];
|
||||
if (strcmp(name,"blank")==NULL) {
|
||||
hg=hff;
|
||||
} else {
|
||||
|
||||
|
||||
sprintf(nn,"/local_zfs_raid/tomcat_20160528/trees/img_%s_eta_nb25.root", name);
|
||||
// if (strcmp(name,"blank"))
|
||||
TFile fg(nn);
|
||||
// else
|
||||
// TFile fg=gDirectory;
|
||||
|
||||
//TFile fg("/local_zfs_raid/tomcat_20160528/trees/img_grating_1d_eta_gmap.root");
|
||||
//TH2D *hg=(TH2D*)fg.Get("imgHR");
|
||||
// TFile fg("/local_zfs_raid/tomcat_20160528/trees/img_grating_1d_eta_nb25.root");
|
||||
// TFile fg("/local_zfs_raid/tomcat_20160528/trees/img_sample_eta_nb25.root");
|
||||
// TFile fg("/local_zfs_raid/tomcat_20160528/trees/img_grating_1d_eta_gcorr_nb25.root");
|
||||
sprintf(nn,"%sHR",name);
|
||||
TH2D *hg=(TH2D*)fg.Get(nn);
|
||||
// hg->SetName("imgGrating");
|
||||
|
||||
//hg->Divide(hff);
|
||||
}
|
||||
if (hpix)
|
||||
hg->Divide(hpix);
|
||||
|
||||
Double_t imageData[200*400*25*25];
|
||||
const int nsigma=5.;
|
||||
int ip=0;
|
||||
int max=0;
|
||||
Double_t avg=0, rms=0;
|
||||
for (int iby=0; iby<hg->GetNbinsY(); iby++) {
|
||||
for (int ibx=0; ibx<hg->GetNbinsX(); ibx++) {
|
||||
imageData[ip]=hg->GetBinContent(ibx+1,iby+1);
|
||||
if (imageData[ip]>max) max=imageData[ip];
|
||||
// if (imageData[ip]>3000) imageData[ip]=3000.;
|
||||
avg+=((Double_t)imageData[ip])/(hg->GetNbinsY()*hg->GetNbinsX());
|
||||
rms+=((Double_t)imageData[ip])*((Double_t)imageData[ip])/(hg->GetNbinsY()*hg->GetNbinsX());
|
||||
ip++;
|
||||
}
|
||||
}
|
||||
rms=TMath::Sqrt(rms-avg*avg);
|
||||
ip=0;
|
||||
for (int iby=0; iby<hg->GetNbinsY(); iby++) {
|
||||
for (int ibx=0; ibx<hg->GetNbinsX(); ibx++) {
|
||||
if (imageData[ip]>avg+nsigma*rms) imageData[ip]=avg+nsigma*rms;
|
||||
// if (imageData[ip]>3000) imageData[ip]=3000.;
|
||||
ip++;
|
||||
}
|
||||
}
|
||||
cout << "MAXIMUM IS "<< max << endl;
|
||||
cout << "AVERAGE IS "<< avg << endl;
|
||||
cout << "RMS IS "<< rms << endl;
|
||||
|
||||
|
||||
int nbx=hg->GetNbinsX();
|
||||
int nby=hg->GetNbinsY();
|
||||
Short_t *buffer=new Short_t[nbx];
|
||||
// // cout << "Size of short int is "<<sizeof(char)<< endl;
|
||||
// // cout << "width is "<<nbx<< endl;
|
||||
// // cout << "height is "<<nby<< endl;
|
||||
sprintf(nn,"%s_HR.bin", name);
|
||||
ofstream myFile (nn, ios::out | ios::binary);
|
||||
ip=0;
|
||||
for (int iy=0; iy<nby; iy++) {
|
||||
for (int ix=0; ix<nbx; ix++) {
|
||||
buffer[ix]=imageData[ip]*65535/nsigma/avg;
|
||||
ip++;
|
||||
}
|
||||
myFile.write((char*)buffer, nbx*sizeof(Short_t));
|
||||
}
|
||||
myFile.close();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TASImage *img=new TASImage ( "img",imageData, 400*25, 200*25);// TImagePalette * palette = 0
|
||||
new TCanvas();
|
||||
img->SetImageCompression(0);
|
||||
img->SetImageQuality(TAttImage::kImgBest);
|
||||
// img->Gray(kTRUE);
|
||||
img->Draw();
|
||||
|
||||
sprintf(nn,"%s_HR.tiff", name);
|
||||
|
||||
img->WriteImage(nn, TImage::kTiff);
|
||||
|
||||
// new TCanvas();
|
||||
// hg->SetMaximum(3000);
|
||||
// hg->DrawCopy("colz");
|
||||
|
||||
|
||||
hg->Rebin2D(25,25);
|
||||
|
||||
Double_t imageDataLR[200*400];
|
||||
|
||||
ip=0; max=0;avg=0; rms=0;
|
||||
for (int iby=0; iby<hg->GetNbinsY(); iby++) {
|
||||
for (int ibx=0; ibx<hg->GetNbinsX(); ibx++) {
|
||||
imageDataLR[ip]=hg->GetBinContent(ibx+1,iby+1);
|
||||
if (imageDataLR[ip]>max) max=imageDataLR[ip];
|
||||
avg+=((Double_t)imageDataLR[ip])/(hg->GetNbinsY()*hg->GetNbinsX());
|
||||
rms+=((Double_t)imageDataLR[ip])*((Double_t)imageDataLR[ip])/(hg->GetNbinsY()*hg->GetNbinsX());
|
||||
ip++;
|
||||
}
|
||||
}
|
||||
rms=TMath::Sqrt(rms-avg*avg);
|
||||
ip=0;
|
||||
for (int iby=0; iby<hg->GetNbinsY(); iby++) {
|
||||
for (int ibx=0; ibx<hg->GetNbinsX(); ibx++) {
|
||||
if (imageDataLR[ip]>avg+nsigma*rms) imageDataLR[ip]=avg+nsigma*rms;
|
||||
// if (imageData[ip]>3000) imageData[ip]=3000.;
|
||||
ip++;
|
||||
}
|
||||
}
|
||||
cout << "MAXIMUM IS "<< max << endl;
|
||||
cout << "AVERAGE IS "<< avg << endl;
|
||||
cout << "RMS IS "<< rms << endl;
|
||||
|
||||
TASImage *imgLR=new TASImage ( "imgLR",imageDataLR, 400, 200);// TImagePalette * palette = 0
|
||||
new TCanvas();
|
||||
imgLR->SetImageCompression(0);
|
||||
imgLR->SetImageQuality(TAttImage::kImgBest);
|
||||
// imgLR->Gray(kTRUE);
|
||||
imgLR->Draw();
|
||||
|
||||
|
||||
sprintf(nn,"%s_LR.tiff", name);
|
||||
|
||||
imgLR->WriteImage(nn, TImage::kTiff);
|
||||
|
||||
|
||||
int nbx1=hg->GetNbinsX();
|
||||
int nby1=hg->GetNbinsY();
|
||||
Short_t *buffer1=new Short_t[nbx1];
|
||||
// // cout << "Size of short int is "<<sizeof(char)<< endl;
|
||||
// // cout << "width is "<<nbx<< endl;
|
||||
// // cout << "height is "<<nby<< endl;
|
||||
sprintf(nn,"%s_LR.bin", name);
|
||||
ofstream myFile1 (nn, ios::out | ios::binary);
|
||||
ip=0;
|
||||
for (int iy=0; iy<nby1; iy++) {
|
||||
for (int ix=0; ix<nbx1; ix++) {
|
||||
buffer1[ix]=imageDataLR[ip]*256/nsigma/avg;
|
||||
ip++;
|
||||
}
|
||||
myFile1.write((char*)buffer1, nbx1*sizeof(Short_t));
|
||||
}
|
||||
myFile1.close();
|
||||
|
||||
cout << sizeof(Short_t) << endl;
|
||||
//for grating2D the gratings are in the pixels (150-260)x(80-190)
|
||||
|
||||
|
||||
|
||||
|
||||
// // hg->Draw("colz");
|
||||
// int off=13;
|
||||
// // hg->Divide(hpix);
|
||||
// int ix,iy, sbx, sby, ibx2, iby2, sbx2, sby2;
|
||||
// TH2F *hh13b=new TH2F("hh13b","hh13b",400*24,0,400,200*24,100,300);
|
||||
// TH2F *hh13=new TH2F("hh13","hh13",400*23,0,400,200*23,100,300);
|
||||
// TH2F *hh=new TH2F("hh","hh",400*21,0,400,200*21,100,300);
|
||||
// TH2F *h1=new TH2F("h1","h1",400*23,0,400,200*23,100,300);
|
||||
// for (int ibx=0; ibx<hg->GetNbinsX(); ibx++) {
|
||||
// for (int iby=0; iby<hg->GetNbinsY(); iby++) {
|
||||
// ix=(ibx-off)/25;
|
||||
// iy=(iby-off)/25;
|
||||
// sbx=(ibx-off)%25;
|
||||
// sby=(iby-off)%25;
|
||||
// sbx2=sbx-1;
|
||||
// sby2=sby-1;
|
||||
// if (sbx2<0) sbx2=0;
|
||||
// if (sby2<0) sby2=0;
|
||||
// if (sbx2>22) sbx2=22;
|
||||
// if (sby2>22) sby2=22;
|
||||
// ibx2=ix*23+(sbx2+off);
|
||||
// iby2=iy*23+(sby2+off);
|
||||
|
||||
// hh13->Fill(hh13->GetXaxis()->GetBinCenter(ibx2+1),hh13->GetYaxis()->GetBinCenter(iby2+1),hg->GetBinContent(ibx+1,iby+1));
|
||||
// // h1->Fill(h1->GetXaxis()->GetBinCenter(ibx2+1),h1->GetYaxis()->GetBinCenter(iby2+1),hpix->GetBinContent(ibx+1,iby+1));
|
||||
|
||||
// off=13;
|
||||
|
||||
// ix=(ibx-off)/25;
|
||||
// iy=(iby-off)/25;
|
||||
// sbx=(ibx-off)%25;
|
||||
// sby=(iby-off)%25;
|
||||
// sbx2=sbx-1;
|
||||
// sby2=sby-1;
|
||||
// // if (sbx2<0) sbx2=0;
|
||||
// // if (sby2<0) sby2=0;
|
||||
// ibx2=ix*24+(sbx2+off);
|
||||
// iby2=iy*24+(sby2+off);
|
||||
|
||||
// if (sbx2<0 && sby2>=0) {
|
||||
// ibx2=ix*24+(sbx2+off);
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.5*hg->GetBinContent(ibx+1,iby+1));
|
||||
// ibx2=ix*24+(sbx2+off)+1;
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.5*hg->GetBinContent(ibx+1,iby+1));
|
||||
// } else if (sby2<0 && sbx2>=0){
|
||||
// iby2=iy*24+(sby2+off);
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.5*hg->GetBinContent(ibx+1,iby+1));
|
||||
// iby2=iy*24+(sby2+off)+1;
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.5*hg->GetBinContent(ibx+1,iby+1));
|
||||
// } else if (sby2<0 && sbx2<0){
|
||||
// iby2=iy*24+(sby2+off);
|
||||
// ibx2=ix*24+(sbx2+off);
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.25*hg->GetBinContent(ibx+1,iby+1));
|
||||
// iby2=iy*24+(sby2+off)+1;
|
||||
// ibx2=ix*24+(sbx2+off);
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.25*hg->GetBinContent(ibx+1,iby+1));
|
||||
// iby2=iy*24+(sby2+off);
|
||||
// ibx2=ix*24+(sbx2+off)+1;
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.25*hg->GetBinContent(ibx+1,iby+1));
|
||||
// iby2=iy*24+(sby2+off)+1;
|
||||
// ibx2=ix*24+(sbx2+off)+1;
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),0.25*hg->GetBinContent(ibx+1,iby+1));
|
||||
// }else {
|
||||
|
||||
|
||||
// hh13b->Fill(hh13b->GetXaxis()->GetBinCenter(ibx2+1),hh13b->GetYaxis()->GetBinCenter(iby2+1),hg->GetBinContent(ibx+1,iby+1));
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// ix=(ibx-off)/25;
|
||||
// iy=(iby-off)/25;
|
||||
// sbx=(ibx-off)%25;
|
||||
// sby=(iby-off)%25;
|
||||
// sbx2=sbx-2;
|
||||
// sby2=sby-2;
|
||||
// if (sbx2<0) sbx2=-1;
|
||||
// if (sby2<0) sby2=-1;
|
||||
// if (sbx2>20) sbx2=-1;
|
||||
// if (sby2>20) sby2=-1;
|
||||
// ibx2=ix*21+(sbx2+off);
|
||||
// iby2=iy*21+(sby2+off);
|
||||
// if (sbx2>=0 && sby2>=0) hh->Fill(hh->GetXaxis()->GetBinCenter(ibx2+1),hh->GetYaxis()->GetBinCenter(iby2+1),hg->GetBinContent(ibx+1,iby+1));
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
// new TCanvas();
|
||||
// hg->GetXaxis()->SetRangeUser(84,87);
|
||||
// hg->GetYaxis()->SetRangeUser(120,124);
|
||||
// hg->Draw("colz");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// new TCanvas();
|
||||
// // hh->Divide(h1);
|
||||
// hh->GetXaxis()->SetRangeUser(84,87);
|
||||
// hh->GetYaxis()->SetRangeUser(120,124);
|
||||
// hh->Draw("colz");
|
||||
|
||||
|
||||
// new TCanvas();
|
||||
// // hh->Divide(h1);
|
||||
// hh13b->GetXaxis()->SetRangeUser(84,87);
|
||||
// hh13b->GetYaxis()->SetRangeUser(120,124);
|
||||
// hh13b->Draw("colz");
|
||||
|
||||
// new TCanvas();
|
||||
// // hh->Divide(h1);
|
||||
// hh13->GetXaxis()->SetRangeUser(84,87);
|
||||
// hh13->GetYaxis()->SetRangeUser(120,124);
|
||||
// hh13->Draw("colz");
|
||||
|
||||
// // //TFile fsg("/local_zfs_raid/tomcat_20160528/trees/img_sample_grating_1d_eta_gmap.root");
|
||||
// // //TH2D *hsg=(TH2D*)fsg.Get("sample_grating_1dHR");
|
||||
// // TFile fsg("/local_zfs_raid/tomcat_20160528/trees/img_sample_grating_1d_eta.root");
|
||||
// // TH2D *hsg=(TH2D*)fsg.Get("imgHR");
|
||||
// // hsg->SetName("imgGratingSample");
|
||||
|
||||
|
||||
// // hsg->Divide(hpix);
|
||||
|
||||
// // Double_t nf=hff->Integral(100,hff->GetNbinsX()-100,hff->GetYaxis()->FindBin(130), hff->GetYaxis()->FindBin(140))/((hff->GetNbinsX()-200)*250);
|
||||
// // hff->Scale(1./nf);
|
||||
|
||||
// // // hg->Divide(hff);
|
||||
// // //hsg->Divide(hff);
|
||||
|
||||
// // Double_t ng=hg->Integral(100,hg->GetNbinsX()-100,hg->GetYaxis()->FindBin(130), hg->GetYaxis()->FindBin(140))/((hg->GetNbinsX()-200)*250);
|
||||
// // Double_t nsg=hsg->Integral(100,hsg->GetNbinsX()-100,hsg->GetYaxis()->FindBin(130), hsg->GetYaxis()->FindBin(140))/((hsg->GetNbinsX()-200)*250);
|
||||
|
||||
// // hg->Scale(1/ng);
|
||||
// // hsg->Scale(1/nsg);
|
||||
|
||||
// // // new TCanvas();
|
||||
// // // hg->SetMaximum(1.);
|
||||
// // // hg->Draw("colz");
|
||||
// // // new TCanvas();
|
||||
// // // hsg->SetMaximum(1.);
|
||||
// // // hsg->Draw("colz");
|
||||
|
||||
// // // TH1D *pg=hg->ProjectionX("pg",hg->GetYaxis()->FindBin(174.5)+1,hg->GetYaxis()->FindBin(175.5));
|
||||
// // // TH1D *psg=hsg->ProjectionX("psg",hsg->GetYaxis()->FindBin(174.5)+1,hsg->GetYaxis()->FindBin(175.5));
|
||||
// // // psg->SetLineColor(2);
|
||||
// // // new TCanvas();
|
||||
|
||||
// // // pg->Draw("l");
|
||||
// // // psg->Draw("l same");
|
||||
|
||||
// // int nbx=hg->GetNbinsX();
|
||||
// // int nby=hg->GetNbinsY();
|
||||
// // char buffer[nbx];
|
||||
// // cout << "Size of short int is "<<sizeof(char)<< endl;
|
||||
// // cout << "width is "<<nbx<< endl;
|
||||
// // cout << "height is "<<nby<< endl;
|
||||
// // ofstream myFile ("grating_1d.bin", ios::out | ios::binary);
|
||||
// // for (int iy=0; iy<nby; iy++) {
|
||||
// // for (int ix=0; ix<nbx; ix++) {
|
||||
// // buffer[ix]=hg->GetBinContent(ix+1,iy+1);
|
||||
// // }
|
||||
// // myFile.write((char*)buffer, nbx*sizeof(char));
|
||||
// // }
|
||||
// // myFile.close();
|
||||
|
||||
|
||||
// // nbx=hsg->GetNbinsX();
|
||||
// // nby=hsg->GetNbinsY();
|
||||
|
||||
// // cout << "Size of short int is "<<sizeof(char)<< endl;
|
||||
// // cout << "width is "<<nbx<< endl;
|
||||
// // cout << "height is "<<nby<< endl;
|
||||
|
||||
// // ofstream myFile1 ("sample_grating_1d.bin", ios::out | ios::binary);
|
||||
// // for (int iy=0; iy<nby; iy++) {
|
||||
// // for (int ix=0; ix<nbx; ix++) {
|
||||
// // buffer[ix]=hsg->GetBinContent(ix+1,iy+1);
|
||||
// // }
|
||||
// // myFile1.write((char*)buffer, nbx*sizeof(char));
|
||||
// // }
|
||||
// // myFile1.close();
|
||||
|
||||
// // NAME
|
||||
// // raw2tiff - create a TIFF file from a raw data
|
||||
|
||||
// // SYNOPSIS
|
||||
// // raw2tiff [ options ] input.raw output.tif
|
||||
|
||||
// // DESCRIPTION
|
||||
// // raw2tiff converts a raw byte sequence into TIFF. By default, the TIFF image is created with data samples packed (PlanarConfiguration=1), compressed with the PackBits algorithm (Compression=32773),
|
||||
// // and with each strip no more than 8 kilobytes. These characteristics can overridden, or explicitly specified with the options described below.
|
||||
|
||||
// // OPTIONS
|
||||
// // -H number
|
||||
// // size of input image file header in bytes (0 by default). This amount of data just will be skipped from the start of file while reading.
|
||||
|
||||
// // -w number
|
||||
// // width of input image in pixels (can be guessed, see GUESSING THE IMAGE GEOMETRY below).
|
||||
|
||||
// // -l number
|
||||
// // length of input image in lines (can be guessed, see GUESSING THE IMAGE GEOMETRY below).
|
||||
|
||||
// // -b number
|
||||
// // number of bands in input image (1 by default).
|
||||
|
||||
// // -d data_type
|
||||
// // type of samples in input image, where data_type may be:
|
||||
// // byte 8-bit unsigned integer (default),
|
||||
// // short 16-bit unsigned integer,
|
||||
// // long 32-bit unsigned integer,
|
||||
// // sbyte 8-bit signed integer,
|
||||
// // sshort 16-bit signed integer,
|
||||
// // slong 32-bit signed integer,
|
||||
// // float 32-bit IEEE floating point,
|
||||
// // double 64-bit IEEE floating point.
|
||||
|
||||
// // -i config
|
||||
// // type of samples interleaving in input image, where config may be:
|
||||
// // pixel pixel interleaved data (default),
|
||||
// // band band interleaved data.
|
||||
|
||||
// // -p photo
|
||||
// // photometric interpretation (color space) of the input image, where photo may be:
|
||||
// // miniswhite white color represented with 0 value,
|
||||
// // minisblack black color represented with 0 value (default),
|
||||
// // rgb image has RGB color model,
|
||||
// // cmyk image has CMYK (separated) color model,
|
||||
// // ycbcr image has YCbCr color model,
|
||||
// // cielab image has CIE L*a*b color model,
|
||||
// // icclab image has ICC L*a*b color model,
|
||||
// // itulab image has ITU L*a*b color model.
|
||||
|
||||
// // -s swap bytes fetched from the input file.
|
||||
|
||||
// // -L input data has LSB2MSB bit order (default).
|
||||
|
||||
// // -M input data has MSB2LSB bit order.
|
||||
|
||||
// // -c Specify a compression scheme to use when writing image data: -c none for no compression, -c packbits for the PackBits compression algorithm (the default), -c jpeg for the baseline JPEG compres-
|
||||
// // sion algorithm, -c zip for the Deflate compression algorithm, and -c lzw for Lempel-Ziv & Welch.
|
||||
|
||||
// // -r number
|
||||
// // Write data with a specified number of rows per strip; by default the number of rows/strip is selected so that each strip is approximately 8 kilobytes.
|
||||
// //width is 10000
|
||||
// //height is 5000
|
||||
|
||||
|
||||
}
|
149
slsDetectorCalibration/etaVEL/imageMacroG2D.C
Normal file
149
slsDetectorCalibration/etaVEL/imageMacroG2D.C
Normal file
@ -0,0 +1,149 @@
|
||||
{
|
||||
// TFile ff("/local_zfs_raid/tomcat_20160528/trees/img_blank_eta.root");
|
||||
// TH2D *hff=(TH2D*)ff.Get("imgHR");
|
||||
TFile ff("/local_zfs_raid/tomcat_20160528/trees/img_blank_eta_gmap_v2.root");
|
||||
TH2D *hff=(TH2D*)ff.Get("blankHR");
|
||||
hff->SetName("imgBlank");
|
||||
TH2D *hpixel=new TH2D("hpixel","hpixel",25,0,25,25,0,25);
|
||||
for (int ibx=10*25; ibx<hff->GetNbinsX()-10*25; ibx++) {
|
||||
for (int iby=20*25; iby<hff->GetNbinsY()-20*25; iby++) {
|
||||
hpixel->Fill((ibx-12)%25,(iby-12)%25,hff->GetBinContent(ibx+1,iby+1));
|
||||
}
|
||||
}
|
||||
hpixel->Scale(1./hpixel->GetBinContent(13,13));
|
||||
|
||||
// new TCanvas();
|
||||
// hpixel->Draw("colz");
|
||||
|
||||
TH2D *hraw=(TH2D*)hff->Clone("hraw");
|
||||
TH2D *hpix=(TH2D*)hff->Clone("hpix");
|
||||
|
||||
for (int ibx=0; ibx<hff->GetNbinsX(); ibx++) {
|
||||
for (int iby=0; iby<hff->GetNbinsY(); iby++) {
|
||||
hpix->SetBinContent(ibx+1,iby+1,hpixel->GetBinContent(hpixel->GetXaxis()->FindBin((ibx-12)%25),hpixel->GetXaxis()->FindBin((iby-12)%25)));
|
||||
}
|
||||
}
|
||||
|
||||
hff->Divide(hpix);
|
||||
|
||||
// new TCanvas();
|
||||
// hff->Draw("colz");
|
||||
|
||||
|
||||
// TFile fg("/local_zfs_raid/tomcat_20160528/trees/img_grating_2d_eta.root");
|
||||
// TH2D *hg=(TH2D*)fg.Get("imgHR");
|
||||
TFile fg("/local_zfs_raid/tomcat_20160528/trees/img_grating_2d_eta_gmap_v2.root");
|
||||
TH2D *hg=(TH2D*)fg.Get("grating_2dHR");
|
||||
hg->SetName("imgGrating");
|
||||
|
||||
hg->Divide(hpix);
|
||||
|
||||
|
||||
|
||||
Double_t nf=hff->Integral(100,hff->GetNbinsX()-100,hff->GetYaxis()->FindBin(130), hff->GetYaxis()->FindBin(140))/((hff->GetNbinsX()-200)*250);
|
||||
hff->Scale(1./nf);
|
||||
|
||||
// hg->Divide(hff);
|
||||
//hsg->Divide(hff);
|
||||
|
||||
Double_t ng=hg->Integral(100,hg->GetNbinsX()-100,hg->GetYaxis()->FindBin(130), hg->GetYaxis()->FindBin(140))/((hg->GetNbinsX()-200)*250);
|
||||
|
||||
hg->Scale(1/ng);
|
||||
|
||||
new TCanvas();
|
||||
hg->SetMaximum(1.);
|
||||
hg->Draw("colz");
|
||||
// new TCanvas();
|
||||
// hsg->SetMaximum(1.);
|
||||
// hsg->Draw("colz");
|
||||
|
||||
// TH1D *pg=hg->ProjectionX("pg",hg->GetYaxis()->FindBin(174.5)+1,hg->GetYaxis()->FindBin(175.5));
|
||||
// TH1D *psg=hsg->ProjectionX("psg",hsg->GetYaxis()->FindBin(174.5)+1,hsg->GetYaxis()->FindBin(175.5));
|
||||
// psg->SetLineColor(2);
|
||||
// new TCanvas();
|
||||
|
||||
// pg->Draw("l");
|
||||
// psg->Draw("l same");
|
||||
|
||||
int nbx=hg->GetNbinsX();
|
||||
int nby=hg->GetNbinsY();
|
||||
char buffer[nbx];
|
||||
cout << "Size of short int is "<<sizeof(char)<< endl;
|
||||
cout << "width is "<<nbx<< endl;
|
||||
cout << "height is "<<nby<< endl;
|
||||
ofstream myFile ("grating_2d.bin", ios::out | ios::binary);
|
||||
for (int iy=0; iy<nby; iy++) {
|
||||
for (int ix=0; ix<nbx; ix++) {
|
||||
buffer[ix]=hg->GetBinContent(ix+1,iy+1);
|
||||
}
|
||||
myFile.write((char*)buffer, nbx*sizeof(char));
|
||||
}
|
||||
myFile.close();
|
||||
|
||||
|
||||
// NAME
|
||||
// raw2tiff - create a TIFF file from a raw data
|
||||
|
||||
// SYNOPSIS
|
||||
// raw2tiff [ options ] input.raw output.tif
|
||||
|
||||
// DESCRIPTION
|
||||
// raw2tiff converts a raw byte sequence into TIFF. By default, the TIFF image is created with data samples packed (PlanarConfiguration=1), compressed with the PackBits algorithm (Compression=32773),
|
||||
// and with each strip no more than 8 kilobytes. These characteristics can overridden, or explicitly specified with the options described below.
|
||||
|
||||
// OPTIONS
|
||||
// -H number
|
||||
// size of input image file header in bytes (0 by default). This amount of data just will be skipped from the start of file while reading.
|
||||
|
||||
// -w number
|
||||
// width of input image in pixels (can be guessed, see GUESSING THE IMAGE GEOMETRY below).
|
||||
|
||||
// -l number
|
||||
// length of input image in lines (can be guessed, see GUESSING THE IMAGE GEOMETRY below).
|
||||
|
||||
// -b number
|
||||
// number of bands in input image (1 by default).
|
||||
|
||||
// -d data_type
|
||||
// type of samples in input image, where data_type may be:
|
||||
// byte 8-bit unsigned integer (default),
|
||||
// short 16-bit unsigned integer,
|
||||
// long 32-bit unsigned integer,
|
||||
// sbyte 8-bit signed integer,
|
||||
// sshort 16-bit signed integer,
|
||||
// slong 32-bit signed integer,
|
||||
// float 32-bit IEEE floating point,
|
||||
// double 64-bit IEEE floating point.
|
||||
|
||||
// -i config
|
||||
// type of samples interleaving in input image, where config may be:
|
||||
// pixel pixel interleaved data (default),
|
||||
// band band interleaved data.
|
||||
|
||||
// -p photo
|
||||
// photometric interpretation (color space) of the input image, where photo may be:
|
||||
// miniswhite white color represented with 0 value,
|
||||
// minisblack black color represented with 0 value (default),
|
||||
// rgb image has RGB color model,
|
||||
// cmyk image has CMYK (separated) color model,
|
||||
// ycbcr image has YCbCr color model,
|
||||
// cielab image has CIE L*a*b color model,
|
||||
// icclab image has ICC L*a*b color model,
|
||||
// itulab image has ITU L*a*b color model.
|
||||
|
||||
// -s swap bytes fetched from the input file.
|
||||
|
||||
// -L input data has LSB2MSB bit order (default).
|
||||
|
||||
// -M input data has MSB2LSB bit order.
|
||||
|
||||
// -c Specify a compression scheme to use when writing image data: -c none for no compression, -c packbits for the PackBits compression algorithm (the default), -c jpeg for the baseline JPEG compres-
|
||||
// sion algorithm, -c zip for the Deflate compression algorithm, and -c lzw for Lempel-Ziv & Welch.
|
||||
|
||||
// -r number
|
||||
// Write data with a specified number of rows per strip; by default the number of rows/strip is selected so that each strip is approximately 8 kilobytes.
|
||||
//width is 10000
|
||||
//height is 5000
|
||||
|
||||
|
||||
}
|
173
slsDetectorCalibration/etaVEL/imageMacroSample.C
Normal file
173
slsDetectorCalibration/etaVEL/imageMacroSample.C
Normal file
@ -0,0 +1,173 @@
|
||||
{
|
||||
// TFile ff("/local_zfs_raid/tomcat_20160528/trees/img_blank_eta.root");
|
||||
// TH2D *hff=(TH2D*)ff.Get("imgHR");
|
||||
// TFile ff("/local_zfs_raid/tomcat_20160528/trees/img_blank_eta_gmap_v2.root");
|
||||
// TH2D *hff=(TH2D*)ff.Get("blankHR");
|
||||
// hff->SetName("imgBlank");
|
||||
// TH2D *hpixel=new TH2D("hpixel","hpixel",25,0,25,25,0,25);
|
||||
// for (int ibx=10*25; ibx<hff->GetNbinsX()-10*25; ibx++) {
|
||||
// for (int iby=20*25; iby<hff->GetNbinsY()-20*25; iby++) {
|
||||
// hpixel->Fill((ibx-12)%25,(iby-12)%25,hff->GetBinContent(ibx+1,iby+1));
|
||||
// }
|
||||
// }
|
||||
// hpixel->Scale(1./hpixel->GetBinContent(13,13));
|
||||
|
||||
// // new TCanvas();
|
||||
// // hpixel->Draw("colz");
|
||||
|
||||
// TH2D *hraw=(TH2D*)hff->Clone("hraw");
|
||||
// TH2D *hpix=(TH2D*)hff->Clone("hpix");
|
||||
|
||||
// for (int ibx=0; ibx<hff->GetNbinsX(); ibx++) {
|
||||
// for (int iby=0; iby<hff->GetNbinsY(); iby++) {
|
||||
// hpix->SetBinContent(ibx+1,iby+1,hpixel->GetBinContent(hpixel->GetXaxis()->FindBin((ibx-12)%25),hpixel->GetXaxis()->FindBin((iby-12)%25)));
|
||||
// }
|
||||
// }
|
||||
|
||||
// hff->Divide(hpix);
|
||||
|
||||
// Double_t nf=hff->Integral(100,hff->GetNbinsX()-100,hff->GetYaxis()->FindBin(130), hff->GetYaxis()->FindBin(140))/((hff->GetNbinsX()-200)*250);
|
||||
// hff->Scale(1./nf);
|
||||
|
||||
// new TCanvas();
|
||||
// hff->Draw("colz");
|
||||
|
||||
|
||||
// TFile fg("/local_zfs_raid/tomcat_20160528/trees/img_grating_2d_eta.root");
|
||||
// TH2D *hg=(TH2D*)fg.Get("imgHR");
|
||||
TFile fg("/local_zfs_raid/tomcat_20160528/trees/img_sample_eta_gmap_v2.root");
|
||||
TH2D *hg=(TH2D*)fg.Get("sampleHR");
|
||||
hg->SetName("imgSample");
|
||||
|
||||
// hg->Divide(hpix);
|
||||
|
||||
|
||||
|
||||
|
||||
// hg->Divide(hff);
|
||||
//hsg->Divide(hff);
|
||||
|
||||
Double_t ng=hg->Integral(100,hg->GetNbinsX()-100,hg->GetYaxis()->FindBin(130), hg->GetYaxis()->FindBin(140))/((hg->GetNbinsX()-200)*250);
|
||||
|
||||
hg->Scale(1/ng);
|
||||
|
||||
// new TCanvas();
|
||||
// hsg->SetMaximum(1.);
|
||||
// hsg->Draw("colz");
|
||||
|
||||
// TH1D *pg=hg->ProjectionX("pg",hg->GetYaxis()->FindBin(174.5)+1,hg->GetYaxis()->FindBin(175.5));
|
||||
// TH1D *psg=hsg->ProjectionX("psg",hsg->GetYaxis()->FindBin(174.5)+1,hsg->GetYaxis()->FindBin(175.5));
|
||||
// psg->SetLineColor(2);
|
||||
// new TCanvas();
|
||||
|
||||
// pg->Draw("l");
|
||||
// psg->Draw("l same");
|
||||
TH2D *hpixel1=new TH2D("hpixel1","hpixel1",25,0,25,25,0,25);
|
||||
for (int ibx=10*25; ibx<35*25; ibx++) {
|
||||
for (int iby=25*25; iby<50*25; iby++) {
|
||||
hpixel1->Fill((ibx-12)%25,(iby-12)%25,hg->GetBinContent(ibx+1,iby+1));
|
||||
}
|
||||
}
|
||||
hpixel1->Scale(1./hpixel1->GetBinContent(13,13));
|
||||
|
||||
// new TCanvas();
|
||||
// hpixel->Draw("colz");
|
||||
|
||||
TH2D *hpix1=(TH2D*)hg->Clone("hpix1");
|
||||
|
||||
for (int ibx=0; ibx<hg->GetNbinsX(); ibx++) {
|
||||
for (int iby=0; iby<hg->GetNbinsY(); iby++) {
|
||||
hpix1->SetBinContent(ibx+1,iby+1,hpixel1->GetBinContent(hpixel1->GetXaxis()->FindBin((ibx-12)%25),hpixel1->GetXaxis()->FindBin((iby-12)%25)));
|
||||
}
|
||||
}
|
||||
|
||||
hg->Divide(hpix1);
|
||||
|
||||
new TCanvas();
|
||||
hg->SetMaximum(4);
|
||||
hg->SetMinimum(0.5);
|
||||
hg->Draw("colz");
|
||||
|
||||
|
||||
int nbx=hg->GetNbinsX();
|
||||
int nby=hg->GetNbinsY();
|
||||
char buffer[nbx];
|
||||
cout << "Size of short int is "<<sizeof(char)<< endl;
|
||||
cout << "width is "<<nbx<< endl;
|
||||
cout << "height is "<<nby<< endl;
|
||||
ofstream myFile ("sample.bin", ios::out | ios::binary);
|
||||
for (int iy=0; iy<nby; iy++) {
|
||||
for (int ix=0; ix<nbx; ix++) {
|
||||
buffer[ix]=hg->GetBinContent(ix+1,iy+1);
|
||||
}
|
||||
myFile.write((char*)buffer, nbx*sizeof(char));
|
||||
}
|
||||
myFile.close();
|
||||
|
||||
|
||||
// NAME
|
||||
// raw2tiff - create a TIFF file from a raw data
|
||||
|
||||
// SYNOPSIS
|
||||
// raw2tiff [ options ] input.raw output.tif
|
||||
|
||||
// DESCRIPTION
|
||||
// raw2tiff converts a raw byte sequence into TIFF. By default, the TIFF image is created with data samples packed (PlanarConfiguration=1), compressed with the PackBits algorithm (Compression=32773),
|
||||
// and with each strip no more than 8 kilobytes. These characteristics can overridden, or explicitly specified with the options described below.
|
||||
|
||||
// OPTIONS
|
||||
// -H number
|
||||
// size of input image file header in bytes (0 by default). This amount of data just will be skipped from the start of file while reading.
|
||||
|
||||
// -w number
|
||||
// width of input image in pixels (can be guessed, see GUESSING THE IMAGE GEOMETRY below).
|
||||
|
||||
// -l number
|
||||
// length of input image in lines (can be guessed, see GUESSING THE IMAGE GEOMETRY below).
|
||||
|
||||
// -b number
|
||||
// number of bands in input image (1 by default).
|
||||
|
||||
// -d data_type
|
||||
// type of samples in input image, where data_type may be:
|
||||
// byte 8-bit unsigned integer (default),
|
||||
// short 16-bit unsigned integer,
|
||||
// long 32-bit unsigned integer,
|
||||
// sbyte 8-bit signed integer,
|
||||
// sshort 16-bit signed integer,
|
||||
// slong 32-bit signed integer,
|
||||
// float 32-bit IEEE floating point,
|
||||
// double 64-bit IEEE floating point.
|
||||
|
||||
// -i config
|
||||
// type of samples interleaving in input image, where config may be:
|
||||
// pixel pixel interleaved data (default),
|
||||
// band band interleaved data.
|
||||
|
||||
// -p photo
|
||||
// photometric interpretation (color space) of the input image, where photo may be:
|
||||
// miniswhite white color represented with 0 value,
|
||||
// minisblack black color represented with 0 value (default),
|
||||
// rgb image has RGB color model,
|
||||
// cmyk image has CMYK (separated) color model,
|
||||
// ycbcr image has YCbCr color model,
|
||||
// cielab image has CIE L*a*b color model,
|
||||
// icclab image has ICC L*a*b color model,
|
||||
// itulab image has ITU L*a*b color model.
|
||||
|
||||
// -s swap bytes fetched from the input file.
|
||||
|
||||
// -L input data has LSB2MSB bit order (default).
|
||||
|
||||
// -M input data has MSB2LSB bit order.
|
||||
|
||||
// -c Specify a compression scheme to use when writing image data: -c none for no compression, -c packbits for the PackBits compression algorithm (the default), -c jpeg for the baseline JPEG compres-
|
||||
// sion algorithm, -c zip for the Deflate compression algorithm, and -c lzw for Lempel-Ziv & Welch.
|
||||
|
||||
// -r number
|
||||
// Write data with a specified number of rows per strip; by default the number of rows/strip is selected so that each strip is approximately 8 kilobytes.
|
||||
//width is 10000
|
||||
//height is 5000
|
||||
|
||||
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
|
||||
|
||||
|
||||
class moench03Ctb10GbData : public slsReceiverData<uint16_t> {
|
||||
class moench03Ctb10GbT1Data : public slsReceiverData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
@ -111,7 +111,6 @@ class moench03Ctb10GbData : public slsReceiverData<uint16_t> {
|
||||
|
||||
/* class jfrau_packet_header_t { */
|
||||
/* public: */
|
||||
/* unsigned char emptyHeader[6]; */
|
||||
/* unsigned char reserved[4]; */
|
||||
/* unsigned char packetNumber[1]; */
|
||||
/* unsigned char frameNumber[3]; */
|
||||
|
Loading…
x
Reference in New Issue
Block a user