21 #pragma GCC system_header
27 #include "wavearray.hh"
29 #include "TObjArray.h"
30 #include "TObjString.h"
64 CWB_Plugin(TFile* jfile, CWB::config* cfg,
network* net, WSeries<double>* x, TString ifo,
int type) {
74 if(type==CWB_PLUGIN_CONFIG) {
76 cout <<
"-----> CWB_Plugin_Gating.C" << endl;
80 if(type==CWB_PLUGIN_ICOHERENCE) {
83 cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
84 double Tb = gCWB2G->GetSegBegin()-cfg->segEdge;
85 double Te = gCWB2G->GetSegEnd()+cfg->segEdge;
90 int nIFO = (gCWB2G->IsSingleDetector()) ? 1 : net->ifoListSize();
91 int size = net->getifo(0)->getHoT()->size();
92 double rate = net->getifo(0)->getHoT()->rate();
97 wavearray<double>* hot[NIFO_MAX];
98 for(
int n=0;
n<
nIFO;
n++) hot[
n] = net->getifo(
n)->getHoT();
106 int X = int(cfg->segEdge/dt+0.5);
107 int M = int(
TEDG/dt)+1;
108 int N = int(
TWIN/dt);
110 vector<waveSegment> glist;
111 wavearray<double> SE(
size);
112 wavearray<int> sVeto(
size);
119 for(
int j=0;j<N;j++) SE[N-1]+=pow(hot[
n]->
data[N-1-j],2);
120 for(
int i=N;i<
size;i++) {
122 SE[i] -= pow(hot[
n]->
data[i-N],2);
123 SE[i] += pow(hot[
n]->
data[i],2);
127 for(
int i=0;i<
size;i++) {
129 int is = i-
M>X ? i-
M : X;
131 for(
int k=is;k<es;k++) sVeto[k]=1;
135 sVeto[0]=0;sVeto[
size-1]=0;
136 for(
int i=0;i<
size-1;i++) sVeto[i]=sVeto[i+1]-sVeto[i];
141 for(
int i=0;i<
size;i++) {
142 if(sVeto[i]== 1) gseg.start = Tb+int(i*dt);
144 gseg.stop = Tb+int(i*dt+0.5);
146 glist.push_back(gseg);
153 for(
int j=gsize;j<glist.size();j++) {
154 cout << j <<
" -----> CWB_Plugin_Gating.C - " << net->getifo(
n)->Name <<
" gating time : start="
155 << glist[j].start <<
" stop=" << glist[j].stop <<
" len=" << glist[j].stop-glist[j].start << endl;
162 double gating_time = 0;
164 glist = CWB::Toolbox::unionSegments(glist);
165 gating_time = CWB::Toolbox::getTimeSegList(glist);
166 glist = CWB::Toolbox::invertSegments(glist);
167 net->segList = CWB::Toolbox::mergeSegLists(glist,net->segList);
170 cout<<
"-----> CWB_Plugin_Gating.C - gating time : " << gating_time << endl << endl;
174 sprintf(info,
"-GT:%g",gating_time);
175 gCWB2G->PrintAnalysisInfo(CWB_STAGE_COHERENCE,
"cwb2G::Coherence",info,
false);
197 #pragma GCC system_header
201 #include "network.hh"
202 #include "wavearray.hh"
204 #include "TObjArray.h"
205 #include "TObjString.h"
207 #include "TComplex.h"
210 #include "watplot.hh"
211 #include "gwavearray.hh"
226 void GetLveto(netcluster* pwc,
int cid,
int nifo,
float* Lveto);
227 void GetWveto(netcluster* pwc,
int cid,
int nifo,
float* Wveto);
228 void PlotWaveform(TString ifo, wavearray<double>* wfREC,
229 CWB::config* cfg,
bool fft=
false,
bool strain=
false);
234 CWB_Plugin(TFile* jfile, CWB::config* cfg,
network* NET, WSeries<double>* x, TString ifo,
int type) {
239 cout <<
"-----> CWB_Plugin_QLWveto.C" << endl;
240 cout <<
"ifo " << ifo.Data() << endl;
241 cout <<
"type " << type << endl;
244 float Qveto[2*NIFO_MAX];
248 if(type==CWB_PLUGIN_CONFIG) {
252 if(type==CWB_PLUGIN_ILIKELIHOOD) {
257 TList *files = (TList*)gROOT->GetListOfFiles();
260 int nIFO = NET->ifoListSize();
266 while ((file=(TSystemFile*)next())) {
267 fname = file->GetName();
269 if(
fname.Contains(
"wave_")) {
270 froot=(TFile*)file;froot->cd();
272 outDump.ReplaceAll(
".root.tmp",
".txt");
277 cout <<
"CWB_Plugin_QLWveto.C : Error - output root file not found" << endl;
281 cout <<
"CWB_Plugin_QLWveto.C : Error - output root file not found" << endl;
285 TTree* net_tree = (TTree *) froot->Get(
"waveburst");
287 EVT =
new netevent(
nIFO);
288 net_tree = EVT->setTree();
289 net_tree->Branch(
"Qveto",Qveto,TString::Format(
"Qveto[%i]/F",2*cfg->nIFO));
290 net_tree->Branch(
"Lveto",Lveto,TString::Format(
"Lveto[%i]/F",3));
291 net_tree->Branch(
"Wveto",Wveto,TString::Format(
"Wveto[%i]/F",2));
295 if(type==CWB_PLUGIN_OLIKELIHOOD) {
297 if(TString(cfg->analysis)!=
"2G") {
298 cout <<
"CWB_Plugin_QLWveto.C -> "
299 <<
"CWB_PLUGIN_OLIKELIHOOD implemented only for 2G" << endl;
304 int gIFACTOR=-1; IMPORT(
int,gIFACTOR)
305 cout <<
"-----> CWB_Plugin_QLWveto.C -> "
306 <<
" gIFACTOR : " << gIFACTOR << endl;
309 float* gSLAGSHIFT=NULL; IMPORT(
float*,gSLAGSHIFT)
311 int nIFO = NET->ifoListSize();
314 wavearray<double>
id;
316 double factor = cfg->factors[gIFACTOR];
321 TList *files = (TList*)gROOT->GetListOfFiles();
328 while ((file=(TSystemFile*)next())) {
329 fname = file->GetName();
331 if(
fname.Contains(
"wave_")) {
332 froot=(TFile*)file;froot->cd();
334 outDump.ReplaceAll(
".root.tmp",
".txt");
339 cout <<
"CWB_Plugin_QLWveto.C : Error - output root file not found" << endl;
343 cout <<
"CWB_Plugin_QLWveto.C : Error - output root file not found" << endl;
347 TTree* net_tree = (TTree *) froot->Get(
"waveburst");
349 EVT =
new netevent(net_tree,
nIFO);
350 net_tree->SetBranchAddress(
"Qveto",Qveto);
351 net_tree->SetBranchAddress(
"Lveto",Lveto);
352 net_tree->SetBranchAddress(
"Wveto",Wveto);
354 EVT =
new netevent(
nIFO);
355 net_tree = EVT->setTree();
356 net_tree->Branch(
"Qveto",Qveto,TString::Format(
"Qveto[%i]/F",2*cfg->nIFO));
357 net_tree->Branch(
"Lveto",Lveto,TString::Format(
"Lveto[%i]/F",3));
358 net_tree->Branch(
"Wveto",Wveto,TString::Format(
"Wveto[%i]/F",2));
360 EVT->setSLags(gSLAGSHIFT);
362 for(
int k=0; k<K; k++) {
364 id = NET->getwc(k)->get(
const_cast<char*
>(
"ID"), 0,
'L', rate);
366 for(
int j=0; j<(int)
id.
size(); j++) {
368 int ID = size_t(
id.
data[j]+0.5);
370 if(NET->getwc(k)->sCuts[ID-1]!=-1)
continue;
373 if(cfg->simulation==4) ofactor=-factor;
374 else if(cfg->simulation==3) ofactor=-gIFACTOR;
377 EVT->output2G(NULL,NET,ID,k,ofactor);
379 wavearray<double>** pwfREC =
new wavearray<double>*[
nIFO];
380 detector* pd = NET->getifo(0);
381 int idSize = pd->RWFID.size();
384 for (
int mm=0; mm<idSize; mm++)
if (pd->RWFID[mm]==ID) wfIndex=mm;
385 if(wfIndex==-1)
continue;
387 netcluster* pwc = NET->getwc(k);
388 cout << endl <<
"----------------------------------------------------------------" << endl;
390 cout <<
"Lveto : " <<
"fmean : " << Lveto[0] <<
" frms : " << Lveto[1]
391 <<
" Energy Ratio : " << Lveto[2] << endl << endl;
393 cout <<
"Wveto : " <<
" Slope : " << Wveto[0] <<
" Correlation : " << Wveto[1] << endl << endl;
400 pwfREC[
n] = pd->RWFP[wfIndex];
401 wavearray<double>* wfREC = pwfREC[
n];
403 #ifdef PLOT_WHITENED_WAVEFORMS
408 NET->getMRAwave(ID,k,
'S',0,
true);
411 NET->getMRAwave(ID,k,
'W',0,
true);
415 cout <<
"Qveto : " << pd->Name <<
" Qveto[R] = " << Qveto[
n]
416 <<
" Qveto[W] = " << Qveto[
n+
nIFO] << endl;
420 cout <<
"----------------------------------------------------------------" << endl;
423 std::vector<int> sCuts = NET->getwc(k)->sCuts;
425 for(
int i=0; i<(int)sCuts.size(); i++)
if(i!=ID-1) NET->getwc(k)->sCuts[i]=1;
428 NET->getwc(k)->sCuts = sCuts;
430 if(cfg->dump) EVT->dopen(outDump.Data(),
const_cast<char*
>(
"a"),
false);
431 EVT->output2G(net_tree,NET,ID,k,ofactor);
434 fprintf(EVT->fP,
"Qveto: ");
435 for(
int i=0; i<2*
nIFO; i++) fprintf(EVT->fP,
"%f ",Qveto[i]);
436 fprintf(EVT->fP,
"\n");
438 fprintf(EVT->fP,
"Lveto: ");
439 for(
int i=0; i<3; i++) fprintf(EVT->fP,
"%f ",Lveto[i]);
440 fprintf(EVT->fP,
"\n");
442 fprintf(EVT->fP,
"Wveto: ");
443 for(
int i=0; i<2; i++) fprintf(EVT->fP,
"%f ",Wveto[i]);
444 fprintf(EVT->fP,
"\n");
446 if(cfg->dump) EVT->dclose();
447 if(!cfg->cedDump) NET->getwc(k)->sCuts[ID-1]=1;
460 wavearray<double> x = *
wf;;
465 x.resize(4*x.size());
467 for(
int j=xsize;j<x.size();j++) x[j]=0;
471 wavearray<double> a(x.size());
473 double dt = 1./x.rate();
476 for (
int i=1;i<x.size();i++) {
477 if(fabs(x[i])>xmax) xmax=fabs(x[i]);
489 for (
int i=1;i<
size;i++) {
490 if(a[i]>amax) {amax=a[i];imax=i;}
506 for (
int i=0;i<
size;i++) {
507 if(abs(imax-i)<=
NTHR) {
511 if(a[i]>amax/
ATHR) eout+=a[i]*a[i];
515 float Qveto = ein>0 ? eout/ein : 0.;
522 GetLveto(netcluster* pwc,
int cid,
int nifo,
float* Lveto) {
534 Lveto[0] = Lveto[1] = Lveto[2] = 0;
536 std::vector<int>* vint = &(pwc->cList[cid-1]);
537 int V = vint->size();
548 for(
int n=0;
n<V;
n++) {
549 netpixel* pix = pwc->getPixel(cid,
n);
550 if(pix->layers%2==0) {
551 cout <<
"CWB_Plugin_QLWveto.C - Error : is enabled only for WDM (2G)" << endl;
554 if(!pix->core)
continue;
557 for(
int m=0;
m<nifo;
m++) {
558 likePix += pow(pix->getdata(
'S',
m),2);
559 likePix += pow(pix->getdata(
'P',
m),2);
562 double freq = pix->frequency*pix->rate/2.;
563 double df = pix->rate/2.;
566 if(likePix>likeMax) {likeMax=likePix;freqMax=freq;dfreqMax=df;}
578 for(
int n=0;
n<V;
n++) {
579 netpixel* pix = pwc->getPixel(cid,
n);
580 if(!pix->core)
continue;
583 for(
int m=0;
m<nifo;
m++) {
584 likePix += pow(pix->getdata(
'S',
m),2);
585 likePix += pow(pix->getdata(
'P',
m),2);
590 double freq = pix->frequency*pix->rate/2.;
591 if(fabs(freq-freqMax)<=dfreqMax) {
593 fmean += likePix*freq;
594 frms += likePix*freq*freq;
598 fmean = fmean/likeLin;
599 frms = frms/likeLin-fmean*fmean;
600 frms = frms>0 ? sqrt(frms) : 0.;
602 if(frms<dfreqMax/2.) frms=dfreqMax/2.;
610 Lveto[2] = likeTot>0. ? likeLin/likeTot : 0.;
616 #if defined PLOT_LIKELIHOOD
617 watplot WTS(
const_cast<char*
>(
"wts"));
618 WTS.plot(pwc, cid, nifo,
'L', 0,
const_cast<char*
>(
"COLZ"));
619 WTS.canvas->Print(
"l_tfmap_scalogram.png");
626 GetWveto(netcluster* pwc,
int cid,
int nifo,
float* Wveto) {
637 Wveto[0] = Wveto[1] = 0;
639 std::vector<int>* vint = &(pwc->cList[cid-1]);
640 int V = vint->size();
643 std::vector<double> x;
644 std::vector<double> y;
645 std::vector<double>
w;
648 for(
int j=0; j<V; j++) {
649 netpixel* pix = pwc->getPixel(cid,j);
650 if(pix->layers%2==0) {
651 cout <<
"CWB_Plugin_QLWveto.C - Error : is enabled only for WDM (2G)" << endl;
654 if(pix->likelihood<1. || pix->frequency==0)
continue;
657 double time = int(
double(pix->time)/pix->layers)/pix->rate;
658 double freq = pix->frequency*pix->rate/2.;
662 w.push_back(pix->likelihood);
667 double xcm, ycm, qxx, qyy, qxy, ew;
668 xcm = ycm = qxx = qyy = qxy = ew = 0;
670 for(
int i=0; i<
size; ++i) {
678 for(
int i=0; i<
size; ++i) {
679 qxx += (x[i] - xcm)*(x[i] - xcm)*
w[i];
680 qyy += (y[i] - ycm)*(y[i] - ycm)*
w[i];
681 qxy += (x[i] - xcm)*(y[i] - ycm)*
w[i];
684 double beta = qxy/qxx;
685 double alpha = ycm-beta*xcm;
686 double corr = qxy/sqrt(qxx*qyy);
687 double duration = sqrt(qxx/ew);
688 double bandwidth = sqrt(qyy/ew);
694 Wveto[1] = fabs(corr);
701 CWB::config* cfg,
bool fft,
bool strain) {
703 watplot PTS(
const_cast<char*
>(
"ptswrc"),200,20,800,500);
706 double tmin = wfREC->start();
707 wfREC->start(wfREC->start()-tmin);
709 PTS.plot(wfREC,
const_cast<char*
>(
"ALP"), 1, 0, 0,
true, cfg->fLow, cfg->fHigh);
711 PTS.plot(wfREC,
const_cast<char*
>(
"ALP"), 1, 0, 0);
713 PTS.graph[0]->SetLineWidth(1);
714 wfREC->start(wfREC->start()+tmin);
725 PTS.canvas->Print(
fname);
726 cout <<
"write : " <<
fname << endl;
735 n = ifo->IWFP.size();
736 for (
int i=0;i<
n;i++) {
737 wavearray<double>*
wf = (wavearray<double>*)ifo->IWFP[i];
743 n = ifo->RWFP.size();
744 for (
int i=0;i<
n;i++) {
745 wavearray<double>*
wf = (wavearray<double>*)ifo->RWFP[i];
772 #pragma GCC system_header
777 CWB_Plugin(TFile* jfile, CWB::config* cfg,
network* net, WSeries<double>* x, TString ifo,
int type) {
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *net, WSeries< double > *x, TString ifo, int type)
sprintf(tag,"wave_%s", data_label)
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *net, WSeries< double > *x, TString ifo, int type)
void GetWveto(netcluster *pwc, int cid, int nifo, float *Wveto)
void GetQveto(wavearray< double > *wf, float &Qveto, float &Qfactor)
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *NET, WSeries< double > *x, TString ifo, int type)
void GetLveto(netcluster *pwc, int cid, int nifo, float *Lveto)
void ClearWaveforms(detector *ifo)
void PlotWaveform(TString ifo, wavearray< double > *wfREC, CWB::config *cfg, bool fft=false, bool strain=false)