|
ATLAS Offline Software
|
|
def | DrawLabels (hist, jetDefString, scenarioString, drawATLASLabel, labelName) |
|
def | DrawLabelsGuessScenario (histo) |
|
def | saveHists4D (canvas, plotFileName, hist, oneSidedAxis, fixedX, fixedY, fixedStr, scenarioLabel="", drawATLASLabel=True, additionalString="") |
|
def | getFixedValuesFromName (histName) |
|
def | getFixedValuesFromFile (inFile, jetDef) |
|
def | getFixedValuesFromFiles (inFiles, jetDef) |
|
def | relativeMetric (numerator, denominator) |
|
def | buildAndFillHists4DFromFiles (inFiles, jetDef, varString, fixedString, fixedX, fixedY, filterStartString="", granularityFactor=1, relativeMetric=False) |
|
def | buildAndFillHists4DFromFile (inFile, jetDef, varString, fixedString, fixedX, fixedY, excludeStartString="", granularityFactor=1, relativeMetric=False) |
|
def | buildAndFillHists4DFromDifferenceHists (hists, relativeMetric=False) |
|
def | buildAndFillHist4DFromMinOfSet (hists, relativeMetric=False) |
|
def | buildAndFillHist4DFromMaxOfSet (hists, relativeMetric=False) |
|
def | buildAndFillHists4DFromEnvelopeOfSet (hists, relativeMetric=False) |
|
def | buildAndFillHist4DFromCoverageOfSet (minDiffFromNominal, maxDiffBetweenScenarios, plotStyle, nominalHist=None, relativeMetric=False) |
|
◆ buildAndFillHist4DFromCoverageOfSet()
def CorrelationMatrixHelpers.buildAndFillHist4DFromCoverageOfSet |
( |
|
minDiffFromNominal, |
|
|
|
maxDiffBetweenScenarios, |
|
|
|
plotStyle, |
|
|
|
nominalHist = None , |
|
|
|
relativeMetric = False |
|
) |
| |
Definition at line 781 of file CorrelationMatrixHelpers.py.
782 coverageHist = CorrMat4D(relativeMetric)
783 coverageHist.setInfoCopy(minDiffFromNominal,
"coverage_type%d"%(plotStyle))
785 if not coverageHist.fillHist4DFromCoverageOfSet(minDiffFromNominal,maxDiffBetweenScenarios,plotStyle,nominalHist):
◆ buildAndFillHist4DFromMaxOfSet()
def CorrelationMatrixHelpers.buildAndFillHist4DFromMaxOfSet |
( |
|
hists, |
|
|
|
relativeMetric = False |
|
) |
| |
Definition at line 757 of file CorrelationMatrixHelpers.py.
759 if not hists
or len(hists) == 0:
760 print "Argument is None or empty list: ",hists
763 maxHist = CorrMat4D(relativeMetric)
764 maxHist.setInfoCopy(hists[0],
"maxDiff_%dinputs"%(len(hists)))
765 if not maxHist.fillHist4DFromMaxOfSet(hists):
◆ buildAndFillHist4DFromMinOfSet()
def CorrelationMatrixHelpers.buildAndFillHist4DFromMinOfSet |
( |
|
hists, |
|
|
|
relativeMetric = False |
|
) |
| |
Definition at line 745 of file CorrelationMatrixHelpers.py.
747 if not hists
or len(hists) == 0:
748 print "Argument is None or empty list: ",hists
751 minHist = CorrMat4D(relativeMetric)
752 minHist.setInfoCopy(hists[0],
"minDiff_%dinputs"%(len(hists)))
753 if not minHist.fillHist4DFromMinOfSet(hists):
◆ buildAndFillHists4DFromDifferenceHists()
def CorrelationMatrixHelpers.buildAndFillHists4DFromDifferenceHists |
( |
|
hists, |
|
|
|
relativeMetric = False |
|
) |
| |
Definition at line 732 of file CorrelationMatrixHelpers.py.
736 for iHist1
in range(0,len(hists)):
737 for iHist2
in range(iHist1+1,len(hists)):
738 hist4D = CorrMat4D(relativeMetric)
739 hist4D.setInfoCopy(hists[iHist1],
"diff_%s_%s"%(hists[iHist1].plotType,hists[iHist2].plotType))
740 if not hist4D.fillHist4DFromDifference(hists[iHist1],hists[iHist2]):
742 diffHists.append(hist4D)
◆ buildAndFillHists4DFromEnvelopeOfSet()
def CorrelationMatrixHelpers.buildAndFillHists4DFromEnvelopeOfSet |
( |
|
hists, |
|
|
|
relativeMetric = False |
|
) |
| |
Definition at line 769 of file CorrelationMatrixHelpers.py.
771 if not hists
or len(hists) < 2:
772 print "Argument is None or contains less than two histograms: ",hists
775 envelopeHist = CorrMat4D(relativeMetric)
776 envelopeHist.setInfoCopy(hists[0],
"envelope_%dinputs"%(len(hists)))
777 if not envelopeHist.fillHist4DFromEnvelopeOfSet(hists):
◆ buildAndFillHists4DFromFile()
def CorrelationMatrixHelpers.buildAndFillHists4DFromFile |
( |
|
inFile, |
|
|
|
jetDef, |
|
|
|
varString, |
|
|
|
fixedString, |
|
|
|
fixedX, |
|
|
|
fixedY, |
|
|
|
excludeStartString = "" , |
|
|
|
granularityFactor = 1 , |
|
|
|
relativeMetric = False |
|
) |
| |
Definition at line 696 of file CorrelationMatrixHelpers.py.
696 def buildAndFillHists4DFromFile(inFile,jetDef,varString,fixedString,fixedX,fixedY,excludeStartString="",granularityFactor=1,relativeMetric=False):
698 iterator = iter(inFile)
707 if isinstance(inFile,str):
708 inFile = TFile.Open(inFile,
"READ")
710 print "Expected a string, but did not receive one: ",inFile
711 print "This method is for building a set of histograms from a single file"
716 for histName
in inFile.GetKeyNames():
717 if excludeStartString !=
"" and histName.startswith(excludeStartString):
720 startStrings.add(histName[:histName.find(
"_var")])
723 hists4D = [CorrMat4D(relativeMetric)
for aString
in startStrings]
724 for aString,aHist
in zip(startStrings,hists4D):
725 aHist.setInfo(jetDef,varString,
"raw_"+aString)
726 if not aHist.fillHist4DFromFile(inFile,fixedString,fixedX,fixedY,aString,granularityFactor):
◆ buildAndFillHists4DFromFiles()
def CorrelationMatrixHelpers.buildAndFillHists4DFromFiles |
( |
|
inFiles, |
|
|
|
jetDef, |
|
|
|
varString, |
|
|
|
fixedString, |
|
|
|
fixedX, |
|
|
|
fixedY, |
|
|
|
filterStartString = "" , |
|
|
|
granularityFactor = 1 , |
|
|
|
relativeMetric = False |
|
) |
| |
#
Build-and-fill functions # #
Definition at line 670 of file CorrelationMatrixHelpers.py.
670 def buildAndFillHists4DFromFiles(inFiles,jetDef,varString,fixedString,fixedX,fixedY,filterStartString="",granularityFactor=1,relativeMetric=False):
672 iterator = iter(inFiles)
680 if isinstance(inFiles,str):
681 inFiles = [TFile.Open(inFiles,
"READ")]
683 for iFile
in range(0,len(inFiles)):
684 if isinstance(inFiles[iFile],str):
685 inFiles[iFile] = TFile.Open(inFiles[iFile],
"READ")
687 hists4D = [CorrMat4D(relativeMetric)
for aFile
in inFiles]
688 for aFile,aHist
in zip(inFiles,hists4D):
689 aHist.setInfo(jetDef,varString,
"raw" if filterStartString ==
"" else "raw_"+ re.sub(
"_",
"",filterStartString))
690 if not aHist.fillHist4DFromFile(aFile,fixedString,fixedX,fixedY,filterStartString,granularityFactor):
◆ DrawLabels()
def CorrelationMatrixHelpers.DrawLabels |
( |
|
hist, |
|
|
|
jetDefString, |
|
|
|
scenarioString, |
|
|
|
drawATLASLabel, |
|
|
|
labelName |
|
) |
| |
Definition at line 411 of file CorrelationMatrixHelpers.py.
411 def DrawLabels(hist,jetDefString,scenarioString,drawATLASLabel,labelName):
412 if scenarioString !=
"":
417 if jetDefString.startswith(
"AntiKt4"):
418 jetDefLabel +=
"anti-k_{t} #it{R} = 0.4, "
419 elif jetDefString.startswith(
"AntiKt6"):
420 jetDefLabel +=
"anti-k_{t} #it{R} = 0.6, "
422 if jetDefString.endswith(
"LCTopo")
or jetDefString.endswith(
"TopoLC"):
423 jetDefLabel +=
"LCW+JES"
424 elif jetDefString.endswith(
"EMTopo")
or jetDefString.endswith(
"TopoEM"):
425 jetDefLabel +=
"EM+JES"
427 scenarioString =
"{0}".
format(scenarioString)
435 if jetDefString.startswith(
"AntiKt4"):
436 jetDefLabel +=
"anti-#it{k}_{t} #it{R} = 0.4, "
437 elif jetDefString.startswith(
"AntiKt6"):
438 jetDefLabel +=
"anti-#it{k}_{t} #it{R} = 0.6, "
440 if jetDefString.endswith(
"LCTopo")
or jetDefString.endswith(
"TopoLC"):
441 jetDefLabel +=
"LCW+JES + #it{in situ}"
442 elif jetDefString.endswith(
"EMTopo")
or jetDefString.endswith(
"TopoEM"):
443 jetDefLabel +=
"EM+JES + #it{in situ}"
445 scenarioString =
"{0}".
format(scenarioString)
447 doDrawText(0.09,0.900,
"Data 2015, #sqrt{s} = 13 TeV")
◆ DrawLabelsGuessScenario()
def CorrelationMatrixHelpers.DrawLabelsGuessScenario |
( |
|
histo | ) |
|
Definition at line 449 of file CorrelationMatrixHelpers.py.
450 jetDefString = histo.jetDef
451 scenarioLabel = histo.hist4D.GetName().
replace(
"4D_varpt_%s_"%(jetDefString),
"").
replace(
"4D_vareta_%s_"%(jetDefString),
"").
replace(
".root",
"")
452 plotType = histo.plotType
453 if "_" in scenarioLabel:
454 if scenarioLabel.startswith(
"diff_"):
455 scenarioLabel = re.sub(
"diff_",
"",scenarioLabel)
456 scenarioLabel = re.sub(
"_",
" - ",scenarioLabel)
457 scenarioLabel =
"Correlation differences, "+scenarioLabel
458 elif scenarioLabel.startswith(
"minDiff_"):
459 scenarioLabel = re.sub(
"minDiff_",
"",scenarioLabel)
460 scenarioLabel = re.sub(
"_",
", ",scenarioLabel)
462 scenarioLabel =
"Metric 1 (minimum correlation differences)" if not histo.relativeMetric
else "Metric 1' (minimum correlation differences)"
463 elif scenarioLabel.startswith(
"maxDiff_"):
464 scenarioLabel = re.sub(
"maxDiff_",
"",scenarioLabel)
465 scenarioLabel = re.sub(
"_",
", ",scenarioLabel)
466 scenarioLabel =
"Correlation differences, max[" + scenarioLabel +
"]"
467 elif scenarioLabel.startswith(
"coverageRaw_"):
468 scenarioLabel = re.sub(
"coverageRaw_",
"",scenarioLabel)
469 scenarioLabel = re.sub(
"_",
", ",scenarioLabel)
471 scenarioLabel =
"Metric 2 (raw)"
472 elif scenarioLabel.startswith(
"coverageRes_")
or plotType ==
"Metric2" or plotType ==
"Metric 2":
473 scenarioLabel = re.sub(
"coverageRes_",
"",scenarioLabel)
474 scenarioLabel = re.sub(
"_",
", ",scenarioLabel)
476 scenarioLabel =
"Metric 2 (uncovered correlation differences)" if not histo.relativeMetric
else "Metric 2' (uncovered correlation differences)"
477 elif scenarioLabel.startswith(
"uncertaintyRaw_coverageRaw"):
479 scenarioLabel =
"Metric 3 (raw)"
480 elif scenarioLabel.startswith(
"uncertaintyRes_coverageRes")
or plotType ==
"Metric3" or plotType ==
"Metric 3":
482 scenarioLabel =
"Metric 3 (uncovered corr. diff. including uncertainties)" if not histo.relativeMetric
else "Metric 3' (uncovered corr. diff. including uncertainties)"
483 elif scenarioLabel==
"uncenvelope":
484 scenarioLabel =
"Correlation uncertainties"
486 scenarioNum = re.sub(
"JER",
"",re.sub(
"4NP",
"",re.sub(
"3NP",
"",scenarioLabel)))
487 if len(scenarioNum) == 1:
488 scenarioLabel =
"Correlation difference, Rep_{full}^{JES} - Rep_{str.red}^{%s,JES}"%(scenarioNum
if not (scenarioNum ==
"3" and "JER" in scenarioLabel)
else "evdm")
490 scenarioNum =
"Correlation difference, full - %s"%(scenarioLabel)
492 DrawLabels(histo.hist4D,jetDefString,
"",histo.DrawATLASLabel,histo.ATLASLabelName)
495 sanitizedLabel=
"Uncovered correlation loss" if "Metric 2" in scenarioLabel
else (scenarioLabel
if "Metric" not in scenarioLabel
else re.sub(
"\)",
"",re.sub(
".*\(",
"",scenarioLabel)))
496 histo.hist4D.GetZaxis().SetTitle(sanitizedLabel)
497 histo.hist4D.GetZaxis().SetTitleOffset(1.8)
◆ getFixedValuesFromFile()
def CorrelationMatrixHelpers.getFixedValuesFromFile |
( |
|
inFile, |
|
|
|
jetDef |
|
) |
| |
Definition at line 573 of file CorrelationMatrixHelpers.py.
576 for histName
in inFile.GetKeyNames():
578 if not jetDef
in histName:
581 if not histName.startswith(
"diff_"):
586 if fixed1 !=
"" and fixed2 !=
"":
587 if fixed1.startswith(
"pt")
and fixed2.startswith(
"pt"):
588 newfixedPt.append([
float(fixed1.replace(
"pt",
"",1)),
float(fixed2.replace(
"pt",
"",1))])
589 elif fixed1.startswith(
"eta")
and fixed2.startswith(
"eta"):
590 newfixedEta.append([
float(fixed1.replace(
"eta",
"",1)),
float(fixed2.replace(
"eta",
"",1))])
592 print "ERROR: Unexpected mixture of fixed variables for histogram:",histName
595 print "ERROR: Failed to parse histogram name for fixed values:",histName
599 return newfixedPt,newfixedEta
◆ getFixedValuesFromFiles()
def CorrelationMatrixHelpers.getFixedValuesFromFiles |
( |
|
inFiles, |
|
|
|
jetDef |
|
) |
| |
Definition at line 602 of file CorrelationMatrixHelpers.py.
609 for aFile
in inFiles[1:]:
616 if len(localFixedPt) != len(newfixedPt):
617 print "ERROR: File %s has %d fixed pt values, while %s has %d values"%(aFile.GetNameNoDir(),len(localFixedPt),inFiles[0],len(newfixedPt))
619 elif len(localFixedEta) != len(newfixedEta):
620 print "ERROR: File %s has %d fixed eta values, while %s has %d values"%(aFile.GetNameNoDir(),len(localFixedEta),inFiles[0],len(newfixedEta))
622 for localVal,globalVal
in zip(localFixedPt,newfixedPt):
623 if fabs(localVal[0]-globalVal[0]) > 1.e-4
or fabs(localVal[1]-globalVal[1]) > 1.e-4:
624 print "ERROR: File %s and %s have different fixed pt values, was comparing %f and %f"%(aFile.GetNameNoDir(),inFiles[0],localVal,globalVal)
626 for localVal,globalVal
in zip(localFixedEta,newfixedEta):
627 if fabs(localVal[0]-globalVal[0]) > 1.e-4
or fabs(localVal[1]-globalVal[1]) > 1.e-4:
628 print "ERROR: File %s and %s have different fixed eta values, was comparing %f and %f"%(aFile.GetNameNoDir(),inFiles[0],localVal,globalVal)
633 newfixedPtX =
set([])
634 newfixedPtY =
set([])
635 for newfixedPtSet
in newfixedPt:
636 newfixedPtX.add(newfixedPtSet[0])
637 newfixedPtY.add(newfixedPtSet[1])
638 newfixedPtX =
sorted(newfixedPtX)
639 newfixedPtY =
sorted(newfixedPtY)
641 newfixedEtaX =
set([])
642 newfixedEtaY =
set([])
643 for newfixedEtaSet
in newfixedEta:
644 newfixedEtaX.add(newfixedEtaSet[0])
645 newfixedEtaY.add(newfixedEtaSet[1])
646 newfixedEtaX =
sorted(newfixedEtaX)
647 newfixedEtaY =
sorted(newfixedEtaY)
650 return newfixedPtX,newfixedPtY,newfixedEtaX,newfixedEtaY
◆ getFixedValuesFromName()
def CorrelationMatrixHelpers.getFixedValuesFromName |
( |
|
histName | ) |
|
#
Fixed value manipulation (pT and eta values) # #
Definition at line 550 of file CorrelationMatrixHelpers.py.
552 tokens = histName.split(
"_")
555 for aToken
in tokens:
557 if aToken.startswith(
"pt"):
559 elif aToken.startswith(
"eta"):
568 print "ERROR: More than two fixed values appear in name:",histName
◆ relativeMetric()
def CorrelationMatrixHelpers.relativeMetric |
( |
|
numerator, |
|
|
|
denominator |
|
) |
| |
Definition at line 653 of file CorrelationMatrixHelpers.py.
654 if fabs(denominator) < 1.e-3:
655 if fabs(numerator) < 1.e-3:
659 if numerator/denominator < 0:
660 print "NUM/DEN = %f/%f"%(numerator,denominator)
661 return sqrt(numerator/denominator)
◆ saveHists4D()
def CorrelationMatrixHelpers.saveHists4D |
( |
|
canvas, |
|
|
|
plotFileName, |
|
|
|
hist, |
|
|
|
oneSidedAxis, |
|
|
|
fixedX, |
|
|
|
fixedY, |
|
|
|
fixedStr, |
|
|
|
scenarioLabel = "" , |
|
|
|
drawATLASLabel = True , |
|
|
|
additionalString = "" |
|
) |
| |
Definition at line 499 of file CorrelationMatrixHelpers.py.
499 def saveHists4D(canvas,plotFileName,hist,oneSidedAxis,fixedX,fixedY,fixedStr,scenarioLabel="",drawATLASLabel=True,additionalString = ""):
504 elif isinstance(hist,list):
507 saveHists4D(canvas,plotFileName,aHist,oneSidedAxis,fixedX,fixedY,fixedStr,drawATLASLabel=drawATLASLabel,additionalString =
"{0}.{1}".
format(additionalString,hist.index(aHist)))
510 hist.DrawATLASLabel = drawATLASLabel
515 hist.hist4D.GetXaxis().SetMoreLogLabels()
517 hist.hist4D.GetYaxis().SetMoreLogLabels()
519 hist.hist4D.GetZaxis().SetMoreLogLabels()
520 hist.hist4D.GetZaxis().SetLabelOffset(0.0010)
522 if hist.relativeMetric:
523 for binX
in range(1,hist.hist4D.GetNbinsX()+1):
524 for binY
in range(1,hist.hist4D.GetNbinsY()+1):
525 if hist.hist4D.GetBinContent(binX,binY) < hist.OOBT:
526 hist.hist4D.SetBinContent(binX,binY,1.e-10)
527 hist.hist4D.Draw(
"colz")
529 thisMaxAll,thisMaxAvg =
DetermineStatValues(hist.hist4D,fixedX,fixedY,hist.OOBT
if not hist.relativeMetric
else 1.e-9,1e10,
not hist.relativeMetric)
530 if scenarioLabel !=
"":
DrawLabels(hist.hist4D,hist.jetDef,scenarioLabel,hist.DrawATLASLabel,hist.ATLASLabelName)
533 if not (plotFileName.endswith(
".eps")
or plotFileName.endswith(
".png")):
534 canvas.Print(plotFileName)
536 mynewname = plotFileName.replace(
".png",
"-{0}-maxAll{1}-maxAvg{2}.png".
format(additionalString,
int(fabs(thisMaxAll*100)),
int(fabs(thisMaxAvg*100))))
537 mynewname = mynewname.replace(
".eps",
"-{0}-maxAll{1}-maxAvg{2}.eps".
format(additionalString,
int(fabs(thisMaxAll*100)),
int(fabs(thisMaxAvg*100))))
538 canvas.Print(mynewname)
def buildAndFillHists4DFromDifferenceHists(hists, relativeMetric=False)
std::string replace(std::string s, const std::string &s2, const std::string &s3)
def SetAxisRange(histo, oneSided=True, lowBound=-1e10, highBound=1e10)
def DrawLabels(hist, jetDefString, scenarioString, drawATLASLabel, labelName)
def buildAndFillHist4DFromMinOfSet(hists, relativeMetric=False)
def saveHists4D(canvas, plotFileName, hist, oneSidedAxis, fixedX, fixedY, fixedStr, scenarioLabel="", drawATLASLabel=True, additionalString="")
def SetAxisLabels(histo, xValues, yValues, labelString)
def buildAndFillHist4DFromMaxOfSet(hists, relativeMetric=False)
def getFixedValuesFromFiles(inFiles, jetDef)
def getFixedValuesFromFile(inFile, jetDef)
def DetermineStatValues(histo, xValues, yValues, lowBound=-1e10, highBound=1e10, percent=True)
def buildAndFillHists4DFromEnvelopeOfSet(hists, relativeMetric=False)
def DrawLabelsGuessScenario(histo)
def ATLASLabel(x, y, text="", color=kBlack)
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
def buildAndFillHist4DFromCoverageOfSet(minDiffFromNominal, maxDiffBetweenScenarios, plotStyle, nominalHist=None, relativeMetric=False)
def buildAndFillHists4DFromFiles(inFiles, jetDef, varString, fixedString, fixedX, fixedY, filterStartString="", granularityFactor=1, relativeMetric=False)
def buildAndFillHists4DFromFile(inFile, jetDef, varString, fixedString, fixedX, fixedY, excludeStartString="", granularityFactor=1, relativeMetric=False)
double relativeMetric(const double numerator, const double denominator)
def getFixedValuesFromName(histName)
def doDrawText(xPos, yPos, text)
def DrawGrid(histo, xValues, yValues)