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

Ge21 generalizing #252

Merged
merged 9 commits into from
Nov 7, 2019
Merged

Conversation

dteague
Copy link
Contributor

@dteague dteague commented Oct 14, 2019

PR for changing the gem plotting code to be compatible with GE21 plotting

Description

The gem-plotting code is hardcoded with many magic numbers that are specific to the GE11, so with changes in the tree structure to add gemtype and detectortype, the plotting code can be expanded to allow for GE21 plotting that is determined on the fly by this gemType variable.

The bulk of the code is removing instances of 24, 8, 3, and combinations of these to more generic variables, ie nVFATS, maxiEta, maxiPhi. These variables are derived from chamber_maxiEtaiPhiPair in ./mapping/chamberInfo.py and from vfatsPerGemVariant in gempython.tools.hw_constants All of the mapping/chamberInfo.py variables have been turned into dictionaries that require the gemType to get the correct variables, ie

chamber_vfatPos2iEta => chamber_vfatPos2iEta["ge11"]
etc.

Since a large code change is the actual canvas creation code, the largest change is to canvas making. The makeAxBCanvas has been removed in place of merging this functionality into the saveSummaryCanvas to make a new function called getSummaryCanvas. This means the function now always returns a canvas created and there is a flag to decide to save the canvas or not. ie function def is now

canv = make3x8Canvas(...)    =>    canv = getSummaryCanvas(..., gemType="ge11")
saveSummaryCanvas(...)    =>    getSummaryCanvas(..., gemType="ge11", write2Disk=True)

Also, because the makeAxBCanvas function also added histograms to an existing canvas, this functionality has be put to a helper function addPlotToCanvas which hopefully will make the code more readable as well. So the change becomes

canv = make3x8Canvas(initialContent=hist1, ...)
canv = make3x8Canvas(initialContent=hist2, canv=canv, ...)

=>

canv = getSummaryCanvas(hist1, ..., gemType="ge11")
canv = addPlotToCanvas(canv, hist2, gemType="ge11")

Last, many functions include now a gemType variable that needs to be supplied to give the right gemType. The default is "ge11", so the code remains backwards compatible for all cases where the gemType isn't actually supplied.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Motivation and Context

This change has mainly be motivated to be backwards compatible and to default to ge11 in all unknown cases. Since ge21 is needing plots specifically made for it (and not ones derived from ge11 algorithms), having code that can flexibly handle ge21 and in the future, me0 is a must.

For further information on this, look at issue #226

How Has This Been Tested?

