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

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