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

Last change on this file since 9477 was 9367, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 11.1 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("\\lambda [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
128// --------------------------------------------------------------------------
129//
130// Default constructor. Creates and initializes the histograms.
131//
132MHPhotonEvent::MHPhotonEvent(Double_t max, const char *name, const char *title)
133 : fHistT("", "", 1, 0, 1, 1, 0, 1), fType(-1), fPermanentReset(kFALSE)
134{
135 // pre-initialization of the profile is necessary to get fZmin and fZmax set
136
137 Init(name, title);
138
139 MBinning binsd, binsa;
140 binsd.SetEdges(50, -max, max);
141 binsa.SetEdges(50, -1, 1);
142
143 SetBinning(&fHistXY, &binsd, &binsd);
144 SetBinning(&fHistUV, &binsa, &binsa);
145 SetBinning(&fHistT, &binsd, &binsd);
146}
147
148// --------------------------------------------------------------------------
149//
150// Creates and initializes the histograms.
151//
152MHPhotonEvent::MHPhotonEvent(Int_t type, const char *name, const char *title)
153 : fHistT("", "", 1, 0, 1, 1, 0, 1), fType(type), fPermanentReset(kFALSE)
154{
155 // pre-initialization of the profile is necessary to get fZmin and fZmax set
156
157 Init(name, title);
158
159 MBinning binsd, bins;
160 bins.SetEdges(50, -1, 1);
161
162 SetBinning(&fHistUV, &bins, &bins);
163}
164
165// --------------------------------------------------------------------------
166//
167// Find good limits for a binning num x [-max;max]
168// and apply it to fHistXY and fHistT.
169//
170void MHPhotonEvent::SetBinningXY(Int_t num, Double_t max)
171{
172 Double_t min = -max;
173
174 MH::FindGoodLimits(num, num, min, max, kFALSE);
175
176 MBinning binsd, binsa, binsz;
177 binsd.SetEdges(num, min, max);
178
179 SetBinning(&fHistXY, &binsd, &binsd);
180 SetBinning(&fHistT, &binsd, &binsd);
181}
182
183// --------------------------------------------------------------------------
184//
185// Search for MRflEvtData, MRflEvtHeader and MGeomCam
186//
187Bool_t MHPhotonEvent::SetupFill(const MParList *pList)
188{
189 Double_t xmax = -1;
190 Int_t num = 100;
191
192 const Int_t f = fPermanentReset ? 2 : 1;
193 MBinning(100/f, 0, 25).Apply(fHistH);
194 MBinning(70, 275, 625).Apply(fHistWL);
195
196 switch (fType)
197 {
198 case -1:
199 return kTRUE;
200 // case0: Take a value defined by the user
201 case 1:
202 xmax = 25000;
203 break;
204 case 2:
205 {
206 MReflector *r = (MReflector*)pList->FindObject("Reflector", "MReflector");
207 if (!r)
208 {
209 *fLog << err << "Reflector [MReflector] not found... aborting." << endl;
210 return kFALSE;
211 }
212 xmax = r->GetMaxR();
213 break;
214 }
215 case 3: // The maximum radius
216 case 4: // Two times the pixel-0 traversal size
217 {
218 MGeomCam *c = (MGeomCam*)pList->FindObject("MGeomCam");
219 if (!c)
220 {
221 *fLog << err << "MGeomCam not found... aborting." << endl;
222 return kFALSE;
223 }
224 xmax = fType==3 ? c->GetMaxRadius()/10 : 2*(*c)[0].GetT()/10;
225 num = 50;
226
227 break;
228 }
229 default:
230 *fLog << err << "No valid binning (Type=" << fType << ") given... aborting." << endl;
231 return kFALSE;
232 }
233
234 SetBinningXY(num, xmax);
235
236 return kTRUE;
237}
238
239// --------------------------------------------------------------------------
240//
241// ReInit overwrites the binning of the Wavelength histogram
242// by the wavlenegth band from MCorsikaRunHeader.
243// The bin-width is 5nm (fPermanentReset==kTRUE) or 10nm (kFALSE).
244//
245Bool_t MHPhotonEvent::ReInit(MParList *pList)
246{
247 MCorsikaRunHeader *h = (MCorsikaRunHeader*)pList->FindObject("MCorsikaRunHeader");
248 if (!h)
249 {
250 *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
251 return kFALSE;
252 }
253
254 /*
255 // What is the size of the light pool onm the ground?
256 if (fType==1)
257 SetBinningXY(100, h->GetImpactMax());
258 */
259
260 const Int_t f = fPermanentReset ? 10 : 2;
261
262 Double_t xmin = h->GetWavelengthMin()-20;
263 Double_t xmax = h->GetWavelengthMax()+20;
264 Int_t num = TMath::CeilNint((xmax-xmin)/f);
265
266 MH::FindGoodLimits(num, num, xmin, xmax, kTRUE);
267
268 MBinning(TMath::Abs(num), xmin-.5, xmax-.5).Apply(fHistWL);
269
270 return kTRUE;
271}
272
273// --------------------------------------------------------------------------
274//
275// Fill contents of MPhotonEvent into histograms
276//
277Int_t MHPhotonEvent::Fill(const MParContainer *par, const Stat_t weight)
278{
279 const MPhotonEvent *evt = dynamic_cast<const MPhotonEvent*>(par);
280 if (!evt)
281 {
282 *fLog << err << dbginf << "No MPhotonEvent found..." << endl;
283 return kERROR;
284 }
285
286 // Check if we want to use this class as a single event display
287 if (fPermanentReset && evt->GetNumPhotons()>0)
288 Clear();
289
290 // Get number of photons
291 const Int_t num = evt->GetNumPhotons();
292
293 // Set minimum to maximum possible value
294 Double_t min = FLT_MAX;
295
296 // Loop over all photons and determine the time of the first photon
297 // FIXME: Should we get it from some statistics container?
298 for (Int_t idx=0; idx<num; idx++)
299 min = TMath::Min(min, (*evt)[idx].GetTime());
300
301 // Now fill all histograms
302 for (Int_t idx=0; idx<num; idx++)
303 {
304 const MPhotonData &ph = (*evt)[idx];
305
306 if (ph.GetPrimary()==MMcEvtBasic::kNightSky)
307 continue;
308
309 const Double_t x = ph.GetPosX();
310 const Double_t y = ph.GetPosY();
311 const Double_t u = ph.GetCosU();
312 const Double_t v = ph.GetCosV();
313 const Double_t t = ph.GetTime()-min;
314 const Double_t w = ph.GetWavelength();
315 const Double_t h = ph.GetProductionHeight()/100000;
316
317 //TVector3 dir = dat->GetDir3();
318 //dir *= -1./dir.Z();
319
320 fHistXY.Fill(x, y);
321 fHistUV.Fill(u, v);
322 fHistT.Fill(x, y, t);
323 fHistWL.Fill(w);
324 fHistH.Fill(h);
325 }
326
327 return kTRUE;
328}
329
330// --------------------------------------------------------------------------
331//
332/*
333Bool_t MHPhotonEvent::Finalize()
334{
335 const TAxis &axey = *fHistRad.GetYaxis();
336 for (int y=1; y<=fHistRad.GetNbinsY(); y++)
337 {
338 const Double_t lo = axey.GetBinLowEdge(y);
339 const Double_t hi = axey.GetBinLowEdge(y+1);
340
341 const Double_t A = (hi*hi-lo*lo)*TMath::Pi()*TMath::Pi();
342
343 for (int x=1; x<=fHistRad.GetNbinsX(); x++)
344 fHistRad.SetBinContent(x, y, fHistRad.GetBinContent(x, y)/A);
345 }
346 return kTRUE;
347}
348*/
349
350// --------------------------------------------------------------------------
351//
352// Make sure that the TProfile2D doesn't fix it's displayed minimum at 0.
353// Set the pretty-palette.
354//
355void MHPhotonEvent::Paint(Option_t *opt)
356{
357 SetPalette("pretty");
358
359 fHistT.SetMinimum();
360 fHistT.SetMinimum(fHistT.GetMinimum(0));
361}
362
363// --------------------------------------------------------------------------
364//
365void MHPhotonEvent::Draw(Option_t *o)
366{
367 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
368 pad->SetBorderMode(0);
369
370 AppendPad();
371
372 pad->Divide(3,2);
373
374 pad->cd(1);
375 gPad->SetBorderMode(0);
376 gPad->SetGrid();
377 fHistXY.Draw("colz");
378
379 pad->cd(2);
380 gPad->SetBorderMode(0);
381 gPad->SetGrid();
382 fHistT.Draw("colz");
383
384 pad->cd(4);
385 gPad->SetBorderMode(0);
386 gPad->SetGrid();
387 fHistUV.Draw("colz");
388
389 pad->cd(5);
390 gPad->SetBorderMode(0);
391 gPad->SetGrid();
392 fHistWL.Draw();
393
394 pad->cd(6);
395 gPad->SetBorderMode(0);
396 gPad->SetGrid();
397 fHistH.Draw();
398}
399
400// --------------------------------------------------------------------------
401//
402// PermanentReset: Off
403//
404Int_t MHPhotonEvent::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
405{
406 Bool_t rc = kFALSE;
407 if (IsEnvDefined(env, prefix, "PermanentReset", print))
408 {
409 rc = kTRUE;
410 fPermanentReset = GetEnvValue(env, prefix, "PermanentReset", fPermanentReset);
411 }
412
413 return rc;
414}
Note: See TracBrowser for help on using the repository browser.