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 | // ToDo:
|
---|
40 | // =====
|
---|
41 | //
|
---|
42 | // - Replace time-binning by histogram (which is enhanced bin-wise)
|
---|
43 | //
|
---|
44 | //
|
---|
45 | //////////////////////////////////////////////////////////////////////////////
|
---|
46 | #include "MHAlpha.h"
|
---|
47 |
|
---|
48 | #include <TF1.h>
|
---|
49 | #include <TGraph.h>
|
---|
50 | #include <TStyle.h>
|
---|
51 | #include <TLatex.h>
|
---|
52 | #include <TCanvas.h>
|
---|
53 | #include <TPaveStats.h>
|
---|
54 | #include <TStopwatch.h>
|
---|
55 |
|
---|
56 | #include "MGeomCam.h"
|
---|
57 | #include "MSrcPosCam.h"
|
---|
58 | #include "MHillasSrc.h"
|
---|
59 | #include "MEnergyEst.h"
|
---|
60 | #include "MTime.h"
|
---|
61 | #include "MObservatory.h"
|
---|
62 | #include "MPointingPos.h"
|
---|
63 | #include "MAstroSky2Local.h"
|
---|
64 | #include "MStatusDisplay.h"
|
---|
65 | #include "MParameters.h"
|
---|
66 | #include "MHMatrix.h"
|
---|
67 |
|
---|
68 | #include "MBinning.h"
|
---|
69 | #include "MParList.h"
|
---|
70 |
|
---|
71 | #include "MLog.h"
|
---|
72 | #include "MLogManip.h"
|
---|
73 |
|
---|
74 | ClassImp(MHAlpha);
|
---|
75 | ClassImp(MAlphaFitter);
|
---|
76 |
|
---|
77 | using namespace std;
|
---|
78 |
|
---|
79 | // --------------------------------------------------------------------------
|
---|
80 | //
|
---|
81 | // Default Constructor
|
---|
82 | //
|
---|
83 | MHAlpha::MHAlpha(const char *name, const char *title)
|
---|
84 | : fOffData(0), fResult(0), /*fExcess(0),*/ fEnergy(0), fHillas(0),
|
---|
85 | fPointPos(0), fTimeEffOn(0), fTime(0),
|
---|
86 | fSkipHistTime(kFALSE), fSkipHistTheta(kFALSE), fSkipHistEnergy(kFALSE),
|
---|
87 | fNumTimeBins(10), fMatrix(0)
|
---|
88 | {
|
---|
89 | //
|
---|
90 | // set the name and title of this object
|
---|
91 | //
|
---|
92 | fName = name ? name : "MHAlpha";
|
---|
93 | fTitle = title ? title : "Alpha plot";
|
---|
94 |
|
---|
95 | fHAlpha.SetName("Alpha");
|
---|
96 | fHAlpha.SetTitle("Alpha");
|
---|
97 | fHAlpha.SetXTitle("\\Theta [deg]");
|
---|
98 | fHAlpha.SetYTitle("E_{est} [GeV]");
|
---|
99 | fHAlpha.SetZTitle("|\\alpha| [\\circ]");
|
---|
100 | fHAlpha.SetDirectory(NULL);
|
---|
101 | fHAlpha.UseCurrentStyle();
|
---|
102 |
|
---|
103 | // Main histogram
|
---|
104 | fHAlphaTime.SetName("Alpha");
|
---|
105 | fHAlphaTime.SetXTitle("|\\alpha| [\\circ]");
|
---|
106 | fHAlphaTime.SetYTitle("Counts");
|
---|
107 | fHAlphaTime.UseCurrentStyle();
|
---|
108 | fHAlphaTime.SetDirectory(NULL);
|
---|
109 |
|
---|
110 |
|
---|
111 | //fHEnergy.SetName("Energy");
|
---|
112 | //fHEnergy.SetTitle(" N_{exc} vs. E_{est} ");
|
---|
113 | //fHEnergy.SetXTitle("E_{est} [GeV]");
|
---|
114 | fHEnergy.SetYTitle("N_{exc}");
|
---|
115 | fHEnergy.SetDirectory(NULL);
|
---|
116 | fHEnergy.UseCurrentStyle();
|
---|
117 |
|
---|
118 | fHTheta.SetName("Theta");
|
---|
119 | fHTheta.SetTitle(" N_{exc} vs. \\Theta ");
|
---|
120 | fHTheta.SetXTitle("\\Theta [\\circ]");
|
---|
121 | fHTheta.SetYTitle("N_{exc}");
|
---|
122 | fHTheta.SetDirectory(NULL);
|
---|
123 | fHTheta.UseCurrentStyle();
|
---|
124 |
|
---|
125 | // effective on time versus time
|
---|
126 | fHTime.SetName("Time");
|
---|
127 | fHTime.SetTitle(" N_{exc} vs. Time ");
|
---|
128 | fHTime.SetXTitle("Time");
|
---|
129 | fHTime.SetYTitle("N_{exc} [s]");
|
---|
130 | fHTime.UseCurrentStyle();
|
---|
131 | fHTime.SetDirectory(NULL);
|
---|
132 | fHTime.GetYaxis()->SetTitleOffset(1.2);
|
---|
133 | fHTime.GetXaxis()->SetLabelSize(0.033);
|
---|
134 | fHTime.GetXaxis()->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
|
---|
135 | fHTime.GetXaxis()->SetTimeDisplay(1);
|
---|
136 | fHTime.Sumw2();
|
---|
137 |
|
---|
138 | MBinning binsa, binse, binst;
|
---|
139 | binsa.SetEdges(18, 0, 90);
|
---|
140 | binse.SetEdgesLog(25, 10, 100000);
|
---|
141 | binst.SetEdgesCos(50, 0, 60);
|
---|
142 | binse.Apply(fHEnergy);
|
---|
143 | binst.Apply(fHTheta);
|
---|
144 | binsa.Apply(fHAlphaTime);
|
---|
145 |
|
---|
146 | MH::SetBinning(&fHAlpha, &binst, &binse, &binsa);
|
---|
147 | }
|
---|
148 |
|
---|
149 | void MHAlpha::FitEnergySpec(Bool_t paint)
|
---|
150 | {
|
---|
151 | /*
|
---|
152 | TF1 f("Spectrum", "pow(x, [0])*exp(-x/[1])*[2]*x");//
|
---|
153 | f.SetParameter(0, -2.1);
|
---|
154 | f.SetParameter(1, 1400); // 50
|
---|
155 | f.SetParameter(2, fHEnergy.Integral()); // 50
|
---|
156 | f.SetLineWidth(2);
|
---|
157 |
|
---|
158 | fHEnergy.Fit(&f, "0QI", "", 100, 2400); // Integral? 90, 2800
|
---|
159 |
|
---|
160 | const Double_t chi2 = f.GetChisquare();
|
---|
161 | const Int_t NDF = f.GetNDF();
|
---|
162 |
|
---|
163 | // was fit successful ?
|
---|
164 | const Bool_t ok = NDF>0 && chi2<2.5*NDF;
|
---|
165 | f.SetLineColor(ok ? kGreen : kRed);
|
---|
166 |
|
---|
167 | if (paint)
|
---|
168 | {
|
---|
169 | f.Paint("same");
|
---|
170 |
|
---|
171 | if (ok)
|
---|
172 | {
|
---|
173 | TString s;
|
---|
174 | s += Form("\\alpha=%.1f ", f.GetParameter(0));
|
---|
175 | s += Form("E_{c}=%.1f TeV ", f.GetParameter(1)/1000);
|
---|
176 | s += Form("N=%.1e", f.GetParameter(2));
|
---|
177 |
|
---|
178 | TLatex text(0.25, 0.94, s.Data());
|
---|
179 | text.SetBit(TLatex::kTextNDC);
|
---|
180 | text.SetTextSize(0.04);
|
---|
181 | text.Paint();
|
---|
182 | }
|
---|
183 | }*/
|
---|
184 | }
|
---|
185 |
|
---|
186 | void MHAlpha::FitEnergyBins(Bool_t paint)
|
---|
187 | {
|
---|
188 | // Do not store the 'final' result in fFit
|
---|
189 | MAlphaFitter fit(fFit);
|
---|
190 |
|
---|
191 | const Int_t n = fHAlpha.GetNbinsY();
|
---|
192 |
|
---|
193 | fHEnergy.SetEntries(0);
|
---|
194 |
|
---|
195 | for (int i=1; i<=n; i++)
|
---|
196 | {
|
---|
197 | if (fit.FitEnergy(fHAlpha, fOffData, i))
|
---|
198 | {
|
---|
199 | fHEnergy.SetBinContent(i, fit.GetEventsExcess());
|
---|
200 | fHEnergy.SetBinError(i, fit.GetEventsExcess()*0.2);
|
---|
201 | }
|
---|
202 | }
|
---|
203 | }
|
---|
204 |
|
---|
205 | void MHAlpha::FitThetaBins(Bool_t paint)
|
---|
206 | {
|
---|
207 | // Do not store the 'final' result in fFit
|
---|
208 | MAlphaFitter fit(fFit);
|
---|
209 |
|
---|
210 | const Int_t n = fHAlpha.GetNbinsX();
|
---|
211 |
|
---|
212 | fHTheta.SetEntries(0);
|
---|
213 |
|
---|
214 | for (int i=1; i<=n; i++)
|
---|
215 | {
|
---|
216 | if (fit.FitTheta(fHAlpha, fOffData, i))
|
---|
217 | {
|
---|
218 | fHTheta.SetBinContent(i, fit.GetEventsExcess());
|
---|
219 | fHTheta.SetBinError(i, fit.GetEventsExcess()*0.2);
|
---|
220 | }
|
---|
221 | }
|
---|
222 | }
|
---|
223 |
|
---|
224 | Bool_t MHAlpha::SetupFill(const MParList *pl)
|
---|
225 | {
|
---|
226 | fHAlpha.Reset();
|
---|
227 | fHEnergy.Reset();
|
---|
228 | fHTheta.Reset();
|
---|
229 | fHTime.Reset();
|
---|
230 |
|
---|
231 | if (fName!=(TString)"MHAlphaOff" && fOffData==NULL)
|
---|
232 | {
|
---|
233 | MHAlpha *hoff = (MHAlpha*)pl->FindObject("MHAlphaOff", "MHAlpha");
|
---|
234 | if (!hoff)
|
---|
235 | *fLog << inf << "No MHAlphaOff [MHAlpha] found... using current data only!" << endl;
|
---|
236 | else
|
---|
237 | {
|
---|
238 | *fLog << inf << "MHAlphaOff [MHAlpha] found... using on-off mode!" << endl;
|
---|
239 | SetOffData(*hoff);
|
---|
240 | }
|
---|
241 | }
|
---|
242 |
|
---|
243 | fHillas = 0;
|
---|
244 | /*
|
---|
245 | if (fSizeMin>=0 || fSizeMax>=0)
|
---|
246 | {
|
---|
247 | fHillas = (MHillas*)pl->FindObject("MHillas");
|
---|
248 | if (!fHillas)
|
---|
249 | {
|
---|
250 | *fLog << warn << "Size cut set, but MHillas not found... abort." << endl;
|
---|
251 | return kFALSE;
|
---|
252 | }
|
---|
253 | }
|
---|
254 | */
|
---|
255 | fEnergy = (MEnergyEst*)pl->FindObject("MEnergyEst");
|
---|
256 | if (!fEnergy)
|
---|
257 | { /*
|
---|
258 | if (fEnergyMin>=0 || fEnergyMax>=0)
|
---|
259 | {
|
---|
260 | *fLog << warn << "Energy cut set, but MEnergyEst not found... abort." << endl;
|
---|
261 | return kFALSE;
|
---|
262 | } */
|
---|
263 |
|
---|
264 | *fLog << warn << "MEnergyEst not found... " << flush;
|
---|
265 |
|
---|
266 | if (!fHillas)
|
---|
267 | fHillas = (MHillas*)pl->FindObject("MHillas");
|
---|
268 | if (fHillas)
|
---|
269 | *fLog << "using SIZE instead!" << endl;
|
---|
270 | else
|
---|
271 | *fLog << "ignored." << endl;
|
---|
272 |
|
---|
273 | fHEnergy.SetName("Size");
|
---|
274 | fHEnergy.SetTitle(" N_{exc} vs. Size ");
|
---|
275 | fHEnergy.SetXTitle("Size [\\gamma]");
|
---|
276 | }
|
---|
277 | else
|
---|
278 | {
|
---|
279 | fHEnergy.SetName("Energy");
|
---|
280 | fHEnergy.SetTitle(" N_{exc} vs. E_{est} ");
|
---|
281 | fHEnergy.SetXTitle("E_{est} [GeV]");
|
---|
282 | }
|
---|
283 |
|
---|
284 | fPointPos = (MPointingPos*)pl->FindObject("MPointingPos");
|
---|
285 | if (!fPointPos)
|
---|
286 | *fLog << warn << "MPointingPos not found... ignored." << endl;
|
---|
287 |
|
---|
288 | fTimeEffOn = (MTime*)pl->FindObject("MTimeEffectiveOnTime", "MTime");
|
---|
289 | if (!fTimeEffOn)
|
---|
290 | *fLog << warn << "MTimeEffectiveOnTime [MTime] not found... ignored." << endl;
|
---|
291 | else
|
---|
292 | *fTimeEffOn = MTime(); // FIXME: How to do it different?
|
---|
293 |
|
---|
294 | fTime = (MTime*)pl->FindObject("MTime");
|
---|
295 | if (!fTime)
|
---|
296 | *fLog << warn << "MTime not found... ignored." << endl;
|
---|
297 |
|
---|
298 | fResult = (MParameterD*)const_cast<MParList*>(pl)->FindCreateObj("MParameterD", "MinimizationValue");
|
---|
299 | if (!fResult)
|
---|
300 | return kFALSE;
|
---|
301 |
|
---|
302 | //fExcess = (MParameterD*)const_cast<MParList*>(pl)->FindCreateObj("MParameterD", "MExcess");
|
---|
303 | //if (!fExcess)
|
---|
304 | // return kFALSE;
|
---|
305 |
|
---|
306 | fLastTime = MTime();
|
---|
307 | fNumRebin = fNumTimeBins;
|
---|
308 |
|
---|
309 | MBinning binst, binse, binsa;
|
---|
310 | binst.SetEdges(fOffData ? *fOffData : fHAlpha, 'x');
|
---|
311 | binse.SetEdges(fOffData ? *fOffData : fHAlpha, 'y');
|
---|
312 | binsa.SetEdges(fOffData ? *fOffData : fHAlpha, 'z');
|
---|
313 |
|
---|
314 | if (!fOffData)
|
---|
315 | {
|
---|
316 | if (!fPointPos)
|
---|
317 | binst.SetEdges(1, 0, 60);
|
---|
318 | else
|
---|
319 | binst.SetEdges(*pl, "BinningTheta");
|
---|
320 |
|
---|
321 | if (!fEnergy && !fHillas)
|
---|
322 | binse.SetEdges(1, 10, 100000);
|
---|
323 | else
|
---|
324 | binse.SetEdges(*pl, "BinningEnergyEst");
|
---|
325 |
|
---|
326 | binsa.SetEdges(*pl, "BinningAlpha");
|
---|
327 | }
|
---|
328 |
|
---|
329 | binse.Apply(fHEnergy);
|
---|
330 | binst.Apply(fHTheta);
|
---|
331 | binsa.Apply(fHAlphaTime);
|
---|
332 | MH::SetBinning(&fHAlpha, &binst, &binse, &binsa);
|
---|
333 |
|
---|
334 | MAlphaFitter *fit = (MAlphaFitter*)pl->FindObject("MAlphaFitter");
|
---|
335 | if (!fit)
|
---|
336 | *fLog << warn << "MAlphaFitter not found... ignored." << endl;
|
---|
337 | else
|
---|
338 | fit->Copy(fFit);
|
---|
339 |
|
---|
340 | fFit.Print();
|
---|
341 |
|
---|
342 | return kTRUE;
|
---|
343 | }
|
---|
344 |
|
---|
345 | void MHAlpha::InitAlphaTime(const MTime &t)
|
---|
346 | {
|
---|
347 | //
|
---|
348 | // If this is the first call we have to initialize the time-histogram
|
---|
349 | //
|
---|
350 | MBinning bins;
|
---|
351 | bins.SetEdges(1, t.GetAxisTime()-60, t.GetAxisTime());
|
---|
352 | bins.Apply(fHTime);
|
---|
353 |
|
---|
354 | fLastTime=t;
|
---|
355 | }
|
---|
356 |
|
---|
357 | void MHAlpha::UpdateAlphaTime(Bool_t final)
|
---|
358 | {
|
---|
359 | if (!fTimeEffOn)
|
---|
360 | return;
|
---|
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 | fNumRebin--;
|
---|
374 | }
|
---|
375 |
|
---|
376 | if (fNumRebin>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 | fNumRebin++;
|
---|
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.ScaleAndFit(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 | fNumRebin = fNumTimeBins;
|
---|
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 | const Double_t alpha = fFit.Scale(*hoff, *hon);
|
---|
550 |
|
---|
551 | hon->SetMaximum();
|
---|
552 | hon->SetMaximum(TMath::Max(hon->GetMaximum(), hoff->GetMaximum())*1.05);
|
---|
553 |
|
---|
554 | // BE CARFEULL: This is a really weird workaround!
|
---|
555 | hoff->SetMaximum(alpha);
|
---|
556 |
|
---|
557 | if ((h0=(TH1D*)gPad->FindObject("ProjAlphaOnOff")))
|
---|
558 | {
|
---|
559 | h0->Reset();
|
---|
560 | h0->Add(hoff, hon, -1);
|
---|
561 | const Float_t min = h0->GetMinimum()*1.05;
|
---|
562 | hon->SetMinimum(min<0 ? min : 0);
|
---|
563 | }
|
---|
564 | }
|
---|
565 | FitEnergyBins();
|
---|
566 | FitThetaBins();
|
---|
567 | }
|
---|
568 |
|
---|
569 | if (o==(TString)"alpha")
|
---|
570 | if ((h0 = (TH1D*)gPad->FindObject("ProjAlpha")))
|
---|
571 | {
|
---|
572 | // Check whether we are dealing with on-off analysis
|
---|
573 | TH1D *hoff = (TH1D*)gPad->FindObject("ProjAlphaOff");
|
---|
574 |
|
---|
575 | // BE CARFEULL: This is a really weird workaround!
|
---|
576 | const Double_t scale = !hoff || hoff->GetMaximum()<0 ? 1 : hoff->GetMaximum();
|
---|
577 |
|
---|
578 | // Do not store the 'final' result in fFit
|
---|
579 | MAlphaFitter fit(fFit);
|
---|
580 | fit.Fit(*h0, hoff, scale, kTRUE);
|
---|
581 | fit.PaintResult();
|
---|
582 | }
|
---|
583 |
|
---|
584 | if (o==(TString)"time")
|
---|
585 | PaintText(fHTime.Integral(), 0);
|
---|
586 |
|
---|
587 | if (o==(TString)"theta")
|
---|
588 | {
|
---|
589 | TH1 *h = (TH1*)gPad->FindObject("Alpha_x");
|
---|
590 | if (h)
|
---|
591 | {
|
---|
592 | TH1D *h2 = (TH1D*)fHAlpha.Project3D("dum_x");
|
---|
593 | h2->SetDirectory(0);
|
---|
594 | h2->Scale(fHTheta.Integral()/h2->Integral());
|
---|
595 | h->Reset();
|
---|
596 | h->Add(h2);
|
---|
597 | delete h2;
|
---|
598 | }
|
---|
599 | PaintText(fHTheta.Integral(), 0);
|
---|
600 | }
|
---|
601 |
|
---|
602 | if (o==(TString)"energy")
|
---|
603 | {
|
---|
604 | TH1 *h = (TH1*)gPad->FindObject("Alpha_y");
|
---|
605 | if (h)
|
---|
606 | {
|
---|
607 | TH1D *h2 = (TH1D*)fHAlpha.Project3D("dum_y");
|
---|
608 | h2->SetDirectory(0);
|
---|
609 | h2->Scale(fHEnergy.Integral()/h2->Integral());
|
---|
610 | h->Reset();
|
---|
611 | h->Add(h2);
|
---|
612 | delete h2;
|
---|
613 | }
|
---|
614 |
|
---|
615 | if (fHEnergy.GetMaximum()>1)
|
---|
616 | {
|
---|
617 | gPad->SetLogx();
|
---|
618 | gPad->SetLogy();
|
---|
619 | }
|
---|
620 | FitEnergySpec(kTRUE);
|
---|
621 | }
|
---|
622 |
|
---|
623 | gPad = padsave;
|
---|
624 | }
|
---|
625 |
|
---|
626 | // --------------------------------------------------------------------------
|
---|
627 | //
|
---|
628 | // Draw the histogram
|
---|
629 | //
|
---|
630 | void MHAlpha::Draw(Option_t *opt)
|
---|
631 | {
|
---|
632 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
---|
633 |
|
---|
634 | // Do the projection before painting the histograms into
|
---|
635 | // the individual pads
|
---|
636 | AppendPad("proj");
|
---|
637 |
|
---|
638 | pad->SetBorderMode(0);
|
---|
639 | pad->Divide(2,2);
|
---|
640 |
|
---|
641 | TH1D *h=0;
|
---|
642 |
|
---|
643 | pad->cd(1);
|
---|
644 | gPad->SetBorderMode(0);
|
---|
645 |
|
---|
646 | h = fHAlpha.ProjectionZ("ProjAlpha", -1, 9999, -1, 9999, "E");
|
---|
647 | h->SetBit(TH1::kNoTitle);
|
---|
648 | h->SetStats(kTRUE);
|
---|
649 | h->SetXTitle("\\alpha [\\circ]");
|
---|
650 | h->SetYTitle("Counts");
|
---|
651 | h->SetDirectory(NULL);
|
---|
652 | h->SetMarkerStyle(kFullDotMedium);
|
---|
653 | h->SetBit(kCanDelete);
|
---|
654 | h->Draw("");
|
---|
655 |
|
---|
656 | if (fOffData)
|
---|
657 | {
|
---|
658 | h->SetMarkerColor(kGreen);
|
---|
659 |
|
---|
660 | h = fOffData->ProjectionZ("ProjAlphaOff", -1, 9999, -1, 9999, "E");
|
---|
661 | h->SetBit(TH1::kNoTitle);
|
---|
662 | h->SetXTitle("\\alpha [\\circ]");
|
---|
663 | h->SetYTitle("Counts");
|
---|
664 | h->SetDirectory(NULL);
|
---|
665 | h->SetMarkerStyle(kFullDotMedium);
|
---|
666 | h->SetBit(kCanDelete);
|
---|
667 | h->SetMarkerColor(kRed);
|
---|
668 | h->Draw("same");
|
---|
669 |
|
---|
670 | h = (TH1D*)h->Clone("ProjAlphaOnOff");
|
---|
671 | h->SetBit(TH1::kNoTitle);
|
---|
672 | h->SetXTitle("\\alpha [\\circ]");
|
---|
673 | h->SetYTitle("Counts");
|
---|
674 | h->SetDirectory(NULL);
|
---|
675 | h->SetMarkerStyle(kFullDotMedium);
|
---|
676 | h->SetBit(kCanDelete);
|
---|
677 | h->SetMarkerColor(kBlue);
|
---|
678 | h->Draw("same");
|
---|
679 |
|
---|
680 | TLine lin;
|
---|
681 | lin.SetLineStyle(kDashed);
|
---|
682 | lin.DrawLine(0, 0, 90, 0);
|
---|
683 | }
|
---|
684 |
|
---|
685 | // After the Alpha-projection has been drawn. Fit the histogram
|
---|
686 | // and paint the result into this pad
|
---|
687 | AppendPad("alpha");
|
---|
688 |
|
---|
689 | if (fHEnergy.GetNbinsX()>1)
|
---|
690 | {
|
---|
691 | pad->cd(2);
|
---|
692 | gPad->SetBorderMode(0);
|
---|
693 | fHEnergy.Draw();
|
---|
694 |
|
---|
695 | AppendPad("energy");
|
---|
696 |
|
---|
697 | h = (TH1D*)fHAlpha.Project3D("y");
|
---|
698 | h->SetBit(TH1::kNoTitle|TH1::kNoStats);
|
---|
699 | h->SetXTitle("E [GeV]");
|
---|
700 | h->SetYTitle("Counts");
|
---|
701 | h->SetDirectory(NULL);
|
---|
702 | h->SetMarkerStyle(kFullDotMedium);
|
---|
703 | h->SetBit(kCanDelete);
|
---|
704 | h->SetMarkerColor(kCyan);
|
---|
705 | h->SetLineColor(kCyan);
|
---|
706 | h->Draw("Psame");
|
---|
707 | }
|
---|
708 | else
|
---|
709 | delete pad->GetPad(2);
|
---|
710 |
|
---|
711 | if (fTimeEffOn && fTime || fHTime.GetNbinsX()>1)
|
---|
712 | {
|
---|
713 | pad->cd(3);
|
---|
714 | gPad->SetBorderMode(0);
|
---|
715 | fHTime.Draw();
|
---|
716 | AppendPad("time");
|
---|
717 | }
|
---|
718 | else
|
---|
719 | delete pad->GetPad(3);
|
---|
720 |
|
---|
721 | if (fHTheta.GetNbinsX()>1)
|
---|
722 | {
|
---|
723 | pad->cd(4);
|
---|
724 | gPad->SetBorderMode(0);
|
---|
725 | fHTheta.Draw();
|
---|
726 |
|
---|
727 | AppendPad("theta");
|
---|
728 |
|
---|
729 | h = (TH1D*)fHAlpha.Project3D("x");
|
---|
730 | h->SetBit(TH1::kNoTitle|TH1::kNoStats);
|
---|
731 | h->SetXTitle("\\theta [\\circ]");
|
---|
732 | h->SetYTitle("Counts");
|
---|
733 | h->SetDirectory(NULL);
|
---|
734 | h->SetMarkerStyle(kFullDotMedium);
|
---|
735 | h->SetBit(kCanDelete);
|
---|
736 | h->SetMarkerColor(kCyan);
|
---|
737 | h->SetLineColor(kCyan);
|
---|
738 | h->Draw("Psame");
|
---|
739 | }
|
---|
740 | else
|
---|
741 | delete pad->GetPad(4);
|
---|
742 | }
|
---|
743 |
|
---|
744 | void MHAlpha::DrawAll()
|
---|
745 | {
|
---|
746 | // FIXME: Do in Paint if special option given!
|
---|
747 | TCanvas *c = new TCanvas;
|
---|
748 | Int_t n = fHAlpha.GetNbinsY();
|
---|
749 | Int_t nc = (Int_t)(TMath::Sqrt((Float_t)n-1)+1);
|
---|
750 | c->Divide(nc, nc, 0, 0);
|
---|
751 |
|
---|
752 | // Do not store the 'final' result in fFit
|
---|
753 | MAlphaFitter fit(fFit);
|
---|
754 |
|
---|
755 | for (int i=1; i<=fHAlpha.GetNbinsY(); i++)
|
---|
756 | {
|
---|
757 | c->cd(i);
|
---|
758 |
|
---|
759 | TH1D *hon = fHAlpha.ProjectionZ("ProjAlpha", -1, 9999, i, i, "E");
|
---|
760 | hon->SetBit(TH1::kNoTitle);
|
---|
761 | hon->SetStats(kTRUE);
|
---|
762 | hon->SetXTitle("\\alpha [\\circ]");
|
---|
763 | hon->SetYTitle("Counts");
|
---|
764 | hon->SetDirectory(NULL);
|
---|
765 | hon->SetMarkerStyle(kFullDotMedium);
|
---|
766 | hon->SetBit(kCanDelete);
|
---|
767 | hon->Draw("");
|
---|
768 |
|
---|
769 | TH1D *hof = 0;
|
---|
770 | Double_t alpha = 1;
|
---|
771 |
|
---|
772 | if (fOffData)
|
---|
773 | {
|
---|
774 | hon->SetMarkerColor(kGreen);
|
---|
775 |
|
---|
776 | hof = fOffData->ProjectionZ("ProjAlphaOff", -1, 9999, i, i, "E");
|
---|
777 | hof->SetBit(TH1::kNoTitle|TH1::kNoStats);
|
---|
778 | hof->SetXTitle("\\alpha [\\circ]");
|
---|
779 | hof->SetYTitle("Counts");
|
---|
780 | hof->SetDirectory(NULL);
|
---|
781 | hof->SetMarkerStyle(kFullDotMedium);
|
---|
782 | hof->SetBit(kCanDelete);
|
---|
783 | hof->SetMarkerColor(kRed);
|
---|
784 | hof->Draw("same");
|
---|
785 |
|
---|
786 | alpha = fit.Scale(*hof, *hon);
|
---|
787 |
|
---|
788 | hon->SetMaximum();
|
---|
789 | hon->SetMaximum(TMath::Max(hon->GetMaximum(), hof->GetMaximum())*1.05);
|
---|
790 |
|
---|
791 | TH1D *diff = new TH1D(*hon);
|
---|
792 | diff->Add(hof, -1);
|
---|
793 | diff->SetBit(TH1::kNoTitle);
|
---|
794 | diff->SetXTitle("\\alpha [\\circ]");
|
---|
795 | diff->SetYTitle("Counts");
|
---|
796 | diff->SetDirectory(NULL);
|
---|
797 | diff->SetMarkerStyle(kFullDotMedium);
|
---|
798 | diff->SetBit(kCanDelete);
|
---|
799 | diff->SetMarkerColor(kBlue);
|
---|
800 | diff->Draw("same");
|
---|
801 |
|
---|
802 | TLine lin;
|
---|
803 | lin.SetLineStyle(kDashed);
|
---|
804 | lin.DrawLine(0, 0, 90, 0);
|
---|
805 |
|
---|
806 | const Float_t min = diff->GetMinimum()*1.05;
|
---|
807 | hon->SetMinimum(min<0 ? min : 0);
|
---|
808 | }
|
---|
809 |
|
---|
810 | if (hof ? fit.Fit(*hon, *hof, alpha) : fit.Fit(*hon))
|
---|
811 | *fLog << dbg << "Bin " << i << ": sigma=" << fit.GetSignificance() << " omega=" << fit.GetGausSigma() << " events=" << fit.GetEventsExcess() << endl;
|
---|
812 | /*
|
---|
813 | if (fit.FitEnergy(fHAlpha, fOffData, i, kTRUE))
|
---|
814 | {
|
---|
815 | fHEnergy.SetBinContent(i, fit.GetEventsExcess());
|
---|
816 | fHEnergy.SetBinError(i, fit.GetEventsExcess()*0.2);
|
---|
817 | }*/
|
---|
818 | }
|
---|
819 |
|
---|
820 | }
|
---|
821 |
|
---|
822 |
|
---|
823 | Bool_t MHAlpha::Finalize()
|
---|
824 | {
|
---|
825 | //TH1D *h = fHAlpha.ProjectionZ("AlphaExc_px", -1, 9999, -1, 9999, "E");
|
---|
826 | //h->SetDirectory(0);
|
---|
827 | //Bool_t rc = fFit.Fit(*h);
|
---|
828 | //delete h;
|
---|
829 | if (!fFit.FitAlpha(fHAlpha, fOffData))
|
---|
830 | {
|
---|
831 | *fLog << warn << "Histogram empty." << endl;
|
---|
832 | return kTRUE;
|
---|
833 | }
|
---|
834 |
|
---|
835 | // Store the final result in fFit
|
---|
836 | fFit.Print("result");
|
---|
837 |
|
---|
838 | fResult->SetVal(fFit.GetMinimizationValue());
|
---|
839 |
|
---|
840 | if (!fSkipHistEnergy)
|
---|
841 | {
|
---|
842 | *fLog << inf << "Processing energy bins..." << endl;
|
---|
843 | FitEnergyBins();
|
---|
844 | }
|
---|
845 | if (!fSkipHistTheta)
|
---|
846 | {
|
---|
847 | *fLog << inf << "Processing theta bins..." << endl;
|
---|
848 | FitThetaBins();
|
---|
849 | }
|
---|
850 | if (!fSkipHistTime)
|
---|
851 | {
|
---|
852 | *fLog << inf << "Processing time bins..." << endl;
|
---|
853 | UpdateAlphaTime(kTRUE);
|
---|
854 | MH::RemoveFirstBin(fHTime);
|
---|
855 | }
|
---|
856 |
|
---|
857 | return kTRUE;
|
---|
858 | }
|
---|
859 |
|
---|
860 | // --------------------------------------------------------------------------
|
---|
861 | //
|
---|
862 | // You can use this function if you want to use a MHMatrix instead of
|
---|
863 | // MMcEvt. This function adds all necessary columns to the
|
---|
864 | // given matrix. Afterward you should fill the matrix with the corresponding
|
---|
865 | // data (eg from a file by using MHMatrix::Fill). If you now loop
|
---|
866 | // through the matrix (eg using MMatrixLoop) MHHadronness::Fill
|
---|
867 | // will take the values from the matrix instead of the containers.
|
---|
868 | //
|
---|
869 | // It takes fSkipHist* into account!
|
---|
870 | //
|
---|
871 | void MHAlpha::InitMapping(MHMatrix *mat, Int_t type)
|
---|
872 | {
|
---|
873 | if (fMatrix)
|
---|
874 | return;
|
---|
875 |
|
---|
876 | fMatrix = mat;
|
---|
877 |
|
---|
878 | fMap[0] = fMatrix->AddColumn("MHillasSrc.fAlpha");
|
---|
879 | fMap[1] = -1;
|
---|
880 | fMap[2] = -1;
|
---|
881 | fMap[3] = -1;
|
---|
882 | fMap[4] = -1;
|
---|
883 |
|
---|
884 | if (!fSkipHistEnergy)
|
---|
885 | if (type==0)
|
---|
886 | {
|
---|
887 | fMap[1] = fMatrix->AddColumn("MEnergyEst.fEnergy");
|
---|
888 | fMap[2] = -1;
|
---|
889 | }
|
---|
890 | else
|
---|
891 | {
|
---|
892 | fMap[1] = -1;
|
---|
893 | fMap[2] = fMatrix->AddColumn("MHillas.fSize");
|
---|
894 | }
|
---|
895 |
|
---|
896 | if (!fSkipHistTheta)
|
---|
897 | fMap[3] = fMatrix->AddColumn("MPointingPos.fZd");
|
---|
898 |
|
---|
899 | // if (!fSkipHistTime)
|
---|
900 | // fMap[4] = fMatrix->AddColumn("MTime.GetAxisTime");
|
---|
901 | }
|
---|
902 |
|
---|
903 | void MHAlpha::StopMapping()
|
---|
904 | {
|
---|
905 | fMatrix = NULL;
|
---|
906 | }
|
---|
907 |
|
---|
908 | Int_t MHAlpha::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
909 | {
|
---|
910 | Bool_t rc = kFALSE;
|
---|
911 | if (IsEnvDefined(env, prefix, "NumTimeBins", print))
|
---|
912 | {
|
---|
913 | SetNumTimeBins(GetEnvValue(env, prefix, "NumTimeBins", fNumTimeBins));
|
---|
914 | rc = kTRUE;
|
---|
915 | }
|
---|
916 | return rc;
|
---|
917 | }
|
---|