ATLAS Offline Software
Loading...
Searching...
No Matches
CorrelationMatrixHelpers Namespace Reference

Classes

class  CorrMat4D

Functions

 DrawLabels (hist, jetDefString, scenarioString, drawATLASLabel, labelName)
 DrawLabelsGuessScenario (histo)
 saveHists4D (canvas, plotFileName, hist, oneSidedAxis, fixedX, fixedY, fixedStr, scenarioLabel="", drawATLASLabel=True, additionalString="")
 getFixedValuesFromName (histName)
 getFixedValuesFromFile (inFile, jetDef)
 getFixedValuesFromFiles (inFiles, jetDef)
 relativeMetric (numerator, denominator)
 buildAndFillHists4DFromFiles (inFiles, jetDef, varString, fixedString, fixedX, fixedY, filterStartString="", granularityFactor=1, relativeMetric=False)
 buildAndFillHists4DFromFile (inFile, jetDef, varString, fixedString, fixedX, fixedY, excludeStartString="", granularityFactor=1, relativeMetric=False)
 buildAndFillHists4DFromDifferenceHists (hists, relativeMetric=False)
 buildAndFillHist4DFromMinOfSet (hists, relativeMetric=False)
 buildAndFillHist4DFromMaxOfSet (hists, relativeMetric=False)
 buildAndFillHists4DFromEnvelopeOfSet (hists, relativeMetric=False)
 buildAndFillHist4DFromCoverageOfSet (minDiffFromNominal, maxDiffBetweenScenarios, plotStyle, nominalHist=None, relativeMetric=False)

Function Documentation

◆ buildAndFillHist4DFromCoverageOfSet()

CorrelationMatrixHelpers.buildAndFillHist4DFromCoverageOfSet ( minDiffFromNominal,
maxDiffBetweenScenarios,
plotStyle,
nominalHist = None,
relativeMetric = False )

Definition at line 781 of file CorrelationMatrixHelpers.py.

781def buildAndFillHist4DFromCoverageOfSet(minDiffFromNominal,maxDiffBetweenScenarios,plotStyle,nominalHist=None,relativeMetric=False):
782 coverageHist = CorrMat4D(relativeMetric)
783 coverageHist.setInfoCopy(minDiffFromNominal,"coverage_type%d"%(plotStyle))
784
785 if not coverageHist.fillHist4DFromCoverageOfSet(minDiffFromNominal,maxDiffBetweenScenarios,plotStyle,nominalHist):
786 return None
787 return coverageHist
788
789

◆ buildAndFillHist4DFromMaxOfSet()

CorrelationMatrixHelpers.buildAndFillHist4DFromMaxOfSet ( hists,
relativeMetric = False )

Definition at line 757 of file CorrelationMatrixHelpers.py.

757def buildAndFillHist4DFromMaxOfSet(hists,relativeMetric=False):
758 # Ensure the histogram(s) exist
759 if not hists or len(hists) == 0:
760 print "Argument is None or empty list: ",hists
761 return None
762
763 maxHist = CorrMat4D(relativeMetric)
764 maxHist.setInfoCopy(hists[0],"maxDiff_%dinputs"%(len(hists)))
765 if not maxHist.fillHist4DFromMaxOfSet(hists):
766 return None
767 return maxHist
768

◆ buildAndFillHist4DFromMinOfSet()

CorrelationMatrixHelpers.buildAndFillHist4DFromMinOfSet ( hists,
relativeMetric = False )

Definition at line 745 of file CorrelationMatrixHelpers.py.

745def buildAndFillHist4DFromMinOfSet(hists,relativeMetric=False):
746 # Ensure the histogram(s) exist
747 if not hists or len(hists) == 0:
748 print "Argument is None or empty list: ",hists
749 return None
750
751 minHist = CorrMat4D(relativeMetric)
752 minHist.setInfoCopy(hists[0],"minDiff_%dinputs"%(len(hists)))
753 if not minHist.fillHist4DFromMinOfSet(hists):
754 return None
755 return minHist
756

◆ buildAndFillHists4DFromDifferenceHists()

