source: trunk/MagicSoft/Mars/mhist/MHMcEnergy.cc@ 879

Last change on this file since 879 was 867, checked in by tbretz, 23 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 5.4 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 (jlopez@ifae.es)
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHMcEnergy
28//
29// This class holds the information (histogram and fit function)
30// about the energy threshold for a particular trigger condition.
31//
32////////////////////////////////////////////////////////////////////////////
33#include "MHMcEnergy.h"
34
35#include <iostream.h>
36
37#include <TH1.h>
38#include <TF1.h>
39#include <TCanvas.h>
40#include <TPaveLabel.h>
41
42ClassImp(MHMcEnergy);
43
44// -------------------------------------------------------------------------
45//
46// Default Constructor.
47//
48MHMcEnergy::MHMcEnergy(const UInt_t idx, const char *name, const char *title)
49{
50 char aux[15]="MHMcEnergy";
51
52 if (idx>0)
53 sprintf(aux+strlen(aux), ";%i", idx);
54
55 *fName = name ? name : aux;
56 *fTitle = title ? title : "Container for an energy distribution histogram" ;
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 char text[256];
63 sprintf(text, "Energy Distribution for trigger condition #%i", idx);
64
65 strcpy(aux, "log(E)");
66 if (idx>0)
67 sprintf(aux+strlen(aux), " #%i", idx);
68 fHist = new TH1F(aux, text, 40, 0.5, 4.5);
69 fHist->SetXTitle("log(E/GeV)");
70 fHist->SetYTitle("dN/dE");
71}
72
73//-------------------------------------------------------------------------
74//
75// Defualt Destructor
76//
77MHMcEnergy::~MHMcEnergy()
78{
79 delete fHist;
80}
81
82//--------------------------------------------------------------------------
83//
84// Fill the histogram with the log10 of the energy for triggered events.
85//
86void MHMcEnergy::Fill(Float_t log10E, Float_t w)
87{
88 fHist->Fill(log10E, w);
89}
90
91// -------------------------------------------------------------------------
92//
93// Fitting function
94//
95void MHMcEnergy::Fit(Axis_t xxmin, Axis_t xxmax)
96{
97 //
98 // 0: don't draw the function (it is drawn together with the histogram)
99 // Q: quiet mode
100 //
101 fHist->Fit("gaus", "Q0", "", xxmin, xxmax);
102
103 TF1 *result = fHist->GetFunction("gaus");
104
105 fThreshold = CalcThreshold(result);
106 fThresholdErr = CalcThresholdErr(result);
107 fGaussPeak = CalcGaussPeak(result);
108 fGaussSigma = CalcGaussSigma(result);
109}
110
111// ------------------------------------------------------------------------
112//
113// Drawing function. It creates its own canvas.
114//
115void MHMcEnergy::Draw(Option_t *option)
116{
117 char text[256];
118
119 const Float_t min = fHist->GetMinimum();
120 const Float_t max = fHist->GetMaximum();
121 const Float_t sum = min+max;
122
123 TCanvas *c=new TCanvas(fHist->GetName(), fHist->GetTitle());
124
125 fHist->Draw(option);
126
127 sprintf(text, "Energy Threshold = %4.1f +- %4.1f GeV",
128 fThreshold, fThresholdErr);
129
130 TPaveLabel* label = new TPaveLabel(2.2, 0.75*sum, 4.4, 0.90*sum, text);
131 label->SetFillColor(10);
132 label->SetTextSize(0.3);
133 label->SetBit(kCanDelete);
134 label->Draw();
135
136 c->Modified();
137 c->Update();
138}
139
140// --------------------------------------------------------------------------
141//
142// Set the number of bins in the histogran.
143//
144void MHMcEnergy::SetNumBins(Int_t nbins)
145{
146 fHist->SetBins(nbins, 0.5, 4.5);
147}
148// --------------------------------------------------------------------------
149//
150// Write the threshold and its error in the standard output
151//
152void MHMcEnergy::Print(Option_t*)
153{
154 cout << "Threshold: " << fThreshold << " +- " << fThresholdErr << endl;
155}
156
157// -------------------------------------------------------------------------
158//
159// Return the threshold
160//
161Float_t MHMcEnergy::CalcThreshold(TF1 *gauss)
162{
163 const Float_t p1 = gauss->GetParameter(1);
164
165 return pow(10, p1);
166}
167
168// -------------------------------------------------------------------------
169//
170// Return the error of the threshold.
171//
172Float_t MHMcEnergy::CalcThresholdErr(TF1 *gauss)
173{
174 const Float_t lg10 = log(10);
175 const Float_t p1 = gauss->GetParameter(1);
176 const Float_t p1err = gauss->GetParError(1);
177
178 // The error has into accuont the error in the fit
179 return pow(10, p1) * p1err * lg10;
180}
181
182// -------------------------------------------------------------------------
183//
184// Return the peak of the fitted gaussan function.
185//
186Float_t MHMcEnergy::CalcGaussPeak(TF1 *gauss)
187{
188 return gauss->GetParameter(1);
189}
190
191// -------------------------------------------------------------------------
192//
193// Return the sigma of the fitted gaussan function.
194//
195Float_t MHMcEnergy::CalcGaussSigma(TF1 *gauss)
196{
197 return gauss->GetParameter(2);
198}
199
Note: See TracBrowser for help on using the repository browser.