source: trunk/MagicSoft/Mars/mtemp/mifae/macros/signalPoint.C@ 4308

Last change on this file since 4308 was 3973, checked in by rico, 21 years ago
*** empty log message ***
File size: 3.8 KB
Line 
1/////////////////////////////////////////////////////////////////////////////
2//
3// This macro makes the alpha-plot for one of the positions of the
4// False Source Method:
5//
6// Ester Aliu <aliu@ifae.es>
7// Oscar Blanch <blanch@ifae.es>
8// Javier Rico <jrico@ifae.es>
9////////////////////////////////////////////////////////////////////////////
10
11void signalPoint(Int_t i=0, Int_t j=0, TString fname="hillasCrab/falseSourceCrab20040215.root")
12{
13 // constants
14 const Int_t nbins = 18;
15
16 // general settings
17 gROOT->Reset();
18 gStyle->SetCanvasColor(0);
19 gStyle->SetCanvasBorderMode(0);
20 gStyle->SetPadBorderMode(0);
21 gStyle->SetFrameBorderMode(0);
22 gStyle->SetOptTitle(0);
23 gStyle->SetTitleOffset(1.7,"y");
24 gStyle->SetPadLeftMargin(0.15);
25 gStyle->SetOptStat(111110);
26 gStyle->SetStatColor(0);
27 gStyle->SetStatBorderSize(1);
28 gStyle->SetStatW(0.2);
29 gStyle->SetStatH(0.1);
30 gStyle->SetStatX(0.9);
31 gStyle->SetStatY(0.9);
32
33
34 // open file and access to the histograms
35 TFile *f = new TFile(fname);
36
37 Char_t name[20];
38 Char_t title[50];
39
40 sprintf(name,"hOnAlpha[%d][%d]", i, j);
41 sprintf(title,"Alpha-Plot(On data) (%d ,%d)", i, j);
42 TH1F* onhisto = (TH1F*)gDirectory->Get(name);
43
44 sprintf(name,"hOffAlpha[%d][%d]", i, j);
45 sprintf(title,"Alpha-Plot(Off data) (%d ,%d)", i, j);
46 TH1F* offhisto = (TH1F*)gDirectory->Get(name);
47
48 TPostScript myps("signalpoint.ps",111);
49 myps.Range(15,15);
50 TCanvas *c1 = new TCanvas("c1","c1",800,600);
51 c1->cd(1);
52
53 // line/normalization
54 const Int_t inibin = 20./90.*nbins+1;
55 Float_t level=0;
56 Float_t leveloff=0;
57 Float_t levelofferror=0;
58 for(Int_t ibin = inibin; ibin<=nbins;ibin++)
59 {
60 level+=onhisto->GetBinContent(ibin);
61 leveloff+=offhisto->GetBinContent(ibin);
62 }
63 level/=(nbins-inibin+1);
64 leveloff/=(nbins-inibin+1);
65
66 // normalize on/off
67 offhisto->Sumw2(); // needed to compute correct errors after normalization
68 const Float_t norm = level/leveloff;
69 cout << "Normalizing by factor " << norm <<endl;
70 offhisto->Scale(norm);
71
72 // significance:
73 Float_t sig=0,bg=0,esig=0,ebg=0;
74 Float_t significance=0;
75 const Int_t signbins = inibin-1;
76 for(Int_t ibin = 1; ibin<=signbins;ibin++)
77 {
78 // Float_t sigma = (onhisto->GetBinContent(ibin)-level)/onhisto->GetBinError(ibin);
79 // significance+=sigma*sigma;
80 sig += onhisto->GetBinContent(ibin);
81 esig += onhisto->GetBinError(ibin)*onhisto->GetBinError(ibin);
82 bg += offhisto->GetBinContent(ibin);
83 ebg += offhisto->GetBinError(ibin)*offhisto->GetBinError(ibin);
84 }
85 Float_t error= TMath::Sqrt(esig+ebg);
86 significance = (sig-bg)/error;
87
88 cout << "Significance: " << significance << endl;
89
90 // plot
91 onhisto->SetXTitle("alpha (deg)");
92 onhisto->SetYTitle("Entries");
93 onhisto->SetMarkerColor(4);
94 onhisto->SetMarkerStyle(20);
95 onhisto->SetMarkerSize(.7);
96 onhisto->SetLineColor(4);
97 onhisto->SetMaximum(onhisto->GetBinContent(nbins)*1.5);
98
99 offhisto->SetFillColor(2);
100 offhisto->SetMaximum(offhisto->GetBinContent(nbins)*1.5);
101 offhisto->SetXTitle("alpha (deg)");
102 offhisto->SetYTitle("Entries");
103
104 offhisto->Draw("HIST");
105 offhisto->Draw("ESAME");
106 onhisto->Draw("ESAMES");
107 // onhisto->Draw("E");
108
109 // move stat box to make them all visible
110 gPad->Update();
111 TPaveStats* offpavstat = (TPaveStats*) offhisto->GetListOfFunctions()->FindObject("stats");
112 if(offpavstat)
113 {
114 Float_t shiftx = offpavstat->GetX2NDC()-offpavstat->GetX1NDC();
115 offpavstat->SetX1NDC(offpavstat->GetX1NDC()-shiftx);
116 offpavstat->SetX2NDC(offpavstat->GetX2NDC()-shiftx);
117 }
118
119 // draw line
120 TLine* line = new TLine(0.,level,90.,level);
121 line->SetLineColor(2);
122 line->SetLineStyle(2);
123 // line->Draw();
124
125 gPad->Modified();
126 gPad->Update();
127
128 myps.Close();
129}
130
131
Note: See TracBrowser for help on using the repository browser.