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

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