42 #pragma GCC system_header
48 #include "wavearray.hh"
50 #include "TObjArray.h"
51 #include "TObjString.h"
85 CWB_Plugin(TFile* jfile, CWB::config* cfg,
network* net, WSeries<double>* x, TString ifo,
int type) {
95 if(type==CWB_PLUGIN_CONFIG) {
97 cout <<
"-----> CWB_Plugin_Gating.C" << endl;
101 if(type==CWB_PLUGIN_ICOHERENCE) {
104 cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
105 double Tb = gCWB2G->GetSegBegin()-cfg->segEdge;
106 double Te = gCWB2G->GetSegEnd()+cfg->segEdge;
111 int nIFO = (gCWB2G->IsSingleDetector()) ? 1 : net->ifoListSize();
112 int size = net->getifo(0)->getHoT()->size();
113 double rate = net->getifo(0)->getHoT()->rate();
118 wavearray<double>* hot[NIFO_MAX];
119 for(
int n=0;
n<
nIFO;
n++) hot[
n] = net->getifo(
n)->getHoT();
127 int X = int(cfg->segEdge/dt+0.5);
128 int M = int(
TEDG/dt)+1;
129 int N = int(
TWIN/dt);
131 vector<waveSegment> glist;
132 wavearray<double> SE(
size);
133 wavearray<int> sVeto(
size);
140 for(
int j=0;j<N;j++) SE[N-1]+=pow(hot[
n]->
data[N-1-j],2);
141 for(
int i=N;i<
size;i++) {
143 SE[i] -= pow(hot[
n]->
data[i-N],2);
144 SE[i] += pow(hot[
n]->
data[i],2);
148 for(
int i=0;i<
size;i++) {
150 int is = i-
M>X ? i-
M : X;
152 for(
int k=is;k<es;k++) sVeto[k]=1;
156 sVeto[0]=0;sVeto[
size-1]=0;
157 for(
int i=0;i<
size-1;i++) sVeto[i]=sVeto[i+1]-sVeto[i];
162 for(
int i=0;i<
size;i++) {
163 if(sVeto[i]== 1) gseg.start = Tb+int(i*dt);
165 gseg.stop = Tb+int(i*dt+0.5);
167 glist.push_back(gseg);
174 for(
int j=gsize;j<glist.size();j++) {
175 cout << j <<
" -----> CWB_Plugin_Gating.C - " << net->getifo(
n)->Name <<
" gating time : start="
176 << glist[j].start <<
" stop=" << glist[j].stop <<
" len=" << glist[j].stop-glist[j].start << endl;
183 double gating_time = 0;
185 glist = CWB::Toolbox::unionSegments(glist);
186 gating_time = CWB::Toolbox::getTimeSegList(glist);
187 glist = CWB::Toolbox::invertSegments(glist);
188 net->segList = CWB::Toolbox::mergeSegLists(glist,net->segList);
191 cout<<
"-----> CWB_Plugin_Gating.C - gating time : " << gating_time << endl << endl;
195 sprintf(info,
"-GT:%g",gating_time);
196 gCWB2G->PrintAnalysisInfo(CWB_STAGE_COHERENCE,
"cwb2G::Coherence",info,
false);
239 #pragma GCC system_header
243 #include "network.hh"
244 #include "wavearray.hh"
246 #include "TObjArray.h"
247 #include "TObjString.h"
249 #include "TComplex.h"
252 #include "watplot.hh"
253 #include "gwavearray.hh"
267 void GetQveto(wavearray<double>*
wf,
float &Qveto,
float &Qfactor);
268 void GetLveto(netcluster* pwc,
int cid,
int nifo,
float* Lveto);
269 void PlotWaveform(TString ifo, wavearray<double>* wfREC,
270 CWB::config* cfg,
bool fft=
false,
bool strain=
false);
273 std::vector<netpixel>
DoPCA(
network* NET, CWB::config* cfg,
int lag,
int id);
274 void ResetPCA(
network* NET, CWB::config* cfg, netcluster* pwc, std::vector<netpixel>* vPIX,
int ID);
278 CWB_Plugin(TFile* jfile, CWB::config* cfg,
network* NET, WSeries<double>* x, TString ifo,
int type) {
291 if(type==CWB_PLUGIN_CONFIG) {
293 cout <<
"-----> CWB_Plugin_QLveto.C" << endl;
298 if(type==CWB_PLUGIN_ILIKELIHOOD) {
303 TList *files = (TList*)gROOT->GetListOfFiles();
306 int nIFO = NET->ifoListSize();
312 while ((file=(TSystemFile*)next())) {
313 fname = file->GetName();
315 if(
fname.Contains(
"wave_")) {
316 froot=(TFile*)file;froot->cd();
318 outDump.ReplaceAll(
".root.tmp",
".txt");
323 cout <<
"CWB_Plugin_QLveto.C : Error - output root file not found" << endl;
327 cout <<
"CWB_Plugin_QLveto.C : Error - output root file not found" << endl;
331 TTree* net_tree = (TTree *) froot->Get(
"waveburst");
333 EVT =
new netevent(
nIFO);
334 net_tree = EVT->setTree();
335 net_tree->Branch(
"Qveto",Qveto,TString::Format(
"Qveto[%i]/F",2));
336 net_tree->Branch(
"Lveto",Lveto,TString::Format(
"Lveto[%i]/F",3));
339 bool qveto_exists=
false;
340 bool lveto_exists=
false;
341 TIter next(net_tree->GetListOfBranches());
342 while ((branch=(TBranch*)next())) {
343 if(TString(
"Qveto").CompareTo(branch->GetName())==0) qveto_exists=
true;
344 if(TString(
"Lveto").CompareTo(branch->GetName())==0) lveto_exists=
true;
347 if(!qveto_exists) net_tree->Branch(
"Qveto",Qveto,TString::Format(
"Qveto[%i]/F",2));
348 if(!lveto_exists) net_tree->Branch(
"Lveto",Lveto,TString::Format(
"Lveto[%i]/F",3));
352 if(type==CWB_PLUGIN_OLIKELIHOOD) {
354 if(TString(cfg->analysis)!=
"2G") {
355 cout <<
"CWB_Plugin_QLveto.C -> "
356 <<
"CWB_PLUGIN_OLIKELIHOOD implemented only for 2G" << endl;
361 int gIFACTOR=-1; IMPORT(
int,gIFACTOR)
366 float* gSLAGSHIFT=NULL; IMPORT(
float*,gSLAGSHIFT)
368 int nIFO = NET->ifoListSize();
371 wavearray<double>
id;
373 double factor = cfg->factors[gIFACTOR];
378 TList *files = (TList*)gROOT->GetListOfFiles();
385 while ((file=(TSystemFile*)next())) {
386 fname = file->GetName();
388 if(
fname.Contains(
"wave_")) {
389 froot=(TFile*)file;froot->cd();
391 outDump.ReplaceAll(
".root.tmp",
".txt");
396 cout <<
"CWB_Plugin_QLveto.C : Error - output root file not found" << endl;
400 cout <<
"CWB_Plugin_QLveto.C : Error - output root file not found" << endl;
404 TTree* net_tree = (TTree *) froot->Get(
"waveburst");
406 EVT =
new netevent(net_tree,
nIFO);
407 net_tree->SetBranchAddress(
"Qveto",Qveto);
408 net_tree->SetBranchAddress(
"Lveto",Lveto);
410 EVT =
new netevent(
nIFO);
411 net_tree = EVT->setTree();
412 net_tree->Branch(
"Qveto",Qveto,TString::Format(
"Qveto[%i]/F",2));
413 net_tree->Branch(
"Lveto",Lveto,TString::Format(
"Lveto[%i]/F",3));
415 EVT->setSLags(gSLAGSHIFT);
417 for(
int k=0; k<K; k++) {
419 id = NET->getwc(k)->get(
const_cast<char*
>(
"ID"), 0,
'L', rate);
421 for(
int j=0; j<(int)
id.
size(); j++) {
423 int ID = size_t(
id.
data[j]+0.5);
425 if(NET->getwc(k)->sCuts[ID-1]!=-1)
continue;
428 if(cfg->simulation==4) ofactor=-factor;
429 else if(cfg->simulation==3) ofactor=-gIFACTOR;
432 EVT->output2G(NULL,NET,ID,k,ofactor);
434 wavearray<double>** pwfREC =
new wavearray<double>*[
nIFO];
435 detector* pd = NET->getifo(0);
436 int idSize = pd->RWFID.size();
439 for (
int mm=0; mm<idSize; mm++)
if (pd->RWFID[mm]==ID) wfIndex=mm;
440 if(wfIndex==-1)
continue;
442 netcluster* pwc = NET->getwc(k);
443 cout << endl <<
"----------------------------------------------------------------" << endl;
446 Qveto[0]=Qveto[1]=1.e20;
451 pwfREC[
n] = pd->RWFP[wfIndex];
452 wavearray<double>* wfREC = pwfREC[
n];
454 #ifdef PLOT_WHITENED_WAVEFORMS
462 NET->getMRAwave(ID,k,
'S',0,
true);
463 GetQveto(&(pd->waveForm), qveto, qfactor);
464 if(qveto<Qveto[0]) Qveto[0]=qveto;
465 if(qfactor<Qveto[1]) Qveto[1]=qfactor;
468 NET->getMRAwave(ID,k,
'W',0,
true);
469 GetQveto(&(pd->waveBand), qveto, qfactor);
470 if(qveto<Qveto[0]) Qveto[0]=qveto;
471 if(qfactor<Qveto[1]) Qveto[1]=qfactor;
473 cout <<
"Qveto : " << pd->Name <<
" Qveto[0] = " << Qveto[0]
474 <<
" Qveto[1] = " << Qveto[1] << endl;
480 std::vector<netpixel> vPIX;
481 if(cfg->pattern>0) vPIX =
DoPCA(NET, cfg, k, ID);
483 if(cfg->pattern>0)
ResetPCA(NET, cfg, pwc, &vPIX, ID);
486 cout <<
"Lveto : " <<
"fmean : " << Lveto[0] <<
" frms : " << Lveto[1]
487 <<
" Energy Ratio : " << Lveto[2] << endl << endl;
488 cout <<
"----------------------------------------------------------------" << endl;
490 std::vector<int> sCuts = NET->getwc(k)->sCuts;
492 for(
int i=0; i<(int)sCuts.size(); i++)
if(i!=ID-1) NET->getwc(k)->sCuts[i]=1;
495 NET->getwc(k)->sCuts = sCuts;
497 if(cfg->dump) EVT->dopen(outDump.Data(),
const_cast<char*
>(
"a"),
false);
498 EVT->output2G(net_tree,NET,ID,k,ofactor);
501 fprintf(EVT->fP,
"Qveto: ");
502 for(
int i=0; i<2*
nIFO; i++) fprintf(EVT->fP,
"%f ",Qveto[i]);
503 fprintf(EVT->fP,
"\n");
505 fprintf(EVT->fP,
"Lveto: ");
506 for(
int i=0; i<3; i++) fprintf(EVT->fP,
"%f ",Lveto[i]);
507 fprintf(EVT->fP,
"\n");
509 if(cfg->dump) EVT->dclose();
510 if(!cfg->cedDump) NET->getwc(k)->sCuts[ID-1]=1;
521 GetQveto(wavearray<double>*
wf,
float &Qveto,
float &Qfactor) {
523 wavearray<double> x = *
wf;;
528 x.resize(4*x.size());
530 for(
int j=xsize;j<x.size();j++) x[j]=0;
534 wavearray<double> a(x.size());
536 double dt = 1./x.rate();
539 for (
int i=1;i<x.size();i++) {
540 if(fabs(x[i])>xmax) xmax=fabs(x[i]);
552 for (
int i=1;i<
size;i++) {
553 if(a[i]>amax) {amax=a[i];imax=i;}
569 for (
int i=0;i<
size;i++) {
570 if(abs(imax-i)<=
NTHR) {
574 if(a[i]>amax/
ATHR) eout+=a[i]*a[i];
578 Qveto = ein>0 ? eout/ein : 0.;
582 float R = (a[imax-1]+a[imax+1])/a[imax]/2.;
583 Qfactor = sqrt(-pow(TMath::Pi(),2)/log(
R)/2.);
590 GetLveto(netcluster* pwc,
int cid,
int nifo,
float* Lveto) {
602 Lveto[0] = Lveto[1] = Lveto[2] = 0;
604 std::vector<int>* vint = &(pwc->cList[cid-1]);
605 int V = vint->size();
616 for(
int n=0;
n<V;
n++) {
617 netpixel* pix = pwc->getPixel(cid,
n);
618 if(pix->layers%2==0) {
619 cout <<
"CWB_Plugin_QLveto.C - Error : is enabled only for WDM (2G)" << endl;
622 if(!pix->core)
continue;
625 for(
int m=0;
m<nifo;
m++) {
626 likePix += pow(pix->getdata(
'S',
m),2);
627 likePix += pow(pix->getdata(
'P',
m),2);
630 double freq = pix->frequency*pix->rate/2.;
631 double df = pix->rate/2.;
634 if(likePix>likeMax) {likeMax=likePix;freqMax=freq;dfreqMax=df;}
646 for(
int n=0;
n<V;
n++) {
647 netpixel* pix = pwc->getPixel(cid,
n);
648 if(!pix->core)
continue;
651 for(
int m=0;
m<nifo;
m++) {
652 likePix += pow(pix->getdata(
'S',
m),2);
653 likePix += pow(pix->getdata(
'P',
m),2);
658 double freq = pix->frequency*pix->rate/2.;
659 if(fabs(freq-freqMax)<=dfreqMax) {
661 fmean += likePix*freq;
662 frms += likePix*freq*freq;
666 fmean = fmean/likeLin;
667 frms = frms/likeLin-fmean*fmean;
668 frms = frms>0 ? sqrt(frms) : 0.;
670 if(frms<dfreqMax/2.) frms=dfreqMax/2.;
678 Lveto[2] = likeTot>0. ? likeLin/likeTot : 0.;
684 #if defined PLOT_LIKELIHOOD
685 watplot WTS(
const_cast<char*
>(
"wts"));
686 WTS.plot(pwc, cid, nifo,
'L', 0,
const_cast<char*
>(
"COLZ"));
687 WTS.canvas->Print(
"l_tfmap_scalogram.png");
695 CWB::config* cfg,
bool fft,
bool strain) {
697 watplot PTS(
const_cast<char*
>(
"ptswrc"),200,20,800,500);
700 double tmin = wfREC->start();
701 wfREC->start(wfREC->start()-tmin);
703 PTS.plot(wfREC,
const_cast<char*
>(
"ALP"), 1, 0, 0,
true, cfg->fLow, cfg->fHigh);
705 PTS.plot(wfREC,
const_cast<char*
>(
"ALP"), 1, 0, 0);
707 PTS.graph[0]->SetLineWidth(1);
708 wfREC->start(wfREC->start()+tmin);
719 PTS.canvas->Print(
fname);
720 cout <<
"write : " <<
fname << endl;
729 n = ifo->IWFP.size();
730 for (
int i=0;i<
n;i++) {
731 wavearray<double>*
wf = (wavearray<double>*)ifo->IWFP[i];
737 n = ifo->RWFP.size();
738 for (
int i=0;i<
n;i++) {
739 wavearray<double>*
wf = (wavearray<double>*)ifo->RWFP[i];
746 std::vector<netpixel>
DoPCA(
network* NET, CWB::config* cfg,
int lag,
int id) {
750 size_t nIFO = NET->ifoList.size();
752 float En = 2*NET->acor*NET->acor*
nIFO;
754 int size = NET->a_00.size();
758 netcluster* pwc = NET->getwc(lag);
759 std::vector<netpixel> vPIX;
761 std::vector<int> pI = NET->wdmMRA.getXTalk(pwc,
id,
false);
763 if(V>cfg->BATCH)
return vPIX;
765 wavearray<float> xi(
size); xi=0;
766 wavearray<float> XI(
size); XI=0;
768 __m128* _xi = (__m128*) xi.data;
769 __m128* _XI = (__m128*) XI.data;
771 __m128* _aa = (__m128*) NET->a_00.data;
772 __m128* _AA = (__m128*) NET->a_90.data;
775 for(
int j=0; j<V; j++) {
777 _sse_zero_ps(_xi+jf);
778 _sse_zero_ps(_XI+jf);
779 ee = _sse_abs_ps(_aa+jf,_AA+jf);
780 if(ee>En) nPC++;
else ee=0.;
781 NET->rNRG.data[j] = ee;
782 NET->pNRG.data[j] = NET->rNRG.data[j];
785 nPC = NET->_sse_mra_ps(xi.data,XI.data,En,nPC);
787 for(
int j=0; j<V; j++) {
788 pix = pwc->getPixel(
id,pI[j]);
789 vPIX.push_back(*pix);
791 ee = NET->pNRG.data[j];
794 for(
int i=0; i<
nIFO; i++) {
795 pix->setdata(
double(xi.data[j*NIFO+i]),
'S',i);
796 pix->setdata(
double(XI.data[j*NIFO+i]),
'P',i);
803 void ResetPCA(
network* NET, CWB::config* cfg, netcluster* pwc, std::vector<netpixel>* vPIX,
int ID) {
805 std::vector<int> pI = NET->wdmMRA.getXTalk(pwc, ID,
false);
807 if(V>cfg->BATCH)
return;
808 for(
int j=0; j<V; j++) {
809 netpixel* pix = pwc->getPixel(ID,pI[j]);
813 while(!vPIX->empty()) vPIX->pop_back();
814 vPIX->clear(); std::vector<netpixel>().swap(*vPIX);
836 #pragma GCC system_header
841 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 ResetPCA(network *NET, CWB::config *cfg, netcluster *pwc, std::vector< netpixel > *vPIX, int ID)
std::vector< netpixel > DoPCA(network *NET, CWB::config *cfg, int lag, int id)
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)