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",
"Parnt 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",
"Parnt 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::FillTH3",
"Parent group %s does not exist", dirname.Data());
515 TH3 *hist =
dynamic_cast<TH3 *
>(parent->FindObject(hname));
517 Fatal(
"THistManager::FillTH3",
"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(x);
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(y);
528 if(biny != 0 && biny != hist->GetYaxis()->GetNbins()) myweight *= 1./hist->GetYaxis()->GetBinWidth(biny);
530 if(optstring.Contains(
"wz")){
531 Int_t binz = hist->GetZaxis()->FindBin(z);
532 if(binz != 0 && binz != hist->GetZaxis()->GetNbins()) myweight *= 1./hist->GetZaxis()->GetBinWidth(binz);
534 hist->Fill(x, y, z, weight);
541 Fatal(
"THistManager::FillTH3",
"Parent group %s does not exist", dirname.Data());
544 TH3 *hist =
dynamic_cast<TH3 *
>(parent->FindObject(hname));
546 Fatal(
"THistManager::FillTH3",
"Histogram %s not found in parent group %s", hname.Data(), dirname.Data());
550 Double_t myweight = optstring.Contains(
"w") ? 1. : weight;
551 if(optstring.Contains(
"wx")){
552 Int_t binx = hist->GetXaxis()->FindBin(point[0]);
553 if(binx != 0 && binx != hist->GetXaxis()->GetNbins()) myweight *= 1./hist->GetXaxis()->GetBinWidth(binx);
555 if(optstring.Contains(
"wy")){
556 Int_t biny = hist->GetYaxis()->FindBin(point[1]);
557 if(biny != 0 && biny != hist->GetYaxis()->GetNbins()) myweight *= 1./hist->GetYaxis()->GetBinWidth(biny);
559 if(optstring.Contains(
"wz")){
560 Int_t binz = hist->GetZaxis()->FindBin(point[2]);
561 if(binz != 0 && binz != hist->GetZaxis()->GetNbins()) myweight *= 1./hist->GetZaxis()->GetBinWidth(binz);
563 hist->Fill(point[0], point[1], point[2], weight);
570 Fatal(
"THistManager::FillTHnSparse",
"Parent group %s does not exist", dirname.Data());
573 THnSparseD *hist =
dynamic_cast<THnSparseD *
>(parent->FindObject(hname));
575 Fatal(
"THistManager::FillTHnSparse",
"Histogram %s not found in parent group %s", hname.Data(), dirname.Data());
579 Double_t myweight = optstring.Contains(
"w") ? 1. : weight;
580 for(
Int_t iaxis = 0; iaxis < hist->GetNdimensions(); iaxis++){
581 std::stringstream weighthandler;
582 weighthandler <<
"w" << iaxis;
583 if(optstring.Contains(weighthandler.str().c_str())){
584 Int_t bin = hist->GetAxis(iaxis)->FindBin(x[iaxis]);
585 if(bin != 0 && bin != hist->GetAxis(iaxis)->GetNbins()) myweight *= hist->GetAxis(iaxis)->GetBinWidth(bin);
589 hist->Fill(x, weight);
596 Fatal(
"THistManager::FillTProfile",
"Parent group %s does not exist", dirname.Data());
597 TProfile *hist =
dynamic_cast<TProfile *
>(parent->FindObject(hname));
599 Fatal(
"THistManager::FillTProfile",
"Histogram %s not found in parent group %s", hname.Data(), dirname.Data());
600 hist->Fill(x, y, weight);
606 if(!parent)
return NULL;
607 return parent->FindObject(hname);
613 if(!parent)
return NULL;
614 return parent->FindObject(hname);
618 if(!strlen(dirname) || !strcmp(dirname,
"/"))
return fHistos;
621 if(parentlist)
return static_cast<THashList *
>(parentlist->FindObject(
histname(dirname)));
626 int index = path.Last(
'/');
627 if(index < 0)
return "";
628 return TString(path(0, index));
632 int index = path.Last(
'/');
633 if(index < 0)
return path;
634 return TString(path(index+1, path.Length() - (index+1)));
651 fkArray(ref.fkArray),
652 fCurrentPos(ref.fCurrentPos),
654 fDirection(ref.fDirection)
672 if(fDirection == kTHMIforward)
686 if(fDirection == kTHMIforward)
701 return fkArray->GetListOfHistograms()->At(fCurrentPos);
712 namespace TestTHistManager {
714 int THistManagerTestSuite::TestBuildSimpleHistograms(){
718 testmgr.
CreateTH1(
"Test1D",
"Test Histogram 1D", 1, 0., 1.);
719 testmgr.
CreateTH2(
"Test2D",
"Test Histogram 2D", 2, 0., 2., 10., 0., 10);
720 testmgr.
CreateTH3(
"Test3D",
"Test Histogram 3D", 3, 2, 6., 10., 0., 10., 50., 0., 50.);
721 int nbins[3] = {3, 3, 3};
double min[3] = {0., 0., 0}, max[3] = {6, 9, 12};
722 testmgr.
CreateTHnSparse(
"TestNSparse",
"Test Histogram NSparse", 3, nbins, min, max);
729 std::cout <<
"Not found: Test1D" << std::endl;
733 std::cout <<
"Not found: Test2D" << std::endl;
737 std::cout <<
"Not found: Test3D" << std::endl;
741 std::cout <<
"Not found: TestNSparse" << std::endl;
745 std::cout <<
"Not found: TestProfile" << std::endl;
749 return found ? 0 : 1;
752 int THistManagerTestSuite::TestBuildGroupedHistograms(){
756 testmgr.
CreateTH1(
"Group1/Test1",
"Test Histogram 1 in group 1", 1, 0., 1.);
757 testmgr.
CreateTH1(
"Group1/Test2",
"Test Histogram 2 in group 1", 1, 0., 1.);
758 testmgr.
CreateTH2(
"Group2/Test1",
"Test Histogram 1 in group 2", 1, 0., 1., 1, 0., 1.);
759 testmgr.
CreateTH2(
"Group2/Test2",
"Test Histogram 2 in group 2", 1, 0., 1., 1, 0., 1.);
760 testmgr.
CreateTH3(
"Group3/Test1",
"Test Histogram 1 in group 3", 1, 0., 1., 1, 0., 1., 1, 0., 1.);
761 testmgr.
CreateTH3(
"Group3/Test2",
"Test Histogram 2 in group 3", 1, 0., 1., 1, 0., 1., 1, 0., 1.);
763 testmgr.
CreateTProfile(
"Group4/Subgroup1/Test1",
"Test histogram for subgroup handling", 1, 0., 1);
768 THashList *currentdir(
nullptr);
769 if(!(currentdir = dynamic_cast<THashList *>(testmgr.
GetListOfHistograms()->FindObject(
"Group1")))){
770 std::cout <<
"Not found: Group1" << std::endl;
773 if(!dynamic_cast<TH1 *>(currentdir->FindObject(
"Test1"))){
774 std::cout <<
"Not found in Group1: Test1" << std::endl;
777 if(!dynamic_cast<TH1 *>(currentdir->FindObject(
"Test2"))){
778 std::cout <<
"Not found in Group1: Test2" << std::endl;
782 if(!(currentdir = dynamic_cast<THashList *>(testmgr.
GetListOfHistograms()->FindObject(
"Group2")))){
783 std::cout <<
"Not found: Group2" << std::endl;
786 if(!dynamic_cast<TH2 *>(currentdir->FindObject(
"Test1"))){
787 std::cout <<
"Not found in Group2: Test1" << std::endl;
790 if(!dynamic_cast<TH2 *>(currentdir->FindObject(
"Test2"))){
791 std::cout <<
"Not found in Group2: Test2" << std::endl;
795 if(!(currentdir = dynamic_cast<THashList *>(testmgr.
GetListOfHistograms()->FindObject(
"Group3")))){
796 std::cout <<
"Not found: Group3" << std::endl;
799 if(!static_cast<TH3 *>(currentdir->FindObject(
"Test1"))){
800 std::cout <<
"Not found in Group3: Test1" << std::endl;
803 if(!static_cast<TH3 *>(currentdir->FindObject(
"Test2"))){
804 std::cout <<
"Not found in Group3: Test2" << std::endl;
808 if(!(currentdir = dynamic_cast<THashList *>(testmgr.
GetListOfHistograms()->FindObject(
"Group4")))){
809 std::cout <<
"Not found: Group4" << std::endl;
812 if(!(currentdir = dynamic_cast<THashList *>(currentdir->FindObject(
"Subgroup1")))){
813 std::cout <<
"Not found in Group4: Subgroup1" << std::endl;
816 if(!dynamic_cast<TH1 *>(currentdir->FindObject(
"Test1"))){
817 std::cout <<
"Not found in Subgroup1: Test1" << std::endl;
822 return found ? 0 : 1;
825 int THistManagerTestSuite::TestFillSimpleHistograms(){
828 testmgr.
CreateTH1(
"Test1",
"Test fill 1D histogram", 1, 0., 1.);
829 testmgr.
CreateTH2(
"Test2",
"Test fill 2D histogram", 1, 0., 1., 1, 0., 1.);
830 testmgr.
CreateTH3(
"Test3",
"Test fill 3D histogram", 1, 0., 1., 1, 0., 1., 1, 0., 1.);
831 int nbins[4] = {1,1,1,1};
double min[4] = {0.,0.,0.,0.}, max[4] = {1.,1.,1.,1.};
832 testmgr.
CreateTHnSparse(
"TestN",
"Test Fill THnSparse", 4, nbins, min, max);
833 testmgr.
CreateTProfile(
"TestProfile",
"Test fill Profile histogram", 1, 0., 1.);
835 double point[4] = {0.5, 0.5, 0.5, 0.5};
836 for(
int i = 0; i < 100; i++){
838 testmgr.
FillTH2(
"Test2", 0.5, 0.5);
839 testmgr.
FillTH3(
"Test3", 0.5, 0.5, 0.5);
850 if(TMath::Abs(test1->GetBinContent(1) - 100) > DBL_EPSILON){
851 std::cout <<
"Test1: Mismatch in values, expected 100, found " << test1->GetBinContent(1) << std::endl;
855 std::cout <<
"Not found: Test1" << std::endl;
861 if(TMath::Abs(test2->GetBinContent(1, 1) - 100) > DBL_EPSILON){
862 std::cout <<
"Test2: Mismatch in values, expected 100, found " << test2->GetBinContent(1,1) << std::endl;
866 std::cout <<
"Not found: Test2" << std::endl;
872 if(TMath::Abs(test3->GetBinContent(1, 1, 1) - 100) > DBL_EPSILON){
873 std::cout <<
"Test3: Mismatch in values, expected 100, found " << test3->GetBinContent(1,1,1) << std::endl;
877 std::cout <<
"Not found: Test3" << std::endl;
881 THnSparse *testN =
dynamic_cast<THnSparse *
>(testmgr.
GetListOfHistograms()->FindObject(
"TestN"));
883 int index[4] = {1,1,1,1};
884 if(TMath::Abs(testN->GetBinContent(index) - 100) > DBL_EPSILON){
885 std::cout <<
"TestN: Mismatch in values, expected 100, found " << testN->GetBinContent(index) << std::endl;
889 std::cout <<
"Not found: TestN" << std::endl;
893 TProfile *testProfile =
dynamic_cast<TProfile *
>(testmgr.
GetListOfHistograms()->FindObject(
"TestProfile"));
895 if(TMath::Abs(testProfile->GetBinContent(1) - 1) > DBL_EPSILON){
896 std::cout <<
"TestProfile: Mismatch in values, expected 1, found " << testProfile->GetBinContent(1) << std::endl;
900 std::cout <<
"Not found: TestProfile" << std::endl;
904 return success ? 0 : 1;
908 int THistManagerTestSuite::TestFillGroupedHistograms(){
912 testmgr.
CreateTH1(
"Group1/Test1",
"Test 1 Group 1D", 1, 0., 1.);
913 testmgr.
CreateTH1(
"Group1/Test2",
"Test 2 Group 1D", 1, 0., 1.);
914 testmgr.
CreateTH2(
"Group2/Test1",
"Test 1 Group 2D", 1, 0., 1., 1, 0., 1.);
915 testmgr.
CreateTH2(
"Group2/Test2",
"Test 2 Group 2D", 1, 0., 1., 1, 0., 1.);
916 testmgr.
CreateTProfile(
"Group3/Subgroup1/Test1",
"Test 1 with subgroup", 1, 0., 1.);
918 for(
int i = 0; i < 100; i++){
919 testmgr.
FillTH1(
"Group1/Test1", 0.5);
920 testmgr.
FillTH1(
"Group1/Test2", 0.5);
921 testmgr.
FillTH2(
"Group2/Test1", 0.5, 0.5);
922 testmgr.
FillTH2(
"Group2/Test2", 0.5, 0.5);
923 testmgr.
FillProfile(
"Group3/Subgroup1/Test1", 0.5, 1);
929 THashList *currentdir =
dynamic_cast<THashList *
>(testmgr.
GetListOfHistograms()->FindObject(
"Group1"));
931 TH1 *test1 =
dynamic_cast<TH1 *
>(currentdir->FindObject(
"Test1"));
933 if(TMath::Abs(test1->GetBinContent(1) - 100) > DBL_EPSILON){
934 std::cout <<
"Group1/Test1: Value mismatch: expected 100, found " << test1->GetBinContent(1) << std::endl;
938 std::cout <<
"Not found in Group1: Test1" << std::endl;
941 test1 =
dynamic_cast<TH1 *
>(currentdir->FindObject(
"Test2"));
943 if(TMath::Abs(test1->GetBinContent(1) - 100) > DBL_EPSILON){
944 std::cout <<
"Group1/Test2: Value mismatch: expected 100, found " << test1->GetBinContent(1) << std::endl;
948 std::cout <<
"Not found in Group1: Test2" << std::endl;
952 std::cout <<
"Not found: Group1" << std::endl;
956 currentdir =
dynamic_cast<THashList *
>(testmgr.
GetListOfHistograms()->FindObject(
"Group2"));
958 TH2 *test2 =
dynamic_cast<TH2 *
>(currentdir->FindObject(
"Test1"));
960 if(TMath::Abs(test2->GetBinContent(1,1) - 100) > DBL_EPSILON){
961 std::cout <<
"Group2/Test1: Value mismatch: expected 100, found " << test2->GetBinContent(1,1) << std::endl;
965 std::cout <<
"Not found in Group2: Test1" << std::endl;
968 test2 =
dynamic_cast<TH2 *
>(currentdir->FindObject(
"Test2"));
970 if(TMath::Abs(test2->GetBinContent(1,1) - 100) > DBL_EPSILON){
971 std::cout <<
"Group2/Test2: Value mismatch: expected 100, found " << test2->GetBinContent(1,1) << std::endl;
975 std::cout <<
"Not found in Group2: Test2" << std::endl;
979 std::cout <<
"Not found: Group2" << std::endl;
983 currentdir =
dynamic_cast<THashList *
>(testmgr.
GetListOfHistograms()->FindObject(
"Group3"));
985 currentdir =
dynamic_cast<THashList *
>(currentdir->FindObject(
"Subgroup1"));
987 TProfile *testprofile =
dynamic_cast<TProfile *
>(currentdir->FindObject(
"Test1"));
989 if(TMath::Abs(testprofile->GetBinContent(1) - 1) > DBL_EPSILON){
990 std::cout <<
"Group3/Subgroup1/Test1: Value mismatch: expected 1, found " << testprofile->GetBinContent(1) << std::endl;
994 std::cout <<
"Not found in Group3/Subgroup1: Test1" << std::endl;
998 std::cout <<
"Not found in Group3: Subgroup1" << std::endl;
1002 std::cout <<
"Not found: Group3" << std::endl;
1005 return success ? 0 : 1;
1012 std::cout <<
"Running test: Build simple" << std::endl;
1014 std::cout <<
"Result after test: " << testresult << std::endl;
1016 std::cout <<
"Running test: Build grouped" << std::endl;
1018 std::cout <<
"Result after test: " << testresult << std::endl;
1020 std::cout <<
"Running test: Fill Simple" << std::endl;
1022 std::cout <<
"Result after test: " << testresult << std::endl;
1024 std::cout <<
"Running test: Fill Grouped" << std::endl;
1026 std::cout <<
"Result after test: " << testresult << std::endl;
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.
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
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()