Skip to content

Commit

Permalink
Merge branch 'main' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
nstelter-slac committed Apr 26, 2024
2 parents 7842783 + e5be548 commit 674f269
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 40 deletions.
6 changes: 4 additions & 2 deletions calibrationSuite/psana2Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def setupPsana(self):
try:
self.step_value = self.myrun.Detector("step_value")
self.step_docstring = self.myrun.Detector("step_docstring")
##print('foo', self.step_value, self.step_docstring)
except:
self.step_value = self.step_docstring = None

Expand Down Expand Up @@ -297,11 +298,12 @@ def getScanValue(self, step, useStringInfo=False):
##print(self.step_value(step),self.step_docstring(step),useStringInfo)
if useStringInfo:
payload = self.step_docstring(step)
##print(payload)
print(payload)
sv = eval(payload.split()[-1][:-1])
##print('sv', sv)
print("step", int(self.step_value(step)), sv)
logger.info("step" + str(int(self.step_value(step))) + str(sv))
return sv
return int(float(sv))
return self.step_value(step)

def plainGetRawData(self, evt):
Expand Down
Binary file added data/cometPinhole.npy
Binary file not shown.
Binary file added data/smallRegionFourAsicsForBhavna.npy
Binary file not shown.
Binary file added data/smallRegionTwoAsicsForBhavna.npy
Binary file not shown.
4 changes: 1 addition & 3 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ current_dir=$(pwd)
export PYTHONPATH="$PYTHONPATH:$current_dir"

# so output folders are written in a shared location
#export OUTPUT_ROOT="/sdf/data/lcls/ds/rix/rixx1003721/results/scripts/"
export OUTPUT_ROOT="/sdf/data/lcls/ds/rix/rixx1005922/scratch/"
echo "export OUTPUT_ROOT="\"$OUTPUT_ROOT\"

# point to which config file to use
#export SUITE_CONFIG="rixSuiteConfig.py"
export SUITE_CONFIG="epixMSuiteConfig.py"
echo "export SUITE_CONFIG="\"$SUITE_CONFIG\"
echo "export SUITE_CONFIG="\"$SUITE_CONFIG\"
1 change: 1 addition & 0 deletions standalone_scripts/simpler_epixhr.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ds = DataSource(exp="%s" % (expt), run=run)
myrun = next(ds.runs())
det = myrun.Detector("epixhr")
det = myrun.Detector("epixm")


from psmon import publish
Expand Down
12 changes: 7 additions & 5 deletions suite_scripts/AnalyzeH5.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def __init__(self):
self.files = args.files.replace(" ", "")
print(self.files)
self.outputDir = args.path
logging.info("Output dir: " + self.outputDir)
print("output dir:", self.outputDir)
##logging.info("Output dir: " + self.outputDir)
self.label = args.label
self.camera = 0

Expand All @@ -55,6 +56,7 @@ def identifyAnalysis(self):
try:
self.analysisType = self.h5Files[0]["analysisType"]
self.sliceCoordinates = self.h5Files[0]["sliceCoordinates"][()]
print('slice coordinates:', self.sliceCoordinates)
except:
## do something useful here, maybe
self.analysisType = None
Expand Down Expand Up @@ -82,13 +84,13 @@ def clusterAnalysis(self):
except:
pass

self.nBins = 100
self.nBins = 200## for epixM with a lot of 2 photon events...
self.lowEnergyCut = 4 ## fix - should be 0.5 photons or something
self.highEnergyCut = 15 ## fix - should be 1.5 photons or something
##tmp
npyFileName = "%s/r%d_clusters.npy" % (self.outputDir, self.run)
np.save(npyFileName, clusters)
logger.info("Wrote file: " + npyFileName)
##logger.info("Wrote file: " + npyFileName)

self.analyzeSimpleClusters(clusters)

Expand Down Expand Up @@ -148,7 +150,7 @@ def analyzeSimpleClusters(self, clusters):

