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, 1/2009 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: Software Development, 2000-2009
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MHPhotonEvent
|
---|
28 | //
|
---|
29 | // This is a histogram class to visualize the contents of a MPhotonEvent.
|
---|
30 | //
|
---|
31 | // Histograms for the distribution in x/y (z is just ignored), the
|
---|
32 | // arrival direction, a profile of the arrival time vs position and
|
---|
33 | // a spectrum is filles and displayed.
|
---|
34 | //
|
---|
35 | // There are several types of histograms (in the sense of binnings)
|
---|
36 | // for several purposes:
|
---|
37 | //
|
---|
38 | // Type 1:
|
---|
39 | // The maximum in x and y is determined from MCorsikaRunHeader
|
---|
40 | // (not yet implemented. Fixed to 25000)
|
---|
41 | //
|
---|
42 | // Type 2:
|
---|
43 | // The maximum in x and y is determined from MReflector->GetMaxR();
|
---|
44 | //
|
---|
45 | // Type 3:
|
---|
46 | // The maximum in x and y is determined from MCamera->GetMaxR();
|
---|
47 | //
|
---|
48 | // Type 4:
|
---|
49 | // As type 3 but divided by 10.
|
---|
50 | //
|
---|
51 | // Type 5:
|
---|
52 | // The maximum in x and y is determined from MGeomCam->GetMaxR();
|
---|
53 | //
|
---|
54 | // Type 6:
|
---|
55 | // As type 5 but divided by 10.
|
---|
56 | //
|
---|
57 | // The binning is optimized using MH::FindGoodLimits. The number of bins
|
---|
58 | // in 100 in the default case and 50 for type 3-6.
|
---|
59 | //
|
---|
60 | // Fill expects a MPhotonEvent (the second argumnet in MFillH).
|
---|
61 | //
|
---|
62 | /////////////////////////////////////////////////////////////////////////////
|
---|
63 | #include "MHPhotonEvent.h"
|
---|
64 |
|
---|
65 | #include <TCanvas.h>
|
---|
66 |
|
---|
67 | #include "MLog.h"
|
---|
68 | #include "MLogManip.h"
|
---|
69 |
|
---|
70 | #include "MBinning.h"
|
---|
71 | #include "MParList.h"
|
---|
72 |
|
---|
73 | #include "MGeomCam.h"
|
---|
74 |
|
---|
75 | #include "MPhotonEvent.h"
|
---|
76 | #include "MPhotonData.h"
|
---|
77 |
|
---|
78 | #include "MCorsikaRunHeader.h"
|
---|
79 |
|
---|
80 | #include "../msimreflector/MSimReflector.h" // MCamera, MReflector
|
---|
81 |
|
---|
82 | ClassImp(MHPhotonEvent);
|
---|
83 |
|
---|
84 | using namespace std;
|
---|
85 |
|
---|
86 | void MHPhotonEvent::Init(const char *name, const char *title)
|
---|
87 | {
|
---|
88 | fName = name ? name : "MHPhotonEvent";
|
---|
89 | fTitle = title ? title : "Histogram to display the information of MPhotonEvents";
|
---|
90 |
|
---|
91 | fHistXY.SetName("Position");
|
---|
92 | fHistXY.SetTitle("Histogram of position x/y");
|
---|
93 | fHistXY.SetXTitle("X [cm]");
|
---|
94 | fHistXY.SetYTitle("Y [cm]");
|
---|
95 | fHistXY.SetZTitle("Counts");
|
---|
96 | fHistXY.SetDirectory(NULL);
|
---|
97 | fHistXY.Sumw2();
|
---|
98 |
|
---|
99 | fHistUV.SetName("Direction");
|
---|
100 | fHistUV.SetTitle("Histogram of arrival direction CosU/CosV");
|
---|
101 | fHistUV.SetXTitle("CosU");
|
---|
102 | fHistUV.SetYTitle("CosV");
|
---|
103 | fHistUV.SetZTitle("Counts");
|
---|
104 | fHistUV.SetDirectory(NULL);
|
---|
105 | fHistUV.Sumw2();
|
---|
106 |
|
---|
107 | fHistT.SetName("Time");
|
---|
108 | fHistT.SetTitle("Time profile in x/y");
|
---|
109 | fHistT.SetXTitle("X [cm]");
|
---|
110 | fHistT.SetYTitle("Y [cm]");
|
---|
111 | fHistT.SetZTitle("T [ns]");
|
---|
112 | fHistT.SetDirectory(NULL);
|
---|
113 |
|
---|
114 | fHistWL.SetName("Spectrum");
|
---|
115 | fHistWL.SetTitle("Wavelength distribution");
|
---|
116 | fHistWL.SetXTitle("\\lamba [nm]");
|
---|
117 | fHistWL.SetYTitle("Counts");
|
---|
118 | fHistWL.SetDirectory(NULL);
|
---|
119 |
|
---|
120 | // FIXME: Get this information from the corsika run-header
|
---|
121 | MBinning(70, 275, 625).Apply(fHistWL);
|
---|
122 | }
|
---|
123 |
|
---|
124 | // --------------------------------------------------------------------------
|
---|
125 | //
|
---|
126 | // Default constructor. Creates and initializes the histograms.
|
---|
127 | //
|
---|
128 | MHPhotonEvent::MHPhotonEvent(Double_t max, const char *name, const char *title)
|
---|
129 | : fHistT("", "", 1, 0, 1, 1, 0, 1), fType(-1), fPermanentReset(kFALSE)
|
---|
130 | {
|
---|
131 | // pre-initialization of the profile is necessary to get fZmin and fZmax set
|
---|
132 |
|
---|
133 | Init(name, title);
|
---|
134 |
|
---|
135 | MBinning binsd, binsa;
|
---|
136 | binsd.SetEdges(50, -max, max);
|
---|
137 | binsa.SetEdges(50, -1, 1);
|
---|
138 |
|
---|
139 | SetBinning(&fHistXY, &binsd, &binsd);
|
---|
140 | SetBinning(&fHistUV, &binsa, &binsa);
|
---|
141 | SetBinning(&fHistT, &binsd, &binsd);
|
---|
142 | }
|
---|
143 |
|
---|
144 | // --------------------------------------------------------------------------
|
---|
145 | //
|
---|
146 | // Creates and initializes the histograms.
|
---|
147 | //
|
---|
148 | MHPhotonEvent::MHPhotonEvent(Int_t type, const char *name, const char *title)
|
---|
149 | : fHistT("", "", 1, 0, 1, 1, 0, 1), fType(type), fPermanentReset(kFALSE)
|
---|
150 | {
|
---|
151 | // pre-initialization of the profile is necessary to get fZmin and fZmax set
|
---|
152 |
|
---|
153 | Init(name, title);
|
---|
154 |
|
---|
155 | MBinning binsd, bins;
|
---|
156 | bins.SetEdges(50, -1, 1);
|
---|
157 |
|
---|
158 | SetBinning(&fHistUV, &bins, &bins);
|
---|
159 | }
|
---|
160 |
|
---|
161 | // --------------------------------------------------------------------------
|
---|
162 | //
|
---|
163 | // Search for MRflEvtData, MRflEvtHeader and MGeomCam
|
---|
164 | //
|
---|
165 | Bool_t MHPhotonEvent::SetupFill(const MParList *pList)
|
---|
166 | {
|
---|
167 | Double_t xmax = -1;
|
---|
168 | Int_t num = 100;
|
---|
169 |
|
---|
170 | switch (fType)
|
---|
171 | {
|
---|
172 | case -1:
|
---|
173 | return kTRUE;
|
---|
174 | // case0: Take a value defined by the user
|
---|
175 | case 1:
|
---|
176 | {
|
---|
177 | MCorsikaRunHeader *h = (MCorsikaRunHeader*)pList->FindObject("MCorsikaRunHeader");
|
---|
178 | if (!h)
|
---|
179 | {
|
---|
180 | *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
|
---|
181 | return kFALSE;
|
---|
182 | }
|
---|
183 | xmax = 25000;//h->GetImpactMax()*1.25; // Estimate scattering in the atmosphere
|
---|
184 | break;
|
---|
185 | }
|
---|
186 | case 2:
|
---|
187 | {
|
---|
188 | MReflector *r = (MReflector*)pList->FindObject("MReflector");
|
---|
189 | if (!r)
|
---|
190 | {
|
---|
191 | *fLog << err << "MReflector not found... aborting." << endl;
|
---|
192 | return kFALSE;
|
---|
193 | }
|
---|
194 | xmax = r->GetMaxR();
|
---|
195 | break;
|
---|
196 | }
|
---|
197 | case 3:
|
---|
198 | case 4:
|
---|
199 | {
|
---|
200 | MCamera *c = (MCamera*)pList->FindObject("MCamera");
|
---|
201 | if (!c)
|
---|
202 | {
|
---|
203 | *fLog << err << "MCamera not found... aborting." << endl;
|
---|
204 | return kFALSE;
|
---|
205 | }
|
---|
206 | xmax = fType==3 ? c->GetMaxR() : c->GetMaxR()/10;
|
---|
207 | num = 50;
|
---|
208 |
|
---|
209 | break;
|
---|
210 | }
|
---|
211 | case 5:
|
---|
212 | case 6:
|
---|
213 | {
|
---|
214 | MGeomCam *c = (MGeomCam*)pList->FindObject("MGeomCam");
|
---|
215 | if (!c)
|
---|
216 | {
|
---|
217 | *fLog << err << "MGeomCam not found... aborting." << endl;
|
---|
218 | return kFALSE;
|
---|
219 | }
|
---|
220 | xmax = fType==5 ? c->GetMaxRadius() : c->GetMaxRadius()/10;
|
---|
221 | num = 50;
|
---|
222 |
|
---|
223 | break;
|
---|
224 | }
|
---|
225 | default:
|
---|
226 | *fLog << err << "No valid binning (Type=" << fType << ") given... aborting." << endl;
|
---|
227 | return kFALSE;
|
---|
228 | }
|
---|
229 |
|
---|
230 | Double_t xmin = -xmax;
|
---|
231 |
|
---|
232 | MH::FindGoodLimits(num, num, xmin, xmax, kFALSE);
|
---|
233 |
|
---|
234 | MBinning binsd, binsa, binsz;
|
---|
235 | binsd.SetEdges(num, xmin, xmax);
|
---|
236 |
|
---|
237 | SetBinning(&fHistXY, &binsd, &binsd);
|
---|
238 | SetBinning(&fHistT, &binsd, &binsd);
|
---|
239 |
|
---|
240 | return kTRUE;
|
---|
241 | }
|
---|
242 |
|
---|
243 | // --------------------------------------------------------------------------
|
---|
244 | //
|
---|
245 | // Fill contents of MPhotonEvent into histograms
|
---|
246 | //
|
---|
247 | Int_t MHPhotonEvent::Fill(const MParContainer *par, const Stat_t weight)
|
---|
248 | {
|
---|
249 | const MPhotonEvent *evt = dynamic_cast<const MPhotonEvent*>(par);
|
---|
250 | if (!evt)
|
---|
251 | {
|
---|
252 | *fLog << err << dbginf << "No MPhotonEvent found..." << endl;
|
---|
253 | return kERROR;
|
---|
254 | }
|
---|
255 |
|
---|
256 | // Check if we want to use this class as a single event display
|
---|
257 | if (fPermanentReset && evt->GetNumPhotons()>0)
|
---|
258 | {
|
---|
259 | fHistXY.Reset();
|
---|
260 | fHistUV.Reset();
|
---|
261 | fHistT.Reset();
|
---|
262 | }
|
---|
263 |
|
---|
264 | // Get number of photons
|
---|
265 | const Int_t num = evt->GetNumPhotons();
|
---|
266 |
|
---|
267 | // Set minimum to maximum possible value
|
---|
268 | Double_t min = FLT_MAX;
|
---|
269 |
|
---|
270 | // Loop over all photons and determine the time of the first photon
|
---|
271 | // FIXME: Should we get it from some statistics container?
|
---|
272 | for (Int_t idx=0; idx<num; idx++)
|
---|
273 | min = TMath::Min(min, (*evt)[idx].GetTime());
|
---|
274 |
|
---|
275 | // Now fill all histograms
|
---|
276 | for (Int_t idx=0; idx<num; idx++)
|
---|
277 | {
|
---|
278 | const MPhotonData &ph = (*evt)[idx];
|
---|
279 |
|
---|
280 | const Double_t x = ph.GetPosX();
|
---|
281 | const Double_t y = ph.GetPosY();
|
---|
282 | const Double_t u = ph.GetCosU();
|
---|
283 | const Double_t v = ph.GetCosV();
|
---|
284 | const Double_t t = ph.GetTime()-min;
|
---|
285 | const Double_t w = ph.GetWavelength();
|
---|
286 |
|
---|
287 | //TVector3 dir = dat->GetDir3();
|
---|
288 | //dir *= -1./dir.Z();
|
---|
289 |
|
---|
290 | fHistXY.Fill(x, y);
|
---|
291 | fHistUV.Fill(u, v);
|
---|
292 | fHistT.Fill(x, y, t);
|
---|
293 | fHistWL.Fill(w);
|
---|
294 | }
|
---|
295 |
|
---|
296 | return kTRUE;
|
---|
297 | }
|
---|
298 |
|
---|
299 | // --------------------------------------------------------------------------
|
---|
300 | //
|
---|
301 | /*
|
---|
302 | Bool_t MHPhotonEvent::Finalize()
|
---|
303 | {
|
---|
304 | const TAxis &axey = *fHistRad.GetYaxis();
|
---|
305 | for (int y=1; y<=fHistRad.GetNbinsY(); y++)
|
---|
306 | {
|
---|
307 | const Double_t lo = axey.GetBinLowEdge(y);
|
---|
308 | const Double_t hi = axey.GetBinLowEdge(y+1);
|
---|
309 |
|
---|
310 | const Double_t A = (hi*hi-lo*lo)*TMath::Pi()*TMath::Pi();
|
---|
311 |
|
---|
312 | for (int x=1; x<=fHistRad.GetNbinsX(); x++)
|
---|
313 | fHistRad.SetBinContent(x, y, fHistRad.GetBinContent(x, y)/A);
|
---|
314 | }
|
---|
315 | return kTRUE;
|
---|
316 | }
|
---|
317 | */
|
---|
318 |
|
---|
319 | // --------------------------------------------------------------------------
|
---|
320 | //
|
---|
321 | // Make sure that the TProfile2D doesn't fix it's displayed minimum at 0.
|
---|
322 | // Set the pretty-palette.
|
---|
323 | //
|
---|
324 | void MHPhotonEvent::Paint(Option_t *opt)
|
---|
325 | {
|
---|
326 | SetPalette("pretty");
|
---|
327 |
|
---|
328 | fHistT.SetMinimum();
|
---|
329 | fHistT.SetMinimum(fHistT.GetMinimum(0));
|
---|
330 | }
|
---|
331 |
|
---|
332 | // --------------------------------------------------------------------------
|
---|
333 | //
|
---|
334 | void MHPhotonEvent::Draw(Option_t *o)
|
---|
335 | {
|
---|
336 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
---|
337 | pad->SetBorderMode(0);
|
---|
338 |
|
---|
339 | AppendPad();
|
---|
340 |
|
---|
341 | pad->Divide(3,2);
|
---|
342 |
|
---|
343 | pad->cd(1);
|
---|
344 | gPad->SetBorderMode(0);
|
---|
345 | gPad->SetGrid();
|
---|
346 | fHistXY.Draw("colz");
|
---|
347 |
|
---|
348 | pad->cd(2);
|
---|
349 | gPad->SetBorderMode(0);
|
---|
350 | gPad->SetGrid();
|
---|
351 | fHistT.Draw("colz");
|
---|
352 |
|
---|
353 | pad->cd(4);
|
---|
354 | gPad->SetBorderMode(0);
|
---|
355 | gPad->SetGrid();
|
---|
356 | fHistUV.Draw("colz");
|
---|
357 |
|
---|
358 | pad->cd(5);
|
---|
359 | gPad->SetBorderMode(0);
|
---|
360 | gPad->SetGrid();
|
---|
361 | fHistWL.Draw();
|
---|
362 | }
|
---|