source: trunk/MagicSoft/Mars/mhflux/MHFalseSource.cc@ 9562

Last change on this file since 9562 was 9367, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 43.4 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MHFalseSource.cc,v 1.26 2009-03-01 12:51:03 tbretz Exp $
3! --------------------------------------------------------------------------
4!
5! *
6! * This file is part of MARS, the MAGIC Analysis and Reconstruction
7! * Software. It is distributed to you in the hope that it can be a useful
8! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
9! * It is distributed WITHOUT ANY WARRANTY.
10! *
11! * Permission to use, copy, modify and distribute this software and its
12! * documentation for any purpose is hereby granted without fee,
13! * provided that the above copyright notice appear in all copies and
14! * that both that copyright notice and this permission notice appear
15! * in supporting documentation. It is provided "as is" without express
16! * or implied warranty.
17! *
18!
19!
20! Author(s): Thomas Bretz, 3/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
21!
22! Copyright: MAGIC Software Development, 2000-2004
23!
24!
25\* ======================================================================== */
26
27//////////////////////////////////////////////////////////////////////////////
28//
29// MHFalseSource
30//
31// Create a false source plot. For the Binning in x,y the object MBinning
32// "BinningFalseSource" is taken from the paremeter list.
33//
34// The binning in alpha is currently fixed as 18bins from 0 to 90deg.
35//
36// If MTime, MObservatory and MPointingPos is available in the paremeter
37// list each image is derotated.
38//
39// MHFalseSource fills a 3D histogram with alpha distribution for
40// each (derotated) x and y position.
41//
42// Only a radius of 1.2deg around the camera center is taken into account.
43//
44// The displayed histogram is the projection of alpha<fAlphaCut into
45// the x,y plain and the projection of alpha>90-fAlphaCut
46//
47// By using the context menu (find it in a small region between the single
48// pads) you can change the AlphaCut 'online'
49//
50// Each Z-Projection (Alpha-histogram) is scaled such, that the number
51// of entries fits the maximum number of entries in all Z-Projections.
52// This should correct for the different acceptance in the center
53// and at the vorder of the camera. This, however, produces more noise
54// at the border.
55//
56// Here is a slightly simplified version of the algorithm:
57// ------------------------------------------------------
58// MHillas hil; // Taken as second argument in MFillH
59//
60// MSrcPosCam src;
61// MHillasSrc hsrc;
62// hsrc.SetSrcPos(&src);
63//
64// for (int ix=0; ix<nx; ix++)
65// for (int iy=0; iy<ny; iy++)
66// {
67// TVector2 v(cx[ix], cy[iy]); //cx center of x-bin ix
68// if (rho!=0) //cy center of y-bin iy
69// v=v.Rotate(rho); //image rotation angle
70//
71// src.SetXY(v); //source position in the camera
72//
73// if (!hsrc.Calc(hil)) //calc source dependant hillas
74// return;
75//
76// //fill absolute alpha into histogram
77// const Double_t alpha = hsrc.GetAlpha();
78// fHist.Fill(cx[ix], cy[iy], TMath::Abs(alpha), w);
79// }
80// }
81//
82// Use MHFalse Source like this:
83// -----------------------------
84// MFillH fill("MHFalseSource", "MHillas");
85// or
86// MHFalseSource hist;
87// hist.SetAlphaCut(12.5); // The default value
88// hist.SetBgmean(55); // The default value
89// MFillH fill(&hist, "MHillas");
90//
91// To be implemented:
92// ------------------
93// - a switch to use alpha or |alpha|
94// - taking the binning for alpha from the parlist (binning is
95// currently fixed)
96// - a possibility to change the fit-function (eg using a different TF1)
97// - a possibility to change the fit algorithm (eg which paremeters
98// are fixed at which time)
99// - use a different varaible than alpha
100// - a possiblity to change the algorithm which is used to calculate
101// alpha (or another parameter) is missing (this could be done using
102// a tasklist somewhere...)
103// - a more clever (and faster) algorithm to fill the histogram, eg by
104// calculating alpha once and fill the two coils around the mean
105// - more drawing options...
106// - Move Significance() to a more 'general' place and implement
107// also different algorithms like (Li/Ma)
108// - implement fit for best alpha distribution -- online (Paint)
109// - currently a constant pointing position is assumed in Fill()
110// - the center of rotation need not to be the camera center
111// - ERRORS on each alpha bin to estimate the chi^2 correctly!
112// (sqrt(N)/binwidth) needed for WOlfgangs proposed caluclation
113// of alpha(Li/Ma)
114// - use the g/h-separation filters from the tasklists ("Cut1") as filters
115// two
116//
117//////////////////////////////////////////////////////////////////////////////
118#include "MHFalseSource.h"
119
120#include <TF1.h>
121#include <TF2.h>
122#include <TH2.h>
123#include <TLatex.h>
124#include <TGraph.h>
125#include <TStyle.h>
126#include <TCanvas.h>
127#include <TRandom.h>
128#include <TEllipse.h>
129#include <TPaveText.h>
130#include <TStopwatch.h>
131
132#include "MGeomCam.h"
133#include "MSrcPosCam.h"
134#include "MHillas.h"
135#include "MHillasSrc.h"
136#include "MTime.h"
137#include "MObservatory.h"
138#include "MPointingPos.h"
139#include "MAstroCatalog.h"
140#include "MAstroSky2Local.h"
141#include "MStatusDisplay.h"
142
143#include "MMath.h"
144#include "MAlphaFitter.h"
145
146#include "MString.h"
147#include "MBinning.h"
148#include "MParList.h"
149
150#include "MLog.h"
151#include "MLogManip.h"
152
153ClassImp(MHFalseSource);
154
155using namespace std;
156
157//class MHillasExt;
158
159// --------------------------------------------------------------------------
160//
161// Default Constructor
162//
163MHFalseSource::MHFalseSource(const char *name, const char *title)
164 : fTime(0), fPointPos(0), fObservatory(0), fMm2Deg(-1), fAlphaCut(12.5),
165 fBgMean(55), fMinDist(-1), fMaxDist(-1), fMinDW(-1), fMaxDW(-1),
166 fHistOff(0)
167{
168 //
169 // set the name and title of this object
170 //
171 fName = name ? name : "MHFalseSource";
172 fTitle = title ? title : "3D-plot of Alpha vs x, y";
173
174 fHist.SetDirectory(NULL);
175
176 fHist.SetName("Alpha");
177 fHist.SetTitle("3D-plot of Alpha vs x, y");
178 fHist.SetXTitle("x [\\circ]");
179 fHist.SetYTitle("y [\\circ]");
180 fHist.SetZTitle("\\alpha [\\circ]");
181}
182
183void MHFalseSource::MakeSymmetric(TH1 *h)
184{
185 h->SetMinimum();
186 h->SetMaximum();
187
188 const Float_t min = TMath::Abs(h->GetMinimum());
189 const Float_t max = TMath::Abs(h->GetMaximum());
190
191 const Float_t absmax = TMath::Max(min, max)*1.002;
192
193 h->SetMaximum( absmax);
194 h->SetMinimum(-absmax);
195}
196
197// --------------------------------------------------------------------------
198//
199// Set the alpha cut (|alpha|<fAlphaCut) which is use to estimate the
200// number of excess events
201//
202void MHFalseSource::SetAlphaCut(Float_t alpha)
203{
204 if (alpha<0)
205 *fLog << warn << "Alpha<0... taking absolute value." << endl;
206
207 fAlphaCut = TMath::Abs(alpha);
208
209 Modified();
210}
211
212// --------------------------------------------------------------------------
213//
214// Set mean alpha around which the off sample is determined
215// (fBgMean-fAlphaCut/2<|fAlpha|<fBgMean+fAlphaCut/2) which is use
216// to estimate the number of off events
217//
218void MHFalseSource::SetBgMean(Float_t alpha)
219{
220 if (alpha<0)
221 *fLog << warn << "Alpha<0... taking absolute value." << endl;
222
223 fBgMean = TMath::Abs(alpha);
224
225 Modified();
226}
227
228// --------------------------------------------------------------------------
229//
230// Set binnings (takes BinningFalseSource) and prepare filling of the
231// histogram.
232//
233// Also search for MTime, MObservatory and MPointingPos
234//
235Bool_t MHFalseSource::SetupFill(const MParList *plist)
236{
237 const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
238 if (!geom)
239 {
240 *fLog << err << "MGeomCam not found... aborting." << endl;
241 return kFALSE;
242 }
243 fMm2Deg = geom->GetConvMm2Deg();
244
245 const TString off(MString::Format("%sOff", fName.Data()));
246 if (fName!=off && fHistOff==NULL)
247 {
248 const TString desc(MString::Format("%s [%s] found... using ", off.Data(), ClassName()));
249 MHFalseSource *hoff = (MHFalseSource*)plist->FindObject(off, ClassName());
250 if (!hoff)
251 *fLog << inf << "No " << desc << "current data only!" << endl;
252 else
253 {
254 *fLog << inf << desc << "on-off mode!" << endl;
255 SetOffData(*hoff);
256 }
257 }
258
259 if (fHistOff)
260 MH::SetBinning(&fHist, fHistOff);
261 else
262 {
263 MBinning binsa(18, 0, 90);
264 binsa.SetEdges(*plist, "BinningAlpha");
265
266 const MBinning *bins = (MBinning*)plist->FindObject("BinningFalseSource");
267 if (!bins || bins->IsDefault())
268 {
269 const Float_t r = (geom ? geom->GetMaxRadius()/3 : 200)*fMm2Deg;
270
271 MBinning b;
272 b.SetEdges(20, -r, r);
273 SetBinning(&fHist, &b, &b, &binsa);
274 }
275 else
276 SetBinning(&fHist, bins, bins, &binsa);
277 }
278
279 fPointPos = (MPointingPos*)plist->FindObject(AddSerialNumber("MPointingPos"));
280 if (!fPointPos)
281 *fLog << warn << "MPointingPos not found... no derotation." << endl;
282
283 fTime = (MTime*)plist->FindObject(AddSerialNumber("MTime"));
284 if (!fTime)
285 *fLog << warn << "MTime not found... no derotation." << endl;
286
287 fSrcPos = (MSrcPosCam*)plist->FindObject(AddSerialNumber("MSrcPosCam"));
288 if (!fSrcPos)
289 *fLog << warn << "MSrcPosCam not found... no translation." << endl;
290
291 fObservatory = (MObservatory*)plist->FindObject(AddSerialNumber("MObservatory"));
292 if (!fObservatory)
293 *fLog << warn << "MObservatory not found... no derotation." << endl;
294
295 MPointingPos *point = (MPointingPos*)plist->FindObject("MSourcePos", "MPointingPos");
296 if (!point)
297 point = fPointPos;
298
299 // FIXME: Because the pointing position could change we must check
300 // for the current pointing position and add a offset in the
301 // Fill function!
302 fRa = point ? point->GetRa() : 0;
303 fDec = point ? point->GetDec() : 90;
304
305 return kTRUE;
306}
307
308// --------------------------------------------------------------------------
309//
310// Fill the histogram. For details see the code or the class description
311//
312Int_t MHFalseSource::Fill(const MParContainer *par, const Stat_t w)
313{
314 const MHillas *hil = dynamic_cast<const MHillas*>(par);
315 if (!hil)
316 {
317 *fLog << err << "MHFalseSource::Fill: No container specified!" << endl;
318 return kERROR;
319 }
320
321 // Get max radius...
322 const Double_t maxr = 0.98*TMath::Abs(fHist.GetBinCenter(1));
323
324 // Get camera rotation angle
325 Double_t rho = 0;
326 if (fTime && fObservatory && fPointPos)
327 rho = fPointPos->RotationAngle(*fObservatory, *fTime);
328 //if (fPointPos)
329 // rho = fPointPos->RotationAngle(*fObservatory);
330
331 // Create necessary containers for calculation
332 MSrcPosCam src;
333 MHillasSrc hsrc;
334 hsrc.SetSrcPos(&src);
335
336 // Get number of bins and bin-centers
337 const Int_t nx = fHist.GetNbinsX();
338 const Int_t ny = fHist.GetNbinsY();
339 Axis_t cx[nx];
340 Axis_t cy[ny];
341 fHist.GetXaxis()->GetCenter(cx);
342 fHist.GetYaxis()->GetCenter(cy);
343
344 for (int ix=0; ix<nx; ix++)
345 {
346 for (int iy=0; iy<ny; iy++)
347 {
348 // check distance... to get a circle plot
349 if (TMath::Hypot(cx[ix], cy[iy])>maxr)
350 continue;
351
352 // rotate center of bin
353 // precalculation of sin/cos doesn't accelerate
354 TVector2 v(cx[ix], cy[iy]);
355 if (rho!=0)
356 v=v.Rotate(rho);
357
358 // convert degrees to millimeters
359 v *= 1./fMm2Deg;
360
361 if (fSrcPos)
362 v += fSrcPos->GetXY();
363
364 src.SetXY(v);
365
366 // Source dependant hillas parameters
367 if (hsrc.Calc(*hil/*, ext*/)>0)
368 {
369 *fLog << warn << "Calculation of MHillasSrc failed for x=" << cx[ix] << " y=" << cy[iy] << endl;
370 return kFALSE;
371 }
372
373 // FIXME: This should be replaced by an external MFilter
374 // and/or MTaskList
375 // Source dependant distance cut
376 if (fMinDist>0 && hsrc.GetDist()*fMm2Deg<fMinDist)
377 continue;
378 if (fMaxDist>0 && hsrc.GetDist()*fMm2Deg>fMaxDist)
379 continue;
380
381 if (fMaxDW>0 && hsrc.GetDist()>fMaxDW*hil->GetWidth())
382 continue;
383 if (fMinDW<0 && hsrc.GetDist()<fMinDW*hil->GetWidth())
384 continue;
385
386 // Fill histogram
387 const Double_t alpha = hsrc.GetAlpha();
388 fHist.Fill(cx[ix], cy[iy], TMath::Abs(alpha), w);
389 }
390 }
391
392 return kTRUE;
393}
394
395// --------------------------------------------------------------------------
396//
397// Create projection for off data, taking sum of bin contents of
398// range (fBgMean-fAlphaCut/2, fBgMean+fAlphaCut) Making sure to take
399// the same number of bins than for on-data
400//
401void MHFalseSource::ProjectOff(const TH3D &src, TH2D *h2, TH2D *hall)
402{
403 TAxis &axe = *src.GetZaxis();
404
405 // Find range to cut (left edge and width)
406 const Int_t f = axe.FindBin(fBgMean-fAlphaCut/2);
407 const Int_t l = axe.FindBin(fAlphaCut)+f-1;
408
409 axe.SetRange(f, l);
410 const Float_t cut1 = axe.GetBinLowEdge(f);
411 const Float_t cut2 = axe.GetBinUpEdge(l);
412 h2->SetTitle(MString::Format("Distribution of %.1f\\circ<|\\alpha|<%.1f\\circ in x,y", cut1, cut2));
413
414 // Get projection for range
415 TH2D *p = (TH2D*)src.Project3D("yx_off_NULL");
416
417 // Reset range
418 axe.SetRange(0,9999);
419
420//#if ROOT_VERSION_CODE < ROOT_VERSION(4,02,00)
421 // Move contents from projection to h2
422 h2->Reset();
423 h2->Add(p, hall->GetMaximum());
424 h2->Divide(hall);
425
426 // Delete p
427 delete p;
428/*#else
429 p->Scale(all->GetMaximum());
430 p->Divide(all);
431#endif*/
432
433 // Set Minimum as minimum value Greater Than 0
434 h2->SetMinimum(GetMinimumGT(*h2));
435}
436
437// --------------------------------------------------------------------------
438//
439// Create projection for on data, taking sum of bin contents of
440// range (0, fAlphaCut)
441//
442void MHFalseSource::ProjectOn(const TH3D &src, TH2D *h3, TH2D *hall)
443{
444 TAxis &axe = *src.GetZaxis();
445
446 // Find range to cut
447 axe.SetRangeUser(0, fAlphaCut);
448 const Float_t cut = axe.GetBinUpEdge(axe.GetLast());
449 h3->SetTitle(MString::Format("Distribution of |\\alpha|<%.1f\\circ in x,y", cut));
450
451 // Get projection for range
452 TH2D *p = (TH2D*)src.Project3D("yx_on_NULL");
453
454 // Reset range
455 axe.SetRange(0,9999);
456
457//#if ROOT_VERSION_CODE < ROOT_VERSION(4,02,00)
458 // Move contents from projection to h3
459 h3->Reset();
460 h3->Add(p, hall->GetMaximum());
461 h3->Divide(hall);
462
463 // Delete p
464 delete p;
465/*#else
466 p->Scale(all->GetMaximum());
467 p->Divide(all);
468#endif*/
469
470 // Set Minimum as minimum value Greater Than 0
471 h3->SetMinimum(GetMinimumGT(*h3));
472}
473
474// --------------------------------------------------------------------------
475//
476// Create projection for all data, taking sum of bin contents of
477// range (0, 90) - corresponding to the number of entries in this slice.
478//
479void MHFalseSource::ProjectAll(TH2D *h3)
480{
481 h3->SetTitle("Number of entries");
482
483 // Get projection for range
484#if ROOT_VERSION_CODE < ROOT_VERSION(4,02,00)
485 TH2D *p = (TH2D*)fHist.Project3D("yx_all");
486
487 // Move contents from projection to h3
488 h3->Reset();
489 h3->Add(p);
490 delete p;
491#else
492 fHist.Project3D("yx_all");
493#endif
494
495 // Set Minimum as minimum value Greater Than 0
496 h3->SetMinimum(GetMinimumGT(*h3));
497}
498
499void MHFalseSource::ProjectOnOff(TH2D *h2, TH2D *h0)
500{
501 ProjectOn(*fHistOff, h2, h0);
502
503 TH2D h;
504 MH::SetBinning(&h, h2);
505
506 // Divide by number of entries in off region (of off-data)
507 ProjectOff(*fHistOff, &h, h0);
508 h2->Divide(&h);
509
510 // Multiply by number of entries in off region (of on-data)
511 ProjectOff(fHist, &h, h0);
512 h2->Multiply(&h);
513
514 // Recalculate Minimum
515 h2->SetMinimum(GetMinimumGT(*h2));
516}
517
518// --------------------------------------------------------------------------
519//
520// Update the projections and paint them
521//
522void MHFalseSource::Paint(Option_t *opt)
523{
524 // Set pretty color palette
525 gStyle->SetPalette(1, 0);
526
527 TVirtualPad *padsave = gPad;
528
529 TH1D* h1;
530 TH2D* h0;
531 TH2D* h2;
532 TH2D* h3;
533 TH2D* h4;
534 TH2D* h5;
535
536 // Update projection of all-events
537 padsave->GetPad(2)->cd(3);
538 if ((h0 = (TH2D*)gPad->FindObject("Alpha_yx_all")))
539 ProjectAll(h0);
540
541 // Update projection of on-events
542 padsave->GetPad(1)->cd(1);
543 if ((h3 = (TH2D*)gPad->FindObject("Alpha_yx_on")))
544 ProjectOn(fHist, h3, h0);
545
546 // Update projection of off-events
547 padsave->GetPad(1)->cd(3);
548 if ((h2 = (TH2D*)gPad->FindObject("Alpha_yx_off")))
549 {
550 if (!fHistOff)
551 ProjectOff(fHist, h2, h0);
552 else
553 ProjectOnOff(h2, h0);
554 }
555
556 padsave->GetPad(2)->cd(2);
557 if ((h5 = (TH2D*)gPad->FindObject("Alpha_yx_diff")))
558 {
559 h5->Add(h2, h3, -1);
560 MakeSymmetric(h5);
561 }
562
563 // Update projection of significance
564 padsave->GetPad(1)->cd(2);
565 if (h2 && h3 && (h4 = (TH2D*)gPad->FindObject("Alpha_yx_sig")))
566 {
567 const Int_t nx = h4->GetXaxis()->GetNbins();
568 const Int_t ny = h4->GetYaxis()->GetNbins();
569
570 Int_t maxx=nx/2;
571 Int_t maxy=ny/2;
572
573 Int_t max = h4->GetBin(nx, ny);
574
575 h4->SetEntries(0);
576 for (int ix=1; ix<=nx; ix++)
577 for (int iy=1; iy<=ny; iy++)
578 {
579 const Int_t n = h4->GetBin(ix, iy);
580
581 const Double_t s = h3->GetBinContent(n);
582 const Double_t b = h2->GetBinContent(n);
583
584 const Double_t sig = MMath::SignificanceLiMaSigned(s, b);
585
586 h4->SetBinContent(n, sig);
587
588 if (sig>h4->GetBinContent(max) && sig>0/* && (ix-nx/2)*(ix-nx/2)+(iy-ny/2)*(iy-ny/2)<nr*nr/9*/)
589 {
590 max = n;
591 maxx=ix;
592 maxy=iy;
593 }
594 }
595
596 MakeSymmetric(h4);
597
598 // Update projection of 'the best alpha-plot'
599 padsave->GetPad(2)->cd(1);
600 if ((h1 = (TH1D*)gPad->FindObject("Alpha_z")) && max>0)
601 {
602 const Double_t x = h4->GetXaxis()->GetBinCenter(maxx);
603 const Double_t y = h4->GetYaxis()->GetBinCenter(maxy);
604 const Double_t s = h4->GetBinContent(max);
605
606 // This is because a 3D histogram x and y are vice versa
607 // Than for their projections
608 TH1 *h = fHist.ProjectionZ("Alpha_z", maxx, maxx, maxy, maxy);
609 h->SetTitle(MString::Format("Distribution of \\alpha for x=%.2f y=%.2f (S_{max}=%.1f\\sigma)", x, y, s));
610
611 TH1D *ho=0;
612 if ((ho = (TH1D*)gPad->FindObject("AlphaOff_z")))
613 {
614 fHistOff->ProjectionZ("AlphaOff_z", maxx, maxx, maxy, maxy);
615
616 /* ============= local scaling ================ */
617 const Int_t f = ho->GetXaxis()->FindFixBin(fBgMean-1.5*fAlphaCut);
618 const Int_t l = ho->GetXaxis()->FindFixBin(fAlphaCut*3)+f-1;
619 ho->Scale(h1->Integral(f, l)/ho->Integral(f, l));
620
621
622 //h0->Scale(h1->GetEntries()/h0->GetEntries());
623
624 /* ============= global scaling ================
625 const Int_t f = fHistOff->GetZaxis()->FindFixBin(fBgMean-1.5*fAlphaCut);
626 const Int_t l = fHistOff->GetZaxis()->FindFixBin(fAlphaCut*3)+f-1;
627
628 Double_t c0 = fHist.Integral(0, 9999, 0, 9999, f, l);
629 Double_t c1 = fHistOff->Integral(0, 9999, 0, 9999, f, l);
630
631 h0->Scale(c0/c1);
632 */
633 }
634 }
635 }
636
637 gPad = padsave;
638}
639
640// --------------------------------------------------------------------------
641//
642// Get the MAstroCatalog corresponding to fRa, fDec. The limiting magnitude
643// is set to 9, while the fov is equal to the current fov of the false
644// source plot.
645//
646TObject *MHFalseSource::GetCatalog() const
647{
648 const Double_t maxr = TMath::Abs(fHist.GetBinLowEdge(1))*TMath::Sqrt(2);
649
650 // Create catalog...
651 MAstroCatalog *stars = new MAstroCatalog;
652 stars->SetMarkerColor(kWhite);
653 stars->SetLimMag(9);
654 stars->SetGuiActive(kFALSE);
655 stars->SetRadiusFOV(maxr);
656 stars->SetRaDec(fRa*TMath::DegToRad()*15, fDec*TMath::DegToRad());
657 stars->ReadBSC("bsc5.dat");
658
659 stars->SetBit(kCanDelete);
660 return stars;
661}
662
663// --------------------------------------------------------------------------
664//
665// Draw the histogram
666//
667void MHFalseSource::Draw(Option_t *opt)
668{
669 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
670 pad->SetBorderMode(0);
671
672 AppendPad("");
673
674 pad->Divide(1, 2, 1e-10, 0.03);
675
676// TObject *catalog = GetCatalog();
677
678 // Initialize upper part
679 pad->cd(1);
680 // Make sure that the catalog is deleted only once
681 // Normally this is not done by root, because it is not necessary...
682 // but in this case it is necessary, because the catalog is
683 // deleted by the first pad and the second one tries to do the same!
684// gROOT->GetListOfCleanups()->Add(gPad);
685 gPad->SetBorderMode(0);
686 gPad->Divide(3, 1);
687
688 // PAD #1
689 pad->GetPad(1)->cd(1);
690 gPad->SetBorderMode(0);
691 fHist.GetZaxis()->SetRangeUser(0,fAlphaCut);
692 TH1 *h3 = fHist.Project3D("yx_on");
693 fHist.GetZaxis()->SetRange(0,9999);
694 h3->SetDirectory(NULL);
695 h3->SetXTitle(fHist.GetXaxis()->GetTitle());
696 h3->SetYTitle(fHist.GetYaxis()->GetTitle());
697 h3->Draw("colz");
698 h3->SetBit(kCanDelete);
699// catalog->Draw("mirror same *");
700
701 // PAD #2
702 pad->GetPad(1)->cd(2);
703 gPad->SetBorderMode(0);
704 fHist.GetZaxis()->SetRange(0,0);
705 TH1 *h4 = fHist.Project3D("yx_sig"); // Do this to get the correct binning....
706 fHist.GetZaxis()->SetRange(0,9999);
707 h4->SetTitle("Significance");
708 h4->SetDirectory(NULL);
709 h4->SetXTitle(fHist.GetXaxis()->GetTitle());
710 h4->SetYTitle(fHist.GetYaxis()->GetTitle());
711 h4->Draw("colz");
712 h4->SetBit(kCanDelete);
713// catalog->Draw("mirror same *");
714
715 // PAD #3
716 pad->GetPad(1)->cd(3);
717 gPad->SetBorderMode(0);
718 TH1 *h2 = 0;
719 if (fHistOff)
720 {
721 fHistOff->GetZaxis()->SetRangeUser(0,fAlphaCut);
722 h2 = fHistOff->Project3D("yx_off");
723 fHistOff->GetZaxis()->SetRange(0,9999);
724 }
725 else
726 {
727 fHist.GetZaxis()->SetRangeUser(fBgMean-fAlphaCut/2, fBgMean+fAlphaCut/2);
728 h2 = fHist.Project3D("yx_off");
729 fHist.GetZaxis()->SetRange(0,9999);
730 }
731 h2->SetDirectory(NULL);
732 h2->SetXTitle(fHist.GetXaxis()->GetTitle());
733 h2->SetYTitle(fHist.GetYaxis()->GetTitle());
734 h2->Draw("colz");
735 h2->SetBit(kCanDelete);
736// catalog->Draw("mirror same *");
737
738 // Initialize lower part
739 pad->cd(2);
740 // Make sure that the catalog is deleted only once
741// gROOT->GetListOfCleanups()->Add(gPad);
742 gPad->SetBorderMode(0);
743 gPad->Divide(3, 1);
744
745 // PAD #4
746 pad->GetPad(2)->cd(1);
747 gPad->SetBorderMode(0);
748 TH1 *h1 = fHist.ProjectionZ("Alpha_z");
749 h1->SetDirectory(NULL);
750 h1->SetTitle("Distribution of \\alpha");
751 h1->SetXTitle(fHist.GetZaxis()->GetTitle());
752 h1->SetYTitle("Counts");
753 h1->Draw();
754 h1->SetBit(kCanDelete);
755 if (fHistOff)
756 {
757 h1->SetLineColor(kGreen);
758
759 h1 = fHistOff->ProjectionZ("AlphaOff_z");
760 h1->SetDirectory(NULL);
761 h1->SetTitle("Distribution of \\alpha");
762 h1->SetXTitle(fHistOff->GetZaxis()->GetTitle());
763 h1->SetYTitle("Counts");
764 h1->Draw("same");
765 h1->SetBit(kCanDelete);
766 h1->SetLineColor(kRed);
767 }
768
769 // PAD #5
770 pad->GetPad(2)->cd(2);
771 gPad->SetBorderMode(0);
772 TH1 *h5 = (TH1*)h3->Clone("Alpha_yx_diff");
773 h5->Add(h2, -1);
774 h5->SetTitle("Difference of on- and off-distribution");
775 h5->SetDirectory(NULL);
776 h5->Draw("colz");
777 h5->SetBit(kCanDelete);
778// catalog->Draw("mirror same *");
779
780 // PAD #6
781 pad->GetPad(2)->cd(3);
782 gPad->SetBorderMode(0);
783 TH1 *h0 = fHist.Project3D("yx_all");
784 h0->SetDirectory(NULL);
785 h0->SetXTitle(fHist.GetXaxis()->GetTitle());
786 h0->SetYTitle(fHist.GetYaxis()->GetTitle());
787 h0->Draw("colz");
788 h0->SetBit(kCanDelete);
789// catalog->Draw("mirror same *");
790}
791
792// --------------------------------------------------------------------------
793//
794// Everything which is in the main pad belongs to this class!
795//
796Int_t MHFalseSource::DistancetoPrimitive(Int_t px, Int_t py)
797{
798 return 0;
799}
800
801// --------------------------------------------------------------------------
802//
803// Set all sub-pads to Modified()
804//
805void MHFalseSource::Modified()
806{
807 if (!gPad)
808 return;
809
810 TVirtualPad *padsave = gPad;
811 padsave->Modified();
812 padsave->GetPad(1)->cd(1);
813 gPad->Modified();
814 padsave->GetPad(1)->cd(3);
815 gPad->Modified();
816 padsave->GetPad(2)->cd(1);
817 gPad->Modified();
818 padsave->GetPad(2)->cd(2);
819 gPad->Modified();
820 padsave->GetPad(2)->cd(3);
821 gPad->Modified();
822 gPad->cd();
823}
824
825// --------------------------------------------------------------------------
826//
827// The following resources are available:
828//
829// MHFalseSource.DistMin: 0.5
830// MHFalseSource.DistMax: 1.4
831// MHFalseSource.DWMin: 0.1
832// MHFalseSource.DWMax: 0.3
833//
834Int_t MHFalseSource::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
835{
836 Bool_t rc = kFALSE;
837 if (IsEnvDefined(env, prefix, "DistMin", print))
838 {
839 rc = kTRUE;
840 SetMinDist(GetEnvValue(env, prefix, "DistMin", fMinDist));
841 }
842 if (IsEnvDefined(env, prefix, "DistMax", print))
843 {
844 rc = kTRUE;
845 SetMaxDist(GetEnvValue(env, prefix, "DistMax", fMaxDist));
846 }
847
848 if (IsEnvDefined(env, prefix, "DWMin", print))
849 {
850 rc = kTRUE;
851 SetMinDW(GetEnvValue(env, prefix, "DWMin", fMinDist));
852 }
853 if (IsEnvDefined(env, prefix, "DWMax", print))
854 {
855 rc = kTRUE;
856 SetMaxDW(GetEnvValue(env, prefix, "DWMax", fMaxDist));
857 }
858
859 return rc;
860}
861
862static Double_t FcnGauss2d(Double_t *x, Double_t *par)
863{
864 TVector2 v = TVector2(x[0], x[1]).Rotate(par[5]*TMath::DegToRad());
865
866 const Double_t g0 = TMath::Gaus(v.X(), par[1], par[2]);
867 const Double_t g1 = TMath::Gaus(v.Y(), par[3], par[4]);
868
869 //Gaus(Double_t x, Double_t mean=0, Double_t sigma=1, Bool_t norm=kFALSE);
870 return par[0]*g0*g1;
871}
872
873// --------------------------------------------------------------------------
874//
875// This is a preliminary implementation of a alpha-fit procedure for
876// all possible source positions. It will be moved into its own
877// more powerfull class soon.
878//
879// The fit function is "gaus(0)+pol2(3)" which is equivalent to:
880// [0]*exp(-0.5*((x-[1])/[2])^2) + [3] + [4]*x + [5]*x^2
881// or
882// A*exp(-0.5*((x-mu)/sigma)^2) + a + b*x + c*x^2
883//
884// Parameter [1] is fixed to 0 while the alpha peak should be
885// symmetric around alpha=0.
886//
887// Parameter [4] is fixed to 0 because the first derivative at
888// alpha=0 should be 0, too.
889//
890// In a first step the background is fitted between bgmin and bgmax,
891// while the parameters [0]=0 and [2]=1 are fixed.
892//
893// In a second step the signal region (alpha<sigmax) is fittet using
894// the whole function with parameters [1], [3], [4] and [5] fixed.
895//
896// The number of excess and background events are calculated as
897// s = int(0, sigint, gaus(0)+pol2(3))
898// b = int(0, sigint, pol2(3))
899//
900// The Significance is calculated using the Significance() member
901// function.
902//
903void MHFalseSource::FitSignificance(Float_t sigint, Float_t sigmax, Float_t bgmin, Float_t bgmax, Byte_t polynom)
904{
905// TObject *catalog = GetCatalog();
906
907 TH1D h0a("A", "", 50, 0, 4000);
908 TH1D h4a("chisq1", "", 50, 0, 35);
909 //TH1D h5a("prob1", "", 50, 0, 1.1);
910 TH1D h6("signifcance", "", 50, -20, 20);
911
912 TH1D h1("mu", "Parameter \\mu", 50, -1, 1);
913 TH1D h2("sigma", "Parameter \\sigma", 50, 0, 90);
914 TH1D h3("b", "Parameter b", 50, -0.1, 0.1);
915
916 TH1D h0b("a", "Parameter a (red), A (blue)", 50, 0, 4000);
917 TH1D h4b("\\chi^{2}", "\\chi^{2} (red, green) / significance (black)", 50, 0, 35);
918 //TH1D h5b("prob", "Fit probability: Bg(red), F(blue)", 50, 0, 1.1);
919
920 h0a.SetLineColor(kBlue);
921 h4a.SetLineColor(kBlue);
922 //h5a.SetLineColor(kBlue);
923 h0b.SetLineColor(kRed);
924 h4b.SetLineColor(kRed);
925 //h5b.SetLineColor(kRed);
926
927 TH1 *hist = fHist.Project3D("yx_fit");
928 hist->SetDirectory(0);
929 TH1 *hists = fHist.Project3D("yx_fit");
930 hists->SetDirectory(0);
931 TH1 *histb = fHist.Project3D("yx_fit");
932 histb->SetDirectory(0);
933 hist->Reset();
934 hists->Reset();
935 histb->Reset();
936 hist->SetNameTitle("Significance",
937 MString::Format("Fit Region: Signal<%.1f\\circ, %.1f\\circ<Bg<%.1f\\circ",
938 sigmax, bgmin, bgmax));
939 hists->SetName("Excess");
940 histb->SetName("Background");
941 hist->SetXTitle(fHist.GetXaxis()->GetTitle());
942 hists->SetXTitle(fHist.GetXaxis()->GetTitle());
943 histb->SetXTitle(fHist.GetXaxis()->GetTitle());
944 hist->SetYTitle(fHist.GetYaxis()->GetTitle());
945 hists->SetYTitle(fHist.GetYaxis()->GetTitle());
946 histb->SetYTitle(fHist.GetYaxis()->GetTitle());
947
948 const Double_t w = fHist.GetZaxis()->GetBinWidth(1);
949
950 TArrayD maxpar;
951
952 /* func.SetParName(0, "A");
953 * func.SetParName(1, "mu");
954 * func.SetParName(2, "sigma");
955 */
956
957 const Int_t nx = hist->GetXaxis()->GetNbins();
958 const Int_t ny = hist->GetYaxis()->GetNbins();
959 //const Int_t nr = nx*nx+ny*ny;
960
961 Double_t maxalpha0=0;
962 Double_t maxs=3;
963
964 Int_t maxx=0;
965 Int_t maxy=0;
966
967 TStopwatch clk;
968 clk.Start();
969
970 *fLog << inf;
971 *fLog << "Signal fit: alpha < " << sigmax << endl;
972 *fLog << "Integration: alpha < " << sigint << endl;
973 *fLog << "Background fit: " << bgmin << " < alpha < " << bgmax << endl;
974 *fLog << "Polynom order: " << (int)polynom << endl;
975 *fLog << "Fitting False Source Plot..." << flush;
976
977 TH1 *h0 = fHist.Project3D("yx_entries");
978 Float_t entries = h0->GetMaximum();
979 delete h0;
980
981 MAlphaFitter fit;
982 fit.SetSignalIntegralMax(sigint);
983 fit.SetSignalFitMax(sigmax);
984 fit.SetBackgroundFitMin(bgmin);
985 fit.SetBackgroundFitMax(bgmax);
986 fit.SetPolynomOrder(polynom);
987
988 TH1D *h=0, *hoff=0;
989 Double_t scale = 1;
990 for (int ix=1; ix<=nx; ix++)
991 for (int iy=1; iy<=ny; iy++)
992 {
993 // This is because a 3D histogram x and y are vice versa
994 // Than for their projections
995 h = fHist.ProjectionZ("AlphaFit", ix, ix, iy, iy);
996
997 if (h->GetEntries()==0)
998 continue;
999
1000 // This is a quick hack to correct for the lower acceptance at
1001 // the edge of the camera
1002 h->Scale(entries/h->GetEntries());
1003
1004 if (fHistOff)
1005 {
1006 hoff = fHistOff->ProjectionZ("AlphaFitOff", ix, ix, iy, iy);
1007 // This is a quick hack to correct for the lower acceptance at
1008 // the edge of the camera
1009 hoff->Scale(entries/h->GetEntries());
1010 scale = fit.Scale(*hoff, *h);
1011 }
1012
1013 if (!fit.Fit(*h, hoff, scale))
1014 continue;
1015
1016 const Double_t alpha0 = h->GetBinContent(1);
1017 if (alpha0>maxalpha0)
1018 maxalpha0=alpha0;
1019
1020 // Fill results into some histograms
1021 h0a.Fill(fit.GetGausA()); // gaus-A
1022 h0b.Fill(fit.GetCoefficient(3)); // 3
1023 h1.Fill(fit.GetGausMu()); // mu
1024 h2.Fill(fit.GetGausSigma()); // sigma-gaus
1025 if (polynom>1 && !fHistOff)
1026 h3.Fill(fit.GetCoefficient(5));
1027 h4b.Fill(fit.GetChiSqSignal());
1028
1029 const Double_t sig = fit.GetSignificance();
1030 const Double_t b = fit.GetEventsBackground();
1031 const Double_t s = fit.GetEventsSignal();
1032
1033 const Int_t n = hist->GetBin(ix, iy);
1034 hists->SetBinContent(n, s-b);
1035 histb->SetBinContent(n, b);
1036
1037 hist->SetBinContent(n, sig);
1038 if (sig!=0)
1039 h6.Fill(sig);
1040
1041 if (sig>maxs)
1042 {
1043 maxs = sig;
1044 maxx = ix;
1045 maxy = iy;
1046 maxpar = fit.GetCoefficients();
1047 }
1048 }
1049
1050 *fLog << "Done." << endl;
1051
1052 h0a.GetXaxis()->SetRangeUser(0, maxalpha0*1.5);
1053 h0b.GetXaxis()->SetRangeUser(0, maxalpha0*1.5);
1054
1055 hists->SetTitle(MString::Format("Excess events for \\alpha<%.0f\\circ (N_{max}=%d)", sigint, (int)hists->GetMaximum()));
1056 histb->SetTitle(MString::Format("Background events for \\alpha<%.0f\\circ", sigint));
1057
1058 //hists->SetMinimum(GetMinimumGT(*hists));
1059 histb->SetMinimum(GetMinimumGT(*histb));
1060
1061 MakeSymmetric(hists);
1062 MakeSymmetric(hist);
1063
1064 clk.Stop();
1065 clk.Print("m");
1066
1067 TCanvas *c=new TCanvas;
1068
1069 gStyle->SetPalette(1, 0);
1070
1071 c->Divide(3,2, 1e-10, 1e-10);
1072 c->cd(1);
1073 gPad->SetBorderMode(0);
1074 hists->Draw("colz");
1075 hists->SetBit(kCanDelete);
1076// catalog->Draw("mirror same *");
1077 c->cd(2);
1078 gPad->SetBorderMode(0);
1079 hist->Draw("colz");
1080 hist->SetBit(kCanDelete);
1081
1082
1083 const Double_t maxr = 0.9*TMath::Abs(fHist.GetBinCenter(1));
1084 TF2 f2d("Gaus-2D", FcnGauss2d, -maxr, maxr, -maxr, maxr, 6);
1085 f2d.SetLineWidth(1);
1086 f2d.SetParName(0, "Max sigma");
1087 f2d.SetParName(1, "Mean_1 deg");
1088 f2d.SetParName(2, "Sigma_1 deg");
1089 f2d.SetParName(3, "Mean_2 deg");
1090 f2d.SetParName(4, "Sigma_2 deg");
1091 f2d.SetParName(5, "Phi deg");
1092 f2d.SetParLimits(1, -maxr/2, maxr/2); // mu_1
1093 f2d.SetParLimits(3, -maxr/2, maxr/2); // mu_2
1094 f2d.SetParLimits(2, 0, maxr); // sigma_1
1095 f2d.SetParLimits(4, 0, maxr); // sigma_2
1096 f2d.SetParLimits(5, 0, 45); // phi
1097 f2d.SetParameter(0, maxs); // A
1098 f2d.SetParameter(1, hist->GetXaxis()->GetBinCenter(maxx)); // mu_1
1099 f2d.SetParameter(2, 0.1); // sigma_1
1100 f2d.SetParameter(3, hist->GetYaxis()->GetBinCenter(maxy)); // mu_2
1101 f2d.SetParameter(4, 0.1); // sigma_2
1102 f2d.FixParameter(5, 0); // phi
1103 hist->Fit(&f2d, "NI0R");
1104 f2d.DrawCopy("cont2same");
1105
1106
1107// catalog->Draw("mirror same *");
1108 c->cd(3);
1109 gPad->SetBorderMode(0);
1110 histb->Draw("colz");
1111 histb->SetBit(kCanDelete);
1112// catalog->Draw("mirror same *");
1113 c->cd(4);
1114 gPad->Divide(1,3, 0, 0);
1115 TVirtualPad *p=gPad;
1116 p->SetBorderMode(0);
1117 p->cd(1);
1118 gPad->SetBorderMode(0);
1119 h0b.DrawCopy();
1120 h0a.DrawCopy("same");
1121 p->cd(2);
1122 gPad->SetBorderMode(0);
1123 h3.DrawCopy();
1124 p->cd(3);
1125 gPad->SetBorderMode(0);
1126 h2.DrawCopy();
1127 c->cd(6);
1128 gPad->Divide(1,2, 0, 0);
1129 TVirtualPad *q=gPad;
1130 q->SetBorderMode(0);
1131 q->cd(1);
1132 gPad->SetBorderMode(0);
1133 gPad->SetBorderMode(0);
1134 h4b.DrawCopy();
1135 h4a.DrawCopy("same");
1136 h6.DrawCopy("same");
1137 q->cd(2);
1138 gPad->SetBorderMode(0);
1139 //h5b.DrawCopy();
1140 //h5a.DrawCopy("same");
1141 c->cd(5);
1142 gPad->SetBorderMode(0);
1143 if (maxx>0 && maxy>0)
1144 {
1145 const TString title = MString::Format(" \\alpha for x=%.2f y=%.2f (S_{max}=%.1f\\sigma) ",
1146 hist->GetXaxis()->GetBinCenter(maxx),
1147 hist->GetYaxis()->GetBinCenter(maxy), maxs);
1148
1149 h = fHist.ProjectionZ("AlphaFit", maxx, maxx, maxy, maxy);
1150 h->Scale(entries/h->GetEntries());
1151
1152 h->SetDirectory(NULL);
1153 h->SetNameTitle("Result \\alpha", title);
1154 h->SetBit(kCanDelete);
1155 h->SetXTitle("\\alpha [\\circ]");
1156 h->SetYTitle("Counts");
1157 h->Draw();
1158
1159 if (fHistOff)
1160 {
1161 h->SetLineColor(kGreen);
1162
1163 TH1D *hof=fHistOff->ProjectionZ("AlphaFitOff", maxx, maxx, maxy, maxy);
1164 hof->Scale(entries/hof->GetEntries());
1165
1166 fit.Scale(*(TH1D*)hof, *(TH1D*)h);
1167
1168 hof->SetLineColor(kRed);
1169 hof->SetDirectory(NULL);
1170 hof->SetNameTitle("Result \\alpha", title);
1171 hof->SetBit(kCanDelete);
1172 hof->SetXTitle("\\alpha [\\circ]");
1173 hof->SetYTitle("Counts");
1174 hof->Draw("same");
1175
1176 TH1D *diff = (TH1D*)h->Clone("AlphaFitOnOff");
1177 diff->Add(hof, -1);
1178 diff->SetLineColor(kBlue);
1179 diff->SetNameTitle("Result On-Off \\alpha", title);
1180 diff->SetBit(kCanDelete);
1181 diff->SetXTitle("\\alpha [\\circ]");
1182 diff->SetYTitle("Counts");
1183 diff->Draw("same");
1184
1185 h->SetMinimum(diff->GetMinimum()<0 ? diff->GetMinimum()*1.2 : 0);
1186
1187 TLine l;
1188 l.DrawLine(0, 0, 90, 0);
1189 }
1190
1191 TF1 f1("f1", MString::Format("gaus(0) + pol%d(3)", fHistOff ? 0 : polynom).Data(), 0, 90);
1192 TF1 f2("f2", MString::Format("gaus(0) + pol%d(3)", fHistOff ? 0 : polynom).Data(), 0, 90);
1193 f1.SetParameters(maxpar.GetArray());
1194 f2.SetParameters(maxpar.GetArray());
1195 f2.FixParameter(0, 0);
1196 f2.FixParameter(1, 0);
1197 f2.FixParameter(2, 1);
1198 f1.SetLineColor(kGreen);
1199 f2.SetLineColor(kRed);
1200
1201 f2.DrawCopy("same");
1202 f1.DrawCopy("same");
1203
1204 TPaveText *leg = new TPaveText(0.35, 0.10, 0.90, 0.35, "brNDC");
1205 leg->SetBorderSize(1);
1206 leg->SetTextSize(0.04);
1207 leg->AddText(0.5, 0.82, MString::Format("A * exp(-(\\frac{x-\\mu}{\\sigma})^{2}/2) + pol%d", polynom))->SetTextAlign(22);
1208 //leg->AddText(0.5, 0.82, "A * exp(-(\\frac{x-\\mu}{\\sigma})^{2}/2) + b*x^{2} + a")->SetTextAlign(22);
1209 leg->AddLine(0, 0.65, 0, 0.65);
1210 leg->AddText(0.06, 0.54, MString::Format("A=%.2f", maxpar[0]))->SetTextAlign(11);
1211 leg->AddText(0.06, 0.34, MString::Format("\\sigma=%.2f", maxpar[2]))->SetTextAlign(11);
1212 leg->AddText(0.06, 0.14, MString::Format("\\mu=%.2f (fix)", maxpar[1]))->SetTextAlign(11);
1213 leg->AddText(0.60, 0.54, MString::Format("a=%.2f", maxpar[3]))->SetTextAlign(11);
1214 leg->AddText(0.60, 0.34, MString::Format("b=%.2f (fix)", maxpar[4]))->SetTextAlign(11);
1215 if (polynom>1)
1216 leg->AddText(0.60, 0.14, MString::Format("c=%.2f", !fHistOff?maxpar[5]:0))->SetTextAlign(11);
1217 leg->SetBit(kCanDelete);
1218 leg->Draw();
1219
1220 q->cd(2);
1221
1222 TGraph *g = new TGraph;
1223 g->SetPoint(0, 0, 0);
1224
1225 Int_t max=0;
1226 Float_t maxsig=0;
1227 for (int i=1; i<89; i++)
1228 {
1229 const Double_t s = f1.Integral(0, (float)i)/w;
1230 const Double_t b = f2.Integral(0, (float)i)/w;
1231
1232 const Double_t sig = MMath::SignificanceLiMaSigned(s, b);
1233
1234 g->SetPoint(g->GetN(), i, sig);
1235
1236 if (sig>maxsig)
1237 {
1238 max = i;
1239 maxsig = sig;
1240 }
1241 }
1242
1243 g->SetNameTitle("SigVs\\alpha", "Significance vs \\alpha");
1244 g->GetHistogram()->SetXTitle("\\alpha_{0} [\\circ]");
1245 g->GetHistogram()->SetYTitle("Significance");
1246 g->SetBit(kCanDelete);
1247 g->Draw("AP");
1248
1249 leg = new TPaveText(0.35, 0.10, 0.90, 0.25, "brNDC");
1250 leg->SetBorderSize(1);
1251 leg->SetTextSize(0.1);
1252 leg->AddText(MString::Format("S_{max}=%.1f\\sigma at \\alpha_{max}=%d\\circ", maxsig, max));
1253 leg->SetBit(kCanDelete);
1254 leg->Draw();
1255 }
1256}
1257
1258void MHFalseSource::DrawNicePlot() const
1259{
1260 Int_t newc = kTRUE;
1261 Float_t zoom = 0.95;
1262 Int_t col = kBlue+180;
1263
1264 if (!newc && !fDisplay)
1265 return;
1266
1267 TH1 *h = dynamic_cast<TH1*>(FindObjectInPad("Alpha_yx_on"));
1268 if (!h)
1269 return;
1270
1271 // Open and setup canvas/pad
1272 TCanvas &c = newc ? *new TCanvas("Excess", "Excess Plot", TMath::Nint(500.), TMath::Nint(500*0.77/0.89)) : fDisplay->AddTab("ThetsSq");
1273
1274 //c.SetPad(0.15, 0, 0.90, 1);
1275
1276 c.SetBorderMode(0);
1277 c.SetFrameBorderMode(0);
1278 c.SetFillColor(kWhite);
1279
1280 c.SetLeftMargin(0.11);
1281 c.SetRightMargin(0.12);
1282 c.SetBottomMargin(0.10);
1283 c.SetTopMargin(0.01);
1284
1285 TH1 *h1 = (TH1*)h->Clone("");
1286 h1->SetDirectory(0);
1287 h1->SetTitle("");
1288 h1->SetContour(99);
1289 h1->SetBit(TH1::kNoStats);
1290 h1->SetBit(TH1::kCanDelete);
1291
1292 if (h1->FindObject("stats"))
1293 delete h1->FindObject("stats");
1294
1295 TAxis &x = *h1->GetXaxis();
1296 TAxis &y = *h1->GetYaxis();
1297 TAxis &z = *h1->GetZaxis();
1298
1299 x.SetRangeUser(-zoom, zoom);
1300 y.SetRangeUser(-zoom, zoom);
1301
1302 x.SetTitleOffset(1.1);
1303 y.SetTitleOffset(1.3);
1304
1305 x.SetTickLength(0.025);
1306 y.SetTickLength(0.025);
1307
1308 x.SetAxisColor(kWhite);
1309 y.SetAxisColor(kWhite);
1310
1311 x.CenterTitle();
1312 y.CenterTitle();
1313
1314 x.SetTitle("Offset [#circ]");
1315 y.SetTitle("Offset [#circ]");
1316
1317 x.SetDecimals();
1318 y.SetDecimals();
1319 z.SetDecimals();
1320
1321 MH::SetPalette("glowsym", 99);
1322
1323 const Float_t max = TMath::Max(h1->GetMinimum(), h1->GetMaximum());
1324
1325 h1->SetMinimum(-max);
1326 h1->SetMaximum(max);
1327
1328 h1->Draw("colz");
1329
1330 // ------
1331 // Convert pave coordinates from NDC to Pad coordinates.
1332
1333 gPad->Update();
1334
1335 Float_t x0 = 0.80;
1336 Float_t y0 = 0.88;
1337
1338 Double_t dx = gPad->GetX2() - gPad->GetX1();
1339 Double_t dy = gPad->GetY2() - gPad->GetY1();
1340
1341 // Check if pave initialisation has been done.
1342 // This operation cannot take place in the Pave constructor because
1343 // the Pad range may not be known at this time.
1344 Float_t px = gPad->GetX1() + x0*dx;
1345 Float_t py = gPad->GetY1() + y0*dy;
1346 // -------
1347
1348 TEllipse *el = new TEllipse(px, py, 0.12, 0.12, 0, 360, 0);
1349 el->SetFillStyle(4100);
1350 el->SetFillColor(kBlack);
1351 el->SetLineWidth(2);
1352 el->SetLineColor(kWhite);
1353 el->SetBit(kCanDelete);
1354 el->Draw();
1355
1356 TString str1("el.SetX1(gPad->GetX1()+0.9*(gPad->GetX2()-gPad->GetX1()));");
1357 TString str2("el.SetY1(gPad->GetY1()+0.9*(gPad->GetY2()-gPad->GetY1()));");
1358
1359 str1.ReplaceAll("el.", MString::Format("((TEllipse*)%p)->", el));
1360 str2.ReplaceAll("el.", MString::Format("((TEllipse*)%p)->", el));
1361
1362 str1.ReplaceAll("0.9", MString::Format("%f", x0));
1363 str2.ReplaceAll("0.9", MString::Format("%f", y0));
1364
1365 TLatex tex;
1366 tex.SetBit(TText::kTextNDC);
1367 tex.SetTextColor(kWhite);
1368 tex.SetTextAlign(22);
1369 tex.SetTextSize(0.04);
1370 tex.SetTextAngle(0);
1371 tex.DrawLatex(x0, y0, "psf");
1372
1373 TPad *pad = new TPad("pad", "Catalog Pad",
1374 c.GetLeftMargin(), c.GetBottomMargin(),
1375 1-c.GetRightMargin(), 1-c.GetTopMargin());
1376
1377 pad->SetFillStyle(4000);
1378 pad->SetFillColor(kBlack);
1379 pad->SetBorderMode(0);
1380 pad->SetFrameBorderMode(0);
1381 pad->SetBit(kCanDelete);
1382 pad->Draw();
1383
1384 pad->Range(x.GetBinLowEdge(x.GetFirst()),
1385 y.GetBinLowEdge(y.GetFirst()),
1386 x.GetBinLowEdge(x.GetLast()+1),
1387 y.GetBinLowEdge(y.GetLast()+1));
1388
1389 TString str3("pad->Range(x.GetBinLowEdge(x.GetFirst()),"
1390 "y.GetBinLowEdge(y.GetFirst()),"
1391 "x.GetBinLowEdge(x.GetLast()+1),"
1392 "y.GetBinLowEdge(y.GetLast()+1));");
1393
1394 str3.ReplaceAll("x.", MString::Format("((TAxis*)%p)->", &x));
1395 str3.ReplaceAll("y.", MString::Format("((TAxis*)%p)->", &y));
1396 // str3.ReplaceAll("pad", Form("((TPad*)(%p))", pad));
1397
1398 c.AddExec("SetPosX", str1);
1399 c.AddExec("SetPosY", str2);
1400 c.AddExec("Resize", str3);
1401
1402 pad->cd();
1403 gROOT->SetSelectedPad(0);
1404
1405 MAstroCatalog *cat = (MAstroCatalog*)GetCatalog();
1406
1407 cat->GetAttLineSky().SetLineColor(col);
1408 cat->GetAttLineSky().SetLineWidth(2);
1409 cat->GetAttLineSky().SetLineStyle(7);
1410
1411 cat->GetList()->Clear();
1412 cat->SetBit(kCanDelete);
1413 // cat->AddObject(MAstro::Hms2Hor(12,17,52)*TMath::Pi()/12, TMath::DegToRad()*MAstro::Dms2Deg(30,7,0), 6, "1ES1215+303");
1414 // cat->AddObject(MAstro::Hms2Hor(12,18,27)*TMath::Pi()/12, TMath::DegToRad()*MAstro::Dms2Deg(29,48,46), 6, "Mrk766");
1415
1416 cat->Draw("mirror same");
1417
1418 /*
1419 Int_t col = kBlue+180;
1420
1421 TLatex tex;
1422 tex.SetTextColor(col);
1423 tex.SetTextAlign(21);
1424 tex.SetTextSize(0.04);
1425 tex.DrawLatex(-0.79, -0.8, "43.0\\circ");
1426 tex.DrawLatex(-0.78, 0.2, "42.0\\circ");
1427
1428 tex.SetTextAngle(-90);
1429 tex.DrawLatex(-0.45, -0.55, "22.00h");
1430 tex.DrawLatex( 0.30, -0.55, "22.07h");
1431 */
1432}
Note: See TracBrowser for help on using the repository browser.