1 // Author: Dariusz Miskowiec <mailto:d.miskowiec@gsi.de> 2007
3 //=============================================================================
4 // multidimensional histogram
5 //=============================================================================
14 const Int_t fMaxNdim=10; // maximum number of dimensions
16 //=============================================================================
17 class AliDHN : public TH1D {
20 AliDHN() : TH1D(), fNdim(0) {printf("AliDHN object created\n");}
21 AliDHN(Char_t *nam, Int_t ndim, TAxis **ax); // constructor from scratch
22 AliDHN(Char_t *filename, Char_t *name); // constructor from file
23 virtual ~AliDHN() {printf("AliDHN object %s deleted\n",GetName());}
24 Int_t GetNdim() const {return fNdim;}
25 TAxis *GetAxis(Int_t i) const {return (TAxis*) &fAxis[i];}
27 Int_t Fill(Double_t *xx, Double_t y=1); // fill histo
28 Int_t Fill(Double_t) {return -1;} // insufficient number of arguments
29 Int_t Fill(Double_t x0, Double_t w) {return Fill(&x0,w);} // 1-dim histo fill
30 Int_t Fill(Double_t x0, Double_t x1, ...);// 2 or more dim histo fill
31 Int_t Fill(const char*, Double_t) {return -1;} // overload TH1
33 Int_t Write() const; // save histo and axis on file
34 Int_t Write() {return ((const AliDHN*)this)->Write();}
35 Int_t Write(const char *, Int_t, Int_t) {return Write();} // overload TObject
36 Int_t Write(const char *, Int_t, Int_t) const {return Write();}
38 // project along (integrate over) one axis
39 AliDHN *ProjectAlong(char *nam, Int_t dim, Int_t first=-1, Int_t last=-1);
40 // project on 1-dim histogram
41 TH1D *ProjectOn(char *nam, Int_t dim, Int_t *first=0, Int_t *last=0) const;
42 // project on 1-dim histogram
43 TH1D *ProjectOn(char *nam, Int_t dim, Double_t *first, Double_t *last);
44 // project on 2-dim histogram
45 TH2D *ProjectOn(char *nam, Int_t dim0, Int_t dim1, Int_t *first=0, Int_t *last=0) const;
49 Int_t fNdim; // number of dimensions
50 TAxis fAxis[fMaxNdim]; // axes
51 Int_t fNbins[fMaxNdim]; // {fAxis[0]->GetNbins(),fAxis[1]->...
52 Int_t fMbins[fMaxNdim]; // {...[fNdim-2]*fNbins[fNdim-1],fNbins[fNdim-1],1}
54 static Int_t Albins(Int_t n, TAxis **ax); // product of nbins of ax[0]...ax[n-1]
55 Int_t MulToOne(Int_t *k) const; // calc 1-dim index from n-dim indices
56 Int_t MulToOne(Double_t *x); // calc 1-dim index from n-dim vector
57 void OneToMul(Int_t n, Int_t *k) const; // calc n-dim indices from 1-dim index
61 //=============================================================================