BmnRoot
Loading...
Searching...
No Matches
BmnHist.cxx
Go to the documentation of this file.
1#include "BmnHist.h"
2
4 : isShown(kFALSE)
5 , fServer(nullptr)
6 , frecoTree(nullptr)
7 , fDir(nullptr)
8 , refFile(nullptr)
9 , fPeriodID(PeriodID)
10 , fSetup(setup)
11{}
12
14
15void BmnHist::DrawRef(unique_ptr<TCanvas>& canGemStrip, vector<PadInfo*>* canGemStripPads)
16{
17 DrawRef(canGemStrip.get(), canGemStripPads);
18}
19
20void BmnHist::DrawRef(TCanvas* can, vector<PadInfo*>* canPads)
21{
22 for (size_t iPad = 0; iPad < canPads->size(); iPad++) {
23 TPad* pad = static_cast<TPad*>(can->cd(iPad + 1));
24 PadInfo* info = canPads->at(iPad);
25 if ((!pad) || (!info))
26 continue;
27 if (info->logx)
28 pad->SetLogx();
29 if (info->logy)
30 pad->SetLogy();
31 if (info->logz)
32 pad->SetLogz();
33 DrawPad(pad, info);
34 }
35 can->Update();
36 can->Modified();
37}
38
39void BmnHist::DrawPad(TVirtualPad* pad, PadInfo* info)
40{
41 pad->Clear();
42 Double_t maxy(0);
43 // TClass * cl_base(nullptr);
44 if (info->current) {
45 // maxy = info->current->GetMaximum();
46
47 maxy = info->current->GetBinContent(info->current->GetMaximumBin());
48 if (info->ref) {
49 if (info->normalize && (info->ref->Integral() > 0))
50 maxy = TMath::Max(maxy, info->ref->GetMaximum() * info->current->Integral() / info->ref->Integral());
51 else
52 maxy = TMath::Max(maxy, info->ref->GetMaximum());
53 }
54 }
55 if (info->aux.size()) {
56 for (size_t it = 0; it < info->aux.size(); it++) {
57 auto h_aux = info->aux.at(it);
58 maxy = TMath::Max(maxy, h_aux->GetBinContent(h_aux->GetMaximumBin()));
59 }
60 if (info->aux[0]->Integral() > 0)
61 info->aux[0]->SetMaximum(1.2 * maxy);
62 }
63 if (info->current) {
64 if (info->current->Integral() > 0)
65 info->current->SetMaximum(1.2 * maxy);
66 info->current->Draw(info->opt.c_str());
67 if (info->ref) {
68 if (info->normalize && (info->ref->Integral() > 0))
69 info->ref->DrawNormalized((info->opt + "same").c_str(), info->current->Integral());
70 else
71 info->ref->Draw((info->opt + "same").c_str());
72 }
73 }
74 for (size_t it = 0; it < info->aux.size(); it++) {
75 auto h = info->aux.at(it);
76 if (h) {
77 TString opt = (it || info->current) ? "same " : "";
78 if (it < info->auxOpt.size())
79 opt += info->auxOpt.at(it);
80 h->Draw(opt);
81 }
82 }
83 if (info->legend)
84 info->legend->Draw();
85 pad->Modified();
86}
87
88void BmnHist::FillPad(PadInfo* info, TTree* tree)
89{
90 // printf("%s dir %p\n", info->temp->GetName(), (void*)info->temp->GetDirectory());
91 info->temp->GetDirectory()->cd();
92 /*Long64_t dr = */ tree->Draw((info->variable + ">>" + info->temp->GetName()).c_str(), info->selection.c_str(),
93 (info->opt + " goff").c_str());
94 // printf("draw %lld integral %f\n", dr, *info->temp->GetIntegral());
95 // printf(" max %f\n", info->temp->GetMaximum());
96 info->current->Add(info->temp);
97 info->temp->Reset();
98}
99
101 TString FullName,
102 TString fTitle,
103 vector<PadInfo*> canPads,
104 vector<TString> Names)
105{
106 return LoadRefRun(refID, FullName, fTitle, canPads);
107}
108
109BmnStatus BmnHist::LoadRefRun(Int_t refID, TString FullName, TString fTitle, vector<PadInfo*> canPads)
110{
111 printf("Loading ref histos\n");
112 TFile* refFile = new TFile(FullName, "read");
113 if (refFile->IsOpen() == false) {
114 printf("Cannot open file %s !\n", FullName.Data());
115 return kBMNERROR;
116 }
117 TString refName = Form("ref%06d_", refID);
118 for (size_t iPad = 0; iPad < canPads.size(); iPad++) {
119 PadInfo* info = canPads[iPad];
120 if (!info)
121 continue;
122 if (!(info->current))
123 continue;
124 TString name = info->current->GetName();
125 delete info->ref;
126 info->ref = NULL;
127 TH1* tempH = NULL;
128 tempH = static_cast<TH1*>(refFile->Get(refName + fTitle + "_hists/" + refName + name));
129 if (tempH == NULL) {
130 tempH = static_cast<TH1*>(refFile->Get(fTitle + "_hists/" + name));
131 }
132 if (tempH == NULL) {
133 printf("Cannot load %s !\n", name.Data());
134 continue;
135 }
136 info->ref = static_cast<TH1*>(tempH->Clone(refName + name));
137 info->ref->SetLineColor(kRed);
138 info->ref->SetDirectory(0);
139 printf("Loaded %s \n", info->ref->GetName());
140 }
141 delete refFile;
142 refFile = NULL;
143 return kBMNSUCCESS;
144}
145
147{
148 if (PadInfo* info = br->GetPadInfo()) {
149 if (info->current)
150 info->current->Reset();
151 if (info->ref)
152 info->ref->Reset();
153 for (auto& h : info->aux)
154 if (h)
155 h->Reset();
156 } else {
157 for (auto& b : br->GetBranchesRef()) {
158 if (b)
159 ResetPadTree(b);
160 }
161 }
162 return;
163}
164
166{
167 if (!br)
168 return kBMNERROR;
169 if (PadInfo* info = br->GetPadInfo()) {
170 TVirtualPad* pad = info->padPtr;
171 DrawPad(pad, info);
172 } else {
173 for (auto& b : br->GetBranchesRef()) {
175 }
176 }
177 return kBMNSUCCESS;
178}
179
181{
182 if (!br)
183 return kBMNERROR;
184 if (PadInfo* info = br->GetPadInfo()) {
185 // TVirtualPad* pad = info->padPtr;
186 FillPad(info, tree);
187 } else {
188 for (auto& b : br->GetBranchesRef()) {
189 FillPadFromTree(b, tree);
190 }
191 }
192 return kBMNSUCCESS;
193}
194
196{
197 h->SetTitleSize(0.07, "XY");
198 h->SetLabelSize(0.07, "XY");
199 h->GetXaxis()->SetTitleColor(kOrange + 10);
200 h->GetXaxis()->SetTitleOffset(0.7);
201 h->GetXaxis()->SetTitleSize(0.06);
202 h->GetYaxis()->SetTitleColor(kOrange + 10);
203 h->GetYaxis()->SetTitleOffset(0.6);
204}
TCanvas * can(nullptr)
BmnStatus
Definition BmnEnums.h:24
@ kBMNERROR
Definition BmnEnums.h:26
@ kBMNSUCCESS
Definition BmnEnums.h:25
BmnSetup
Definition BmnEnums.h:89
Int_t refID
Definition BmnHist.h:92
static void DrawRef(unique_ptr< TCanvas > &canGemStrip, vector< PadInfo * > *canGemStripPads)
Definition BmnHist.cxx:15
static void DrawPad(TVirtualPad *pad, PadInfo *info)
Definition BmnHist.cxx:39
static BmnStatus DrawPadFromTree(BmnPadBranch *br)
Definition BmnHist.cxx:165
static void ResetPadTree(BmnPadBranch *br)
Definition BmnHist.cxx:146
static void FillPad(PadInfo *info, TTree *tree)
Definition BmnHist.cxx:88
static void SetHistStyleTH1(TH1 *h)
Definition BmnHist.cxx:195
static BmnStatus FillPadFromTree(BmnPadBranch *br, TTree *tree)
Definition BmnHist.cxx:180
virtual ~BmnHist()
Definition BmnHist.cxx:13
static BmnStatus LoadRefRun(Int_t refID, TString FullName, TString fTitle, vector< PadInfo * > canPads, vector< TString > Names)
Definition BmnHist.cxx:100
TFile * refFile
Definition BmnHist.h:93
BmnHist(Int_t periodID=7, BmnSetup setup=kBMNSETUP)
Definition BmnHist.cxx:3
Node of pad tree.
vector< BmnPadBranch * > & GetBranchesRef()
PadInfo * GetPadInfo()
Storage for pad content and it's options.
Definition PadInfo.h:20
string selection
Definition PadInfo.h:91
string opt
Definition PadInfo.h:88
bool normalize
Definition PadInfo.h:87
bool logy
Definition PadInfo.h:85
string variable
Definition PadInfo.h:90
TH1 * ref
Definition PadInfo.h:79
bool logz
Definition PadInfo.h:86
vector< TH1 * > aux
Definition PadInfo.h:80
vector< TString > auxOpt
Definition PadInfo.h:81
TLegend * legend
Definition PadInfo.h:82
TH1 * current
Definition PadInfo.h:78
TH1 * temp
Definition PadInfo.h:76
bool logx
Definition PadInfo.h:84
Definition setup.py:1