@@ -144,3 +144,33 @@ TEST(THn, GetBinCenter)
144144 EXPECT_DOUBLE_EQ (centers.at (0 ), 2.5 );
145145 EXPECT_DOUBLE_EQ (centers.at (1 ), -1.5 );
146146}
147+
148+ TEST (THn, ErrorsOfProjection)
149+ {
150+ const int bins[] = {10 , 10 , 10 , 10 };
151+ const double xmin[] = {0 , 0 , 0 , 0 };
152+ const double xmax[] = {10 , 10 , 10 , 10 };
153+ THnF thn (" thn" , " " , 4 , bins, xmin, xmax);
154+ thn.Sumw2 ();
155+
156+ const double coordinates1[]{0.5 , 0.5 , 0.5 , 0.5 };
157+
158+ for (int i = 0 ; i < 9 ; i++) {
159+ thn.Fill (coordinates1, 0.1 );
160+ const double coordinates2[]{1.5 , 1.5 , 0.5 + i, 0.5 + i};
161+ thn.Fill (coordinates2, 2 .);
162+ }
163+
164+ const Int_t dimensions[] = {0 , 1 };
165+ // Despite the option "E", the errors are resetted to sqrt(N) instead of keeping the original ones
166+ std::unique_ptr<THnBase> proj{thn.ProjectionND (2 , dimensions, " E" )};
167+
168+ const auto projectedBin = proj->GetBin (coordinates1);
169+ EXPECT_FLOAT_EQ (proj->GetBinContent (projectedBin), 0.9 );
170+ EXPECT_FLOAT_EQ (proj->GetBinError (projectedBin), 0.3 );
171+
172+ const double coordinates2[]{1.5 , 1.5 };
173+ const auto projectedBin2 = proj->GetBin (coordinates2);
174+ EXPECT_FLOAT_EQ (proj->GetBinContent (projectedBin2), 18 .);
175+ EXPECT_FLOAT_EQ (proj->GetBinError (projectedBin2), 6 .);
176+ }
0 commit comments