42 #pragma GCC system_header
47 #include "wavearray.hh"
49 #include "TObjArray.h"
50 #include "TObjString.h"
56 #include "gwavearray.hh"
76 void GetLveto(netcluster* pwc,
int cid,
int nifo,
float* Lveto);
78 CWB::config* cfg,
bool fft=
false,
bool strain=
false);
81 std::vector<netpixel>
DoPCA(
network* NET, CWB::config* cfg,
int lag,
int id);
82 void ResetPCA(
network* NET, CWB::config* cfg, netcluster* pwc, std::vector<netpixel>* vPIX,
int ID);
86 CWB_Plugin(TFile* jfile, CWB::config* cfg,
network* NET, WSeries<double>* x, TString ifo,
int type) {
91 cout <<
"-----> CWB_Plugin_QLveto.C" << endl;
92 cout <<
"ifo " << ifo.Data() << endl;
93 cout <<
"type " << type << endl;
96 float Qveto[2*NIFO_MAX];
99 if(type==CWB_PLUGIN_CONFIG) {
103 if(type==CWB_PLUGIN_ILIKELIHOOD) {
108 TList *files = (TList*)gROOT->GetListOfFiles();
111 int nIFO = NET->ifoListSize();
117 while ((file=(TSystemFile*)next())) {
118 fname = file->GetName();
120 if(
fname.Contains(
"wave_")) {
121 froot=(TFile*)file;froot->cd();
123 outDump.ReplaceAll(
".root.tmp",
".txt");
128 cout <<
"CWB_Plugin_QLveto.C : Error - output root file not found" << endl;
132 cout <<
"CWB_Plugin_QLveto.C : Error - output root file not found" << endl;
136 TTree* net_tree = (TTree *) froot->Get(
"waveburst");
138 EVT =
new netevent(
nIFO);
139 net_tree = EVT->setTree();
140 net_tree->Branch(
"Qveto",Qveto,TString::Format(
"Qveto[%i]/F",2*cfg->nIFO));
141 net_tree->Branch(
"Lveto",Lveto,TString::Format(
"Lveto[%i]/F",3));
145 if(type==CWB_PLUGIN_OLIKELIHOOD) {
147 if(TString(cfg->analysis)!=
"2G") {
148 cout <<
"CWB_Plugin_QLveto.C -> "
149 <<
"CWB_PLUGIN_OLIKELIHOOD implemented only for 2G" << endl;
154 int gIFACTOR=-1; IMPORT(
int,gIFACTOR)
155 cout <<
"-----> CWB_Plugin_QLveto.C -> "
156 <<
" gIFACTOR : " << gIFACTOR << endl;
159 float* gSLAGSHIFT=NULL; IMPORT(
float*,gSLAGSHIFT)
161 int nIFO = NET->ifoListSize();
164 wavearray<double>
id;
166 double factor = cfg->factors[gIFACTOR];
171 TList *files = (TList*)gROOT->GetListOfFiles();
178 while ((file=(TSystemFile*)next())) {
179 fname = file->GetName();
181 if(
fname.Contains(
"wave_")) {
182 froot=(TFile*)file;froot->cd();
184 outDump.ReplaceAll(
".root.tmp",
".txt");
189 cout <<
"CWB_Plugin_QLveto.C : Error - output root file not found" << endl;
193 cout <<
"CWB_Plugin_QLveto.C : Error - output root file not found" << endl;
197 TTree* net_tree = (TTree *) froot->Get(
"waveburst");
199 EVT =
new netevent(net_tree,
nIFO);
200 net_tree->SetBranchAddress(
"Qveto",Qveto);
201 net_tree->SetBranchAddress(
"Lveto",Lveto);
203 EVT =
new netevent(
nIFO);
204 net_tree = EVT->setTree();
205 net_tree->Branch(
"Qveto",Qveto,TString::Format(
"Qveto[%i]/F",2*cfg->nIFO));
206 net_tree->Branch(
"Lveto",Lveto,TString::Format(
"Lveto[%i]/F",3));
208 EVT->setSLags(gSLAGSHIFT);
210 for(
int k=0; k<K; k++) {
212 id = NET->getwc(k)->get(
const_cast<char*
>(
"ID"), 0,
'L', rate);
214 for(
int j=0; j<(int)
id.
size(); j++) {
216 int ID = size_t(
id.
data[j]+0.5);
218 if(NET->getwc(k)->sCuts[ID-1]!=-1)
continue;
221 if(cfg->simulation==4) ofactor=-factor;
222 else if(cfg->simulation==3) ofactor=-gIFACTOR;
225 EVT->output2G(NULL,NET,ID,k,ofactor);
227 wavearray<double>** pwfREC =
new wavearray<double>*[
nIFO];
228 detector* pd = NET->getifo(0);
229 int idSize = pd->RWFID.size();
232 for (
int mm=0; mm<idSize; mm++)
if (pd->RWFID[mm]==ID) wfIndex=mm;
233 if(wfIndex==-1)
continue;
235 netcluster* pwc = NET->getwc(k);
236 cout << endl <<
"----------------------------------------------------------------" << endl;
243 pwfREC[
n] = pd->RWFP[wfIndex];
244 wavearray<double>* wfREC = pwfREC[
n];
246 #ifdef PLOT_WHITENED_WAVEFORMS
251 NET->getMRAwave(ID,k,
'S',0,
true);
254 NET->getMRAwave(ID,k,
'W',0,
true);
258 cout <<
"Qveto : " << pd->Name <<
" Qveto[R] = " << Qveto[
n]
259 <<
" Qveto[W] = " << Qveto[
n+
nIFO] << endl;
265 std::vector<netpixel> vPIX;
266 if(cfg->pattern>0) vPIX =
DoPCA(NET, cfg, k, ID);
268 if(cfg->pattern>0)
ResetPCA(NET, cfg, pwc, &vPIX, ID);
271 cout <<
"Lveto : " <<
"fmean : " << Lveto[0] <<
" frms : " << Lveto[1]
272 <<
" Energy Ratio : " << Lveto[2] << endl << endl;
273 cout <<
"----------------------------------------------------------------" << endl;
275 std::vector<int> sCuts = NET->getwc(k)->sCuts;
277 for(
int i=0; i<(int)sCuts.size(); i++)
if(i!=ID-1) NET->getwc(k)->sCuts[i]=1;
280 NET->getwc(k)->sCuts = sCuts;
282 if(cfg->dump) EVT->dopen(outDump.Data(),
const_cast<char*
>(
"a"),
false);
283 EVT->output2G(net_tree,NET,ID,k,ofactor);
286 fprintf(EVT->fP,
"Qveto: ");
287 for(
int i=0; i<2*
nIFO; i++) fprintf(EVT->fP,
"%f ",Qveto[i]);
288 fprintf(EVT->fP,
"\n");
290 fprintf(EVT->fP,
"Lveto: ");
291 for(
int i=0; i<3; i++) fprintf(EVT->fP,
"%f ",Lveto[i]);
292 fprintf(EVT->fP,
"\n");
294 if(cfg->dump) EVT->dclose();
295 if(!cfg->cedDump) NET->getwc(k)->sCuts[ID-1]=1;
308 wavearray<double> x = *
wf;;
313 x.resize(4*x.size());
315 for(
int j=xsize;j<x.size();j++) x[j]=0;
319 wavearray<double> a(x.size());
321 double dt = 1./x.rate();
324 for (
int i=1;i<x.size();i++) {
325 if(fabs(x[i])>xmax) xmax=fabs(x[i]);
337 for (
int i=1;i<
size;i++) {
338 if(a[i]>amax) {amax=a[i];imax=i;}
354 for (
int i=0;i<
size;i++) {
355 if(abs(imax-i)<=
NTHR) {
359 if(a[i]>amax/
ATHR) eout+=a[i]*a[i];
363 float Qveto = ein>0 ? eout/ein : 0.;
370 GetLveto(netcluster* pwc,
int cid,
int nifo,
float* Lveto) {
382 Lveto[0] = Lveto[1] = Lveto[2] = 0;
384 std::vector<int>* vint = &(pwc->cList[cid-1]);
385 int V = vint->size();
396 for(
int n=0;
n<V;
n++) {
397 netpixel* pix = pwc->getPixel(cid,
n);
398 if(pix->layers%2==0) {
399 cout <<
"CWB_Plugin_QLveto.C - Error : is enabled only for WDM (2G)" << endl;
402 if(!pix->core)
continue;
405 for(
int m=0;
m<nifo;
m++) {
406 likePix += pow(pix->getdata(
'S',
m),2);
407 likePix += pow(pix->getdata(
'P',
m),2);
410 double freq = pix->frequency*pix->rate/2.;
411 double df = pix->rate/2.;
414 if(likePix>likeMax) {likeMax=likePix;freqMax=freq;dfreqMax=df;}
426 for(
int n=0;
n<V;
n++) {
427 netpixel* pix = pwc->getPixel(cid,
n);
428 if(!pix->core)
continue;
431 for(
int m=0;
m<nifo;
m++) {
432 likePix += pow(pix->getdata(
'S',
m),2);
433 likePix += pow(pix->getdata(
'P',
m),2);
438 double freq = pix->frequency*pix->rate/2.;
439 if(fabs(freq-freqMax)<=dfreqMax) {
441 fmean += likePix*freq;
442 frms += likePix*freq*freq;
446 fmean = fmean/likeLin;
447 frms = frms/likeLin-fmean*fmean;
448 frms = frms>0 ? sqrt(frms) : 0.;
450 if(frms<dfreqMax/2.) frms=dfreqMax/2.;
458 Lveto[2] = likeTot>0. ? likeLin/likeTot : 0.;
464 #if defined PLOT_LIKELIHOOD
465 watplot WTS(
const_cast<char*
>(
"wts"));
466 WTS.plot(pwc, cid, nifo,
'L', 0,
const_cast<char*
>(
"COLZ"));
467 WTS.canvas->Print(
"l_tfmap_scalogram.png");
475 CWB::config* cfg,
bool fft,
bool strain) {
477 watplot PTS(
const_cast<char*
>(
"ptswrc"),200,20,800,500);
480 double tmin = wfREC->start();
481 wfREC->start(wfREC->start()-tmin);
483 PTS.plot(wfREC,
const_cast<char*
>(
"ALP"), 1, 0, 0,
true, cfg->fLow, cfg->fHigh);
485 PTS.plot(wfREC,
const_cast<char*
>(
"ALP"), 1, 0, 0);
487 PTS.graph[0]->SetLineWidth(1);
488 wfREC->start(wfREC->start()+tmin);
499 PTS.canvas->Print(
fname);
500 cout <<
"write : " <<
fname << endl;
509 n = ifo->IWFP.size();
510 for (
int i=0;i<
n;i++) {
511 wavearray<double>*
wf = (wavearray<double>*)ifo->IWFP[i];
517 n = ifo->RWFP.size();
518 for (
int i=0;i<
n;i++) {
519 wavearray<double>*
wf = (wavearray<double>*)ifo->RWFP[i];
526 std::vector<netpixel>
DoPCA(
network* NET, CWB::config* cfg,
int lag,
int id) {
530 size_t nIFO = NET->ifoList.size();
532 float En = 2*NET->acor*NET->acor*
nIFO;
534 int size = NET->a_00.size();
538 netcluster* pwc = NET->getwc(lag);
539 std::vector<netpixel> vPIX;
541 std::vector<int> pI = NET->wdmMRA.getXTalk(pwc,
id,
false);
543 if(V>cfg->BATCH)
return vPIX;
545 wavearray<float> xi(
size); xi=0;
546 wavearray<float> XI(
size); XI=0;
548 __m128* _xi = (__m128*) xi.data;
549 __m128* _XI = (__m128*) XI.data;
551 __m128* _aa = (__m128*) NET->a_00.data;
552 __m128* _AA = (__m128*) NET->a_90.data;
555 for(
int j=0; j<V; j++) {
557 _sse_zero_ps(_xi+jf);
558 _sse_zero_ps(_XI+jf);
559 ee = _sse_abs_ps(_aa+jf,_AA+jf);
560 if(ee>En) nPC++;
else ee=0.;
561 NET->rNRG.data[j] = ee;
562 NET->pNRG.data[j] = NET->rNRG.data[j];
565 nPC = NET->_sse_mra_ps(xi.data,XI.data,En,nPC);
567 for(
int j=0; j<V; j++) {
568 pix = pwc->getPixel(
id,pI[j]);
569 vPIX.push_back(*pix);
571 ee = NET->pNRG.data[j];
574 for(
int i=0; i<
nIFO; i++) {
575 pix->setdata(
double(xi.data[j*NIFO+i]),
'S',i);
576 pix->setdata(
double(XI.data[j*NIFO+i]),
'P',i);
583 void ResetPCA(
network* NET, CWB::config* cfg, netcluster* pwc, std::vector<netpixel>* vPIX,
int ID) {
585 std::vector<int> pI = NET->wdmMRA.getXTalk(pwc, ID,
false);
587 if(V>cfg->BATCH)
return;
588 for(
int j=0; j<V; j++) {
589 netpixel* pix = pwc->getPixel(ID,pI[j]);
593 while(!vPIX->empty()) vPIX->pop_back();
594 vPIX->clear(); std::vector<netpixel>().swap(*vPIX);
614 #pragma GCC system_header
619 #include "network.hh"
620 #include "wavearray.hh"
622 #include "TObjArray.h"
623 #include "TObjString.h"
625 #include "Toolbox.hh"
643 #define SETHR 1000000
668 CWB_Plugin(TFile* jfile, CWB::config* cfg,
network* net, WSeries<double>* x, TString ifo,
int type) {
674 cout <<
"-----> CWB_Plugin_Gating.C" << endl;
675 cout <<
"ifo " << ifo.Data() << endl;
676 cout <<
"type " << type << endl;
679 if(type==CWB_PLUGIN_ECOHERENCE) {
684 size_t gILEVEL=-1; IMPORT(
size_t,gILEVEL)
685 char slevel[256];
sprintf(slevel,
",%d,",gILEVEL);
687 int nIFO = net->ifoListSize();
688 detector* pD[NIFO_MAX];
689 for(
int n=0;
n<
nIFO;
n++) pD[
n] = net->getifo(
n);
690 WSeries<double>* WS[NIFO_MAX];
691 for(
int n=0;
n<
nIFO;
n++) WS[
n] = pD[
n]->getTFmap();
693 int layers = WS[0]->maxLayer()+1;
694 int slices = WS[0]->sizeZero();
696 double df = WS[0]->resolution();
697 double dt = 1./(2*df);
699 int rate = int(1./dt);
701 cout <<
"layers : " << layers <<
"\t slices : " << slices <<
"\t rate : " << rate
702 <<
"\t dt : " << dt <<
"\t df : " << df << endl;
704 double rTWIN = fabs(
TWIN/dt-TMath::Nint(
TWIN/dt));
705 if(TWIN<dt || rTWIN>1e-7) {
706 cout <<
"-----> CWB_Plugin_Gating.C : Error-> " <<
" TWIN=" <<
TWIN
707 <<
" is not a multiple of dt=" << dt << endl;
711 double rTEDG = fabs(
TEDG/dt-TMath::Nint(
TEDG/dt));
712 if(TEDG<dt || rTEDG>1e-7) {
713 cout <<
"-----> CWB_Plugin_Gating.C : Error-> " <<
" TEDG=" <<
TEDG
714 <<
" is not a multiple of dt=" << dt << endl;
722 wavearray<double> se[NIFO_MAX];
724 se[
n].resize(slices); se[
n]=0;
725 for(
int i=0;i<slices;i++) {
726 for(
int j=0;j<layers;j++) se[
n][i] += WS[
n]->getSample(i,j);
733 int N = int(
TWIN/dt);
735 wavearray<double> SE[NIFO_MAX];
737 SE[
n].resize(slices); SE[
n]=0;
738 for(
int i=N-1;i<slices;i++)
for(
int j=0;j<N;j++) SE[
n][i]+=se[
n][i-j];
747 int X = int(cfg->segEdge/dt+0.5);
748 int M = int(
TEDG/dt)+1;
749 wavearray<int> sCut[NIFO_MAX];
751 sCut[
n].resize(slices); sCut[
n]=0;
752 for(
int i=0;i<slices;i++) {
754 int is = i-
M>X ? i-
M : X;
755 int es = i+
M<(slices-X) ? i+
M : slices-X;
756 for(
int ii=is;ii<es;ii++) sCut[
n][ii]=1;
765 double gating_time=0.;
767 for(
int i=0;i<slices;i++) {
770 for(
int j=0;j<layers;j++) WS[
n]->putSample(-1e20,i,j);
777 sprintf(info,
"-RES:%d-GT:%g",cfg->l_high-gILEVEL,gating_time);
778 cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
779 gCWB2G->PrintAnalysisInfo(CWB_STAGE_COHERENCE,
"cwb2G::Coherence",info,
false);
805 #pragma GCC system_header
812 CWB_Plugin(TFile* jfile, CWB::config* cfg,
network* net, WSeries<double>* x, TString ifo,
int type) {
834 #pragma GCC system_header
838 #include "network.hh"
839 #include "wavearray.hh"
841 #include "TObjArray.h"
842 #include "TObjString.h"
844 #include "TComplex.h"
852 CWB_Plugin(TFile* jfile, CWB::config* cfg,
network* net, WSeries<double>* x, TString ifo,
int type) {
857 cout <<
"-----> plugins/CWB_Plugin_EBBH.C" << endl;
858 cout <<
"ifo " << ifo.Data() << endl;
859 cout <<
"type " << type << endl;
862 if(type==CWB_PLUGIN_CONFIG) {
867 if(type==CWB_PLUGIN_MDC) {
870 sprintf(
cmd,
"network* net = (network*)%p;",net);
871 gROOT->ProcessLine(
cmd);
872 sprintf(
cmd,
"CWB::config* cfg = (CWB::config*)%p;",cfg);
873 gROOT->ProcessLine(
cmd);
881 cfg->configPlugin.Exec();
902 if(ifo.CompareTo(net->ifoName[0])==0) {
903 net->mdcList.clear();
904 net->mdcType.clear();
905 net->mdcTime.clear();
906 net->mdcList=
MDC.mdcList;
907 net->mdcType=
MDC.mdcType;
908 net->mdcTime=
MDC.mdcTime;
910 double Tb = x->start();
911 double dT = x->size()/x->rate();
914 sprintf(log_label,
"%d_%d_%s_job%d",
int(Tb),
int(dT),cfg->data_label,net->nRun);
915 sprintf(tmpFile,
"%s/%s-LogTMP.txt",cfg->log_dir,log_label);
916 cout <<
"Write MDC Log : " << tmpFile << endl;
917 MDC.DumpLog(tmpFile);
924 for(
int k=0;k<(int)net->mdcList.size();k++) cout << k <<
" mdcList " <<
MDC.mdcList[k] << endl;
925 for(
int k=0;k<(
int)net->mdcTime.size();k++) cout << k <<
" mdcTime " <<
MDC.mdcTime[k] << endl;
926 for(
int k=0;k<(
int)net->mdcType.size();k++) cout << k <<
" mdcType " <<
MDC.mdcType[k] << endl;
967 #pragma GCC system_header
972 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 ClearWaveforms(detector *ifo)
void PlotWaveform(TString ifo, wavearray< double > *wfREC, CWB::config *cfg, bool fft=false, bool strain=false)
void ResetPCA(network *NET, CWB::config *cfg, netcluster *pwc, std::vector< netpixel > *vPIX, int ID)
void GetLveto(netcluster *pwc, int cid, int nifo, float *Lveto)
float GetQveto(wavearray< double > *wf)
std::vector< netpixel > DoPCA(network *NET, CWB::config *cfg, int lag, int id)
void 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)
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *NET, WSeries< double > *x, TString ifo, int type)