1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz 07/2001 <mailto:tbretz@uni-sw.gwdg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2002
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | // //
|
---|
27 | // MH //
|
---|
28 | // //
|
---|
29 | // This is a base tasks for mars histograms. It defines a common interface //
|
---|
30 | // for filling the histograms with events (MH::Fill) which is used by a //
|
---|
31 | // common 'filler' And a SetupFill member function which may be used //
|
---|
32 | // by MFillH. The idea is: //
|
---|
33 | // 1) If your Histogram can become filled by one single container //
|
---|
34 | // (like MHHillas) you overload MH::Fill and it gets called with //
|
---|
35 | // a pointer to the container with which it should be filled. //
|
---|
36 | // //
|
---|
37 | // 2) You histogram needs several containers to get filled. Than you //
|
---|
38 | // have to overload MH::SetupFill and get the necessary objects from //
|
---|
39 | // the parameter list. Use this objects in Fill to fill your //
|
---|
40 | // histogram. //
|
---|
41 | // //
|
---|
42 | // If you want to create your own histogram class the new class must be //
|
---|
43 | // derived from MH (instead of the base MParContainer) and you must //
|
---|
44 | // the fill function of MH. This is the function which is called to fill //
|
---|
45 | // the histogram(s) by the data of a corresponding parameter container. //
|
---|
46 | // //
|
---|
47 | //////////////////////////////////////////////////////////////////////////////
|
---|
48 |
|
---|
49 | #include "MH.h"
|
---|
50 |
|
---|
51 | #include <TH1.h>
|
---|
52 | #include <TCanvas.h>
|
---|
53 |
|
---|
54 | #include "MBinning.h"
|
---|
55 |
|
---|
56 | ClassImp(MH);
|
---|
57 |
|
---|
58 | // --------------------------------------------------------------------------
|
---|
59 | //
|
---|
60 | // Default Constructor. It sets name and title only. Typically you won't
|
---|
61 | // need to change this.
|
---|
62 | //
|
---|
63 | MH::MH(const char *name, const char *title)
|
---|
64 | {
|
---|
65 | //
|
---|
66 | // set the name and title of this object
|
---|
67 | //
|
---|
68 | fName = name ? name : "MH" ;
|
---|
69 | fTitle = title ? title : "Base class for Mars histograms" ;
|
---|
70 | }
|
---|
71 |
|
---|
72 | // --------------------------------------------------------------------------
|
---|
73 | //
|
---|
74 | // This is a function which should replace the creation of default
|
---|
75 | // canvases like root does. Because this is inconvinient in some aspects.
|
---|
76 | // need to change this.
|
---|
77 | // You can specify a name for the default canvas and a title. Also
|
---|
78 | // width and height can be given.
|
---|
79 | // MakeDefCanvas looks for a canvas with the given name. If now name is
|
---|
80 | // given the DefCanvasName of root is used. If no such canvas is existing
|
---|
81 | // it is created and returned. If such a canvas already exists a new canvas
|
---|
82 | // with a name plus anumber is created (the number is calculated by the
|
---|
83 | // number of all existing canvases plus one)
|
---|
84 | //
|
---|
85 | TCanvas *MH::MakeDefCanvas(const char *name, const char *title,
|
---|
86 | const UInt_t w, const UInt_t h)
|
---|
87 | {
|
---|
88 | const TList *list = (TList*)gROOT->GetListOfCanvases();
|
---|
89 |
|
---|
90 | const char *def = name ? name : gROOT->GetDefCanvasName();
|
---|
91 |
|
---|
92 | TCanvas *c;
|
---|
93 | if (list->FindObject(def))
|
---|
94 | {
|
---|
95 | const char *n = StrDup(Form("%s <%d>", def, list->GetSize()+1));
|
---|
96 | c = new TCanvas(n, title, w, h);
|
---|
97 | delete [] n;
|
---|
98 | }
|
---|
99 | else
|
---|
100 | c = new TCanvas(def, title, w, h);
|
---|
101 |
|
---|
102 | return c;
|
---|
103 | }
|
---|
104 |
|
---|
105 | // --------------------------------------------------------------------------
|
---|
106 | //
|
---|
107 | // This function works like MakeDefCanvas(name, title, w, h) but name
|
---|
108 | // and title are retrieved from the given TObject.
|
---|
109 | //
|
---|
110 | TCanvas *MH::MakeDefCanvas(const TObject *obj,
|
---|
111 | const UInt_t w, const UInt_t h)
|
---|
112 | {
|
---|
113 | return MakeDefCanvas(obj->GetName(), obj->GetTitle(), w, h);
|
---|
114 | }
|
---|
115 |
|
---|
116 | void MH::SetBinning(TH1 *h, const MBinning *binsx)
|
---|
117 | {
|
---|
118 | //
|
---|
119 | // This is a necessary workaround if one wants to set
|
---|
120 | // non-equidistant bins after the initialization
|
---|
121 | // TH1D::fNcells must be set correctly.
|
---|
122 | //
|
---|
123 | h->SetBins(binsx->GetNumBins(), 0, 1);
|
---|
124 |
|
---|
125 | //
|
---|
126 | // Set the binning of the current histogram to the binning
|
---|
127 | // in one of the two given histograms
|
---|
128 | //
|
---|
129 | h->GetXaxis()->Set(binsx->GetNumBins(), binsx->GetEdges());
|
---|
130 | }
|
---|
131 |
|
---|
132 | void MH::SetBinning(TH1 *h, const MBinning *binsx, const MBinning *binsy)
|
---|
133 | {
|
---|
134 | //
|
---|
135 | // This is a necessary workaround if one wants to set
|
---|
136 | // non-equidistant bins after the initialization
|
---|
137 | // TH1D::fNcells must be set correctly.
|
---|
138 | //
|
---|
139 | h->SetBins(binsx->GetNumBins(), 0, 1,
|
---|
140 | binsy->GetNumBins(), 0, 1);
|
---|
141 |
|
---|
142 | //
|
---|
143 | // Set the binning of the current histogram to the binning
|
---|
144 | // in one of the two given histograms
|
---|
145 | //
|
---|
146 | h->GetXaxis()->Set(binsx->GetNumBins(), binsx->GetEdges());
|
---|
147 | h->GetYaxis()->Set(binsy->GetNumBins(), binsy->GetEdges());
|
---|
148 | }
|
---|
149 |
|
---|
150 | void MH::SetBinning(TH1 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz)
|
---|
151 | {
|
---|
152 | //
|
---|
153 | // This is a necessary workaround if one wants to set
|
---|
154 | // non-equidistant bins after the initialization
|
---|
155 | // TH1D::fNcells must be set correctly.
|
---|
156 | //
|
---|
157 | h->SetBins(binsx->GetNumBins(), 0, 1,
|
---|
158 | binsy->GetNumBins(), 0, 1,
|
---|
159 | binsz->GetNumBins(), 0, 1);
|
---|
160 |
|
---|
161 | //
|
---|
162 | // Set the binning of the current histogram to the binning
|
---|
163 | // in one of the two given histograms
|
---|
164 | //
|
---|
165 | h->GetXaxis()->Set(binsx->GetNumBins(), binsx->GetEdges());
|
---|
166 | h->GetYaxis()->Set(binsy->GetNumBins(), binsy->GetEdges());
|
---|
167 | h->GetZaxis()->Set(binsz->GetNumBins(), binsz->GetEdges());
|
---|
168 | }
|
---|
169 |
|
---|
170 | void MH::SetBinning(TH1 *h, const TArrayD *binsx)
|
---|
171 | {
|
---|
172 | MBinning bx;
|
---|
173 | bx.SetEdges(*binsx);
|
---|
174 | SetBinning(h, &bx);
|
---|
175 | }
|
---|
176 |
|
---|
177 | void MH::SetBinning(TH1 *h, const TArrayD *binsx, const TArrayD *binsy)
|
---|
178 | {
|
---|
179 | MBinning bx;
|
---|
180 | MBinning by;
|
---|
181 | bx.SetEdges(*binsx);
|
---|
182 | by.SetEdges(*binsy);
|
---|
183 | SetBinning(h, &bx, &by);
|
---|
184 | }
|
---|
185 |
|
---|
186 | void MH::SetBinning(TH1 *h, const TArrayD *binsx, const TArrayD *binsy, const TArrayD *binsz)
|
---|
187 | {
|
---|
188 | MBinning bx;
|
---|
189 | MBinning by;
|
---|
190 | MBinning bz;
|
---|
191 | bx.SetEdges(*binsx);
|
---|
192 | by.SetEdges(*binsy);
|
---|
193 | bz.SetEdges(*binsz);
|
---|
194 | SetBinning(h, &bx, &by, &bz);
|
---|
195 | }
|
---|
196 |
|
---|
197 | void MH::SetBinning(TH1 *h, const TAxis *binsx)
|
---|
198 | {
|
---|
199 | const Int_t nx = binsx->GetNbins();
|
---|
200 |
|
---|
201 | TArrayD bx(nx+1);
|
---|
202 | for (int i=0; i<nx; i++) bx[i] = binsx->GetBinLowEdge(i+1);
|
---|
203 | bx[nx] = binsx->GetXmax();
|
---|
204 |
|
---|
205 | SetBinning(h, &bx);
|
---|
206 | }
|
---|
207 |
|
---|
208 | void MH::SetBinning(TH1 *h, const TAxis *binsx, const TAxis *binsy)
|
---|
209 | {
|
---|
210 | const Int_t nx = binsx->GetNbins();
|
---|
211 | const Int_t ny = binsy->GetNbins();
|
---|
212 |
|
---|
213 | TArrayD bx(nx+1);
|
---|
214 | TArrayD by(ny+1);
|
---|
215 | for (int i=0; i<nx; i++) bx[i] = binsx->GetBinLowEdge(i+1);
|
---|
216 | for (int i=0; i<ny; i++) by[i] = binsy->GetBinLowEdge(i+1);
|
---|
217 | bx[nx] = binsx->GetXmax();
|
---|
218 | by[ny] = binsy->GetXmax();
|
---|
219 |
|
---|
220 | SetBinning(h, &bx, &by);
|
---|
221 | }
|
---|
222 |
|
---|
223 | void MH::SetBinning(TH1 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz)
|
---|
224 | {
|
---|
225 | const Int_t nx = binsx->GetNbins();
|
---|
226 | const Int_t ny = binsy->GetNbins();
|
---|
227 | const Int_t nz = binsz->GetNbins();
|
---|
228 |
|
---|
229 | TArrayD bx(nx+1);
|
---|
230 | TArrayD by(ny+1);
|
---|
231 | TArrayD bz(nz+1);
|
---|
232 | for (int i=0; i<nx; i++) bx[i] = binsx->GetBinLowEdge(i+1);
|
---|
233 | for (int i=0; i<ny; i++) by[i] = binsy->GetBinLowEdge(i+1);
|
---|
234 | for (int i=0; i<nz; i++) bz[i] = binsz->GetBinLowEdge(i+1);
|
---|
235 | bx[nx] = binsx->GetXmax();
|
---|
236 | by[ny] = binsy->GetXmax();
|
---|
237 | bz[nz] = binsz->GetXmax();
|
---|
238 |
|
---|
239 | SetBinning(h, &bx, &by, &bz);
|
---|
240 | }
|
---|
241 |
|
---|
242 | void MH::SetBinning(TH1 *h, TH1 *x)
|
---|
243 | {
|
---|
244 | SetBinning(h, x->GetXaxis(), x->GetYaxis(), x->GetZaxis());
|
---|
245 | }
|
---|