rows = self.sliceEdges[0]
cols = self.sliceEdges[1]
m = 1## temp hack
m = 1## temp hack, Kaz's favorite asic, off by 1
fitInfo = np.zeros((maximumModule, rows, cols, 5)) ## mean, std, area, mu, sigma
for i in range(rows):
for j in range(cols):
Expand Down Expand Up @@ -176,7 +178,7 @@ def analyzeSimpleClusters(self, clusters):
plt.figtext(0.7, 0.8, "%d entries (peak)" % (area))
plt.figtext(0.7, 0.75, "mu %0.2f" % (mu))
plt.figtext(0.7, 0.7, "sigma %0.2f" % (sigma))
figFileName = "%s/%s_m%d_r%d_c%d_r%d_c%d_%s_E.png" % (
figFileName = "%s/%s_r%d_c%d_m%d_r%d_c%d_%s_E.png" % (
self.outputDir,
self.__class__.__name__,
self.run,
Expand Down
30 changes: 17 additions & 13 deletions suite_scripts/LinearityPlotsParallelSlice.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
class LinearityPlotsParallel(BasicSuiteScript):
def __init__(self):
super().__init__("scan") ##self)
self.saturated = [True, False][0]
self.saturated = [True, False][1]
print("using saturation fit =", self.saturated)
logger.info("using saturation fit =" + str(self.saturated))
self.residuals = [True, False][0]
self.profiles = [True, False][1]
self.seabornProfiles = [True, False][1]
self.seabornProfiles = [True, False][0]
try:
print("positive events:", "positive" in self.special)
logger.info("positive events:" + str("positive" in self.special))
Expand Down Expand Up @@ -172,8 +172,8 @@ def analyze_h5(self, dataFile, label):
lpp.plotDataROIs(rois.T, fluxes, "ROIs")

def analyze_h5_slice(self, dataFile, label):
module = 0
nModules = 1
module = 2
nModules = 3
data = h5py.File(dataFile)
fluxes = data["fluxes"][()]
pixels = data["slice"][()]
Expand All @@ -185,15 +185,16 @@ def analyze_h5_slice(self, dataFile, label):
for i in range(rows):
for j in range(cols):
iDet, jDet = self.sliceToDetector(i, j)
self.fitInfo[module, i, j, 8] = self.g0Ped[module, iDet, jDet]
self.fitInfo[module, i, j, 9] = self.g1Ped[module, iDet, jDet]
self.fitInfo[module, i, j, 10] = self.g0Gain[module, iDet, jDet]
self.fitInfo[module, i, j, 11] = self.g1Gain[module, iDet, jDet]
self.fitInfo[module, i, j, 12] = self.offset[module, iDet, jDet]
g0 = pixels[:, i, j] < lpp.g0cut
if False:
self.fitInfo[module, i, j, 8] = self.g0Ped[module, iDet, jDet]
self.fitInfo[module, i, j, 9] = self.g1Ped[module, iDet, jDet]
self.fitInfo[module, i, j, 10] = self.g0Gain[module, iDet, jDet]
self.fitInfo[module, i, j, 11] = self.g1Gain[module, iDet, jDet]
self.fitInfo[module, i, j, 12] = self.offset[module, iDet, jDet]
g0 = pixels[:, module, i, j] < lpp.g0cut
g1 = np.logical_not(g0)
if len(g0[g0]) > 2:
y = np.bitwise_and(pixels[:, i, j][g0], lpp.gainBitsMask)
y = np.bitwise_and(pixels[:, module, i, j][g0], lpp.gainBitsMask)
y_g0_max = y.max()
x = fluxes[g0]
if self.profiles:
Expand All @@ -208,6 +209,8 @@ def analyze_h5_slice(self, dataFile, label):
##np.save("temp_r%dc%d_x.py" %(i,j), fluxes[g0])
##np.save("temp_r%dc%d_y.py" %(i,j), y)
##np.save("temp_r%dc%d_func.py" %(i,j), fitFunc)
##print(fitInfo.shape)
##print(fitPar)
self.fitInfo[module, i, j, 0:2] = fitPar[0:2] ## indices for saturated case
self.fitInfo[module, i, j, 2] = r2
self.fitInfo[module, i, j, 6] = y_g0_max
Expand All @@ -226,7 +229,7 @@ def analyze_h5_slice(self, dataFile, label):
plt.figure(1)

if len(g1[g1]) > 2:
y = np.bitwise_and(pixels[:, i, j][g1], lpp.gainBitsMask)
y = np.bitwise_and(pixels[:, module, i, j][g1], lpp.gainBitsMask)
y_g1_min = y.min()
x = fluxes[g1]
if self.profiles:
Expand Down Expand Up @@ -372,7 +375,7 @@ def analyze_h5_slice(self, dataFile, label):
fluxes=flux,
rois=np.array(roiMeans),
pixels=np.array(singlePixelData),
slice=rawFrames[0][lpp.regionSlice],
slice=rawFrames[lpp.regionSlice]
)

nGoodEvents += 1
Expand Down Expand Up @@ -410,6 +413,7 @@ def analyze_h5_slice(self, dataFile, label):
logger.info("Wrote file: " + fileName)

if False:
print("this is broken")
label = "rawInTimeDot"
if doKazFlux:
label = "raw_smarterPoints"
Expand Down
2 changes: 1 addition & 1 deletion suite_scripts/SimpleClustersParallelSlice.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def analyze_h5(self, dataFile, label):
smd = sic.ds.smalldata(filename="%s/%s_c%d_r%d_n%d.h5" % (sic.outputDir, sic.className, sic.camera, sic.run, size))

## 50x50 pixels, 3x3 clusters, 10% occ., 2 sensors
maxClusters = int(50 * 50 / 3 / 3 * 0.1 * 2)
maxClusters = 1000##int(50 * 50 / 3 / 3 * 0.1 * 2)
try:
seedCut = sic.detectorInfo.seedCut
except:
Expand Down
24 changes: 15 additions & 9 deletions suite_scripts/TimeScanParallelSlice.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ def __init__(self):
pass

def plotData(self, rois, pixels, delays, label):
## print(type(delays))
## print('delays here:', delays)
for i, roi in enumerate(self.ROIs):
ax = plt.subplot()
ax.plot(delays, rois[i], label=self.ROIfileNames[i])
plt.grid(which="major", linewidth=0.5)
minor_locator = AutoMinorLocator(5)
ax.xaxis.set_minor_locator(minor_locator)
plt.grid(which="minor", linewidth=0.5)
plt.xlabel("Time delay (Ticks)")
plt.xlabel("Time delay (Ticks/1000)")
# plt.ylabel('Step Mean (keV)')
plt.ylabel("Step Mean (ADU)")
plt.grid(which="major", linewidth=0.75)
Expand All @@ -56,7 +58,7 @@ def plotData(self, rois, pixels, delays, label):
minor_locator = AutoMinorLocator(5)
ax.xaxis.set_minor_locator(minor_locator)
plt.grid(which="minor", linewidth=0.5)
plt.xlabel("Time delay (Ticks)")
plt.xlabel("Time delay (Ticks/1000)")
# plt.ylabel('Step Mean (keV)')
plt.ylabel("Step Mean (ADU)")
##plt.yscale('log')
Expand All @@ -76,7 +78,7 @@ def plotData(self, rois, pixels, delays, label):
minor_locator = AutoMinorLocator(5)
ax.xaxis.set_minor_locator(minor_locator)
plt.grid(which="minor", linewidth=0.5)
plt.xlabel("Delay (Ticks)")
plt.xlabel("Delay (Ticks/1000)")
plt.ylabel("Pixel ADU")

figFileName = "%s/%s_r%d_c%d_%s_pixel%d.png" % (self.outputDir, self.__class__.__name__, self.run, self.camera, label, i)
Expand Down Expand Up @@ -119,10 +121,14 @@ def analyze_h5(self, dataFile, norm, label):

a = h5py.File(dataFile)[norm]
delays = np.array([k for k in a.keys()])
delays = delays.astype("int")
print(delays)
##delays = delays.astype('float').astype("int")
##delays = delays.astype('float').astype("int")
delays.sort()
d = np.array([a[str(k)] for k in delays])
delays = np.array([d for d in delays])
delays = [eval(d)/1000. for d in delays]
##delays /= 1000.
print(delays)

runString = "_r%d" % (self.run)
Expand Down Expand Up @@ -168,7 +174,7 @@ def analyze_h5(self, dataFile, norm, label):
offset = len(tsp.ROIs)

stepGen = tsp.getStepGen()
## for nstep, step in enumerate (tsp.ds.steps()):
##for nstep, step in enumerate (tsp.ds.steps()):
for nstep, step in enumerate(stepGen):
##scanValue = tsp.getScanValue(step, useStringInfo=True)
scanValue = tsp.getScanValue(step, True)
Expand All @@ -193,12 +199,12 @@ def analyze_h5(self, dataFile, norm, label):

##tsp.isBeamEvent(evt):
if tsp.detectorInfo.detectorType == 'epixm' or tsp.isBeamEvent(evt):##FEE hack
frames = tsp.getRawData(evt, gainBitsMasked=True)
frames = tsp.getRawData(evt)##, gainBitsMasked=True)
##print("real beam on event", nstep, nevt)
##logger.info("real beam on event" + str(nstep) + ", " + str(nevt))
elif tsp.use_281_for_old_data and ec[281]:
frames = tsp.getRawData(evt, gainBitsMasked=True)
##print("281 only...")
frames = tsp.getRawData(evt)##, gainBitsMasked=True)
print("281 only...")
elif ec[137]:
tsp.flux = tsp._getFlux(evt) ## fix this
continue
Expand All @@ -208,7 +214,7 @@ def analyze_h5(self, dataFile, norm, label):
continue
else:
tsp.flux = tsp._getFlux(evt) ## fix this
frames = tsp.getRawData(evt, gainBitsMasked=True)
frames = tsp.getRawData(evt)##, gainBitsMasked=True)

if frames is None:
##print("no frame")
Expand Down
16 changes: 10 additions & 6 deletions suite_scripts/epixMSuiteConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,32 @@
##experimentHash = {'exp':'mfxx1005021', 'location':'MfxEndstation', 'fluxSource':'MFX-USR-DIO', 'fluxChannels':[11], 'fluxSign':-1}
##experimentHash = {'exp':'rixc00121', 'location':'RixEndstation',
singlePixelArray = []
for i in range(4):
for i in range(1,3):
singlePixelArray.append([i, 10, 10])
singlePixelArray.append([i, 10, 100])
singlePixelArray.append([i, 100, 10])
singlePixelArray.append([i, 100, 100])
singlePixelArray.append([i, 150, 150])
singlePixelArray.append([i, 80, 20])

singlePixelArray.append([2, 178, 367])

experimentHash = {
"detectorType": "epixm",
##"exp": "rixx1005922",
"exp": "rixx1003721",
"exp": "rixx1005922",
##"exp": "rixx1003721",
"location": "RixEndstation",
"analyzedModules":[1,2],
"seedCut":40, ## pure guess
"neighborCut":10, ##pure guess
"fluxSource": "MfxDg1BmMon",
'fluxChannels':[8, 14],
'fluxChannels':[11],
"fluxSign": -1,
"singlePixels": singlePixelArray,
# 'ROIs':['module0', 'module2', 'module4', 'module6', 'module10','module12', 'module14']
# 'ROIs':['roiFromSwitched_e557_rmfxx1005021']
## 'ROIs':['allHRasicPixels', 'goodboxROI']#'roiAbove7k_raw_r123']
##"ROIs": ["../data/XavierV4_2", "../data/OffXavierV4_2"],
"ROIs": ["../data/smallRegionFourAsics.npy"],
"regionSlice": np.s_[0:4, 40:60:, 170:200],## random
"ROIs": ["../data/cometPinhole.npy", "../data/smallRegionFourAsics.npy", "../data/smallRegionTwoAsicsForBhavna.npy"],
"regionSlice": np.s_[0:4, 150:180:, 340:368],## small region near Kaz rec
}
3 changes: 2 additions & 1 deletion suite_scripts/simplePhotonCounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ def __init__(self):
if evt is None:
break
if not spc.isBeamEvent(evt):
print('foo')
##print('foo')
continue

if spc.fakePedestal is not None:
rawFrames = spc.getRawData(evt)
frames = rawFrames.astype("float") - spc.fakePedestal
frames /= gain ## psana may not have the right default
else:
Expand Down

0 comments on commit 674f269

Please sign in to comment.