Skip to content
This repository has been archived by the owner on Jan 31, 2022. It is now read-only.

Refactoring of anaUltraScurve.py and additional output distributions #75

Merged
merged 42 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6fc0c32
added getMapping function for creating chan-strip-panpin look up table
Mar 22, 2018
3f590af
removed unnecessary imports and made use of getMapping()
Mar 22, 2018
e34b1c7
added function for creating empty lists to be more pythonic
Mar 22, 2018
71b670c
cleaned up duplication in histogram initialization
Mar 22, 2018
af3af2f
getMapping() will now also include the vfat channel number as a ident…
Mar 22, 2018
5d948cd
removed unnecessary duplication of code when filling summary histograms
Mar 22, 2018
9338611
added additional method to ScanDataFitter to allow a histogram to be …
Mar 22, 2018
05bb749
Nev is now a nesteddict in ScanDataFitter and will be applied per vfa…
Mar 22, 2018
a3bdf37
functionality added to ScanDataFitter to provide output in either cha…
Mar 22, 2018
6d43ec9
cleaned up hot channel determination and made output table compatible…
Mar 22, 2018
b5e2cc9
ScanDataFitter.scanFits renamed to scanFitResults to distinguish it m…
Mar 22, 2018
1dc921d
removed unnecessary duplicate containers
Mar 22, 2018
66e9e39
ScanDataFitter.calDAC2Q_m and ScanDataFitter.calDAC2Q_b are now corre…
Mar 22, 2018
43b7f09
migrated dict_calSF to anaInfo since multiple objects require it
Mar 22, 2018
4724d92
moved fill2DScurveSummaryPlots() to anaUltraScurve.py and moved def o…
Mar 22, 2018
d3c6326
fixed a syntax error when checking for current pulse mode in ScanData…
Mar 22, 2018
74203b5
the saveSummary() has been moved from anaUltraScurve.py into anautili…
Mar 22, 2018
5d38901
cleaning up saving output plots
Mar 22, 2018
b470b2e
additional 1D histograms are made showing scurve mean and width posit…
Mar 22, 2018
7f3b1ff
added graphical 1D distributions of histograms and fits
Mar 22, 2018
77c5a6f
syntax and bug fixes, moved TTree declaration to block of code where …
Mar 22, 2018
c663b1a
changed drawing performed by plotAllSCurvesOnCanvas()
Mar 22, 2018
c603ba2
saveSummary will now take draw option as an argument
Mar 22, 2018
2f92ae4
tweaking thresh and enc distribution binning
Mar 22, 2018
50c53d9
adding vfatList argument which defaults to VFAT0..23 inclusive
Mar 23, 2018
3e3dd94
undoing vfatList option, more thought is required
Mar 23, 2018
3309d97
color coding TF1's in fitting based on fit results
Mar 23, 2018
594f741
fixed an issue where fitting scurves would use negative initial param…
Mar 23, 2018
c41ca6a
new utility function for list like object index finding
Mar 23, 2018
a83fcc9
added the possibility of debug printing to ScanDataFitter
Mar 23, 2018
e2c946c
filling histograms is now done via SetBinContent method so the error …
Mar 23, 2018
b3e478e
moved around where chargeBin list was determined to increase algorith…
Mar 23, 2018
5078e55
updated TObject and output names to be less ambigious, e.g. instead o…
Mar 23, 2018
93e86bf
added axis labels to thr and enc distributions
Mar 23, 2018
7c9215f
Added a threshold and enc distribution which summarizes the entire de…
Mar 26, 2018
def8374
typos fixed and added summary output directory
Mar 26, 2018
f558ada
merged with develop
Mar 26, 2018
b477934
mak3x8Canvas can now accept a TCanvas object to plot additional distr…
Mar 26, 2018
d053fb9
changing names of TObjects for scurve sigma to be consistent
Mar 26, 2018
f3a92c2
removing commented lines
Mar 26, 2018
174d8f9
decreasing bin size of scurve mean and sigma dist's for full detector
Mar 26, 2018
7f1a0e4
Merge branch 'develop' into feature_refactoringSCurve
Mar 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tweaking thresh and enc distribution binning
  • Loading branch information
