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 2001 <mailto:tbretz@uni-sw.gwdg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2002
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MHHillas
|
---|
28 | //
|
---|
29 | // This class contains histograms for every Hillas parameter
|
---|
30 | //
|
---|
31 | /////////////////////////////////////////////////////////////////////////////
|
---|
32 |
|
---|
33 | #include "MHHillas.h"
|
---|
34 |
|
---|
35 | #include <math.h>
|
---|
36 |
|
---|
37 | #include <TH1.h>
|
---|
38 | #include <TPad.h>
|
---|
39 | #include <TCanvas.h>
|
---|
40 |
|
---|
41 | #include "MLog.h"
|
---|
42 | #include "MLogManip.h"
|
---|
43 |
|
---|
44 | #include "MGeomCam.h"
|
---|
45 | #include "MHillas.h"
|
---|
46 | #include "MParList.h"
|
---|
47 |
|
---|
48 | ClassImp(MHHillas);
|
---|
49 |
|
---|
50 | // --------------------------------------------------------------------------
|
---|
51 | //
|
---|
52 | // Setup four histograms for Width, Length
|
---|
53 | //
|
---|
54 | MHHillas::MHHillas(const char *name, const char *title)
|
---|
55 | : fMm2Deg(-1), fUseMmScale(kFALSE)
|
---|
56 | {
|
---|
57 | //
|
---|
58 | // set the name and title of this object
|
---|
59 | //
|
---|
60 | fName = name ? name : "MHHillas";
|
---|
61 | fTitle = title ? title : "Container for Hillas histograms";
|
---|
62 |
|
---|
63 | //
|
---|
64 | // loop over all Pixels and create two histograms
|
---|
65 | // one for the Low and one for the High gain
|
---|
66 | // connect all the histogram with the container fHist
|
---|
67 | //
|
---|
68 | fWidth = new TH1F("Width", "Width of Ellipse", 100, 0, 300);
|
---|
69 | fLength = new TH1F("Length", "Length of Ellipse", 100, 0, 300);
|
---|
70 |
|
---|
71 | fLength->SetDirectory(NULL);
|
---|
72 | fWidth->SetDirectory(NULL);
|
---|
73 |
|
---|
74 | fLength->GetXaxis()->SetTitle("Length [mm]");
|
---|
75 | fWidth->GetXaxis()->SetTitle("Width [mm]");
|
---|
76 |
|
---|
77 | fLength->GetYaxis()->SetTitle("Counts");
|
---|
78 | fWidth->GetYaxis()->SetTitle("Counts");
|
---|
79 | }
|
---|
80 |
|
---|
81 | // --------------------------------------------------------------------------
|
---|
82 | //
|
---|
83 | // Delete the four histograms
|
---|
84 | //
|
---|
85 | MHHillas::~MHHillas()
|
---|
86 | {
|
---|
87 | delete fWidth;
|
---|
88 | delete fLength;
|
---|
89 | }
|
---|
90 |
|
---|
91 | // --------------------------------------------------------------------------
|
---|
92 | //
|
---|
93 | // Setup the Binning for the histograms automatically if the correct
|
---|
94 | // instances of MBinning (with the names 'BinningWidth' and 'BinningLength')
|
---|
95 | // are found in the parameter list
|
---|
96 | // Use this function if you want to set the conversion factor which
|
---|
97 | // is used to convert the mm-scale in the camera plain into the deg-scale
|
---|
98 | // used for histogram presentations. The conversion factor is part of
|
---|
99 | // the camera geometry. Please create a corresponding MGeomCam container.
|
---|
100 | //
|
---|
101 | Bool_t MHHillas::SetupFill(const MParList *plist)
|
---|
102 | {
|
---|
103 | const MBinning* binsw = (MBinning*)plist->FindObject("BinningWidth");
|
---|
104 | const MBinning* binsl = (MBinning*)plist->FindObject("BinningLength");
|
---|
105 | if (!binsw || !binsl)
|
---|
106 | {
|
---|
107 | *fLog << err << dbginf << "At least one MBinning not found... aborting." << endl;
|
---|
108 | return kFALSE;
|
---|
109 | }
|
---|
110 |
|
---|
111 | SetBinning(fWidth, binsw);
|
---|
112 | SetBinning(fLength, binsl);
|
---|
113 |
|
---|
114 | const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
|
---|
115 | if (!geom)
|
---|
116 | {
|
---|
117 | *fLog << warn << dbginf << "No Camera Geometry available. Using mm-scale for histograms." << endl;
|
---|
118 | return kTRUE;
|
---|
119 | }
|
---|
120 |
|
---|
121 | fLength->GetXaxis()->SetTitle("Length [\\circ]");
|
---|
122 | fWidth->GetXaxis()->SetTitle("Width [\\circ]");
|
---|
123 |
|
---|
124 | fMm2Deg = geom->GetConvMm2Deg();
|
---|
125 |
|
---|
126 | return kTRUE;
|
---|
127 | }
|
---|
128 |
|
---|
129 | // --------------------------------------------------------------------------
|
---|
130 | //
|
---|
131 | // Fill the four histograms with data from a MHillas-Container.
|
---|
132 | // Be careful: Only call this with an object of type MHillas
|
---|
133 | //
|
---|
134 | Bool_t MHHillas::Fill(const MParContainer *par)
|
---|
135 | {
|
---|
136 | const MHillas &h = *(MHillas*)par;
|
---|
137 |
|
---|
138 | if (fUseMmScale)
|
---|
139 | {
|
---|
140 | fWidth ->Fill(h.GetWidth());
|
---|
141 | fLength->Fill(h.GetLength());
|
---|
142 | }
|
---|
143 | else
|
---|
144 | {
|
---|
145 | fWidth ->Fill(fMm2Deg*h.GetWidth());
|
---|
146 | fLength->Fill(fMm2Deg*h.GetLength());
|
---|
147 | }
|
---|
148 |
|
---|
149 | return kTRUE;
|
---|
150 | }
|
---|
151 |
|
---|
152 | // --------------------------------------------------------------------------
|
---|
153 | //
|
---|
154 | // Use this function to setup your own conversion factor between degrees
|
---|
155 | // and millimeters. The conversion factor should be the one calculated in
|
---|
156 | // MGeomCam. Use this function with Caution: You could create wrong values
|
---|
157 | // by setting up your own scale factor.
|
---|
158 | //
|
---|
159 | void MHHillas::SetMm2Deg(Float_t mmdeg)
|
---|
160 | {
|
---|
161 | if (mmdeg<0)
|
---|
162 | {
|
---|
163 | *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
|
---|
164 | return;
|
---|
165 | }
|
---|
166 |
|
---|
167 | if (fMm2Deg>=0)
|
---|
168 | *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
|
---|
169 |
|
---|
170 | fMm2Deg = mmdeg;
|
---|
171 | }
|
---|
172 |
|
---|
173 | // --------------------------------------------------------------------------
|
---|
174 | //
|
---|
175 | // With this function you can convert the histogram ('on the fly') between
|
---|
176 | // degrees and millimeters.
|
---|
177 | //
|
---|
178 | void MHHillas::SetMmScale(Bool_t mmscale)
|
---|
179 | {
|
---|
180 | if (fUseMmScale == mmscale)
|
---|
181 | return;
|
---|
182 |
|
---|
183 | if (fMm2Deg<0)
|
---|
184 | {
|
---|
185 | *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
|
---|
186 | return;
|
---|
187 | }
|
---|
188 |
|
---|
189 | if (fUseMmScale)
|
---|
190 | {
|
---|
191 | fLength->GetXaxis()->SetTitle("Length [mm]");
|
---|
192 | fWidth->GetXaxis()->SetTitle("Width [mm]");
|
---|
193 |
|
---|
194 | fLength->Scale(1./fMm2Deg);
|
---|
195 | fWidth->Scale(1./fMm2Deg);
|
---|
196 | }
|
---|
197 | else
|
---|
198 | {
|
---|
199 | fLength->GetXaxis()->SetTitle("Length [\\circ]");
|
---|
200 | fWidth->GetXaxis()->SetTitle("Width [\\circ]");
|
---|
201 |
|
---|
202 | fLength->Scale(fMm2Deg);
|
---|
203 | fWidth->Scale(fMm2Deg);
|
---|
204 | }
|
---|
205 |
|
---|
206 | fUseMmScale = mmscale;
|
---|
207 | }
|
---|
208 |
|
---|
209 | // --------------------------------------------------------------------------
|
---|
210 | //
|
---|
211 | // Draw clones of all four histograms. So that the object can be deleted
|
---|
212 | // and the histograms are still visible in the canvas.
|
---|
213 | // The cloned object are deleted together with the canvas if the canvas is
|
---|
214 | // destroyed. If you want to handle dostroying the canvas you can get a
|
---|
215 | // pointer to it from this function
|
---|
216 | //
|
---|
217 | TObject *MHHillas::DrawClone(Option_t *opt) const
|
---|
218 | {
|
---|
219 | TCanvas *c = MakeDefCanvas("Hillas", "Histograms of Hillas Parameters",
|
---|
220 | 350, 500);
|
---|
221 | c->Divide(1, 2);
|
---|
222 |
|
---|
223 | gROOT->SetSelectedPad(NULL);
|
---|
224 |
|
---|
225 | //
|
---|
226 | // This is necessary to get the expected bahviour of DrawClone
|
---|
227 | //
|
---|
228 | c->cd(1);
|
---|
229 | fLength->DrawCopy();
|
---|
230 |
|
---|
231 | c->cd(2);
|
---|
232 | fWidth->DrawCopy();
|
---|
233 |
|
---|
234 | c->Modified();
|
---|
235 | c->Update();
|
---|
236 |
|
---|
237 | return c;
|
---|
238 | }
|
---|
239 |
|
---|
240 | // --------------------------------------------------------------------------
|
---|
241 | //
|
---|
242 | // Creates a new canvas and draws the four histograms into it.
|
---|
243 | // Be careful: The histograms belongs to this object and won't get deleted
|
---|
244 | // together with the canvas.
|
---|
245 | //
|
---|
246 | void MHHillas::Draw(Option_t *)
|
---|
247 | {
|
---|
248 | if (!gPad)
|
---|
249 | MakeDefCanvas("Hillas", "Histograms of Hillas Parameters", 350, 500);
|
---|
250 |
|
---|
251 | gPad->Divide(1, 2);
|
---|
252 |
|
---|
253 | gPad->cd(1);
|
---|
254 | fLength->Draw();
|
---|
255 |
|
---|
256 | gPad->cd(2);
|
---|
257 | fWidth->Draw();
|
---|
258 |
|
---|
259 | gPad->Modified();
|
---|
260 | gPad->Update();
|
---|
261 | }
|
---|