source: trunk/MagicSoft/Mars/mhist/MHMcEfficiency.cc@ 1861

Last change on this file since 1861 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// MHMcEfficiency
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 "MHMcEfficiency.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(MHMcEfficiency);
47
48// -------------------------------------------------------------------------
49//
50// Default Constructor.
51//
52MHMcEfficiency::MHMcEfficiency(const char *name, const char *title)
53 : fHist()
54{
55 fName = name ? name : "MHMcEfficiency";
56 fTitle = title ? title : "Trigger Efficieny (Energy-Impact parameter plane)";
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("r [m]");
69 fHist.SetZTitle("Trig. Eff. [1]");
70
71
72 MBinning binsx;
73 binsx.SetEdgesLog(10, 1, 100000); // [GeV]
74
75 MBinning binsy;
76 binsy.SetEdges(9, 0, 450); // [m]
77 MH::SetBinning(&fHist, &binsx, &binsy);
78}
79
80void MHMcEfficiency::SetName(const char *name)
81{
82 fName = name;
83 fHist.SetName(name);
84 fHist.SetDirectory(NULL);
85}
86
87void MHMcEfficiency::SetTitle(const char *title)
88{
89 fTitle = title;
90 fHist.SetTitle(title);
91}
92
93//-------------------------------------------------------------------------
94//
95// Defualt Destructor
96//
97MHMcEfficiency::~MHMcEfficiency()
98{
99}
100
101// ------------------------------------------------------------------------
102//
103// Drawing function. It creates its own canvas.
104//
105void MHMcEfficiency::Draw(Option_t *option)
106{
107 if (!gPad)
108 MH::MakeDefCanvas(&fHist);
109
110 gPad->SetLogx();
111
112 fHist.Draw(option);
113
114 gPad->Modified();
115 gPad->Update();
116}
117
118TObject *MHMcEfficiency::DrawClone(Option_t *option) const
119{
120 TCanvas *c = MH::MakeDefCanvas(&fHist);
121
122 c->SetLogx();
123
124 //
125 // This is necessary to get the expected bahviour of DrawClone
126 //
127 gROOT->SetSelectedPad(NULL);
128
129 ((TH2D&)fHist).DrawCopy(option);
130
131 c->Modified();
132 c->Update();
133
134 return c;
135}
136
137void MHMcEfficiency::Calc(const TH2D &hsel, const TH2D &hall)
138{
139 //
140 // Set the binning from the two axis of one of the two histograms
141 //
142 MH::SetBinning(&fHist, ((TH2D&)hsel).GetXaxis(), ((TH2D&)hsel).GetYaxis());
143
144 //
145 // This is necessary to initialize thze error calculation correctly
146 // (Nothing important: The histogram set the size of its internal
147 // array storing the errors to the correct size)
148 //
149 fHist.Sumw2();
150
151 //
152 // Calculate the efficiency by dividing the number of selected
153 // (eg. triggered) showers by the number of all showers per bin.
154 // Both histograms are weighted with weight 1, and for the error
155 // calculation we assume a binomial error calculation.
156 //
157 fHist.Divide((TH2D*)&hsel, (TH2D*)&hall, 1, 1, "B");
158
159 SetReadyToSave();
160}
161
162// --------------------------------------------------------------------------
163//
164// Calculate the Efficiency and set the 'ReadyToSave' flag.
165// The Efficiency is calculated as the number of selected showers
166// (eg. triggered ones) divided by the number of all showers.
167// For error calculation Binomial errors are computed.
168//
169void MHMcEfficiency::Calc(const MHMcEnergyImpact &mcsel, const MHMcEnergyImpact &mcall)
170{
171 Calc(*mcsel.GetHist(), *mcall.GetHist());
172
173}
Note: See TracBrowser for help on using the repository browser.