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): Nicola Galante, 2003 <mailto:nicola.galante@pi.infn.it>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2003
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MHMcTriggerLvl2
|
---|
28 | //
|
---|
29 | // This class contains histograms for the Trigger Level2 image parameters
|
---|
30 | //
|
---|
31 | /////////////////////////////////////////////////////////////////////////////
|
---|
32 |
|
---|
33 | #include "MHMcTriggerLvl2.h"
|
---|
34 |
|
---|
35 | #include <TMath.h>
|
---|
36 |
|
---|
37 | #include <TH2.h>
|
---|
38 | #include <TH1.h>
|
---|
39 | #include <TF1.h>
|
---|
40 | #include <TPad.h>
|
---|
41 | #include <TStyle.h>
|
---|
42 | #include <TCanvas.h>
|
---|
43 | #include <TPaveLabel.h>
|
---|
44 |
|
---|
45 | #include "MLog.h"
|
---|
46 | #include "MLogManip.h"
|
---|
47 |
|
---|
48 | #include "MParList.h"
|
---|
49 |
|
---|
50 | #include "MMcTriggerLvl2.h"
|
---|
51 |
|
---|
52 | using namespace std;
|
---|
53 |
|
---|
54 | /* Use this insteadif you want to have some value which is the same for all
|
---|
55 | your instances of MHMcTriggerLvl2, if not define the values in the constructor
|
---|
56 | and remove the 'static'
|
---|
57 | */
|
---|
58 |
|
---|
59 | Int_t MHMcTriggerLvl2::fColorLps = 1;
|
---|
60 | Int_t MHMcTriggerLvl2::fColorSbc = 1;
|
---|
61 | Int_t MHMcTriggerLvl2::fColorPs = 1;
|
---|
62 | Int_t MHMcTriggerLvl2::fColorPsE = 1;
|
---|
63 | Int_t MHMcTriggerLvl2::fColorLPsE = 1;
|
---|
64 | Int_t MHMcTriggerLvl2::fColorSBCE = 1;
|
---|
65 |
|
---|
66 |
|
---|
67 | ClassImp(MHMcTriggerLvl2);
|
---|
68 |
|
---|
69 | // --------------------------------------------------------------------------
|
---|
70 | //
|
---|
71 | // Setup three histograms for fLutPseudoSize, fPseudoSize, fSizeBiggerCell
|
---|
72 | //
|
---|
73 | MHMcTriggerLvl2::MHMcTriggerLvl2(const char *name, const char *title)
|
---|
74 | {
|
---|
75 | //
|
---|
76 | // set the name and title of this object
|
---|
77 | //
|
---|
78 | fName = name ? name : "MHMcTriggerLvl2";
|
---|
79 | fTitle = title ? title : "Trigger L2 image parameters";
|
---|
80 |
|
---|
81 | fHistLutPseudoSize = new TH1F("fHistLutPseudoSize", "number of compact pixels in one lut", 12, 0, 12);
|
---|
82 | fHistPseudoSize = new TH1F("fHistPseudoSize", "Multiplicity of the cluster identified by the L2T", 397, 0, 397);
|
---|
83 | fHistSizeBiggerCell = new TH1F("fHistSizeBiggerCell", "Number of fired pixel in bigger cell", 36, 0, 36);
|
---|
84 |
|
---|
85 | fHistLutPseudoSizeNorm = new TH1F("fHistLutPseudoSizeNorm", "Normalized Number of compact pixels in one lut", 12, 0, 12);
|
---|
86 | fHistPseudoSizeNorm = new TH1F("fHistPseudoSizeNorm", "Normalized Multiplicity of the cluster identified by the L2T", 397, 0, 397);
|
---|
87 | fHistSizeBiggerCellNorm = new TH1F("fHistSizeBiggerCellNorm", "Normalized Number of fired pixel in bigger cell", 36, 0, 36);
|
---|
88 |
|
---|
89 | fHistLutPseudoSize->SetDirectory(NULL);
|
---|
90 | fHistLutPseudoSizeNorm->SetDirectory(NULL);
|
---|
91 | fHistPseudoSize->SetDirectory(NULL);
|
---|
92 | fHistPseudoSizeNorm->SetDirectory(NULL);
|
---|
93 | fHistSizeBiggerCell->SetDirectory(NULL);
|
---|
94 | fHistSizeBiggerCellNorm->SetDirectory(NULL);
|
---|
95 |
|
---|
96 | fHistLutPseudoSize->SetXTitle("Number of Pixels");
|
---|
97 | fHistLutPseudoSizeNorm->SetXTitle("Number of Pixels");
|
---|
98 | fHistPseudoSize->SetXTitle("Number of Pixels");
|
---|
99 | fHistPseudoSizeNorm->SetXTitle("Number of Pixels");
|
---|
100 | fHistSizeBiggerCell->SetXTitle("Number of Pixels");
|
---|
101 | fHistSizeBiggerCellNorm->SetXTitle("Number of Pixels");
|
---|
102 |
|
---|
103 | fHistLutPseudoSize->SetYTitle("Counts");
|
---|
104 | fHistLutPseudoSizeNorm->SetYTitle("Counts/Total Counts");
|
---|
105 | fHistPseudoSize->SetYTitle("Counts");
|
---|
106 | fHistPseudoSizeNorm->SetYTitle("Counts/Total Counts");
|
---|
107 | fHistSizeBiggerCell->SetYTitle("Counts");
|
---|
108 | fHistSizeBiggerCellNorm->SetYTitle("Counts/Total Counts");
|
---|
109 |
|
---|
110 | fHistPseudoSizeEnergy = new TH2D("fHistPseudoSizeEnergy","Ps Size vs Energy", 40, 1, 5, 397, 0,397);
|
---|
111 | fHistLutPseudoSizeEnergy = new TH2D("fHistLutPseudoSizeEnergy","Ps Size vs Energy", 40, 1, 5, 397, 0,397);
|
---|
112 | fHistSizeBiggerCellEnergy = new TH2D("fHistSizeBiggerCellEnergy","Ps Size vs Energy", 40, 1, 5, 397, 0,397);
|
---|
113 |
|
---|
114 | fHistPseudoSizeEnergy->SetName("fHistPseudoSizeEnergy");
|
---|
115 | fHistPseudoSizeEnergy->SetTitle("PseudoSize vs. Energy");
|
---|
116 | fHistPseudoSizeEnergy->SetXTitle("Log(E[GeV])");
|
---|
117 | fHistPseudoSizeEnergy->SetYTitle("PseudoSize");
|
---|
118 |
|
---|
119 | fHistLutPseudoSizeEnergy->SetName("fHistLutPseudoSizeEnergy");
|
---|
120 | fHistLutPseudoSizeEnergy->SetTitle("LutPseudoSize vs. Energy");
|
---|
121 | fHistLutPseudoSizeEnergy->SetXTitle("Log(E[GeV])");
|
---|
122 | fHistLutPseudoSizeEnergy->SetYTitle("LutPseudoSize");
|
---|
123 |
|
---|
124 | fHistSizeBiggerCellEnergy->SetName("fHistSizeBiggerCellEnergy");
|
---|
125 | fHistSizeBiggerCellEnergy->SetTitle("Size Bigger Cell vs. Energy");
|
---|
126 | fHistSizeBiggerCellEnergy->SetXTitle("Log(E[GeV])");
|
---|
127 | fHistSizeBiggerCellEnergy->SetYTitle("Size Bigger Cell");
|
---|
128 |
|
---|
129 |
|
---|
130 |
|
---|
131 |
|
---|
132 | fFNorm = new TF1("FNorm", "1", -1, 397);
|
---|
133 | }
|
---|
134 |
|
---|
135 | // --------------------------------------------------------------------------
|
---|
136 | //
|
---|
137 | // Delete the histograms
|
---|
138 | //
|
---|
139 | MHMcTriggerLvl2::~MHMcTriggerLvl2()
|
---|
140 | {
|
---|
141 | delete fHistLutPseudoSize;
|
---|
142 | delete fHistPseudoSize;
|
---|
143 | delete fHistSizeBiggerCell;
|
---|
144 | delete fHistLutPseudoSizeNorm;
|
---|
145 | delete fHistPseudoSizeNorm;
|
---|
146 | delete fHistSizeBiggerCellNorm;
|
---|
147 | delete fHistPseudoSizeEnergy;
|
---|
148 | delete fHistLutPseudoSizeEnergy;
|
---|
149 | delete fHistSizeBiggerCellEnergy;
|
---|
150 | delete fFNorm;
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 | // --------------------------------------------------------------------------
|
---|
155 | //
|
---|
156 | // Fill the histograms with data from a MMcTriggerLvl2-Container.
|
---|
157 | // Be careful: Only call this with an object of type MMcTriggerLvl2
|
---|
158 | //
|
---|
159 | Bool_t MHMcTriggerLvl2::Fill(const MParContainer *par, const Stat_t w)
|
---|
160 | {
|
---|
161 | const MMcTriggerLvl2 &h = *(MMcTriggerLvl2 *)par;
|
---|
162 |
|
---|
163 | fHistLutPseudoSize->Fill(h.GetLutPseudoSize());
|
---|
164 | fHistPseudoSize->Fill(h.GetPseudoSize());
|
---|
165 | fHistSizeBiggerCell->Fill(h.GetSizeBiggerCell());
|
---|
166 | fHistPseudoSizeEnergy->Fill(TMath::Log10(h.GetEnergy()), h.GetPseudoSize());
|
---|
167 | fHistLutPseudoSizeEnergy->Fill(TMath::Log10(h.GetEnergy()), h.GetLutPseudoSize());
|
---|
168 | fHistSizeBiggerCellEnergy->Fill(TMath::Log10(h.GetEnergy()), h.GetSizeBiggerCell());
|
---|
169 |
|
---|
170 | return kTRUE;
|
---|
171 | }
|
---|
172 |
|
---|
173 |
|
---|
174 |
|
---|
175 |
|
---|
176 | // --------------------------------------------------------------------------
|
---|
177 | //
|
---|
178 | // This is the private function member which draw a clone of a histogram.
|
---|
179 | // This method is called by the DrawClone method.
|
---|
180 | //
|
---|
181 | TObject *MHMcTriggerLvl2::DrawHist(TH1 &hist, TH1 &histNorm, const TString &canvasname, Int_t &col) const
|
---|
182 | {
|
---|
183 | col++;
|
---|
184 |
|
---|
185 | TCanvas *c = (TCanvas*)gROOT->FindObject(canvasname);
|
---|
186 |
|
---|
187 | Bool_t same = kTRUE;
|
---|
188 | if (!c)
|
---|
189 | {
|
---|
190 | c = MakeDefCanvas(canvasname,canvasname, 800, 610);
|
---|
191 | c->Divide(2,1);
|
---|
192 | same = kFALSE;
|
---|
193 | }
|
---|
194 |
|
---|
195 | c->cd(1);
|
---|
196 | hist.SetLineColor(col);
|
---|
197 | hist.DrawCopy(same?"same":"");
|
---|
198 |
|
---|
199 | c->cd(2);
|
---|
200 | histNorm.SetLineColor(col);
|
---|
201 | histNorm.DrawCopy(same?"same":"");
|
---|
202 |
|
---|
203 | return c;
|
---|
204 | }
|
---|
205 |
|
---|
206 |
|
---|
207 | // --------------------------------------------------------------------------
|
---|
208 | //
|
---|
209 | // This is the private function member which draw a clone of a 2D-histogram.
|
---|
210 | // This method is called by the DrawClone method.
|
---|
211 | //
|
---|
212 | TObject *MHMcTriggerLvl2::Draw2DHist(TH1 &hist, const TString &canvasname, Int_t &col) const
|
---|
213 | {
|
---|
214 | col++;
|
---|
215 |
|
---|
216 | TCanvas *c = (TCanvas*)gROOT->FindObject(canvasname);
|
---|
217 |
|
---|
218 | Bool_t same = kTRUE;
|
---|
219 | if (!c)
|
---|
220 | {
|
---|
221 | c = MakeDefCanvas(canvasname,canvasname, 800, 600);
|
---|
222 | same = kFALSE;
|
---|
223 | }
|
---|
224 |
|
---|
225 | hist.SetLineColor(col);
|
---|
226 | hist.DrawCopy(same?"same":"");
|
---|
227 |
|
---|
228 | return c;
|
---|
229 | }
|
---|
230 |
|
---|
231 |
|
---|
232 | // --------------------------------------------------------------------------
|
---|
233 | //
|
---|
234 | // Draw a clone of a data member histogram. So that the object can be deleted
|
---|
235 | // and the histogram is still visible in the canvas.
|
---|
236 | // The cloned object are deleted together with the canvas if the canvas is
|
---|
237 | // destroyed. If you want to handle dostroying the canvas you can get a
|
---|
238 | // pointer to it from this function
|
---|
239 | // Possible options are:
|
---|
240 | // "lps" for the fLutPseudoSize histogram;
|
---|
241 | // "sbc" for the fSizeBiggerCell histogram;
|
---|
242 | // "ps" for the fPseudoSize histogram;
|
---|
243 | // "lut-energy" for the fLutPseudoSize vs. energy 2D histogram
|
---|
244 | // "size-energy" for the fPseudoSize vs. energy 2D histogram
|
---|
245 | // "big-energy" for the fSizeBiggerCell vs. energy 2D histogram
|
---|
246 | //
|
---|
247 | // default: "ps"
|
---|
248 | //
|
---|
249 | TObject *MHMcTriggerLvl2::DrawClone(Option_t *opt) const
|
---|
250 | {
|
---|
251 | TString str(opt);
|
---|
252 |
|
---|
253 | if (str.IsNull())
|
---|
254 | str = "ps";
|
---|
255 |
|
---|
256 | if (!str.Contains("lps", TString::kIgnoreCase) &&
|
---|
257 | !str.Contains("sbc", TString::kIgnoreCase) &&
|
---|
258 | !str.Contains("ps", TString::kIgnoreCase) &&
|
---|
259 | !str.Contains("lut-energy", TString::kIgnoreCase) &&
|
---|
260 | !str.Contains("size-energy", TString::kIgnoreCase) &&
|
---|
261 | !str.Contains("big-energy", TString::kIgnoreCase))
|
---|
262 | {
|
---|
263 | *fLog << "ARGH!@! Possible options are \"lps\", \"sbc\", \"ps\", \"lut-energy\", \"size-energy\", \"big-energy\" or NULL!" <<endl;
|
---|
264 | return NULL;
|
---|
265 | }
|
---|
266 |
|
---|
267 | if (str.Contains("lps",TString::kIgnoreCase)){
|
---|
268 | TH1 *hist=NormalizeHist(fHistLutPseudoSizeNorm, fHistLutPseudoSize);
|
---|
269 | return DrawHist(*fHistLutPseudoSize, *hist, "CanvasLPS", fColorLps);
|
---|
270 | }
|
---|
271 |
|
---|
272 | if (str.Contains("sbc",TString::kIgnoreCase)){
|
---|
273 | TH1 *hist=NormalizeHist(fHistSizeBiggerCellNorm, fHistSizeBiggerCell);
|
---|
274 | return DrawHist(*fHistSizeBiggerCell, *hist, "CanvasSBC", fColorSbc);
|
---|
275 | }
|
---|
276 |
|
---|
277 | if (str.Contains("ps",TString::kIgnoreCase)){
|
---|
278 | TH1 *hist=NormalizeHist(fHistPseudoSizeNorm, fHistPseudoSize);
|
---|
279 | return DrawHist(*fHistPseudoSize, *hist, "CanvasPS", fColorPs);
|
---|
280 | }
|
---|
281 |
|
---|
282 | if (str.Contains("size-energy",TString::kIgnoreCase))
|
---|
283 | return Draw2DHist(*fHistPseudoSizeEnergy, "CanvasPSE", fColorPsE);
|
---|
284 |
|
---|
285 | if (str.Contains("lut-energy",TString::kIgnoreCase))
|
---|
286 | return Draw2DHist(*fHistLutPseudoSizeEnergy, "CanvasLPSE", fColorLPsE);
|
---|
287 |
|
---|
288 | if (str.Contains("big-energy",TString::kIgnoreCase))
|
---|
289 | return Draw2DHist(*fHistSizeBiggerCellEnergy, "CanvasSBCE", fColorSBCE);
|
---|
290 |
|
---|
291 |
|
---|
292 | return NULL;
|
---|
293 | }
|
---|
294 |
|
---|
295 |
|
---|
296 |
|
---|
297 | // --------------------------------------------------------------------------
|
---|
298 | //
|
---|
299 | // Creates a new canvas and draws the three histograms into it.
|
---|
300 | // Be careful: The histograms belongs to this object and won't get deleted
|
---|
301 | // together with the canvas.
|
---|
302 | //
|
---|
303 | void MHMcTriggerLvl2::Draw(Option_t *)
|
---|
304 | {
|
---|
305 | MakeDefCanvas("c","L2T Parameters", 720, 810);
|
---|
306 |
|
---|
307 | TPad* pad1 = new TPad("pad1","Pad with fLutPseudoSize", 0.003, 0.7, 0.4, 0.997);
|
---|
308 | TPad* pad2 = new TPad("pad2","Pad with fSizeBiggerCell", 0.403, 0.7, 0.997, 0.997);
|
---|
309 | TPad* pad3 = new TPad("pad3","Pad with fPseudoSize", 0.003, 0.003, 0.997, 0.697);
|
---|
310 | pad1->Draw();
|
---|
311 | pad2->Draw();
|
---|
312 | pad3->Draw();
|
---|
313 |
|
---|
314 | pad1->cd();
|
---|
315 | fHistLutPseudoSize->Draw();
|
---|
316 |
|
---|
317 | pad2->cd();
|
---|
318 | fHistSizeBiggerCell->Draw();
|
---|
319 |
|
---|
320 | pad3->cd();
|
---|
321 | fHistPseudoSize->Draw();
|
---|
322 | }
|
---|
323 |
|
---|
324 |
|
---|
325 |
|
---|
326 | // --------------------------------------------------------------------------
|
---|
327 | //
|
---|
328 | // Return the histogram by its name. This method returns a (TObject *)
|
---|
329 | // so remember to cast the returned object if you want to work with it.
|
---|
330 | //
|
---|
331 | TObject *MHMcTriggerLvl2::GetHistByName(const TString name) const
|
---|
332 | {
|
---|
333 | if (name.Contains("fHistLutPseudoSize", TString::kIgnoreCase))
|
---|
334 | return fHistLutPseudoSize;
|
---|
335 | if (name.Contains("fHistSizeBiggerCell", TString::kIgnoreCase))
|
---|
336 | return fHistSizeBiggerCell;
|
---|
337 | if (name.Contains("fHistPseudoSize", TString::kIgnoreCase))
|
---|
338 | return fHistPseudoSize;
|
---|
339 |
|
---|
340 | if (name.Contains("fHistLutPseudoSizeNorm", TString::kIgnoreCase))
|
---|
341 | return fHistLutPseudoSizeNorm;
|
---|
342 | if (name.Contains("fHistSizeBiggerCellNorm", TString::kIgnoreCase))
|
---|
343 | return fHistSizeBiggerCellNorm;
|
---|
344 | if (name.Contains("fHistPseudoSizeNorm", TString::kIgnoreCase))
|
---|
345 | return fHistPseudoSizeNorm;
|
---|
346 |
|
---|
347 | if (name.Contains("fHistLutPseudoSizeEnergy", TString::kIgnoreCase))
|
---|
348 | return fHistLutPseudoSizeEnergy;
|
---|
349 | if (name.Contains("fHistSizeBiggerCellEnergy", TString::kIgnoreCase))
|
---|
350 | return fHistSizeBiggerCellEnergy;
|
---|
351 | if (name.Contains("fHistPseudoSizeEnergy", TString::kIgnoreCase))
|
---|
352 | return fHistPseudoSizeEnergy;
|
---|
353 |
|
---|
354 | return NULL;
|
---|
355 | }
|
---|
356 |
|
---|
357 |
|
---|
358 |
|
---|
359 | // --------------------------------------------------------------------------
|
---|
360 | //
|
---|
361 | // Normalize the histogram on its integral, i.e. normalize the
|
---|
362 | // values of the histogram on the statistics. This method creates
|
---|
363 | // a copy (histNorm) of the histogram to normalize (hist) and normalize
|
---|
364 | // the copy (histNorm) on its integral. It returns histNorm.
|
---|
365 | //
|
---|
366 | TH1 *MHMcTriggerLvl2::NormalizeHist(TH1 *histNorm, TH1 *hist) const
|
---|
367 | {
|
---|
368 | if (histNorm == hist){
|
---|
369 | *fLog << "ARGH!@! You cannot pass the same histogram into each argument!" << endl;
|
---|
370 | return NULL;
|
---|
371 | }
|
---|
372 |
|
---|
373 | if ((hist == NULL) || (hist->Integral() == (Stat_t)0)){
|
---|
374 | *fLog << "ARGH!@! You are trying to normalize the histogram to 0!" << endl;
|
---|
375 | return NULL;
|
---|
376 | }
|
---|
377 |
|
---|
378 | histNorm->Reset("ICE");
|
---|
379 | histNorm->Add(hist, 1);
|
---|
380 | histNorm->Divide(fFNorm, (Double_t)(hist->Integral()));
|
---|
381 |
|
---|
382 | return histNorm;
|
---|
383 | }
|
---|