9#include <dqm/analysis/modules/DQMHistReferenceModule.h>
31 B2DEBUG(1,
"DQMHistReference: Constructor done.");
39 B2DEBUG(1,
"DQMHistReference: initialized.");
44 B2DEBUG(1,
"DQMHistReference: beginRun called.");
51 TH1::AddDirectory(
false);
53 B2DEBUG(1,
"DQMHistReference: reading references from input root file");
56 if (run_type ==
"") run_type =
"default";
58 B2INFO(
"DQMHistReference: run_type " << run_type);
62 if (refFile->IsZombie()) {
63 B2INFO(
"DQMHistReference: reference file " <<
m_referenceFileName <<
" does not exist. No references will be used!");
71 TIter nextkey(refFile->GetListOfKeys());
73 while ((key = (TKey*)nextkey())) {
74 if (key->IsFolder() &&
string(key->GetName()) ==
string(
"ref")) {
75 TDirectory* refdir = (TDirectory*)key->ReadObj();
76 TIter nextDetDir(refdir->GetListOfKeys());
79 while ((detDir = (TKey*)nextDetDir())) {
80 if (!detDir->IsFolder())
continue;
81 TIter nextTypeDir(((TDirectory*)detDir->ReadObj())->GetListOfKeys());
83 TDirectory* foundDir = NULL;
85 while ((typeDir = (TKey*)nextTypeDir())) {
86 if (!typeDir->IsFolder())
continue;
87 if (
string(typeDir->GetName()) == run_type) {
88 foundDir = (TDirectory*)typeDir->ReadObj();
91 if (
string(typeDir->GetName()) ==
"default") foundDir = (TDirectory*)typeDir->ReadObj();
93 string dirname = detDir->GetName();
95 B2INFO(
"No run type specific or default references available for " << dirname);
97 B2INFO(
"Reading reference histograms for " << dirname <<
" from run type folder: " << foundDir->GetName());
99 TIter next(foundDir->GetListOfKeys());
102 while ((hh = (TKey*)next())) {
103 if (hh->IsFolder())
continue;
104 TObject* obj = hh->ReadObj();
105 if (obj->IsA()->InheritsFrom(
"TH1")) {
107 string histname = h->GetName();
108 std::string name = dirname +
"/" + histname;
110 n.m_orghist_name = name;
111 n.m_refhist_name =
"ref/" + name;
112 h->SetName((n.m_refhist_name).c_str());
115 n.setRefCopy(
nullptr);
116 n.setCanvas(
nullptr);
128 B2INFO(
"DQMHistReference: read references done");
135 TH1::AddDirectory(
false);
136 gStyle->SetOptStat(0);
137 gStyle->SetStatStyle(1);
138 gStyle->SetOptDate(22);
142 time_t now = time(0);
143 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&now));
144 B2INFO(
"[" << mbstr <<
"] before ref loop");
147 TH1* ref = it.second.getRefHist();
149 TCanvas* canvas = it.second.getCanvas();
154 B2DEBUG(1,
"Canvas is without histogram -> no display " << it.second.m_orghist_name);
164 B2DEBUG(1,
"No canvas found for reference histogram " << it.second.m_orghist_name);
167 if (hist1->Integral() == 0)
continue;
177 if (abs(ref->Integral()) > 0) {
178 auto refCopy =
scaleReference(1, hist1, it.second.getReference());
181 if (refCopy->GetMaximum() > hist1->GetMaximum())
182 hist1->SetMaximum(1.1 * refCopy->GetMaximum());
185 refCopy->Draw(
"hist,same");
189 B2DEBUG(2,
"Adding ref: " << it.second.m_orghist_name <<
" " << ref->GetName() <<
" " << ref);
197 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&now));
198 B2INFO(
"[" << mbstr <<
"] after ref loop");
203 B2DEBUG(1,
"DQMHistReference: endRun called");
208 B2DEBUG(1,
"DQMHistReference: terminate called");
The base class for the histogram analysis module.
static TH1 * scaleReference(int scaling, const TH1 *hist, TH1 *ref)
Using the original and reference, create scaled version.
static const std::string & getRunType(void)
Get the Run Type.
static RefList & getRefList()
Get the list of the reference histograms.
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.
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.
std::string m_referenceFileName
Reference Histogram Root file name.
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.