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)
59 middleString =
"_".
join(fullString.split(
"_")[1:])
60 if middleString.endswith(
"_y"): middleString =
"_".
join(middleString.split(
"_")[:-1])
61 middleString =
"_".
join(middleString.split(
"_")[:-1])
71 for elem
in toBeReplaced:
72 if elem
in mainString:
73 mainString = mainString.replace(elem, newString)
82 textBox = ROOT.TPaveText(x1,y1,x2,y2)
83 textBox.SetFillColor(ROOT.kWhite)
84 if "median" not in var
or not self.
args[
'useFit']:
85 if self.
args[
'showMeanError']
and self.
args[
'showRMSError']:
87 elif self.
args[
'showMean']
and self.
args[
'showRMS']
and (self.
args[
'showMeanError']
or self.
args[
'showRMSError']):
92 if self.
args[
'useFitError']:
96 textBox.SetTextFont(42)
106 duplicity_check =
False 108 if self.
args[
'isDMR']:
119 for root,dirs,files
in os.walk(dataDir):
121 if dir.startswith(
"offline"): dirsToMake.append(self.
outputDir+
"/"+dir)
122 for dir
in dirsToMake:
123 if not os.path.isdir(dir):
124 os.system(
"mkdir "+dir)
126 duplicity_check =
True 128 self.
__log__(
"e",
"No input directory found! No DATA or MC present.")
132 self.
__log__(
"w",
"Duplicated file names found. Plots will be overwritten.")
142 if not os.path.isfile(datafile):
145 if not os.path.isfile(mcfile):
155 self.
__log__(
"f",
"Results file NOT found! No DATA or MC present.")
163 objDicts = {
'DATA' : [],
'MC' : []}
167 if not os.path.isfile(datafile):
continue 168 fInput = ROOT.TFile.Open(datafile,
'READ')
169 keyList = ROOT.gDirectory.GetListOfKeys()
170 _id = [ id
for id
in datafile.split(
"/")
if "offline_" in id ]
180 if "TH1" in obj.ClassName():
181 objList.append(obj.Clone())
182 objName = obj.GetName()
185 for tag
in [
"layer",
"disc",
"plus",
"minus"]:
186 if tag
in objName: skipHist =
True 187 if skipHist:
continue 189 if objName[-1] !=
"y":
190 generalObjName = self.
_replaceMulti(objName, [objName.split(
"_")[0]+
"_",
"_"+objName.split(
"_")[-1]],
"")
191 if len(self.
args[
'objects']) == 0:
192 if generalObjName
not in _objNameList:
193 _objNameList.append(generalObjName)
195 if generalObjName
not in self.
args[
'objects']:
196 self.
__log__(
"w",
"Object \""+generalObjName+
"\" found but ignored for plotting!")
197 objAreIgnored.append(generalObjName)
199 if generalObjName
not in _objNameList:
200 _objNameList.append(generalObjName)
201 self.
objNameList = [ genObjName
for genObjName
in _objNameList ]
205 objDict[objName] = []
207 if objName
in obj.GetName():
210 if obj.GetName()[-1] ==
"y":
211 segment = obj.GetName().
split(
"_")[-2]
212 var = obj.GetName().
split(
"_")[0]+
"Y" 214 segment = obj.GetName().
split(
"_")[-1]
215 var = obj.GetName().
split(
"_")[0]+
"X" 217 objDict[objName].
append({
'hist' : obj,
224 objDicts[
'DATA'].
append(objDict)
227 if len(self.
args[
'objects']) != 0:
230 order.append(self.
args[
'objects'].
index(genObjName))
235 self.
__log__(
"e",
"Data object names (if specified) must correspond to names in given input file!")
239 self.
__log__(
"i",
"Object \""+genObjName+
"\" found for plotting.")
243 fInputMC = ROOT.TFile.Open(mcFile,
'READ')
244 keyListMC = ROOT.gDirectory.GetListOfKeys()
249 for key
in keyListMC:
251 if "TH1" in obj.ClassName():
252 objName = obj.GetName()
253 objListMC.append(obj.Clone(objName))
256 for tag
in [
"layer",
"disc",
"plus",
"minus"]:
257 if tag
in objName: skipHist =
True 258 if skipHist:
continue 260 if objName[-1] !=
"y":
261 generalObjName = self.
_replaceMulti(objName, [objName.split(
"_")[0]+
"_",
"_"+objName.split(
"_")[-1]],
"")
262 if len(self.
args[
'objects']) == 0:
266 if generalObjName
not in self.
args[
'objects']:
267 self.
__log__(
"w",
"Object \""+generalObjName+
"\" found but ignored for plotting!")
275 objDictMC[generalObjName] = []
276 for obj
in objListMC:
277 if generalObjName
in obj.GetName():
280 if obj.GetName()[-1] ==
"y":
281 segment = obj.GetName().
split(
"_")[-2]
282 var = obj.GetName().
split(
"_")[0]+
"Y" 284 segment = obj.GetName().
split(
"_")[-1]
285 var = obj.GetName().
split(
"_")[0]+
"X" 287 objDictMC[generalObjName].
append({
'hist' : obj,
293 objDicts[
'MC'].
append(objDictMC)
296 self.
__log__(
"e",
"MC object names (if specified) must correspond to names in given input file!")
300 self.
__log__(
"i",
"Object \""+genObjName+
"\" found for plotting.")
314 fInput = ROOT.TFile.Open(datafile,
'READ')
315 keyList = ROOT.gDirectory.GetListOfKeys()
321 if "TH1" in obj.ClassName():
322 objList.append(obj.Clone())
323 objName = obj.GetName()
326 for tag
in [
"layer",
"disc",
"plus",
"minus"]:
327 if tag
in objName: skipHist =
True 328 if skipHist:
continue 330 if objName[-1] !=
"y":
331 generalObjName = self.
_replaceMulti(objName, [objName.split(
"_")[0]+
"_",
"_"+objName.split(
"_")[-1]],
"")
332 if len(self.
args[
'objects']) == 0:
333 if generalObjName
not in _objNameList:
334 _objNameList.append(generalObjName)
336 if generalObjName
not in self.
args[
'objects']:
337 self.
__log__(
"w",
"Object \""+generalObjName+
"\" found but ignored for plotting!")
338 objAreIgnored.append(generalObjName)
340 if generalObjName
not in _objNameList:
341 _objNameList.append(generalObjName)
342 duplicates = [ genObjName
for genObjName
in _objNameList
if genObjName
in self.
objNameList ]
343 for dup
in duplicates:
344 self.
__log__(
"e",
"Duplicated object "+
str(dup)+
" was found! Please rename this object in your input file!")
349 for objName
in _objNameList:
350 if objName
in objAreIgnored:
continue 351 objDict[objName] = []
356 if obj.GetName()[-1] ==
"y":
357 segment = obj.GetName().
split(
"_")[-2]
358 var = obj.GetName().
split(
"_")[0]+
"Y" 360 segment = obj.GetName().
split(
"_")[-1]
361 var = obj.GetName().
split(
"_")[0]+
"X" 363 objDict[objName].
append({
'hist' : obj,
372 if len(self.args['objects']) != 0: 374 for genObjName in self.objNameList: 375 order.append(self.args['objects'].index(genObjName)) 376 orderedList = [self.objNameList[i] for i in order] 377 self.objNameList = orderedList 381 self.
__log__(
"e",
"Data object names (if specified) must correspond to names in given input file!")
385 self.
__log__(
"i",
"Object \""+genObjName+
"\" found for plotting.")
389 fInputMC = ROOT.TFile.Open(MCobject,
'READ')
390 keyListMC = ROOT.gDirectory.GetListOfKeys()
396 for key
in keyListMC:
398 if "TH1" in obj.ClassName():
399 objName = obj.GetName()
400 objListMC.append(obj.Clone(objName))
403 for tag
in [
"layer",
"disc",
"plus",
"minus"]:
404 if tag
in objName: skipHist =
True 405 if skipHist:
continue 407 if objName[-1] !=
"y":
408 generalObjName = self.
_replaceMulti(objName, [objName.split(
"_")[0]+
"_",
"_"+objName.split(
"_")[-1]],
"")
409 if len(self.
args[
'objects']) == 0:
410 if generalObjName
not in _objNameList:
411 _objNameList.append(generalObjName)
413 if generalObjName
not in self.
args[
'objects']:
414 self.
__log__(
"w",
"Object \""+generalObjName+
"\" found but ignored for plotting!")
415 objAreIgnored.append(generalObjName)
417 if generalObjName
not in _objNameList:
418 _objNameList.append(generalObjName)
419 duplicates = [ genObjName
for genObjName
in _objNameList
if genObjName
in self.
objNameListMC ]
420 for dup
in duplicates:
421 self.
__log__(
"e",
"Duplicated object "+
str(dup)+
" was found! Please rename this object in your input file!")
426 for objName
in _objNameList:
427 if objName
in objAreIgnored:
continue 428 objDict[objName] = []
429 for obj
in objListMC:
430 if objName
in obj.GetName():
433 if obj.GetName()[-1] ==
"y":
434 segment = obj.GetName().
split(
"_")[-2]
435 var = obj.GetName().
split(
"_")[0]+
"Y" 437 segment = obj.GetName().
split(
"_")[-1]
438 var = obj.GetName().
split(
"_")[0]+
"X" 440 objDict[objName].
append({
'hist' : obj,
448 self.
__log__(
"e",
"MC object names (if specified) must correspond to names in given input file!")
452 self.
__log__(
"i",
"Object \""+genObjName+
"\" found for plotting.")
456 if len(self.
args[
'objects']) != 0:
459 order.append(self.
args[
'objects'].
index(genObjName))
471 if not hist
or hist.GetEntries() < 20:
return 0
472 self.
__log__(
"i",
"Fitting histogram: "+hist.GetName())
475 mean = hist.GetMean(1)*xScale
476 sigma = hist.GetRMS(1)*xScale
477 funcName =
"gaussian_"+hist.GetName()
478 func = ROOT.TF1(funcName,
"gaus",mean - 2.*sigma,mean + 2.*sigma)
479 func.SetLineColor(ROOT.kMagenta)
483 if int(hist.Fit(func,
"QNR")) == 0:
484 mean = func.GetParameter(1)
485 sigma = func.GetParameter(2)
486 func.SetRange(mean - 3.*sigma, mean + 3.*sigma)
490 if int(hist.Fit(func,
"Q0ILR")) == 0:
514 if not self.
args[
'useFit']
or "median" not in var:
515 if self.
args[
'showMean']
and self.
args[
'showRMS']:
517 if self.
args[
'showMean']:
519 if hist.GetMean(1) >= 0.:
520 statLabel += (
" "+form).
format(Decimal(
str(hist.GetMean(1)*muScale)))
522 statLabel += form.format(Decimal(
str(hist.GetMean(1)*muScale)))
523 if self.
args[
'showMeanError']:
525 statLabel += formScie.format(Decimal(
str(hist.GetMeanError(1)*muScale)))
526 statLabel += delimeter
527 if self.
args[
'showRMS']:
529 statLabel += (
" "+form).
format(Decimal(
str(hist.GetRMS(1)*muScale)))
530 if self.
args[
'showRMSError']:
532 statLabel += form.format(Decimal(
str(hist.GetRMSError(1)*muScale)))
536 if not isinstance(fitResults, int):
538 meanFit = fitResults.GetParameter(1)
539 meanFitError = fitResults.GetParError(1)
540 sigmaFit = fitResults.GetParameter(2)
541 sigmaFitError = fitResults.GetParError(2)
544 statLabel += (
" "+formScie).
format(Decimal(
str(meanFit)))
545 if self.
args[
'useFitError']:
547 statLabel += form.format(Decimal(
str(meanFitError)))
549 statLabel += formScie.format(Decimal(
str(meanFit)))
550 if self.
args[
'useFitError']:
552 statLabel += form.format(Decimal(
str(meanFitError)))
553 statLabel += delimeter
554 statLabel +=
"#sigma=" 555 statLabel += (
" "+form).
format(Decimal(
str(sigmaFit)))
556 if self.
args[
'useFitError']:
558 statLabel += form.format(Decimal(
str(sigmaFitError)))
569 varsX = {
'medianX' :
"median(x\'_{pred}-x\'_{hit})[#mum]",
570 'medianY' :
"median(y\'_{pred}-y\'_{hit})[#mum]",
571 'DrmsNRX' :
"RMS((x\'_{pred}-x\'_{hit})/#sigma)",
572 'DrmsNRY' :
"RMS((y\'_{pred}-y\'_{hit})/#sigma)" 575 varsY = {
'medianX' :
"luminosity-weighted number of modules",
576 'medianY' :
"luminosity-weighted number of modules",
577 'DrmsNRX' :
"luminosity-weighted number of modules",
578 'DrmsNRY' :
"luminosity-weighted number of modules" 580 limitX = {
'min' : 10000,
'max' : 10000}
583 for objName,objList
in objects.items():
587 obj[
'hist'].GetXaxis().SetTitle(varsX[obj[
'var']])
588 obj[
'hist'].GetXaxis().SetTitleFont(obj[
'hist'].GetYaxis().GetTitleFont())
589 obj[
'hist'].GetYaxis().SetTitleSize(0.038)
590 obj[
'hist'].GetYaxis().SetTitleOffset(1.7)
591 if "median" in obj[
'var']:
592 scaleFactor =
"/"+
'{:.2f}'.
format((obj[
'hist'].GetXaxis().GetXmax()*limitX[
'max']-obj[
'hist'].GetXaxis().GetXmin()*limitX[
'min'])/obj[
'hist'].GetXaxis().GetNbins())+
" #mum" 593 minX = obj[
'hist'].GetXaxis().GetXmin()
594 maxX = obj[
'hist'].GetXaxis().GetXmax()
595 obj[
'hist'].GetXaxis().SetLimits(minX*limitX[
'min'],maxX*limitX[
'max'])
596 obj[
'hist'].GetYaxis().SetTitle(varsY[obj[
'var']]+scaleFactor)
599 obj[
'hist'].SetTitle(
"")
602 if len(self.
args[
'objects']) != 0:
603 if obj[
'type'] ==
"MC":
604 obj[
'hist'].SetLineColor(self.
args[
'colors'][self.
args[
'objects'].
index(objName)])
605 obj[
'hist'].SetLineStyle(self.
args[
'styles'][self.
args[
'objects'].
index(objName)])
606 obj[
'hist'].SetLineWidth(3)
607 elif obj[
'type'] ==
"DATA":
608 obj[
'hist'].SetMarkerColor(self.
args[
'colors'][self.
args[
'objects'].
index(objName)])
609 obj[
'hist'].SetLineColor(self.
args[
'colors'][self.
args[
'objects'].
index(objName)])
610 obj[
'hist'].SetLineWidth(3)
611 obj[
'hist'].SetMarkerStyle(self.
args[
'styles'][self.
args[
'objects'].
index(objName)])
612 obj[
'hist'].SetMarkerSize(1.5)
615 tStyle = ROOT.TStyle(
"StyleCMS",
"Style CMS")
621 tStyle.SetCanvasBorderMode(0)
622 tStyle.SetCanvasColor(ROOT.kWhite)
623 tStyle.SetCanvasDefH(800)
624 tStyle.SetCanvasDefW(800)
625 tStyle.SetCanvasDefX(0)
626 tStyle.SetCanvasDefY(0)
629 tStyle.SetFrameBorderMode(0)
630 tStyle.SetFrameBorderSize(10)
631 tStyle.SetFrameFillColor(ROOT.kBlack)
632 tStyle.SetFrameFillStyle(0)
633 tStyle.SetFrameLineColor(ROOT.kBlack)
634 tStyle.SetFrameLineStyle(0)
635 tStyle.SetFrameLineWidth(1)
636 tStyle.SetLineWidth(2)
639 tStyle.SetPadBorderMode(0)
640 tStyle.SetPadColor(ROOT.kWhite)
641 tStyle.SetPadGridX(
False)
642 tStyle.SetPadGridY(
False)
643 tStyle.SetGridColor(0)
644 tStyle.SetGridStyle(3)
645 tStyle.SetGridWidth(1)
648 tStyle.SetPadTopMargin(0.08)
649 tStyle.SetPadBottomMargin(0.13)
650 tStyle.SetPadLeftMargin(0.16)
651 tStyle.SetPadRightMargin(0.05)
654 tStyle.SetHistLineStyle(0)
655 tStyle.SetHistLineWidth(3)
656 tStyle.SetMarkerSize(0.8)
657 tStyle.SetEndErrorSize(4)
658 tStyle.SetHatchesLineWidth(1)
664 tStyle.SetAxisColor(1,
"XYZ")
665 tStyle.SetTickLength(0.03,
"XYZ")
666 tStyle.SetNdivisions(510,
"XYZ")
667 tStyle.SetPadTickX(1)
668 tStyle.SetPadTickY(1)
669 tStyle.SetStripDecimals(ROOT.kFALSE)
672 tStyle.SetTitleColor(1,
"XYZ")
673 tStyle.SetLabelColor(1,
"XYZ")
674 tStyle.SetLabelFont(42,
"XYZ")
675 tStyle.SetLabelOffset(0.007,
"XYZ")
676 tStyle.SetLabelSize(0.04,
"XYZ")
677 tStyle.SetTitleFont(42,
"XYZ")
678 tStyle.SetTitleSize(0.047,
"XYZ")
679 tStyle.SetTitleXOffset(1.2)
680 tStyle.SetTitleYOffset(1.7)
683 tStyle.SetLegendBorderSize(0)
685 tStyle.SetLegendFont(42)
697 leftMargin = canvas.GetLeftMargin()
698 rightMargin = canvas.GetRightMargin()
699 topMargin = canvas.GetTopMargin()
704 CMSextraOffset = 0.10
705 CMStext = ROOT.TLatex()
706 CMSextra = ROOT.TLatex()
711 CMStext.SetTextAngle(0)
712 CMSextra.SetTextAngle(0)
714 CMStext.SetTextColor(ROOT.kBlack)
715 CMSextra.SetTextColor(ROOT.kBlack)
717 CMStext.SetTextFont(61)
718 CMSextra.SetTextFont(52)
720 CMStext.SetTextAlign(11)
721 CMStext.SetTextSize(0.045)
722 CMSextra.SetTextSize(0.035)
724 CMStext.DrawLatex(leftMargin,1.-topMargin+0.01,CMSlabel)
725 CMSextra.DrawLatex(leftMargin+CMSextraOffset,1-topMargin+0.01,CMSextraLabel)
728 eraText = ROOT.TLatex()
730 eraText.SetTextAngle(0)
731 eraText.SetTextColor(ROOT.kBlack)
732 eraText.SetTextFont(42)
733 eraText.SetTextAlign(33)
734 eraText.SetTextSize(0.035)
735 eraText.DrawLatex(1.-rightMargin,1.-topMargin+0.035,eraLabel)
746 for dirpath,dirs,files
in os.walk(self.
cwd):
747 if dirpath != self.
cwd:
continue 749 if ".png" in n_file
or ".pdf" in n_file
or ".eps" in n_file:
750 self.
__log__(
"i",
"File "+n_file+
" was created.")
751 os.system(
"mv "+n_file+
" "+self.
outputDir)
761 os.system(
"mv "+datafile+
" "+self.
outputDir)
763 os.system(
"mv "+mcfile+
" "+self.
outputDir)
764 for dirpath,dirs,files
in os.walk(self.
cwd):
765 if dirpath != self.
cwd:
continue 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.")
769 os.system(
"mv "+n_file+
" "+self.
outputDir)
777 for dirpath,dirs,files
in os.walk(self.
outputDir):
779 if ".png" in n_file
or ".pdf" in n_file
or ".eps" in n_file:
780 self.
__log__(
"i",
"File "+n_file+
" was created.")
788 if os.path.isfile(
str(filename)):
789 self.
__log__(
"i",
"DATA file: "+
str(filename)+
" was added for plotting.")
801 if os.path.isdir(dataDir):
802 self.
__log__(
"i",
"DATA dir: "+dataDir+
" was added for plotting.")
805 self.
__log__(
"w",
"DATA dir: "+dataDir+
" NOT found.")
809 if self.
args[
'isDMR']:
811 for root,dirs,files
in os.walk(dataDir):
813 if dir.startswith(
"offline"):
814 self.
dataFiles.
append(dataDir+
"/"+dir+
"/ExtendedOfflineValidation_Images/OfflineValidationSummary.root")
820 if os.path.isdir(mcDir):
821 self.
__log__(
"i",
"MC dir: "+mcDir+
" was added for plotting.")
823 for dirpath,dirs,files
in os.walk(mcDir):
826 self.
__log__(
"i",
"MC file: "+
str(file)+
" was added for plotting.")
830 self.
__log__(
"w",
"No MC file found in "+
str(mcDir)+
".")
832 self.
__log__(
"w",
"MC dir: "+mcDir+
" NOT found.")
838 if os.path.isfile(
str(filename)):
839 self.
__log__(
"i",
"MC file: "+
str(filename)+
" was added for plotting.")
857 objectsData = objects[
'DATA']
858 objectsMC = objects[
'MC']
861 for objDict
in objectsData:
863 for objDict
in objectsMC:
867 ROOT.gROOT.SetBatch(
True)
868 ROOT.gROOT.ProcessLine(
"gErrorIgnoreLevel = 1001;")
870 for objDict
in objectsData:
872 for var
in self.
varsX:
874 for key
in objDict.keys():
875 for _obj
in objDict[key]:
877 canvas = ROOT.TCanvas(id+
"_"+var+
"_"+segment)
881 segmentText = {
'text' : segment,
'xmin' : 0.0,
'xmax' : 0.0}
882 statText = {
'xmin' : 0.0,
'xmax' : 0.0}
884 segmentText[
'xmin'] = 2.5
885 segmentText[
'xmax'] = 3.5
886 statText[
'xmin'] = 0.20
887 statText[
'xmax'] = 0.85
889 segmentText[
'xmin'] = 1.4
890 segmentText[
'xmax'] = 1.6
891 statText[
'xmin'] = 0.65
892 statText[
'xmax'] = 0.95
899 for obj
in objDict[objName]:
900 if obj[
'var'] == var
and obj[
'segment'] == segment:
901 if obj[
'hist'].GetBinContent(obj[
'hist'].GetMaximumBin()) >= maxY:
902 maxY = obj[
'hist'].GetBinContent(obj[
'hist'].GetMaximumBin())
904 legendLabel = objName.replace(
"_",
" ")
905 if len(self.
args[
'labels']) != 0:
906 legendLabel = self.
args[
'labels'][self.
args[
'objects'].
index(objName)]
912 for objDictMC
in objectsMC:
914 for objMC
in objDictMC[objNameMC]:
915 if objMC[
'var'] == var
and objMC[
'segment'] == segment:
916 if objMC[
'hist'].GetBinContent(objMC[
'hist'].GetMaximumBin()) >= maxY:
917 maxY = objMC[
'hist'].GetBinContent(objMC[
'hist'].GetMaximumBin())
918 legendLabelMC = objNameMC.replace(
"_",
" ")
919 if len(self.
args[
'labels']) != 0:
920 legendLabelMC = self.
args[
'labels'][self.
args[
'objects'].
index(objNameMC)]
921 objMC[
'hist'].SetDirectory(0)
922 histsMC.append(objMC[
'hist'])
923 labelsMC.append(legendLabelMC)
924 statsMC.append(self.
__getStat__(objMC[
'hist'],var))
925 objGroup.append({
'hist' : obj[
'hist'],
927 'labelsMC': labelsMC,
929 'label' : legendLabel,
934 datasetType =
"singlemuon" 940 leg = ROOT.TLegend(0.08,legMinY,0.45,0.88)
941 leg.SetNColumns(nColumns)
943 maxX = objGroup[0][
'hist'].GetXaxis().GetXmax()
945 for igroup,group
in enumerate(objGroup):
946 group[
'hist'].GetYaxis().SetRangeUser(0,self.
legendOffset*maxY)
947 leg.AddEntry(group[
'hist'],group[
'label'],
"l")
948 stat.AddText(group[
'stat'])
949 group[
'hist'].Draw(
"HISTSAME")
951 if igroup == len(objGroup)-1:
952 for ihist,histmc
in enumerate(group[
'histsMC']):
953 leg.AddEntry(histmc,group[
'labelsMC'][ihist],
"l")
954 stat.AddText(group[
'statsMC'][ihist])
955 histmc.Draw(
"HISTSAME")
957 seg.DrawLatex(segmentText[
'xmin'],self.
segmentTextOffset[
'ymin']*maxY,segmentText[
'text'])
960 canvas.SaveAs(self.
outputDir+
"/offline_"+datasetType+
"_"+
str(id)+
"/"+var+
"_"+segment+
".png")
961 canvas.SaveAs(self.
outputDir+
"/offline_"+datasetType+
"_"+
str(id)+
"/"+var+
"_"+segment+
".pdf")
962 self.
__log__(
"i",
"Saving "+self.
outputDir+
"/offline_"+datasetType+
"_"+
str(id)+
"/"+var+
"_"+segment)
983 ROOT.gROOT.SetBatch(
True)
984 ROOT.gROOT.ProcessLine(
"gErrorIgnoreLevel = 1001;")
987 for var
in self.
varsX:
988 canvas = ROOT.TCanvas(var+
"_"+segment)
992 segmentText = {
'text' : segment,
'xmin' : 0.0,
'xmax' : 0.0}
993 statText = {
'xmin' : 0.0,
'xmax' : 0.0}
995 segmentText[
'xmin'] = 2.5
996 segmentText[
'xmax'] = 3.5
997 statText[
'xmin'] = 0.27
998 statText[
'xmax'] = 0.92
1000 segmentText[
'xmin'] = 1.4
1001 segmentText[
'xmax'] = 1.6
1002 statText[
'xmin'] = 0.75
1003 statText[
'xmax'] = 0.95
1010 for obj
in objects[objName]:
1011 if obj[
'var'] == var
and obj[
'segment'] == segment:
1012 if obj[
'hist'].GetBinContent(obj[
'hist'].GetMaximumBin()) >= maxY:
1013 maxY = obj[
'hist'].GetBinContent(obj[
'hist'].GetMaximumBin())
1015 legendLabel = objName.replace(
"_",
" ")
1016 if len(self.
args[
'labels']) != 0:
1017 legendLabel = self.
args[
'labels'][self.
args[
'objects'].
index(objName)]
1020 if obj[
'type'] ==
"MC":
1021 drawStyle =
"HIST SAME" 1023 if obj[
'type'] ==
"DATA":
1024 drawStyle +=
"P HIST SAME" 1026 objGroup.append({
'hist' : obj[
'hist'],
1027 'label' : legendLabel,
1029 'drawStyle' : drawStyle,
1030 'legStyle' : legStyle
1039 leg = ROOT.TLegend(0.20,legMinY,0.50,0.88)
1040 leg.SetNColumns(nColumns)
1042 maxX = objGroup[0][
'hist'].GetXaxis().GetXmax()
1044 for group
in objGroup:
1045 group[
'hist'].GetYaxis().SetRangeUser(0,self.
legendOffset*maxY)
1046 leg.AddEntry(group[
'hist'],group[
'label'],group[
'legStyle'])
1047 stat.AddText(group[
'stat'])
1048 group[
'hist'].Draw(group[
'drawStyle'])
1050 seg.DrawLatex(segmentText[
'xmin'],self.
segmentTextOffset[
'ymin']*maxY,segmentText[
'text'])
1053 canvas.Print(self.
outputDir+
"/"+var+
"_"+segment+
".png")
1054 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 _middleString(self, fullString)
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)
static std::string join(char **cmd)
def __defineObjects__(self)
def _styledTPaveText(self, x1, y1, x2, y2, var)