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 <stdlib.h>
|
---|
36 | #include <iostream.h>
|
---|
37 |
|
---|
38 | #include <TH1.h>
|
---|
39 | #include <TF1.h>
|
---|
40 | #include <TCanvas.h>
|
---|
41 | #include <TPaveLabel.h>
|
---|
42 |
|
---|
43 | ClassImp(MHMcEnergy);
|
---|
44 |
|
---|
45 | // -------------------------------------------------------------------------
|
---|
46 | //
|
---|
47 | // Default Constructor.
|
---|
48 | //
|
---|
49 | MHMcEnergy::MHMcEnergy(const char *name, const char *title)
|
---|
50 | {
|
---|
51 | *fTitle = title ? title : "Container for an energy distribution histogram";
|
---|
52 |
|
---|
53 | // - we initialize the histogram
|
---|
54 | // - we have to give diferent names for the diferent histograms because
|
---|
55 | // root don't allow us to have diferent histograms with the same name
|
---|
56 |
|
---|
57 | fHist = new TH1F("", "", 40, 0.5, 4.5);
|
---|
58 | fHist->SetXTitle("log(E/GeV)");
|
---|
59 | fHist->SetYTitle("dN/dE");
|
---|
60 |
|
---|
61 | SetName(name ? name : "MHMcEnergy");
|
---|
62 | }
|
---|
63 |
|
---|
64 | // -------------------------------------------------------------------------
|
---|
65 | //
|
---|
66 | // This doesn't only set the name. It tries to get the number from the
|
---|
67 | // name and creates also name and title of the histogram.
|
---|
68 | //
|
---|
69 | // This is necessary for example if a list of such MHMcEnergy histograms
|
---|
70 | // is created (s. MParList::CreateObjList)
|
---|
71 | //
|
---|
72 | void MHMcEnergy::SetName(const char *name)
|
---|
73 | {
|
---|
74 | TString cname(name);
|
---|
75 | const char *semicolon = strrchr(cname, ';');
|
---|
76 |
|
---|
77 | UInt_t idx = semicolon ? atoi(semicolon+1) : 0;
|
---|
78 |
|
---|
79 | *fName = cname;
|
---|
80 |
|
---|
81 | char text[256];
|
---|
82 | if (idx>0)
|
---|
83 | sprintf(text, "Energy Distribution for trigger condition #%i", idx);
|
---|
84 | else
|
---|
85 | sprintf(text, "Energy Distribution");
|
---|
86 |
|
---|
87 | char aux[256];
|
---|
88 | strcpy(aux, "log(E)");
|
---|
89 |
|
---|
90 | if (idx>0)
|
---|
91 | sprintf(aux+strlen(aux), " #%i", idx);
|
---|
92 |
|
---|
93 | fHist->SetName(aux);
|
---|
94 | fHist->SetTitle(text);
|
---|
95 | }
|
---|
96 |
|
---|
97 | //-------------------------------------------------------------------------
|
---|
98 | //
|
---|
99 | // Defualt Destructor
|
---|
100 | //
|
---|
101 | MHMcEnergy::~MHMcEnergy()
|
---|
102 | {
|
---|
103 | delete fHist;
|
---|
104 | }
|
---|
105 |
|
---|
106 | //--------------------------------------------------------------------------
|
---|
107 | //
|
---|
108 | // Fill the histogram with the log10 of the energy for triggered events.
|
---|
109 | //
|
---|
110 | void MHMcEnergy::Fill(Float_t log10E, Float_t w)
|
---|
111 | {
|
---|
112 | fHist->Fill(log10E, w);
|
---|
113 | }
|
---|
114 |
|
---|
115 | // -------------------------------------------------------------------------
|
---|
116 | //
|
---|
117 | // Fitting function
|
---|
118 | //
|
---|
119 | void MHMcEnergy::Fit(Axis_t xxmin, Axis_t xxmax)
|
---|
120 | {
|
---|
121 | //
|
---|
122 | // 0: don't draw the function (it is drawn together with the histogram)
|
---|
123 | // Q: quiet mode
|
---|
124 | //
|
---|
125 | fHist->Fit("gaus", "Q0", "", xxmin, xxmax);
|
---|
126 |
|
---|
127 | TF1 *result = fHist->GetFunction("gaus");
|
---|
128 |
|
---|
129 | fThreshold = CalcThreshold(result);
|
---|
130 | fThresholdErr = CalcThresholdErr(result);
|
---|
131 | fGaussPeak = CalcGaussPeak(result);
|
---|
132 | fGaussSigma = CalcGaussSigma(result);
|
---|
133 | }
|
---|
134 |
|
---|
135 | // ------------------------------------------------------------------------
|
---|
136 | //
|
---|
137 | // Drawing function. It creates its own canvas.
|
---|
138 | //
|
---|
139 | void MHMcEnergy::Draw(Option_t *option)
|
---|
140 | {
|
---|
141 | char text[256];
|
---|
142 |
|
---|
143 | const Float_t min = fHist->GetMinimum();
|
---|
144 | const Float_t max = fHist->GetMaximum();
|
---|
145 | const Float_t sum = min+max;
|
---|
146 |
|
---|
147 | TCanvas *c=new TCanvas(fHist->GetName(), fHist->GetTitle());
|
---|
148 |
|
---|
149 | fHist->Draw(option);
|
---|
150 |
|
---|
151 | sprintf(text, "Energy Threshold = %4.1f +- %4.1f GeV",
|
---|
152 | fThreshold, fThresholdErr);
|
---|
153 |
|
---|
154 | TPaveLabel* label = new TPaveLabel(2.2, 0.75*sum, 4.4, 0.90*sum, text);
|
---|
155 | label->SetFillColor(10);
|
---|
156 | label->SetTextSize(0.3);
|
---|
157 | label->SetBit(kCanDelete);
|
---|
158 | label->Draw();
|
---|
159 |
|
---|
160 | c->Modified();
|
---|
161 | c->Update();
|
---|
162 | }
|
---|
163 |
|
---|
164 | // --------------------------------------------------------------------------
|
---|
165 | //
|
---|
166 | // Set the number of bins in the histogran.
|
---|
167 | //
|
---|
168 | void MHMcEnergy::SetNumBins(Int_t nbins)
|
---|
169 | {
|
---|
170 | fHist->SetBins(nbins, 0.5, 4.5);
|
---|
171 | }
|
---|
172 | // --------------------------------------------------------------------------
|
---|
173 | //
|
---|
174 | // Write the threshold and its error in the standard output
|
---|
175 | //
|
---|
176 | void MHMcEnergy::Print(Option_t*)
|
---|
177 | {
|
---|
178 | cout << "Threshold: " << fThreshold << " +- " << fThresholdErr << endl;
|
---|
179 | }
|
---|
180 |
|
---|
181 | // -------------------------------------------------------------------------
|
---|
182 | //
|
---|
183 | // Return the threshold
|
---|
184 | //
|
---|
185 | Float_t MHMcEnergy::CalcThreshold(TF1 *gauss)
|
---|
186 | {
|
---|
187 | const Float_t p1 = gauss->GetParameter(1);
|
---|
188 |
|
---|
189 | return pow(10, p1);
|
---|
190 | }
|
---|
191 |
|
---|
192 | // -------------------------------------------------------------------------
|
---|
193 | //
|
---|
194 | // Return the error of the threshold.
|
---|
195 | //
|
---|
196 | Float_t MHMcEnergy::CalcThresholdErr(TF1 *gauss)
|
---|
197 | {
|
---|
198 | const Float_t lg10 = log(10);
|
---|
199 | const Float_t p1 = gauss->GetParameter(1);
|
---|
200 | const Float_t p1err = gauss->GetParError(1);
|
---|
201 |
|
---|
202 | // The error has into accuont the error in the fit
|
---|
203 | return pow(10, p1) * p1err * lg10;
|
---|
204 | }
|
---|
205 |
|
---|
206 | // -------------------------------------------------------------------------
|
---|
207 | //
|
---|
208 | // Return the peak of the fitted gaussan function.
|
---|
209 | //
|
---|
210 | Float_t MHMcEnergy::CalcGaussPeak(TF1 *gauss)
|
---|
211 | {
|
---|
212 | return gauss->GetParameter(1);
|
---|
213 | }
|
---|
214 |
|
---|
215 | // -------------------------------------------------------------------------
|
---|
216 | //
|
---|
217 | // Return the sigma of the fitted gaussan function.
|
---|
218 | //
|
---|
219 | Float_t MHMcEnergy::CalcGaussSigma(TF1 *gauss)
|
---|
220 | {
|
---|
221 | return gauss->GetParameter(2);
|
---|
222 | }
|
---|
223 |
|
---|