4 from array 
import array
 
    5 from math 
import fabs,exp,log,sqrt
 
   11 from PlotHelpers 
import *
 
   40     def setInfo(self,jetDef,varType,plotType):
 
   46         self.
jetDef   = toCopy.jetDef
 
   48         self.
plotType = plotType 
if plotType != 
"" else toCopy.plotType
 
   52             self.
hist4D = toClone.Clone()
 
   53         except AttributeError:
 
   54             self.
hist4D = toClone.hist4D.Clone()
 
   59           print "Cannot apply absolute value when the histogram hasn't been created" 
   64             if self.
hist4D.GetBinContent(binX,binY) > self.
OOBT:
 
   65                 self.
hist4D.SetBinContent(binX,binY,fabs(self.
hist4D.GetBinContent(binX,binY)))
 
   70     def fillHist4DFromFile(self,inFile,fixedString,fixedX,fixedY,filterStartString="",granularityFactor=1):
 
   73           print "Blocking re-filling of existing CorrMat4D histogram of name ",self.
hist4D.GetName()
 
   78       for histName 
in inFile.GetKeyNames():
 
   79         if filterStartString != 
"" and not histName.startswith(filterStartString):
 
   81         if self.
jetDef not in histName:
 
   83         if "_%s"%(fixedString) 
in histName:
 
   84             hist = inFile.Get(histName)
 
   85             numBins = hist.GetNbinsX()
 
   88         print "Failed to find histogram matching criteria:" 
   89         print "jetDef = \"%s\""%(self.
jetDef)
 
   90         print "filterStartString = \"%s\""%(filterStartString)
 
   94       localNumBins = 
int(numBins / granularityFactor) 
if granularityFactor > 1 
else numBins
 
   95       if granularityFactor > 1:
 
   97         if numBins % granularityFactor != 0:
 
   98             print "Cannot apply granularity factor: %d bins can't be divided by %d"%(numBins,granularityFactor)
 
  102       histName4D = 
"4D_var%s_%s_%s"%(self.
varType,self.
jetDef,inFile.GetNameNoDir())
 
  103       self.
hist4D = TH2D(histName4D,
"",len(fixedX)*localNumBins,0.,len(fixedX)*localNumBins,len(fixedY)*localNumBins,0.,len(fixedY)*localNumBins)
 
  108             self.
hist4D.SetBinContent(binX,binY,self.
OOB)
 
  111       for histName 
in inFile.GetKeyNames():
 
  112         if filterStartString != 
"" and not histName.startswith(filterStartString):
 
  114         if self.
jetDef not in histName:
 
  120         if not fixed1.startswith(fixedString): 
continue 
  121         fixed1 = 
float(fixed1.replace(fixedString,
"",1))
 
  122         fixed2 = 
float(fixed2.replace(fixedString,
"",1))
 
  127         for aIndex 
in range(0,len(fixedX)):
 
  128             aValue = fixedX[aIndex]
 
  129             if fabs(aValue - fixed1) < 1.e-4:
 
  132         for aIndex 
in range(0,len(fixedY)):
 
  133             aValue = fixedY[aIndex]
 
  134             if fabs(aValue - fixed2) < 1.e-4:
 
  137         if index1 < 0 
or index2 < 0:
 
  138             print "Failed to find index1 (%d) or index2 (%d) for histogram (%s)"%(index1,index2,histName)
 
  145         hist2D = inFile.Get(histName)
 
  146         offsetX = 
int((self.
hist4D.GetNbinsX()/len(fixedX))*index1)
 
  147         offsetY = 
int((self.
hist4D.GetNbinsY()/len(fixedY))*index2)
 
  148         if localNumBins == numBins:
 
  149             for binX 
in range(1,hist2D.GetNbinsX()+1):
 
  150                 for binY 
in range(1,hist2D.GetNbinsY()+1):
 
  151                     self.
hist4D.SetBinContent(binX+offsetX,binY+offsetY,hist2D.GetBinContent(binX,binY))
 
  156             for binX 
in range(0,hist2D.GetNbinsX()/granularityFactor):
 
  157                 for binY 
in range(0,hist2D.GetNbinsY()/granularityFactor):
 
  160                     for subBinX 
in range(1,granularityFactor+1):
 
  161                         for subBinY 
in range(1,granularityFactor+1):
 
  162                             binContent = hist2D.GetBinContent(binX*granularityFactor+subBinX,binY*granularityFactor+subBinY)
 
  163                             if binContent > self.
OOBT:
 
  166                     self.
hist4D.SetBinContent(binX+1+offsetX,binY+1+offsetY,subVal/numVal 
if numVal > 0 
else self.
OOB)
 
  178         print "Blocking re-filling of existing CorrMat4D histogram of name ",self.
hist4D.GetName()
 
  182       if not hist1 
or not hist2:
 
  183         print "Argument(s) are None: ",hist1,hist2
 
  190       for binX 
