source: trunk/MagicSoft/Mars/mtemp/mifae/macros/signal.C@ 6723

Last change on this file since 6723 was 4094, checked in by rico, 21 years ago
*** empty log message ***
File size: 4.6 KB
Line 
1/////////////////////////////////////////////////////////////////////////////
2//
3// This macro makes the two-dimension plot of the False Source Method:
4// root > .x signal.C(TString name, TString psname)
5//
6// Ester Aliu <aliu@ifae.es>
7// Oscar Blanch <blanch@ifae.es>
8// Javier Rico <jrico@ifae.es>
9////////////////////////////////////////////////////////////////////////////
10void signal(
11TString fname ="hillasCrab/falseSourceCrab20040215.root",
12TString psname ="kk.ps")
13{
14 Float_t excess;
15 Float_t significance;
16 Float_t array[2];
17
18 Int_t nbin2d = 5;
19 Int_t ntotal = 2*nbin2d+1;
20
21 Int_t nx = 0;
22 Int_t ny = 0;
23
24 Float_t max = -10000;
25 Int_t imax;
26 Int_t jmax;
27 Float_t A ;
28 Float_t B;
29
30 TH2F *hsignif = new TH2F("hsignif","Significance", ntotal, -1.0, 1.0, ntotal, -1.0, 1.0);
31 TH2F *hexcess = new TH2F("hexcess","Excess", ntotal, -1.0, 1.0, ntotal, -1.0, 1.0);
32
33
34 // loop on the histos and compute excess and significance
35 for( Int_t i = -nbin2d; i <= nbin2d ; i++)
36 {
37 nx++;
38 ny = 0;
39 for( Int_t j = -nbin2d; j <= nbin2d ; j++)
40 {
41 ny++;
42 step_signal(i,j,&array[0], fname);
43
44 excess = array[0];
45 significance = array[1];
46
47 hexcess->SetBinContent(nx, ny, excess);
48 hsignif->SetBinContent(nx, ny, significance);
49
50 if ( significance > max)
51 {
52 max = significance;
53 imax = i;
54 jmax = j;
55 A = excess;
56 B = significance;
57 }
58 }
59 }
60
61 cout << "The position of maximum significance is ( " << imax << " , " << jmax << " )" << endl;
62 cout << "Excess: " << A << endl;
63 cout << "Significance: " << B << endl;
64
65 // Plot
66 gROOT->Reset();
67 gStyle->SetCanvasColor(0);
68 gStyle->SetCanvasBorderMode(0);
69 gStyle->SetPadBorderMode(0);
70 gStyle->SetFrameBorderMode(0);
71 gStyle->SetOptTitle(0);
72 gStyle->SetTitleOffset(1.7,"y");
73 gStyle->SetPadLeftMargin(0.15);
74 gStyle->SetOptStat(kFALSE);
75 gStyle->SetStatColor(0);
76 gStyle->SetStatBorderSize(1);
77 gStyle->SetStatW(0.2);
78 gStyle->SetStatH(0.1);
79 gStyle->SetStatX(0.9);
80 gStyle->SetStatY(0.9);
81
82
83 TPostScript myps(psname,111);
84 myps.Range(15,15);
85 TCanvas *c2d = new TCanvas("c2d", "Matrices", 0, 0, 800,800);
86 c2d->Divide(2,2);
87 gStyle->SetPalette(1);
88
89 c2d->cd(1);
90 hexcess->Draw("colz");
91 hexcess->SetXTitle("X position (deg)");
92 hexcess->SetYTitle("Y position (deg)");
93 gPad->Update();
94
95 c2d->cd(2);
96 hsignif->Draw("colz");
97 hsignif->SetXTitle("X position (deg)");
98 hsignif->SetYTitle("Y position (deg)");
99 gPad->Update();
100
101 c2d->cd(3);
102 hexcess->Draw("lego2");
103 hexcess->SetXTitle("X position (deg)");
104 hexcess->SetYTitle("Y position (deg)");
105 gPad->Update();
106
107 c2d->cd(4);
108 hsignif->Draw("lego2");
109 hsignif->SetXTitle("X position (deg)");
110 hsignif->SetYTitle("Y position (deg)");
111 gPad->Update();
112
113 myps.Close();
114}
115
116
117void step_signal(Int_t i, Int_t j, Float_t *array, TString fname)
118{
119 cout << "Bin (" << i << "," << j << ")" << endl;
120 TH1F *onhisto;
121 TH1F *offhisto;
122
123 // open file and access to the histograms
124 TFile *f = new TFile(fname);
125 Char_t name[20];
126 Char_t title[50];
127
128 // histo name
129 sprintf(name,"hOnAlpha[%d][%d]", i, j);
130 sprintf(title,"Alpha-Plot(On data) (%d ,%d)", i, j);
131 onhisto = (TH1F*)gDirectory->Get(name);
132
133 sprintf(name,"hOffAlpha[%d][%d]", i, j);
134 sprintf(title,"Alpha-Plot(Off data) (%d ,%d)", i, j);
135 offhisto = (TH1F*)gDirectory->Get(name);
136
137 // line/normalization
138 const Int_t nbins = 18;
139 const Int_t inibin = 20./90.*nbins+1;
140 Float_t level=0;
141 Float_t leveloff=0;
142 Float_t levelofferror=0;
143 for(Int_t ibin = inibin; ibin<=nbins;ibin++)
144 {
145 level+=onhisto->GetBinContent(ibin);
146 leveloff+=offhisto->GetBinContent(ibin);
147 }
148 level/=(nbins-inibin+1);
149 leveloff/=(nbins-inibin+1);
150
151 // normalize on/off
152 offhisto->Sumw2(); // needed to compute correct errors after normalization
153 const Float_t norm = level/leveloff;
154 cout << "Normalizing by factor " << norm <<endl;
155 offhisto->Scale(norm);
156
157 // significance:
158 Float_t sig=0,bg=0,esig=0,ebg=0;
159 Float_t significance=0;
160 const Int_t signbins = inibin-1;
161 for(Int_t ibin = 1; ibin<=signbins;ibin++)
162 {
163 sig += onhisto->GetBinContent(ibin);
164 esig += onhisto->GetBinError(ibin)*onhisto->GetBinError(ibin);
165 bg += offhisto->GetBinContent(ibin);
166 ebg += offhisto->GetBinError(ibin)*offhisto->GetBinError(ibin);
167 }
168 Float_t error= TMath::Sqrt(esig+ebg);
169 Float_t excess = sig-bg;
170 Float_t significance = excess/error;
171
172 cout << "Excess: " << excess << endl;
173 cout << "Significance: " << significance << endl;
174
175 array[0] = excess;
176 array[1] = significance;
177}
178
179
180
Note: See TracBrowser for help on using the repository browser.