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, 12/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2003
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MHCamEvent
|
---|
28 | //
|
---|
29 | // A histogram to store the sum of camera events. This can be photons,
|
---|
30 | // currents or enything else derived from MCamEvent
|
---|
31 | //
|
---|
32 | // Setup
|
---|
33 | // =====
|
---|
34 | //
|
---|
35 | // To count how often a certain pixel is above or below a threshold do:
|
---|
36 | // MHCamEvent::SetThreshold(5.5); // Default=LowerBound
|
---|
37 | // MHCamEvent::SetThreshold(5.5, MHCamEvent::kIsUpperBound);
|
---|
38 | //
|
---|
39 | //
|
---|
40 | // Axis titles
|
---|
41 | // ===========
|
---|
42 | //
|
---|
43 | // 1) If no other title is given 'a.u.' is used.
|
---|
44 | // 2) If the title of MHCamEvent is different from the default,
|
---|
45 | // it is used as histogram title. You can use this to set the
|
---|
46 | // axis title, too. For more information see TH1::SetTitle, eg.
|
---|
47 | // SetTitle("MyHist;;y[cm];Counts");
|
---|
48 | // Make sure to set an empty x-axis title.
|
---|
49 | //
|
---|
50 | // For example:
|
---|
51 | // MHCamEvent myhist("Titele;;y [cm]");
|
---|
52 | //
|
---|
53 | // Class Version 3:
|
---|
54 | // ----------------
|
---|
55 | // + fNameSub
|
---|
56 | // + fIsRatio
|
---|
57 | //
|
---|
58 | /////////////////////////////////////////////////////////////////////////////
|
---|
59 | #include "MHCamEvent.h"
|
---|
60 |
|
---|
61 | #include "MLog.h"
|
---|
62 | #include "MLogManip.h"
|
---|
63 |
|
---|
64 | #include "MString.h"
|
---|
65 | #include "MParList.h"
|
---|
66 | #include "MCamEvent.h"
|
---|
67 | #include "MHCamera.h"
|
---|
68 |
|
---|
69 | #include "MGeomCam.h"
|
---|
70 |
|
---|
71 | ClassImp(MHCamEvent);
|
---|
72 |
|
---|
73 | using namespace std;
|
---|
74 |
|
---|
75 | const TString MHCamEvent::gsDefName = "MHCamEvent";
|
---|
76 | const TString MHCamEvent::gsDefTitle = "Average of MCamEvents";
|
---|
77 |
|
---|
78 | // --------------------------------------------------------------------------
|
---|
79 | //
|
---|
80 | // Initialize the name and title of the task
|
---|
81 | //
|
---|
82 | void MHCamEvent::Init(const char *name, const char *title)
|
---|
83 | {
|
---|
84 | //
|
---|
85 | // set the name and title of this object
|
---|
86 | //
|
---|
87 | fName = name ? name : gsDefName.Data();
|
---|
88 | fTitle = title ? title : gsDefTitle.Data();
|
---|
89 |
|
---|
90 | fNameGeom = "MGeomCam";
|
---|
91 | }
|
---|
92 |
|
---|
93 | // --------------------------------------------------------------------------
|
---|
94 | //
|
---|
95 | // Initialize the name and title of the task. Set fType to 0
|
---|
96 | //
|
---|
97 | MHCamEvent::MHCamEvent(const char *name, const char *title)
|
---|
98 | : fSum(NULL), fErr(NULL), fEvt(NULL), fSub(0), fType(0), fErrorSpread(kTRUE), fErrorRelative(kFALSE),
|
---|
99 | fThreshold(0), fUseThreshold(0), fIsRatio(false)
|
---|
100 | {
|
---|
101 | Init(name, title);
|
---|
102 |
|
---|
103 | fSum = new MHCamera;
|
---|
104 | }
|
---|
105 |
|
---|
106 | // --------------------------------------------------------------------------
|
---|
107 | //
|
---|
108 | // Initialize the name and title of the task. Set fType to type
|
---|
109 | //
|
---|
110 | MHCamEvent::MHCamEvent(Int_t type, const char *name, const char *title)
|
---|
111 | : fSum(NULL), fErr(NULL), fEvt(NULL), fSub(0), fType(type), fErrorSpread(kTRUE), fErrorRelative(kFALSE),
|
---|
112 | fThreshold(0), fUseThreshold(0), fIsRatio(false)
|
---|
113 | {
|
---|
114 | Init(name, title);
|
---|
115 |
|
---|
116 | fSum = new MHCamera;
|
---|
117 | }
|
---|
118 |
|
---|
119 | // --------------------------------------------------------------------------
|
---|
120 | //
|
---|
121 | // Delete the corresponding camera display if available
|
---|
122 | //
|
---|
123 | MHCamEvent::~MHCamEvent()
|
---|
124 | {
|
---|
125 | if (fSum)
|
---|
126 | delete fSum;
|
---|
127 | }
|
---|
128 |
|
---|
129 | Bool_t MHCamEvent::InitGeom(const MParList &plist)
|
---|
130 | {
|
---|
131 | MGeomCam *cam = (MGeomCam*)plist.FindObject(fNameGeom, "MGeomCam");
|
---|
132 | if (!cam)
|
---|
133 | {
|
---|
134 | *fLog << err << fNameGeom << " [MGeomCam] not found... abort." << endl;
|
---|
135 | return kFALSE;
|
---|
136 | }
|
---|
137 |
|
---|
138 | // combine name
|
---|
139 | const TString name = fNameEvt.IsNull() ? fName : fNameEvt;
|
---|
140 |
|
---|
141 | fSum->SetGeometry(*cam, name+";avg");
|
---|
142 | if (fTitle!=gsDefTitle)
|
---|
143 | fSum->SetTitle(fTitle);
|
---|
144 | if (!fTitle.Contains(";"))
|
---|
145 | fSum->SetYTitle("a.u.");
|
---|
146 |
|
---|
147 | if (fErr)
|
---|
148 | fErr->SetGeometry(*fSum->GetGeometry(), fErr->GetName(), fErr->GetTitle());
|
---|
149 |
|
---|
150 | return kTRUE;
|
---|
151 | }
|
---|
152 |
|
---|
153 | // --------------------------------------------------------------------------
|
---|
154 | //
|
---|
155 | // Get the event (MCamEvent) the histogram might be filled with. If
|
---|
156 | // it is not given, it is assumed, that it is filled with the argument
|
---|
157 | // of the Fill function.
|
---|
158 | // Looks for the camera geometry MGeomCam and resets the sum histogram.
|
---|
159 | //
|
---|
160 | Bool_t MHCamEvent::SetupFill(const MParList *plist)
|
---|
161 | {
|
---|
162 | fEvt = dynamic_cast<MCamEvent*>(plist->FindObject(fNameEvt, "MCamEvent"));
|
---|
163 | if (!fEvt)
|
---|
164 | {
|
---|
165 | if (!fNameEvt.IsNull())
|
---|
166 | {
|
---|
167 | *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
|
---|
168 | return kFALSE;
|
---|
169 | }
|
---|
170 | *fLog << inf << GetDescriptor() << ": Assuming to get MCamEvent from Fill()..." << endl;
|
---|
171 | }
|
---|
172 |
|
---|
173 | fSub = 0;
|
---|
174 | if (!fNameSub.IsNull())
|
---|
175 | {
|
---|
176 | fSub = dynamic_cast<MCamEvent*>(plist->FindObject(fNameSub, "MCamEvent"));
|
---|
177 | if (!fSub)
|
---|
178 | {
|
---|
179 | *fLog << err << GetDescriptor() << ": No " << fNameSub <<" [MCamEvent] available..." << endl;
|
---|
180 | return kFALSE;
|
---|
181 | }
|
---|
182 | *fLog << inf << GetDescriptor() << ": Will subtract '" << fNameSub << "'" << endl;
|
---|
183 | }
|
---|
184 |
|
---|
185 | fSum->Reset();
|
---|
186 |
|
---|
187 | fNumReInit = 0;
|
---|
188 |
|
---|
189 | if (!InitGeom(*plist))
|
---|
190 | return kFALSE;
|
---|
191 |
|
---|
192 | if (fUseThreshold!=kCollectMin && fUseThreshold!=kCollectMax)
|
---|
193 | fSum->SetBit(MHCamera::kProfile);
|
---|
194 | if (!fErrorSpread)
|
---|
195 | fSum->SetBit(MHCamera::kErrorMean);
|
---|
196 |
|
---|
197 | return kTRUE;
|
---|
198 | }
|
---|
199 |
|
---|
200 | // --------------------------------------------------------------------------
|
---|
201 | //
|
---|
202 | // The geometry read from the RunHeaders might have changed. This does not
|
---|
203 | // effect anything in PreProcess. So we set a new geometry. We don't move
|
---|
204 | // this away from PreProcess to support also loops without calling ReInit.
|
---|
205 | //
|
---|
206 | Bool_t MHCamEvent::ReInit(MParList *plist)
|
---|
207 | {
|
---|
208 | return fNumReInit++==0 ? InitGeom(*plist) : kTRUE;
|
---|
209 | }
|
---|
210 |
|
---|
211 |
|
---|
212 | // --------------------------------------------------------------------------
|
---|
213 | //
|
---|
214 | // Fill the histograms with data from a MCamEvent-Container.
|
---|
215 | //
|
---|
216 | Int_t MHCamEvent::Fill(const MParContainer *par, const Stat_t w)
|
---|
217 | {
|
---|
218 | const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
|
---|
219 | if (!evt)
|
---|
220 | {
|
---|
221 | *fLog << err << dbginf << "Got no MCamEvent as argument of Fill()..." << endl;
|
---|
222 | return kERROR;
|
---|
223 | }
|
---|
224 |
|
---|
225 | switch (fUseThreshold)
|
---|
226 | {
|
---|
227 | case kNoBound:
|
---|
228 | if (fSub)
|
---|
229 | {
|
---|
230 | if (fIsRatio)
|
---|
231 | fSum->AddCamRatio(*evt, *fSub, fType, w);
|
---|
232 | else
|
---|
233 | fSum->AddCamDifference(*evt, *fSub, fType, w);
|
---|
234 | }
|
---|
235 | else
|
---|
236 | fSum->AddCamContent(*evt, fType, w);
|
---|
237 | break;
|
---|
238 |
|
---|
239 | case kIsLowerBound:
|
---|
240 | case kIsUpperBound:
|
---|
241 | fSum->CntCamContent(*evt, fThreshold, fType, fUseThreshold>0);
|
---|
242 | break;
|
---|
243 |
|
---|
244 | case kCollectMin:
|
---|
245 | fSum->SetMinCamContent(*evt, /*fThreshold,*/ fType);
|
---|
246 | break;
|
---|
247 |
|
---|
248 | case kCollectMax:
|
---|
249 | fSum->SetMaxCamContent(*evt, /*fThreshold,*/ fType);
|
---|
250 | break;
|
---|
251 |
|
---|
252 | case kMeanShift:
|
---|
253 | fSum->AddMeanShift(*evt, fType, w);
|
---|
254 | break;
|
---|
255 |
|
---|
256 | case kMedianShift:
|
---|
257 | fSum->AddMedianShift(*evt, fType, w);
|
---|
258 | break;
|
---|
259 |
|
---|
260 | default:
|
---|
261 | *fLog << err << "ERROR - MHCamEvent::Fill: Unknown type." << endl;
|
---|
262 | return kERROR;
|
---|
263 | }
|
---|
264 |
|
---|
265 | return kTRUE;
|
---|
266 | }
|
---|
267 |
|
---|
268 | // --------------------------------------------------------------------------
|
---|
269 | //
|
---|
270 | // Take the mean of the sum histogram and print all pixel indices
|
---|
271 | // which are above sum+s*rms
|
---|
272 | //
|
---|
273 | void MHCamEvent::PrintOutliers(Float_t s) const
|
---|
274 | {
|
---|
275 | const Double_t mean = fSum->GetMean();
|
---|
276 | const Double_t rms = fSum->GetRMS();
|
---|
277 |
|
---|
278 | *fLog << all << underline << GetDescriptor() << ": Mean=" << mean << ", Rms=" << rms << endl;
|
---|
279 |
|
---|
280 | for (UInt_t i=0; i<fSum->GetNumPixels(); i++)
|
---|
281 | {
|
---|
282 | if (!fSum->IsUsed(i))
|
---|
283 | continue;
|
---|
284 |
|
---|
285 | if ((*fSum)[i+1]>mean+s*rms)
|
---|
286 | *fLog << "Contents of Pixel-Index #" << i << ": " << (*fSum)[i+1] << " > " << s << "*rms" << endl;
|
---|
287 | }
|
---|
288 | }
|
---|
289 |
|
---|
290 | // --------------------------------------------------------------------------
|
---|
291 | //
|
---|
292 | // Return fSum for "sum" and fRms for "rms"
|
---|
293 | //
|
---|
294 | TH1 *MHCamEvent::GetHistByName(const TString name) const
|
---|
295 | {
|
---|
296 | return fSum;
|
---|
297 | }
|
---|
298 |
|
---|
299 | // --------------------------------------------------------------------------
|
---|
300 | //
|
---|
301 | // Set the camera histogram to a clone of cam
|
---|
302 | //
|
---|
303 | void MHCamEvent::SetHist(const MHCamera &cam)
|
---|
304 | {
|
---|
305 | if (fSum)
|
---|
306 | delete fSum;
|
---|
307 |
|
---|
308 | fSum = static_cast<MHCamera*>(cam.Clone());
|
---|
309 | }
|
---|
310 |
|
---|
311 | TString MHCamEvent::Format(const char *ext) const
|
---|
312 | {
|
---|
313 | TString n = fSum->GetName();
|
---|
314 |
|
---|
315 | const Ssiz_t pos = n.Last(';');
|
---|
316 | if (pos<0)
|
---|
317 | return "";
|
---|
318 |
|
---|
319 | n = n(0, pos);
|
---|
320 | n += ";";
|
---|
321 | n += ext;
|
---|
322 | return n;
|
---|
323 | }
|
---|
324 |
|
---|
325 | void MHCamEvent::Paint(Option_t *)
|
---|
326 | {
|
---|
327 | TVirtualPad *pad = gPad;
|
---|
328 |
|
---|
329 | pad->cd(2);
|
---|
330 | if (gPad->FindObject("proj"))
|
---|
331 | {
|
---|
332 | TH1 *h=fSum->Projection("proj");
|
---|
333 | if (h->GetMaximum()>0)
|
---|
334 | gPad->SetLogy();
|
---|
335 | }
|
---|
336 |
|
---|
337 | pad->cd(5);
|
---|
338 | if (gPad->FindObject("rad"))
|
---|
339 | fSum->RadialProfile("rad");
|
---|
340 |
|
---|
341 | pad->cd(6);
|
---|
342 | if (gPad->FindObject("az"))
|
---|
343 | fSum->AzimuthProfile("az");
|
---|
344 |
|
---|
345 | pad->cd(4);
|
---|
346 | gPad->cd(1);
|
---|
347 | MHCamera *cam = (MHCamera*)gPad->FindObject("err");
|
---|
348 | if (cam)
|
---|
349 | cam->SetCamContent(*fSum, fErrorRelative ? 2 : 1);
|
---|
350 | }
|
---|
351 |
|
---|
352 | void MHCamEvent::Draw(Option_t *)
|
---|
353 | {
|
---|
354 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
---|
355 | const Int_t col = pad->GetFillColor();
|
---|
356 | pad->SetBorderMode(0);
|
---|
357 |
|
---|
358 | AppendPad();
|
---|
359 |
|
---|
360 | TString name = MString::Format("%s_1", pad->GetName());
|
---|
361 | TPad *p = new TPad(name,name,0.005, 0.5, 0.66, 0.995,col,0,0);
|
---|
362 | p->SetFrameBorderMode(0);
|
---|
363 | p->SetNumber(1);
|
---|
364 | p->Draw();
|
---|
365 | p->cd();
|
---|
366 | fSum->Draw("EPhist");
|
---|
367 |
|
---|
368 | pad->cd();
|
---|
369 | name = MString::Format("%s_2", pad->GetName());
|
---|
370 | p = new TPad(name,name,0.66, 0.5, 0.995, 0.995,col,0,0);
|
---|
371 | p->SetFrameBorderMode(0);
|
---|
372 | p->SetNumber(2);
|
---|
373 | p->Draw();
|
---|
374 | p->cd();
|
---|
375 | TH1 *h = fSum->Projection("proj", 50);
|
---|
376 | h->SetTitle("Projection");
|
---|
377 | h->SetBit(kCanDelete);
|
---|
378 | h->Draw();
|
---|
379 |
|
---|
380 | pad->cd();
|
---|
381 | name = MString::Format("%s_3", pad->GetName());
|
---|
382 | p = new TPad(name,name,0.005, 0.005, 3./8, 0.5,col,0,0);
|
---|
383 | p->SetFrameBorderMode(0);
|
---|
384 | p->SetNumber(3);
|
---|
385 | p->Draw();
|
---|
386 | p->cd();
|
---|
387 | fSum->Draw();
|
---|
388 |
|
---|
389 | pad->cd();
|
---|
390 | name = MString::Format("%s_4", pad->GetName());
|
---|
391 | p = new TPad(name,name,3./8, 0.005, 6./8-0.005, 0.5,col,0,0);
|
---|
392 | p->SetFrameBorderMode(0);
|
---|
393 | p->SetNumber(4);
|
---|
394 | p->Draw();
|
---|
395 | p->cd();
|
---|
396 |
|
---|
397 | TString e = "Sqrt(Variance)";
|
---|
398 | if (fSum->TestBit(MHCamera::kErrorMean))
|
---|
399 | e += "/Sqrt(n_{i})";
|
---|
400 | if (fErrorRelative)
|
---|
401 | e += "/v_{i}";
|
---|
402 |
|
---|
403 | fErr = new MHCamera(*fSum->GetGeometry());
|
---|
404 | fErr->SetName("err");
|
---|
405 | fErr->SetTitle(e);
|
---|
406 | fErr->SetYTitle(fSum->GetYaxis()->GetTitle());
|
---|
407 | fErr->SetCamContent(*fSum, fErrorRelative ? 2 : 1);
|
---|
408 | fErr->SetBit(kMustCleanup);
|
---|
409 | fErr->SetBit(kCanDelete);
|
---|
410 | fErr->Draw();
|
---|
411 |
|
---|
412 | pad->cd();
|
---|
413 | name = MString::Format("%s_5", pad->GetName());
|
---|
414 | p = new TPad(name,name,6./8,0.25,0.995,0.5,col,0,0);
|
---|
415 | p->SetFrameBorderMode(0);
|
---|
416 | p->SetNumber(5);
|
---|
417 | p->Draw();
|
---|
418 | p->cd();
|
---|
419 | h = (TH1*)fSum->RadialProfile("rad", 20);
|
---|
420 | h->SetTitle("Radial Profile");
|
---|
421 | h->SetBit(kCanDelete|TH1::kNoStats);
|
---|
422 | h->Draw();
|
---|
423 |
|
---|
424 | pad->cd();
|
---|
425 | name = MString::Format("%s_6", pad->GetName());
|
---|
426 | p = new TPad(name,name,6./8,0.005,0.995,0.25,col,0,0);
|
---|
427 | p->SetFrameBorderMode(0);
|
---|
428 | p->SetNumber(6);
|
---|
429 | p->Draw();
|
---|
430 | p->cd();
|
---|
431 | h = (TH1*)fSum->AzimuthProfile("az", 30);
|
---|
432 | h->SetTitle("Azimuth Profile");
|
---|
433 | h->SetBit(kCanDelete|TH1::kNoStats);
|
---|
434 | h->Draw();
|
---|
435 | }
|
---|
436 |
|
---|
437 |
|
---|
438 | void MHCamEvent::RecursiveRemove(TObject *obj)
|
---|
439 | {
|
---|
440 | if (obj==fErr)
|
---|
441 | fErr = 0;
|
---|
442 | if (obj==fSum)
|
---|
443 | fSum = 0;
|
---|
444 |
|
---|
445 | MH::RecursiveRemove(obj);
|
---|
446 | }
|
---|