source: trunk/MagicSoft/Mars/mhist/MHMcEfficiencyEnergy.cc@ 1942

Last change on this file since 1942 was 1228, checked in by tbretz, 23 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 4.6 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): Javier Lopez 05/2001 <mailto:jlopez@ifae.es>
19! Author(s): Thomas Bretz 05/2001 <mailto:tbretz@uni-sw.gwdg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2001
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MHMcEfficiencyEnergy
29//
30// This class holds the information (histogram and fit function)
31// about the energy threshold for a particular trigger condition.
32//
33////////////////////////////////////////////////////////////////////////////
34#include "MHMcEfficiencyEnergy.h"
35
36#include <math.h>
37
38#include <TH2.h>
39#include <TCanvas.h>
40
41#include "MH.h"
42#include "MBinning.h"
43
44#include "MHMcEnergyImpact.h"
45
46ClassImp(MHMcEfficiencyEnergy);
47
48// -------------------------------------------------------------------------
49//
50// Default Constructor.
51//
52MHMcEfficiencyEnergy::MHMcEfficiencyEnergy(const char *name, const char *title)
53 : fHist()
54{
55 fName = name ? name : "MHMcEfficiencyEnergy";
56 fTitle = title ? title : "Trigger Efficieny vs. Energy";
57
58 // - we initialize the histogram
59 // - we have to give diferent names for the diferent histograms because
60 // root don't allow us to have diferent histograms with the same name
61
62 fHist.SetName(fName);
63 fHist.SetTitle(fTitle);
64
65 fHist.SetDirectory(NULL);
66
67 fHist.SetXTitle("E [GeV]");
68 fHist.SetYTitle("Trig. Eff. [1]");
69
70 MBinning binse;
71 binse.SetEdgesLog(10, 1, 100000); // [GeV]
72 MH::SetBinning(&fHist, &binse);
73}
74
75void MHMcEfficiencyEnergy::SetName(const char *name)
76{
77 fName = name;
78 fHist.SetName(name);
79 fHist.SetDirectory(NULL);
80}
81
82void MHMcEfficiencyEnergy::SetTitle(const char *title)
83{
84 fTitle = title;
85 fHist.SetTitle(title);
86}
87
88//-------------------------------------------------------------------------
89//
90// Defualt Destructor
91//
92MHMcEfficiencyEnergy::~MHMcEfficiencyEnergy()
93{
94}
95
96// ------------------------------------------------------------------------
97//
98// Drawing function. It creates its own canvas.
99//
100void MHMcEfficiencyEnergy::Draw(Option_t *option)
101{
102 if (!gPad)
103 MH::MakeDefCanvas(&fHist);
104
105 gPad->SetLogx();
106
107 fHist.Draw(option);
108
109 gPad->Modified();
110 gPad->Update();
111}
112
113TObject *MHMcEfficiencyEnergy::DrawClone(Option_t *option) const
114{
115 TCanvas *c = MH::MakeDefCanvas(&fHist);
116
117 c->SetLogx();
118
119 //
120 // This is necessary to get the expected bahviour of DrawClone
121 //
122 gROOT->SetSelectedPad(NULL);
123
124 ((TH1D&)fHist).DrawCopy(option);
125
126 c->Modified();
127 c->Update();
128
129 return c;
130}
131
132void MHMcEfficiencyEnergy::Calc(const TH2D &hsel, const TH2D &hall)
133{
134 //
135 // Set the binning from the two axis of one of the two histograms
136 //
137 MH::SetBinning(&fHist, ((TH2D&)hsel).GetXaxis());
138
139 //
140 // This is necessary to initialize thze error calculation correctly
141 // (Nothing important: The histogram set the size of its internal
142 // array storing the errors to the correct size)
143 //
144 fHist.Sumw2();
145
146 //
147 // Calculate the efficiency by dividing the number of selected
148 // (eg. triggered) showers by the number of all showers per bin.
149 // Both histograms are weighted with weight 1, and for the error
150 // calculation we assume a binomial error calculation.
151 //
152 TH1D &tsel = *((TH2D&)hsel).ProjectionX();
153 TH1D &tall = *((TH2D&)hall).ProjectionX();
154 fHist.Divide(&tsel, &tall, 1, 1);
155 delete &tsel;
156 delete &tall;
157
158 SetReadyToSave();
159}
160
161// --------------------------------------------------------------------------
162//
163// Calculate the EfficiencyEnergy and set the 'ReadyToSave' flag.
164// The EfficiencyEnergy is calculated as the number of selected showers
165// (eg. triggered ones) divided by the number of all showers.
166// For error calculation Binomial errors are computed.
167//
168void MHMcEfficiencyEnergy::Calc(const MHMcEnergyImpact &mcsel, const MHMcEnergyImpact &mcall)
169{
170 Calc(*mcsel.GetHist(), *mcall.GetHist());
171}
Note: See TracBrowser for help on using the repository browser.