27 #include <THnSparse.h> 28 #include <THashList.h> 30 #include <TObjArray.h> 31 #include <TObjString.h> 50 TNamed(name, Form(
"Histogram container %s", name)),
55 fHistos->SetName(Form(
"histos%s", name));
65 THashList *foundgroup =
FindGroup(groupname);
71 THashList *parentgroup =
FindGroup(parentname);
73 THashList *childgroup =
new THashList();
74 childgroup->SetName(
histname(groupname));
75 childgroup->SetOwner();
76 parentgroup->Add(childgroup);
84 if(parent->FindObject(hname)){
85 Fatal(
"THistManager::CreateTH1",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
88 TH1* h =
new TH1D(hname, title, nbins, xmin, xmax);
90 optionstring.ToLower();
91 if(optionstring.Contains(
"s"))
101 if(parent->FindObject(hname)){
102 Fatal(
"THistManager::CreateTH1",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
105 TH1* h =
new TH1D(hname, title, nbins, xbins);
107 optionstring.ToLower();
108 if(optionstring.Contains(
"s"))
118 if(parent->FindObject(hname)){
119 Fatal(
"THistManager::CreateTH1",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
122 TH1* h =
new TH1D(hname, title, xbins.GetSize()-1, xbins.GetArray());
124 optionstring.ToLower();
125 if(optionstring.Contains(
"s"))
135 }
catch(std::exception &e){
136 Fatal(
"THistManager::CreateTH1",
"Exception raised: %s", e.what());
138 return CreateTH1(name, title, myxbins, opt);
145 if(parent->FindObject(hname)){
146 Fatal(
"THistManager::CreateTH2",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
149 TH2* h =
new TH2D(hname, title, nbinsx, xmin, xmax, nbinsy, ymin, ymax);
151 optionstring.ToLower();
152 if(optionstring.Contains(
"s"))
162 if(parent->FindObject(hname)){
163 Fatal(
"THistManager::CreateTH2",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
166 TH2* h =
new TH2D(hname, title, nbinsx, xbins, nbinsy, ybins);
168 optionstring.ToLower();
169 if(optionstring.Contains(
"s"))
179 if(parent->FindObject(hname)){
180 Fatal(
"THistManager::CreateTH2",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
183 TH2* h =
new TH2D(hname, title, xbins.GetSize() - 1, xbins.GetArray(), ybins.GetSize() - 1, ybins.GetArray());
185 optionstring.ToLower();
186 if(optionstring.Contains(
"s"))
196 }
catch (std::exception &e) {
197 Fatal(
"THistManager::CreateTH2 (x-dir)",
"Exception raised: %s", e.what());
201 }
catch (std::exception &e) {
202 Fatal(
"THistManager::CreateTH2 (y-dir)",
"Exception raised: %s", e.what());
205 return CreateTH2(name, title, myxbins, myybins, opt);
208 TH3*
THistManager::CreateTH3(
const char* name,
const char*
title,
int nbinsx,
double xmin,
double xmax,
int nbinsy,
double ymin,
double ymax,
int nbinsz,
double zmin,
double zmax,
Option_t *opt) {
212 if(parent->FindObject(hname)){
213 Fatal(
"THistManager::CreateTH3",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
216 TH3* h =
new TH3D(hname, title, nbinsx, xmin, xmax, nbinsy, ymin, ymax, nbinsz, zmin, zmax);
218 optionstring.ToLower();
219 if(optionstring.Contains(
"s"))
229 if(parent->FindObject(hname)){
230 Fatal(
"THistManager::CreateTH3",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
233 TH3* h =
new TH3D(hname, title, nbinsx, xbins, nbinsy, ybins, nbinsz, zbins);
235 optionstring.ToLower();
236 if(optionstring.Contains(
"s"))
246 if(parent->FindObject(hname)){
247 Fatal(
"THistManager::CreateTH3",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
250 TH3* h =
new TH3D(hname, title, xbins.GetSize()-1, xbins.GetArray(), ybins.GetSize()-1, ybins.GetArray(), zbins.GetSize()-1, zbins.GetArray());
252 optionstring.ToLower();
253 if(optionstring.Contains(
"s"))
260 TArrayD myxbins, myybins, myzbins;
263 }
catch (std::exception &e) {
264 Fatal(
"THistManager::CreateTH2 (x-dir)",
"Exception raised: %s", e.what());
268 }
catch (std::exception &e) {
269 Fatal(
"THistManager::CreateTH2 (y-dir)",
"Exception raised: %s", e.what());
273 }
catch (std::exception &e) {
274 Fatal(
"THistManager::CreateTH2 (z-dir)",
"Exception raised: %s", e.what());
277 return CreateTH3(name, title, myxbins, myybins, myzbins);
284 if(parent->FindObject(hname)){
285 Fatal(
"THistManager::CreateTHnSparse",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
288 THnSparse* h =
new THnSparseD(hname, title, ndim, nbins, min, max);
290 optionstring.ToLower();
291 if(optionstring.Contains(
"s"))
301 if(parent->FindObject(hname)){
302 Fatal(
"THistManager::CreateTHnSparse",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
305 TArrayD xmin(ndim), xmax(ndim);
307 for(
int idim = 0; idim < ndim; ++idim){
308 const TAxis &myaxis = *(axes[idim]);
309 nbins[idim] = myaxis.GetNbins();
310 xmin[idim] = myaxis.GetXmin();
311 xmax[idim] = myaxis.GetXmax();
313 THnSparseD *hsparse =
new THnSparseD(hname, title, ndim, nbins.GetArray(), xmin.GetArray(), xmax.GetArray());
314 for(
int id = 0;
id < ndim; ++id)
315 *(hsparse->GetAxis(
id)) = *(axes[
id]);
317 optionstring.ToLower();
318 if(optionstring.Contains(
"s"))
320 parent->Add(hsparse);
328 if(parent->FindObject(hname)){
329 Fatal(
"THistManager::CreateTHnSparse",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
332 TArrayD xmin(ndim), xmax(ndim);
334 std::vector<TArrayD> binnings;
335 for(
int idim = 0; idim < ndim; ++idim){
336 const TBinning &myaxis = *(axes[idim]);
339 nbins[idim] = binEdges.GetSize()-1;
340 xmin[idim] = binEdges[0];
341 xmax[idim] = binEdges[binEdges.GetSize()-1];
342 binnings.push_back(binEdges);
344 THnSparseD *hsparse =
new THnSparseD(hname, title, ndim, nbins.GetArray(), xmin.GetArray(), xmax.GetArray());
345 for(
int id = 0;
id < ndim; ++id){
346 TArrayD &binEdges = binnings[id];
347 hsparse->GetAxis(
id)->Set(binEdges.GetSize()-1, binEdges.GetArray());
350 optionstring.ToLower();
351 if(optionstring.Contains(
"s"))
353 parent->Add(hsparse);
361 if(parent->FindObject(hname))
362 Fatal(
"THistManager::CreateTProfile",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
363 TProfile *hist =
new TProfile(hname, title, nbinsX, xmin, xmax, opt);
371 if(parent->FindObject(hname))
372 Fatal(
"THistManager::CreateTHnSparse",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
373 TProfile *hist =
new TProfile(hname, title, nbinsX, xbins, opt);
381 if(parent->FindObject(hname))
382 Fatal(
"THistManager::CreateTHnSparse",
"Object %s already exists in group %s", hname.Data(), dirname.Data());
383 TProfile *hist =
new TProfile(hname.Data(),
title, xbins.GetSize()-1, xbins.GetArray(), opt);
391 }
catch (std::exception &e){
392 Fatal(
"THistManager::CreateProfile",
"Exception raised: %s", e.what());
400 if(parent->FindObject(o->GetName())){
401 Fatal(
"THistManager::SetObject",
"Parent %s does not exist", strcmp(group,
"/") ? group :
"");
404 if(!(dynamic_cast<THnBase *>(o) || dynamic_cast<TH1 *>(o))){
405 Fatal(
"THistManager::SetObject",
"Object %s is not of a histogram type",o->GetName());
415 Fatal(
"THistManager::FillTH1",
"Parent group %s does not exist", dirname.Data());
418 TH1 *hist =
dynamic_cast<TH1 *
>(parent->FindObject(hname));
420 Fatal(
"THistManager::FillTH1",
"Histogram %s not found in parent group %s", hname.Data(), dirname.Data());
424 if(optionstring.Contains(
"w")){
426 Int_t bin = hist->GetXaxis()->FindBin(x);
428 if(bin != 0 && bin != hist->GetXaxis()->GetNbins())
429 weight = 1./hist->GetXaxis()->GetBinWidth(bin);
431 hist->Fill(x, weight);
438 Fatal(
"THistManager::FillTH1",
"Parent group %s does not exist", dirname.Data());
441 TH1 *hist =
dynamic_cast<TH1 *
>(parent->FindObject(hname));
443 Fatal(
"THistManager::FillTH1",
"Histogram %s not found in parent group %s", hname.Data(), dirname.Data());
447 if(optionstring.Contains(
"w")){
450 Int_t bin = hist->GetXaxis()->FindBin(label);
452 if(bin != 0 && bin != hist->GetXaxis()->GetNbins())
453 weight = 1./hist->GetXaxis()->GetBinWidth(bin);
455 hist->Fill(label, weight);
462 Fatal(
"THistManager::FillTH2",
"Parent group %s does not exist", dirname.Data());
465 TH2 *hist =
dynamic_cast<TH2 *
>(parent->FindObject(hname));
467 Fatal(
"THistManager::FillTH2",
"Histogram %s not found in parent group %s", hname.Data(), dirname.Data());
471 Double_t myweight = optstring.Contains(
"w") ? 1. : weight;
472 if(optstring.Contains(
"wx")){
473 Int_t binx = hist->GetXaxis()->FindBin(x);
474 if(binx != 0 && binx != hist->GetXaxis()->GetNbins()) myweight *= 1./hist->GetXaxis()->GetBinWidth(binx);
476 if(optstring.Contains(
"wy")){
477 Int_t biny = hist->GetYaxis()->FindBin(y);
478 if(biny != 0 && biny != hist->GetYaxis()->GetNbins()) myweight *= 1./hist->GetYaxis()->GetBinWidth(biny);
480 hist->Fill(x, y, myweight);
487 Fatal(
"THistManager::FillTH2",
"Parent group %s does not exist", dirname.Data());
490 TH2 *hist =
dynamic_cast<TH2 *
>(parent->FindObject(hname));
492 Fatal(
"THistManager::FillTH2",
"Histogram %s not found in parent group %s", hname.Data(), dirname.Data());
496 Double_t myweight = optstring.Contains(
"w") ? 1. : weight;
497 if(optstring.Contains(
"wx")){
498 Int_t binx = hist->GetXaxis()->FindBin(point[0]);
499 if(binx != 0 && binx != hist->GetXaxis()->GetNbins()) myweight *= 1./hist->GetXaxis()->GetBinWidth(binx);
501 if(optstring.Contains(
"wy")){
502 Int_t biny = hist->GetYaxis()->FindBin(point[1]);
503 if(biny != 0 && biny != hist->GetYaxis()->GetNbins()) myweight *= 1./hist->GetYaxis()->GetBinWidth(biny);
505 hist->Fill(point[0], point[1], weight);
512 Fatal(
"THistManager::FillTH2",
"Parent group %s does not exist", dirname.Data());
515 TH2 *hist =
dynamic_cast<TH2 *
>(parent->FindObject(hname));
517 Fatal(
"THistManager::FillTH2",
"Histogram %s not found in parent group %s", hname.Data(), dirname.Data());
521 Double_t myweight = optstring.Contains(
"w") ? 1. : weight;
522 if(optstring.Contains(
"wx")){
523 Int_t binx = hist->GetXaxis()->FindBin(labelY);
524 if(binx != 0 && binx != hist->GetXaxis()->GetNbins()) myweight *= 1./hist->GetXaxis()->GetBinWidth(binx);
526 if(optstring.Contains(
"wy")){
527 Int_t biny = hist->GetYaxis()->FindBin(labelX);
528 if(biny != 0 && biny != hist->GetYaxis()->GetNbins()) myweight *= 1./hist->GetYaxis()->GetBinWidth(biny);
530 hist->Fill(labelX, labelY, weight);
537 Fatal(
"THistManager::FillTH3",
"Parent group %s does not exist", dirname.Data());
540 TH3 *hist =
dynamic_cast<TH3 *
>(parent->FindObject(hname));
542 Fatal(
"THistManager::FillTH3",
"Histogram %s not found in parent group %s", hname.Data(), dirname.Data());
546 Double_t myweight = optstring.Contains(
"w") ? 1. : weight;
547 if(optstring.Contains(
"wx")){
548 Int_t binx = hist->GetXaxis()->FindBin(x);
549 if(binx != 0 && binx != hist->GetXaxis()->GetNbins()) myweight *= 1./hist->GetXaxis()->GetBinWidth(binx);
551 if(optstring.Contains(
"wy")){
552 Int_t biny = hist->GetYaxis()->FindBin(y);
553 if(biny != 0 && biny != hist->GetYaxis()->GetNbins()) myweight *= 1./hist->GetYaxis()->GetBinWidth(biny);
555 if(optstring.Contains(
"wz")){
556 Int_t binz = hist->GetZaxis()->FindBin(z);
557 if(binz != 0 && binz != hist->GetZaxis()->GetNbins()) myweight *= 1./hist->GetZaxis()->GetBinWidth(binz);
559 hist->Fill(x, y, z, weight);
566 Fatal(
"THistManager::FillTH3",
"Parent group %s does not exist", dirname.Data());
569 TH3 *hist =
dynamic_cast<TH3 *
>(parent->FindObject(hname));
571 Fatal(
"THistManager::FillTH3",
"Histogram %s not found in parent group %s", hname.Data(), dirname.Data());
575 Double_t myweight = optstring.Contains(
"w") ? 1. : weight;
576 if(optstring.Contains(
"wx")){
577 Int_t binx = hist->GetXaxis()->FindBin(point[0]);
578 if(binx != 0 && binx != hist->GetXaxis()->GetNbins()) myweight *= 1./hist->GetXaxis()->GetBinWidth(binx);
580 if(optstring.Contains(
"wy")){
581 Int_t biny = hist->GetYaxis()->FindBin(point[1]);
582 if(biny != 0 && biny != hist->GetYaxis()->GetNbins()) myweight *= 1./hist->GetYaxis()->GetBinWidth(biny);
584 if(optstring.Contains(
"wz")){
585 Int_t binz = hist->GetZaxis()->FindBin(point[2]);
586 if(binz != 0 && binz != hist->GetZaxis()->GetNbins()) myweight *= 1./hist->GetZaxis()->GetBinWidth(binz);
588 hist->Fill(point[0], point[1], point[2], weight);
595 Fatal(
"THistManager::FillTHnSparse",
"Parent group %s does not exist", dirname.Data());
598 THnSparseD *hist =
dynamic_cast<THnSparseD *
>(parent->FindObject(hname));
600 Fatal(
"THistManager::FillTHnSparse",
"Histogram %s not found in parent group %s", hname.Data(), dirname.Data());
604 Double_t myweight = optstring.Contains(
"w") ? 1. : weight;
605 for(
Int_t iaxis = 0; iaxis < hist->GetNdimensions(); iaxis++){
606 std::stringstream weighthandler;
607 weighthandler <<
"w" << iaxis;
608 if(optstring.Contains(weighthandler.str().c_str())){
609 Int_t bin = hist->GetAxis(iaxis)->FindBin(x[iaxis]);
610 if(bin != 0 && bin != hist->GetAxis(iaxis)->GetNbins()) myweight *= hist->GetAxis(iaxis)->GetBinWidth(bin);
614 hist->Fill(x, weight);
621 Fatal(
"THistManager::FillTProfile",
"Parent group %s does not exist", dirname.Data());
622 TProfile *hist =
dynamic_cast<TProfile *
>(parent->FindObject(hname));
624 Fatal(
"THistManager::FillTProfile",
"Histogram %s not found in parent group %s", hname.Data(), dirname.Data());
625 hist->Fill(x, y, weight);
631 if(!parent)
return NULL;
632 return parent->FindObject(hname);
638 if(!parent)
return NULL;
639 return parent->FindObject(hname);
643 if(!strlen(dirname) || !strcmp(dirname,
"/"))
return fHistos;
646 if(parentlist)
return static_cast<THashList *
>(parentlist->FindObject(
histname(dirname)));
651 int index = path.Last(
'/');
652 if(index < 0)
return "";
653 return TString(path(0, index));
657 int index = path.Last(
'/');
658 if(index < 0)
return path;
659 return TString(path(index+1, path.Length() - (index+1)));
739 int THistManagerTestSuite::TestBuildSimpleHistograms(){
743 testmgr.
CreateTH1(
"Test1D",
"Test Histogram 1D", 1, 0., 1.);
744 testmgr.
CreateTH2(
"Test2D",
"Test Histogram 2D", 2, 0., 2., 10., 0., 10);
745 testmgr.
CreateTH3(
"Test3D",
"Test Histogram 3D", 3, 2, 6., 10., 0., 10., 50., 0., 50.);
746 int nbins[3] = {3, 3, 3};
double min[3] = {0., 0., 0}, max[3] = {6, 9, 12};
747 testmgr.
CreateTHnSparse(
"TestNSparse",
"Test Histogram NSparse", 3, nbins, min, max);
754 std::cout <<
"Not found: Test1D" << std::endl;
758 std::cout <<
"Not found: Test2D" << std::endl;
762 std::cout <<
"Not found: Test3D" << std::endl;
766 std::cout <<
"Not found: TestNSparse" << std::endl;
770 std::cout <<
"Not found: TestProfile" << std::endl;
774 return found ? 0 : 1;
777 int THistManagerTestSuite::TestBuildGroupedHistograms(){
781 testmgr.
CreateTH1(
"Group1/Test1",
"Test Histogram 1 in group 1", 1, 0., 1.);
782 testmgr.
CreateTH1(
"Group1/Test2",
"Test Histogram 2 in group 1", 1, 0., 1.);
783 testmgr.
CreateTH2(
"Group2/Test1",
"Test Histogram 1 in group 2", 1, 0., 1., 1, 0., 1.);
784 testmgr.
CreateTH2(
"Group2/Test2",
"Test Histogram 2 in group 2", 1, 0., 1., 1, 0., 1.);
785 testmgr.
CreateTH3(
"Group3/Test1",
"Test Histogram 1 in group 3", 1, 0., 1., 1, 0., 1., 1, 0., 1.);
786 testmgr.
CreateTH3(
"Group3/Test2",
"Test Histogram 2 in group 3", 1, 0., 1., 1, 0., 1., 1, 0., 1.);
788 testmgr.
CreateTProfile(
"Group4/Subgroup1/Test1",
"Test histogram for subgroup handling", 1, 0., 1);
793 THashList *currentdir(
nullptr);
794 if(!(currentdir = dynamic_cast<THashList *>(testmgr.
GetListOfHistograms()->FindObject(
"Group1")))){
795 std::cout <<
"Not found: Group1" << std::endl;
798 if(!dynamic_cast<TH1 *>(currentdir->FindObject(
"Test1"))){
799 std::cout <<
"Not found in Group1: Test1" << std::endl;
802 if(!dynamic_cast<TH1 *>(currentdir->FindObject(
"Test2"))){
803 std::cout <<
"Not found in Group1: Test2" << std::endl;
807 if(!(currentdir = dynamic_cast<THashList *>(testmgr.
GetListOfHistograms()->FindObject(
"Group2")))){
808 std::cout <<
"Not found: Group2" << std::endl;
811 if(!dynamic_cast<TH2 *>(currentdir->FindObject(
"Test1"))){
812 std::cout <<
"Not found in Group2: Test1" << std::endl;
815 if(!dynamic_cast<TH2 *>(currentdir->FindObject(
"Test2"))){
816 std::cout <<
"Not found in Group2: Test2" << std::endl;
820 if(!(currentdir = dynamic_cast<THashList *>(testmgr.
GetListOfHistograms()->FindObject(
"Group3")))){
821 std::cout <<
"Not found: Group3" << std::endl;
824 if(!static_cast<TH3 *>(currentdir->FindObject(
"Test1"))){
825 std::cout <<
"Not found in Group3: Test1" << std::endl;
828 if(!static_cast<TH3 *>(currentdir->FindObject(
"Test2"))){
829 std::cout <<
"Not found in Group3: Test2" << std::endl;
833 if(!(currentdir = dynamic_cast<THashList *>(testmgr.
GetListOfHistograms()->FindObject(
"Group4")))){
834 std::cout <<
"Not found: Group4" << std::endl;
837 if(!(currentdir = dynamic_cast<THashList *>(currentdir->FindObject(
"Subgroup1")))){
838 std::cout <<
"Not found in Group4: Subgroup1" << std::endl;
841 if(!dynamic_cast<TH1 *>(currentdir->FindObject(
"Test1"))){
842 std::cout <<
"Not found in Subgroup1: Test1" << std::endl;
847 return found ? 0 : 1;
850 int THistManagerTestSuite::TestFillSimpleHistograms(){
853 testmgr.
CreateTH1(
"Test1",
"Test fill 1D histogram", 1, 0., 1.);
854 testmgr.
CreateTH2(
"Test2",
"Test fill 2D histogram", 1, 0., 1., 1, 0., 1.);
855 testmgr.
CreateTH3(
"Test3",
"Test fill 3D histogram", 1, 0., 1., 1, 0., 1., 1, 0., 1.);
856 int nbins[4] = {1,1,1,1};
double min[4] = {0.,0.,0.,0.}, max[4] = {1.,1.,1.,1.};
857 testmgr.
CreateTHnSparse(
"TestN",
"Test Fill THnSparse", 4, nbins, min, max);
858 testmgr.
CreateTProfile(
"TestProfile",
"Test fill Profile histogram", 1, 0., 1.);
860 double point[4] = {0.5, 0.5, 0.5, 0.5};
861 for(
int i = 0; i < 100; i++){
863 testmgr.
FillTH2(
"Test2", 0.5, 0.5);
864 testmgr.
FillTH3(
"Test3", 0.5, 0.5, 0.5);
875 if(TMath::Abs(test1->GetBinContent(1) - 100) > DBL_EPSILON){
876 std::cout <<
"Test1: Mismatch in values, expected 100, found " << test1->GetBinContent(1) << std::endl;
880 std::cout <<
"Not found: Test1" << std::endl;
886 if(TMath::Abs(test2->GetBinContent(1, 1) - 100) > DBL_EPSILON){
887 std::cout <<
"Test2: Mismatch in values, expected 100, found " << test2->GetBinContent(1,1) << std::endl;
891 std::cout <<
"Not found: Test2" << std::endl;
897 if(TMath::Abs(test3->GetBinContent(1, 1, 1) - 100) > DBL_EPSILON){
898 std::cout <<
"Test3: Mismatch in values, expected 100, found " << test3->GetBinContent(1,1,1) << std::endl;
902 std::cout <<
"Not found: Test3" << std::endl;
906 THnSparse *testN =
dynamic_cast<THnSparse *
>(testmgr.
GetListOfHistograms()->FindObject(
"TestN"));
908 int index[4] = {1,1,1,1};
909 if(TMath::Abs(testN->GetBinContent(index) - 100) > DBL_EPSILON){
910 std::cout <<
"TestN: Mismatch in values, expected 100, found " << testN->GetBinContent(index) << std::endl;
914 std::cout <<
"Not found: TestN" << std::endl;
918 TProfile *testProfile =
dynamic_cast<TProfile *
>(testmgr.
GetListOfHistograms()->FindObject(
"TestProfile"));
920 if(TMath::Abs(testProfile->GetBinContent(1) - 1) > DBL_EPSILON){
921 std::cout <<
"TestProfile: Mismatch in values, expected 1, found " << testProfile->GetBinContent(1) << std::endl;
925 std::cout <<
"Not found: TestProfile" << std::endl;
929 return success ? 0 : 1;
933 int THistManagerTestSuite::TestFillGroupedHistograms(){
937 testmgr.
CreateTH1(
"Group1/Test1",
"Test 1 Group 1D", 1, 0., 1.);
938 testmgr.
CreateTH1(
"Group1/Test2",
"Test 2 Group 1D", 1, 0., 1.);
939 testmgr.
CreateTH2(
"Group2/Test1",
"Test 1 Group 2D", 1, 0., 1., 1, 0., 1.);
940 testmgr.
CreateTH2(
"Group2/Test2",
"Test 2 Group 2D", 1, 0., 1., 1, 0., 1.);
941 testmgr.
CreateTProfile(
"Group3/Subgroup1/Test1",
"Test 1 with subgroup", 1, 0., 1.);
943 for(
int i = 0; i < 100; i++){
944 testmgr.
FillTH1(
"Group1/Test1", 0.5);
945 testmgr.
FillTH1(
"Group1/Test2", 0.5);
946 testmgr.
FillTH2(
"Group2/Test1", 0.5, 0.5);
947 testmgr.
FillTH2(
"Group2/Test2", 0.5, 0.5);
948 testmgr.
FillProfile(
"Group3/Subgroup1/Test1", 0.5, 1);
954 THashList *currentdir =
dynamic_cast<THashList *
>(testmgr.
GetListOfHistograms()->FindObject(
"Group1"));
956 TH1 *test1 =
dynamic_cast<TH1 *
>(currentdir->FindObject(
"Test1"));
958 if(TMath::Abs(test1->GetBinContent(1) - 100) > DBL_EPSILON){
959 std::cout <<
"Group1/Test1: Value mismatch: expected 100, found " << test1->GetBinContent(1) << std::endl;
963 std::cout <<
"Not found in Group1: Test1" << std::endl;
966 test1 =
dynamic_cast<TH1 *
>(currentdir->FindObject(
"Test2"));
968 if(TMath::Abs(test1->GetBinContent(1) - 100) > DBL_EPSILON){
969 std::cout <<
"Group1/Test2: Value mismatch: expected 100, found " << test1->GetBinContent(1) << std::endl;
973 std::cout <<
"Not found in Group1: Test2" << std::endl;
977 std::cout <<
"Not found: Group1" << std::endl;
981 currentdir =
dynamic_cast<THashList *
>(testmgr.
GetListOfHistograms()->FindObject(
"Group2"));
983 TH2 *test2 =
dynamic_cast<TH2 *
>(currentdir->FindObject(
"Test1"));
985 if(TMath::Abs(test2->GetBinContent(1,1) - 100) > DBL_EPSILON){
986 std::cout <<
"Group2/Test1: Value mismatch: expected 100, found " << test2->GetBinContent(1,1) << std::endl;
990 std::cout <<
"Not found in Group2: Test1" << std::endl;
993 test2 =
dynamic_cast<TH2 *
>(currentdir->FindObject(
"Test2"));
995 if(TMath::Abs(test2->GetBinContent(1,1) - 100) > DBL_EPSILON){
996 std::cout <<
"Group2/Test2: Value mismatch: expected 100, found " << test2->GetBinContent(1,1) << std::endl;
1000 std::cout <<
"Not found in Group2: Test2" << std::endl;
1004 std::cout <<
"Not found: Group2" << std::endl;
1008 currentdir =
dynamic_cast<THashList *
>(testmgr.
GetListOfHistograms()->FindObject(
"Group3"));
1010 currentdir =
dynamic_cast<THashList *
>(currentdir->FindObject(
"Subgroup1"));
1012 TProfile *testprofile =
dynamic_cast<TProfile *
>(currentdir->FindObject(
"Test1"));
1014 if(TMath::Abs(testprofile->GetBinContent(1) - 1) > DBL_EPSILON){
1015 std::cout <<
"Group3/Subgroup1/Test1: Value mismatch: expected 1, found " << testprofile->GetBinContent(1) << std::endl;
1019 std::cout <<
"Not found in Group3/Subgroup1: Test1" << std::endl;
1023 std::cout <<
"Not found in Group3: Subgroup1" << std::endl;
1027 std::cout <<
"Not found: Group3" << std::endl;
1030 return success ? 0 : 1;
1037 std::cout <<
"Running test: Build simple" << std::endl;
1039 std::cout <<
"Result after test: " << testresult << std::endl;
1041 std::cout <<
"Running test: Build grouped" << std::endl;
1043 std::cout <<
"Result after test: " << testresult << std::endl;
1045 std::cout <<
"Running test: Fill Simple" << std::endl;
1047 std::cout <<
"Result after test: " << testresult << std::endl;
1049 std::cout <<
"Running test: Fill Grouped" << std::endl;
1051 std::cout <<
"Result after test: " << testresult << std::endl;
Collection of simple test for the THistManager.
Int_t fNext
Next position in the histmanager.
iterator & operator=(const iterator &rhs)
THashList * CreateHistoGroup(const char *groupname)
Create a new group of histograms within a parent group.
bool fIsOwner
Set the ownership.
THistManager()
Default constructor.
THashList * FindGroup(const char *dirname) const
Find histogram group.
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
Fill a 2D histogram within the container.
void FillTH3(const char *hname, double x, double y, double z, double weight=1., Option_t *opt="")
Fill a 3D histogram within the container.
virtual void CreateBinEdges(TArrayD &binedges) const =0
const THistManager * fkArray
Underlying histmanager to iterate over.
void SetObject(TObject *const o, const char *group="/")
Set a new group into the container into the parent group.
Interface for binnings used by the histogram handler.
THMIDirection_t fDirection
Direction of the iterator.
Bool_t operator!=(const iterator &aIter) const
Comparison operator for unequalness.
void FillTHnSparse(const char *name, const double *x, double weight=1., Option_t *opt="")
~THistManager()
Destructor.
TH2 * CreateTH2(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, Option_t *opt="")
Create a new TH2 within the container.
TObject * FindObject(const char *name) const
Find an object inside the container.
int TestBuildSimpleHistograms()
void CreateTProfile(const char *name, const char *title, int nbinsX, double xmin, double xmax, Option_t *opt="")
Create a new TProfile within the container.
THashList * GetListOfHistograms() const
Get the list of histograms.
TH1 * CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
Create a new TH1 within the container.
void FillProfile(const char *name, double x, double y, double weight=1.)
int TestBuildGroupedHistograms()
THMIDirection_t
Direction for the iteration.
int TestFillGroupedHistograms()
stl-iterator for the histogram manager
void FillTH1(const char *hname, double x, double weight=1., Option_t *opt="")
Fill a 1D histogram within the container.
iterator & operator++()
Prefix increment operator.
int TestRunBuildGrouped()
TString basename(const TString &path) const
Extracting the basename from a given histogram path.
Collection of tests for the THistManager.
iterator & operator--()
Prefix decrement operator.
TString histname(const TString &path) const
Extracting the histogram name from a given histogram path.
TObject * operator*() const
Dereferncing operator.
Container class for histograms.
THnSparse * CreateTHnSparse(const char *name, const char *title, int ndim, const int *nbins, const double *min, const double *max, Option_t *opt="")
Create a new THnSparse within the container.
THashList * fHistos
List of histograms.
TH3 * CreateTH3(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, int nbinsz, double zmin, double zmax, Option_t *opt="")
Create a new TH2 within the container.
Int_t fCurrentPos
Current position of the iterator in the histmanager.
int TestFillSimpleHistograms()