28 #pragma GCC system_header
33 #include "wavearray.hh"
35 #include "TObjArray.h"
36 #include "TObjString.h"
48 CWB_Plugin(TFile* jfile, CWB::config* cfg,
network* net, WSeries<double>* x, TString ifo,
int type) {
50 if(type==CWB_PLUGIN_CONFIG) {
54 if(type==CWB_PLUGIN_MDC) {
56 cout <<
"Execute CWB_Plugin_MDC_OTF.C : Inject On The Fly MDC ..." << endl;
64 CWB_PLUGIN_EXPORT(
MDC)
66 int gIFACTOR=-1; IMPORT(
int,gIFACTOR)
67 int xstart = (int)x->start();
68 int xstop = (int)x->stop();
69 CWB_PLUGIN_EXPORT(net)
70 CWB_PLUGIN_EXPORT(cfg)
71 CWB_PLUGIN_EXPORT(xstart)
72 CWB_PLUGIN_EXPORT(xstop)
73 CWB_PLUGIN_EXPORT(gIFACTOR)
83 int gIFOID=0;
for(
int n=0;
n<cfg->nIFO;
n++)
if(ifo==net->getifo(
n)->Name) {gIFOID=
n;
break;}
85 gROOT->ProcessLine(
cmd);
87 sprintf(
cmd,
"network* net = (network*)%p;",net);
88 gROOT->ProcessLine(
cmd);
90 sprintf(
cmd,
"CWB::config* cfg = (CWB::config*)%p;",cfg);
91 gROOT->ProcessLine(
cmd);
93 sprintf(
cmd,
"int xstart = %d;",(
int)x->start());
94 gROOT->ProcessLine(
cmd);
97 gROOT->ProcessLine(
cmd);
101 cfg->configPlugin.Exec(NULL,&error);
103 cout <<
"Error executing macro : " << cfg->configPlugin.GetTitle() << endl;
104 cfg->configPlugin.Print();
125 if(ifo.CompareTo(net->ifoName[0])==0) {
126 net->mdcList.clear();
127 net->mdcType.clear();
128 net->mdcTime.clear();
129 net->mdcList=
MDC.mdcList;
130 net->mdcType=
MDC.mdcType;
131 net->mdcTime=
MDC.mdcTime;
142 int runID = net->nRun;
143 int Tb=x->start()+cfg->segEdge;
144 int dT=x->size()/x->rate()-2*cfg->segEdge;
145 sprintf(logFile,
"%s/log_%d_%d_%s_job%d.txt",cfg->output_dir,
int(Tb),
int(dT),cfg->data_label,runID);
146 cout <<
"Dump : " << logFile << endl;
147 if(ifo==cfg->ifo[0])
MDC.DumpLog(logFile);
155 if(ifo.CompareTo(net->ifoName[0])==0) {
156 for(
int k=0;k<(int)net->mdcList.size();k++) cout << k <<
" mdcList " <<
MDC.mdcList[k] << endl;
157 for(
int k=0;k<(
int)net->mdcTime.size();k++) cout << k <<
" mdcTime " <<
MDC.mdcTime[k] << endl;
158 for(
int k=0;k<(
int)net->mdcType.size();k++) cout << k <<
" mdcType " <<
MDC.mdcType[k] << endl;
181 #pragma GCC system_header
185 #include "network.hh"
186 #include "wavearray.hh"
188 #include "TObjArray.h"
189 #include "TObjString.h"
191 #include "TComplex.h"
194 #include "watplot.hh"
195 #include "gwavearray.hh"
209 void GetQveto(wavearray<double>*
wf,
float &Qveto,
float &Qfactor);
210 void GetLveto(netcluster* pwc,
int cid,
int nifo,
float* Lveto);
211 void PlotWaveform(TString ifo, wavearray<double>* wfREC,
212 CWB::config* cfg,
bool fft=
false,
bool strain=
false);
215 std::vector<netpixel>
DoPCA(
network* NET, CWB::config* cfg,
int lag,
int id);
216 void ResetPCA(
network* NET, CWB::config* cfg, netcluster* pwc, std::vector<netpixel>* vPIX,
int ID);
220 CWB_Plugin(TFile* jfile, CWB::config* cfg,
network* NET, WSeries<double>* x, TString ifo,
int type) {
225 cout <<
"-----> CWB_Plugin_QLveto.C" << endl;
226 cout <<
"ifo " << ifo.Data() << endl;
227 cout <<
"type " << type << endl;
233 if(type==CWB_PLUGIN_CONFIG) {
237 if(type==CWB_PLUGIN_ILIKELIHOOD) {
242 TList *files = (TList*)gROOT->GetListOfFiles();
245 int nIFO = NET->ifoListSize();
251 while ((file=(TSystemFile*)next())) {
252 fname = file->GetName();
254 if(
fname.Contains(
"wave_")) {
255 froot=(TFile*)file;froot->cd();
257 outDump.ReplaceAll(
".root.tmp",
".txt");
262 cout <<
"CWB_Plugin_QLveto.C : Error - output root file not found" << endl;
266 cout <<
"CWB_Plugin_QLveto.C : Error - output root file not found" << endl;
270 TTree* net_tree = (TTree *) froot->Get(
"waveburst");
272 EVT =
new netevent(
nIFO);
273 net_tree = EVT->setTree();
274 net_tree->Branch(
"Qveto",Qveto,TString::Format(
"Qveto[%i]/F",2));
275 net_tree->Branch(
"Lveto",Lveto,TString::Format(
"Lveto[%i]/F",3));
278 bool qveto_exists=
false;
279 bool lveto_exists=
false;
280 TIter next(net_tree->GetListOfBranches());
281 while ((branch=(TBranch*)next())) {
282 if(TString(
"Qveto").CompareTo(branch->GetName())==0) qveto_exists=
true;
283 if(TString(
"Lveto").CompareTo(branch->GetName())==0) lveto_exists=
true;
286 if(!qveto_exists) net_tree->Branch(
"Qveto",Qveto,TString::Format(
"Qveto[%i]/F",2));
287 if(!lveto_exists) net_tree->Branch(
"Lveto",Lveto,TString::Format(
"Lveto[%i]/F",3));
291 if(type==CWB_PLUGIN_OLIKELIHOOD) {
293 if(TString(cfg->analysis)!=
"2G") {
294 cout <<
"CWB_Plugin_QLveto.C -> "
295 <<
"CWB_PLUGIN_OLIKELIHOOD implemented only for 2G" << endl;
300 int gIFACTOR=-1; IMPORT(
int,gIFACTOR)
301 cout <<
"-----> CWB_Plugin_QLveto.C -> "
302 <<
" gIFACTOR : " << gIFACTOR << endl;
305 float* gSLAGSHIFT=NULL; IMPORT(
float*,gSLAGSHIFT)
307 int nIFO = NET->ifoListSize();
310 wavearray<double>
id;
312 double factor = cfg->factors[gIFACTOR];
317 TList *files = (TList*)gROOT->GetListOfFiles();
324 while ((file=(TSystemFile*)next())) {
325 fname = file->GetName();
327 if(
fname.Contains(
"wave_")) {
328 froot=(TFile*)file;froot->cd();
330 outDump.ReplaceAll(
".root.tmp",
".txt");
335 cout <<
"CWB_Plugin_QLveto.C : Error - output root file not found" << endl;
339 cout <<
"CWB_Plugin_QLveto.C : Error - output root file not found" << endl;
343 TTree* net_tree = (TTree *) froot->Get(
"waveburst");
345 EVT =
new netevent(net_tree,
nIFO);
346 net_tree->SetBranchAddress(
"Qveto",Qveto);
347 net_tree->SetBranchAddress(
"Lveto",Lveto);
349 EVT =
new netevent(
nIFO);
350 net_tree = EVT->setTree();
351 net_tree->Branch(
"Qveto",Qveto,TString::Format(
"Qveto[%i]/F",2));
352 net_tree->Branch(
"Lveto",Lveto,TString::Format(
"Lveto[%i]/F",3));
354 EVT->setSLags(gSLAGSHIFT);
356 for(
int k=0; k<K; k++) {
358 id = NET->getwc(k)->get(
const_cast<char*
>(
"ID"), 0,
'L', rate);
360 for(
int j=0; j<(int)
id.
size(); j++) {
362 int ID = size_t(
id.
data[j]+0.5);
364 if(NET->getwc(k)->sCuts[ID-1]!=-1)
continue;
367 if(cfg->simulation==4) ofactor=-factor;
368 else if(cfg->simulation==3) ofactor=-gIFACTOR;
371 EVT->output2G(NULL,NET,ID,k,ofactor);
373 wavearray<double>** pwfREC =
new wavearray<double>*[
nIFO];
374 detector* pd = NET->getifo(0);
375 int idSize = pd->RWFID.size();
378 for (
int mm=0; mm<idSize; mm++)
if (pd->RWFID[mm]==ID) wfIndex=mm;
379 if(wfIndex==-1)
continue;
381 netcluster* pwc = NET->getwc(k);
382 cout << endl <<
"----------------------------------------------------------------" << endl;
385 Qveto[0]=Qveto[1]=1.e20;
390 pwfREC[
n] = pd->RWFP[wfIndex];
391 wavearray<double>* wfREC = pwfREC[
n];
393 #ifdef PLOT_WHITENED_WAVEFORMS
401 NET->getMRAwave(ID,k,
'S',0,
true);
402 GetQveto(&(pd->waveForm), qveto, qfactor);
403 if(qveto<Qveto[0]) Qveto[0]=qveto;
404 if(qfactor<Qveto[1]) Qveto[1]=qfactor;
407 NET->getMRAwave(ID,k,
'W',0,
true);
408 GetQveto(&(pd->waveBand), qveto, qfactor);
409 if(qveto<Qveto[0]) Qveto[0]=qveto;
410 if(qfactor<Qveto[1]) Qveto[1]=qfactor;
412 cout <<
"Qveto : " << pd->Name <<
" Qveto[0] = " << Qveto[0]
413 <<
" Qveto[1] = " << Qveto[1] << endl;
419 std::vector<netpixel> vPIX;
420 if(cfg->pattern>0) vPIX =
DoPCA(NET, cfg, k, ID);
422 if(cfg->pattern>0)
ResetPCA(NET, cfg, pwc, &vPIX, ID);
425 cout <<
"Lveto : " <<
"fmean : " << Lveto[0] <<
" frms : " << Lveto[1]
426 <<
" Energy Ratio : " << Lveto[2] << endl << endl;
427 cout <<
"----------------------------------------------------------------" << endl;
429 std::vector<int> sCuts = NET->getwc(k)->sCuts;
431 for(
int i=0; i<(int)sCuts.size(); i++)
if(i!=ID-1) NET->getwc(k)->sCuts[i]=1;
434 NET->getwc(k)->sCuts = sCuts;
436 if(cfg->dump) EVT->dopen(outDump.Data(),
const_cast<char*
>(
"a"),
false);
437 EVT->output2G(net_tree,NET,ID,k,ofactor);
440 fprintf(EVT->fP,
"Qveto: ");
441 for(
int i=0; i<2*
nIFO; i++) fprintf(EVT->fP,
"%f ",Qveto[i]);
442 fprintf(EVT->fP,
"\n");
444 fprintf(EVT->fP,
"Lveto: ");
445 for(
int i=0; i<3; i++) fprintf(EVT->fP,
"%f ",Lveto[i]);
446 fprintf(EVT->fP,
"\n");
448 if(cfg->dump) EVT->dclose();
449 if(!cfg->cedDump) NET->getwc(k)->sCuts[ID-1]=1;
460 GetQveto(wavearray<double>*
wf,
float &Qveto,
float &Qfactor) {
462 wavearray<double> x = *
wf;;
467 x.resize(4*x.size());
469 for(
int j=xsize;j<x.size();j++) x[j]=0;
473 wavearray<double> a(x.size());
475 double dt = 1./x.rate();
478 for (
int i=1;i<x.size();i++) {
479 if(fabs(x[i])>xmax) xmax=fabs(x[i]);
491 for (
int i=1;i<
size;i++) {
492 if(a[i]>amax) {amax=a[i];imax=i;}
508 for (
int i=0;i<
size;i++) {
509 if(abs(imax-i)<=
NTHR) {
513 if(a[i]>amax/
ATHR) eout+=a[i]*a[i];
517 Qveto = ein>0 ? eout/ein : 0.;
521 float R = (a[imax-1]+a[imax+1])/a[imax]/2.;
522 Qfactor = sqrt(-pow(TMath::Pi(),2)/log(
R)/2.);
529 GetLveto(netcluster* pwc,
int cid,
int nifo,
float* Lveto) {
541 Lveto[0] = Lveto[1] = Lveto[2] = 0;
543 std::vector<int>* vint = &(pwc->cList[cid-1]);
544 int V = vint->size();
555 for(
int n=0;
n<V;
n++) {
556 netpixel* pix = pwc->getPixel(cid,
n);
557 if(pix->layers%2==0) {
558 cout <<
"CWB_Plugin_QLveto.C - Error : is enabled only for WDM (2G)" << endl;
561 if(!pix->core)
continue;
564 for(
int m=0;
m<nifo;
m++) {
565 likePix += pow(pix->getdata(
'S',
m),2);
566 likePix += pow(pix->getdata(
'P',
m),2);
569 double freq = pix->frequency*pix->rate/2.;
570 double df = pix->rate/2.;
573 if(likePix>likeMax) {likeMax=likePix;freqMax=freq;dfreqMax=df;}
585 for(
int n=0;
n<V;
n++) {
586 netpixel* pix = pwc->getPixel(cid,
n);
587 if(!pix->core)
continue;
590 for(
int m=0;
m<nifo;
m++) {
591 likePix += pow(pix->getdata(
'S',
m),2);
592 likePix += pow(pix->getdata(
'P',
m),2);
597 double freq = pix->frequency*pix->rate/2.;
598 if(fabs(freq-freqMax)<=dfreqMax) {
600 fmean += likePix*freq;
601 frms += likePix*freq*freq;
605 fmean = fmean/likeLin;
606 frms = frms/likeLin-fmean*fmean;
607 frms = frms>0 ? sqrt(frms) : 0.;
609 if(frms<dfreqMax/2.) frms=dfreqMax/2.;
617 Lveto[2] = likeTot>0. ? likeLin/likeTot : 0.;
623 #if defined PLOT_LIKELIHOOD
624 watplot WTS(
const_cast<char*
>(
"wts"));
625 WTS.plot(pwc, cid, nifo,
'L', 0,
const_cast<char*
>(
"COLZ"));
626 WTS.canvas->Print(
"l_tfmap_scalogram.png");
634 CWB::config* cfg,
bool fft,
bool strain) {
636 watplot PTS(
const_cast<char*
>(
"ptswrc"),200,20,800,500);
639 double tmin = wfREC->start();
640 wfREC->start(wfREC->start()-tmin);
642 PTS.plot(wfREC,
const_cast<char*
>(
"ALP"), 1, 0, 0,
true, cfg->fLow, cfg->fHigh);
644 PTS.plot(wfREC,
const_cast<char*
>(
"ALP"), 1, 0, 0);
646 PTS.graph[0]->SetLineWidth(1);
647 wfREC->start(wfREC->start()+tmin);
658 PTS.canvas->Print(
fname);
659 cout <<
"write : " <<
fname << endl;
668 n = ifo->IWFP.size();
669 for (
int i=0;i<
n;i++) {
670 wavearray<double>*
wf = (wavearray<double>*)ifo->IWFP[i];
676 n = ifo->RWFP.size();
677 for (
int i=0;i<
n;i++) {
678 wavearray<double>*
wf = (wavearray<double>*)ifo->RWFP[i];
685 std::vector<netpixel>
DoPCA(
network* NET, CWB::config* cfg,
int lag,
int id) {
689 size_t nIFO = NET->ifoList.size();
691 float En = 2*NET->acor*NET->acor*
nIFO;
693 int size = NET->a_00.size();
697 netcluster* pwc = NET->getwc(lag);
698 std::vector<netpixel> vPIX;
700 std::vector<int> pI = NET->wdmMRA.getXTalk(pwc,
id,
false);
702 if(V>cfg->BATCH)
return vPIX;
704 wavearray<float> xi(
size); xi=0;
705 wavearray<float> XI(
size); XI=0;
707 __m128* _xi = (__m128*) xi.data;
708 __m128* _XI = (__m128*) XI.data;
710 __m128* _aa = (__m128*) NET->a_00.data;
711 __m128* _AA = (__m128*) NET->a_90.data;
714 for(
int j=0; j<V; j++) {
716 _sse_zero_ps(_xi+jf);
717 _sse_zero_ps(_XI+jf);
718 ee = _sse_abs_ps(_aa+jf,_AA+jf);
719 if(ee>En) nPC++;
else ee=0.;
720 NET->rNRG.data[j] = ee;
721 NET->pNRG.data[j] = NET->rNRG.data[j];
724 nPC = NET->_sse_mra_ps(xi.data,XI.data,En,nPC);
726 for(
int j=0; j<V; j++) {
727 pix = pwc->getPixel(
id,pI[j]);
728 vPIX.push_back(*pix);
730 ee = NET->pNRG.data[j];
733 for(
int i=0; i<
nIFO; i++) {
734 pix->setdata(
double(xi.data[j*NIFO+i]),
'S',i);
735 pix->setdata(
double(XI.data[j*NIFO+i]),
'P',i);
742 void ResetPCA(
network* NET, CWB::config* cfg, netcluster* pwc, std::vector<netpixel>* vPIX,
int ID) {
744 std::vector<int> pI = NET->wdmMRA.getXTalk(pwc, ID,
false);
746 if(V>cfg->BATCH)
return;
747 for(
int j=0; j<V; j++) {
748 netpixel* pix = pwc->getPixel(ID,pI[j]);
752 while(!vPIX->empty()) vPIX->pop_back();
753 vPIX->clear(); std::vector<netpixel>().swap(*vPIX);
772 #pragma GCC system_header
777 #include "network.hh"
778 #include "wavearray.hh"
780 #include "TObjArray.h"
781 #include "TObjString.h"
783 #include "Toolbox.hh"
798 #define SETHR 1000000
815 CWB_Plugin(TFile* jfile, CWB::config* cfg,
network* net, WSeries<double>* x, TString ifo,
int type) {
820 cout <<
"-----> CWB_Plugin_Gating.C" << endl;
821 cout <<
"ifo " << ifo.Data() << endl;
822 cout <<
"type " << type << endl;
825 if(type==CWB_PLUGIN_ICOHERENCE) {
828 cwb2G* gCWB2G; IMPORT(cwb2G*,gCWB2G)
829 double Tb = gCWB2G->Tb-cfg->segEdge;
830 double Te = gCWB2G->Te+cfg->segEdge;
834 int nIFO = (gCWB2G->singleDetector) ? 1 : net->ifoListSize();
835 int size = net->getifo(0)->getHoT()->size();
836 double rate = net->getifo(0)->getHoT()->rate();
841 wavearray<double>* hot[NIFO_MAX];
842 for(
int n=0;
n<
nIFO;
n++) hot[
n] = net->getifo(
n)->getHoT();
850 int X = int(cfg->segEdge/dt+0.5);
851 int M = int(
TEDG/dt)+1;
852 int N = int(
TWIN/dt);
854 vector<waveSegment> glist;
855 wavearray<double> SE(
size);
856 wavearray<int> sVeto(
size);
861 for(
int i=N-1;i<
size;i++)
for(
int j=0;j<N;j++) SE[i]+=pow(hot[
n]->
data[i-j],2);
863 for(
int i=0;i<
size;i++) {
865 int is = i-
M>X ? i-
M : X;
867 for(
int k=is;k<es;k++) sVeto[k]=1;
871 sVeto[0]=0;sVeto[
size-1]=0;
872 for(
int i=0;i<
size-1;i++) sVeto[i]=sVeto[i+1]-sVeto[i];
877 for(
int i=0;i<
size;i++) {
878 if(sVeto[i]== 1) gseg.start = Tb+int(i*dt);
880 gseg.stop = Tb+int(i*dt+0.5);
882 glist.push_back(gseg);
889 for(
int j=gsize;j<glist.size();j++) {
890 cout << j <<
" -----> CWB_Plugin_Gating.C - " << net->getifo(
n)->Name <<
" gating time : start="
891 << glist[j].start <<
" stop=" << glist[j].stop <<
" len=" << glist[j].stop-glist[j].start << endl;
898 double gating_time = 0;
900 glist = CWB::Toolbox::unionSegments(glist);
901 gating_time = CWB::Toolbox::getTimeSegList(glist);
902 glist = CWB::Toolbox::invertSegments(glist);
903 net->segList = CWB::Toolbox::mergeSegLists(glist,net->segList);
906 cout<<
"-----> CWB_Plugin_Gating.C - gating time : " << gating_time << endl << endl;
910 sprintf(info,
"-GT:%g",gating_time);
911 gCWB2G->PrintAnalysisInfo(CWB_STAGE_COHERENCE,
"cwb2G::Coherence",info,
false);
937 #pragma GCC system_header
942 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)
void CWB_Plugin(TFile *jfile, CWB::config *cfg, network *NET, WSeries< double > *x, TString ifo, int type)