in range(1,hist1.hist4D.GetNbinsX()+1):
 
  191         for binY 
in range(1,hist2.hist4D.GetNbinsX()+1):
 
  192             if hist1.hist4D.GetBinContent(binX,binY) > self.
OOBT and hist2.hist4D.GetBinContent(binX,binY) > self.
OOBT:
 
  193                 if not hist1.relativeMetric:
 
  194                     self.
hist4D.SetBinContent(binX,binY,hist1.hist4D.GetBinContent(binX,binY) - hist2.hist4D.GetBinContent(binX,binY))
 
  196                     self.
hist4D.SetBinContent(binX,binY,
relativeMetric(hist1.hist4D.GetBinContent(binX,binY),hist2.hist4D.GetBinContent(binX,binY)))
 
  206         print "Blocking re-filling of existing CorrMat4D histogram of name ",self.
hist4D.GetName()
 
  210       if not hists 
or len(hists) == 0:
 
  211         print "Argument is None or empty list: ",hists
 
  221       for aHist 
in hists[1:]:
 
  222         for binX 
in range(1,aHist.hist4D.GetNbinsX()+1):
 
  223             for binY 
in range(1,aHist.hist4D.GetNbinsY()+1):
 
  224                 if aHist.hist4D.GetBinContent(binX,binY) > aHist.OOBT:
 
  225                     if not aHist.relativeMetric:
 
  226                         if fabs(aHist.hist4D.GetBinContent(binX,binY)) < fabs(self.
hist4D.GetBinContent(binX,binY)):
 
  227                             self.
hist4D.SetBinContent(binX,binY,aHist.hist4D.GetBinContent(binX,binY))
 
  229                         currVal = self.
hist4D.GetBinContent(binX,binY)
 
  230                         newVal  = aHist.hist4D.GetBinContent(binX,binY)
 
  232                         if currVal <= 1 
and newVal >= 1:
 
  233                             self.
hist4D.SetBinContent(binX,binY,1)
 
  234                         elif currVal >= 1 
and newVal <= 1:
 
  235                             self.
hist4D.SetBinContent(binX,binY,1)
 
  236                         elif currVal < 1 
and newVal < 1:
 
  238                                 self.
hist4D.SetBinContent(binX,binY,newVal)
 
  245                         elif currVal > 1 
and newVal > 1:
 
  247                                 self.
hist4D.SetBinContent(binX,binY,newVal)
 
  256         print "Blocking re-filling of existing CorrMat4D histogram of name ",self.
hist4D.GetName()
 
  260       if not hists 
or len(hists) == 0:
 
  261         print "Argument is None or empty list: ",hists
 
  271       for aHist 
in hists[1:]:
 
  272         for binX 
in range(1,aHist.hist4D.GetNbinsX()+1):
 
  273             for binY 
in range(1,aHist.hist4D.GetNbinsY()+1):
 
  274                 if aHist.hist4D.GetBinContent(binX,binY) > aHist.OOBT 
and aHist.hist4D.GetBinContent(binX,binY) < -aHist.OOBT:
 
  275                     if not aHist.relativeMetric:
 
  276                         if fabs(aHist.hist4D.GetBinContent(binX,binY)) > fabs(self.
hist4D.GetBinContent(binX,binY)):
 
  277                             self.
hist4D.SetBinContent(binX,binY,aHist.hist4D.GetBinContent(binX,binY))
 
  279                         currVal = self.
hist4D.GetBinContent(binX,binY)
 
  280                         newVal  = aHist.hist4D.GetBinContent(binX,binY)
 
  281                         if currVal < 1 
and newVal < 1:
 
  283                                 self.
hist4D.SetBinContent(binX,binY,newVal)
 
  284                         elif currVal < 1 
and newVal > 1:
 
  285                             if newVal > 1/currVal:
 
  286                                 self.
hist4D.SetBinContent(binX,binY,newVal)
 
  287                         elif currVal > 1 
and newVal < 1:
 
  288                             if newVal < 1/currVal:
 
  289                                 self.
hist4D.SetBinContent(binX,binY,newVal)
 
  290                         elif currVal > 1 
and newVal > 1:
 
  292                                 self.
hist4D.SetBinContent(binX,binY,newVal)
 
  301         print "Blocking re-filling of existing CorrMat4D histogram of name ",self.
hist4D.GetName()
 
  305       if not hists 
or len(hists) < 2:
 
  306         print "Argument is None or contains less than two histograms: ",hists
 
  316             if self.
hist4D.GetBinContent(binX,binY) > self.
OOBT:
 
  317                 self.
hist4D.SetBinContent(binX,binY,0)
 
  321       for iHist1 
in range(0,len(hists)):
 
  322         hist1 = hists[iHist1]
 
  323         for iHist2 
in range(iHist1+1,len(hists)):
 
  324             hist2 = hists[iHist2]
 
  327                     if self.
