6 from decimal
import Decimal
16 self.
cwd = os.getcwd()
20 self.
segments = [
"BPIX",
"FPIX",
"TEC",
"TID",
"TIB",
"TOB"]
37 v =
int(sys.version_info[0])
38 source =
"DMRplotter: " 42 print(source,
"[INFO] ",text)
46 print(source,
"[WARNING] ",text)
48 print(source,
"[ERROR] ",text)
50 print(source,
"[FATAL] ",text)
60 for elem
in toBeReplaced:
61 if elem
in mainString:
62 mainString = mainString.replace(elem, newString)
71 textBox = ROOT.TPaveText(x1,y1,x2,y2)
72 textBox.SetFillColor(ROOT.kWhite)
73 if "median" not in var
or not self.
args[
'useFit']:
74 if self.
args[
'showMeanError']
and self.
args[
'showRMSError']:
76 elif self.
args[
'showMean']
and self.
args[
'showRMS']
and (self.
args[
'showMeanError']
or self.
args[
'showRMSError']):
81 if self.
args[
'useFitError']:
85 textBox.SetTextFont(42)
95 duplicity_check =
False 97 if self.
args[
'isDMR']:
108 for root,dirs,files
in os.walk(dataDir):
110 if dir.startswith(
"offline"): dirsToMake.append(self.
outputDir+
"/"+dir)
111 for dir
in dirsToMake:
112 if not os.path.isdir(dir):
113 os.system(
"mkdir "+dir)
115 duplicity_check =
True 117 self.
__log__(
"e",
"No input directory found! No DATA or MC present.")
121 self.
__log__(
"w",
"Duplicated file names found. Plots will be overwritten.")
131 if not os.path.isfile(datafile):
134 if not os.path.isfile(mcfile):
144 self.
__log__(
"f",
"Results file NOT found! No DATA or MC present.")
152 objDicts = {
'DATA' : [],
'MC' : []}
156 if not os.path.isfile(datafile):
continue 157 fInput = ROOT.TFile.Open(datafile,
'READ')
158 keyList = ROOT.gDirectory.GetListOfKeys()
159 _id = [ id
for id
in datafile.split(
"/")
if "offline_" in id ]
169 if "TH1" in obj.ClassName():
170 objList.append(obj.Clone())
171 objName = obj.GetName()
174 for tag
in [
"layer",
"disc",
"plus",
"minus"]:
175 if tag
in objName: skipHist =
True 176 if skipHist:
continue 178 if objName[-1] !=
"y":
179 generalObjName = self.
_replaceMulti(objName, [objName.split(
"_")[0]+
"_",
"_"+objName.split(
"_")[-1]],
"")
180 if len(self.
args[
'objects']) == 0:
181 if generalObjName
not in _objNameList:
182 _objNameList.append(generalObjName)
184 if generalObjName
not in self.
args[
'objects']:
185 self.
__log__(
"w",
"Object \""+generalObjName+
"\" found but ignored for plotting!")
186 objAreIgnored.append(generalObjName)
188 if generalObjName
not in _objNameList:
189 _objNameList.append(generalObjName)
190 self.
objNameList = [ genObjName
for genObjName
in _objNameList ]
194 objDict[objName] = []
196 if objName
in obj.GetName():
199 if obj.GetName()[-1] ==
"y":
200 segment = obj.GetName().
split(
"_")[-2]
201 var = obj.GetName().
split(
"_")[0]+
"Y" 203 segment = obj.GetName().
split(
"_")[-1]
204 var = obj.GetName().
split(
"_")[0]+
"X" 206 objDict[objName].
append({
'hist' : obj,
213 objDicts[
'DATA'].
append(objDict)
216 if len(self.
args[
'objects']) != 0:
219 order.append(self.
args[
'objects'].
index(genObjName))
224 self.
__log__(
"e",
"Data object names (if specified) must correspond to names in given input file!")
228 self.
__log__(
"i",
"Object \""+genObjName+
"\" found for plotting.")
232 fInputMC = ROOT.TFile.Open(mcFile,
'READ')
233 keyListMC = ROOT.gDirectory.GetListOfKeys()
238 for key
in keyListMC:
240 if "TH1" in obj.ClassName():
241 objName = obj.GetName()
242 objListMC.append(obj.Clone(objName))
245 for tag
in [
"layer",
"disc",
"plus",
"minus"]:
246 if tag
in objName: skipHist =
True 247 if skipHist:
continue 249 if objName[-1] !=
"y":
250 generalObjName = self.
_replaceMulti(objName, [objName.split(
"_")[0]+
"_",
"_"+objName.split(
"_")[-1]],
"")
251 if len(self.
args[
'objects']) == 0:
255 if generalObjName
not in self.
args[
'objects']:
256 self.
__log__(
"w",
"Object \""+generalObjName+
"\" found but ignored for plotting!")
264 objDictMC[generalObjName] = []
265 for obj
in objListMC:
266 if generalObjName
in obj.GetName():
269 if obj.GetName()[-1] ==
"y":
270 segment = obj.GetName().
split(
"_")[-2]
271 var = obj.GetName().
split(
"_")[0]+
"Y" 273 segment = obj.GetName().
split(
"_")[-1]
274 var = obj.GetName().
split(
"_")[0]+
"X" 276 objDictMC[generalObjName].
append({
'hist' : obj,
282 objDicts[
'MC'].
append(objDictMC)
285 self.
__log__(
"e",
"MC object names (if specified) must correspond to names in given input file!")
289 self.
__log__(
"i",
"Object \""+genObjName+
"\" found for plotting.")
303 fInput = ROOT.TFile.Open(datafile,
'READ')
304 keyList = ROOT.gDirectory.GetListOfKeys()
310 if "TH1" in obj.ClassName():
311 objList.append(obj.Clone())
312 objName = obj.GetName()
315 for tag
in [
"layer",
"disc",
"plus",
"minus"]:
316 if tag
in objName: skipHist =
True 317 if skipHist:
continue 319 if objName[-1] !=
"y":
320 generalObjName = self.
_replaceMulti(objName, [objName.split(
"_")[0]+
"_",
"_"+objName.split(
"_")[-1]],
"")
321 if len(self.
args[
'objects']) == 0:
322 if generalObjName
not in _objNameList:
323 _objNameList.append(generalObjName)
325 if generalObjName
not in self.
args[
'objects']:
326 self.
__log__(
"w",
"Object \""+generalObjName+
"\" found but ignored for plotting!")
327 objAreIgnored.append(generalObjName)
329 if generalObjName
not in _objNameList:
330 _objNameList.append(generalObjName)
331 duplicates = [ genObjName
for genObjName
in _objNameList
if genObjName
in self.
objNameList ]
332 for dup
in duplicates:
333 self.
__log__(
"e",
"Duplicated object "+
str(dup)+
" was found! Please rename this object in your input file!")
338 for objName
in _objNameList:
339 if objName
in objAreIgnored:
continue 340 objDict[objName] = []
342 if objName
in obj.GetName():
345 if obj.GetName()[-1] ==
"y":
346 segment = obj.GetName().
split(
"_")[-2]
347 var = obj.GetName().
split(
"_")[0]+
"Y" 349 segment = obj.GetName().
split(
"_")[-1]
350 var = obj.GetName().
split(
"_")[0]+
"X" 352 objDict[objName].
append({
'hist' : obj,
361 if len(self.args['objects']) != 0: 363 for genObjName in self.objNameList: 364 order.append(self.args['objects'].index(genObjName)) 365 orderedList = [self.objNameList[i] for i in order] 366 self.objNameList = orderedList 370 self.
__log__(
"e",
"Data object names (if specified) must correspond to names in given input file!")
374 self.
__log__(
"i",
"Object \""+genObjName+
"\" found for plotting.")
378 fInputMC = ROOT.TFile.Open(MCobject,
'READ')
379 keyListMC = ROOT.gDirectory.GetListOfKeys()
385 for key
in keyListMC:
387 if "TH1" in obj.ClassName():
388 objName = obj.GetName()
389 objListMC.append(obj.Clone(objName))
392 for tag
in [
"layer",
"disc",
"plus",
"minus"]:
393 if tag
in objName: skipHist =
True 394 if skipHist:
continue 396 if objName[-1] !=
"y":
397 generalObjName = self.
_replaceMulti(objName, [objName.split(
"_")[0]+
"_",
"_"+objName.split(
"_")[-1]],
"")
398 if len(self.
args[
'objects']) == 0:
399 if generalObjName
not in _objNameList:
400 _objNameList.append(generalObjName)
402 if generalObjName
not in self.
args[
'objects']:
403 self.
__log__(
"w",
"Object \""+generalObjName+
"\" found but ignored for plotting!")
404 objAreIgnored.append(generalObjName)
406 if generalObjName
not in _objNameList:
407 _objNameList.append(generalObjName)
408 duplicates = [ genObjName
for genObjName
in _objNameList
if genObjName
in self.
objNameListMC ]
409 for dup
in duplicates:
410 self.
__log__(
"e",
"Duplicated object "+
str(dup)+
" was found! Please rename this object in your input file!")
415 for objName
in _objNameList:
416 if objName
in objAreIgnored:
continue 417 objDict[objName] = []
418 for obj
in objListMC:
419 if objName
in obj.GetName():
422 if obj.GetName()[-1] ==
"y":
423 segment = obj.GetName().
split(
"_")[-2]
424 var = obj.GetName().
split(
"_")[0]+
"Y" 426 segment = obj.GetName().
split(
"_")[-1]
427 var = obj.GetName().
split(
"_")[0]+
"X" 429 objDict[objName].
append({
'hist' : obj,
437 self.
__log__(
"e",
"MC object names (if specified) must correspond to names in given input file!")
441 self.
__log__(
"i",
"Object \""+genObjName+
"\" found for plotting.")
445 if len(self.
args[
'objects']) != 0:
448 order.append(self.
args[
'objects'].
index(genObjName))
460 if not hist
or hist.GetEntries() < 20:
return 0
461 self.
__log__(
"i",
"Fitting histogram: "+hist.GetName())
464 mean = hist.GetMean(1)*xScale
465 sigma = hist.GetRMS(1)*xScale
466 funcName =
"gaussian_"+hist.GetName()
467 func = ROOT.TF1(funcName,
"gaus",mean - 2.*sigma,mean + 2.*sigma)
468 func.SetLineColor(ROOT.kMagenta)
472 if int(hist.Fit(func,
"QNR")) == 0:
473 mean = func.GetParameter(1)
474 sigma = func.GetParameter(2)
475 func.SetRange(mean - 3.*sigma, mean + 3.*sigma)
479 if int(hist.Fit(func,
"Q0ILR")) == 0:
503 if not self.
args[
'useFit']
or "median" not in var:
504 if self.
args[
'showMean']
and self.
args[
'showRMS']:
506 if self.
args[
'showMean']:
508 if hist.GetMean(1) >= 0.:
509 statLabel += (
" "+form).
format(Decimal(
str(hist.GetMean(1)*muScale)))
511 statLabel += form.format(Decimal(
str(hist.GetMean(1)*muScale)))
512 if self.
args[
'showMeanError']:
514 statLabel += formScie.format(Decimal(
str(hist.GetMeanError(1)*muScale)))
515 statLabel += delimeter
516 if self.
args[
'showRMS']:
518 statLabel += (
" "+form).
format(Decimal(
str(hist.GetRMS(1)*muScale)))
519 if self.
args[
'showRMSError']:
521 statLabel += form.format(Decimal(
str(hist.GetRMSError(1)*muScale)))
525 if not isinstance(fitResults, int):
527 meanFit = fitResults.GetParameter(1)
528 meanFitError = fitResults.GetParError(1)
529 sigmaFit = fitResults.GetParameter(2)
530 sigmaFitError = fitResults.GetParError(2)
533 statLabel += (
" "+formScie).
format(Decimal(
str(meanFit)))
534 if self.
args[
'useFitError']:
536 statLabel += form.format(Decimal(
str(meanFitError)))
538 statLabel += formScie.format(Decimal(
str(meanFit)))
539 if self.
args[
'useFitError']:
541 statLabel += form.format(Decimal(
str(meanFitError)))
542 statLabel += delimeter
543 statLabel +=
"#sigma=" 544 statLabel += (
" "+form).
format(Decimal(
str(sigmaFit)))
545 if self.
args[
'useFitError']:
547 statLabel += form.format(Decimal(
str(sigmaFitError)))
558 varsX = {
'medianX' :
"median(x\'_{pred}-x\'_{hit})[#mum]",
559 'medianY' :
"median(y\'_{pred}-y\'_{hit})[#mum]",
560 'DrmsNRX' :
"RMS((x\'_{pred}-x\'_{hit})/#sigma)",
561 'DrmsNRY' :
"RMS((y\'_{pred}-y\'_{hit})/#sigma)" 564 varsY = {
'medianX' :
"luminosity-weighted number of modules",
565 'medianY' :
"luminosity-weighted number of modules",
566 'DrmsNRX' :
"luminosity-weighted number of modules",
567 'DrmsNRY' :
"luminosity-weighted number of modules" 569 limitX = {
'min' : 10000,
'max' : 10000}
572 for objName,objList
in objects.items():
576 obj[
'hist'].GetXaxis().SetTitle(varsX[obj[
'var']])
577 obj[
'hist'].GetXaxis().SetTitleFont(obj[
'hist'].GetYaxis().GetTitleFont())
578 obj[
'hist'].GetYaxis().SetTitleSize(0.038)
579 obj[
'hist'].GetYaxis().SetTitleOffset(1.7)
580 if "median" in obj[
'var']:
581 scaleFactor =
"/"+
'{:.2f}'.
format((obj[
'hist'].GetXaxis().GetXmax()*limitX[
'max']-obj[
'hist'].GetXaxis().GetXmin()*limitX[
'min'])/obj[
'hist'].GetXaxis().GetNbins())+
" #mum" 582 minX = obj[
'hist'].GetXaxis().GetXmin()
583 maxX = obj[
'hist'].GetXaxis().GetXmax()
584 obj[
'hist'].GetXaxis().SetLimits(minX*limitX[
'min'],maxX*limitX[
'max'])
585 obj[
'hist'].GetYaxis().SetTitle(varsY[obj[
'var']]+scaleFactor)
588 obj[
'hist'].SetTitle(
"")
591 if len(self.
args[
'objects']) != 0:
592 if obj[
'type'] ==
"MC":
593 obj[
'hist'].SetLineColor(self.
args[
'colors'][self.
args[
'objects'].
index(objName)])
594 obj[
'hist'].SetLineStyle(self.
args[
'styles'][self.
args[
'objects'].
index(objName)])
595 obj[
'hist'].SetLineWidth(3)
596 elif obj[
'type'] ==
"DATA":
597 obj[
'hist'].SetMarkerColor(self.
args[
'colors'][self.
args[
'objects'].
index(objName)])
598 obj[
'hist'].SetLineColor(self.
args[
'colors'][self.
args[
'objects'].
index(objName)])
599 obj[
'hist'].SetMarkerStyle(self.
args[
'styles'][self.
args[
'objects'].
index(objName)])
600 obj[
'hist'].SetMarkerSize(1.5)
603 tStyle = ROOT.TStyle(
"StyleCMS",
"Style CMS")
609 tStyle.SetCanvasBorderMode(0)
610 tStyle.SetCanvasColor(ROOT.kWhite)
611 tStyle.SetCanvasDefH(800)
612 tStyle.SetCanvasDefW(800)
613 tStyle.SetCanvasDefX(0)
614 tStyle.SetCanvasDefY(0)
617 tStyle.SetFrameBorderMode(0)
618 tStyle.SetFrameBorderSize(10)
619 tStyle.SetFrameFillColor(ROOT.kBlack)
620 tStyle.SetFrameFillStyle(0)
621 tStyle.SetFrameLineColor(ROOT.kBlack)
622 tStyle.SetFrameLineStyle(0)
623 tStyle.SetFrameLineWidth(1)
624 tStyle.SetLineWidth(2)
627 tStyle.SetPadBorderMode(0)
628 tStyle.SetPadColor(ROOT.kWhite)
629 tStyle.SetPadGridX(
False)
630 tStyle.SetPadGridY(
False)
631 tStyle.SetGridColor(0)
632 tStyle.SetGridStyle(3)
633 tStyle.SetGridWidth(1)
636 tStyle.SetPadTopMargin(0.08)
637 tStyle.SetPadBottomMargin(0.13)
638 tStyle.SetPadLeftMargin(0.16)
639 tStyle.SetPadRightMargin(0.05)
642 tStyle.SetHistLineStyle(0)
643 tStyle.SetHistLineWidth(3)
644 tStyle.SetMarkerSize(0.8)
645 tStyle.SetEndErrorSize(4)
646 tStyle.SetHatchesLineWidth(1)
652 tStyle.SetAxisColor(1,
"XYZ")
653 tStyle.SetTickLength(0.03,
"XYZ")
654 tStyle.SetNdivisions(510,
"XYZ")
655 tStyle.SetPadTickX(1)
656 tStyle.SetPadTickY(1)
657 tStyle.SetStripDecimals(ROOT.kFALSE)
660 tStyle.SetTitleColor(1,
"XYZ")
661 tStyle.SetLabelColor(1,
"XYZ")
662 tStyle.SetLabelFont(42,
"XYZ")
663 tStyle.SetLabelOffset(0.007,
"XYZ")
664 tStyle.SetLabelSize(0.04,
"XYZ")
665 tStyle.SetTitleFont(42,
"XYZ")
666 tStyle.SetTitleSize(0.047,
"XYZ")
667 tStyle.SetTitleXOffset(1.2)
668 tStyle.SetTitleYOffset(1.7)
671 tStyle.SetLegendBorderSize(0)
673 tStyle.SetLegendFont(42)
685 leftMargin = canvas.GetLeftMargin()
686 rightMargin = canvas.GetRightMargin()
687 topMargin = canvas.GetTopMargin()
692 CMSextraOffset = 0.10
693 CMStext = ROOT.TLatex()
694 CMSextra = ROOT.TLatex()
699 CMStext.SetTextAngle(0)
700 CMSextra.SetTextAngle(0)
702 CMStext.SetTextColor(ROOT.kBlack)
703 CMSextra.SetTextColor(ROOT.kBlack)
705 CMStext.SetTextFont(61)
706 CMSextra.SetTextFont(52)
708 CMStext.SetTextAlign(11)
709 CMStext.SetTextSize(0.045)
710 CMSextra.SetTextSize(0.035)
712 CMStext.DrawLatex(leftMargin,1.-topMargin+0.01,CMSlabel)
713 CMSextra.DrawLatex(leftMargin+CMSextraOffset,1-topMargin+0.01,CMSextraLabel)
716 eraText = ROOT.TLatex()
718 eraText.SetTextAngle(0)
719 eraText.SetTextColor(ROOT.kBlack)
720 eraText.SetTextFont(42)
721 eraText.SetTextAlign(33)
722 eraText.SetTextSize(0.035)
723 eraText.DrawLatex(1.-rightMargin,1.-topMargin+0.035,eraLabel)
734 for dirpath,dirs,files
in os.walk(self.
cwd):
735 if dirpath != self.
cwd:
continue 737 if ".png" in n_file
or ".pdf" in n_file
or ".eps" in n_file:
738 self.
__log__(
"i",
"File "+n_file+
" was created.")
739 os.system(
"mv "+n_file+
" "+self.
outputDir)
749 os.system(
"mv "+datafile+
" "+self.
outputDir)
751 os.system(
"mv "+mcfile+
" "+self.
outputDir)
752 for dirpath,dirs,files
in os.walk(self.
cwd):
753 if dirpath != self.
cwd:
continue 755 if ".png" in n_file
or ".pdf" in n_file
or ".eps" in n_file:
756 self.
__log__(
"i",
"File "+n_file+
" was created.")
757 os.system(
"mv "+n_file+
" "+self.
outputDir)
765 for dirpath,dirs,files
in os.walk(self.
outputDir):
767 if ".png" in n_file
or ".pdf" in n_file
or ".eps" in n_file:
768 self.
__log__(
"i",
"File "+n_file+
" was created.")
776 if os.path.isfile(
str(filename)):
777 self.
__log__(
"i",
"DATA file: "+
str(filename)+
" was added for plotting.")
789 if os.path.isdir(dataDir):
790 self.
__log__(
"i",
"DATA dir: "+dataDir+
" was added for plotting.")
793 self.
__log__(
"w",
"DATA dir: "+dataDir+
" NOT found.")
797 if self.
args[
'isDMR']:
799 for root,dirs,files
in os.walk(dataDir):
801 if dir.startswith(
"offline"):
802 self.
dataFiles.
append(dataDir+
"/"+dir+
"/ExtendedOfflineValidation_Images/OfflineValidationSummary.root")
808 if os.path.isdir(mcDir):
809 self.
__log__(
"i",
"MC dir: "+mcDir+
" was added for plotting.")
811 for dirpath,dirs,files
in os.walk(mcDir):
814 self.
__log__(
"i",
"MC file: "+
str(file)+
" was added for plotting.")
818 self.
__log__(
"w",
"No MC file found in "+
str(mcDir)+
".")
820 self.
__log__(
"w",
"MC dir: "+mcDir+
" NOT found.")
826 if os.path.isfile(
str(filename)):
827 self.
__log__(
"i",
"MC file: "+
str(filename)+
" was added for plotting.")
845 objectsData = objects[
'DATA']
846 objectsMC = objects[
'MC']
849 for objDict
in objectsData:
851 for objDict
in objectsMC:
855 ROOT.gROOT.SetBatch(
True)
856 ROOT.gROOT.ProcessLine(
"gErrorIgnoreLevel = 1001;")
858 for objDict
in objectsData:
860 for var
in self.
varsX:
862 for key
in objDict.keys():
863 for _obj
in objDict[key]:
865 canvas = ROOT.TCanvas(id+
"_"+var+
"_"+segment)
869 segmentText = {
'text' : segment,
'xmin' : 0.0,
'xmax' : 0.0}
870 statText = {
'xmin' : 0.0,
'xmax' : 0.0}
872 segmentText[
'xmin'] = 2.5
873 segmentText[
'xmax'] = 3.5
874 statText[
'xmin'] = 0.20
875 statText[
'xmax'] = 0.85
877 segmentText[
'xmin'] = 1.4
878 segmentText[
'xmax'] = 1.6
879 statText[
'xmin'] = 0.65
880 statText[
'xmax'] = 0.95
887 for obj
in objDict[objName]:
888 if obj[
'var'] == var
and obj[
'segment'] == segment:
889 if obj[
'hist'].GetBinContent(obj[
'hist'].GetMaximumBin()) >= maxY:
890 maxY = obj[
'hist'].GetBinContent(obj[
'hist'].GetMaximumBin())
892 legendLabel = objName.replace(
"_",
" ")
893 if len(self.
args[
'labels']) != 0:
894 legendLabel = self.
args[
'labels'][self.
args[
'objects'].
index(objName)]
900 for objDictMC
in objectsMC:
902 for objMC
in objDictMC[objNameMC]:
903 if objMC[
'var'] == var
and objMC[
'segment'] == segment:
904 if objMC[
'hist'].GetBinContent(objMC[
'hist'].GetMaximumBin()) >= maxY:
905 maxY = objMC[
'hist'].GetBinContent(objMC[
'hist'].GetMaximumBin())
906 legendLabelMC = objNameMC.replace(
"_",
" ")
907 if len(self.
args[
'labels']) != 0:
908 legendLabelMC = self.
args[
'labels'][self.
args[
'objects'].
index(objNameMC)]
909 objMC[
'hist'].SetDirectory(0)
910 histsMC.append(objMC[
'hist'])
911 labelsMC.append(legendLabelMC)
912 statsMC.append(self.
__getStat__(objMC[
'hist'],var))
913 objGroup.append({
'hist' : obj[
'hist'],
915 'labelsMC': labelsMC,
917 'label' : legendLabel,
922 datasetType =
"singlemuon" 928 leg = ROOT.TLegend(0.08,legMinY,0.45,0.88)
929 leg.SetNColumns(nColumns)
931 maxX = objGroup[0][
'hist'].GetXaxis().GetXmax()
933 for igroup,group
in enumerate(objGroup):
934 group[
'hist'].GetYaxis().SetRangeUser(0,self.
legendOffset*maxY)
935 leg.AddEntry(group[
'hist'],group[
'label'],
"l")
936 stat.AddText(group[
'stat'])
937 group[
'hist'].Draw(
"HISTSAME")
939 if igroup == len(objGroup)-1:
940 for ihist,histmc
in enumerate(group[
'histsMC']):
941 leg.AddEntry(histmc,group[
'labelsMC'][ihist],
"l")
942 stat.AddText(group[
'statsMC'][ihist])
943 histmc.Draw(
"HISTSAME")
945 seg.DrawLatex(segmentText[
'xmin'],self.
segmentTextOffset[
'ymin']*maxY,segmentText[
'text'])
948 canvas.SaveAs(self.
outputDir+
"/offline_"+datasetType+
"_"+
str(id)+
"/"+var+
"_"+segment+
".png")
949 canvas.SaveAs(self.
outputDir+
"/offline_"+datasetType+
"_"+
str(id)+
"/"+var+
"_"+segment+
".pdf")
950 self.
__log__(
"i",
"Saving "+self.
outputDir+
"/offline_"+datasetType+
"_"+
str(id)+
"/"+var+
"_"+segment)
971 ROOT.gROOT.SetBatch(
True)
972 ROOT.gROOT.ProcessLine(
"gErrorIgnoreLevel = 1001;")
975 for var
in self.
varsX:
976 canvas = ROOT.TCanvas(var+
"_"+segment)
980 segmentText = {
'text' : segment,
'xmin' : 0.0,
'xmax' : 0.0}
981 statText = {
'xmin' : 0.0,
'xmax' : 0.0}
983 segmentText[
'xmin'] = 2.5
984 segmentText[
'xmax'] = 3.5
985 statText[
'xmin'] = 0.27
986 statText[
'xmax'] = 0.92
988 segmentText[
'xmin'] = 1.4
989 segmentText[
'xmax'] = 1.6
990 statText[
'xmin'] = 0.75
991 statText[
'xmax'] = 0.95
998 for obj
in objects[objName]:
999 if obj[
'var'] == var
and obj[
'segment'] == segment:
1000 if obj[
'hist'].GetBinContent(obj[
'hist'].GetMaximumBin()) >= maxY:
1001 maxY = obj[
'hist'].GetBinContent(obj[
'hist'].GetMaximumBin())
1003 legendLabel = objName.replace(
"_",
" ")
1004 if len(self.
args[
'labels']) != 0:
1005 legendLabel = self.
args[
'labels'][self.
args[
'objects'].
index(objName)]
1008 if obj[
'type'] ==
"MC":
1009 drawStyle =
"HIST SAME" 1011 if obj[
'type'] ==
"DATA":
1012 drawStyle +=
"P HIST SAME" 1014 objGroup.append({
'hist' : obj[
'hist'],
1015 'label' : legendLabel,
1017 'drawStyle' : drawStyle,
1018 'legStyle' : legStyle
1028 leg = ROOT.TLegend(0.20,legMinY,0.50,0.88)
1029 leg.SetNColumns(nColumns)
1031 maxX = objGroup[0][
'hist'].GetXaxis().GetXmax()
1033 for group
in objGroup:
1034 group[
'hist'].GetYaxis().SetRangeUser(0,self.
legendOffset*maxY)
1035 leg.AddEntry(group[
'hist'],group[
'label'],group[
'legStyle'])
1036 stat.AddText(group[
'stat'])
1037 group[
'hist'].Draw(group[
'drawStyle'])
1039 seg.DrawLatex(segmentText[
'xmin'],self.
segmentTextOffset[
'ymin']*maxY,segmentText[
'text'])
1042 canvas.Print(self.
outputDir+
"/"+var+
"_"+segment+
".png")
1043 canvas.Print(self.
outputDir+
"/"+var+
"_"+segment+
".pdf")
def addDirDATA(self, dataDir)
def __createSingleArchitecture__(self)
def __log__(self, log_type="", text="")
objNameList
Open each file separately and get object groups.
def __fitGauss__(self, hist)
def replace(string, replacements)
def __beautify__(self, canvas, CMSextraLabel, eraLabel)
varsX
Set histogram labels, axis titles, line color, stat bar, etc.
def addDATA(self, filename)
def addMC(self, filename)
def addDirMC(self, mcDir)
def __defineSingleObjects__(self)
def __createArchitecture__(self)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def _replaceMulti(self, mainString, toBeReplaced, newString)
def __setTHStyle__(self, objects)
def __cleanSingle__(self)
def __getStat__(self, hist, var)
def split(sequence, size)
def __defineObjects__(self)
def _styledTPaveText(self, x1, y1, x2, y2, var)