source: tags/Mars-V2.1/mhistmc/MHMcTriggerLvl2.cc

Last change on this file was 6977, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 14.7 KB
Line 
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
52using 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
59Int_t MHMcTriggerLvl2::fColorLps = 1;
60Int_t MHMcTriggerLvl2::fColorCps = 1;
61Int_t MHMcTriggerLvl2::fColorSbc = 1;
62Int_t MHMcTriggerLvl2::fColorPs = 1;
63Int_t MHMcTriggerLvl2::fColorPsE = 1;
64Int_t MHMcTriggerLvl2::fColorCPsE = 1;
65Int_t MHMcTriggerLvl2::fColorLPsE = 1;
66Int_t MHMcTriggerLvl2::fColorSBCE = 1;
67
68
69ClassImp(MHMcTriggerLvl2);
70
71// --------------------------------------------------------------------------
72//
73// Setup three histograms for fLutPseudoSize, fPseudoSize, fSizeBiggerCell
74//
75MHMcTriggerLvl2::MHMcTriggerLvl2(const char *name, const char *title)
76{
77 //
78 // set the name and title of this object
79 //
80 fName = name ? name : "MHMcTriggerLvl2";
81 fTitle = title ? title : "Trigger L2 image parameters";
82
83 fHistLutPseudoSize = new TH1F("fHistLutPseudoSize", "Lut Pseudo Size", 13, 0, 13);
84 fHistPseudoSize = new TH1F("fHistPseudoSize", "Pseudo Size", 397, 0, 397);
85 fHistCellPseudoSize = new TH1F("fHistCellPseudoSize", "Cell Pseudo Size", 37, 0, 37);
86 fHistSizeBiggerCell = new TH1F("fHistSizeBiggerCell", "Size in Bigger Cell", 37, 0, 37);
87
88 fHistLutPseudoSizeNorm = new TH1F("fHistLutPseudoSizeNorm", "Normalized Lut Pseudo Size", 13, 0, 13);
89 fHistPseudoSizeNorm = new TH1F("fHistPseudoSizeNorm", "Normalized Pseudo Size", 397, 0, 397);
90 fHistSizeBiggerCellNorm = new TH1F("fHistSizeBiggerCellNorm", "Normalized Size in Bigger Cell", 37, 0, 37);
91 fHistCellPseudoSizeNorm = new TH1F("fHistCellPseudoSizeNorm", "Normalized Cell Pseudo Size", 37, 0, 37);
92
93 fHistLutPseudoSize->SetDirectory(NULL);
94 fHistLutPseudoSizeNorm->SetDirectory(NULL);
95 fHistPseudoSize->SetDirectory(NULL);
96 fHistPseudoSizeNorm->SetDirectory(NULL);
97 fHistSizeBiggerCell->SetDirectory(NULL);
98 fHistSizeBiggerCellNorm->SetDirectory(NULL);
99 fHistCellPseudoSize->SetDirectory(NULL);
100 fHistCellPseudoSizeNorm->SetDirectory(NULL);
101
102 fHistLutPseudoSize->SetXTitle("Number of Pixels");
103 fHistLutPseudoSizeNorm->SetXTitle("Number of Pixels");
104 fHistPseudoSize->SetXTitle("Number of Pixels");
105 fHistPseudoSizeNorm->SetXTitle("Number of Pixels");
106 fHistSizeBiggerCell->SetXTitle("Number of Pixels");
107 fHistSizeBiggerCellNorm->SetXTitle("Number of Pixels");
108 fHistCellPseudoSize->SetXTitle("Number of Pixels");
109 fHistCellPseudoSizeNorm->SetXTitle("Number of Pixels");
110
111 fHistLutPseudoSize->SetYTitle("Counts");
112 fHistLutPseudoSizeNorm->SetYTitle("Counts/Total Counts");
113 fHistPseudoSize->SetYTitle("Counts");
114 fHistPseudoSizeNorm->SetYTitle("Counts/Total Counts");
115 fHistSizeBiggerCell->SetYTitle("Counts");
116 fHistSizeBiggerCellNorm->SetYTitle("Counts/Total Counts");
117 fHistCellPseudoSize->SetYTitle("Counts");
118 fHistCellPseudoSizeNorm->SetYTitle("Counts/Total Counts");
119
120 fHistPseudoSizeEnergy = new TH2D("fHistPseudoSizeEnergy","Ps Size vs Energy", 40, 1, 5, 397, 0,397);
121 fHistCellPseudoSizeEnergy = new TH2D("fHistCellPseudoSizeEnergy","CPS Size vs Energy", 40, 1, 5, 397, 0,397);
122 fHistLutPseudoSizeEnergy = new TH2D("fHistLutPseudoSizeEnergy","Ps Size vs Energy", 40, 1, 5, 397, 0,397);
123 fHistSizeBiggerCellEnergy = new TH2D("fHistSizeBiggerCellEnergy","Ps Size vs Energy", 40, 1, 5, 397, 0,397);
124
125 fHistPseudoSizeEnergy->SetName("fHistPseudoSizeEnergy");
126 fHistPseudoSizeEnergy->SetTitle("PseudoSize vs. Energy");
127 fHistPseudoSizeEnergy->SetXTitle("Log(E[GeV])");
128 fHistPseudoSizeEnergy->SetYTitle("PseudoSize");
129
130 fHistCellPseudoSizeEnergy->SetName("fHistCellPseudoSizeEnergy");
131 fHistCellPseudoSizeEnergy->SetTitle("CellPseudoSize vs. Energy");
132 fHistCellPseudoSizeEnergy->SetXTitle("Log(E[GeV])");
133 fHistCellPseudoSizeEnergy->SetYTitle("CellPseudoSize");
134
135 fHistLutPseudoSizeEnergy->SetName("fHistLutPseudoSizeEnergy");
136 fHistLutPseudoSizeEnergy->SetTitle("LutPseudoSize vs. Energy");
137 fHistLutPseudoSizeEnergy->SetXTitle("Log(E[GeV])");
138 fHistLutPseudoSizeEnergy->SetYTitle("LutPseudoSize");
139
140 fHistSizeBiggerCellEnergy->SetName("fHistSizeBiggerCellEnergy");
141 fHistSizeBiggerCellEnergy->SetTitle("Size Bigger Cell vs. Energy");
142 fHistSizeBiggerCellEnergy->SetXTitle("Log(E[GeV])");
143 fHistSizeBiggerCellEnergy->SetYTitle("Size Bigger Cell");
144
145
146
147
148 fFNorm = new TF1("FNorm", "1", -1, 397);
149}
150
151// --------------------------------------------------------------------------
152//
153// Delete the histograms
154//
155MHMcTriggerLvl2::~MHMcTriggerLvl2()
156{
157 delete fHistLutPseudoSize;
158 delete fHistPseudoSize;
159 delete fHistCellPseudoSize;
160 delete fHistSizeBiggerCell;
161 delete fHistLutPseudoSizeNorm;
162 delete fHistPseudoSizeNorm;
163 delete fHistCellPseudoSizeNorm;
164 delete fHistSizeBiggerCellNorm;
165 delete fHistPseudoSizeEnergy;
166 delete fHistCellPseudoSizeEnergy;
167 delete fHistLutPseudoSizeEnergy;
168 delete fHistSizeBiggerCellEnergy;
169 delete fFNorm;
170}
171
172
173// --------------------------------------------------------------------------
174//
175// Fill the histograms with data from a MMcTriggerLvl2-Container.
176// Be careful: Only call this with an object of type MMcTriggerLvl2
177//
178Bool_t MHMcTriggerLvl2::Fill(const MParContainer *par, const Stat_t w)
179{
180 const MMcTriggerLvl2 &h = *(MMcTriggerLvl2 *)par;
181
182 fHistLutPseudoSize->Fill(h.GetLutPseudoSize());
183 fHistPseudoSize->Fill(h.GetPseudoSize());
184 fHistCellPseudoSize->Fill(h.GetCellPseudoSize());
185 fHistSizeBiggerCell->Fill(h.GetSizeBiggerCell());
186 fHistPseudoSizeEnergy->Fill(TMath::Log10(h.GetEnergy()), h.GetPseudoSize());
187 fHistCellPseudoSizeEnergy->Fill(TMath::Log10(h.GetEnergy()), h.GetCellPseudoSize());
188 fHistLutPseudoSizeEnergy->Fill(TMath::Log10(h.GetEnergy()), h.GetLutPseudoSize());
189 fHistSizeBiggerCellEnergy->Fill(TMath::Log10(h.GetEnergy()), h.GetSizeBiggerCell());
190
191 return kTRUE;
192}
193
194
195
196
197// --------------------------------------------------------------------------
198//
199// This is the private function member which draw a clone of a histogram.
200// This method is called by the DrawClone method.
201//
202TObject *MHMcTriggerLvl2::DrawHist(TH1 &hist, TH1 &histNorm, const TString &canvasname, Int_t &col) const
203{
204 col++;
205
206 TCanvas *c = (TCanvas*)gROOT->FindObject(canvasname);
207
208 Bool_t same = kTRUE;
209 if (!c)
210 {
211 c = MakeDefCanvas(canvasname,canvasname, 800, 610);
212 c->Divide(2,1);
213 same = kFALSE;
214 }
215
216 c->cd(1);
217 hist.SetLineColor(col);
218 hist.DrawCopy(same?"same":"");
219
220 c->cd(2);
221 histNorm.SetLineColor(col);
222 histNorm.DrawCopy(same?"same":"");
223
224 return c;
225}
226
227
228// --------------------------------------------------------------------------
229//
230// This is the private function member which draw a clone of a 2D-histogram.
231// This method is called by the DrawClone method.
232//
233TObject *MHMcTriggerLvl2::Draw2DHist(TH1 &hist, const TString &canvasname, Int_t &col) const
234{
235 col++;
236
237 TCanvas *c = (TCanvas*)gROOT->FindObject(canvasname);
238
239 Bool_t same = kTRUE;
240 if (!c)
241 {
242 c = MakeDefCanvas(canvasname,canvasname, 800, 600);
243 same = kFALSE;
244 }
245
246 hist.SetLineColor(col);
247 hist.DrawCopy(same?"same":"");
248
249 return c;
250}
251
252
253// --------------------------------------------------------------------------
254//
255// Draw a clone of a data member histogram. So that the object can be deleted
256// and the histogram is still visible in the canvas.
257// The cloned object are deleted together with the canvas if the canvas is
258// destroyed. If you want to handle dostroying the canvas you can get a
259// pointer to it from this function
260// Possible options are:
261// "lps" for the fLutPseudoSize histogram;
262// "sbc" for the fSizeBiggerCell histogram;
263// "ps" for the fPseudoSize histogram;
264// "lut-energy" for the fLutPseudoSize vs. energy 2D histogram
265// "size-energy" for the fPseudoSize vs. energy 2D histogram
266// "big-energy" for the fSizeBiggerCell vs. energy 2D histogram
267//
268// default: "ps"
269//
270TObject *MHMcTriggerLvl2::DrawClone(Option_t *opt) const
271{
272 TString str(opt);
273
274 if (str.IsNull())
275 str = "ps";
276
277 if (!str.Contains("lps", TString::kIgnoreCase) &&
278 !str.Contains("cps", TString::kIgnoreCase) &&
279 !str.Contains("sbc", TString::kIgnoreCase) &&
280 !str.Contains("ps", TString::kIgnoreCase) &&
281 !str.Contains("lut-energy", TString::kIgnoreCase) &&
282 !str.Contains("size-energy", TString::kIgnoreCase) &&
283 !str.Contains("cellsize-energy", TString::kIgnoreCase) &&
284 !str.Contains("big-energy", TString::kIgnoreCase))
285 {
286 *fLog << "ARGH!@! Possible options are \"lps\", \"cps\", \"sbc\", \"ps\", \"lut-energy\", \"size-energy\", \"cellsize-energy\", \"big-energy\" or NULL!" <<endl;
287 return NULL;
288 }
289
290 if (str.Contains("lps",TString::kIgnoreCase)){
291 TH1 *hist=NormalizeHist(*fHistLutPseudoSizeNorm, fHistLutPseudoSize);
292 return DrawHist(*fHistLutPseudoSize, *hist, "CanvasLPS", fColorLps);
293 }
294
295 if (str.Contains("cps",TString::kIgnoreCase)){
296 TH1 *hist=NormalizeHist(*fHistCellPseudoSizeNorm, fHistCellPseudoSize);
297 return DrawHist(*fHistCellPseudoSize, *hist, "CanvasCPS", fColorCps);
298 }
299
300 if (str.Contains("sbc",TString::kIgnoreCase)){
301 TH1 *hist=NormalizeHist(*fHistSizeBiggerCellNorm, fHistSizeBiggerCell);
302 return DrawHist(*fHistSizeBiggerCell, *hist, "CanvasSBC", fColorSbc);
303 }
304
305 if (str.Contains("ps",TString::kIgnoreCase)){
306 TH1 *hist=NormalizeHist(*fHistPseudoSizeNorm, fHistPseudoSize);
307 return DrawHist(*fHistPseudoSize, *hist, "CanvasPS", fColorPs);
308 }
309
310 if (str.Contains("size-energy",TString::kIgnoreCase))
311 return Draw2DHist(*fHistPseudoSizeEnergy, "CanvasPSE", fColorPsE);
312
313 if (str.Contains("cellsize-energy",TString::kIgnoreCase))
314 return Draw2DHist(*fHistCellPseudoSizeEnergy, "CanvasCPSE", fColorCPsE);
315
316 if (str.Contains("lut-energy",TString::kIgnoreCase))
317 return Draw2DHist(*fHistLutPseudoSizeEnergy, "CanvasLPSE", fColorLPsE);
318
319 if (str.Contains("big-energy",TString::kIgnoreCase))
320 return Draw2DHist(*fHistSizeBiggerCellEnergy, "CanvasSBCE", fColorSBCE);
321
322
323 return NULL;
324}
325
326
327
328// --------------------------------------------------------------------------
329//
330// Creates a new canvas and draws the three histograms into it.
331// Be careful: The histograms belongs to this object and won't get deleted
332// together with the canvas.
333//
334void MHMcTriggerLvl2::Draw(Option_t *)
335{
336 MakeDefCanvas("c","L2T Parameters", 720, 810);
337
338 TPad* pad1 = new TPad("pad1","Pad with fLutPseudoSize", 0.003, 0.7, 0.4, 0.997);
339 TPad* pad2 = new TPad("pad2","Pad with fSizeBiggerCell", 0.403, 0.7, 0.997, 0.997);
340 TPad* pad3 = new TPad("pad3","Pad with fPseudoSize", 0.003, 0.003, 0.997, 0.697);
341 pad1->Draw();
342 pad2->Draw();
343 pad3->Draw();
344
345 pad1->cd();
346 fHistLutPseudoSize->Draw();
347
348 pad2->cd();
349 fHistSizeBiggerCell->Draw();
350
351 pad3->cd();
352 fHistPseudoSize->Draw();
353}
354
355
356
357// --------------------------------------------------------------------------
358//
359// Return the histogram by its name. This method returns a (TObject *)
360// so remember to cast the returned object if you want to work with it.
361//
362TH1 *MHMcTriggerLvl2::GetHistByName(const TString name) const
363{
364
365 if (name.Contains("fHistLutPseudoSizeEnergy", TString::kIgnoreCase))
366 return fHistLutPseudoSizeEnergy;
367 if (name.Contains("fHistSizeBiggerCellEnergy", TString::kIgnoreCase))
368 return fHistSizeBiggerCellEnergy;
369 if (name.Contains("fHistPseudoSizeEnergy", TString::kIgnoreCase))
370 return fHistPseudoSizeEnergy;
371 if (name.Contains("fHistCellPseudoSizeEnergy", TString::kIgnoreCase))
372 return fHistCellPseudoSizeEnergy;
373
374 if (name.Contains("fHistLutPseudoSizeNorm", TString::kIgnoreCase))
375 return fHistLutPseudoSizeNorm;
376 if (name.Contains("fHistSizeBiggerCellNorm", TString::kIgnoreCase))
377 return fHistSizeBiggerCellNorm;
378 if (name.Contains("fHistPseudoSizeNorm", TString::kIgnoreCase))
379 return fHistPseudoSizeNorm;
380 if (name.Contains("fHistCellPseudoSizeNorm", TString::kIgnoreCase))
381 return fHistCellPseudoSizeNorm;
382
383 if (name.Contains("fHistLutPseudoSize", TString::kIgnoreCase))
384 return fHistLutPseudoSize;
385 if (name.Contains("fHistSizeBiggerCell", TString::kIgnoreCase))
386 return fHistSizeBiggerCell;
387 if (name.Contains("fHistPseudoSize", TString::kIgnoreCase))
388 return fHistPseudoSize;
389 if (name.Contains("fHistCellPseudoSize", TString::kIgnoreCase))
390 return fHistCellPseudoSize;
391
392
393 return NULL;
394}
395
396
397
398// --------------------------------------------------------------------------
399//
400// Normalize the histogram on its integral, i.e. normalize the
401// values of the histogram on the statistics. This method creates
402// a copy (histNorm) of the histogram to normalize (hist) and normalize
403// the copy (histNorm) on its integral. It returns histNorm.
404//
405TH1 *MHMcTriggerLvl2::NormalizeHist(TH1 &histNorm, TH1 *hist) const
406{
407 if (&histNorm == hist){
408 *fLog << "ARGH!@! You cannot pass the same histogram into each argument!" << endl;
409 return NULL;
410 }
411
412 if ((hist == NULL) || (hist->Integral() == (Stat_t)0)){
413 *fLog << "ARGH!@! You are trying to normalize the histogram to 0!" << endl;
414 return NULL;
415 }
416
417 histNorm.Reset("ICE");
418 histNorm.Add(hist, 1);
419 histNorm.Divide(fFNorm, (Double_t)(hist->Integral()));
420
421 return &histNorm;
422}
Note: See TracBrowser for help on using the repository browser.