source: trunk/MagicSoft/Mars/mimage/MHVsSize.cc@ 6979

Last change on this file since 6979 was 6961, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 10.6 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! Author(s): Wolfgang Wittek 2002 <mailto:wittek@mppmu.mpg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MHVsSize
29//
30// This class contains histograms for the source independent image parameters
31//
32/////////////////////////////////////////////////////////////////////////////
33#include "MHVsSize.h"
34
35#include <TH2.h>
36#include <TPad.h>
37#include <TStyle.h>
38#include <TCanvas.h>
39
40#include "MLog.h"
41#include "MLogManip.h"
42
43#include "MParList.h"
44
45#include "MHillas.h"
46#include "MHillasSrc.h"
47#include "MHillasExt.h"
48#include "MNewImagePar.h"
49#include "MGeomCam.h"
50#include "MBinning.h"
51
52ClassImp(MHVsSize);
53
54using namespace std;
55
56// --------------------------------------------------------------------------
57//
58// Setup four histograms for Width, Length
59//
60MHVsSize::MHVsSize(const char *name, const char *title)
61 : fHillas(NULL), fHillasExt(NULL), fNewImagePar(NULL), fMm2Deg(1), fUseMmScale(kTRUE)
62{
63 //
64 // set the name and title of this object
65 //
66 fName = name ? name : "MHVsSize";
67 fTitle = title ? title : "Source independent image parameters";
68
69 fLength.SetNameTitle("Length", "Length vs. Size");
70 fWidth.SetNameTitle( "Width", "Width vs. Size");
71 fDist.SetNameTitle( "Dist", "Dist vs. Size");
72 fConc1.SetNameTitle( "Conc1", "Conc1 vs. Size");
73 fArea.SetNameTitle( "Area", "Area vs. Size");
74 fM3Long.SetNameTitle("M3Long", "M3Long vs. Size");
75
76 fLength.SetDirectory(NULL);
77 fWidth.SetDirectory(NULL);
78 fDist.SetDirectory(NULL);
79 fConc1.SetDirectory(NULL);
80 fArea.SetDirectory(NULL);
81 fM3Long.SetDirectory(NULL);
82
83 fLength.SetXTitle("Size [phe]");
84 fWidth.SetXTitle("Size [phe]");
85 fDist.SetXTitle("Size [phe]");
86 fConc1.SetXTitle("Size [phe]");
87 fArea.SetXTitle("Size [phe]");
88 fM3Long.SetXTitle("Size [phe]");
89
90 fLength.SetYTitle("Length [mm]");
91 fWidth.SetYTitle("Width [mm]");
92 fDist.SetYTitle("Distance [mm]");
93 fConc1.SetYTitle("Conc1 [ratio]");
94 fArea.SetYTitle("Conc1 [mm^{2}]");
95 fM3Long.SetYTitle("M3Long [mm]");
96
97 MBinning binse, binsl, binsd, binsc, binsa, binsm;
98 binse.SetEdgesLog( 50, 10, 1e5);
99 binsl.SetEdges( 100, 0, 296.7/2);
100 binsd.SetEdges( 100, 0, 600);
101 binsc.SetEdgesLog(100, 1e-5, 5e-3);
102 binsa.SetEdges( 100, 0, 445*45);
103 binsm.SetEdges( 100, -445, 445);
104
105 MH::SetBinning(&fLength, &binse, &binsl);
106 MH::SetBinning(&fWidth, &binse, &binsl);
107 MH::SetBinning(&fDist, &binse, &binsd);
108 MH::SetBinning(&fConc1, &binse, &binsc);
109 MH::SetBinning(&fArea, &binse, &binsa);
110 MH::SetBinning(&fM3Long, &binse, &binsm);
111
112 fLength.UseCurrentStyle();
113 fWidth.UseCurrentStyle();
114 fDist.UseCurrentStyle();
115 fConc1.UseCurrentStyle();
116 fArea.UseCurrentStyle();
117 fM3Long.UseCurrentStyle();
118}
119
120// --------------------------------------------------------------------------
121//
122// Setup the Binning for the histograms automatically if the correct
123// instances of MBinning (with the names 'BinningWidth' and 'BinningLength')
124// are found in the parameter list
125// Use this function if you want to set the conversion factor which
126// is used to convert the mm-scale in the camera plain into the deg-scale
127// used for histogram presentations. The conversion factor is part of
128// the camera geometry. Please create a corresponding MGeomCam container.
129//
130Bool_t MHVsSize::SetupFill(const MParList *plist)
131{
132 MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
133 if (!geom)
134 *fLog << warn << GetDescriptor() << ": No Camera Geometry available. Using mm-scale for histograms." << endl;
135 else
136 {
137 fMm2Deg = geom->GetConvMm2Deg();
138 SetMmScale(kFALSE);
139 }
140
141 fHillas = (MHillas*)plist->FindObject("MHillas");
142 if (!fHillas)
143 {
144 *fLog << err << "MHillas not found... abort." << endl;
145 return kFALSE;
146 }
147
148 fHillasExt = (MHillasExt*)plist->FindObject("MHillasExt");
149 if (!fHillasExt)
150 {
151 *fLog << err << "MHillasExt not found... abort." << endl;
152 return kFALSE;
153 }
154
155 fNewImagePar = (MNewImagePar*)plist->FindObject("MNewImagePar");
156 if (!fNewImagePar)
157 {
158 *fLog << err << "MNewImagePar not found... abort." << endl;
159 return kFALSE;
160 }
161
162 /*
163 ApplyBinning(*plist, "Width", fWidth);
164 ApplyBinning(*plist, "Length", fLength);
165 ApplyBinning(*plist, "Dist", fDistC);
166 ApplyBinning(*plist, "Delta", fDelta);
167 ApplyBinning(*plist, "Size", fSize);
168
169 const MBinning *bins = (MBinning*)plist->FindObject("BinningCamera");
170 if (!bins)
171 {
172 float r = fGeomCam ? fGeomCam->GetMaxRadius() : 600;
173 r *= 0.9;
174 if (!fUseMmScale)
175 r *= fMm2Deg;
176
177 MBinning b;
178 b.SetEdges(61, -r, r);
179 SetBinning(fCenter, &b, &b);
180 }
181 else
182 SetBinning(fCenter, bins, bins);
183 */
184
185 return kTRUE;
186}
187
188// --------------------------------------------------------------------------
189//
190// Use this function to setup your own conversion factor between degrees
191// and millimeters. The conversion factor should be the one calculated in
192// MGeomCam. Use this function with Caution: You could create wrong values
193// by setting up your own scale factor.
194//
195void MHVsSize::SetMm2Deg(Float_t mmdeg)
196{
197 if (mmdeg<0)
198 {
199 *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
200 return;
201 }
202
203 if (fMm2Deg>=0)
204 *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
205
206 fMm2Deg = mmdeg;
207}
208
209// --------------------------------------------------------------------------
210//
211// With this function you can convert the histogram ('on the fly') between
212// degrees and millimeters.
213//
214void MHVsSize::SetMmScale(Bool_t mmscale)
215{
216 if (fUseMmScale == mmscale)
217 return;
218
219 if (fMm2Deg<0)
220 {
221 *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
222 return;
223 }
224
225 const Double_t scale = mmscale ? 1./fMm2Deg : fMm2Deg;
226 MH::ScaleAxis(&fLength, 1, scale);
227 MH::ScaleAxis(&fWidth, 1, scale);
228 MH::ScaleAxis(&fDist, 1, scale);
229 MH::ScaleAxis(&fM3Long, 1, scale);
230 MH::ScaleAxis(&fArea, 1, scale*scale);
231
232 if (mmscale)
233 {
234 fLength.SetYTitle("Length [mm]");
235 fWidth.SetYTitle("Width [mm]");
236 fDist.SetYTitle("Distance [mm]");
237 fArea.SetYTitle("Area [mm^{2}]");
238 fM3Long.SetYTitle("M3Long [mm]");
239 }
240 else
241 {
242 fLength.SetYTitle("Length [\\circ]");
243 fWidth.SetYTitle("Width [\\circ]");
244 fDist.SetYTitle("Distance [\\circ]");
245 fArea.SetYTitle("Area [\\circ^{2}]");
246 fM3Long.SetYTitle("M3Long [\\circ]");
247 }
248
249 fUseMmScale = mmscale;
250}
251
252// --------------------------------------------------------------------------
253//
254// Fill the histograms with data from a MHillas-Container.
255// Be careful: Only call this with an object of type MHillas
256//
257Bool_t MHVsSize::Fill(const MParContainer *par, const Stat_t w)
258{
259 const MHillasSrc *src = dynamic_cast<const MHillasSrc*>(par);
260 if (!src)
261 {
262 *fLog << err << "MHVsSize::Fill: Wrong argument... abort." << endl;
263 return kFALSE;
264 }
265
266 const Double_t scale = fUseMmScale ? 1 : fMm2Deg;
267
268 fLength.Fill(fHillas->GetSize(), scale*fHillas->GetLength(), w);
269 fWidth.Fill( fHillas->GetSize(), scale*fHillas->GetWidth(), w);
270 fDist.Fill( fHillas->GetSize(), scale*src->GetDist(), w);
271 fConc1.Fill( fHillas->GetSize(), scale*fNewImagePar->GetConc1(), w);
272 fArea.Fill( fHillas->GetSize(), scale*scale*fHillas->GetArea(), w);
273 fM3Long.Fill(fHillas->GetSize(), scale*fHillasExt->GetM3Long()*TMath::Sign(1.0f, src->GetCosDeltaAlpha()), w);
274
275 return kTRUE;
276}
277
278// --------------------------------------------------------------------------
279//
280// Creates a new canvas and draws the four histograms into it.
281// Be careful: The histograms belongs to this object and won't get deleted
282// together with the canvas.
283//
284void MHVsSize::Draw(Option_t *o)
285{
286 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
287 pad->SetBorderMode(0);
288
289 AppendPad("");
290
291 TString opt(o);
292 opt.ToLower();
293
294 // FIXME: If same-option given make two independant y-axis!
295 const Bool_t same = opt.Contains("same");
296
297 if (!same)
298 pad->Divide(3,2);
299 else
300 {
301 fLength.SetName("LengthSame");
302 fWidth.SetName("WidthSame");
303 fDist.SetName("DistSame");
304 fConc1.SetName("Conc1Same");
305 fArea.SetName("AreaSame");
306 fM3Long.SetName("M3LongSame");
307
308 fLength.SetDirectory(0);
309 fWidth.SetDirectory(0);
310 fDist.SetDirectory(0);
311 fConc1.SetDirectory(0);
312 fArea.SetDirectory(0);
313 fM3Long.SetDirectory(0);
314
315 fDist.SetMarkerColor(kBlue);
316 fConc1.SetMarkerColor(kBlue);
317 fWidth.SetMarkerColor(kBlue);
318 fLength.SetMarkerColor(kBlue);
319 fArea.SetMarkerColor(kBlue);
320 fM3Long.SetMarkerColor(kBlue);
321 }
322
323 pad->cd(1);
324 gPad->SetBorderMode(0);
325 gPad->SetLogx();
326 RemoveFromPad("LengthSame");
327 fLength.Draw(same?"same":"");
328
329 pad->cd(2);
330 gPad->SetBorderMode(0);
331 gPad->SetLogx();
332 RemoveFromPad("WidthSame");
333 fWidth.Draw(same?"same":"");
334
335 pad->cd(3);
336 gPad->SetBorderMode(0);
337 gPad->SetLogx();
338 RemoveFromPad("DistSame");
339 fDist.Draw(same?"same":"");
340
341 pad->cd(4);
342 gPad->SetBorderMode(0);
343 gPad->SetLogx();
344 RemoveFromPad("AreaSame");
345 fArea.Draw(same?"same":"");
346
347 pad->cd(5);
348 gPad->SetBorderMode(0);
349 gPad->SetLogx();
350 RemoveFromPad("M3LongSame");
351 fM3Long.Draw(same?"same":"");
352
353 pad->cd(6);
354 gPad->SetBorderMode(0);
355 gPad->SetLogx();
356 gPad->SetLogy();
357 RemoveFromPad("Conc1Same");
358 fConc1.Draw(same?"same":"");
359}
Note: See TracBrowser for help on using the repository browser.