CbmRoot
Loading...
Searching...
No Matches
CbmQaIO.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#include "CbmQaIO.h"
11
12#include "CbmQaCanvas.h"
13#include "CbmQaUtil.h"
14#include "TFile.h"
15#include "TPaveStats.h"
16
17// ---------------------------------------------------------------------------------------------------------------------
18//
19CbmQaIO::CbmQaIO(TString prefixName, std::shared_ptr<ObjList_t> pObjList) : fsPrefix(prefixName), fpvObjList(pObjList)
20{
21 if (!fsPrefix.IsNull()) {
22 //fsPrefix += "_";
23 }
24 if (!fpvObjList.get()) {
25 fpvObjList = std::make_shared<ObjList_t>();
26 }
27}
28
29// ---------------------------------------------------------------------------------------------------------------------
30//
32
33
34// ---------------------------------------------------------------------------------------------------------------------
35//
36void CbmQaIO::SetTH1Properties(TH1* pHist) const
37{
38 // Set default histo properties
39 pHist->GetYaxis()->SetLabelOffset(0.95);
40
41 TPaveStats* stats = cbm::qa::util::GetHistStats(pHist);
42 assert(stats);
43 stats->SetY1NDC(0.7);
44 stats->SetOptStat(111110);
45 stats->SetOptFit(100001);
46}
47
48// ---------------------------------------------------------------------------------------------------------------------
49//
50void CbmQaIO::SetTH2Properties(TH2* pHist) const
51{
52 // Set default histo properties
53
54 pHist->SetOption("colz");
55 pHist->SetStats(false);
56 //pHist->GetYaxis()->SetLabelOffset(0.95);
57 /*
58 TPaveStats* stats = cbm::qa::util::GetHistStats(pHist);
59 assert(stats);
60 stats->SetOptStat(10);
61 stats->SetOptFit(0);
62 */
63}
64
65// ---------------------------------------------------------------------------------------------------------------------
66//
67void CbmQaIO::SetTProfile2DProperties(TProfile2D* pHist) const
68{
69 // Set default histo properties
70
71 pHist->GetYaxis()->SetLabelOffset(0.95);
72 pHist->SetOption("colz");
73 pHist->SetStats(false);
74 /*
75 TPaveStats* stats = cbm::qa::util::GetHistStats(pHist);
76 assert(stats);
77 stats->SetOptStat(10);
78 stats->SetOptFit(0);
79 */
80}
81
82// ---------------------------------------------------------------------------------------------------------------------
83//
84void CbmQaIO::SetCanvasProperties(TCanvas* pCanv) const
85{
86 constexpr double left = 0.18;
87 constexpr double bottom = 0.15;
88 constexpr double right = 0.10;
89 constexpr double top = 0.10;
90 pCanv->SetMargin(left, right, bottom, top);
91}
92
93// ---------------------------------------------------------------------------------------------------------------------
94//
95void CbmQaIO::SetConfigName(const char* path)
96{
97 fsConfigName = path;
98 try {
99 fConfigNode = YAML::LoadFile(path)["qa"][fsPrefix.Data()];
100 }
101 catch (const YAML::BadFile& exc) {
102 std::stringstream msg;
103 msg << "configuration file for QA \"" << path << "\" does not exist";
104 throw std::runtime_error(msg.str());
105 }
106 catch (const YAML::ParserException& exc) {
107 std::stringstream msg;
108 msg << "configuration file for QA \"" << path << "\" is improperly formatted";
109 throw std::runtime_error(msg.str());
110 }
111 LOG(info) << fsPrefix << ": configuration file is set to " << path;
112}
113
114// ---------------------------------------------------------------------------------------------------------------------
115//
116void CbmQaIO::WriteToFile(TFile* pOutFile) const
117{
118 pOutFile->cd();
119 for (auto& [pObject, sPath] : (*fpvObjList)) {
120 if (!pOutFile->GetDirectory(sPath)) {
121 pOutFile->mkdir(sPath);
122 }
123 pOutFile->cd(sPath);
124 if (pObject) {
125 pObject->Write();
126 }
127 }
128}
129
130// ---------------------------------------------------------------------------------------------------------------------
131//
132void CbmQaIO::MakeQaDirectory(TString sDirectory)
133{
134 // Add parent directory
135 if (fsRootFolderName.Length() != 0) {
136 sDirectory = fsRootFolderName + "/" + sDirectory;
137 }
138
139 // Register the object in the list
140 fpvObjList->push_back(std::make_pair(nullptr, sDirectory));
141}
Definition of the CbmQaCanvas class.
Module for ROOT objects IO interface (header)
Useful utilities for CBM QA tasks.
virtual void SetTProfile2DProperties(TProfile2D *pHist) const
Applies properties on the profile 2D created with the MakeQaObject function.
Definition CbmQaIO.cxx:67
virtual void SetCanvasProperties(TCanvas *pCanv) const
Applies properties on the canvas created with the MakeQaObject funciton.
Definition CbmQaIO.cxx:84
void SetConfigName(const char *path)
Creates a ROOT object.
Definition CbmQaIO.cxx:95
void WriteToFile(TFile *pOutFile) const
Writes objects into file.
Definition CbmQaIO.cxx:116
YAML::Node fConfigNode
Configuration node.
Definition CbmQaIO.h:164
void MakeQaDirectory(TString sName)
Definition CbmQaIO.cxx:132
virtual void SetTH2Properties(TH2 *pHist) const
Applies properties on the histogram created with the MakeQaObject function.
Definition CbmQaIO.cxx:50
virtual ~CbmQaIO()
Destructor.
Definition CbmQaIO.cxx:31
TString fsPrefix
Unique prefix for all writeable root.
Definition CbmQaIO.h:159
virtual void SetTH1Properties(TH1 *pHist) const
Applies properties on the histogram created with the MakeQaObject function.
Definition CbmQaIO.cxx:36
std::shared_ptr< ObjList_t > fpvObjList
List of registered ROOT objects.
Definition CbmQaIO.h:162
CbmQaIO(TString prefixName, std::shared_ptr< ObjList_t > pObjList=nullptr)
Constructor.
Definition CbmQaIO.cxx:19
TString fsRootFolderName
Name of root folder.
Definition CbmQaIO.h:157
TString fsConfigName
Name of configuration file.
Definition CbmQaIO.h:158
TPaveStats * GetHistStats(TH1 *pHist)
Finds/Creates stats window for a histogram.
Definition CbmQaUtil.cxx:28