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): Thomas Bretz, 3/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MHAlpha
|
---|
28 | //
|
---|
29 | // Create a single Alpha-Plot. The alpha-plot is fitted online. You can
|
---|
30 | // check the result when it is filles in the MStatusDisplay
|
---|
31 | // For more information see MHFalseSource::FitSignificance
|
---|
32 | //
|
---|
33 | // For convinience (fit) the output significance is stored in a
|
---|
34 | // container in the parlisrt
|
---|
35 | //
|
---|
36 | // PRELIMINARY!
|
---|
37 | //
|
---|
38 | //////////////////////////////////////////////////////////////////////////////
|
---|
39 | #include "MHAlpha.h"
|
---|
40 |
|
---|
41 | #include <TF1.h>
|
---|
42 | #include <TGraph.h>
|
---|
43 | #include <TStyle.h>
|
---|
44 | #include <TLatex.h>
|
---|
45 | #include <TCanvas.h>
|
---|
46 | #include <TPaveStats.h>
|
---|
47 | #include <TStopwatch.h>
|
---|
48 |
|
---|
49 | #include "MGeomCam.h"
|
---|
50 | #include "MSrcPosCam.h"
|
---|
51 | #include "MHillasSrc.h"
|
---|
52 | #include "MEnergyEst.h"
|
---|
53 | #include "MTime.h"
|
---|
54 | #include "MObservatory.h"
|
---|
55 | #include "MPointingPos.h"
|
---|
56 | #include "MAstroSky2Local.h"
|
---|
57 | #include "MStatusDisplay.h"
|
---|
58 | #include "MParameters.h"
|
---|
59 | #include "MHMatrix.h"
|
---|
60 |
|
---|
61 | #include "MBinning.h"
|
---|
62 | #include "MParList.h"
|
---|
63 |
|
---|
64 | #include "MLog.h"
|
---|
65 | #include "MLogManip.h"
|
---|
66 |
|
---|
67 | ClassImp(MHAlpha);
|
---|
68 | ClassImp(MAlphaFitter);
|
---|
69 |
|
---|
70 | using namespace std;
|
---|
71 |
|
---|
72 | // --------------------------------------------------------------------------
|
---|
73 | //
|
---|
74 | // Default Constructor
|
---|
75 | //
|
---|
76 | MHAlpha::MHAlpha(const char *name, const char *title)
|
---|
77 | : fOffData(0), fResult(0), /*fExcess(0),*/ fEnergy(0), fHillas(0),
|
---|
78 | fPointPos(0), fTimeEffOn(0), fTime(0),
|
---|
79 | fSkipHistTime(kFALSE), fSkipHistTheta(kFALSE), fSkipHistEnergy(kFALSE),
|
---|
80 | //fEnergyMin(-1), fEnergyMax(-1), fSizeMin(-1), fSizeMax(-1),
|
---|
81 | fMatrix(0)
|
---|
82 | {
|
---|
83 | //
|
---|
84 | // set the name and title of this object
|
---|
85 | //
|
---|
86 | fName = name ? name : "MHAlpha";
|
---|
87 | fTitle = title ? title : "Alpha plot";
|
---|
88 |
|
---|
89 | fHAlpha.SetName("Alpha");
|
---|
90 | fHAlpha.SetTitle("Alpha");
|
---|
91 | fHAlpha.SetXTitle("\\Theta [deg]");
|
---|
92 | fHAlpha.SetYTitle("E_{est} [GeV]");
|
---|
93 | fHAlpha.SetZTitle("|\\alpha| [\\circ]");
|
---|
94 | fHAlpha.SetDirectory(NULL);
|
---|
95 | fHAlpha.UseCurrentStyle();
|
---|
96 |
|
---|
97 | // Main histogram
|
---|
98 | fHAlphaTime.SetName("Alpha");
|
---|
99 | fHAlphaTime.SetXTitle("|\\alpha| [\\circ]");
|
---|
100 | fHAlphaTime.SetYTitle("Counts");
|
---|
101 | fHAlphaTime.UseCurrentStyle();
|
---|
102 | fHAlphaTime.SetDirectory(NULL);
|
---|
103 |
|
---|
104 |
|
---|
105 | //fHEnergy.SetName("Energy");
|
---|
106 | //fHEnergy.SetTitle(" N_{exc} vs. E_{est} ");
|
---|
107 | //fHEnergy.SetXTitle("E_{est} [GeV]");
|
---|
108 | fHEnergy.SetYTitle("N_{exc}");
|
---|
109 | fHEnergy.SetDirectory(NULL);
|
---|
110 | fHEnergy.UseCurrentStyle();
|
---|
111 |
|
---|
112 | fHTheta.SetName("Theta");
|
---|
113 | fHTheta.SetTitle(" N_{exc} vs. \\Theta ");
|
---|
114 | fHTheta.SetXTitle("\\Theta [\\circ]");
|
---|
115 | fHTheta.SetYTitle("N_{exc}");
|
---|
116 | fHTheta.SetDirectory(NULL);
|
---|
117 | fHTheta.UseCurrentStyle();
|
---|
118 |
|
---|
119 | // effective on time versus time
|
---|
120 | fHTime.SetName("Time");
|
---|
121 | fHTime.SetTitle(" N_{exc} vs. Time ");
|
---|
122 | fHTime.SetXTitle("Time");
|
---|
123 | fHTime.SetYTitle("N_{exc} [s]");
|
---|
124 | fHTime.UseCurrentStyle();
|
---|
125 | fHTime.SetDirectory(NULL);
|
---|
126 | fHTime.GetYaxis()->SetTitleOffset(1.2);
|
---|
127 | fHTime.GetXaxis()->SetLabelSize(0.033);
|
---|
128 | fHTime.GetXaxis()->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
|
---|
129 | fHTime.GetXaxis()->SetTimeDisplay(1);
|
---|
130 | fHTime.Sumw2();
|
---|
131 |
|
---|
132 | MBinning binsa, binse, binst;
|
---|
133 | binsa.SetEdges(18, 0, 90);
|
---|
134 | binse.SetEdgesLog(25, 10, 100000);
|
---|
135 | binst.SetEdgesCos(50, 0, 60);
|
---|
136 | binse.Apply(fHEnergy);
|
---|
137 | binst.Apply(fHTheta);
|
---|
138 | binsa.Apply(fHAlphaTime);
|
---|
139 |
|
---|
140 | MH::SetBinning(&fHAlpha, &binst, &binse, &binsa);
|
---|
141 | }
|
---|
142 |
|
---|
143 | void MHAlpha::FitEnergySpec(Bool_t paint)
|
---|
144 | {
|
---|
145 | /*
|
---|
146 | TF1 f("Spectrum", "pow(x, [0])*exp(-x/[1])*[2]*x");//
|
---|
147 | f.SetParameter(0, -2.1);
|
---|
148 | f.SetParameter(1, 1400); // 50
|
---|
149 | f.SetParameter(2, fHEnergy.Integral()); // 50
|
---|
150 | f.SetLineWidth(2);
|
---|
151 |
|
---|
152 | fHEnergy.Fit(&f, "0QI", "", 100, 2400); // Integral? 90, 2800
|
---|
153 |
|
---|
154 | const Double_t chi2 = f.GetChisquare();
|
---|
155 | const Int_t NDF = f.GetNDF();
|
---|
156 |
|
---|
157 | // was fit successful ?
|
---|
158 | const Bool_t ok = NDF>0 && chi2<2.5*NDF;
|
---|
159 | f.SetLineColor(ok ? kGreen : kRed);
|
---|
160 |
|
---|
161 | if (paint)
|
---|
162 | {
|
---|
163 | f.Paint("same");
|
---|
164 |
|
---|
165 | if (ok)
|
---|
166 | {
|
---|
167 | TString s;
|
---|
168 | s += Form("\\alpha=%.1f ", f.GetParameter(0));
|
---|
169 | s += Form("E_{c}=%.1f TeV ", f.GetParameter(1)/1000);
|
---|
170 | s += Form("N=%.1e", f.GetParameter(2));
|
---|
171 |
|
---|
172 | TLatex text(0.25, 0.94, s.Data());
|
---|
173 | text.SetBit(TLatex::kTextNDC);
|
---|
174 | text.SetTextSize(0.04);
|
---|
175 | text.Paint();
|
---|
176 | }
|
---|
177 | }*/
|
---|
178 | }
|
---|
179 |
|
---|
180 | void MHAlpha::FitEnergyBins(Bool_t paint)
|
---|
181 | {
|
---|
182 | // Do not store the 'final' result in fFit
|
---|
183 | MAlphaFitter fit(fFit);
|
---|
184 |
|
---|
185 | const Int_t n = fHAlpha.GetNbinsY();
|
---|
186 |
|
---|
187 | fHEnergy.SetEntries(0);
|
---|
188 |
|
---|
189 | for (int i=1; i<=n; i++)
|
---|
190 | {
|
---|
191 | if (fit.FitEnergy(fHAlpha, fOffData, i))
|
---|
192 | {
|
---|
193 | fHEnergy.SetBinContent(i, fit.GetEventsExcess());
|
---|
194 | fHEnergy.SetBinError(i, fit.GetEventsExcess()*0.2);
|
---|
195 | }
|
---|
196 | }
|
---|
197 | }
|
---|
198 |
|
---|
199 | void MHAlpha::FitThetaBins(Bool_t paint)
|
---|
200 | {
|
---|
201 | // Do not store the 'final' result in fFit
|
---|
202 | MAlphaFitter fit(fFit);
|
---|
203 |
|
---|
204 | const Int_t n = fHAlpha.GetNbinsX();
|
---|
205 |
|
---|
206 | fHTheta.SetEntries(0);
|
---|
207 |
|
---|
208 | for (int i=1; i<=n; i++)
|
---|
209 | {
|
---|
210 | if (fit.FitTheta(fHAlpha, fOffData, i))
|
---|
211 | {
|
---|
212 | fHTheta.SetBinContent(i, fit.GetEventsExcess());
|
---|
213 | fHTheta.SetBinError(i, fit.GetEventsExcess()*0.2);
|
---|
214 | }
|
---|
215 | }
|
---|
216 | }
|
---|
217 |
|
---|
218 | Bool_t MHAlpha::SetupFill(const MParList *pl)
|
---|
219 | {
|
---|
220 | fHAlpha.Reset();
|
---|
221 | fHEnergy.Reset();
|
---|
222 | fHTheta.Reset();
|
---|
223 |
|
---|
224 | if (fName!=(TString)"MHAlphaOff" && fOffData==NULL)
|
---|
225 | {
|
---|
226 | MHAlpha *hoff = (MHAlpha*)pl->FindObject("MHAlphaOff", "MHAlpha");
|
---|
227 | if (!hoff)
|
---|
228 | *fLog << inf << "No MHAlphaOff [MHAlpha] found... using current data only!" << endl;
|
---|
229 | else
|
---|
230 | {
|
---|
231 | *fLog << inf << "MHAlphaOff [MHAlpha] found... using on-off mode!" << endl;
|
---|
232 | SetOffData(*hoff);
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | fHillas = 0;
|
---|
237 | /*
|
---|
238 | if (fSizeMin>=0 || fSizeMax>=0)
|
---|
239 | {
|
---|
240 | fHillas = (MHillas*)pl->FindObject("MHillas");
|
---|
241 | if (!fHillas)
|
---|
242 | {
|
---|
243 | *fLog << warn << "Size cut set, but MHillas not found... abort." << endl;
|
---|
244 | return kFALSE;
|
---|
245 | }
|
---|
246 | }
|
---|
247 | */
|
---|
248 | fEnergy = (MEnergyEst*)pl->FindObject("MEnergyEst");
|
---|
249 | if (!fEnergy)
|
---|
250 | { /*
|
---|
251 | if (fEnergyMin>=0 || fEnergyMax>=0)
|
---|
252 | {
|
---|
253 | *fLog << warn << "Energy cut set, but MEnergyEst not found... abort." << endl;
|
---|
254 | return kFALSE;
|
---|
255 | } */
|
---|
256 |
|
---|
257 | *fLog << warn << "MEnergyEst not found... " << flush;
|
---|
258 |
|
---|
259 | if (!fHillas)
|
---|
260 | fHillas = (MHillas*)pl->FindObject("MHillas");
|
---|
261 | if (fHillas)
|
---|
262 | *fLog << "using SIZE instead!" << endl;
|
---|
263 | else
|
---|
264 | *fLog << "ignored." << endl;
|
---|
265 |
|
---|
266 | fHEnergy.SetName("Size");
|
---|
267 | fHEnergy.SetTitle(" N_{exc} vs. Size ");
|
---|
268 | fHEnergy.SetXTitle("Size [\\gamma]");
|
---|
269 | }
|
---|
270 | else
|
---|
271 | {
|
---|
272 | fHEnergy.SetName("Energy");
|
---|
273 | fHEnergy.SetTitle(" N_{exc} vs. E_{est} ");
|
---|
274 | fHEnergy.SetXTitle("E_{est} [GeV]");
|
---|
275 | }
|
---|
276 |
|
---|
277 | fPointPos = (MPointingPos*)pl->FindObject("MPointingPos");
|
---|
278 | if (!fPointPos)
|
---|
279 | *fLog << warn << "MPointingPos not found... ignored." << endl;
|
---|
280 |
|
---|
281 | fTimeEffOn = (MTime*)pl->FindObject("MTimeEffectiveOnTime", "MTime");
|
---|
282 | if (!fTimeEffOn)
|
---|
283 | *fLog << warn << "MTimeEffectiveOnTime [MTime] not found... ignored." << endl;
|
---|
284 | else
|
---|
285 | *fTimeEffOn = MTime(); // FIXME: How to do it different?
|
---|
286 |
|
---|
287 | fTime = (MTime*)pl->FindObject("MTime");
|
---|
288 | if (!fTime)
|
---|
289 | *fLog << warn << "MTime not found... ignored." << endl;
|
---|
290 |
|
---|
291 | fResult = (MParameterD*)const_cast<MParList*>(pl)->FindCreateObj("MParameterD", "Significance");
|
---|
292 | if (!fResult)
|
---|
293 | return kFALSE;
|
---|
294 |
|
---|
295 | //fExcess = (MParameterD*)const_cast<MParList*>(pl)->FindCreateObj("MParameterD", "MExcess");
|
---|
296 | //if (!fExcess)
|
---|
297 | // return kFALSE;
|
---|
298 |
|
---|
299 | fLastTime = MTime();
|
---|
300 |
|
---|
301 | MBinning binst, binse, binsa;
|
---|
302 | binst.SetEdges(fOffData ? *fOffData : fHAlpha, 'x');
|
---|
303 | binse.SetEdges(fOffData ? *fOffData : fHAlpha, 'y');
|
---|
304 | binsa.SetEdges(fOffData ? *fOffData : fHAlpha, 'z');
|
---|
305 |
|
---|
306 | if (!fOffData)
|
---|
307 | {
|
---|
308 | MBinning *bins = (MBinning*)pl->FindObject("BinningTheta", "MBinning");
|
---|
309 | if (fPointPos && bins)
|
---|
310 | binst.SetEdges(*bins);
|
---|
311 | if (!fPointPos)
|
---|
312 | binst.SetEdges(1, 0, 60);
|
---|
313 |
|
---|
314 | bins = (MBinning*)pl->FindObject("BinningEnergyEst", "MBinning");
|
---|
315 | if ((fEnergy||fHillas) && bins)
|
---|
316 | binse.SetEdges(*bins);
|
---|
317 | if (!fEnergy && !fHillas)
|
---|
318 | binse.SetEdges(1, 10, 100000);
|
---|
319 |
|
---|
320 | bins = (MBinning*)pl->FindObject("BinningAlpha", "MBinning");
|
---|
321 | if (bins)
|
---|
322 | binsa.SetEdges(*bins);
|
---|
323 | }
|
---|
324 |
|
---|
325 | binse.Apply(fHEnergy);
|
---|
326 | binst.Apply(fHTheta);
|
---|
327 | binsa.Apply(fHAlphaTime);
|
---|
328 | MH::SetBinning(&fHAlpha, &binst, &binse, &binsa);
|
---|
329 |
|
---|
330 | MAlphaFitter *fit = (MAlphaFitter*)pl->FindObject("MAlphaFitter");
|
---|
331 | if (!fit)
|
---|
332 | *fLog << warn << "MAlphaFitter not found... ignored." << endl;
|
---|
333 | else
|
---|
334 | fit->Copy(fFit);
|
---|
335 |
|
---|
336 | fFit.Print();
|
---|
337 |
|
---|
338 | return kTRUE;
|
---|
339 | }
|
---|
340 |
|
---|
341 | void MHAlpha::InitAlphaTime(const MTime &t)
|
---|
342 | {
|
---|
343 | //
|
---|
344 | // If this is the first call we have to initialize the time-histogram
|
---|
345 | //
|
---|
346 | MBinning bins;
|
---|
347 | bins.SetEdges(1, t.GetAxisTime()-60, t.GetAxisTime());
|
---|
348 | bins.Apply(fHTime);
|
---|
349 |
|
---|
350 | fLastTime=t;
|
---|
351 | }
|
---|
352 |
|
---|
353 | void MHAlpha::UpdateAlphaTime(Bool_t final)
|
---|
354 | {
|
---|
355 | if (!fTimeEffOn)
|
---|
356 | return;
|
---|
357 |
|
---|
358 | const Int_t steps = 10;
|
---|
359 |
|
---|
360 | static int rebin = steps;
|
---|
361 |
|
---|
362 | if (!final)
|
---|
363 | {
|
---|
364 | if (fLastTime==MTime() && *fTimeEffOn!=MTime())
|
---|
365 | {
|
---|
366 | InitAlphaTime(*fTimeEffOn);
|
---|
367 | return;
|
---|
368 | }
|
---|
369 |
|
---|
370 | if (fLastTime!=*fTimeEffOn)
|
---|
371 | {
|
---|
372 | fLastTime=*fTimeEffOn;
|
---|
373 | rebin--;
|
---|
374 | }
|
---|
375 |
|
---|
376 | if (rebin>0)
|
---|
377 | return;
|
---|
378 | }
|
---|
379 |
|
---|
380 | // Check new 'last time'
|
---|
381 | MTime *time = final ? fTime : fTimeEffOn;
|
---|
382 |
|
---|
383 | if (time->GetAxisTime()<=fHTime.GetXaxis()->GetXmax())
|
---|
384 | {
|
---|
385 | *fLog << warn << "WARNING - New time-stamp " << *time << " lower" << endl;
|
---|
386 | *fLog << "than upper edge of histogram... skipped." << endl;
|
---|
387 | *fLog << "This should not happen. Maybe you started you eventloop with" << endl;
|
---|
388 | *fLog << "an already initialized time stamp MTimeEffectiveOnTime?" << endl;
|
---|
389 | rebin++;
|
---|
390 | return;
|
---|
391 | }
|
---|
392 |
|
---|
393 | // Fit time histogram
|
---|
394 | MAlphaFitter fit(fFit);
|
---|
395 |
|
---|
396 | TH1D *h = fOffData ? fOffData->ProjectionZ("ProjTimeTemp", -1, 9999, -1, 9999, "E") : 0;
|
---|
397 | const Bool_t rc = fit.Fit(fHAlphaTime, h);
|
---|
398 | if (h)
|
---|
399 | delete h;
|
---|
400 |
|
---|
401 | if (!rc)
|
---|
402 | return;
|
---|
403 |
|
---|
404 | // Reset Histogram
|
---|
405 | fHAlphaTime.Reset();
|
---|
406 | fHAlphaTime.SetEntries(0);
|
---|
407 |
|
---|
408 | // Get number of bins
|
---|
409 | const Int_t n = fHTime.GetNbinsX();
|
---|
410 |
|
---|
411 | //
|
---|
412 | // Prepare Histogram
|
---|
413 | //
|
---|
414 | if (final)
|
---|
415 | time->Plus1ns();
|
---|
416 |
|
---|
417 | // Enhance binning
|
---|
418 | MBinning bins;
|
---|
419 | bins.SetEdges(fHTime, 'x');
|
---|
420 | bins.AddEdge(time->GetAxisTime());
|
---|
421 | bins.Apply(fHTime);
|
---|
422 |
|
---|
423 | //
|
---|
424 | // Fill histogram
|
---|
425 | //
|
---|
426 | fHTime.SetBinContent(n+1, fit.GetEventsExcess());
|
---|
427 | fHTime.SetBinError(n+1, fit.GetEventsExcess()*0.1);
|
---|
428 |
|
---|
429 | *fLog << all << *fTimeEffOn << ": " << fit.GetEventsExcess() << endl;
|
---|
430 |
|
---|
431 | rebin = steps;
|
---|
432 | }
|
---|
433 |
|
---|
434 | // --------------------------------------------------------------------------
|
---|
435 | //
|
---|
436 | // Fill the histogram. For details see the code or the class description
|
---|
437 | //
|
---|
438 | Bool_t MHAlpha::Fill(const MParContainer *par, const Stat_t w)
|
---|
439 | {
|
---|
440 | Double_t alpha, energy, theta;
|
---|
441 | Double_t size=-1;
|
---|
442 |
|
---|
443 | if (fMatrix)
|
---|
444 | {
|
---|
445 | alpha = (*fMatrix)[fMap[0]];
|
---|
446 | energy = fMap[1]<0 ? -1 : (*fMatrix)[fMap[1]];
|
---|
447 | size = fMap[2]<0 ? -1 : (*fMatrix)[fMap[2]];
|
---|
448 | //<0 ? 1000 : (*fMatrix)[fMap[1]];
|
---|
449 | theta = 0;
|
---|
450 |
|
---|
451 | if (energy<0)
|
---|
452 | energy=size;
|
---|
453 | if (size<0)
|
---|
454 | size=energy;
|
---|
455 |
|
---|
456 | if (energy<0 && size<0)
|
---|
457 | energy = size = 1000;
|
---|
458 | }
|
---|
459 | else
|
---|
460 | {
|
---|
461 | const MHillasSrc *hil = dynamic_cast<const MHillasSrc*>(par);
|
---|
462 | if (!par)
|
---|
463 | {
|
---|
464 | *fLog << err << dbginf << "MHillasSrc not found... abort." << endl;
|
---|
465 | return kFALSE;
|
---|
466 | }
|
---|
467 |
|
---|
468 | alpha = hil->GetAlpha();
|
---|
469 | if (fHillas)
|
---|
470 | size = fHillas->GetSize();
|
---|
471 | energy = fEnergy ? fEnergy->GetEnergy() : (fHillas?fHillas->GetSize():1000);
|
---|
472 | theta = fPointPos ? fPointPos->GetZd() : 0;
|
---|
473 | }
|
---|
474 |
|
---|
475 | // enhance histogram if necessary
|
---|
476 | UpdateAlphaTime();
|
---|
477 |
|
---|
478 | // Fill histograms
|
---|
479 | fHAlpha.Fill(theta, energy, TMath::Abs(alpha), w);
|
---|
480 |
|
---|
481 | // Check cuts
|
---|
482 | /*
|
---|
483 | if ( (fEnergyMin>=0 && energy<fEnergyMin) ||
|
---|
484 | (fEnergyMax>=0 && energy>fEnergyMax) ||
|
---|
485 | (fSizeMin>=0 && size <fSizeMin) ||
|
---|
486 | (fSizeMax>=0 && size >fSizeMin) )
|
---|
487 | return kTRUE;
|
---|
488 | */
|
---|
489 |
|
---|
490 | if (!fSkipHistTime)
|
---|
491 | fHAlphaTime.Fill(TMath::Abs(alpha), w);
|
---|
492 |
|
---|
493 | return kTRUE;
|
---|
494 | }
|
---|
495 |
|
---|
496 | // --------------------------------------------------------------------------
|
---|
497 | //
|
---|
498 | // Paint the integral and the error on top of the histogram
|
---|
499 | //
|
---|
500 | void MHAlpha::PaintText(Double_t val, Double_t error) const
|
---|
501 | {
|
---|
502 | TLatex text(0.45, 0.94, Form("N_{exc} = %.1f \\pm %.1f", val, error));
|
---|
503 | text.SetBit(TLatex::kTextNDC);
|
---|
504 | text.SetTextSize(0.04);
|
---|
505 | text.Paint();
|
---|
506 | }
|
---|
507 |
|
---|
508 | // --------------------------------------------------------------------------
|
---|
509 | //
|
---|
510 | // Update the projections
|
---|
511 | //
|
---|
512 | void MHAlpha::Paint(Option_t *opt)
|
---|
513 | {
|
---|
514 | // Note: Any object cannot be added to a pad twice!
|
---|
515 | // The object is searched by gROOT->FindObject only in
|
---|
516 | // gPad itself!
|
---|
517 | TVirtualPad *padsave = gPad;
|
---|
518 |
|
---|
519 | TH1D *h0=0;
|
---|
520 |
|
---|
521 | TString o(opt);
|
---|
522 | if (o==(TString)"proj")
|
---|
523 | {
|
---|
524 | TPaveStats *st=0;
|
---|
525 | for (int x=0; x<4; x++)
|
---|
526 | {
|
---|
527 | TVirtualPad *p=padsave->GetPad(x+1);
|
---|
528 | if (!p || !(st = (TPaveStats*)p->GetPrimitive("stats")))
|
---|
529 | continue;
|
---|
530 |
|
---|
531 | if (st->GetOptStat()==11)
|
---|
532 | continue;
|
---|
533 |
|
---|
534 | const Double_t y1 = st->GetY1NDC();
|
---|
535 | const Double_t y2 = st->GetY2NDC();
|
---|
536 | const Double_t x1 = st->GetX1NDC();
|
---|
537 | const Double_t x2 = st->GetX2NDC();
|
---|
538 |
|
---|
539 | st->SetY1NDC((y2-y1)/3+y1);
|
---|
540 | st->SetX1NDC((x2-x1)/3+x1);
|
---|
541 | st->SetOptStat(11);
|
---|
542 | }
|
---|
543 |
|
---|
544 | padsave->cd(1);
|
---|
545 | TH1D *hon = fHAlpha.ProjectionZ("ProjAlpha");
|
---|
546 | if (fOffData)
|
---|
547 | {
|
---|
548 | TH1D *hoff = fOffData->ProjectionZ("ProjAlphaOff");
|
---|
549 | fFit.Scale(*hoff, *hon);
|
---|
550 |
|
---|
551 | hon->SetMaximum();
|
---|
552 | hon->SetMaximum(TMath::Max(hon->GetMaximum(), hoff->GetMaximum())*1.05);
|
---|
553 |
|
---|
554 | if ((h0=(TH1D*)gPad->FindObject("ProjAlphaOnOff")))
|
---|
555 | {
|
---|
556 | h0->Reset();
|
---|
557 | h0->Add(hoff, hon, -1);
|
---|
558 | const Float_t min = h0->GetMinimum()*1.05;
|
---|
559 | hon->SetMinimum(min<0 ? min : 0);
|
---|
560 | }
|
---|
561 | }
|
---|
562 | FitEnergyBins();
|
---|
563 | FitThetaBins();
|
---|
564 | }
|
---|
565 |
|
---|
566 | if (o==(TString)"alpha")
|
---|
567 | if ((h0 = (TH1D*)gPad->FindObject("ProjAlpha")))
|
---|
568 | {
|
---|
569 | // Do not store the 'final' result in fFit
|
---|
570 | MAlphaFitter fit(fFit);
|
---|
571 | TH1D *hoff = (TH1D*)gPad->FindObject("ProjAlphaOff");
|
---|
572 | fit.Fit(*h0, hoff, kTRUE);
|
---|
573 | fit.PaintResult();
|
---|
574 | }
|
---|
575 |
|
---|
576 | if (o==(TString)"time")
|
---|
577 | PaintText(fHTime.Integral(), 0);
|
---|
578 |
|
---|
579 | if (o==(TString)"theta")
|
---|
580 | {
|
---|
581 | TH1 *h = (TH1*)gPad->FindObject("Alpha_x");
|
---|
582 | if (h)
|
---|
583 | {
|
---|
584 | TH1D *h2 = (TH1D*)fHAlpha.Project3D("dum_x");
|
---|
585 | h2->SetDirectory(0);
|
---|
586 | h2->Scale(fHTheta.Integral()/h2->Integral());
|
---|
587 | h->Reset();
|
---|
588 | h->Add(h2);
|
---|
589 | delete h2;
|
---|
590 | }
|
---|
591 | PaintText(fHTheta.Integral(), 0);
|
---|
592 | }
|
---|
593 |
|
---|
594 | if (o==(TString)"energy")
|
---|
595 | {
|
---|
596 | TH1 *h = (TH1*)gPad->FindObject("Alpha_y");
|
---|
597 | if (h)
|
---|
598 | {
|
---|
599 | TH1D *h2 = (TH1D*)fHAlpha.Project3D("dum_y");
|
---|
600 | h2->SetDirectory(0);
|
---|
601 | h2->Scale(fHEnergy.Integral()/h2->Integral());
|
---|
602 | h->Reset();
|
---|
603 | h->Add(h2);
|
---|
604 | delete h2;
|
---|
605 | }
|
---|
606 |
|
---|
607 | if (fHEnergy.GetMaximum()>1)
|
---|
608 | {
|
---|
609 | gPad->SetLogx();
|
---|
610 | gPad->SetLogy();
|
---|
611 | }
|
---|
612 | FitEnergySpec(kTRUE);
|
---|
613 | }
|
---|
614 |
|
---|
615 | gPad = padsave;
|
---|
616 | }
|
---|
617 |
|
---|
618 | // --------------------------------------------------------------------------
|
---|
619 | //
|
---|
620 | // Draw the histogram
|
---|
621 | //
|
---|
622 | void MHAlpha::Draw(Option_t *opt)
|
---|
623 | {
|
---|
624 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
---|
625 |
|
---|
626 | // Do the projection before painting the histograms into
|
---|
627 | // the individual pads
|
---|
628 | AppendPad("proj");
|
---|
629 |
|
---|
630 | pad->SetBorderMode(0);
|
---|
631 | pad->Divide(2,2);
|
---|
632 |
|
---|
633 | TH1D *h=0;
|
---|
634 |
|
---|
635 | pad->cd(1);
|
---|
636 | gPad->SetBorderMode(0);
|
---|
637 |
|
---|
638 | h = fHAlpha.ProjectionZ("ProjAlpha", -1, 9999, -1, 9999, "E");
|
---|
639 | h->SetBit(TH1::kNoTitle);
|
---|
640 | h->SetStats(kTRUE);
|
---|
641 | h->SetXTitle("\\alpha [\\circ]");
|
---|
642 | h->SetYTitle("Counts");
|
---|
643 | h->SetDirectory(NULL);
|
---|
644 | h->SetMarkerStyle(kFullDotMedium);
|
---|
645 | h->SetBit(kCanDelete);
|
---|
646 | h->Draw("");
|
---|
647 |
|
---|
648 | if (fOffData)
|
---|
649 | {
|
---|
650 | h->SetMarkerColor(kGreen);
|
---|
651 |
|
---|
652 | h = fOffData->ProjectionZ("ProjAlphaOff", -1, 9999, -1, 9999, "E");
|
---|
653 | h->SetBit(TH1::kNoTitle);
|
---|
654 | h->SetXTitle("\\alpha [\\circ]");
|
---|
655 | h->SetYTitle("Counts");
|
---|
656 | h->SetDirectory(NULL);
|
---|
657 | h->SetMarkerStyle(kFullDotMedium);
|
---|
658 | h->SetBit(kCanDelete);
|
---|
659 | h->SetMarkerColor(kRed);
|
---|
660 | h->Draw("same");
|
---|
661 |
|
---|
662 | h = (TH1D*)h->Clone("ProjAlphaOnOff");
|
---|
663 | h->SetBit(TH1::kNoTitle);
|
---|
664 | h->SetXTitle("\\alpha [\\circ]");
|
---|
665 | h->SetYTitle("Counts");
|
---|
666 | h->SetDirectory(NULL);
|
---|
667 | h->SetMarkerStyle(kFullDotMedium);
|
---|
668 | h->SetBit(kCanDelete);
|
---|
669 | h->SetMarkerColor(kBlue);
|
---|
670 | h->Draw("same");
|
---|
671 |
|
---|
672 | TLine lin;
|
---|
673 | lin.SetLineStyle(kDashed);
|
---|
674 | lin.DrawLine(0, 0, 90, 0);
|
---|
675 | }
|
---|
676 |
|
---|
677 | // After the Alpha-projection has been drawn. Fit the histogram
|
---|
678 | // and paint the result into this pad
|
---|
679 | AppendPad("alpha");
|
---|
680 |
|
---|
681 | if (fHEnergy.GetNbinsX()>1)
|
---|
682 | {
|
---|
683 | pad->cd(2);
|
---|
684 | gPad->SetBorderMode(0);
|
---|
685 | fHEnergy.Draw();
|
---|
686 |
|
---|
687 | AppendPad("energy");
|
---|
688 |
|
---|
689 | h = (TH1D*)fHAlpha.Project3D("y");
|
---|
690 | h->SetBit(TH1::kNoTitle|TH1::kNoStats);
|
---|
691 | h->SetXTitle("E [GeV]");
|
---|
692 | h->SetYTitle("Counts");
|
---|
693 | h->SetDirectory(NULL);
|
---|
694 | h->SetMarkerStyle(kFullDotMedium);
|
---|
695 | h->SetBit(kCanDelete);
|
---|
696 | h->SetMarkerColor(kCyan);
|
---|
697 | h->SetLineColor(kCyan);
|
---|
698 | h->Draw("Psame");
|
---|
699 | }
|
---|
700 | else
|
---|
701 | delete pad->GetPad(2);
|
---|
702 |
|
---|
703 | if (fTimeEffOn && fTime || fHTime.GetNbinsX()>1)
|
---|
704 | {
|
---|
705 | pad->cd(3);
|
---|
706 | gPad->SetBorderMode(0);
|
---|
707 | fHTime.Draw();
|
---|
708 | AppendPad("time");
|
---|
709 | }
|
---|
710 | else
|
---|
711 | delete pad->GetPad(3);
|
---|
712 |
|
---|
713 | if (fHTheta.GetNbinsX()>1)
|
---|
714 | {
|
---|
715 | pad->cd(4);
|
---|
716 | gPad->SetBorderMode(0);
|
---|
717 | fHTheta.Draw();
|
---|
718 |
|
---|
719 | AppendPad("theta");
|
---|
720 |
|
---|
721 | h = (TH1D*)fHAlpha.Project3D("x");
|
---|
722 | h->SetBit(TH1::kNoTitle|TH1::kNoStats);
|
---|
723 | h->SetXTitle("\\theta [\\circ]");
|
---|
724 | h->SetYTitle("Counts");
|
---|
725 | h->SetDirectory(NULL);
|
---|
726 | h->SetMarkerStyle(kFullDotMedium);
|
---|
727 | h->SetBit(kCanDelete);
|
---|
728 | h->SetMarkerColor(kCyan);
|
---|
729 | h->SetLineColor(kCyan);
|
---|
730 | h->Draw("Psame");
|
---|
731 | }
|
---|
732 | else
|
---|
733 | delete pad->GetPad(4);
|
---|
734 | }
|
---|
735 |
|
---|
736 | void MHAlpha::DrawAll()
|
---|
737 | {
|
---|
738 | // FIXME: Do in Paint if special option given!
|
---|
739 | TCanvas *c = new TCanvas;
|
---|
740 | Int_t n = fHAlpha.GetNbinsY();
|
---|
741 | Int_t nc = (Int_t)(TMath::Sqrt((Float_t)n-1)+1);
|
---|
742 | c->Divide(nc, nc, 0, 0);
|
---|
743 |
|
---|
744 | // Do not store the 'final' result in fFit
|
---|
745 | MAlphaFitter fit(fFit);
|
---|
746 |
|
---|
747 | for (int i=1; i<=fHAlpha.GetNbinsY(); i++)
|
---|
748 | {
|
---|
749 | c->cd(i);
|
---|
750 |
|
---|
751 | TH1D *hon = fHAlpha.ProjectionZ("ProjAlpha", -1, 9999, i, i, "E");
|
---|
752 | hon->SetBit(TH1::kNoTitle);
|
---|
753 | hon->SetStats(kTRUE);
|
---|
754 | hon->SetXTitle("\\alpha [\\circ]");
|
---|
755 | hon->SetYTitle("Counts");
|
---|
756 | hon->SetDirectory(NULL);
|
---|
757 | hon->SetMarkerStyle(kFullDotMedium);
|
---|
758 | hon->SetBit(kCanDelete);
|
---|
759 | hon->Draw("");
|
---|
760 |
|
---|
761 | TH1D *hof = 0;
|
---|
762 |
|
---|
763 | if (fOffData)
|
---|
764 | {
|
---|
765 | hon->SetMarkerColor(kGreen);
|
---|
766 |
|
---|
767 | hof = fOffData->ProjectionZ("ProjAlphaOff", -1, 9999, i, i, "E");
|
---|
768 | hof->SetBit(TH1::kNoTitle|TH1::kNoStats);
|
---|
769 | hof->SetXTitle("\\alpha [\\circ]");
|
---|
770 | hof->SetYTitle("Counts");
|
---|
771 | hof->SetDirectory(NULL);
|
---|
772 | hof->SetMarkerStyle(kFullDotMedium);
|
---|
773 | hof->SetBit(kCanDelete);
|
---|
774 | hof->SetMarkerColor(kRed);
|
---|
775 | hof->Draw("same");
|
---|
776 |
|
---|
777 | fit.Scale(*hof, *hon);
|
---|
778 |
|
---|
779 | hon->SetMaximum();
|
---|
780 | hon->SetMaximum(TMath::Max(hon->GetMaximum(), hof->GetMaximum())*1.05);
|
---|
781 |
|
---|
782 | TH1D *diff = new TH1D(*hon);
|
---|
783 | diff->Add(hof, -1);
|
---|
784 | diff->SetBit(TH1::kNoTitle);
|
---|
785 | diff->SetXTitle("\\alpha [\\circ]");
|
---|
786 | diff->SetYTitle("Counts");
|
---|
787 | diff->SetDirectory(NULL);
|
---|
788 | diff->SetMarkerStyle(kFullDotMedium);
|
---|
789 | diff->SetBit(kCanDelete);
|
---|
790 | diff->SetMarkerColor(kBlue);
|
---|
791 | diff->Draw("same");
|
---|
792 |
|
---|
793 | TLine lin;
|
---|
794 | lin.SetLineStyle(kDashed);
|
---|
795 | lin.DrawLine(0, 0, 90, 0);
|
---|
796 |
|
---|
797 | const Float_t min = diff->GetMinimum()*1.05;
|
---|
798 | hon->SetMinimum(min<0 ? min : 0);
|
---|
799 | }
|
---|
800 |
|
---|
801 | if (hof ? fit.Fit(*hon, *hof) : fit.Fit(*hon))
|
---|
802 | *fLog << dbg << "Bin " << i << ": sigma=" << fit.GetSignificance() << " omega=" << fit.GetGausSigma() << " events=" << fit.GetEventsExcess() << endl;
|
---|
803 | /*
|
---|
804 | if (fit.FitEnergy(fHAlpha, fOffData, i, kTRUE))
|
---|
805 | {
|
---|
806 | fHEnergy.SetBinContent(i, fit.GetEventsExcess());
|
---|
807 | fHEnergy.SetBinError(i, fit.GetEventsExcess()*0.2);
|
---|
808 | }*/
|
---|
809 | }
|
---|
810 |
|
---|
811 | }
|
---|
812 |
|
---|
813 |
|
---|
814 | Bool_t MHAlpha::Finalize()
|
---|
815 | {
|
---|
816 | //TH1D *h = fHAlpha.ProjectionZ("AlphaExc_px", -1, 9999, -1, 9999, "E");
|
---|
817 | //h->SetDirectory(0);
|
---|
818 | //Bool_t rc = fFit.Fit(*h);
|
---|
819 | //delete h;
|
---|
820 | if (!fFit.FitAlpha(fHAlpha, fOffData))
|
---|
821 | {
|
---|
822 | *fLog << warn << "Histogram empty." << endl;
|
---|
823 | return kTRUE;
|
---|
824 | }
|
---|
825 |
|
---|
826 | // Store the final result in fFit
|
---|
827 | fFit.Print("result");
|
---|
828 |
|
---|
829 | if (fResult)
|
---|
830 | fResult->SetVal(fFit.GetSignificance());
|
---|
831 |
|
---|
832 | if (!fSkipHistEnergy)
|
---|
833 | {
|
---|
834 | *fLog << inf << "Processing energy bins..." << endl;
|
---|
835 | FitEnergyBins();
|
---|
836 | }
|
---|
837 | if (!fSkipHistTheta)
|
---|
838 | {
|
---|
839 | *fLog << inf << "Processing theta bins..." << endl;
|
---|
840 | FitThetaBins();
|
---|
841 | }
|
---|
842 | if (!fSkipHistTime)
|
---|
843 | {
|
---|
844 | *fLog << inf << "Processing time bins..." << endl;
|
---|
845 | UpdateAlphaTime(kTRUE);
|
---|
846 | MH::RemoveFirstBin(fHTime);
|
---|
847 | }
|
---|
848 |
|
---|
849 | return kTRUE;
|
---|
850 | }
|
---|
851 |
|
---|
852 | // --------------------------------------------------------------------------
|
---|
853 | //
|
---|
854 | // You can use this function if you want to use a MHMatrix instead of
|
---|
855 | // MMcEvt. This function adds all necessary columns to the
|
---|
856 | // given matrix. Afterward you should fill the matrix with the corresponding
|
---|
857 | // data (eg from a file by using MHMatrix::Fill). If you now loop
|
---|
858 | // through the matrix (eg using MMatrixLoop) MHHadronness::Fill
|
---|
859 | // will take the values from the matrix instead of the containers.
|
---|
860 | //
|
---|
861 | // It takes fSkipHist* into account!
|
---|
862 | //
|
---|
863 | void MHAlpha::InitMapping(MHMatrix *mat, Int_t type)
|
---|
864 | {
|
---|
865 | if (fMatrix)
|
---|
866 | return;
|
---|
867 |
|
---|
868 | fMatrix = mat;
|
---|
869 |
|
---|
870 | fMap[0] = fMatrix->AddColumn("MHillasSrc.fAlpha");
|
---|
871 | fMap[1] = -1;
|
---|
872 | fMap[2] = -1;
|
---|
873 | fMap[3] = -1;
|
---|
874 | fMap[4] = -1;
|
---|
875 |
|
---|
876 | if (!fSkipHistEnergy)
|
---|
877 | if (type==0)
|
---|
878 | {
|
---|
879 | fMap[1] = fMatrix->AddColumn("MEnergyEst.fEnergy");
|
---|
880 | fMap[2] = -1;
|
---|
881 | }
|
---|
882 | else
|
---|
883 | {
|
---|
884 | fMap[1] = -1;
|
---|
885 | fMap[2] = fMatrix->AddColumn("MHillas.fSize");
|
---|
886 | }
|
---|
887 |
|
---|
888 | if (!fSkipHistTheta)
|
---|
889 | fMap[3] = fMatrix->AddColumn("MPointingPos.fZd");
|
---|
890 |
|
---|
891 | // if (!fSkipHistTime)
|
---|
892 | // fMap[4] = fMatrix->AddColumn("MTime.GetAxisTime");
|
---|
893 | }
|
---|
894 |
|
---|
895 | void MHAlpha::StopMapping()
|
---|
896 | {
|
---|
897 | fMatrix = NULL;
|
---|
898 | }
|
---|