1 | /////////////////////////////////////////////////////////////////////////////
|
---|
2 | //
|
---|
3 | // This macro makes the two-dimension plot of the False Source Method:
|
---|
4 | // root > .x signal.C(TString name)
|
---|
5 | //
|
---|
6 | // Ester Aliu <aliu@ifae.es>
|
---|
7 | // Oscar Blanch <blanch@ifae.es>
|
---|
8 | // Javier Rico <jrico@ifae.es>
|
---|
9 | ////////////////////////////////////////////////////////////////////////////
|
---|
10 | void signal(TString fname ="hillasCrab/falseSourceCrab20040215Derotate.root")
|
---|
11 | {
|
---|
12 | Float_t excess;
|
---|
13 | Float_t significance;
|
---|
14 | Float_t array[2];
|
---|
15 |
|
---|
16 | Int_t nbin2d = 10;
|
---|
17 | Int_t ntotal = 2*nbin2d+1;
|
---|
18 |
|
---|
19 | Int_t nx = 0;
|
---|
20 | Int_t ny = 0;
|
---|
21 |
|
---|
22 | TH2F *hsignif = new TH2F("hsignif","Significance", ntotal, -1.0, 1.0, ntotal, -1.0, 1.0);
|
---|
23 | TH2F *hexcess = new TH2F("hexcess","Excess", ntotal, -1.0, 1.0, ntotal, -1.0, 1.0);
|
---|
24 |
|
---|
25 | // loop on the histos and compute excess and significance
|
---|
26 | for( Int_t i = -nbin2d; i <= nbin2d ; i++)
|
---|
27 | {
|
---|
28 | nx++;
|
---|
29 | ny = 0;
|
---|
30 | for( Int_t j = -nbin2d; j <= nbin2d ; j++)
|
---|
31 | {
|
---|
32 | ny++;
|
---|
33 | step_signal(i,j,&array[0], fname);
|
---|
34 |
|
---|
35 | excess = array[0];
|
---|
36 | significance = array[1];
|
---|
37 | hexcess->SetBinContent(nx, ny, excess);
|
---|
38 | hsignif->SetBinContent(nx, ny, significance);
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 |
|
---|
43 | // Plot
|
---|
44 | TPostScript myps("signal.ps",111);
|
---|
45 | myps.Range(15,15);
|
---|
46 | TCanvas *c2d = new TCanvas("c2d", "Matrices", 0, 0, 800,800);
|
---|
47 | c2d->Divide(2,2);
|
---|
48 | gStyle->SetPalette(1);
|
---|
49 | gStyle->SetOptStat(kFALSE);
|
---|
50 |
|
---|
51 | c2d->cd(1);
|
---|
52 | hexcess->Draw("colz");
|
---|
53 | hexcess->SetXTitle("X position (deg)");
|
---|
54 | hexcess->SetYTitle("Y position (deg)");
|
---|
55 | gPad->Update();
|
---|
56 |
|
---|
57 | c2d->cd(2);
|
---|
58 | hsignif->Draw("colz");
|
---|
59 | hsignif->SetXTitle("X position (deg)");
|
---|
60 | hsignif->SetYTitle("Y position (deg)");
|
---|
61 | gPad->Update();
|
---|
62 |
|
---|
63 | c2d->cd(3);
|
---|
64 | hexcess->Draw("lego2");
|
---|
65 | hexcess->SetXTitle("X position (deg)");
|
---|
66 | hexcess->SetYTitle("Y position (deg)");
|
---|
67 | gPad->Update();
|
---|
68 |
|
---|
69 | c2d->cd(4);
|
---|
70 | hsignif->Draw("lego2");
|
---|
71 | hsignif->SetXTitle("X position (deg)");
|
---|
72 | hsignif->SetYTitle("Y position (deg)");
|
---|
73 | gPad->Update();
|
---|
74 |
|
---|
75 | myps.Close();
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | void step_signal(Int_t i, Int_t j, Float_t *array, TString fname)
|
---|
80 | {
|
---|
81 | cout << "Bin (" << i << "," << j << ")" << endl;
|
---|
82 | TH1F *onhisto;
|
---|
83 | TH1F *offhisto;
|
---|
84 |
|
---|
85 | // open file and access to the histograms
|
---|
86 | TFile *f = new TFile(fname);
|
---|
87 | Char_t name[20];
|
---|
88 | Char_t title[50];
|
---|
89 |
|
---|
90 | // histo name
|
---|
91 | sprintf(name,"hOnAlpha[%d][%d]", i, j);
|
---|
92 | sprintf(title,"Alpha-Plot(On data) (%d ,%d)", i, j);
|
---|
93 | onhisto = (TH1F*)gDirectory->Get(name);
|
---|
94 |
|
---|
95 | sprintf(name,"hOffAlpha[%d][%d]", i, j);
|
---|
96 | sprintf(title,"Alpha-Plot(Off data) (%d ,%d)", i, j);
|
---|
97 | offhisto = (TH1F*)gDirectory->Get(name);
|
---|
98 |
|
---|
99 | // line/normalization
|
---|
100 | const Int_t nbins = 18;
|
---|
101 | const Int_t inibin = 20./90.*nbins+1;
|
---|
102 | Float_t level=0;
|
---|
103 | Float_t leveloff=0;
|
---|
104 | Float_t levelofferror=0;
|
---|
105 | for(Int_t ibin = inibin; ibin<=nbins;ibin++)
|
---|
106 | {
|
---|
107 | level+=onhisto->GetBinContent(ibin);
|
---|
108 | leveloff+=offhisto->GetBinContent(ibin);
|
---|
109 | }
|
---|
110 | level/=(nbins-inibin+1);
|
---|
111 | leveloff/=(nbins-inibin+1);
|
---|
112 |
|
---|
113 | // normalize on/off
|
---|
114 | offhisto->Sumw2(); // needed to compute correct errors after normalization
|
---|
115 | const Float_t norm = level/leveloff;
|
---|
116 | cout << "Normalizing by factor " << norm <<endl;
|
---|
117 | offhisto->Scale(norm);
|
---|
118 |
|
---|
119 | // significance:
|
---|
120 | Float_t sig=0,bg=0,esig=0,ebg=0;
|
---|
121 | Float_t significance=0;
|
---|
122 | const Int_t signbins = inibin-1;
|
---|
123 | for(Int_t ibin = 1; ibin<=signbins;ibin++)
|
---|
124 | {
|
---|
125 | sig += onhisto->GetBinContent(ibin);
|
---|
126 | esig += onhisto->GetBinError(ibin)*onhisto->GetBinError(ibin);
|
---|
127 | bg += offhisto->GetBinContent(ibin);
|
---|
128 | ebg += offhisto->GetBinError(ibin)*offhisto->GetBinError(ibin);
|
---|
129 | }
|
---|
130 | Float_t error= TMath::Sqrt(esig+ebg);
|
---|
131 | Float_t excess = sig-bg;
|
---|
132 | Float_t significance = excess/error;
|
---|
133 |
|
---|
134 | cout << "Excess: " << excess << endl;
|
---|
135 | cout << "Significance: " << significance << endl;
|
---|
136 |
|
---|
137 | array[0] = excess;
|
---|
138 | array[1] = significance;
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 |
|
---|