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 plot the variance instead of the rms use:
|
---|
36 | // MHCamEvent::SetBit(MHCamera::kVariance);
|
---|
37 | // or
|
---|
38 | // MHCamEvent::EnableVariance()
|
---|
39 | //
|
---|
40 | // To count how often a certain pixel is above or below a threshold do:
|
---|
41 | // MHCamEvent::SetThreshold(5.5); // Default=LowerBound
|
---|
42 | // MHCamEvent::SetThreshold(5.5, MHCamEvent::kIsUpperBound);
|
---|
43 | //
|
---|
44 | //
|
---|
45 | // Axis titles
|
---|
46 | // ===========
|
---|
47 | //
|
---|
48 | // 1) If no other title is given 'a.u.' is used.
|
---|
49 | // 2) If the title of MHCamEvent is different from the default,
|
---|
50 | // it is used as histogram title. You can use this to set the
|
---|
51 | // axis title, too. For more information see TH1::SetTitle, eg.
|
---|
52 | // SetTitle("MyHist;;y[cm];Counts");
|
---|
53 | // Make sure to set an empty x-axis title.
|
---|
54 | //
|
---|
55 | // For example:
|
---|
56 | // MHCamEvent myhist("Titele;;y [cm]");
|
---|
57 | //
|
---|
58 | /////////////////////////////////////////////////////////////////////////////
|
---|
59 | #include "MHCamEvent.h"
|
---|
60 |
|
---|
61 | #include <TCanvas.h>
|
---|
62 | #include <TPaveStats.h>
|
---|
63 |
|
---|
64 | #include "MLog.h"
|
---|
65 | #include "MLogManip.h"
|
---|
66 |
|
---|
67 | #include "MParList.h"
|
---|
68 | #include "MCamEvent.h"
|
---|
69 | #include "MHCamera.h"
|
---|
70 |
|
---|
71 | #include "MGeomCam.h"
|
---|
72 |
|
---|
73 | ClassImp(MHCamEvent);
|
---|
74 |
|
---|
75 | using namespace std;
|
---|
76 |
|
---|
77 | const TString MHCamEvent::gsDefName = "MHCamEvent";
|
---|
78 | const TString MHCamEvent::gsDefTitle = "Average of MCamEvents";
|
---|
79 |
|
---|
80 | // --------------------------------------------------------------------------
|
---|
81 | //
|
---|
82 | // Initialize the name and title of the task
|
---|
83 | //
|
---|
84 | void MHCamEvent::Init(const char *name, const char *title)
|
---|
85 | {
|
---|
86 | //
|
---|
87 | // set the name and title of this object
|
---|
88 | //
|
---|
89 | fName = name ? name : gsDefName.Data();
|
---|
90 | fTitle = title ? title : gsDefTitle.Data();
|
---|
91 |
|
---|
92 | fNameGeom = "MGeomCam";
|
---|
93 | }
|
---|
94 |
|
---|
95 | // --------------------------------------------------------------------------
|
---|
96 | //
|
---|
97 | // Initialize the name and title of the task. Set fType to 0
|
---|
98 | //
|
---|
99 | MHCamEvent::MHCamEvent(const char *name, const char *title)
|
---|
100 | : fSum(NULL), fEvt(NULL), fType(0), fThreshold(0), fUseThreshold(0)
|
---|
101 | {
|
---|
102 | Init(name, title);
|
---|
103 | }
|
---|
104 |
|
---|
105 | // --------------------------------------------------------------------------
|
---|
106 | //
|
---|
107 | // Initialize the name and title of the task. Set fType to type
|
---|
108 | //
|
---|
109 | MHCamEvent::MHCamEvent(Int_t type, const char *name, const char *title)
|
---|
110 | : fSum(NULL), fEvt(NULL), fType(type), fThreshold(0), fUseThreshold(0)
|
---|
111 | {
|
---|
112 | Init(name, title);
|
---|
113 | }
|
---|
114 |
|
---|
115 | // --------------------------------------------------------------------------
|
---|
116 | //
|
---|
117 | // Delete the corresponding camera display if available
|
---|
118 | //
|
---|
119 | MHCamEvent::~MHCamEvent()
|
---|
120 | {
|
---|
121 | if (fSum)
|
---|
122 | delete fSum;
|
---|
123 | }
|
---|
124 |
|
---|
125 | // --------------------------------------------------------------------------
|
---|
126 | //
|
---|
127 | // use this to display the variance instead of the rms.
|
---|
128 | //
|
---|
129 | void MHCamEvent::EnableVariance(Bool_t b)
|
---|
130 | {
|
---|
131 | b ? SetBit(MHCamera::kVariance) : ResetBit(MHCamera::kVariance);
|
---|
132 | }
|
---|
133 |
|
---|
134 | // --------------------------------------------------------------------------
|
---|
135 | //
|
---|
136 | // Get the event (MCamEvent) the histogram might be filled with. If
|
---|
137 | // it is not given, it is assumed, that it is filled with the argument
|
---|
138 | // of the Fill function.
|
---|
139 | // Looks for the camera geometry MGeomCam and resets the sum histogram.
|
---|
140 | //
|
---|
141 | Bool_t MHCamEvent::SetupFill(const MParList *plist)
|
---|
142 | {
|
---|
143 | fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
|
---|
144 | if (!fEvt)
|
---|
145 | {
|
---|
146 | if (!fNameEvt.IsNull())
|
---|
147 | {
|
---|
148 | *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
|
---|
149 | return kFALSE;
|
---|
150 | }
|
---|
151 | *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
|
---|
152 | }
|
---|
153 |
|
---|
154 | MGeomCam *cam = (MGeomCam*)plist->FindObject(fNameGeom, "MGeomCam");
|
---|
155 | if (!cam)
|
---|
156 | {
|
---|
157 | *fLog << err << fNameGeom << " [MGeomCam] not found... abort." << endl;
|
---|
158 | return kFALSE;
|
---|
159 | }
|
---|
160 |
|
---|
161 | // Delete a possible old histogram from a previous loop
|
---|
162 | if (fSum)
|
---|
163 | delete (fSum);
|
---|
164 |
|
---|
165 | // combine name
|
---|
166 | const TString name = fNameEvt.IsNull() ? fName : fNameEvt;
|
---|
167 |
|
---|
168 | // create and setup MHCamera
|
---|
169 | fSum = new MHCamera(*cam, name+";avg");
|
---|
170 | if (fTitle!=gsDefTitle)
|
---|
171 | fSum->SetTitle(fTitle);
|
---|
172 | if (!fTitle.Contains(";"))
|
---|
173 | fSum->SetYTitle("a.u.");
|
---|
174 | fSum->SetBit(MHCamera::kProfile);
|
---|
175 | if (TestBit(MHCamera::kVariance))
|
---|
176 | fSum->SetBit(MHCamera::kVariance);
|
---|
177 |
|
---|
178 | return kTRUE;
|
---|
179 | }
|
---|
180 |
|
---|
181 | // --------------------------------------------------------------------------
|
---|
182 | //
|
---|
183 | // Fill the histograms with data from a MCamEvent-Container.
|
---|
184 | //
|
---|
185 | Bool_t MHCamEvent::Fill(const MParContainer *par, const Stat_t w)
|
---|
186 | {
|
---|
187 | const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
|
---|
188 | if (!evt)
|
---|
189 | {
|
---|
190 | *fLog << err << dbginf << "Got no MCamEvent as argument of Fill()..." << endl;
|
---|
191 | return kFALSE;
|
---|
192 | }
|
---|
193 | if (fUseThreshold)
|
---|
194 | fSum->CntCamContent(*evt, fThreshold, fType, fUseThreshold>0);
|
---|
195 | else
|
---|
196 | fSum->AddCamContent(*evt, fType);
|
---|
197 | return kTRUE;
|
---|
198 | }
|
---|
199 |
|
---|
200 | // --------------------------------------------------------------------------
|
---|
201 | //
|
---|
202 | // Take the mean of the sum histogram and print all pixel indices
|
---|
203 | // which are above sum+s*rms
|
---|
204 | //
|
---|
205 | void MHCamEvent::PrintOutliers(Float_t s) const
|
---|
206 | {
|
---|
207 | const Double_t mean = fSum->GetMean();
|
---|
208 | const Double_t rms = fSum->GetRMS();
|
---|
209 |
|
---|
210 | *fLog << all << underline << GetDescriptor() << ": Mean=" << mean << ", Rms=" << rms << endl;
|
---|
211 |
|
---|
212 | for (UInt_t i=0; i<fSum->GetNumPixels(); i++)
|
---|
213 | {
|
---|
214 | if (!fSum->IsUsed(i))
|
---|
215 | continue;
|
---|
216 |
|
---|
217 | if ((*fSum)[i+1]>mean+s*rms)
|
---|
218 | *fLog << "Contents of Pixel-Index #" << i << ": " << (*fSum)[i+1] << " > " << s << "*rms" << endl;
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|
222 | // --------------------------------------------------------------------------
|
---|
223 | //
|
---|
224 | // Return fSum for "sum" and fRms for "rms"
|
---|
225 | //
|
---|
226 | TH1 *MHCamEvent::GetHistByName(const TString name)
|
---|
227 | {
|
---|
228 | return fSum;
|
---|
229 | }
|
---|
230 |
|
---|
231 | void MHCamEvent::Paint(Option_t *)
|
---|
232 | {
|
---|
233 | TVirtualPad *pad = gPad;
|
---|
234 |
|
---|
235 | pad->cd(2);
|
---|
236 | if (gPad->FindObject(Form("Proj_%p", this)))
|
---|
237 | {
|
---|
238 | TH1 *h=fSum->Projection(Form("Proj_%p", this));
|
---|
239 | if (h->GetMaximum()>0)
|
---|
240 | gPad->SetLogy();
|
---|
241 | }
|
---|
242 |
|
---|
243 | pad->cd(5);
|
---|
244 | if (gPad->FindObject(Form("ProfR_%p", this)))
|
---|
245 | fSum->RadialProfile(Form("ProfR_%p", this));
|
---|
246 |
|
---|
247 | pad->cd(6);
|
---|
248 | if (gPad->FindObject(Form("ProfA_%p", this)))
|
---|
249 | fSum->AzimuthProfile(Form("ProfA_%p", this));
|
---|
250 |
|
---|
251 | pad->cd(4);
|
---|
252 | gPad->cd(1);
|
---|
253 | MHCamera *cam = (MHCamera*)gPad->FindObject(Form("Err_%p", this));
|
---|
254 | if (cam)
|
---|
255 | cam->SetCamContent(*fSum, 1);
|
---|
256 | }
|
---|
257 |
|
---|
258 | void MHCamEvent::Draw(Option_t *)
|
---|
259 | {
|
---|
260 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
---|
261 | pad->SetBorderMode(0);
|
---|
262 |
|
---|
263 | AppendPad();
|
---|
264 |
|
---|
265 | TString name = Form("%s_5", pad->GetName());
|
---|
266 | TPad *p = new TPad(name,name,6./8,0.25,0.99,0.5,pad->GetFillColor(),0,0);
|
---|
267 | p->SetNumber(5);
|
---|
268 | p->Draw();
|
---|
269 |
|
---|
270 | name = Form("%s_6", pad->GetName());
|
---|
271 | p = new TPad(name,name,6./8,0.01,0.99,0.25,pad->GetFillColor(),0,0);
|
---|
272 | p->SetNumber(6);
|
---|
273 | p->Draw();
|
---|
274 |
|
---|
275 | pad->Divide(2,2);
|
---|
276 |
|
---|
277 | pad->cd(1);
|
---|
278 | gPad->SetBorderMode(0);
|
---|
279 | gPad->SetPad(0.01, 0.5, 0.66, 0.99);
|
---|
280 | fSum->Draw("EPhist");
|
---|
281 |
|
---|
282 | pad->cd(2);
|
---|
283 | gPad->SetBorderMode(0);
|
---|
284 | gPad->SetPad(0.66, 0.5, 0.99, 0.99);
|
---|
285 | TH1 *h = fSum->Projection(Form("Proj_%p", this), 50);
|
---|
286 | h->SetTitle("Projection");
|
---|
287 | h->SetBit(kCanDelete);
|
---|
288 | h->Draw();
|
---|
289 |
|
---|
290 | pad->cd(3);
|
---|
291 | gPad->SetPad(0.01, 0.01, 3./8, 0.5);
|
---|
292 | gPad->SetBorderMode(0);
|
---|
293 | fSum->Draw();
|
---|
294 |
|
---|
295 | pad->cd(4);
|
---|
296 | gPad->SetPad(3./8, 0.01, 6./8, 0.5);
|
---|
297 | gPad->SetBorderMode(0);
|
---|
298 |
|
---|
299 | MHCamera *cam = new MHCamera(*fSum->GetGeometry());
|
---|
300 | cam->SetName(Form("Err_%p", this));
|
---|
301 | cam->SetTitle(fSum->TestBit(MHCamera::kVariance)?"Variance":"Root Mean Squared (rms)");
|
---|
302 | cam->SetYTitle(fSum->GetYaxis()->GetTitle());
|
---|
303 | cam->SetCamContent(*fSum, 1);
|
---|
304 | cam->SetBit(kCanDelete);
|
---|
305 | cam->Draw();
|
---|
306 |
|
---|
307 | pad->cd(5);
|
---|
308 | h = (TH1*)fSum->RadialProfile(Form("ProfR_%p", this), 20);
|
---|
309 | h->SetTitle("Radial Profile");
|
---|
310 | h->SetBit(kCanDelete|TH1::kNoStats);
|
---|
311 | h->Draw();
|
---|
312 |
|
---|
313 | pad->cd(6);
|
---|
314 | h = (TH1*)fSum->AzimuthProfile(Form("ProfA_%p", this), 30);
|
---|
315 | h->SetTitle("Azimuth Profile");
|
---|
316 | h->SetBit(kCanDelete|TH1::kNoStats);
|
---|
317 | h->Draw();
|
---|
318 | }
|
---|
319 |
|
---|