13#include "TRestAnalysisPlot.h"
20#include "TRestManager.h"
21#include "TRestTools.h"
27TRestAnalysisPlot::TRestAnalysisPlot() {
Initialize(); }
29TRestAnalysisPlot::TRestAnalysisPlot(
const char* configFilename,
const char* name)
33 LoadConfigFromFile(fConfigFileName, name);
42 fPlotNamesCheck.clear();
47TRestAnalysisPlot::~TRestAnalysisPlot() {
delete fRun; }
50 if (
fHostmgr->GetRunInfo() !=
nullptr) {
53 if (fRun ==
nullptr) {
55 fRun->SetHistoricMetadataSaving(
false);
56 string defaultFileName = REST_TMP_PATH +
"restplot_" + REST_USER +
".root";
57 string outputname =
GetParameter(
"outputFile", defaultFileName);
58 if (outputname !=
"null" && outputname !=
"/dev/null") {
59 fRun->SetOutputFileName(outputname);
65 while (ele !=
nullptr) {
67 if (inputfile.find(
"http") == 0)
68 this->AddFile(inputfile);
71 for (
const auto& f : infiles) this->AddFile(f);
76 if (fNFiles == 0) AddFileFromExternalRun();
78 if (fNFiles == 0) AddFileFromEnv();
81 RESTWarning <<
"TRestAnalysisPlot: No input files are added!" <<
RESTendl;
85 RESTDebug <<
"TRestAnalysisPlot: Reading canvas settings" <<
RESTendl;
86 TiXmlElement* formatDefinition =
GetElement(
"labels");
87 if (formatDefinition !=
nullptr) {
89 cout << formatDefinition << endl;
90 cout <<
"Reading format definition : " << endl;
91 cout <<
"---------------------------" << endl;
103 if (fLabelOffsetX == -1) fLabelOffsetX = 1.1;
104 if (fLabelOffsetY == -1) fLabelOffsetY = 1.3;
106 if (fTicksScaleX == -1) fTicksScaleX = 1.5;
107 if (fTicksScaleY == -1) fTicksScaleY = 1.5;
109 if (fLabelScaleX == -1) fLabelScaleX = 1.3;
110 if (fLabelScaleY == -1) fLabelScaleY = 1.3;
113 cout <<
"ticks scale X : " << fTicksScaleX << endl;
114 cout <<
"ticks scale Y : " << fTicksScaleY << endl;
115 cout <<
"label scale X : " << fLabelScaleX << endl;
116 cout <<
"label scale Y : " << fLabelScaleY << endl;
117 cout <<
"label offset X : " << fLabelOffsetX << endl;
118 cout <<
"label offset Y : " << fLabelOffsetY << endl;
124 TiXmlElement* legendDefinition =
GetElement(
"legendPosition");
125 if (legendDefinition !=
nullptr) {
127 cout << legendDefinition << endl;
128 cout <<
"Reading legend definition : " << endl;
129 cout <<
"---------------------------" << endl;
138 if (fLegendX1 == -1) fLegendX1 = 0.7;
139 if (fLegendY1 == -1) fLegendY1 = 0.75;
141 if (fLegendX2 == -1) fLegendX2 = 0.88;
142 if (fLegendY2 == -1) fLegendY2 = 0.88;
145 cout <<
"x1 : " << fLegendX1 <<
" y1 : " << fLegendY1 << endl;
146 cout <<
"x2 : " << fLegendX2 <<
" y2 : " << fLegendY2 << endl;
152 TiXmlElement* canvasdef =
fElement->FirstChildElement(
"canvas");
153 if (canvasdef ==
nullptr) {
161 string save = (string)
GetParameter(
"save", canvasdef,
"rest_AnalysisPlot.pdf");
162 if (save.rfind(
"/", 0) == 0)
163 fCanvasSave = (TString)save;
169 RESTDebug <<
"TRestAnalysisPlot: Reading global cuts" <<
RESTendl;
170 vector<string> globalCuts;
171 TiXmlElement* gCutele =
GetElement(
"globalCut");
172 while (gCutele !=
nullptr)
174 string cutActive =
GetParameter(
"value", gCutele,
"ON");
176 if (
ToUpper(cutActive) ==
"ON") {
181 RESTWarning <<
"<globalCut name=\"var\" is now obsolete." <<
RESTendl;
182 RESTWarning <<
"Please, replace by : <globalCut variable=\"var\" " <<
RESTendl;
187 if (obsName ==
"")
continue;
189 string cutCondition =
GetParameter(
"condition", gCutele);
190 string cutString = obsName + cutCondition;
192 globalCuts.push_back(cutString);
198 RESTDebug <<
"TRestAnalysisPlot: Reading global cut strings" <<
RESTendl;
199 TiXmlElement* gCutStrele =
GetElement(
"globalCutString");
200 while (gCutStrele !=
nullptr)
202 string cutActive =
GetParameter(
"value", gCutStrele,
"ON");
204 if (
ToUpper(cutActive) ==
"ON") {
205 string cutString =
GetParameter(
"string", gCutStrele,
"");
206 cutString =
"(" + cutString +
")";
207 if (cutString ==
"")
continue;
209 globalCuts.push_back(cutString);
215 RESTDebug <<
"TRestAnalysisPlot: Reading plot sections" <<
RESTendl;
216 Int_t maxPlots = (Int_t)fCanvasDivisions.X() * (Int_t)fCanvasDivisions.Y();
218 while (plotele !=
nullptr) {
221 int N = fPlots.size();
223 RESTError <<
"Your canvas divisions (" << fCanvasDivisions.X() <<
" , "
224 << fCanvasDivisions.Y() <<
") are not enough to show " << N + 1 <<
" plots"
231 plot.logY = StringToBool(
GetParameter(
"logscale", plotele,
"false"));
232 plot.logY = plot.logY ? plot.logY : StringToBool(
GetParameter(
"logY", plotele,
"false"));
233 plot.logX = StringToBool(
GetParameter(
"logX", plotele,
"false"));
234 plot.logZ = StringToBool(
GetParameter(
"logZ", plotele,
"false"));
235 plot.gridY = StringToBool(
GetParameter(
"gridY", plotele,
"false"));
236 plot.gridX = StringToBool(
GetParameter(
"gridX", plotele,
"false"));
247 plot.legendOn = StringToBool(
GetParameter(
"legend", plotele,
"OFF"));
248 plot.staticsOn = StringToBool(
GetParameter(
"stats", plotele,
"OFF"));
249 plot.annotationOn = StringToBool(
GetParameter(
"annotation", plotele,
"OFF"));
252 plot.timeDisplay = StringToBool(
GetParameter(
"timeDisplay", plotele,
"OFF"));
255 TiXmlElement* histele =
GetElement(
"histo", plotele);
256 if (histele ==
nullptr) {
260 while (histele !=
nullptr) {
261 HistoInfoSet hist = SetupHistogramFromConfigFile(histele, plot);
263 for (
unsigned int i = 0; i < globalCuts.size(); i++) {
264 if (i > 0 || hist.cutString !=
"") hist.cutString +=
" && ";
266 cout <<
"Adding global cut : " << globalCuts[i] << endl;
267 hist.cutString += globalCuts[i];
271 if (hist.plotString ==
"") {
272 RESTWarning <<
"No variables or histograms defined in the plot, skipping!" <<
RESTendl;
274 plot.histos.push_back(hist);
277 if (histele == plotele) {
283 fPlots.push_back(plot);
288 RESTDebug <<
"TRestAnalysisPlot: Reading panel sections" <<
RESTendl;
289 maxPlots -= fPlots.size();
291 while (panelele !=
nullptr) {
294 int N = fPanels.size();
296 RESTError <<
"Your canvas divisions (" << fCanvasDivisions.X() <<
" , "
297 << fCanvasDivisions.Y() <<
") are not enough to show " << fPlots.size()
298 <<
" plots, and " << N + 1 <<
" info panels" <<
RESTendl;
306 TiXmlElement* labelele =
GetElement(
"label", panelele);
307 while (labelele !=
nullptr) {
308 panel.label.push_back(
GetParameter(
"value", labelele,
"Error. Label value not defined"));
315 fPanels.push_back(panel);
320 for (
unsigned int n = 0; n < fPanels.size(); n++) {
321 RESTExtreme <<
"Panel " << n <<
" with font size : " << fPanels[n].font_size <<
RESTendl;
322 for (
unsigned int m = 0; m < fPanels[n].posX.size(); m++) {
323 RESTExtreme <<
"Label : " << fPanels[n].label[m] <<
RESTendl;
324 RESTExtreme <<
"Pos X : " << fPanels[n].posX[m] <<
RESTendl;
325 RESTExtreme <<
"Pos Y : " << fPanels[n].posY[m] <<
RESTendl;
334 hist.drawOption =
GetParameter(
"option", histele,
"colz");
336 for (
const auto& n : fPlotNamesCheck)
337 if (hist.name == n) {
339 <<
"Repeated plot/histo names were found! Please, use different names for different plots!"
341 RESTError <<
"<plot/histo name=\"" << hist.name <<
"\" already defined!" <<
RESTendl;
345 fPlotNamesCheck.push_back(hist.name);
349 vector<string> varNames;
350 vector<TVector2> ranges;
352 TiXmlElement* varele =
GetElement(
"variable", histele);
353 while (varele !=
nullptr) {
357 rangeStr =
Replace(rangeStr,
"unixTime", std::to_string(std::time(
nullptr)));
358 rangeStr =
Replace(rangeStr,
"days",
"24*3600");
365 for (
unsigned int n = 0; n < bins.size(); n++) {
366 cout <<
"Variable " << varNames[n] << endl;
367 cout <<
"------------------------------------------" << endl;
368 cout <<
"Plot range : ( " << ranges.back().X() <<
" , " << ranges.back().Y() <<
" ) " << endl;
369 cout <<
"bins : " << bins.back() << endl;
374 string pltString =
"";
375 for (
int i = varNames.size() - 1; i >= 0; i--) {
377 pltString += varNames[i];
378 if (i > 0) pltString +=
":";
380 hist.plotString = pltString;
383 string rangestr =
"";
384 for (
unsigned int i = 0; i < bins.size(); i++) {
385 string binsStr = ToString(bins[i]);
386 if (bins[i] == -1) binsStr =
" ";
388 string rXStr = ToString(ranges[i].X());
389 if (ranges[i].X() == -1) {
391 if (varNames[i] ==
"timeStamp" || plot.timeDisplay) rXStr =
"MIN_TIME";
394 string rYStr = ToString(ranges[i].Y());
395 if (ranges[i].Y() == -1) {
397 if (varNames[i] ==
"timeStamp" || plot.timeDisplay) rYStr =
"MAX_TIME";
400 if (i == 0) rangestr +=
"(";
401 rangestr += binsStr +
" , " + rXStr +
" , " + rYStr;
402 if (i < bins.size() - 1) rangestr +=
",";
403 if (i == bins.size() - 1) rangestr +=
")";
405 hist.range = rangestr;
408 string cutString =
"";
410 TiXmlElement* cutele =
GetElement(
"cut", histele);
411 while (cutele !=
nullptr) {
413 if (
ToUpper(cutActive) ==
"ON") {
415 if (cutVariable == PARAMETER_NOT_FOUND_STR) {
416 RESTError <<
"Variable was not found! There is a problem inside <cut definition. Check it."
418 cout <<
"Contents of entire <histo definition : " <<
ElementToString(histele) << endl;
422 string cutCondition =
GetParameter(
"condition", cutele);
423 if (cutCondition == PARAMETER_NOT_FOUND_STR) {
424 RESTError <<
"Condition was not found! There is a problem inside <cut definition. Check it."
426 cout <<
"Contents of entire <histo definition : " <<
ElementToString(histele) << endl;
430 if (cutString.length() > 0) cutString +=
" && ";
431 RESTDebug <<
"Adding local cut : " << cutVariable << cutCondition <<
RESTendl;
434 if (cutCondition.find(
"==") == 0) {
435 string condValue = cutCondition.substr(2);
436 if (!
isANumber(condValue)) cutCondition =
"==\"" + condValue +
"\"";
439 cutString += cutVariable + cutCondition;
444 TiXmlElement* cutstrele =
GetElement(
"cutString", histele);
445 while (cutstrele !=
nullptr) {
446 string cutActive =
GetParameter(
"value", cutstrele,
"ON");
447 if (
ToUpper(cutActive) ==
"ON") {
449 if (cutStr == PARAMETER_NOT_FOUND_STR) {
451 <<
"Cut string was not found! There is a problem inside <cutString definition. Check it."
453 cout <<
"Contents of entire <histo definition : " <<
ElementToString(histele) << endl;
457 if (cutString.length() > 0) cutString +=
" && ";
458 RESTDebug <<
"Adding local cut : " << cutStr <<
RESTendl;
460 cutString +=
"(" + cutStr +
")";
464 hist.cutString = cutString;
467 hist.classifyMap.clear();
468 TiXmlElement* classifyele =
GetElement(
"classify", histele);
469 while (classifyele !=
nullptr) {
470 string Active =
GetParameter(
"value", classifyele,
"ON");
472 TiXmlAttribute* attr = classifyele->FirstAttribute();
473 while (attr !=
nullptr) {
474 if (attr->Value() !=
nullptr && !
string(attr->Value()).empty()) {
475 hist.classifyMap[attr->Name()] = attr->Value();
484 hist.lineColor = GetColorIDFromString(
GetParameter(
"lineColor", histele,
"602"));
486 hist.lineStyle = GetLineStyleIDFromString(
GetParameter(
"lineStyle", histele,
"1"));
487 hist.fillStyle = GetFillStyleIDFromString(
GetParameter(
"fillStyle", histele,
"1001"));
488 hist.fillColor = GetColorIDFromString(
GetParameter(
"fillColor", histele,
"0"));
493void TRestAnalysisPlot::AddFile(
const TString& fileName) {
494 RESTInfo <<
"TRestAnalysisPlot::AddFile. Adding file. " <<
RESTendl;
495 RESTInfo <<
"File name: " << fileName <<
RESTendl;
500void TRestAnalysisPlot::SetFile(
const TString& fileName) {
507void TRestAnalysisPlot::AddFileFromExternalRun() {
508 if (fRun !=
nullptr && fNFiles == 0) {
509 if (
fHostmgr->GetProcessRunner() !=
nullptr && fRun->GetOutputFileName() !=
"") {
511 AddFile(fRun->GetOutputFileName());
518void TRestAnalysisPlot::AddFileFromEnv() {
523 for (
const auto& file : files) {
524 RESTEssential <<
"Adding file : " << file <<
RESTendl;
530Int_t TRestAnalysisPlot::GetPlotIndex(
const TString& plotName) {
531 for (
unsigned int n = 0; n < fPlots.size(); n++)
532 if (fPlots[n].name == plotName)
return n;
534 RESTWarning <<
"TRestAnalysisPlot::GetPlotIndex. Plot name " << plotName <<
" not found" <<
RESTendl;
539 if (fRun->GetInputFile() !=
nullptr && fRun->GetInputFile()->GetName() == fileName) {
541 return fRun->GetAnalysisTree();
543 if (fileName == fRun->GetOutputFileName() && fRun->GetOutputFile() !=
nullptr) {
548 fHostmgr->GetProcessRunner()->GetStatus() != kFinished) {
550 return fHostmgr->GetProcessRunner()->GetOutputAnalysisTree();
553 return fRun->GetAnalysisTree();
556TRestRun* TRestAnalysisPlot::GetRunInfo(
const TString& fileName) {
558 if (fRun->GetInputFile() !=
nullptr && fRun->GetInputFile()->GetName() == fileName) {
561 if (fileName == fRun->GetOutputFileName() && fRun->GetOutputFile() !=
nullptr) {
565 fHostmgr->GetProcessRunner()->GetStatus() != kFinished) {
572bool TRestAnalysisPlot::IsDynamicRange(
const TString& rangeString) {
573 return (
string(rangeString)).find(
", ") != string::npos;
576Int_t TRestAnalysisPlot::GetColorIDFromString(
const string& in) {
577 if (in.find_first_not_of(
"0123456789") == string::npos) {
579 }
else if (ColorIdMap.count(in) != 0) {
580 return ColorIdMap.at(in);
582 RESTWarning <<
"cannot find color with name \"" << in <<
"\"" <<
RESTendl;
587Int_t TRestAnalysisPlot::GetFillStyleIDFromString(
const string& in) {
588 if (in.find_first_not_of(
"0123456789") == string::npos) {
590 }
else if (FillStyleMap.count(in) != 0) {
591 return FillStyleMap.at(in);
593 RESTWarning <<
"cannot find fill style with name \"" << in <<
"\"" <<
RESTendl;
598Int_t TRestAnalysisPlot::GetLineStyleIDFromString(
const string& in) {
599 if (in.find_first_not_of(
"0123456789") == string::npos) {
601 }
else if (LineStyleMap.count(in) != 0) {
602 return LineStyleMap.at(in);
604 RESTWarning <<
"cannot find line style with name \"" << in <<
"\"" <<
RESTendl;
609void TRestAnalysisPlot::PlotCombinedCanvas() {
615 fCombinedCanvas =
new TCanvas(this->GetName(), this->GetName(), 0, 0, fCanvasSize.X(), fCanvasSize.Y());
616 fCombinedCanvas->Divide((Int_t)fCanvasDivisions.X(), (Int_t)fCanvasDivisions.Y(),
617 fCanvasDivisionMargins.X(), fCanvasDivisionMargins.Y());
620 TStyle* st =
new TStyle();
621 st->SetPalette(fPaletteStyle);
623 Double_t startTime = 0;
624 Double_t endTime = 0;
625 Double_t runLength = 0;
626 Int_t totalEntries = 0;
628 auto run = GetRunInfo(inputFilename);
630 Double_t endTimeStamp = run->GetEndTimestamp();
631 Double_t startTimeStamp = run->GetStartTimestamp();
634 if (!startTime || startTime > endTimeStamp) startTime = endTimeStamp;
635 if (!startTime || startTime > startTimeStamp) startTime = startTimeStamp;
637 if (!endTime || endTime < startTimeStamp) endTime = startTimeStamp;
638 if (!endTime || endTime < endTimeStamp) endTime = endTimeStamp;
640 if (endTimeStamp - startTimeStamp > 0) {
641 runLength += endTimeStamp - startTimeStamp;
642 totalEntries += run->GetEntries();
646 Double_t meanRate = totalEntries / runLength;
650 for (
unsigned int n = 0; n < fPanels.size(); n++) {
652 for (
unsigned int m = 0; m < fPanels[n].posX.size(); m++) {
653 string label = fPanels[n].label[m];
660 label =
Replace(label,
"[[entries]]", Form(
"%d", totalEntries), pos);
662 label =
Replace(label,
"[[runLength]]", Form(
"%5.2lf", runLength), pos);
664 label =
Replace(label,
"[[meanRate]]", Form(
"%5.2lf", meanRate), pos);
667 label = run->ReplaceMetadataMembers(label, fPanels[n].precision);
669 TLatex* textLatex =
new TLatex(fPanels[n].posX[m], fPanels[n].posY[m], label.c_str());
670 textLatex->SetTextColor(1);
671 textLatex->SetTextSize(fPanels[n].font_size);
672 textLatex->Draw(
"same");
677 vector<TH3F*> histCollectionAll;
678 for (
unsigned int n = 0; n < fPlots.size(); n++) {
679 PlotInfoSet& plot = fPlots[n];
682 targetPad->SetLogx(plot.logX);
683 targetPad->SetLogy(plot.logY);
684 targetPad->SetLogz(plot.logZ);
685 targetPad->SetGridx(plot.gridX);
686 targetPad->SetGridy(plot.gridY);
687 targetPad->SetLeftMargin(plot.marginLeft);
688 targetPad->SetRightMargin(plot.marginRight);
689 targetPad->SetBottomMargin(plot.marginBottom);
690 targetPad->SetTopMargin(plot.marginTop);
693 for (
unsigned int i = 0; i < plot.histos.size(); i++) {
694 HistoInfoSet& hist = plot.histos[i];
696 TString plotString = hist.plotString;
697 TString nameString = hist.name;
698 TString rangeString = hist.range;
699 TString cutString = hist.cutString;
700 TString optString = hist.drawOption;
703 rangeString =
Replace((
string)rangeString,
"MIN_TIME", (
string)Form(
"%9f", startTime), pos);
704 rangeString =
Replace((
string)rangeString,
"MAX_TIME", (
string)Form(
"%9f", endTime), pos);
707 cutString = hist.weight;
708 else if (!hist.weight.empty())
709 cutString =
"(" + cutString +
") * " + hist.weight;
713 cout <<
"--------------------------------------" << endl;
714 cout <<
"Plot string : " << plotString << endl;
715 cout <<
"Plot name : " << nameString << endl;
716 cout <<
"Plot range : " << rangeString << endl;
717 cout <<
"Cut : " << cutString << endl;
718 cout <<
"Plot option : " << optString << endl;
719 cout <<
"++++++++++++++++++++++++++++++++++++++" << endl;
723 bool firstdraw =
false;
724 TH3F* hTotal = hist.ptr;
729 for (
const auto& [inputFile, info] : hist.classifyMap) {
730 if (run->GetRunInformation(inputFile).find(info) == string::npos) {
741 TString reducedHistoName = nameString +
"_" + std::to_string(j);
742 TString histoName = nameString +
"_" + std::to_string(j) + rangeString;
743 RESTInfo <<
"AnalysisTree->Draw(\"" << plotString <<
">>" << histoName <<
"\", \""
744 << cutString <<
"\", \"" << optString <<
"\", " <<
fDrawNEntries <<
", "
745 << fDrawFirstEntry <<
")" <<
RESTendl;
746 outVal = tree->Draw(plotString +
">>" + histoName, cutString, optString,
fDrawNEntries,
748 TH3F* hh = (TH3F*)gPad->GetPrimitive(reducedHistoName);
751 RESTInfo <<
"AnalysisTree is empty? cut is too hard?" <<
RESTendl;
752 }
else if (outVal == -1) {
755 <<
"TRestAnalysisPlot::PlotCombinedCanvas. Plot string not properly constructed. "
756 "Does the analysis observable exist inside the file?"
758 RESTError <<
"Use \" restManager PrintTrees FILE.ROOT\" to get a list of "
759 "existing observables."
766 if (hTotal ==
nullptr) {
768 hTotal = (TH3F*)hh->Clone(nameString);
772 hTotal->SetDirectory(0);
776 if (IsDynamicRange(rangeString)) {
777 hTotal->SetDirectory(gDirectory);
778 hTotal->SetCanExtend(TH1::kAllAxes);
779 tree->Draw(plotString +
">>+" + hTotal->GetName(), cutString, optString,
781 RESTInfo <<
"AnalysisTree->Draw(\"" << plotString <<
">>+" << hTotal->GetName()
782 <<
"\", \"" << cutString <<
"\", \"" << optString <<
"\", "
784 hTotal->SetDirectory(0);
792 if (hTotal ==
nullptr) {
793 RESTWarning <<
"Histogram \"" << nameString <<
"\" is nullptr" <<
RESTendl;
794 }
else if (firstdraw) {
796 hTotal->SetTitle(plot.title.c_str());
797 hTotal->SetStats(plot.staticsOn);
799 hTotal->GetXaxis()->SetTitle(plot.labelX.c_str());
800 hTotal->GetYaxis()->SetTitle(plot.labelY.c_str());
802 hTotal->GetXaxis()->SetLabelSize(1.1 * hTotal->GetXaxis()->GetLabelSize());
803 hTotal->GetYaxis()->SetLabelSize(1.1 * hTotal->GetYaxis()->GetLabelSize());
804 hTotal->GetXaxis()->SetTitleSize(1.1 * hTotal->GetXaxis()->GetTitleSize());
805 hTotal->GetYaxis()->SetTitleSize(1.1 * hTotal->GetYaxis()->GetTitleSize());
806 hTotal->GetXaxis()->SetTitleOffset(1 * hTotal->GetXaxis()->GetTitleOffset());
807 hTotal->GetYaxis()->SetTitleOffset(1 * hTotal->GetYaxis()->GetTitleOffset());
808 hTotal->GetXaxis()->SetNdivisions(plot.ticksX);
809 hTotal->GetYaxis()->SetNdivisions(plot.ticksY);
811 hTotal->SetLineColor(hist.lineColor);
812 hTotal->SetLineWidth(hist.lineWidth);
813 hTotal->SetLineStyle(hist.lineStyle);
814 hTotal->SetFillColor(hist.fillColor);
815 hTotal->SetFillStyle(hist.fillStyle);
817 hTotal->SetDrawOption(hist.drawOption.c_str());
819 if (plot.timeDisplay) hTotal->GetXaxis()->SetTimeDisplay(1);
821 histCollectionAll.push_back(hTotal);
825 bool allEmpty =
true;
826 for (
unsigned int i = 0; i < plot.histos.size(); i++) {
827 if (plot.histos[i].ptr ==
nullptr)
835 RESTWarning <<
"TRestAnalysisPlot: pad empty for the plot: " << plot.name <<
RESTendl;
840 if (plot.normalize > 0) {
841 for (
unsigned int i = 0; i < plot.histos.size(); i++) {
842 if (plot.histos[i].ptr ==
nullptr)
continue;
844 if (plot.histos[i].ptr->Integral() > 0) {
845 scale = plot.normalize / plot.histos[i].ptr->Integral();
846 plot.histos[i].ptr->Scale(scale);
852 if (plot.scale !=
"") {
853 for (
unsigned int i = 0; i < plot.histos.size(); i++) {
854 if (plot.histos[i].ptr ==
nullptr)
continue;
856 if (plot.scale ==
"binSize")
857 scale = 1. / plot.histos[i].ptr->GetXaxis()->GetBinWidth(1);
861 plot.histos[i].ptr->Scale(scale);
867 Double_t maxValue_Pad = 0;
868 unsigned int maxID = 0;
869 for (
unsigned int i = 0; i < plot.histos.size(); i++) {
871 if (plot.histos[i].ptr ==
nullptr)
continue;
872 Double_t value = plot.histos[i]->GetBinContent(plot.histos[i].ptr->GetMaximumBin());
874 maxValue_Pad = value;
875 }
else if (value > maxValue_Pad) {
876 maxValue_Pad = value;
880 plot.histos[maxID]->Draw(plot.histos[maxID].drawOption.c_str());
885 for (
unsigned int i = 0; i < plot.histos.size(); i++) {
887 if (plot.histos[i].ptr ==
nullptr)
continue;
889 plot.histos[i]->Draw((plot.histos[i].drawOption +
"same").c_str());
894 if (fRun->GetOutputFile() !=
nullptr) {
895 fRun->GetOutputFile()->cd();
896 for (
auto& histo : plot.histos) {
897 if (histo.ptr ==
nullptr)
continue;
904 TLegend* legend =
new TLegend(fLegendX1, fLegendY1, fLegendX2, fLegendY2);
905 for (
auto& histo : plot.histos) {
906 if (histo.ptr ==
nullptr)
continue;
907 legend->AddEntry(histo.ptr, histo->GetName(),
"lf");
909 legend->Draw(
"same");
913 targetPad->SetRightMargin(plot.marginRight);
914 targetPad->SetLeftMargin(plot.marginLeft);
915 targetPad->SetBottomMargin(plot.marginBottom);
917 if (!plot.save.empty()) targetPad->Print(plot.save.c_str());
923 if (!REST_Display_CompatibilityMode && StringToBool(
GetParameter(
"previewPlot",
"TRUE"))) {
934 run->SetOutputFileName((
string)fCanvasSave);
936 for (
auto& h : histCollectionAll) {
943 if (fRun->GetOutputFile() !=
nullptr) {
944 fRun->GetOutputFile()->cd();
951void TRestAnalysisPlot::SaveCanvasToPDF(
const TString& fileName) {
fCombinedCanvas->Print(fileName); }
953void TRestAnalysisPlot::SavePlotToPDF(
const TString& fileName, Int_t n) {
964 pad->SetRightMargin(fPlots[n - 1].marginRight);
965 pad->SetLeftMargin(fPlots[n - 1].marginLeft);
966 pad->SetBottomMargin(fPlots[n - 1].marginBottom);
968 TCanvas* c =
new TCanvas(fPlots[n - 1].name.c_str(), fPlots[n - 1].name.c_str(), 800, 600);
978void TRestAnalysisPlot::SaveHistoToPDF(
const TString& fileName, Int_t nPlot, Int_t nHisto) {
979 string name = fPlots[nPlot].histos[nHisto].name;
980 TH3F* hist = (TH3F*)gPad->GetPrimitive(name.c_str());
982 TCanvas* c =
new TCanvas(name.c_str(), name.c_str(), 800, 600);
void Initialize() override
Making default settings.
Long64_t fDrawNEntries
Output canvas.
std::vector< TString > fRunInputFileName
TRestRun to handle output file.
TCanvas * fCombinedCanvas
TRestRun to handle input file.
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
REST core data-saving helper based on TTree.
Data provider and manager in REST.
void OpenInputFile(int i)
Open the i th file in the file list.
TFile * FormOutputFile()
Create a new TFile as REST output file. Writing metadata objects into it.
TString FormFormat(const TString &filenameFormat)
Form output file name according to file info list, proc info list and run data.
@ REST_Extreme
show everything
@ REST_Debug
+show the defined debug messages
Int_t GetChar(std::string hint="Press a KEY to continue ...")
Helps to pause the program, printing a message before pausing.
Double_t StringToDouble(std::string in)
Gets a double from a string.
std::string ToUpper(std::string in)
Convert string to its upper case. Alternative of TString::ToUpper.
Int_t StringToInteger(std::string in)
Gets an integer from a string.
TVector2 StringTo2DVector(std::string in)
Gets a 2D-vector from a string.
Int_t isANumber(std::string in)
Returns 1 only if a valid number is found in the string in. If not it returns 0.
std::string RemoveWhiteSpaces(std::string in)
Returns the input string removing all white spaces.
std::string ToDateTimeString(time_t time)
Format time_t into string.
std::string Replace(std::string in, std::string thisString, std::string byThisString, size_t fromPosition=0, Int_t N=0)
Replace any occurences of thisSring by byThisString inside string in.