9#include <dqm/utilities/DQMCommonUtils.h>
11#include <framework/database/DBImportObjPtr.h>
12#include <framework/database/IntervalOfValidity.h>
13#include <framework/database/DBObjPtr.h>
25 float WarningLevel = 6.0;
26 float ErrorLevel = 10.0;
27 auto temp = std::unique_ptr<TH1F>(
new TH1F(
"temp",
"temp", hist->GetNbinsX(), hist->GetXaxis()->GetXmin(),
28 hist->GetXaxis()->GetXmax()));
32 for (
int j = 0; j < hist->GetNbinsX(); j++) {
33 double val = hist->GetBinContent(j + 1);
36 temp->SetBinContent(j + 1, val);
37 flagInt += temp->GetBinContent(j + 1);
38 flagrInt += refhist->GetBinContent(j + 1);
42 flaghist->SetBinContent(bin + 1, -1);
45 double flag = temp->GetMean();
46 double flagErr = temp->GetMeanError();
47 double flagRMS = temp->GetRMS();
48 double flagRMSErr = temp->GetRMSError();
49 double flagr = refhist->GetMean();
50 double flagrErr = refhist->GetMeanError();
51 double flagrRMS = refhist->GetRMS();
52 double flagrRMSErr = refhist->GetRMSError();
53 TString strDebugInfo = Form(
"Conditions for Flag--->\n source %f %f+-%f %f+-%f\n referen %f %f+-%f %f+-%f\n",
54 flagInt, flag, flagErr, flagRMS, flagRMSErr,
55 flagrInt, flagr, flagrErr, flagrRMS, flagrRMSErr
57 B2DEBUG(130, strDebugInfo.Data());
59 if ((fabs(flag - flagr) > ErrorLevel * (flagErr + flagrErr)) ||
60 (fabs(flagRMS - flagrRMS) > ErrorLevel * (flagRMSErr + flagrRMSErr)) ||
61 (fabs(flagInt - flagrInt) > ErrorLevel * (
sqrt(flagInt) +
sqrt(flagrInt)))
63 flaghist->SetBinContent(bin + 1, 2);
64 }
else if ((fabs(flag - flagr) > WarningLevel * (flagErr + flagrErr)) ||
65 (fabs(flagRMS - flagrRMS) > WarningLevel * (flagRMSErr + flagrRMSErr)) ||
66 (fabs(flagInt - flagrInt) > WarningLevel * (
sqrt(flagInt) +
sqrt(flagrInt)))
68 flaghist->SetBinContent(bin + 1, 1);
70 flaghist->SetBinContent(bin + 1, 0);
73 }
else if (Type == 2) {
74 if (fabs(flagInt - flagrInt) > ErrorLevel * (
sqrt(flagInt) +
sqrt(flagrInt))) {
75 flaghist->SetBinContent(bin + 1, 2);
76 }
else if (fabs(flagInt - flagrInt) > WarningLevel * (
sqrt(flagInt) +
sqrt(flagrInt))) {
77 flaghist->SetBinContent(bin + 1, 1);
79 flaghist->SetBinContent(bin + 1, 0);
82 }
else if (Type == 3) {
83 if (fabs(flag - flagr) > ErrorLevel * (flagErr + flagrErr)) {
84 flaghist->SetBinContent(bin + 1, 2);
85 }
else if (fabs(flag - flagr) > WarningLevel * (flagErr + flagrErr)) {
86 flaghist->SetBinContent(bin + 1, 1);
88 flaghist->SetBinContent(bin + 1, 0);
91 }
else if (Type == 4) {
92 if (fabs(flagRMS - flagrRMS) > ErrorLevel * (flagRMSErr + flagrRMSErr)) {
93 flaghist->SetBinContent(bin + 1, 2);
94 }
else if (fabs(flagRMS - flagrRMS) > WarningLevel * (flagRMSErr + flagrRMSErr)) {
95 flaghist->SetBinContent(bin + 1, 1);
97 flaghist->SetBinContent(bin + 1, 0);
100 }
else if (Type == 5) {
101 if ((fabs(flag - flagr) > ErrorLevel * (flagErr + flagrErr)) ||
102 (fabs(flagInt - flagrInt) > ErrorLevel * (
sqrt(flagInt) +
sqrt(flagrInt)))
104 flaghist->SetBinContent(bin + 1, 2);
105 }
else if ((fabs(flag - flagr) > WarningLevel * (flagErr + flagrErr)) ||
106 (fabs(flagInt - flagrInt) > WarningLevel * (
sqrt(flagInt) +
sqrt(flagrInt)))
108 flaghist->SetBinContent(bin + 1, 1);
110 flaghist->SetBinContent(bin + 1, 0);
113 }
else if (Type == 9) {
114 flagInt = temp->GetBinContent(bin + 1);
115 flagrInt = refhist->GetBinContent(bin + 1);
116 if (fabs(flagInt - flagrInt) > ErrorLevel * (
sqrt(flagInt) +
sqrt(flagrInt))) {
117 flaghist->SetBinContent(bin + 1, 2);
118 }
else if (fabs(flagInt - flagrInt) > WarningLevel * (
sqrt(flagInt) +
sqrt(flagrInt))) {
119 flaghist->SetBinContent(bin + 1, 1);
121 flaghist->SetBinContent(bin + 1, 0);
124 }
else if (Type == 10) {
125 float flag2 = refhist->Chi2Test(temp.get());
126 flaghist->SetBinContent(bin + 1, 0);
128 flaghist->SetBinContent(bin + 1, 2);
130 flaghist->SetBinContent(bin + 1, 1);
132 }
else if (Type == 100) {
133 flaghist->SetBinContent(bin + 1, 0);
136 flaghist->SetBinContent(bin + 1, -3);
139 strDebugInfo = Form(
"SetFlag---> %f, type %i\n", flaghist->GetBinContent(bin + 1), Type);
140 B2DEBUG(130, strDebugInfo.Data());
148 auto histF = std::unique_ptr<TH1F>(
new TH1F(
"histF",
"histF", hist->GetNbinsX(), hist->GetXaxis()->GetXmin(),
149 hist->GetXaxis()->GetXmax()));
150 auto refhistF = std::unique_ptr<TH1F>(
new TH1F(
"refhistF",
"refhistF", refhist->GetNbinsX(), refhist->GetXaxis()->GetXmin(),
151 refhist->GetXaxis()->GetXmax()));
152 for (
int j = 0; j < hist->GetNbinsX(); j++) {
153 histF->SetBinContent(j + 1, hist->GetBinContent(j + 1));
154 refhistF->SetBinContent(j + 1, refhist->GetBinContent(j + 1));
156 int ret =
SetFlag(Type, bin, pars, ratio, histF.get(), refhistF.get(), flaghist);
164 TString Name = Form(
"%s_Ref", HistoDB->GetName());
166 DBHisto.
construct(HistoDB->GetNbinsX() + 3);
167 double* Content =
new double[HistoDB->GetNbinsX() + 3];
168 Content[0] = HistoDB->GetNbinsX();
169 Content[1] = HistoDB->GetXaxis()->GetXmin();
170 Content[2] = HistoDB->GetXaxis()->GetXmax();
171 for (
int i = 0; i < HistoDB->GetNbinsX(); i++) {
172 Content[i + 3] = HistoDB->GetBinContent(i + 1);
174 DBHisto->SetElements(Content);
183 TString Name = Form(
"%s_Ref", HistoDB->GetName());
185 DBHisto.
construct(HistoDB->GetNbinsX() + 3);
186 double* Content =
new double[HistoDB->GetNbinsX() + 3];
187 Content[0] = HistoDB->GetNbinsX();
188 Content[1] = HistoDB->GetXaxis()->GetXmin();
189 Content[2] = HistoDB->GetXaxis()->GetXmax();
190 for (
int i = 0; i < HistoDB->GetNbinsX(); i++) {
191 Content[i + 3] = HistoDB->GetBinContent(i + 1);
193 DBHisto->SetElements(Content);
202 TString Name = Form(
"%s_Ref", HistoDB[0]->GetName());
204 DBHisto.
construct(number * HistoDB[0]->GetNbinsX() + 3);
205 double* Content =
new double[number * HistoDB[0]->GetNbinsX() + 3];
206 Content[0] = HistoDB[0]->GetNbinsX();
207 Content[1] = HistoDB[0]->GetXaxis()->GetXmin();
208 Content[2] = HistoDB[0]->GetXaxis()->GetXmax();
209 for (
int j = 0; j < number; j++) {
210 for (
int i = 0; i < HistoDB[j]->GetNbinsX(); i++) {
211 Content[j * HistoDB[j]->GetNbinsX() + i + 3] = HistoDB[j]->GetBinContent(i + 1);
214 DBHisto->SetElements(Content);
223 TString Name = Form(
"%s_Ref", HistoDB[0]->GetName());
225 DBHisto.
construct(number * HistoDB[0]->GetNbinsX() + 3);
226 double* Content =
new double[number * HistoDB[0]->GetNbinsX() + 3];
227 Content[0] = HistoDB[0]->GetNbinsX();
228 Content[1] = HistoDB[0]->GetXaxis()->GetXmin();
229 Content[2] = HistoDB[0]->GetXaxis()->GetXmax();
230 for (
int j = 0; j < number; j++) {
231 for (
int i = 0; i < HistoDB[j]->GetNbinsX(); i++) {
232 Content[j * HistoDB[j]->GetNbinsX() + i + 3] = HistoDB[j]->GetBinContent(i + 1);
235 DBHisto->SetElements(Content);
243 TString Name = Form(
"%s_Ref", HistoDB->GetName());
248 if (HistoDB->GetNbinsX() != (
int)DBHisto->GetMatrixArray()[0]) ret = 0;
249 if (HistoDB->GetXaxis()->GetXmin() != DBHisto->GetMatrixArray()[1]) ret = 0;
250 if (HistoDB->GetXaxis()->GetXmax() != DBHisto->GetMatrixArray()[2]) ret = 0;
252 for (
int i = 0; i < HistoDB->GetNbinsX(); i++) {
253 HistoDB->SetBinContent(i + 1, (
int)DBHisto->GetMatrixArray()[i + 3]);
258 B2INFO(
"ERROR to open reference histogram: " << Name.Data());
266 TString Name = Form(
"%s_Ref", HistoDB->GetName());
271 if (HistoDB->GetNbinsX() != (
int)DBHisto->GetMatrixArray()[0]) ret = 0;
272 if (HistoDB->GetXaxis()->GetXmin() != DBHisto->GetMatrixArray()[1]) ret = 0;
273 if (HistoDB->GetXaxis()->GetXmax() != DBHisto->GetMatrixArray()[2]) ret = 0;
275 for (
int i = 0; i < HistoDB->GetNbinsX(); i++) {
276 HistoDB->SetBinContent(i + 1, (
int)DBHisto->GetMatrixArray()[i + 3]);
281 B2INFO(
"ERROR to open reference histogram: " << Name.Data());
289 TString Name = Form(
"%s_Ref", HistoDB[0]->GetName());
294 if (HistoDB[0]->GetNbinsX() != (
int)DBHisto->GetMatrixArray()[0]) ret = 0;
295 if (HistoDB[0]->GetXaxis()->GetXmin() != DBHisto->GetMatrixArray()[1]) ret = 0;
296 if (HistoDB[0]->GetXaxis()->GetXmax() != DBHisto->GetMatrixArray()[2]) ret = 0;
297 for (
int j = 0; j < number; j++) {
298 for (
int i = 0; i < HistoDB[j]->GetNbinsX(); i++) {
299 HistoDB[j]->SetBinContent(i + 1, DBHisto->GetMatrixArray()[j * HistoDB[j]->GetNbinsX() + i + 3]);
304 B2INFO(
"ERROR to open reference histogram: " << Name.Data());
312 TString Name = Form(
"%s_Ref", HistoDB[0]->GetName());
317 if (HistoDB[0]->GetNbinsX() != (
int)DBHisto->GetMatrixArray()[0]) ret = 0;
318 if (HistoDB[0]->GetXaxis()->GetXmin() != DBHisto->GetMatrixArray()[1]) ret = 0;
319 if (HistoDB[0]->GetXaxis()->GetXmax() != DBHisto->GetMatrixArray()[2]) ret = 0;
320 for (
int j = 0; j < number; j++) {
321 for (
int i = 0; i < HistoDB[j]->GetNbinsX(); i++) {
322 HistoDB[j]->SetBinContent(i + 1, DBHisto->GetMatrixArray()[j * HistoDB[j]->GetNbinsX() + i + 3]);
327 B2INFO(
"ERROR to open reference histogram: " << Name.Data());
bool isValid() const
Check whether a valid object was obtained from the database.
bool import(const IntervalOfValidity &iov)
Import the object to database.
Class for importing a single object to the database.
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
Class for accessing objects in the database.
static void CreateDBHisto(TH1F *HistoBD)
Function for filling of TH1F histogram to database.
static void CreateDBHistoGroup(TH1F **HistoBD, int number)
Function for filling of group of TH1F histogram to database.
static int LoadDBHistoGroup(TH1F **HistoBD, int number)
Function for loading of group of TH1F histogram from database.
static int SetFlag(int Type, int bin, const double *pars, double ratio, TH1F *hist, TH1F *refhist, TH1I *flaghist)
Function return flag histogram filled based on condition from TH1F source.
static int LoadDBHisto(TH1F *HistoBD)
Function for loading of TH1F histogram from database.
A class that describes the interval of experiments/runs for which an object in the database is valid.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.