CorrelationMatrixHelpers.buildAndFillHists4DFromDifferenceHists ( hists,
relativeMetric = False )

Definition at line 732 of file CorrelationMatrixHelpers.py.

732def buildAndFillHists4DFromDifferenceHists(hists,relativeMetric=False) :
733
734 # Must do all possible comparisons
735 diffHists = []
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]):
741 return None
742 diffHists.append(hist4D)
743 return diffHists
744

◆ buildAndFillHists4DFromEnvelopeOfSet()

CorrelationMatrixHelpers.buildAndFillHists4DFromEnvelopeOfSet ( hists,
relativeMetric = False )

Definition at line 769 of file CorrelationMatrixHelpers.py.

769def buildAndFillHists4DFromEnvelopeOfSet(hists,relativeMetric=False):
770 # Ensure the histogram(s) exist
771 if not hists or len(hists) < 2:
772 print "Argument is None or contains less than two histograms: ",hists
773 return None
774
775 envelopeHist = CorrMat4D(relativeMetric)
776 envelopeHist.setInfoCopy(hists[0],"envelope_%dinputs"%(len(hists)))
777 if not envelopeHist.fillHist4DFromEnvelopeOfSet(hists):
778 return None
779 return envelopeHist
780

◆ buildAndFillHists4DFromFile()

CorrelationMatrixHelpers.buildAndFillHists4DFromFile ( inFile,
jetDef,
varString,
fixedString,
fixedX,
fixedY,
excludeStartString = "",
granularityFactor = 1,
relativeMetric = False )

Definition at line 696 of file CorrelationMatrixHelpers.py.

696def buildAndFillHists4DFromFile(inFile,jetDef,varString,fixedString,fixedX,fixedY,excludeStartString="",granularityFactor=1,relativeMetric=False):
697 try:
698 iterator = iter(inFile)
699 except TypeError:
700 # Not iterable
701 # Probably a single item
702 # Nothing to do in this case
703 pass
704 else:
705 # Iterable
706 # Probably a list of files, but watch for a single string
707 if isinstance(inFile,str):
708 inFile = TFile.Open(inFile,"READ")
709 else:
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"
712 return None
713
714 # Get the list of starts (the string before _var*)
715 startStrings = set()
716 for histName in inFile.GetKeyNames():
717 if excludeStartString != "" and histName.startswith(excludeStartString):
718 continue
719 # Find the _var and get what's in front of it
720 startStrings.add(histName[:histName.find("_var")])
721
722 # Now run over the scenarios
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):
727 return None
728
729 return hists4D
730
731
STL class.

◆ buildAndFillHists4DFromFiles()

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.

670def buildAndFillHists4DFromFiles(inFiles,jetDef,varString,fixedString,fixedX,fixedY,filterStartString="",granularityFactor=1,relativeMetric=False):
671 try:
672 iterator = iter(inFiles)
673 except TypeError:
674 # Not iterable
675 # Probably a single item
676 inFiles = [inFiles]
677 else:
678 # Iterable
679 # Probably a list of files, but watch for strings
680 if isinstance(inFiles,str):
681 inFiles = [TFile.Open(inFiles,"READ")]
682 else:
683 for iFile in range(0,len(inFiles)):
684 if isinstance(inFiles[iFile],str):
685 inFiles[iFile] = TFile.Open(inFiles[iFile],"READ")
686
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):
691 return None
692
693 return hists4D
694
695

◆ DrawLabels()

CorrelationMatrixHelpers.DrawLabels ( hist,
jetDefString,
scenarioString,
drawATLASLabel,
labelName )

Definition at line 411 of file CorrelationMatrixHelpers.py.

