source: trunk/MagicSoft/Mars/mhist/MHHillasExt.cc@ 1575

Last change on this file since 1575 was 1574, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 9.1 KB
Line 
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// MHHillasExt
28//
29// This class contains histograms for every Hillas parameter
30//
31/////////////////////////////////////////////////////////////////////////////
32
33#include "MHHillasExt.h"
34
35#include <math.h>
36
37#include <TH1.h>
38#include <TPad.h>
39#include <TLegend.h>
40#include <TCanvas.h>
41
42#include "MLog.h"
43#include "MLogManip.h"
44
45#include "MGeomCam.h"
46
47#include "MParList.h"
48
49#include "MBinning.h"
50#include "MHillasExt.h"
51#include "MHillasSrc.h"
52
53ClassImp(MHHillasExt);
54
55// --------------------------------------------------------------------------
56//
57// Setup four histograms for Width, Length
58//
59MHHillasExt::MHHillasExt(const char *name, const char *title)
60 : fMm2Deg(1), fUseMmScale(kTRUE)
61{
62 //
63 // set the name and title of this object
64 //
65 fName = name ? name : "MHHillasExt";
66 fTitle = title ? title : "Container for extended Hillas histograms";
67
68 //
69 // loop over all Pixels and create two histograms
70 // one for the Low and one for the High gain
71 // connect all the histogram with the container fHist
72 //
73 fHConc1.SetLineColor(kBlue);
74 fHConc.SetFillStyle(0);
75
76 fHConc.SetDirectory(NULL);
77 fHConc1.SetDirectory(NULL);
78 fHAsym.SetDirectory(NULL);
79 fHM3Long.SetDirectory(NULL);
80 fHM3Trans.SetDirectory(NULL);
81
82 fHConc.SetName("Conc2");
83 fHConc1.SetName("Conc1");
84 fHAsym.SetName("Asymmetry");
85 fHM3Long.SetName("3rd Mom Long");
86 fHM3Trans.SetName("3rd Mom Trans");
87
88 fHConc.SetTitle("Ratio: Conc");
89 fHConc1.SetTitle("Ratio: Conc1");
90 fHAsym.SetTitle("Asymmetry");
91 fHM3Long.SetTitle("3^{rd} Moment Longitudinal");
92 fHM3Trans.SetTitle("3^{rd} Moment Transverse");
93
94 fHConc.SetXTitle("Ratio");
95 fHConc1.SetXTitle("Ratio");
96 fHAsym.SetXTitle("Asym [mm]");
97 fHM3Long.SetXTitle("3^{rd} M_{l} [mm]");
98 fHM3Trans.SetXTitle("3^{rd} M_{t} [mm]");
99
100 fHConc.SetYTitle("Counts");
101 fHConc1.SetYTitle("Counts");
102 fHAsym.SetYTitle("Counts");
103 fHM3Long.SetYTitle("Counts");
104 fHM3Trans.SetYTitle("Counts");
105
106
107 MBinning bins;
108
109 bins.SetEdges(100, 0, 1);
110 bins.Apply(fHConc);
111 bins.Apply(fHConc1);
112
113 bins.SetEdges(101, -326, 326);
114 bins.Apply(fHM3Long);
115 bins.Apply(fHM3Trans);
116
117 bins.SetEdges(101, -593, 593);
118 bins.Apply(fHAsym);
119}
120
121// --------------------------------------------------------------------------
122//
123// Delete the four histograms
124//
125MHHillasExt::~MHHillasExt()
126{
127}
128
129// --------------------------------------------------------------------------
130//
131// Setup the Binning for the histograms automatically if the correct
132// instances of MBinning (with the names 'BinningWidth' and 'BinningLength')
133// are found in the parameter list
134// Use this function if you want to set the conversion factor which
135// is used to convert the mm-scale in the camera plain into the deg-scale
136// used for histogram presentations. The conversion factor is part of
137// the camera geometry. Please create a corresponding MGeomCam container.
138//
139Bool_t MHHillasExt::SetupFill(const MParList *plist)
140{
141 TObject *obj = plist->FindObject("MHillas");
142 if (!obj)
143 {
144 *fLog << err << dbginf << "Sorry 'MHillas' not found in parameter list... aborting." << endl;
145 return kFALSE;
146 }
147 if (!obj->InheritsFrom(MHillasExt::Class()))
148 {
149 *fLog << err << dbginf << "Sorry 'MHillas' doesn't inherit from MHillasExt... aborting." << endl;
150 return kFALSE;
151 }
152 fHillasExt = (MHillasExt*)obj;
153
154 const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
155 if (!geom)
156 *fLog << warn << GetDescriptor() << ": No Camera Geometry available. Using mm-scale for histograms." << endl;
157 else
158 {
159 fMm2Deg = geom->GetConvMm2Deg();
160 SetMmScale(kFALSE);
161 }
162
163 ApplyBinning(*plist, "Conc", &fHConc);
164 ApplyBinning(*plist, "Conc1", &fHConc1);
165 ApplyBinning(*plist, "Asym", &fHAsym);
166 ApplyBinning(*plist, "M3Long", &fHM3Long);
167 ApplyBinning(*plist, "M3Trans", &fHM3Trans);
168
169 return kTRUE;
170}
171
172// --------------------------------------------------------------------------
173//
174// Fill the four histograms with data from a MHillas-Container.
175// Be careful: Only call this with an object of type MHillas
176//
177Bool_t MHHillasExt::Fill(const MParContainer *par)
178{
179 const MHillasSrc *src = (MHillasSrc*)par;
180
181 const Double_t scale = src ? TMath::Sign(fUseMmScale?1:fMm2Deg, src->GetCosDeltaAlpha()) : 1;
182
183 fHConc.Fill(fHillasExt->GetConc());
184 fHConc1.Fill(fHillasExt->GetConc1());
185
186 fHAsym.Fill(scale*fHillasExt->GetAsym());
187 fHM3Long.Fill(scale*fHillasExt->GetM3Long());
188 fHM3Trans.Fill(scale*fHillasExt->GetM3Trans());
189 //fHAsymna.Fill(scale*ext.GetAsymna());
190 //fHAsym0.Fill(scale*ext.GetAsym0());
191
192 return kTRUE;
193}
194
195// --------------------------------------------------------------------------
196//
197// With this function you can convert the histogram ('on the fly') between
198// degrees and millimeters.
199//
200void MHHillasExt::SetMmScale(Bool_t mmscale)
201{
202 if (fUseMmScale == mmscale)
203 return;
204
205 if (fMm2Deg<0)
206 {
207 *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
208 return;
209 }
210
211 const Double_t scale = mmscale ? 1./fMm2Deg : fMm2Deg;
212 MH::ScaleAxis(&fHAsym, scale);
213 MH::ScaleAxis(&fHM3Long, scale);
214 MH::ScaleAxis(&fHM3Trans, scale);
215
216 if (mmscale)
217 {
218 fHAsym.SetXTitle("Asym [mm]");
219 fHM3Long.SetXTitle("3^{rd} M_{l} [mm]");
220 fHM3Trans.SetXTitle("3^{rd} M_{t} [mm]");
221 }
222 else
223 {
224 fHAsym.SetXTitle("Asym [\\circ]");
225 fHM3Long.SetXTitle("3^{rd} M_{l} [\\circ]");
226 fHM3Trans.SetXTitle("3^{rd} M_{t} [\\circ]");
227 }
228
229 fUseMmScale = mmscale;
230}
231
232// --------------------------------------------------------------------------
233//
234// Use this function to setup your own conversion factor between degrees
235// and millimeters. The conversion factor should be the one calculated in
236// MGeomCam. Use this function with Caution: You could create wrong values
237// by setting up your own scale factor.
238//
239void MHHillasExt::SetMm2Deg(Float_t mmdeg)
240{
241 if (mmdeg<0)
242 {
243 *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
244 return;
245 }
246
247 if (fMm2Deg>=0)
248 *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
249
250 fMm2Deg = mmdeg;
251}
252
253// --------------------------------------------------------------------------
254//
255// Draw clones of all four histograms. So that the object can be deleted
256// and the histograms are still visible in the canvas.
257// The cloned object are deleted together with the canvas if the canvas is
258// destroyed. If you want to handle dostroying the canvas you can get a
259// pointer to it from this function
260//
261TObject *MHHillasExt::DrawClone(Option_t *opt) const
262{
263 TCanvas &c = *MakeDefCanvas(this, 720, 540);
264 c.Divide(2, 2);
265
266 gROOT->SetSelectedPad(NULL);
267
268 c.cd(1);
269 DrawCopy(fHConc1, fHConc, "Concentrations");
270
271 c.cd(2);
272 ((TH1&)fHAsym).DrawCopy();
273
274 c.cd(3);
275 ((TH1&)fHM3Long).DrawCopy();
276
277 c.cd(4);
278 ((TH1&)fHM3Trans).DrawCopy();
279
280 c.Modified();
281 c.Update();
282
283 return &c;
284}
285
286// --------------------------------------------------------------------------
287//
288// Creates a new canvas and draws the four histograms into it.
289// Be careful: The histograms belongs to this object and won't get deleted
290// together with the canvas.
291//
292void MHHillasExt::Draw(Option_t *)
293{
294 if (!gPad)
295 MakeDefCanvas(this, 720, 540);
296
297 gPad->Divide(2, 2);
298
299 gPad->cd(1);
300 MH::Draw(fHConc1, fHConc, "Concentrations");
301
302 gPad->cd(2);
303 fHAsym.Draw();
304
305 gPad->cd(3);
306 fHM3Long.Draw();
307
308 gPad->cd(4);
309 fHM3Trans.Draw();
310
311 gPad->Modified();
312 gPad->Update();
313}
314
315TH1 *MHHillasExt::GetHistByName(const TString name)
316{
317 if (name.Contains("Conc", TString::kIgnoreCase))
318 return &fHConc;
319 if (name.Contains("Conc1", TString::kIgnoreCase))
320 return &fHConc1;
321 if (name.Contains("Asym", TString::kIgnoreCase))
322 return &fHAsym;
323 if (name.Contains("M3Long", TString::kIgnoreCase))
324 return &fHM3Long;
325 if (name.Contains("M3Trans", TString::kIgnoreCase))
326 return &fHM3Trans;
327
328 return NULL;
329}
Note: See TracBrowser for help on using the repository browser.