3 #pragma GCC system_header
8 #include "wavearray.hh"
10 #include "TObjArray.h"
11 #include "TObjString.h"
17 #include "gwavearray.hh"
27 void GetLveto(netcluster* pwc,
int cid,
int nifo,
float* Lveto);
28 void GetWveto(netcluster* pwc,
int cid,
int nifo,
float* Wveto);
30 CWB::config* cfg,
bool fft=
false,
bool strain=
false);
35 CWB_Plugin(TFile* jfile, CWB::config* cfg,
network* NET, WSeries<double>* x, TString ifo,
int type) {
40 cout <<
"-----> CWB_Plugin_QLWveto.C" << endl;
41 cout <<
"ifo " << ifo.Data() << endl;
42 cout <<
"type " << type << endl;
45 float Qveto[2*NIFO_MAX];
49 if(type==CWB_PLUGIN_CONFIG) {
53 if(type==CWB_PLUGIN_ILIKELIHOOD) {
58 TList *files = (TList*)gROOT->GetListOfFiles();
61 int nIFO = NET->ifoListSize();
67 while ((file=(TSystemFile*)next())) {
68 fname = file->GetName();
70 if(
fname.Contains(
"wave_")) {
71 froot=(TFile*)file;froot->cd();
73 outDump.ReplaceAll(
".root.tmp",
".txt");
78 cout <<
"CWB_Plugin_QLWveto.C : Error - output root file not found" << endl;
82 cout <<
"CWB_Plugin_QLWveto.C : Error - output root file not found" << endl;
86 TTree* net_tree = (TTree *) froot->Get(
"waveburst");
88 EVT =
new netevent(
nIFO);
89 net_tree = EVT->setTree();
90 net_tree->Branch(
"Qveto",Qveto,TString::Format(
"Qveto[%i]/F",2*cfg->nIFO));
91 net_tree->Branch(
"Lveto",Lveto,TString::Format(
"Lveto[%i]/F",3));
92 net_tree->Branch(
"Wveto",Wveto,TString::Format(
"Wveto[%i]/F",2));
96 if(type==CWB_PLUGIN_OLIKELIHOOD) {
98 if(TString(cfg->analysis)!=
"2G") {
99 cout <<
"CWB_Plugin_QLWveto.C -> "
100 <<
"CWB_PLUGIN_OLIKELIHOOD implemented only for 2G" << endl;
105 int gIFACTOR=-1; IMPORT(
int,gIFACTOR)
106 cout <<
"-----> CWB_Plugin_QLWveto.C -> "
107 <<
" gIFACTOR : " << gIFACTOR << endl;
110 float* gSLAGSHIFT=NULL; IMPORT(
float*,gSLAGSHIFT)
112 int nIFO = NET->ifoListSize();
115 wavearray<double>
id;
117 double factor = cfg->factors[gIFACTOR];
122 TList *files = (TList*)gROOT->GetListOfFiles();
129 while ((file=(TSystemFile*)next())) {
130 fname = file->GetName();
132 if(
fname.Contains(
"wave_")) {
133 froot=(TFile*)file;froot->cd();
135 outDump.ReplaceAll(
".root.tmp",
".txt");
140 cout <<
"CWB_Plugin_QLWveto.C : Error - output root file not found" << endl;
144 cout <<
"CWB_Plugin_QLWveto.C : Error - output root file not found" << endl;
148 TTree* net_tree = (TTree *) froot->Get(
"waveburst");
150 EVT =
new netevent(net_tree,
nIFO);
151 net_tree->SetBranchAddress(
"Qveto",Qveto);
152 net_tree->SetBranchAddress(
"Lveto",Lveto);
153 net_tree->SetBranchAddress(
"Wveto",Wveto);
155 EVT =
new netevent(
nIFO);
156 net_tree = EVT->setTree();
157 net_tree->Branch(
"Qveto",Qveto,TString::Format(
"Qveto[%i]/F",2*cfg->nIFO));
158 net_tree->Branch(
"Lveto",Lveto,TString::Format(
"Lveto[%i]/F",3));
159 net_tree->Branch(
"Wveto",Wveto,TString::Format(
"Wveto[%i]/F",2));
161 EVT->setSLags(gSLAGSHIFT);
163 for(
int k=0; k<K; k++) {
165 id = NET->getwc(k)->get(
const_cast<char*
>(
"ID"), 0,
'L', rate);
167 for(
int j=0; j<(int)
id.
size(); j++) {
169 int ID = size_t(
id.
data[j]+0.5);
171 if(NET->getwc(k)->sCuts[ID-1]!=-1)
continue;
174 if(cfg->simulation==4) ofactor=-factor;
175 else if(cfg->simulation==3) ofactor=-gIFACTOR;
178 EVT->output2G(NULL,NET,ID,k,ofactor);
180 wavearray<double>** pwfREC =
new wavearray<double>*[
nIFO];
181 detector* pd = NET->getifo(0);
182 int idSize = pd->RWFID.size();
185 for (
int mm=0; mm<idSize; mm++)
if (pd->RWFID[mm]==ID) wfIndex=mm;
186 if(wfIndex==-1)
continue;
188 netcluster* pwc = NET->getwc(k);
189 cout << endl <<
"----------------------------------------------------------------" << endl;
191 cout <<
"Lveto : " <<
"fmean : " << Lveto[0] <<
" frms : " << Lveto[1]
192 <<
" Energy Ratio : " << Lveto[2] << endl << endl;
194 cout <<
"Wveto : " <<
" Slope : " << Wveto[0] <<
" Correlation : " << Wveto[1] << endl << endl;
201 pwfREC[
n] = pd->RWFP[wfIndex];
202 wavearray<double>* wfREC = pwfREC[
n];
204 #ifdef PLOT_WHITENED_WAVEFORMS
209 NET->getMRAwave(ID,k,
'S',0,
true);
212 NET->getMRAwave(ID,k,
'W',0,
true);
216 cout <<
"Qveto : " << pd->Name <<
" Qveto[R] = " << Qveto[
n]
217 <<
" Qveto[W] = " << Qveto[
n+
nIFO] << endl;
221 cout <<
"----------------------------------------------------------------" << endl;
224 std::vector<int> sCuts = NET->getwc(k)->sCuts;
226 for(
int i=0; i<(int)sCuts.size(); i++)
if(i!=ID-1) NET->getwc(k)->sCuts[i]=1;
229 NET->getwc(k)->sCuts = sCuts;
231 if(cfg->dump) EVT->dopen(outDump.Data(),
const_cast<char*
>(
"a"),
false);
232 EVT->output2G(net_tree,NET,ID,k,ofactor);
235 fprintf(EVT->fP,
"Qveto: ");
236 for(
int i=0; i<2*
nIFO; i++) fprintf(EVT->fP,
"%f ",Qveto[i]);
237 fprintf(EVT->fP,
"\n");
239 fprintf(EVT->fP,
"Lveto: ");
240 for(
int i=0; i<3; i++) fprintf(EVT->fP,
"%f ",Lveto[i]);
241 fprintf(EVT->fP,
"\n");
243 fprintf(EVT->fP,
"Wveto: ");
244 for(
int i=0; i<2; i++) fprintf(EVT->fP,
"%f ",Wveto[i]);
245 fprintf(EVT->fP,
"\n");
247 if(cfg->dump) EVT->dclose();
248 if(!cfg->cedDump) NET->getwc(k)->sCuts[ID-1]=1;
261 wavearray<double> x = *
wf;;
266 x.resize(4*x.size());
268 for(
int j=xsize;j<x.size();j++) x[j]=0;
272 wavearray<double> a(x.size());
274 double dt = 1./x.rate();
277 for (
int i=1;i<x.size();i++) {
278 if(fabs(x[i])>xmax) xmax=fabs(x[i]);
290 for (
int i=1;i<
size;i++) {
291 if(a[i]>amax) {amax=a[i];imax=i;}
307 for (
int i=0;i<
size;i++) {
308 if(abs(imax-i)<=
NTHR) {
312 if(a[i]>amax/
ATHR) eout+=a[i]*a[i];
316 float Qveto = ein>0 ? eout/ein : 0.;
323 GetLveto(netcluster* pwc,
int cid,
int nifo,
float* Lveto) {
335 Lveto[0] = Lveto[1] = Lveto[2] = 0;
337 std::vector<int>* vint = &(pwc->cList[cid-1]);
338 int V = vint->size();
349 for(
int n=0;
n<V;
n++) {
350 netpixel* pix = pwc->getPixel(cid,
n);
351 if(pix->layers%2==0) {
352 cout <<
"CWB_Plugin_QLWveto.C - Error : is enabled only for WDM (2G)" << endl;
355 if(!pix->core)
continue;
358 for(
int m=0;
m<nifo;
m++) {
359 likePix += pow(pix->getdata(
'S',
m),2);
360 likePix += pow(pix->getdata(
'P',
m),2);
363 double freq = pix->frequency*pix->rate/2.;
364 double df = pix->rate/2.;
367 if(likePix>likeMax) {likeMax=likePix;freqMax=freq;dfreqMax=df;}
379 for(
int n=0;
n<V;
n++) {
380 netpixel* pix = pwc->getPixel(cid,
n);
381 if(!pix->core)
continue;
384 for(
int m=0;
m<nifo;
m++) {
385 likePix += pow(pix->getdata(
'S',
m),2);
386 likePix += pow(pix->getdata(
'P',
m),2);
391 double freq = pix->frequency*pix->rate/2.;
392 if(fabs(freq-freqMax)<=dfreqMax) {
394 fmean += likePix*freq;
395 frms += likePix*freq*freq;
399 fmean = fmean/likeLin;
400 frms = frms/likeLin-fmean*fmean;
401 frms = frms>0 ? sqrt(frms) : 0.;
403 if(frms<dfreqMax/2.) frms=dfreqMax/2.;
411 Lveto[2] = likeTot>0. ? likeLin/likeTot : 0.;
417 #if defined PLOT_LIKELIHOOD
418 watplot WTS(
const_cast<char*
>(
"wts"));
419 WTS.plot(pwc, cid, nifo,
'L', 0,
const_cast<char*
>(
"COLZ"));
420 WTS.canvas->Print(
"l_tfmap_scalogram.png");
427 GetWveto(netcluster* pwc,
int cid,
int nifo,
float* Wveto) {
438 Wveto[0] = Wveto[1] = 0;
440 std::vector<int>* vint = &(pwc->cList[cid-1]);
441 int V = vint->size();
444 std::vector<double> x;
445 std::vector<double> y;
446 std::vector<double>
w;
449 for(
int j=0; j<V; j++) {
450 netpixel* pix = pwc->getPixel(cid,j);
451 if(pix->layers%2==0) {
452 cout <<
"CWB_Plugin_QLWveto.C - Error : is enabled only for WDM (2G)" << endl;
455 if(pix->likelihood<1. || pix->frequency==0)
continue;
458 double time = int(
double(pix->time)/pix->layers)/pix->rate;
459 double freq = pix->frequency*pix->rate/2.;
463 w.push_back(pix->likelihood);
468 double xcm, ycm, qxx, qyy, qxy, ew;
469 xcm = ycm = qxx = qyy = qxy = ew = 0;
471 for(
int i=0; i<
size; ++i) {
479 for(
int i=0; i<
size; ++i) {
480 qxx += (x[i] - xcm)*(x[i] - xcm)*
w[i];
481 qyy += (y[i] - ycm)*(y[i] - ycm)*
w[i];
482 qxy += (x[i] - xcm)*(y[i] - ycm)*
w[i];
485 double beta = qxy/qxx;
486 double alpha = ycm-beta*xcm;
487 double corr = qxy/sqrt(qxx*qyy);
488 double duration = sqrt(qxx/ew);
489 double bandwidth = sqrt(qyy/ew);
495 Wveto[1] = fabs(corr);
502 CWB::config* cfg,
bool fft,
bool strain) {
504 watplot PTS(
const_cast<char*
>(
"ptswrc"),200,20,800,500);
507 double tmin = wfREC->start();
508 wfREC->start(wfREC->start()-tmin);
510 PTS.plot(wfREC,
const_cast<char*
>(
"ALP"), 1, 0, 0,
true, cfg->fLow, cfg->fHigh);
512 PTS.plot(wfREC,
const_cast<char*
>(
"ALP"), 1, 0, 0);
514 PTS.graph[0]->SetLineWidth(1);
515 wfREC->start(wfREC->start()+tmin);
526 PTS.canvas->Print(
fname);
527 cout <<
"write : " <<
fname << endl;
536 n = ifo->IWFP.size();
537 for (
int i=0;i<
n;i++) {
538 wavearray<double>*
wf = (wavearray<double>*)ifo->IWFP[i];
544 n = ifo->RWFP.size();
545 for (
int i=0;i<
n;i++) {
546 wavearray<double>*
wf = (wavearray<double>*)ifo->RWFP[i];
void ClearWaveforms(detector *ifo)
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 PlotWaveform(TString ifo, wavearray< double > *wfREC, CWB::config *cfg, bool fft=false, bool strain=false)
float GetQveto(wavearray< double > *wf)
void GetLveto(netcluster *pwc, int cid, int nifo, float *Lveto)
sprintf(tag,"wave_%s", data_label)