411def DrawLabels(hist,jetDefString,scenarioString,drawATLASLabel,labelName):
412 if scenarioString != "":
413 if drawATLASLabel:
414 AtlasStyleMacro.ATLASLabel(0.10,0.845,labelName)
415 jetDefLabel = ""
416
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, "
421
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"
426
427 scenarioString = "{0}".format(scenarioString)
428 doDrawText(0.10,0.900,jetDefLabel+" 2016")
429 doDrawText(0.10,0.955,scenarioString)
430 else:
431 if drawATLASLabel:
432 AtlasStyleMacro.ATLASLabel(0.09,0.955,labelName)
433 jetDefLabel = ""
434
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, "
439
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}"
444
445 scenarioString = "{0}".format(scenarioString)
446 doDrawText(0.50,0.955,jetDefLabel)
447 doDrawText(0.09,0.900,"Data 2015, #sqrt{s} = 13 TeV")
448
void DrawLabels(const TH2D *histo, const double fixedValue1, const double fixedValue2, const JetUncertaintiesTool *uncTool, const JetUncertaintiesTool *uncToolDiff=nullptr, const double mean=0, const double extremum=0, const int extremeX=-1, const int extremeY=-1)
ATLASLabel(x, y, text="", color=kBlack)

◆ DrawLabelsGuessScenario()

CorrelationMatrixHelpers.DrawLabelsGuessScenario ( histo)

Definition at line 449 of file CorrelationMatrixHelpers.py.

449def DrawLabelsGuessScenario(histo):
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)
461 #scenarioLabel = "Correlation differences, min[" + 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)
470 #scenarioLabel = "Correlation loss coverage, [" + 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)
475 #scenarioLabel = "Correlation loss remaining, [" + scenarioLabel + "]"
476 scenarioLabel = "Metric 2 (uncovered correlation differences)" if not histo.relativeMetric else "Metric 2' (uncovered correlation differences)"
477 elif scenarioLabel.startswith("uncertaintyRaw_coverageRaw"):
478 #scenarioLabel = "Remaining loss not covered by correlation uncertainties"
479 scenarioLabel = "Metric 3 (raw)"
480 elif scenarioLabel.startswith("uncertaintyRes_coverageRes") or plotType == "Metric3" or plotType == "Metric 3":
481 #scenarioLabel = "Remaining loss beyond correlation uncertainties"
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"
485 else:
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")
489 else:
490 scenarioNum = "Correlation difference, full - %s"%(scenarioLabel)
491
492 DrawLabels(histo.hist4D,jetDefString,"",histo.DrawATLASLabel,histo.ATLASLabelName)
493 #DrawLabels(histo.hist4D,jetDefString,scenarioLabel,histo.DrawATLASLabel,histo.ATLASLabelName)
494
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)
498
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310

◆ getFixedValuesFromFile()

CorrelationMatrixHelpers.getFixedValuesFromFile ( inFile,
jetDef )

Definition at line 573 of file CorrelationMatrixHelpers.py.

573def getFixedValuesFromFile(inFile,jetDef):
574 newfixedPt = []
575 newfixedEta = []
576 for histName in inFile.GetKeyNames():
577 # Ensure this histogram is for the collection we want
578 if not jetDef in histName:
579 continue
580 # Ensure this is a difference histogram
581 if not histName.startswith("diff_"):
582 continue
583
584 fixed1,fixed2 = getFixedValuesFromName(histName)
585
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))])
591 else:
592 print "ERROR: Unexpected mixture of fixed variables for histogram:",histName
593 sys.exit(-1)
594 else:
595 print "ERROR: Failed to parse histogram name for fixed values:",histName
596 sys.exit(-2)
597
598
599 return newfixedPt,newfixedEta
600
601

◆ getFixedValuesFromFiles()

CorrelationMatrixHelpers.getFixedValuesFromFiles ( inFiles,
jetDef )

Definition at line 602 of file CorrelationMatrixHelpers.py.

