Function return flag histogram filled based on condition from TH1F source.
Flag values: -3: nonexisting Type -2: histogram is missing or masked -1: less than 100 samples, skip comparison 0: good much with reference 1: warning level = diff > 6 * sigma and < error level 2: error level = diff > 10 * sigma
23{
24 int iret = 0;
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()));
29 double NEvents = 0;
30 double flagInt = 0;
31 double flagrInt = 0;
32 for (int j = 0; j < hist->GetNbinsX(); j++) {
33 double val = hist->GetBinContent(j + 1);
34 NEvents += val;
35 val = val / ratio;
36 temp->SetBinContent(j + 1, val);
37 flagInt += temp->GetBinContent(j + 1);
38 flagrInt += refhist->GetBinContent(j + 1);
39 }
40 if (NEvents < 100) {
41 iret = -1;
42 flaghist->SetBinContent(bin + 1, -1);
43 return iret;
44 }
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
56 );
57 B2DEBUG(130, strDebugInfo.Data());
58 if (Type == 1) {
59 if ((fabs(flag - flagr) > ErrorLevel * (flagErr + flagrErr)) ||
60 (fabs(flagRMS - flagrRMS) > ErrorLevel * (flagRMSErr + flagrRMSErr)) ||
61 (fabs(flagInt - flagrInt) > ErrorLevel * (
sqrt(flagInt) +
sqrt(flagrInt)))
62 ) {
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)))
67 ) {
68 flaghist->SetBinContent(bin + 1, 1);
69 } else {
70 flaghist->SetBinContent(bin + 1, 0);
71 }
72 iret = 1;
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);
78 } else {
79 flaghist->SetBinContent(bin + 1, 0);
80 }
81 iret = 1;
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);
87 } else {
88 flaghist->SetBinContent(bin + 1, 0);
89 }
90 iret = 1;
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);
96 } else {
97 flaghist->SetBinContent(bin + 1, 0);
98 }
99 iret = 1;
100 } else if (Type == 5) {
101 if ((fabs(flag - flagr) > ErrorLevel * (flagErr + flagrErr)) ||
102 (fabs(flagInt - flagrInt) > ErrorLevel * (
sqrt(flagInt) +
sqrt(flagrInt)))
103 ) {
104 flaghist->SetBinContent(bin + 1, 2);
105 } else if ((fabs(flag - flagr) > WarningLevel * (flagErr + flagrErr)) ||
106 (fabs(flagInt - flagrInt) > WarningLevel * (
sqrt(flagInt) +
sqrt(flagrInt)))
107 ) {
108 flaghist->SetBinContent(bin + 1, 1);
109 } else {
110 flaghist->SetBinContent(bin + 1, 0);
111 }
112 iret = 1;
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);
120 } else {
121 flaghist->SetBinContent(bin + 1, 0);
122 }
123 iret = 1;
124 } else if (Type == 10) {
125 float flag2 = refhist->Chi2Test(temp.get());
126 flaghist->SetBinContent(bin + 1, 0);
127 if (flag2 > pars[1])
128 flaghist->SetBinContent(bin + 1, 2);
129 if (flag2 > pars[0])
130 flaghist->SetBinContent(bin + 1, 1);
131 iret = 1;
132 } else if (Type == 100) {
133 flaghist->SetBinContent(bin + 1, 0);
134 iret = 1;
135 } else {
136 flaghist->SetBinContent(bin + 1, -3);
137 iret = -1;
138 }
139 strDebugInfo = Form("SetFlag---> %f, type %i\n", flaghist->GetBinContent(bin + 1), Type);
140 B2DEBUG(130, strDebugInfo.Data());
141 return iret;
142}
double sqrt(double a)
sqrt for double