]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnHistoDef.cxx
d87f7e7be3dd577c9ddb220dc914b8afd1d6b3a5
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnHistoDef.cxx
1 //
2 // Class AliRsnHistoDef
3 //
4 // Definition for a histogram type.
5 // Since one could do an analysis which is not an invariant mass
6 // the histogram definition should be more flexible, and it is stored
7 // separately in a new class.
8 // This class considers the possibility of a 1D or 2D histograms
9 // with its related binning, and can create a new histo from his definitions
10 //
11
12 #include <TH1.h>
13 #include <TH2.h>
14
15 #include "AliLog.h"
16
17 #include "AliRsnHistoDef.h"
18
19 ClassImp(AliRsnHistoDef)
20
21 //_____________________________________________________________________________
22 AliRsnHistoDef::AliRsnHistoDef() :
23   fNDim(0)
24 {
25 //
26 // Default constructor
27 //
28 }
29
30 //_____________________________________________________________________________
31 AliRsnHistoDef::AliRsnHistoDef
32 (Int_t nbins, Double_t min, Double_t max) :
33   fNDim(1)
34 {
35 //
36 // 1D histo definition.
37 //
38
39     SetBins(nbins, min, max);
40 }
41 //_____________________________________________________________________________
42 AliRsnHistoDef::AliRsnHistoDef
43 (Int_t nbinsX, Double_t minX, Double_t maxX, Int_t nbinsY, Double_t minY, Double_t maxY):
44   fNDim(2)
45 {
46 //
47 // 1D histo definition.
48 //
49
50     SetBins(nbinsX, minX, maxX, nbinsY, minY, maxY);
51 }
52
53 //_____________________________________________________________________________
54 void AliRsnHistoDef::SetBins(Int_t n, Double_t min, Double_t max)
55 {
56 //
57 // Binning for 1D histograms.
58 //
59
60     fNDim = 1;
61     
62     fNBins[0] = n;
63     fMin[0] = min;
64     fMax[0] = max;
65     
66     CheckEdges();
67 }
68
69 //_____________________________________________________________________________
70 void AliRsnHistoDef::SetBins
71 (Int_t nx, Double_t minx, Double_t maxx, Int_t ny, Double_t miny, Double_t maxy)
72 {
73 //
74 // Binning for 1D histograms.
75 //
76
77     fNDim = 2;
78     
79     fNBins[0] = nx;
80     fMin[0] = minx;
81     fMax[0] = maxx;
82     
83     fNBins[1] = ny;
84     fMin[1] = miny;
85     fMax[1] = maxy;
86     
87     CheckEdges();
88 }
89
90 //_____________________________________________________________________________
91 void AliRsnHistoDef::CheckEdges()
92 {
93 //
94 // Checks that histogram edges are appropriate,
95 // otherwise swaps them.
96 //
97
98     Int_t i;
99     for (i = 0; i < fNDim; i++) {
100         if (fMin[i] > fMax[i]) {
101             AliWarning(Form("min = %f -- max = %f --> swapping", fMin, fMax));
102             Double_t temp = fMin[i];
103             fMin[i] = fMax[i];
104             fMax[i] = temp;
105         }
106     }
107 }
108
109 //_____________________________________________________________________________
110 TH1D* AliRsnHistoDef::Create1DHistogram(const char *name, const char *title)
111 {
112 //
113 // Create 1D histogram, if the configuration is appropriate for this.
114 //
115
116     if (fNDim != 1) {
117         AliError("Number of dimension not set to 1!");
118         return 0x0;
119     }
120
121     TH1D *histo = new TH1D(name, title, fNBins[0], fMin[0], fMax[0]);
122     return histo;
123 }
124
125 //_____________________________________________________________________________
126 TH2D* AliRsnHistoDef::Create2DHistogram(const char *name, const char *title)
127 {
128 //
129 // Create 2D histogram, if the configuration is appropriate for this.
130 //
131
132     if (fNDim != 2) {
133         AliError("Number of dimension not set to 2!");
134         return 0x0;
135     }
136     
137     TH2D *histo = new TH2D(name, title, fNBins[0], fMin[0], fMax[0], fNBins[1], fMin[1], fMax[1]);
138     return histo;
139 }