source: trunk/MagicSoft/Mars/msim/MHPhotonEvent.cc@ 9328

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