19 #define MAX_EVT 100 // max number of events 21 #define NLOOP 100000 // used to compute the multiple trial p-value 27 #define DRAW_SIGMA_MEDIAN 29 #define DRAW_NAMES 4 // max number of displayed names 31 #define YMIN 0.001 // minimum y-axis p-value 33 #define SIGMA1 0.682689492137 34 #define SIGMA2 0.954499736104 35 #define SIGMA3 0.997300203937 43 TGraphAsymmErrors*
DrawBelt(
int N,
double pinf,
double psup, Color_t color);
49 if(FDR>1) {cout << endl <<
"DrawPvaluesPE Error, FDR must be [0,1]" << endl << endl;
exit(1);}
50 if(fmod(10*FDR,1)!=0) {cout << endl <<
"DrawPvaluesPE Error, FDR must be a multiple of 0.1" << endl << endl;
exit(1);}
53 gRandom->SetSeed(150914);
67 if (!in.good()) {cout <<
"DrawPvaluesPE Error Opening File : " << ifname.Data() << endl;
exit(1);}
74 cout <<
"READ EVENTS" << endl;
77 in >> gw_name[NEVT] >> dummy >> dummy >> match[NEVT] >> dummy >> pvalue[NEVT] >> dummy >> median[NEVT]
78 >> dummy >> l99[NEVT] >> dummy >> l90[NEVT] >> dummy >> l50[NEVT] >> dummy >> u50[NEVT] >> dummy >> u90[NEVT] >> dummy >> u99[NEVT];
80 cout << NEVT <<
" "<< gw_name[NEVT] <<
" "<< match[NEVT] <<
" "<< pvalue[NEVT] << endl;
90 TMath::Sort(NEVT,pvalue,index,
false);
98 for(
int n=0;
n<NEVT;
n++) {
101 spvalue[
n]=pvalue[
k];
102 sgw_name[
n]=gw_name[
k];
105 cout <<
"SORT EVENTS" << endl;
107 for(
int n=0;
n<NEVT;
n++) cout <<
n <<
"\t" << sindex[
n] <<
"\t" << sgw_name[
n] <<
"\t" << spvalue[
n] << endl;;
113 gStyle->SetFrameBorderMode(0);
115 gStyle->SetTitleFont(12,
"D");
116 TCanvas *
canvas =
new TCanvas(
"pvalue",
"pvalue", 300,40, 1000, 600);
122 canvas->SetFillColor(kWhite);
125 TGraph*
gr =
new TGraph(NEVT,sindex,spvalue);
126 if(
title) gr->SetTitle(
"p-values distribution ("+
label+
")");
else gr->SetTitle(
"");
130 gr->GetHistogram()->GetXaxis()->SetLimits(1,xMAX);
131 gr->GetYaxis()->SetRangeUser(spvalue[0],1.0);
132 if(spvalue[0]<
YMIN) gr->GetYaxis()->SetRangeUser(
YMIN,1.0);
133 gr->GetXaxis()->SetTitle(
"Cumulative number of events");
134 gr->GetYaxis()->SetTitle(
"p-value");
135 gr->GetYaxis()->SetRangeUser(0,1);
136 gr->GetXaxis()->SetTitleOffset(0.80);
137 gr->GetYaxis()->SetTitleOffset(0.80);
138 gr->GetXaxis()->CenterTitle(kTRUE);
139 gr->GetYaxis()->CenterTitle(kTRUE);
140 gr->GetXaxis()->SetTitleFont(132);
141 gr->GetXaxis()->SetLabelFont(132);
142 gr->GetYaxis()->SetTitleFont(132);
143 gr->GetYaxis()->SetLabelFont(132);
144 gr->GetXaxis()->SetTitleSize(0.045);
145 gr->GetXaxis()->SetLabelSize(0.045);
146 gr->GetYaxis()->SetTitleSize(0.045);
147 gr->GetYaxis()->SetLabelSize(0.045);
148 gr->GetYaxis()->SetLabelOffset(0.01);
149 gr->GetYaxis()->SetNdivisions(3);
152 gr->GetXaxis()->SetMoreLogLabels();
153 gr->GetXaxis()->SetNoExponent();
155 gr->SetLineColor(kGray+1);
157 gr->SetMarkerSize(1.3);
158 gr->SetMarkerColor(kGreen+2);
160 gr->SetMarkerStyle(20);
165 #ifdef SET_GRID_COLOR 167 gr->GetXaxis()->SetAxisColor(16);
168 gr->GetYaxis()->SetAxisColor(16);
171 double xmin = gr->GetHistogram()->GetXaxis()->GetXmin();
172 double xmax = gr->GetHistogram()->GetXaxis()->GetXmax();
175 double ymax = gPad->GetUymax();
176 cout <<
"xmin=" << xmin <<
" xmax=" << xmax << endl;
177 cout <<
"ymin=" << ymin <<
" ymax=" << ymax << endl;
180 frameLine[0] =
new TLine(xmin,ymin,xmax,ymin);
181 frameLine[1] =
new TLine(xmin,ymin,xmin,ymax);
182 frameLine[2] =
new TLine(xmax,ymin,xmax,ymax);
183 frameLine[3] =
new TLine(0.,ymax,xmax,ymax);
184 for(
int i=0;
i<2;
i++) frameLine[
i]->
Draw();
190 canvas->SetBottomMargin(0.15);
192 gr->GetHistogram()->SetMinimum(
YMIN);
193 gr->GetXaxis()->SetNdivisions(120);
194 gr->GetXaxis()->SetTitle(
"");
195 gr->GetXaxis()->SetLabelOffset(.05);
196 gr->GetXaxis()->SetLabelSize(0.03);
197 gr->GetXaxis()->CenterLabels();
198 for(
int n=0;
n<NEVT;
n++) gr->GetXaxis()->ChangeLabel(
n+1,45,-1,-1,-1,-1,sgw_name[
n]);
199 gr->GetXaxis()->ChangeLabel(NEVT+1,45,-1,-1,-1,-1,
" ");
204 #ifdef DRAW_SIGMA_MEDIAN 233 gr->GetYaxis()->SetNdivisions(10);
234 for(
int n=1;n<=30;n++) {
236 if(n>1 && n<=10) alpha=n*
YMIN;
237 if(n>10 && n<=20) alpha=(n-10)*0.01;
238 if(n>20 && n<=30) alpha=(n-20)*0.1;
240 fdr[n-1] =
new TF1(
"func",
"[0]*x", 1,
MAX_EVT);
241 fdr[n-1]->SetNpx(10000);
242 fdr[n-1]->SetParameter(0,alpha/NEVT);
243 fdr[n-1]->SetLineWidth(1);
244 fdr[n-1]->SetLineColor(kGray);
245 fdr[n-1]->SetLineStyle(1);
248 if(
fabs(alpha-FDR)<1.
e-6) {
250 fdr[n-1]->SetLineStyle(1);
251 fdr[n-1]->Draw(
"SAME");
259 double prob_min=1e20;
263 cout <<
"FDR EVENTS" << endl;
265 for(
int n=0;n<NEVT;n++) {
266 if(spvalue[n]>=fdr[fdr_id]->Eval(n+1))
continue;
269 cout << n <<
"\t" << sgw_name[
n] <<
"\tpvalue = " << spvalue[
n] <<
"\tprob = " << prob[
n] <<
"\tcl1 = " << cl1[
n] << endl;
270 if(prob[n]<prob_min) {prob_min=prob[
n];nmin=
n;}
277 cout << nmin <<
" " << sgw_name[nmin] <<
"\tpvalue = " << spvalue[nmin]
278 <<
"\tprob = " << prob_min <<
"\tlog10(prob_min) " << log10(prob_min) << endl;
285 for(
int i=0;
i<NEVT;
i++) pvalue[
i]=gRandom->Uniform(0,1);
288 TMath::Sort(NEVT,pvalue,index,
false);
291 for(
int n=0;n<NEVT;n++) {
293 if(pvalue[k]>=fdr[fdr_id]->Eval(n+1))
continue;
295 if(prob[n]<pmin[
l]) pmin[
l]=prob[
n];
302 if(pmin[
l]<prob_min) PVALUE+=1;
306 cout <<
"PVALUE " << PVALUE << endl;
309 if(
title) gr->SetTitle(
TString(gr->GetTitle())+TString::Format(
" - significance (#alpha=%.1f): %.4f",FDR,PVALUE));
else gr->SetTitle(
"");
311 #ifdef SHOW_OFFSOURCE_DISTRIBUTION 312 TH1F*
hist =
new TH1F(
"hist",
"hist",100,1
e-5,0);
314 hist->Fill(log10(pmin[
l]));
318 double xline[2]={log10(prob_min),log10(prob_min)};
319 double yline[2]={0,NLOOP};
320 TGraph*
line =
new TGraph(2,xline,yline);
321 line->SetLineColor(kRed);
324 gStyle->SetLineColor(kBlack);
325 canvas->SetLogx(
false);
331 TF1 *f3 =
new TF1(
"f3",
"log10(x)",
YMIN,0.999);
332 TGaxis *
A3 =
new TGaxis(
double(NEVT),0.0,
double(NEVT),1.0,
"f3",505,
"=SG");
333 A3->SetTitle(
"#alpha");
334 A3->CenterTitle(kTRUE);
335 A3->SetTitleFont(132);
336 A3->SetLabelFont(132);
337 A3->SetLabelSize(0.045);
338 A3->SetTickSize(0.02);
339 A3->SetLabelOffset(0.03);
340 A3->SetTitleSize(0.045);
341 A3->SetTitleOffset(0.4);
350 float yrange = spvalue[0]==0 ?
YMIN : spvalue[0];
358 float xfactor = 1 + (0.05 * 10./xrange);
359 float yfactor =1 - (0.30 * log10(yrange)/-3.0);
360 double xpos = sindex[
n]*xfactor;
361 double ypos = spvalue[
n]*yfactor;
362 if(ypos<
YMIN) ypos=1.1*(2-yfactor)*
YMIN;
366 box =
new TBox(xpos, ypos*(2-yfactor), xpos*1.33*xfactor, ypos*(2-yfactor)*yfactor);
368 box->SetFillColor(kWhite);
371 latex =
new TLatex(xpos, ypos, sgw_name[n].Data());
372 latex->SetTextFont(132);
373 latex->SetTextSize(0.035);
374 latex->SetTextColor(kBlack);
378 ypos = spvalue[
n]*yfactor;
380 xpos = xpos*1.14*xfactor;
382 arrow =
new TArrow(xpos,ypos*(2-yfactor),xpos,ypos,0.05,
"|>");
384 arrow->SetLineWidth(2);
385 arrow->SetLineColor(kBlue);
386 arrow->SetFillColor(kBlue);
387 arrow->SetArrowSize(0.012);
397 TLegend *leg =
new TLegend(0.501002,0.1184669,0.8897796,0.3501742,NULL,
"brNDC");
398 leg->SetBorderSize(1);
399 leg->SetTextAlign(22);
400 leg->SetTextFont(12);
401 leg->SetLineColor(1);
402 leg->SetLineStyle(1);
403 leg->SetLineWidth(1);
404 leg->SetFillColor(0);
405 leg->SetFillStyle(1001);
406 leg->SetTextSize(0.04);
407 leg->SetLineColor(kBlack);
408 leg->SetFillColor(kWhite);
409 leg->AddEntry(gr,
"observed",
"lp");
410 leg->AddEntry(gmean,
"null hypothesis",
"lp");
414 leg->AddEntry(gcl90inf,
"90% confidence region",
"lp");
415 if(fdr_id>=0) leg->AddEntry(fdr[fdr_id],TString::Format(
"FDR (#alpha = %.1f)",FDR),
"lp");
419 if(odir!=
"") odir=odir+
"/";
420 TString ofname=odir+
"/"+gSystem->BaseName(ifname);
422 ofname.ReplaceAll(
".txt",tag);
423 cout << ofname << endl;
425 canvas->Print(ofname);
433 for(
int i=0;
i<
k;
i++) {
434 prob-=TMath::Binomial(N,
i)*pow(p,
i)*pow(1-p,N-
i);
442 #define PRECISION 1.e-6 452 x = gRandom->Uniform(xmin,xmax);
455 if(a<p) xmin=
x;
else xmax=
x;
464 #define PRECISION 1.e-6 474 x = gRandom->Uniform(xmin,xmax);
476 a=ROOT::Math::inc_beta(x, k, N-k+1);
477 if(a<p) xmin=
x;
else xmax=
x;
486 double*
x =
new double[
N];
487 for(
int i=0;
i<
N;
i++) x[
i]=
i+1;
489 double* prob =
new double[
N];
492 TGraph* gprob =
new TGraph(N,x,prob);
493 gprob->SetLineColor(color);
495 gprob->SetLineStyle(style);
497 gprob->GetXaxis()->SetRangeUser(1,N);
498 gprob->GetYaxis()->SetRangeUser(0,1);
507 double* X =
new double[2*M+N%2];
508 double* Y =
new double[2*M+N%2];
510 for(
int i=0;
i<
M;
i++) {
511 X[2*
i+0]=x[
i+0]; Y[2*
i+0]=y[
i];
512 X[2*
i+1]=x[
i+1]; Y[2*
i+1]=y[
i];
514 if(N%2) X[2*
M]=x[N-1]; Y[2*
M]=y[N-1];
516 TGraph* gprob =
new TGraph(2*M+N%2,X,Y);
517 gprob->SetLineColor(color);
518 gprob->SetLineWidth(2);
524 TGraphAsymmErrors*
DrawBelt(
int N,
double pinf,
double psup, Color_t color) {
526 double*
x =
new double[
N];
527 for(
int i=0;
i<
N;
i++) x[
i]=
i+1;
528 double* ex =
new double[
N];
529 for(
int i=0;
i<
N;
i++) ex[
i]=0;
531 double*
y =
new double[
N];
534 double* yinf =
new double[
N];
537 double* ysup =
new double[
N];
540 TGraphAsymmErrors* egr;
541 egr =
new TGraphAsymmErrors(N,x,y,ex,ex,yinf,ysup);
542 egr->SetMarkerStyle(20);
543 egr->SetMarkerSize(0);
544 egr->SetLineColor(15);
545 egr->SetFillColorAlpha(color, 0.1);
double GetProbability(int N, int k, double p)
wavearray< double > a(hp.size())
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\ layers : "<< nLAYERS<< "\ dF(hz) : "<< dF<< "\ dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1) *itime+ifreq;double time=itime *dT;double freq=(ifreq >0) ? ifreq *dF :dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
double median(std::vector< double > &vec)
double InverseProbability(int N, int k, double p)
double InverseProbabilityBH(int N, int k, double p)
TGraph * DrawStepGraph(int N, double *x, double *y, Color_t color=kBlack)
TGraph * DrawProbabilityBH(int N, double p, Color_t color, int style=9)
TGraphAsymmErrors * DrawBelt(int N, double pinf, double psup, Color_t color)
double fabs(const Complex &x)
void DrawPvaluesPE(TString ifname, TString odir, TString side, TString label="", bool title=true, double FDR=0)