hist4D.GetBinContent(binX,binY) > self.
OOBT:
 
  328                         if aHist.relativeMetric:
 
  329                             diff = 
relativeMetric(1-hist1.hist4D.GetBinContent(binX,binY),1-hist2.hist4D.GetBinContent(binX,binY))
 
  331                             diff = fabs(hist2.hist4D.GetBinContent(binX,binY) - hist1.hist4D.GetBinContent(binX,binY))
 
  332                         if diff > self.
hist4D.GetBinContent(binX,binY):
 
  333                             self.
hist4D.SetBinContent(binX,binY,diff)
 
  343         print "Blocking re-filling of existing CorrMat4D histogram of name ",self.
hist4D.GetName()
 
  347       if not minDiffFromNominal 
or not maxDiffBetweenScenarios:
 
  348         print "Argument is None or empty list: ",minDiffFromNominal,maxDiffBetweenScenarios
 
  350       if plotStyle==2 
and not nominalHist:
 
  351         print "NominalHist is None for style which requires it" 
  364             if self.
hist4D.GetBinContent(binX,binY) > self.
OOBT:
 
  365                 minDiff = fabs(minDiffFromNominal.hist4D.GetBinContent(binX,binY))
 
  366                 maxDiff = fabs(maxDiffBetweenScenarios.hist4D.GetBinContent(binX,binY))
 
  369                     if minDiff <= maxDiff:
 
  370                         self.
hist4D.SetBinContent(binX,binY,0)
 
  372                         self.
hist4D.SetBinContent(binX,binY,minDiffFromNominal.hist4D.GetBinContent(binX,binY))
 
  374                         self.
hist4D.SetBinContent(binX,binY,maxDiff-minDiff)
 
  376                         self.
hist4D.SetBinContent(binX,binY,nominalHist.hist4D.GetBinContent(binX,binY))
 
  378                         print "Unrecognized plotStyle of ",plotStyle
 
  383                     if (minDiff <= 1 
and maxDiff <= 1) 
and (minDiff >= maxDiff):
 
  384                         self.
hist4D.SetBinContent(binX,binY,1)
 
  385                     elif (minDiff >= 1 
and maxDiff >= 1) 
and (minDiff <= maxDiff):
 
  386                         self.
hist4D.SetBinContent(binX,binY,1)
 
  387                     elif (minDiff >= 1 
and maxDiff <= 1) 
and (minDiff <= 1/maxDiff):
 
  388                         self.
hist4D.SetBinContent(binX,binY,1)
 
  389                     elif (minDiff <= 1 
and maxDiff >= 1) 
and (minDiff >= 1/maxDiff):
 
  390                         self.
hist4D.SetBinContent(binX,binY,1)
 
  393                             self.
hist4D.SetBinContent(binX,binY,minDiffFromNominal.hist4D.GetBinContent(binX,binY))
 
  395                             if (minDiff <= 1 
and maxDiff <= 1) 
or (minDiff >= 1 
and maxDiff >= 1):
 
  396                                 self.
hist4D.SetBinContent(binX,binY,minDiff/maxDiff)
 
  398                                 self.
hist4D.SetBinContent(binX,binY,minDiff*maxDiff)
 
  400                             self.
hist4D.SetBinContent(binX,binY,nominalHist.hist4D.GetBinContent(binX,binY))
 
  402                             print "Unrecognized plotStyle of ",plotStyle
 
  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")
 
  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)
 
  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)
 
  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
 
  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
 
  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
 
  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)
 
  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):
 
  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):
 
  736     for iHist1 
in range(0,len(hists)):
 
  737         for iHist2 
in range(iHist1+1,len(hists)):
 
  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)
 
  747     if not hists 
or len(hists) == 0:
 
  748         print "Argument is None or empty list: ",hists
 
  752     minHist.setInfoCopy(hists[0],
"minDiff_%dinputs"%(len(hists)))
 
  753     if not minHist.fillHist4DFromMinOfSet(hists):
 
  759     if not hists 
or len(hists) == 0:
 
  760         print "Argument is None or empty list: ",hists
 
  764     maxHist.setInfoCopy(hists[0],
"maxDiff_%dinputs"%(len(hists)))
 
  765     if not maxHist.fillHist4DFromMaxOfSet(hists):
 
  771     if not hists 
or len(hists) < 2:
 
  772         print "Argument is None or contains less than two histograms: ",hists
 
  776     envelopeHist.setInfoCopy(hists[0],
"envelope_%dinputs"%(len(hists)))
 
  777     if not envelopeHist.fillHist4DFromEnvelopeOfSet(hists):
 
  783     coverageHist.setInfoCopy(minDiffFromNominal,
"coverage_type%d"%(plotStyle))
 
  785     if not coverageHist.fillHist4DFromCoverageOfSet(minDiffFromNominal,maxDiffBetweenScenarios,plotStyle,nominalHist):