source: trunk/MagicSoft/Mars/mimage/MHHillasExt.cc@ 4693

Last change on this file since 4693 was 3682, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 8.2 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@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHHillasExt
28//
29// This class contains histograms for every Hillas parameter
30//
31/////////////////////////////////////////////////////////////////////////////
32#include "MHHillasExt.h"
33
34#include <math.h>
35
36#include <TH1.h>
37#include <TPad.h>
38#include <TLegend.h>
39#include <TCanvas.h>
40
41#include "MLog.h"
42#include "MLogManip.h"
43
44#include "MGeomCam.h"
45
46#include "MParList.h"
47
48#include "MBinning.h"
49#include "MHillasExt.h"
50#include "MHillasSrc.h"
51
52ClassImp(MHHillasExt);
53
54using namespace std;
55
56// --------------------------------------------------------------------------
57//
58// Setup four histograms for Width, Length
59//
60MHHillasExt::MHHillasExt(const char *name, const char *title)
61 : fMm2Deg(1), fUseMmScale(kTRUE), fHilName("MHillasExt")
62{
63 //
64 // set the name and title of this object
65 //
66 fName = name ? name : "MHHillasExt";
67 fTitle = title ? title : "Container for extended Hillas histograms";
68
69 //
70 // loop over all Pixels and create two histograms
71 // one for the Low and one for the High gain
72 // connect all the histogram with the container fHist
73 //
74 fHAsym.SetDirectory(NULL);
75 fHM3Long.SetDirectory(NULL);
76 fHM3Trans.SetDirectory(NULL);
77 fHMaxDist.SetDirectory(NULL);
78
79 fHAsym.UseCurrentStyle();
80 fHM3Long.UseCurrentStyle();
81 fHM3Trans.UseCurrentStyle();
82 fHMaxDist.UseCurrentStyle();
83
84 fHAsym.SetName("Asymmetry");
85 fHM3Long.SetName("3rd Mom Long");
86 fHM3Trans.SetName("3rd Mom Trans");
87 fHMaxDist.SetName("Max Dist");
88
89 fHAsym.SetTitle("Asymmetry");
90 fHM3Long.SetTitle("3^{rd} Moment Longitudinal");
91 fHM3Trans.SetTitle("3^{rd} Moment Transverse");
92 fHMaxDist.SetTitle("Distance of max distant pixel");
93
94 fHAsym.SetXTitle("Asym [mm]");
95 fHM3Long.SetXTitle("3^{rd} M_{l} [mm]");
96 fHM3Trans.SetXTitle("3^{rd} M_{t} [mm]");
97 fHMaxDist.SetXTitle("D_{max} [mm]");
98
99 fHAsym.SetYTitle("Counts");
100 fHM3Long.SetYTitle("Counts");
101 fHM3Trans.SetYTitle("Counts");
102 fHMaxDist.SetYTitle("Counts");
103
104 fHAsym.SetFillStyle(4000);
105 fHM3Long.SetFillStyle(4000);
106 fHM3Trans.SetFillStyle(4000);
107 fHMaxDist.SetFillStyle(4000);
108
109 fHM3Trans.SetLineColor(kBlue);
110
111 MBinning bins;
112
113 bins.SetEdges(51, -326, 326);
114 bins.Apply(fHM3Long);
115 bins.Apply(fHM3Trans);
116
117 bins.SetEdges(51, -593, 593);
118 bins.Apply(fHAsym);
119
120 bins.SetEdges(101, 0, 593);
121 bins.Apply(fHMaxDist);
122}
123
124// --------------------------------------------------------------------------
125//
126// Setup the Binning for the histograms automatically if the correct
127// instances of MBinning (with the names 'BinningWidth' and 'BinningLength')
128// are found in the parameter list
129// Use this function if you want to set the conversion factor which
130// is used to convert the mm-scale in the camera plain into the deg-scale
131// used for histogram presentations. The conversion factor is part of
132// the camera geometry. Please create a corresponding MGeomCam container.
133//
134Bool_t MHHillasExt::SetupFill(const MParList *plist)
135{
136 fHillasExt = (MHillasExt*)plist->FindObject(fHilName, "MHillasExt");
137 if (!fHillasExt)
138 {
139 *fLog << err << fHilName << "[MHillasExt] not found in parameter list... aborting." << endl;
140 return kFALSE;
141 }
142
143 const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
144 if (!geom)
145 *fLog << warn << GetDescriptor() << ": No Camera Geometry available. Using mm-scale for histograms." << endl;
146 else
147 {
148 fMm2Deg = geom->GetConvMm2Deg();
149 SetMmScale(kFALSE);
150 }
151
152 ApplyBinning(*plist, "Asym", &fHAsym);
153 ApplyBinning(*plist, "M3Long", &fHM3Long);
154 ApplyBinning(*plist, "M3Trans", &fHM3Trans);
155 ApplyBinning(*plist, "MaxDist", &fHMaxDist);
156
157 return kTRUE;
158}
159
160// --------------------------------------------------------------------------
161//
162// Fill the four histograms with data from a MHillas-Container.
163// Be careful: Only call this with an object of type MHillas
164//
165Bool_t MHHillasExt::Fill(const MParContainer *par, const Stat_t w)
166{
167 const MHillasSrc *src = (MHillasSrc*)par;
168
169 const Double_t scale = TMath::Sign(fUseMmScale?1:fMm2Deg, (src ? src->GetCosDeltaAlpha() : 1));
170
171 fHAsym.Fill(scale*fHillasExt->GetAsym(), w);
172 fHM3Long.Fill(scale*fHillasExt->GetM3Long(), w);
173 fHM3Trans.Fill(scale*fHillasExt->GetM3Trans(), w);
174 fHMaxDist.Fill(TMath::Abs(scale*fHillasExt->GetMaxDist()), w);
175
176 return kTRUE;
177}
178
179// --------------------------------------------------------------------------
180//
181// With this function you can convert the histogram ('on the fly') between
182// degrees and millimeters.
183//
184void MHHillasExt::SetMmScale(Bool_t mmscale)
185{
186 if (fUseMmScale == mmscale)
187 return;
188
189 if (fMm2Deg<0)
190 {
191 *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
192 return;
193 }
194
195 const Double_t scale = mmscale ? 1./fMm2Deg : fMm2Deg;
196 MH::ScaleAxis(&fHAsym, scale);
197 MH::ScaleAxis(&fHM3Long, scale);
198 MH::ScaleAxis(&fHM3Trans, scale);
199 MH::ScaleAxis(&fHMaxDist, scale);
200
201 if (mmscale)
202 {
203 fHAsym.SetXTitle("Asym [mm]");
204 fHM3Long.SetXTitle("3^{rd} M_{l} [mm]");
205 fHM3Trans.SetXTitle("3^{rd} M_{t} [mm]");
206 fHMaxDist.SetXTitle("D_{max} [mm]");
207 }
208 else
209 {
210 fHAsym.SetXTitle("Asym [\\circ]");
211 fHM3Long.SetXTitle("3^{rd} M_{l} [\\circ]");
212 fHM3Trans.SetXTitle("3^{rd} M_{t} [\\circ]");
213 fHMaxDist.SetXTitle("D_{max} [\\circ]");
214 }
215
216 fUseMmScale = mmscale;
217}
218
219// --------------------------------------------------------------------------
220//
221// Use this function to setup your own conversion factor between degrees
222// and millimeters. The conversion factor should be the one calculated in
223// MGeomCam. Use this function with Caution: You could create wrong values
224// by setting up your own scale factor.
225//
226void MHHillasExt::SetMm2Deg(Float_t mmdeg)
227{
228 if (mmdeg<0)
229 {
230 *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
231 return;
232 }
233
234 if (fMm2Deg>=0)
235 *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
236
237 fMm2Deg = mmdeg;
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//
246void MHHillasExt::Draw(Option_t *)
247{
248 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
249 pad->SetBorderMode(0);
250
251 AppendPad("");
252
253 pad->Divide(2, 2);
254
255 pad->cd(1);
256 gPad->SetBorderMode(0);
257 MH::DrawSame(fHM3Long, fHM3Trans, "3^{rd} Moments");
258
259 pad->cd(3);
260 gPad->SetBorderMode(0);
261 fHAsym.Draw();
262
263 pad->cd(2);
264 gPad->SetBorderMode(0);
265 fHMaxDist.Draw();
266
267 delete pad->GetPad(4);
268
269 pad->Modified();
270 pad->Update();
271}
272
273TH1 *MHHillasExt::GetHistByName(const TString name)
274{
275 if (name.Contains("Asym", TString::kIgnoreCase))
276 return &fHAsym;
277 if (name.Contains("M3Long", TString::kIgnoreCase))
278 return &fHM3Long;
279 if (name.Contains("M3Trans", TString::kIgnoreCase))
280 return &fHM3Trans;
281 if (name.Contains("MaxDist", TString::kIgnoreCase))
282 return &fHMaxDist;
283
284 return NULL;
285}
Note: See TracBrowser for help on using the repository browser.