00001
00014 #include "jbltools/sfh/MatrixOfH.h"
00015 #include "jbltools/sfh/SetOfHistograms.h"
00016 #include "jbltools/sfh/RegH1F.h"
00017 #include "jbltools/sfh/BinningFun.h"
00018
00019 #include <TFile.h>
00020 #include <TAxis.h>
00021
00022 #include <iostream>
00023 #include <cassert>
00024
00025 using std::endl;
00026 using std::cout;
00027 using std::cerr;
00028
00029 static const char *ident="@(#)$Id: MatrixOfH.C,v 1.5 2005/07/08 15:01:34 blist Exp $";
00030
00031 MatrixOfH::MatrixOfH (const char* name_,
00032 const char* title_,
00033 const ROListPoR& rol,
00034 const BinningFunPoR& binning1_,
00035 const BinningFunPoR& binning2_,
00036 Option_t* option_)
00037 : SetOfH (name_, title_, rol, binning1_, binning2_, option_)
00038 {
00039 assert (getBinning (2));
00040 nbins2 = getBinning (2)->getMaxBins();
00041 }
00042
00043 void MatrixOfH::initHisto (IndexType i) {
00044 assert (0);
00045 }
00046
00047 TH1 *MatrixOfH::getHisto (IndexType i, IndexType j) {
00048 return dynamic_cast<TH1 *>(getEntry (getBinNumber(i, j)));
00049 }
00050
00051 void MatrixOfH::initHistos () {
00052 const BinningFun *binning1 = getBinning (1);
00053 const BinningFun *binning2 = getBinning (2);
00054 assert (binning1);
00055 assert (binning2);
00056 IndexType nbins1 = binning1->getNBins();
00057 IndexType nbins2 = binning2->getNBins();
00058 IndexType nbins = nbins1*nbins2;
00059 for (IndexType i = 0; i < nbins1; i++) {
00060 for (IndexType j = 0; j < nbins2; j++) {
00061 initHisto (i, j);
00062 }
00063 }
00064 cout << "MatrixOfH::initHistos: name=" << getName()
00065 << ", title=" << getTitle()
00066 << "\nnbins1=" << nbins1 << ", nbins2=" << nbins2 << ", nbins=" << nbins
00067 << ", entries=" << getEntries() << endl;
00068
00069 assert (getEntries() == nbins);
00070 }
00071
00072
00073 const char *MatrixOfH::genBinTitle (IndexType i, IndexType j) const {
00074 const BinningFun *binning1 = getBinning (1);
00075 const BinningFun *binning2 = getBinning (2);
00076 assert (binning1);
00077 assert (binning2);
00078 const char *bintitle1 = binning1->getBinTitle(i);
00079 const char *bintitle2 = binning2->getBinTitle(j);
00080 if (!bintitle1) {
00081 char *bt = new char[10];
00082 snprintf (bt, 10, "%lld", i);
00083 bintitle1 = bt;
00084 }
00085 if (!bintitle2) {
00086 char *bt = new char[10];
00087 snprintf (bt, 10, "%lld", i);
00088 bintitle2 = bt;
00089 }
00090 const char *title = getTitle();
00091 if (!title) title = "?";
00092 size_t size = strlen (title) + 1 +
00093 strlen (bintitle1) + 1 +
00094 strlen (bintitle2) + 1;
00095 char *htitle = new char[size];
00096 snprintf (htitle, size, "%s %s %s", title, bintitle1, bintitle2);
00097 delete[] bintitle1;
00098 delete[] bintitle2;
00099 return htitle;
00100 }
00101
00102 const char *MatrixOfH::genBinName (IndexType i, IndexType j) const {
00103 const BinningFun *binning1 = getBinning (1);
00104 const BinningFun *binning2 = getBinning (2);
00105 assert (binning1);
00106 assert (binning2);
00107 const char *binname1 = binning1->getBinName(i);
00108 const char *binname2 = binning2->getBinName(j);
00109 if (!binname1) {
00110 char *bn = new char[10];
00111 snprintf (bn, 10, "%lld", i);
00112 binname1 = bn;
00113 }
00114 if (!binname2) {
00115 char *bn = new char[10];
00116 snprintf (bn, 10, "%lld", i);
00117 binname2 = bn;
00118 }
00119 const char *name = getName();
00120 if (!name) name = "?";
00121 size_t size = strlen (name) + strlen (binname1) + strlen (binname2) + 1;
00122 char *hname = new char[size];
00123 snprintf (hname, size, "%s%s%s", name, binname1, binname2);
00124 delete[] binname1;
00125 delete[] binname2;
00126 return hname;
00127 }
00128
00129 MatrixOfH::~MatrixOfH () {
00130 }
00131