Brian Dorney committed Mar 22, 2018
commit 2f92ae4a1bb99ccb5edbb550ce145d9dc17bccb3
59 changes: 32 additions & 27 deletions anaUltraScurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def plotAllSCurvesOnCanvas(vfatHistos, vfatHistosPanPin2=None, obsName="canvScur
g_scurve.Draw("AP")
else:
g_scurve.Draw("sameP")
canv_dict[vfat].Update()
#canv_dict[vfat].Update()
if vfatHistosPanPin2 is not None:
for vfat,histo in vfatHistosPanPin2.iteritems():
canv_dict[vfat].cd()
Expand All @@ -104,7 +104,7 @@ def plotAllSCurvesOnCanvas(vfatHistos, vfatHistosPanPin2=None, obsName="canvScur

g_scurve = r.TGraph(h_scurve)
g_scurve.Draw("sameP")
canv_dict[vfat].Update()
#canv_dict[vfat].Update()

return canv_dict

Expand Down Expand Up @@ -145,8 +145,10 @@ def plotAllSCurvesOnCanvas(vfatHistos, vfatHistosPanPin2=None, obsName="canvScur
outfilename = options.outfilename
GEBtype = options.GEBtype

# Create the output File
# Create the output File and TTree
outF = r.TFile(filename+'/'+outfilename, 'recreate')
if options.performFit:
myT = r.TTree('scurveFitTree','Tree Holding FitData')

# Set the CAL DAC to fC conversion
calDAC2Q_Intercept = np.zeros(24)
Expand Down Expand Up @@ -330,7 +332,7 @@ def plotAllSCurvesOnCanvas(vfatHistos, vfatHistosPanPin2=None, obsName="canvScur
effectivePedestals[vfat][chan] = fitter.scanFuncs[vfat][chan].Eval(0.0)

# Compute the value to apply MAD on for each channel
trimValue[chan] = scanFitResults[0][vfat][chan] - ztrim[0] * scanFitResults[1][vfat][chan]
trimValue[chan] = scanFitResults[0][vfat][chan] - options.ztrim * scanFitResults[1][vfat][chan]
pass
fitFailed = np.logical_not(fitter.fitValid[vfat])

Expand Down Expand Up @@ -368,9 +370,10 @@ def plotAllSCurvesOnCanvas(vfatHistos, vfatHistosPanPin2=None, obsName="canvScur
calDAC2Q_m=calDAC2Q_Slope,
calDAC2Q_b=calDAC2Q_Intercept)

# Create the output TTree and store the results
# Set the branches of the TTree and store the results
if options.performFit:
myT = r.TTree('scurveFitTree','Tree Holding FitData')
# Due to weird ROOT black magic this cannot be done here
#myT = r.TTree('scurveFitTree','Tree Holding FitData')

chi2 = array( 'f', [ 0 ] )
myT.Branch( 'chi2', chi2, 'chi2/F')
Expand Down Expand Up @@ -419,13 +422,13 @@ def plotAllSCurvesOnCanvas(vfatHistos, vfatHistosPanPin2=None, obsName="canvScur
threshSummaryPlots = {}
encSummaryPlots = {}
for vfat in range (0,24):
fitThr = np.zeroes(128)
fitENC = np.zeroes(128)
stripPinOrChanArray = np.zeroes(128)
fitThr = np.zeros(128)
fitENC = np.zeros(128)
stripPinOrChanArray = np.zeros(128)
for chan in range (0, 128):
# Store stripChanOrPinType to use as x-axis of fit summary plots
stripPinOrChan = float( dict_vfatChanLUT[vfat][stripChanOrPinType][chan] )

stripPinOrChan = dict_vfatChanLUT[vfat][stripChanOrPinType][chan]
# Store Values for making fit summary plots
fitThr[stripPinOrChan] = scanFitResults[0][vfat][chan]
fitENC[stripPinOrChan] = scanFitResults[1][vfat][chan]
Expand Down Expand Up @@ -474,7 +477,7 @@ def plotAllSCurvesOnCanvas(vfatHistos, vfatHistosPanPin2=None, obsName="canvScur
len(fitThr),
stripPinOrChanArray,
fitThr,
len(fitThr),
np.zeros(len(fitThr)),
fitENC
)
fitSummaryPlots[vfat].SetTitle("VFAT %i Fit Summary;Channel;Threshold [fC]"%vfat)
Expand All @@ -491,23 +494,25 @@ def plotAllSCurvesOnCanvas(vfatHistos, vfatHistosPanPin2=None, obsName="canvScur

# Make thresh summary plot - bin size is variable
histThresh = r.TH1F("scurveMean_vfat%i"%vfat,"VFAT %i;S-Curve Mean #left(fC#right);N"%vfat,
100, np.mean(fitThr) - 5. * np.std(fitThr), np.mean(fitThr) + 5. * np.std(fitThr) )
40, np.mean(fitThr) - 5. * np.std(fitThr), np.mean(fitThr) + 5. * np.std(fitThr) )
histThresh.Sumw2()
for thresh in fitThr:
histThresh.Fill(thresh)
if np.std(fitThr) != 0: # Don't fill if we are still at initial values
for thresh in fitThr:
histThresh.Fill(thresh)
gThresh = r.TGraphErrors(histThresh)
gThresh.SetName("gScurveMeanDist_vfat%i"%vfat)
threshSummaryPlots[vfat] = gThresh

# Make enc summary plot - bin size is variable
histENC = r.TH1F("scurveSigma_vfat%i"%vfat,"VFAT %i;S-Curve Sigma #left(fC#right);N"%vfat,
100, np.mean(fitENC) - 5. * np.std(fitENC), np.mean(fitENC) + 5. * np.std(fitENC) )
40, np.mean(fitENC) - 5. * np.std(fitENC), np.mean(fitENC) + 5. * np.std(fitENC) )
histENC.Sumw2()
for enc in fitENC:
histENC.Fill(enc)
if np.std(fitENC) != 0: # Don't fill if we are still at initial values
for enc in fitENC:
histENC.Fill(enc)
gENC = r.TGraphErrors(histENC)
gENC.SetName("gScurveSigmaDist_vfat%i"%vfat)
encSummaryPlots[vfat] = gThresh
encSummaryPlots[vfat] = gENC
pass
pass

Expand Down Expand Up @@ -538,9 +543,9 @@ def plotAllSCurvesOnCanvas(vfatHistos, vfatHistosPanPin2=None, obsName="canvScur
saveSummary(vSummaryPlotsNoHotChan, vSummaryPlotsNoHotChanPanPin2, '%s/PrunedSummary.png'%filename, trimVcal)
else:
saveSummary(vSummaryPlotsNoHotChan, None, '%s/PrunedSummary.png'%filename, trimVcal)
saveSummary(fitSummaryPlots, None, '%s/fitSummary.png'%filename, None)
saveSummary(threshSummaryPlots, None, '%s/ScurveMeanSummary.png'%filename, None)
saveSummary(encSummaryPlots, None, '%s/ScurveWidthSummary.png'%filename, None)
saveSummary(fitSummaryPlots, None, '%s/fitSummary.png'%filename, None, drawOpt="APE1")
saveSummary(threshSummaryPlots, None, '%s/ScurveMeanSummary.png'%filename, None, drawOpt="AP")
saveSummary(encSummaryPlots, None, '%s/ScurveWidthSummary.png'%filename, None, drawOpt="AP")

confF = open(filename+'/chConfig.txt','w')
confF.write('vfatN/I:vfatID/I:vfatCH/I:trimDAC/I:mask/I\n')
Expand Down Expand Up @@ -576,9 +581,9 @@ def plotAllSCurvesOnCanvas(vfatHistos, vfatHistosPanPin2=None, obsName="canvScur
canvOfScurveFits[vfat].cd()
for chan in range (0,128):
if chan == 0:
fitter.scanFuncs[vfat][ch].Draw()
fitter.scanFuncs[vfat][chan].Draw()
else:
fitter.scanFuncs[vfat][ch].Draw("same")
fitter.scanFuncs[vfat][chan].Draw("same")
canvOfScurveFits[vfat].Update()

# Save TObjects
Expand All @@ -590,12 +595,12 @@ def plotAllSCurvesOnCanvas(vfatHistos, vfatHistosPanPin2=None, obsName="canvScur
dirVFAT.cd()
vSummaryPlots[vfat].Write()
if options.PanPin:
vSummaryPlotsPanPin2.Write()
vSummaryPlotsPanPin2[vfat].Write()
canvOfScurveHistos[vfat].Write()
if options.performFit:
vSummaryPlotsNoHotChan.Write()
vSummaryPlotsNoHotChan[vfat].Write()
if options.PanPin:
vSummaryPlotsNoHotChanPanPin2.Write()
vSummaryPlotsNoHotChanPanPin2[vfat].Write()
fitSummaryPlots[vfat].Write()
threshSummaryPlots[vfat].Write()
encSummaryPlots[vfat].Write()
Expand Down
19 changes: 12 additions & 7 deletions fitting/fitScanData.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ def fit(self):

random = r.TRandom3()
random.SetSeed(0)
fitTF1 = r.TF1('myERF','[3]*TMath::Erf((TMath::Max([2],x)-[0])/(TMath::Sqrt(2)*[1]))+[3]',
self.calDAC2Q_m[vfat]*1+self.calDAC2Q_b[vfat],self.calDAC2Q_m[vfat]*253+self.calDAC2Q_b[vfat])
for vfat in range(0,24):
print 'fitting vfat %i'%vfat
fitTF1 = r.TF1('myERF','[3]*TMath::Erf((TMath::Max([2],x)-[0])/(TMath::Sqrt(2)*[1]))+[3]',
self.calDAC2Q_m[vfat]*1+self.calDAC2Q_b[vfat],self.calDAC2Q_m[vfat]*253+self.calDAC2Q_b[vfat])
for ch in range(0,128):
print 'fitting vfat %i chan %i'%(vfat,ch)
if self.isDead[vfat][ch]:
continue # Don't try to fit dead channels
elif not (self.scanHistos[vfat][ch].Integral() > 0):
Expand All @@ -126,19 +126,24 @@ def fit(self):
stepN = 0
while(stepN < 15):
rand = random.Gaus(10, 5)

# Make sure the input parameters are positive
if (rand < 0.0 or rand > 100): continue
#if self.calDAC2Q_m[vfat]*(8+stepN*8)+self.calDAC2Q_b[vfat] < 0: continue
#if self.calDAC2Q_m[vfat]*(rand)+self.calDAC2Q_b[vfat] < 0: continue

# Provide an initial guess
fitTF1.SetParameter(0, self.calDAC2Q_m[vfat]*(8+stepN*8)+self.calDAC2Q_b[vfat] )
fitTF1.SetParameter(1, self.calDAC2Q_m[vfat]*(rand)+self.calDAC2Q_b[vfat])
fitTF1.SetParameter(2, self.calDAC2Q_m[vfat]*(8+stepN*8)+self.calDAC2Q_b[vfat])
fitTF1.SetParameter(3, self.Nev[vfat][ch]/2.)

# Set Parameter Limits
fitTF1.SetParLimits(0, 0.01, self.calDAC2Q_m[vfat]*(300.0)+self.calDAC2Q_b[vfat])
fitTF1.SetParLimits(1, 0.0, self.calDAC2Q_m[vfat]*(100.0)+self.calDAC2Q_b[vfat])
fitTF1.SetParLimits(2, 0.0, self.calDAC2Q_m[vfat]*(300.0)+self.calDAC2Q_b[vfat])
fitTF1.SetParLimits(0, 0.01, self.calDAC2Q_m[vfat]*(256)+self.calDAC2Q_b[vfat])
fitTF1.SetParLimits(1, 0.0, self.calDAC2Q_m[vfat]*(128)+self.calDAC2Q_b[vfat])
fitTF1.SetParLimits(2, 0.0, self.calDAC2Q_m[vfat]*(256)+self.calDAC2Q_b[vfat])
fitTF1.SetParLimits(3, 0.0, self.Nev[vfat][ch] * 2.)

# Fit
fitResult = self.scanHistos[vfat][ch].Fit('myERF','SQ')
fitEmpty = fitResult.IsEmpty()
Expand Down