For testing, the code was run over ge11 and ge21 files with the internal gemType flag flipped (ge21 files didn't have that tree in it).

NOTE: currently, only the main run files (ie files in the top directory) are changed. Files in the ./macros area have not been touched. Here is a list of what has been done.

  • anaDACScan.py, anaUltraScurve.py, anaSBitThresh.py, anaUltraLatency.py - work for both
  • anaUltraThreshold.py, anaSBitMonitor.py - work for ge11, could not fine ge21 file
  • anaSBitReadout.py, anaXDAQLatency.py - could not find input file for either

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Contributor

@jsturdy jsturdy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • extraneous whitespace should be cleaned up
  • all debugging print statements should be removed (or added to an appropriate debug block)
  • all necessary prints should be python3 compatible, i.e., print() instead of print
  • all new string formatting should use "{}".format() rather than "%"() style

I think there are some additional lookup optimizations that can be made, so that map lookups happen only as needed

anaSBitMonitor.py Outdated Show resolved Hide resolved
anaSBitMonitor.py Outdated Show resolved Hide resolved
anaSBitMonitor.py Outdated Show resolved Hide resolved
anaSBitReadout.py Outdated Show resolved Hide resolved
anaSBitReadout.py Outdated Show resolved Hide resolved
utils/threshAlgos.py Show resolved Hide resolved
utils/threshAlgos.py Outdated Show resolved Hide resolved
utils/threshAlgos.py Outdated Show resolved Hide resolved
# initialize a TGraphErrors and a TF1 for each vfat
for idx in range(len(dacNameArray)):
dacName = np.asscalar(dacNameArray[idx])
for entry in crateMap:
ohKey = (entry['shelf'],entry['slot'],entry['link'])
for vfat in range(0,25): #24th VFAT represents "overall case"
for vfat in range(0,vfatsPerGemVariant[gemType]+1): #24th VFAT represents "overall case"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately, there are two conventions for the "all VFATs summary" plot, one is to put it in index -1, one is to put it in index 24
this should be cleaned up everywhere, but this is outside this PR

utils/threshAlgos.py Outdated Show resolved Hide resolved
@jsturdy
Copy link
Contributor

jsturdy commented Oct 15, 2019

when you go to address comments, you should rebase onto the latest cms-gem-daq-project/develop

@dteague
Copy link
Contributor Author

dteague commented Oct 18, 2019

  • I changed most all of the print statements to python 3 format
  • I changed most all of the % string formatting to the preferred .format() function
  • I made a variable for many function for max vfats and max channels (nVFATS and maxChans). - Of course the naming can be changed easily, but it removes multiple look ups of the vfat dictionary and remove some 128 magic numbers from the code

I do have some questions as shown by the comments to code blocks, and after those are answered, I can fix and test on files again to make sure everything is working correctly

@jsturdy
Copy link
Contributor

jsturdy commented Oct 21, 2019

OK, it would probably be good to sit together and go over the rebase workflow, as your previous attempt succeeded (but in a sub-optimal way, as you created a new merge and now have a bunch of duplicate commits)

@dteague
Copy link
Contributor Author

dteague commented Oct 21, 2019

I looked into this and I removed the extraneous commits and rebased them on the newest changes. The commit log shows only the 6 commits on top of the develop branch, so all seems to have worked, but this might need to be looked over since my git skills are still pretty poor 😝

anaSBitReadout.py Outdated Show resolved Hide resolved
ieta_h_ch[ieta] = r.TH1F("h_ieta{0}_chan_vs_hit".format(ieta), "i#eta = {0} | i#phi (1,2,3)".format(ieta), 384, 0., 384.)
for ieta in range(1, maxiEta+1):
ieta_h_strip[ieta] = r.TH1F("h_ieta{0}_strips_vs_hit".format(ieta), "i#eta = {0} | i#phi (1,2,3)".format(ieta), 128*maxiPhi, 0., 128.*maxiPhi)
ieta_h_ch[ieta] = r.TH1F("h_ieta{0}_chan_vs_hit".format(ieta), "i#eta = {0} | i#phi (1,2,3)".format(ieta), maxChans*maxiPhi, 0., maxChans*maxiPhi)
ieta_h_sbitSize[ieta] = r.TH1F("h_ieta{0}_sbitSize_vs_hit".format(ieta), "i#eta = {0} SBIT Size".format(ieta), 8, 0., 8.)
Copy link
Contributor

@jsturdy jsturdy Oct 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here possibly 8-> NUM_IETA_SECTORS
Actually, I think it's the s-bit partition, which is not tied to the ieta sectors


# loop over all branch names but the first (evnt num)
from gempython.gemplotting.mapping.chamberInfo import chamber_vfatPos2iEtaiPhi as vfat_to_etaphi

from gempython.utils.gemlogger import printRed, printYellow
print("Analyzing Raw Data\nThis may take some time please be patient")
h_clusterMulti = r.TH1F("h_clusterMulti".format(vfat), "", 9,-0.5,8.5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here possibly 9-> NUM_IETA_SECTORS+1, probably best to check the semantics when the Fill is done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard to tell, but I don't think. This variable is based on a loop that runs over the clusterNames which are derived from the branches in file, ie

for cName in clusterNames:
# Remove in a later refactoring
# Right now if an sbit is not sent L1A delay will be max and sbit address is 0x0 and cluster size is 0x0, this is 0x3ffc000; so we ignore this word
# Otherwise it will always report SBIT 0 of VFAT 7
word = event[cName]
if word == 0x3ffc000:
continue
# INVALID ADDRESS CHECK
sbitAddr = ((word) & 0x7FF)
if sbitAddr >= 1536:
continue
nValidClusters+=1

and

for branch in inT.GetListOfBranches():
bNames.append(branch.GetName())
clusterNames = copy.deepcopy(bNames)
clusterNames.remove("evtNum")

@@ -313,7 +314,7 @@ def fit(self, debug=False):

if debug:
if self.isVFAT3:
print "| %i | %i | %i | %i | %f | %f | %f | %f | %f | %f | %f | %f | %f |"%(
print("| {0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} | {8} | {9} | {10} | {11} | {12} |".format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't my intention with my comment to have you do all the conversions, (just the ones that were in code you added/modified), but it's a good thing to have done anyway :-)
However, here does the formatting stay constant?
I suppose it can guess at the type, just need to make sure there isn't any implicit type conversion happening during the formatting...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up doing a replace for the files I edited, and changed up the numbers when need be! I can add types to these just to be on the safe side

Copy link
Contributor

@jsturdy jsturdy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small checks

Comment on lines 1098 to 1100
#### Off by one error...?
vfatHistos[event.vfatN].SetBinContent(63-(stripPinOrChan+1),chargeBin,event.Nhits)
vfatHistos[event.vfatN].SetBinError(63-(stripPinOrChan+1),chargeBin,sqrt(event.Nhits))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like an off by one error, namely the (64-1) and (stripPinOrChan+1) seem to be in opposition, eg
stripPinOrChan = 0 => bin = 62
stripPinOrChan = 63 => bin = -1
Want to confirm before I try and change this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know...

  • What is the valid range of values for stripPinOrChan?
  • What do the current histograms look like (especially if you show the over/underflow stats)
  • All things being equal, it looks to me like the +1 should be outside the parentheses, and maybe also vfatHistos should be vfatHistosPanPin2...

Copy link
Contributor Author

@dteague dteague Oct 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some tests, and having the +1 outside was correct. stripPinOrChan in {0,...,127} and the code works by if done by PanPin, the channels are split between the two histograms, vfatHistos and vfatHistosPanPin2, each having a domain of [0,63].

All that being said, I made the fix!

@dteague
Copy link
Contributor Author

dteague commented Oct 24, 2019

Ran tests and made minor changes. Tests are the same as before, namely:

  • anaDACScan.py, anaUltraScurve.py, anaSBitThresh.py, anaUltraLatency.py - work for both
  • anaUltraThreshold.py, anaSBitMonitor.py - work for ge11, could not fine ge21 file
  • anaSBitReadout.py, anaXDAQLatency.py - could not find input file for either

I did notice that anaSBitMonitor gave strange results for GE11, mainly that all vfats pointed to vfat 7 and were misID'd the same number of times for each vfat. Considering not much was changed with this file, I'm inclined to believe this is a problem with the file I'm running over, not the changes made

All of the gemType reading in is surrounded by comments saying ##### FIXME so when a proper gemType read in is decided, that can be changed quickly. For all of these tests, I just changed the default value to "ge21" and recompiled.

If anyone has files for run over the files I haven't checked or wants other files, namely in the macros area changed, I can do that. Otherwise, I hopefully have fixed for all of the above comments.

@jsturdy
Copy link
Contributor

jsturdy commented Oct 24, 2019

Considering not much was changed with this file, I'm inclined to believe this is a problem with the file I'm running over, not the changes made

You can verify by using the unmodified code to run the same analysis on the same file (since it's GE1/1)

@dteague
Copy link
Contributor Author

dteague commented Oct 25, 2019

I ran the code in the develop branch, and it seems like this code isn't used much because it doesn't work out of the box! (args.filename should be args.infilename. It is fixed in this PR). But the develop branch version gives the exact same results, so this is just a strange fluke of the file I think.

@jsturdy
Copy link
Contributor

jsturdy commented Oct 25, 2019

I ran the code in the develop branch, and it seems like this code isn't used much because it doesn't work out of the box! (args.filename should be args.infilename. It is fixed in this PR). But the develop branch version gives the exact same results, so this is just a strange fluke of the file I think.

@AndrewLevin there was some issue in the past that was related to this filename vs infilename if I recall correctly, was this resolved? is the change that @dteague is making here counter to that discussion?
(@dteague, you can probably search the issues for that string to find what the discussion was about)

@dteague
Copy link
Contributor Author

dteague commented Oct 31, 2019

Pinging for status
Also with #256 , it might be good to fix this concurrently with this PR else GE21 plots can't be graphed (will look into fixes and possibly make another PR)

@mexanick
Copy link
Contributor

@dteague the issue #256 requires a separate PR. Would be great if you can provide it

@AndrewLevin
Copy link
Contributor

I ran the code in the develop branch, and it seems like this code isn't used much because it doesn't work out of the box! (args.filename should be args.infilename. It is fixed in this PR). But the develop branch version gives the exact same results, so this is just a strange fluke of the file I think.

@AndrewLevin there was some issue in the past that was related to this filename vs infilename if I recall correctly, was this resolved? is the change that @dteague is making here counter to that discussion?

I think maybe you are referring to this change

https://github.com/cms-gem-daq-project/gem-plotting-tools/pull/239/files#diff-058f061e69c295595d79241cf963cf20L105-R106

but that has nothing to do with this.

(@dteague, you can probably search the issues for that string to find what the discussion was about)

@jsturdy
Copy link
Contributor

jsturdy commented Nov 4, 2019

I ran the code in the develop branch, and it seems like this code isn't used much because it doesn't work out of the box! (args.filename should be args.infilename. It is fixed in this PR). But the develop branch version gives the exact same results, so this is just a strange fluke of the file I think.

@AndrewLevin there was some issue in the past that was related to this filename vs infilename if I recall correctly, was this resolved? is the change that @dteague is making here counter to that discussion?

I think maybe you are referring to this change

https://github.com/cms-gem-daq-project/gem-plotting-tools/pull/239/files#diff-058f061e69c295595d79241cf963cf20L105-R106

but that has nothing to do with this.

(@dteague, you can probably search the issues for that string to find what the discussion was about)

OK, thanks @AndrewLevin, I just wanted to make sure that this change was properly motivated and not rehashing something historical.

jsturdy
jsturdy previously approved these changes Nov 4, 2019
@jsturdy
Copy link
Contributor

jsturdy commented Nov 6, 2019

@dteague, sorry, can you rebase this one final time?
just want to make sure it would be a good merge as you've touched lots of files

@dteague
Copy link
Contributor Author

dteague commented Nov 6, 2019

Just took care of that. Hopefully I rebased correctly and all is up to snuff!

jsturdy
jsturdy previously approved these changes Nov 6, 2019
Copy link
Contributor

@jsturdy jsturdy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready for squash

@lpetre-ulb
Copy link
Contributor

While testing the new GE2/1 setup at FIT, Stephen and I encountered an issue with the usage of this PR within the GE2/1 compatibility PR in vfatqc-python-tools.

Indeed, in getVFAT3CalInfo the gemType argument is not set in testConnectivity.py nor in any other script; this is an issue for GE2/1 operation. While this seems an issue related to vfatqc-python-tools PR, the design in dbutils.py generalization could be improved to prevent this kind of problem.

In fact, why is the GEM type even required to be given to the DB util functions? I mean, one should be able to request the data for an arbitrary number of VFATs; 24 for GE1/1, 12 for GE2/1 or n for a manual lookup.

I see that gemType is used only here:

{ 'vfatN':[vfat for vfat in range(vfatsPerGemVariant[gemType])],

Couldn't vfatsPerGemVariant[gemType] be advantageously replaced with len(vfatList)? This would make the DB util functions fully generic without any requirement on the GEM type. As a side effect, the PR in vfatqc-python-scripts would work without modification.

@dteague
Copy link
Contributor Author

dteague commented Nov 7, 2019

Couldn't vfatsPerGemVariant[gemType] be advantageously replaced with len(vfatList)? This would make the DB util functions fully generic without any requirement on the GEM type. As a side effect, the PR in vfatqc-python-scripts would work without modification.

Very fair, @lpetre-ulb, that is a much better implementation that I didn't see! Let me fix that quickly

@lpetre-ulb
Copy link
Contributor

Thank you for the quick fix @dteague!

@jsturdy
Copy link
Contributor

jsturdy commented Nov 7, 2019

@mexanick, do we want to hold this while @sbutalla tests at FIT, or just merge it as is and do bugfixes later?
oops! too slow of a refresh! (thanks @lpetre-ulb!)

Copy link
Contributor

@jsturdy jsturdy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now ready for squash

Copy link
Contributor

@mexanick mexanick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine to merge and start testing. Bug reports/fixes should be provided upon necessity.

@jsturdy jsturdy merged commit 8c844e3 into cms-gem-daq-project:develop Nov 7, 2019
@lpetre-ulb
Copy link
Contributor

@sbutalla and I discovered what seems like a bug yesterday in the DAC scans plots for GE2/1 (at least). The title is a fifth order polynomial and the axis do not have any legend. Stephen, can you open an issue? I don't have access to the plots.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants