1 | /* ======================================================================== *\!
|
---|
2 | ! Author(s): Oscar Blanch & Javier Rico
|
---|
3 | \* ======================================================================== */
|
---|
4 |
|
---|
5 | void alpha(
|
---|
6 | Float_t cutsize=2000,
|
---|
7 | Float_t upcutsize=9999999,
|
---|
8 | Float_t lengthlowcut=0.,
|
---|
9 | Float_t lengthcut=0.26,
|
---|
10 | Float_t widthlowcut=0.,
|
---|
11 | Float_t widthcut=0.12
|
---|
12 | )
|
---|
13 | {
|
---|
14 | // constants
|
---|
15 | const Int_t nbins = 18;
|
---|
16 | TString psname("alphaMrk.gif");
|
---|
17 | // general settings
|
---|
18 | gROOT->Reset();
|
---|
19 | gStyle->SetCanvasColor(0);
|
---|
20 | gStyle->SetCanvasBorderMode(0);
|
---|
21 | gStyle->SetPadBorderMode(0);
|
---|
22 | gStyle->SetFrameBorderMode(0);
|
---|
23 | gStyle->SetOptTitle(0);
|
---|
24 | gStyle->SetTitleOffset(1.7,"y");
|
---|
25 | gStyle->SetPadLeftMargin(0.15);
|
---|
26 | gStyle->SetOptStat(111110);
|
---|
27 | gStyle->SetStatColor(0);
|
---|
28 | gStyle->SetStatBorderSize(1);
|
---|
29 | gStyle->SetStatW(0.2);
|
---|
30 | gStyle->SetStatH(0.1);
|
---|
31 | gStyle->SetStatX(0.9);
|
---|
32 | gStyle->SetStatY(0.9);
|
---|
33 |
|
---|
34 | // define files, chain, trees, canvas...
|
---|
35 | TChain* ton= new TChain("Parameters");
|
---|
36 |
|
---|
37 | // ON data
|
---|
38 | ton->Add("/mnt/users/jrico/magic/mars/mars/mtemp/mifae/programs/srcPosPrueba.root");
|
---|
39 |
|
---|
40 | TChain* toff= new TChain("Parameters");
|
---|
41 |
|
---|
42 | // OFF data
|
---|
43 | toff->Add("/mnt/users/jrico/magic/mars/mars/mtemp/mifae/programs/srcPosOffPrueba.root");
|
---|
44 |
|
---|
45 | TCanvas *c1 = new TCanvas("c1","c1",800,500);
|
---|
46 | c1->cd(1);
|
---|
47 |
|
---|
48 | // define aliases
|
---|
49 | ton->SetAlias("length","MHillas.fLength*0.6/189");
|
---|
50 | ton->SetAlias("width","MHillas.fWidth*0.6/189");
|
---|
51 | ton->SetAlias("dist","MHillasSrc.fDist*0.6/189");
|
---|
52 | ton->SetAlias("conc","MNewImagePar.fConc");
|
---|
53 | ton->SetAlias("size","MHillas.fSize");
|
---|
54 | ton->SetAlias("event","MRawEvtHeader.fDAQEvtNumber");
|
---|
55 | ton->SetAlias("alpha","abs(MHillasSrc.fAlpha)");
|
---|
56 |
|
---|
57 | toff->SetAlias("length","MHillas.fLength*0.6/189");
|
---|
58 | toff->SetAlias("width","MHillas.fWidth*0.6/189");
|
---|
59 | toff->SetAlias("dist","MHillasSrc.fDist*0.6/189");
|
---|
60 | toff->SetAlias("conc","MNewImagePar.fConc");
|
---|
61 | toff->SetAlias("size","MHillas.fSize");
|
---|
62 | toff->SetAlias("event","MRawEvtHeader.fDAQEvtNumber");
|
---|
63 | toff->SetAlias("alpha","abs(MHillasSrc.fAlpha)");
|
---|
64 |
|
---|
65 | // define cut(s)
|
---|
66 | // const char* eventcut="event%3==0 &&";
|
---|
67 | const char* eventcut="";
|
---|
68 | const char varcut[512];
|
---|
69 | // sprintf(varcut,"size>%f && size<%f && length>%f &&length<%f && width>%f && width<%f",cutsize,upcutsize,lengthlowcut,lengthcut,widthlowcut,widthcut);
|
---|
70 | sprintf(varcut,"size>%f && size<%f && dist>0.2 && dist<1.1 && length>%f &&length<%f && width>%f && width<%f",cutsize,upcutsize,lengthlowcut,lengthcut,widthlowcut,widthcut);
|
---|
71 | // sprintf(varcut,"size>%f && dist>0.2 && dist<0.8 && length<0.21 && width<0.125",cutsize,upcutsize,lengthcut,widthcut);
|
---|
72 | // sprintf(varcut,"size>%f && size<%f && dist>0.2 && dist<0.8 && length<0.21 && width<0.125",cutsize,upcutsize);
|
---|
73 | // sprintf(varcut,"size>%f && size<%f && dist>0.2 && dist<0.8 && length<0.21",cutsize,upcutsize);
|
---|
74 | // sprintf(varcut,"size>%f && size<%f && dist>0.2 && dist<0.8",cutsize,upcutsize);
|
---|
75 | // sprintf(varcut,"size>%f && size<%f",cutsize,upcutsize)
|
---|
76 | // sprintf(varcut,"");
|
---|
77 | Char_t cut[256];
|
---|
78 | Char_t cutoff[256];
|
---|
79 | strcat(cut,eventcut);
|
---|
80 | strcat(cut,varcut);
|
---|
81 | strcat(cutoff,varcut);
|
---|
82 |
|
---|
83 | // fill on/off histos
|
---|
84 | TH1F* onhisto = new TH1F("OnHist" ,"Alpha Plot",nbins,0,90);
|
---|
85 | TH1F* offhisto = new TH1F("OffHist","Alpha Plot",nbins,0,90);
|
---|
86 | ton->Draw("alpha>>OnHist",cut);
|
---|
87 | toff->Draw("alpha>>OffHist",cutoff);
|
---|
88 | cout << "Applied cut: " << cut << endl;
|
---|
89 |
|
---|
90 | // line/normalization
|
---|
91 | const Int_t inibin = 20./90.*nbins+1;
|
---|
92 | Float_t level=0;
|
---|
93 | Float_t leveloff=0;
|
---|
94 | Float_t levelofferror=0;
|
---|
95 | for(Int_t ibin = inibin; ibin<=nbins;ibin++)
|
---|
96 | {
|
---|
97 | level+=onhisto->GetBinContent(ibin);
|
---|
98 | leveloff+=offhisto->GetBinContent(ibin);
|
---|
99 | }
|
---|
100 | level/=(nbins-inibin+1);
|
---|
101 | leveloff/=(nbins-inibin+1);
|
---|
102 |
|
---|
103 | // normalize on/off
|
---|
104 | offhisto->Sumw2(); // needed to compute correct errors after normalization
|
---|
105 | const Float_t norm = level/leveloff;
|
---|
106 | cout << "Normalizing by factor " << norm <<endl;
|
---|
107 | offhisto->Scale(norm);
|
---|
108 |
|
---|
109 | // significance:
|
---|
110 | Float_t sig=0,bg=0,esig=0,ebg=0;
|
---|
111 | Float_t significance=0;
|
---|
112 | const Int_t signbins = inibin-1;
|
---|
113 | for(Int_t ibin = 1; ibin<=signbins;ibin++)
|
---|
114 | {
|
---|
115 | // Float_t sigma = (onhisto->GetBinContent(ibin)-level)/onhisto->GetBinError(ibin);
|
---|
116 | // significance+=sigma*sigma;
|
---|
117 | sig += onhisto->GetBinContent(ibin);
|
---|
118 | esig += onhisto->GetBinError(ibin)*onhisto->GetBinError(ibin);
|
---|
119 | bg += offhisto->GetBinContent(ibin);
|
---|
120 | ebg += offhisto->GetBinError(ibin)*offhisto->GetBinError(ibin);
|
---|
121 | }
|
---|
122 | Float_t error= TMath::Sqrt(esig+ebg);
|
---|
123 | significance = (sig-bg)/error;
|
---|
124 |
|
---|
125 | cout << "Excess: " << sig-bg << endl;
|
---|
126 | cout << "N bkg: " << bg << endl;
|
---|
127 | cout << "Significance: " << significance << endl;
|
---|
128 |
|
---|
129 | // plot
|
---|
130 | onhisto->SetXTitle("alpha (deg)");
|
---|
131 | onhisto->SetYTitle("Entries");
|
---|
132 | onhisto->SetMarkerColor(4);
|
---|
133 | onhisto->SetMarkerStyle(20);
|
---|
134 | onhisto->SetMarkerSize(.7);
|
---|
135 | onhisto->SetLineColor(4);
|
---|
136 | onhisto->SetMaximum(onhisto->GetBinContent(nbins)*1.5);
|
---|
137 |
|
---|
138 | offhisto->SetFillColor(2);
|
---|
139 | offhisto->SetMaximum(offhisto->GetBinContent(nbins)*1.5);
|
---|
140 | offhisto->SetXTitle("alpha (deg)");
|
---|
141 | offhisto->SetYTitle("Entries");
|
---|
142 |
|
---|
143 | offhisto->Draw("HIST");
|
---|
144 | offhisto->Draw("ESAME");
|
---|
145 | onhisto->Draw("ESAMES");
|
---|
146 | // onhisto->Draw("E");
|
---|
147 |
|
---|
148 | // move stat box to make them all visible
|
---|
149 | gPad->Update();
|
---|
150 | TPaveStats* offpavstat = (TPaveStats*) offhisto->GetListOfFunctions()->FindObject("stats");
|
---|
151 | if(offpavstat)
|
---|
152 | {
|
---|
153 | Float_t shiftx = offpavstat->GetX2NDC()-offpavstat->GetX1NDC();
|
---|
154 | offpavstat->SetX1NDC(offpavstat->GetX1NDC()-shiftx);
|
---|
155 | offpavstat->SetX2NDC(offpavstat->GetX2NDC()-shiftx);
|
---|
156 | }
|
---|
157 |
|
---|
158 | // draw line
|
---|
159 | TLine* line = new TLine(0.,level,90.,level);
|
---|
160 | line->SetLineColor(2);
|
---|
161 | line->SetLineStyle(2);
|
---|
162 | // line->Draw();
|
---|
163 |
|
---|
164 | gPad->Modified();
|
---|
165 | gPad->Update();
|
---|
166 |
|
---|
167 | // produce ps
|
---|
168 | // char psname[50];
|
---|
169 | // sprintf(psname,"%s.ps",var);
|
---|
170 | c1->Print(psname);
|
---|
171 | }
|
---|
172 |
|
---|
173 |
|
---|