source: trunk/MagicSoft/Mars/mtemp/mucm/classes/MHExcessEnergyTheta.cc@ 5973

Last change on this file since 5973 was 5450, checked in by marcos, 20 years ago
*** empty log message ***
File size: 8.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): Marcos Lopez 11/2004 <mailto:marcos@gae.ucm.es>
19!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26// //
27// MHExcessEnergyTheta //
28// //
29// 3D-histogram in alpha vs. E-est and Theta //
30// //
31//////////////////////////////////////////////////////////////////////////////
32
33#include "MHExcessEnergyTheta.h"
34
35#include <TCanvas.h>
36#include <THStack.h>
37#include <TLegend.h>
38#include <TStyle.h>
39
40#include "MMcEvt.hxx"
41#include "MHillasSrc.h"
42#include "MEnergyEst.h"
43#include "MPointingPos.h"
44#include "MRawRunHeader.h"
45#include "MHAlphaEnergyTheta.h"
46#include "MHFindSignificance.h"
47
48#include "MBinning.h"
49#include "MParList.h"
50
51#include "MLog.h"
52#include "MLogManip.h"
53
54ClassImp(MHExcessEnergyTheta);
55
56using namespace std;
57
58// --------------------------------------------------------------------------
59//
60// Default Constructor. It sets name and title of the histogram.
61//
62MHExcessEnergyTheta::MHExcessEnergyTheta(const char *name, const char *title)
63 : fHist("","",10,0,1, 10,0,1)
64{
65 //
66 // set the name and title of this object
67 //
68 fName = name ? name : "MHExcessEnergyTheta";
69 fTitle = title ? title : "# Excess events vs. E and Theta";
70
71
72 fHist.SetDirectory(NULL);
73
74 fHist.SetTitle("# Excess events vs. E and Theta");
75 fHist.SetXTitle("E [GeV]");
76 fHist.SetYTitle("\\Theta [\\circ]");
77 fHist.SetZTitle("# Excess events");
78}
79
80// --------------------------------------------------------------------------
81//
82// Set binnings and prepare filling of the histogram
83//
84Bool_t MHExcessEnergyTheta::SetupFill(const MParList *plist)
85{
86
87 // fEnergy = (MEnergyEst*)plist->FindObject("MEnergyEst");
88// if (!fEnergy)
89// {
90// *fLog << err << dbginf << "MEnergyEst not found... aborting." << endl;
91// return kFALSE;
92// }
93
94
95// //
96// // Binning
97// //
98// MBinning* binsenergy = (MBinning*)plist->FindObject("BinningE");
99// MBinning* binsalphaflux = (MBinning*)plist->FindObject("BinningAlphaFlux");
100// MBinning* binstheta = (MBinning*)plist->FindObject("BinningTheta");
101// if (!binsenergy || !binsalphaflux || !binstheta)
102// {
103// *fLog << err << dbginf << "At least one MBinning not found... aborting." << endl;
104// return kFALSE;
105// }
106
107// // SetBinning(&fHist, binsalphaflux, binsenergy, binstheta);
108// SetBinning(&fHist, binsenergy, binstheta, binsalphaflux);
109
110// fHist.Sumw2();
111
112
113 return kTRUE;
114}
115
116// --------------------------------------------------------------------------
117//
118// Look in the parlist for MMcEvt or MPointingPos depending on the run type.
119//
120Bool_t MHExcessEnergyTheta::ReInit(MParList *pList)
121{
122
123// // This must be done in ReInit because in PreProcess the
124// // runheaders are not available
125// const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
126// if (!runheader)
127// {
128// *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
129// *fLog << warn << dbginf << "Warning - Assuming data type file...searching for MPointingPos..." << endl;
130// }
131
132
133// if (runheader && runheader->IsMonteCarloRun())
134// {
135// fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
136// if (!fMcEvt)
137// {
138// *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
139// return kFALSE;
140// }
141// }
142// else
143// {
144// fPointingPos = (MPointingPos*)pList->FindObject("MPointingPos");
145// if (!fPointingPos)
146// {
147// *fLog << err << dbginf << "PointingPos not found... aborting." << endl;
148// return kFALSE;
149// }
150// }
151
152 return kTRUE;
153}
154
155
156
157// --------------------------------------------------------------------------
158//
159// Fill the histogram
160//
161Bool_t MHExcessEnergyTheta::Fill(const MParContainer *par, const Stat_t w)
162{
163 // MHillasSrc &hil = *(MHillasSrc*)par;
164
165// // fHist.Fill(hil.GetAlpha(), fEnergy->GetEnergy(),
166// // fMcEvt->GetTelescopeTheta()*kRad2Deg, w);
167
168
169// const Double_t Zd = (fMcEvt) ? fMcEvt->GetTelescopeTheta()*kRad2Deg : fPointingPos->GetZd() ;
170
171// fHist.Fill(fEnergy->GetEnergy(), Zd, hil.GetAlpha(), w);
172
173// // *fLog<< Zd << " " << fEnergy->GetEnergy() << " " << hil.GetAlpha() << endl;
174
175 return kTRUE;
176}
177
178
179
180// --------------------------------------------------------------------------
181//
182// Get the Alpha distribution for each bin in energy and theta,
183// fit it with MHFindSignificance to get the number of Excess events
184// and it error.
185//
186void MHExcessEnergyTheta::Calc(MHAlphaEnergyTheta* hAlpha)
187{
188 TH3D* aet = (TH3D*)hAlpha->GetHist();
189
190 const TAxis* axisEnergy = aet->GetXaxis();
191 const TAxis* axisTheta = aet->GetYaxis();
192 const Int_t energyBins = aet->GetXaxis()->GetNbins();
193 const Int_t thetaBins = aet->GetYaxis()->GetNbins();;
194
195 MH::SetBinning(&fHist, axisEnergy, axisTheta);
196
197 for(Int_t iy=1; iy<=thetaBins; iy++)
198 {
199 TCanvas* c= new TCanvas(Form("zbin %d",iy),Form("zbin %d",iy));
200 c->Divide(4,3);
201
202 for(Int_t ix=1; ix<=energyBins; ix++)
203 { const Double_t e = aet->GetXaxis()->GetBinCenter(ix);
204 const Double_t e1 = aet->GetXaxis()->GetBinLowEdge(ix);
205 const Double_t e2 = aet->GetXaxis()->GetBinLowEdge(ix+1);
206
207 //TH1* halpha = aet->ProjectionZ("AlphaTemp",ix,ix,iy,iy);
208 TH1* halpha = aet->ProjectionZ("AlphaTemp",ix,ix);
209 halpha->SetTitle(Form("Energy Bin = (%.0f, %.0f) GeV",e1,e2));
210 halpha->SetDirectory(NULL);
211
212 MHFindSignificance findsig;
213 //findsig.SetRebin(kFALSE);
214 double alphasig=20;
215
216 if(ix<5)
217 alphasig = 20;
218 else
219 alphasig = 20;
220
221 switch (ix)
222 {
223 case 1:
224 alphasig = 20;
225 break;
226 case 2:
227 alphasig = 20;
228 break;
229 case 3:
230 alphasig = 20;
231 break;
232 case 4:
233 alphasig = 20;
234 break;
235 case 5:
236 alphasig = 20;
237 break;
238 case 6:
239 alphasig = 20;
240 break;
241 case 7:
242 alphasig = 15;
243 break;
244 case 8:
245 alphasig = 10;
246 break;
247 case 9:
248 alphasig = 5;
249 break;
250 case 10:
251 alphasig = 5;
252 break;
253 }
254
255
256 fLog->SetNullOutput(kTRUE);
257
258 Bool_t rc = findsig.FindSigma(halpha, 30,90, 2, alphasig, 0,1,0);
259 Double_t SigmaGauss = findsig.GetSigmaGauss();
260
261 // alphasig = SigmaGauss*3;
262
263// rc = findsig.FindSigma(halpha, 30,90, 2, alphasig, 0,1,0);
264
265 fLog->SetNullOutput(kFALSE);
266
267 if(ix<=20)
268 {
269 c->cd(ix);
270 findsig.DrawFit("brief");
271 }
272
273 Double_t Nex = 0;
274 Double_t dNex = 0;
275 Double_t Sig = 0;
276
277 if(!rc)
278 {
279 cout << "ERROR: Fit not possible. " << endl;
280 }
281 // else
282 {
283 SigmaGauss = findsig.GetSigmaGauss();
284 Nex = findsig.GetNex();
285 dNex = findsig.GetdNex();
286 Sig = findsig.GetSigLiMa();
287 }
288 // Avoid to have a negative number of excess events, which
289 // will give a negative flux which doesn't make sense
290 if(Nex<0)
291 {
292 Nex = 0;
293 dNex = 0;
294 Sig = 0;
295 }
296
297 fHist.SetBinContent(ix,iy, Nex);
298 fHist.SetBinError(ix,iy, dNex);
299
300
301 // Print
302 *fLog<< endl
303 << " Theta Bin = " << iy << endl
304 << " Energy bin width E = " << ix << endl
305 << " Alphasig = " <<alphasig << endl
306 << " N = " << Nex <<" +- " << dNex << endl
307 << " Significane = " << Sig << endl;
308 }
309 }
310}
311
312
313
314// --------------------------------------------------------------------------
315//
316// Draw the histogram
317//
318void MHExcessEnergyTheta::Draw(Option_t *opt)
319{
320 TCanvas *c1 = new TCanvas("# Excess events vs. E and Theta","# Excess events vs. E and Theta");
321 c1->SetLogx();
322 c1->SetLogz();
323
324 fHist.SetStats(0);
325 fHist.Draw("lego");
326}
Note: See TracBrowser for help on using the repository browser.