9#include <dqm/analysis/modules/DQMHistReferenceModule.h>
31 B2DEBUG(1,
"DQMHistReference: Constructor done.");
39 gStyle->SetOptStat(0);
40 gStyle->SetStatStyle(1);
41 gStyle->SetOptDate(22);
43 B2DEBUG(1,
"DQMHistReference: initialized.");
48 B2DEBUG(1,
"DQMHistReference: beginRun called.");
54 B2DEBUG(1,
"DQMHistReference: reading references from input root file");
57 if (run_type ==
"") run_type =
"default";
59 B2INFO(
"DQMHistReference: run_type " << run_type);
63 if (it.ref_org)
delete it.ref_org;
64 if (it.ref_clone)
delete it.ref_clone;
67 B2INFO(
"DQMHistReference: clear m_pnode. size: " <<
m_pnode.size());
71 if (refFile->IsZombie()) {
72 B2INFO(
"DQMHistReference: reference file " <<
m_referenceFile <<
" does not exist. No references will be used!");
80 TIter nextkey(refFile->GetListOfKeys());
82 while ((key = (TKey*)nextkey())) {
83 if (key->IsFolder() &&
string(key->GetName()) ==
string(
"ref")) {
84 TDirectory* refdir = (TDirectory*)key->ReadObj();
85 TIter nextDetDir(refdir->GetListOfKeys());
88 while ((detDir = (TKey*)nextDetDir())) {
89 if (!detDir->IsFolder())
continue;
90 TIter nextTypeDir(((TDirectory*)detDir->ReadObj())->GetListOfKeys());
92 TDirectory* foundDir = NULL;
94 while ((typeDir = (TKey*)nextTypeDir())) {
95 if (!typeDir->IsFolder())
continue;
96 if (
string(typeDir->GetName()) == run_type) {
97 foundDir = (TDirectory*)typeDir->ReadObj();
100 if (
string(typeDir->GetName()) ==
"default") foundDir = (TDirectory*)typeDir->ReadObj();
102 string dirname = detDir->GetName();
104 B2INFO(
"No run type specific or default references available for " << dirname);
106 B2INFO(
"Reading reference histograms for " << dirname <<
" from run type folder: " << foundDir->GetName());
108 TIter next(foundDir->GetListOfKeys());
111 while ((hh = (TKey*)next())) {
112 if (hh->IsFolder())
continue;
113 TObject* obj = hh->ReadObj();
114 if (obj->IsA()->InheritsFrom(
"TH1")) {
116 if (h->GetDimension() == 1) {
117 string histname = h->GetName();
120 n.orghist_name = dirname +
"/" + histname;
121 n.refhist_name =
"ref/" + dirname +
"/" + histname;
122 h->SetName((n.refhist_name).c_str());
125 n.ref_clone =
nullptr;
141 B2INFO(
"DQMHistReference: insert reference to m_pnode. size: " <<
m_pnode.size());
148 TH1::AddDirectory(
false);
157 time_t now = time(0);
158 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&now));
159 B2INFO(
"[" << mbstr <<
"] before ref loop");
162 if (!it.ref_org)
continue;
166 TCanvas* canvas = it.canvas;
170 B2DEBUG(1,
"No canvas found for reference histogram " << it.orghist_name);
174 B2DEBUG(1,
"Canvas is without histogram -> no display " << it.orghist_name);
184 if (hist1->Integral() == 0)
continue;
193 if (abs(it.ref_org->Integral()) > 0) {
195 it.ref_clone->Reset();
196 it.ref_clone->Add(it.ref_org);
198 if (hist1->InheritsFrom(
"TH1C") or hist1->InheritsFrom(
"TH1S")) {
199 it.ref_clone =
new TH1F();
200 it.ref_org->Copy(*it.ref_clone);
201 }
else if (hist1->InheritsFrom(
"TH1I") or hist1->InheritsFrom(
"TH1L")) {
202 it.ref_clone =
new TH1D();
203 it.ref_org->Copy(*it.ref_clone);
206 it.ref_clone = (TH1*)it.ref_org->Clone();
208 it.ref_clone->SetLineStyle(2);
209 it.ref_clone->SetLineColor(3);
210 it.ref_clone->SetFillColor(0);
211 it.ref_clone->SetStats(kFALSE);
213 it.ref_clone->Scale(hist1->Integral() / it.ref_clone->Integral());
216 if (it.ref_clone->GetMaximum() > hist1->GetMaximum())
217 hist1->SetMaximum(1.1 * it.ref_clone->GetMaximum());
220 it.ref_clone->Draw(
"hist,same");
228 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&now));
229 B2INFO(
"[" << mbstr <<
"] after ref loop");
234 B2DEBUG(1,
"DQMHistReference: endRun called");
240 B2DEBUG(1,
"DQMHistReference: terminate called");
243 if (it.ref_org)
delete it.ref_org;
244 if (it.ref_clone)
delete it.ref_clone;
The base class for the histogram analysis module.
static const std::string & getRunType(void)
Get the Run Type.
TH1 * findHistInCanvas(const std::string &hname, TCanvas **canvas=nullptr)
Find histogram in corresponding canvas.
void initialize() override final
Initializer.
~DQMHistReferenceModule()
Destructor.
void loadReferenceHistos()
Reads reference histograms from input root file.
DQMHistReferenceModule()
Constructor.
std::string m_referenceFile
Reference Histogram Root file name.
std::vector< REFNODE > m_pnode
Struct for reference histogram
bool m_firstInRun
Is first event in run.
void terminate() override final
This method is called at the end of the event processing.
void event() override final
This method is called for each event.
void endRun() override final
This method is called if the current run ends.
void beginRun() override final
Called when entering a new run.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.
Struct for refence histogram info.