602def getFixedValuesFromFiles(inFiles,jetDef):
603 # Get fixed pt and/or eta values from the first file
604 newfixedPt,newfixedEta = getFixedValuesFromFile(inFiles[0],jetDef)
605 newfixedPt.sort()
606 newfixedEta.sort()
607
608 # Ensure that subsequent file(s) match the fixed pt/eta values
609 for aFile in inFiles[1:]:
610 localFixedPt,localFixedEta = getFixedValuesFromFile(aFile,jetDef)
611 localFixedPt.sort()
612 localFixedEta.sort()
613
614 # Check for equality
615 # Note that these are floating point equalities, so be careful
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))
618 sys.exit(3)
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))
621 sys.exit(4)
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)
625 sys.exit(5)
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)
629 sys.exit(6)
630
631 # Files have now been confirmed to match in fixed values, assuming multiple files were specified
632 # Determine the actual pT and eta values available now (not just pairs)
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)
640
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)
648
649 # Done, return the sorted lists of fixed values
650 return newfixedPtX,newfixedPtY,newfixedEtaX,newfixedEtaY
651
652

◆ getFixedValuesFromName()

CorrelationMatrixHelpers.getFixedValuesFromName ( histName)
                                           #

Fixed value manipulation (pT and eta values) # #

Definition at line 550 of file CorrelationMatrixHelpers.py.

550def getFixedValuesFromName(histName):
551 # Parse the histogram name
552 tokens = histName.split("_")
553 fixed1 = ""
554 fixed2 = ""
555 for aToken in tokens:
556 keep = False
557 if aToken.startswith("pt"):
558 keep = True
559 elif aToken.startswith("eta"):
560 keep = True
561
562 if keep:
563 if fixed1 == "":
564 fixed1 = aToken
565 elif fixed2 == "":
566 fixed2 = aToken
567 else:
568 print "ERROR: More than two fixed values appear in name:",histName
569 sys.exit(-1)
570 return fixed1,fixed2
571
572

◆ relativeMetric()

CorrelationMatrixHelpers.relativeMetric ( numerator,
denominator )

Definition at line 653 of file CorrelationMatrixHelpers.py.

653def relativeMetric(numerator,denominator):
654 if fabs(denominator) < 1.e-3:
655 if fabs(numerator) < 1.e-3:
656 return 1
657 else:
658 return globalOOB
659 if numerator/denominator < 0:
660 print "NUM/DEN = %f/%f"%(numerator,denominator)
661 return sqrt(numerator/denominator)
662
double relativeMetric(const double numerator, const double denominator)

◆ saveHists4D()

CorrelationMatrixHelpers.saveHists4D ( canvas,
plotFileName,
hist,
oneSidedAxis,
fixedX,
fixedY,
fixedStr,
scenarioLabel = "",
drawATLASLabel = True,
additionalString = "" )

Definition at line 499 of file CorrelationMatrixHelpers.py.

499def saveHists4D(canvas,plotFileName,hist,oneSidedAxis,fixedX,fixedY,fixedStr,scenarioLabel="",drawATLASLabel=True,additionalString = ""):
500
501 # Check for empty inputs
502 if not hist:
503 pass
504 elif isinstance(hist,list):
505 # A list, iterate on the entries
506 for aHist in hist:
507 saveHists4D(canvas,plotFileName,aHist,oneSidedAxis,fixedX,fixedY,fixedStr,drawATLASLabel=drawATLASLabel,additionalString = "{0}.{1}".format(additionalString,hist.index(aHist)))
508 else:
509 # Not a list, save the output
510 hist.DrawATLASLabel = drawATLASLabel
511 SetAxisRange(hist.hist4D,oneSidedAxis,hist.OOBT,1e10)
512 SetAxisLabels(hist.hist4D,fixedX,fixedY,fixedStr)
513
514 if canvas.GetLogx():
515 hist.hist4D.GetXaxis().SetMoreLogLabels()
516 if canvas.GetLogy():
517 hist.hist4D.GetYaxis().SetMoreLogLabels()
518 if canvas.GetLogz():
519 hist.hist4D.GetZaxis().SetMoreLogLabels()
520 hist.hist4D.GetZaxis().SetLabelOffset(0.0010)
521
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")
528 DrawGrid(hist.hist4D,fixedX,fixedY)
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)
531 else: DrawLabelsGuessScenario(hist)
532
533 if not (plotFileName.endswith(".eps") or plotFileName.endswith(".png")):
534 canvas.Print(plotFileName)
535 else:
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)
539 hist.iEPS += 1
540 #canvas.Print(getPlotFileName(plotFileName))
541
542