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'].SetMarkerStyle(self.
args[
'styles'][self.
args[
'objects'].
index(objName)])
611 obj[
'hist'].SetMarkerSize(1.5)
614 tStyle = ROOT.TStyle(
"StyleCMS",
"Style CMS")
620 tStyle.SetCanvasBorderMode(0)
621 tStyle.SetCanvasColor(ROOT.kWhite)
622 tStyle.SetCanvasDefH(800)
623 tStyle.SetCanvasDefW(800)
624 tStyle.SetCanvasDefX(0)
625 tStyle.SetCanvasDefY(0)
628 tStyle.SetFrameBorderMode(0)
629 tStyle.SetFrameBorderSize(10)
630 tStyle.SetFrameFillColor(ROOT.kBlack)
631 tStyle.SetFrameFillStyle(0)
632 tStyle.SetFrameLineColor(ROOT.kBlack)
633 tStyle.SetFrameLineStyle(0)
634 tStyle.SetFrameLineWidth(1)
635 tStyle.SetLineWidth(2)
638 tStyle.SetPadBorderMode(0)
639 tStyle.SetPadColor(ROOT.kWhite)
640 tStyle.SetPadGridX(
False)
641 tStyle.SetPadGridY(
False)
642 tStyle.SetGridColor(0)
643 tStyle.SetGridStyle(3)
644 tStyle.SetGridWidth(1)
647 tStyle.SetPadTopMargin(0.08)
648 tStyle.SetPadBottomMargin(0.13)
649 tStyle.SetPadLeftMargin(0.16)
650 tStyle.SetPadRightMargin(0.05)
653 tStyle.SetHistLineStyle(0)
654 tStyle.SetHistLineWidth(3)
655 tStyle.SetMarkerSize(0.8)
656 tStyle.SetEndErrorSize(4)
657 tStyle.SetHatchesLineWidth(1)
663 tStyle.SetAxisColor(1,
"XYZ")
664 tStyle.SetTickLength(0.03,
"XYZ")
665 tStyle.SetNdivisions(510,
"XYZ")
666 tStyle.SetPadTickX(1)
667 tStyle.SetPadTickY(1)
668 tStyle.SetStripDecimals(ROOT.kFALSE)
671 tStyle.SetTitleColor(1,
"XYZ")
672 tStyle.SetLabelColor(1,
"XYZ")
673 tStyle.SetLabelFont(42,
"XYZ")
674 tStyle.SetLabelOffset(0.007,
"XYZ")
675 tStyle.SetLabelSize(0.04,
"XYZ")
676 tStyle.SetTitleFont(42,
"XYZ")
677 tStyle.SetTitleSize(0.047,
"XYZ")
678 tStyle.SetTitleXOffset(1.2)
679 tStyle.SetTitleYOffset(1.7)
682 tStyle.SetLegendBorderSize(0)
684 tStyle.SetLegendFont(42)
696 leftMargin = canvas.GetLeftMargin()
697 rightMargin = canvas.GetRightMargin()
698 topMargin = canvas.GetTopMargin()
703 CMSextraOffset = 0.10
704 CMStext = ROOT.TLatex()
705 CMSextra = ROOT.TLatex()
710 CMStext.SetTextAngle(0)
711 CMSextra.SetTextAngle(0)
713 CMStext.SetTextColor(ROOT.kBlack)
714 CMSextra.SetTextColor(ROOT.kBlack)
716 CMStext.SetTextFont(61)
717 CMSextra.SetTextFont(52)
719 CMStext.SetTextAlign(11)
720 CMStext.SetTextSize(0.045)
721 CMSextra.SetTextSize(0.035)
723 CMStext.DrawLatex(leftMargin,1.-topMargin+0.01,CMSlabel)
724 CMSextra.DrawLatex(leftMargin+CMSextraOffset,1-topMargin+0.01,CMSextraLabel)
727 eraText = ROOT.TLatex()
729 eraText.SetTextAngle(0)
730 eraText.SetTextColor(ROOT.kBlack)
731 eraText.SetTextFont(42)
732 eraText.SetTextAlign(33)
733 eraText.SetTextSize(0.035)
734 eraText.DrawLatex(1.-rightMargin,1.-topMargin+0.035,eraLabel)
745 for dirpath,dirs,files
in os.walk(self.
cwd):
746 if dirpath != self.
cwd:
continue 748 if ".png" in n_file
or ".pdf" in n_file
or ".eps" in n_file:
749 self.
__log__(
"i",
"File "+n_file+
" was created.")
750 os.system(
"mv "+n_file+
" "+self.
outputDir)
760 os.system(
"mv "+datafile+
" "+self.
outputDir)
762 os.system(
"mv "+mcfile+
" "+self.
outputDir)
763 for dirpath,dirs,files
in os.walk(self.
cwd):
764 if dirpath != self.
cwd:
continue 766 if ".png" in n_file
or ".pdf" in n_file
or ".eps" in n_file:
767 self.
__log__(
"i",
"File "+n_file+
" was created.")
768 os.system(
"mv "+n_file+
" "+self.
outputDir)
776 for dirpath,dirs,files
in os.walk(self.
outputDir):
778 if ".png" in n_file
or ".pdf" in n_file
or ".eps" in n_file:
779 self.
__log__(
"i",
"File "+n_file+
" was created.")
787 if os.path.isfile(
str(filename)):
788 self.
__log__(
"i",
"DATA file: "+
str(filename)+
" was added for plotting.")
800 if os.path.isdir(dataDir):
801 self.
__log__(
"i",
"DATA dir: "+dataDir+
" was added for plotting.")
804 self.
__log__(
"w",
"DATA dir: "+dataDir+
" NOT found.")
808 if self.
args[
'isDMR']:
810 for root,dirs,files
in os.walk(dataDir):
812 if dir.startswith(
"offline"):
813 self.
dataFiles.
append(dataDir+
"/"+dir+
"/ExtendedOfflineValidation_Images/OfflineValidationSummary.root")
819 if os.path.isdir(mcDir):
820 self.
__log__(
"i",
"MC dir: "+mcDir+
" was added for plotting.")
822 for dirpath,dirs,files
in os.walk(mcDir):
825 self.
__log__(
"i",
"MC file: "+
str(file)+
" was added for plotting.")
829 self.
__log__(
"w",
"No MC file found in "+
str(mcDir)+
".")
831 self.
__log__(
"w",
"MC dir: "+mcDir+
" NOT found.")
837 if os.path.isfile(
str(filename)):
838 self.
__log__(
"i",
"MC file: "+
str(filename)+
" was added for plotting.")
856 objectsData = objects[
'DATA']
857 objectsMC = objects[
'MC']
860 for objDict
in objectsData:
862 for objDict
in objectsMC:
866 ROOT.gROOT.SetBatch(
True)
867 ROOT.gROOT.ProcessLine(
"gErrorIgnoreLevel = 1001;")
869 for objDict
in objectsData:
871 for var
in self.
varsX:
873 for key
in objDict.keys():
874 for _obj
in objDict[key]:
876 canvas = ROOT.TCanvas(id+
"_"+var+
"_"+segment)
880 segmentText = {
'text' : segment,
'xmin' : 0.0,
'xmax' : 0.0}
881 statText = {
'xmin' : 0.0,
'xmax' : 0.0}
883 segmentText[
'xmin'] = 2.5
884 segmentText[
'xmax'] = 3.5
885 statText[
'xmin'] = 0.20
886 statText[
'xmax'] = 0.85
888 segmentText[
'xmin'] = 1.4
889 segmentText[
'xmax'] = 1.6
890 statText[
'xmin'] = 0.65
891 statText[
'xmax'] = 0.95
898 for obj
in objDict[objName]:
899 if obj[
'var'] == var
and obj[
'segment'] == segment:
900 if obj[
'hist'].GetBinContent(obj[
'hist'].GetMaximumBin()) >= maxY:
901 maxY = obj[
'hist'].GetBinContent(obj[
'hist'].GetMaximumBin())
903 legendLabel = objName.replace(
"_",
" ")
904 if len(self.
args[
'labels']) != 0:
905 legendLabel = self.
args[
'labels'][self.
args[
'objects'].
index(objName)]
911 for objDictMC
in objectsMC:
913 for objMC
in objDictMC[objNameMC]:
914 if objMC[
'var'] == var
and objMC[
'segment'] == segment:
915 if objMC[
'hist'].GetBinContent(objMC[
'hist'].GetMaximumBin()) >= maxY:
916 maxY = objMC[
'hist'].GetBinContent(objMC[
'hist'].GetMaximumBin())
917 legendLabelMC = objNameMC.replace(
"_",
" ")
918 if len(self.
args[
'labels']) != 0:
919 legendLabelMC = self.
args[
'labels'][self.
args[
'objects'].
index(objNameMC)]
920 objMC[
'hist'].SetDirectory(0)
921 histsMC.append(objMC[
'hist'])
922 labelsMC.append(legendLabelMC)
923 statsMC.append(self.
__getStat__(objMC[
'hist'],var))
924 objGroup.append({
'hist' : obj[
'hist'],
926 'labelsMC': labelsMC,
928 'label' : legendLabel,
933 datasetType =
"singlemuon" 939 leg = ROOT.TLegend(0.08,legMinY,0.45,0.88)
940 leg.SetNColumns(nColumns)
942 maxX = objGroup[0][
'hist'].GetXaxis().GetXmax()
944 for igroup,group
in enumerate(objGroup):
945 group[
'hist'].GetYaxis().SetRangeUser(0,self.
legendOffset*maxY)
946 leg.AddEntry(group[
'hist'],group[
'label'],
"l")
947 stat.AddText(group[
'stat'])
948 group[
'hist'].Draw(
"HISTSAME")
950 if igroup == len(objGroup)-1:
951 for ihist,histmc
in enumerate(group[
'histsMC']):
952 leg.AddEntry(histmc,group[
'labelsMC'][ihist],
"l")
953 stat.AddText(group[
'statsMC'][ihist])
954 histmc.Draw(
"HISTSAME")
956 seg.DrawLatex(segmentText[
'xmin'],self.
segmentTextOffset[
'ymin']*maxY,segmentText[
'text'])
959 canvas.SaveAs(self.
outputDir+
"/offline_"+datasetType+
"_"+
str(id)+
"/"+var+
"_"+segment+
".png")
960 canvas.SaveAs(self.
outputDir+
"/offline_"+datasetType+
"_"+
str(id)+
"/"+var+
"_"+segment+
".pdf")
961 self.
__log__(
"i",
"Saving "+self.
outputDir+
"/offline_"+datasetType+
"_"+
str(id)+
"/"+var+
"_"+segment)
982 ROOT.gROOT.SetBatch(
True)
983 ROOT.gROOT.ProcessLine(
"gErrorIgnoreLevel = 1001;")
986 for var
in self.
varsX:
987 canvas = ROOT.TCanvas(var+
"_"+segment)
991 segmentText = {
'text' : segment,
'xmin' : 0.0,
'xmax' : 0.0}
992 statText = {
'xmin' : 0.0,
'xmax' : 0.0}
994 segmentText[
'xmin'] = 2.5
995 segmentText[
'xmax'] = 3.5
996 statText[
'xmin'] = 0.27
997 statText[
'xmax'] = 0.92
999 segmentText[
'xmin'] = 1.4
1000 segmentText[
'xmax'] = 1.6
1001 statText[
'xmin'] = 0.75
1002 statText[
'xmax'] = 0.95
1009 for obj
in objects[objName]:
1010 if obj[
'var'] == var
and obj[
'segment'] == segment:
1011 if obj[
'hist'].GetBinContent(obj[
'hist'].GetMaximumBin()) >= maxY:
1012 maxY = obj[
'hist'].GetBinContent(obj[
'hist'].GetMaximumBin())
1014 legendLabel = objName.replace(
"_",
" ")
1015 if len(self.
args[
'labels']) != 0:
1016 legendLabel = self.
args[
'labels'][self.
args[
'objects'].
index(objName)]
1019 if obj[
'type'] ==
"MC":
1020 drawStyle =
"HIST SAME" 1022 if obj[
'type'] ==
"DATA":
1023 drawStyle +=
"P HIST SAME" 1025 objGroup.append({
'hist' : obj[
'hist'],
1026 'label' : legendLabel,
1028 'drawStyle' : drawStyle,
1029 'legStyle' : legStyle
1038 leg = ROOT.TLegend(0.20,legMinY,0.50,0.88)
1039 leg.SetNColumns(nColumns)
1041 maxX = objGroup[0][
'hist'].GetXaxis().GetXmax()
1043 for group
in objGroup:
1044 group[
'hist'].GetYaxis().SetRangeUser(0,self.
legendOffset*maxY)
1045 leg.AddEntry(group[
'hist'],group[
'label'],group[
'legStyle'])
1046 stat.AddText(group[
'stat'])
1047 group[
'hist'].Draw(group[
'drawStyle'])
1049 seg.DrawLatex(segmentText[
'xmin'],self.
segmentTextOffset[
'ymin']*maxY,segmentText[
'text'])
1052 canvas.Print(self.
outputDir+
"/"+var+
"_"+segment+
".png")
1053 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)