39 #include "TTreeFormula.h" 49 std::sort(vec.begin(), vec.end());
50 vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
76 typedef struct{
double value;
int type;} EndPoint;
79 { EndPoint*
a = (EndPoint*)p;
80 EndPoint* b = (EndPoint*)q;
81 if(a->value > b->value)
return 1;
132 size_t nbig = abs(nBIG);
140 std::vector<int> refI;
141 std::vector<float> refF;
142 std::vector<vector_int>::const_iterator it;
153 this->nPIX = value.
nPIX;
156 this->pair = value.
pair;
157 this->nSUB = value.
nSUB;
159 if(!value.
cList.size()) {
160 this->pList = value.
pList;
162 return this->pList.size();
165 for(it=value.
cList.begin(); it!=value.
cList.end(); it++){
167 ID = value.
pList[(*it)[0]].clusterID;
169 if(value.
sCuts[ID-1]>0)
continue;
170 if(nBIG>0 && K>nbig)
continue;
171 if(nBIG<0 && K<nbig)
continue;
173 vr = value.
cRate[ID-1];
177 R =
int(value.
pList[(*it)[k]].rate+0.1);
183 this->pList.reserve(N+2);
185 for(it=value.
cList.begin(); it!=value.
cList.end(); it++){
188 ID = value.
pList[(*it)[0]].clusterID;
189 if(value.
sCuts[ID-1]>0)
continue;
192 vr = value.
cRate[ID-1];
199 pix = value.
pList[(*it)[
k]];
200 R =
int(value.
pList[(*it)[k]].rate+0.1);
203 if(vr[0] != R)
continue;
209 n = this->pList.size();
212 this->pList[n-1].append(1);
218 if(!
id.
size()) cout<<
"netcluster::cpf() error: empty cluster.";
221 cData.push_back(value.
cData[ID-1]);
224 p_Ind.push_back(refI);
225 p_Map.push_back(refF);
226 sArea.push_back(refF);
227 nTofF.push_back(refI);
228 cTime.push_back(value.
cTime[ID-1]);
229 cFreq.push_back(value.
cFreq[ID-1]);
231 return this->pList.size();
238 this->cpf(value,
false);
250 for(i=0; i<this->cList.size(); i++){
252 v = &(this->cList[
i]);
256 if(
id && this->pList[(*v)[k]].clusterID !=
id)
continue;
257 this->pList[(*v)[
k]].core =
core;
269 if(!this->pList.size())
return 0;
271 if(!this->nSUB) this->nSUB=(2*
iGamma(pList[0].
size()-1,0.314));
278 if(strstr(name,
"subnet")) {
279 out = this->
get(
const_cast<char*
>(
"subnet"),0,
'S');
280 for(
int i=0;
i<I;
i++){
282 if(aa<thr) this->ignore(ID.
data[
i]);
286 if(strstr(name,
"subrho")) {
287 out = this->
get(
const_cast<char*
>(
"subrho"),0,
'S');
288 for(
int i=0;
i<I;
i++){
290 if(aa<thr) this->ignore(ID.
data[
i]);
294 if(strstr(name,
"SUBCUT")) {
298 double prl,qrl,ptime,qtime,pfreq,qfreq;
299 int N = pList.size();
303 for(
int i=0;
i<I;
i++){
306 aa = aa*(1+aa/max.
data[
i]);
308 if(out.
data[
i]>thr)
continue;
309 this->ignore(ID.
data[
i]);
314 for(
int n=0;
n<
N;
n++) {
321 for(
int k;
k<
K;
k++){
327 if(
fabs(qfreq-pfreq)>128 &&
328 fabs(qtime-ptime)>0.125)
continue;
341 if(!pList.size() || !cList.size())
return 0;
347 int K = pList.size();
350 vector<vector_int>::iterator it;
352 for(it=this->cList.begin(); it != this->cList.end(); it++) {
354 pix = &(this->pList[((*it)[0])]);
356 if(this->sCuts[ID-1]==0)
continue;
358 for(
size_t n=0;
n<it->size();
n++) {
359 pix = &(this->pList[((*it)[
n])]);
379 size_t K = this->pList.size();
390 q = &(this->pList[
k]);
391 u = &(this->pList[
k].neighbors);
398 cout<<
"netcluster::delink(): cluster ID mismatch"<<endl;
415 size_t n = this->pList.size();
417 size_t M = this->pList[0].layers;
418 double R = this->pList[0].rate;
425 if(n==1)
return this->
cluster();
431 for(i=0; i<
n; i++) { pp[
i] = &(pList[
i]); pp[
i]->
neighbors.clear();}
437 bool isWavelet = (size_t(this->
rate/R+0.1) == pp[
i]->
layers) ?
true :
false;
440 cout<<
"netcluster::cluster(int,int) applied to mixed pixel list"<<endl;
442 for(j=i+1; j<
n; j++){
450 if(index < 0) cout<<
"netcluster::cluster(int,int) sort error"<<endl;
452 if(index/M > kt)
break;
454 if(index > kt)
break;
479 vector<float> refArea;
482 size_t n = pList.size();
484 if(!pList.size())
return 0;
499 for(i=0; i<
n; i++) pList[i].clusterID = 0;
504 if(pList[i].clusterID)
continue;
505 pList[
i].clusterID = ++nCluster;
508 cRate.push_back(refRate);
509 cTime.push_back(-1.);
510 cFreq.push_back(-1.);
511 p_Ind.push_back(refRate);
512 p_Map.push_back(refArea);
513 sArea.push_back(refArea);
514 nTofF.push_back(refRate);
515 refMask.resize(volume);
516 cList.push_back(refMask);
517 cData.push_back(refCD);
521 vector<vector_int>::iterator it;
523 if(!cList.size())
return 0;
525 for(it=cList.begin(); it != cList.end(); it++) {
530 if(pList[i].clusterID == nCluster) (*it)[m++] =
i;
533 if(it->size() !=
m) {
534 cout<<
"cluster::cluster() size mismatch error: ";
535 cout<<m<<
" size="<<it->size()<<
" "<<nCluster<<endl;
565 if(!pList.size() || !cList.size())
return 0;
572 vector<vector_int>::iterator it;
574 std::vector<int>*
pr;
575 std::vector<int> refI;
576 std::vector<float> refF;
582 for(it=x.
cList.begin(); it != x.
cList.end(); it++) {
584 pix = &(x.
pList[((*it)[0])]);
586 if(x.
sCuts[ID-1]>0)
continue;
588 pr = n ? &(x.
cRate[ID-1]) : NULL;
592 for(i=0; i<it->size(); i++) {
593 pix = &(x.
pList[((*it)[
i])]);
604 if(!i) cout<<
"netcluster::cleanhalo() error: empty cluster.";
608 cData.push_back(x.
cData[ID-1]);
610 if(pr) cRate.push_back(*pr);
611 p_Ind.push_back(refI);
612 p_Map.push_back(refF);
613 sArea.push_back(refF);
614 nTofF.push_back(refI);
615 cTime.push_back(x.
cTime[ID-1]);
616 cFreq.push_back(x.
cFreq[ID-1]);
622 pList[
id[i-1]].append(
id[i]-
id[i-1]);
623 pList[
id[
i]].append(
id[i-1]-
id[i]);
636 if(!pList.size() || !cList.size())
return 0;
637 if(mode==0)
return pList.size();
648 vector<vector_int>::iterator it;
651 std::vector<int> nid;
652 std::vector<int>* pn;
653 std::vector<int> refI;
654 std::vector<float> refF;
659 for(k=0; k<9; k++) {nid.push_back(0); jj.push_back(0);}
661 for(it=x.
cList.begin(); it != x.
cList.end(); it++) {
663 pix = &(x.
pList[((*it)[0])]);
665 if(x.
sCuts[ID-1]>0)
continue;
670 for(i=0; i<it->size(); i++) {
671 pix = &(x.
pList[((*it)[
i])]);
678 for(i=0; i<it->size(); i++) {
679 pix = &(x.
pList[((*it)[
i])]);
682 if(!(J%M) || !((J-1)%M) || !((J-2)%M) || !((J+1)%M))
continue;
686 jj[1]=J-M+1; jj[2]=J+1; jj[3]=J+M+1;
687 jj[4]=J-M-1; jj[5]=J-1; jj[6]=J+M-1;
690 jj[1]=J-M-1; jj[2]=J+M+1; K=3;
691 }
else if(mode==-3) {
692 jj[1]=J+M-1; jj[2]=J-M+1; K=3;
694 jj[1]=J-2*M-2; jj[2]=J+2*M+3;
695 jj[3]=J-M-1; jj[4]=J+M+1; K=5;
696 }
else if(mode==-5) {
697 jj[1]=J+2*M-2; jj[2]=J-2*M+3;
698 jj[3]=J+M-1; jj[4]=J-M+1; K=5;
700 jj[1]=J-M-1; jj[2]=J+M+1;
701 jj[3]=J+M-1; jj[4]=J-M+1; K=5;
704 for(k=0; k<
K; k++) nid[k]=0;
705 for(j=0; j<
id.size(); j++) {
706 PIX = &(this->pList[
id[
j]]);
711 if(J==jj[k]) nid[
k] =
id[
j]+1;
717 if(nid[k]!=0)
continue;
721 for(n=0; n<
nIFO; n++) {
722 pix->
data[
n].index+=jj[
k]-jj[0];
728 pn = &(this->pList[nid[0]-1].neighbors);
731 for(j=0; j<pn->size(); j++)
732 if(nid[k]==(*pn)[
j]+1) save=
false;
733 if(save) pn->push_back(nid[k]-1);
739 cData.push_back(x.
cData[ID-1]);
740 cRate.push_back(refI);
741 p_Ind.push_back(refI);
742 p_Map.push_back(refF);
743 sArea.push_back(refF);
744 nTofF.push_back(refI);
745 cTime.push_back(x.
cTime[ID-1]);
746 cFreq.push_back(x.
cFreq[ID-1]);
749 if(!i) cout<<
"netcluster::addhalo() error: empty cluster.";
752 pList[
id[i-1]].append(
id[0]-
id[i-1]);
753 pList[
id[0]].append(
id[i-1]-
id[0]);
755 pList[
id[i-1]].append(
id[i]-
id[i-1]);
756 pList[
id[
i]].append(
id[i-1]-
id[i]);
776 size_t on = pList.size();
783 if(!in) {
return on; }
788 printf(
"\n netcluster::append(): cluster type mismatch");
794 this->pList.reserve(in+on+2);
811 size_t n = pList.size();
831 for(i=0; i<
n; i++) { pp[
i] = &(pList[
i]);}
843 for(j=i+1; j<
n; j++){
850 if(qtime<ptime-eps) cout<<
"netcluster::merge() error"<<endl;
852 if(qtime-ptime > 1.)
break;
853 if(
fabs(qtime-ptime) > eps)
continue;
859 if(
fabs(pfreq-qfreq) > eps)
continue;
869 if((*v)[k] == l) {insert=
false;
break;}
871 if(insert) p->append(l);
881 if((*v)[k] == l) {insert=
false;
break;}
883 if(insert) q->append(l);
888 if(ppo==pp) free(pp);
889 else {cout<<
"netcluster::cluster() free()\n";
exit(1);}
895 std::vector<vector_int>::iterator it;
897 std::vector<int>
rate;
898 std::vector<int> temp;
899 std::vector<int> sIZe;
900 std::vector<bool> cuts;
901 std::vector<double> ampl;
902 std::vector<double> powr;
903 std::vector<double> like;
905 double a,
L,
e,tt,cT,cF,nT,nF;
911 bool oEo = atype==
'E' || atype==
'P';
913 for(it=cList.begin(); it != cList.end(); it++) {
915 if(!k) cout<<
"netcluster::supercluster() error: empty cluster.\n";
929 ID = pList[((*it)[0])].clusterID;
932 pix = &(pList[((*it)[
i])]);
933 if(!pix->
core && core)
continue;
936 for(j=0; j<pix->
size(); j++) {
937 a = pix->
data[
j].asnr;
938 e+=
fabs(a)>1. ? a*a-1 : 0.;
941 a = atype==
'L' ?
L :
e;
943 mm = size_t(this->rate*tt+0.1);
944 cT += (pix->
time/mm + 0.5)*
a;
950 for(j=0; j<rate.size(); j++) {
951 if(rate[j] ==
int(pix->
rate+0.1)) {
960 rate.push_back(
int(pix->
rate+0.1));
964 cuts.push_back(
true);
971 cout<<
"netcluster::merge() error: cluster ID mismatch.\n";
977 if(rate.size()<size_t(1+this->pair) || m<nPIX){ sCuts[ID-1] =
true;
continue; }
980 for(i=0; i<rate.size(); i++) {
981 if((atype==
'L' && like[i]<S) || (oEo && ampl[
i]<
S))
continue;
982 if(!pair) { cuts[
i] = cut =
false;
continue; }
983 for(j=0; j<rate.size(); j++) {
984 if((atype==
'L' && like[j]<S) || (oEo && ampl[
j]<
S))
continue;
985 if(rate[i]/2==rate[j] || rate[j]/2==rate[i]) {
986 cuts[
i] = cuts[
j] = cut =
false;
990 if(cut || sCuts[ID-1]) { sCuts[ID-1] =
true;
continue; }
995 for(j=0; j<rate.size(); j++) {
996 powr[
j] = ampl[
j]/sIZe[
j];
997 if(atype==
'E' && ampl[j]>a && !cuts[j]) {max=
j; a=ampl[
j];}
998 if(atype==
'L' && like[j]>a && !cuts[j]) {max=
j; a=like[
j];}
999 if(atype==
'P' && powr[j]>a && !cuts[j]) {max=
j; a=powr[
j];}
1002 if(a<S) { sCuts[ID-1] =
true;
continue; }
1005 for(j=0; j<rate.size(); j++) {
1006 if(max==j)
continue;
1007 if(atype==
'E' && ampl[j]>a && !cuts[j]) {min=
j; a=ampl[
j];}
1008 if(atype==
'L' && like[j]>a && !cuts[j]) {min=
j; a=like[
j];}
1009 if(atype==
'P' && powr[j]>a && !cuts[j]) {max=
j; a=powr[
j];}
1012 temp.push_back(rate[max]);
1013 temp.push_back(rate[min]);
1014 cTime[ID-1] = cT/nT;
1015 cFreq[ID-1] = cF/nF;
1050 size_t n = pList.size();
1057 std::vector<int>*
v;
1058 double eps,E,R,
T,
dT,dF,prl,qrl,aa;
1060 double ptime, pfreq;
1061 double qtime, qfreq;
1063 size_t nIFO = pList[0].size();
1071 for(i=0; i<
n; i++) {
1072 pp[
i] = &(pList[
i]);
1074 if(1./R > Tgap) Tgap = 1./R;
1085 for(i=0; i<
n; i++) {
1088 ptime = p->
time/prl;
1091 for(j=i+1; j<
n; j++){
1095 qtime = q->
time/qrl;
1096 if(qtime-ptime > Tgap) {
break;}
1102 cout<<
"netcluster::supercluster() error "<<qtime-ptime<<endl;
1110 for(k=0; k<
nIFO; k++) {
1111 aa = p->
data[
k].index/prl;
1112 aa-= q->
data[
k].index/qrl;
1117 dF =
fabs(qfreq-pfreq) - 0.5*R;
1118 eps = (dT>0?dT*R:0) + (dF>0?dF*T:0);
1119 if(his) his->Fill(eps);
1120 if(gap < eps)
continue;
1126 v = &(p->neighbors);
1129 for(k=0; k<
m; k++) {
1130 if((*v)[k] == l) {insert=
false;
break;}
1133 if(insert) p->append(l);
1139 v = &(q->neighbors);
1142 for(k=0; k<
m; k++) {
1143 if((*v)[k] == l) {insert=
false;
break;}
1146 if(insert) q->append(l);
1150 if(ppo==pp) free(pp);
1151 else {cout<<
"netcluster::supercluster() free()\n";
exit(1);}
1157 std::vector<vector_int>::iterator it;
1159 std::vector<int>
rate;
1160 std::vector<int> temp;
1161 std::vector<int> sIZe;
1162 std::vector<bool> cuts;
1163 std::vector<double> ampl;
1164 std::vector<double> powr;
1165 std::vector<double> like;
1167 double a,
L,
e,tt,cT,cF,nT,nF;
1173 bool oEo = atype==
'E' || atype==
'P';
1175 for(it=cList.begin(); it != cList.end(); it++) {
1177 if(!k) cout<<
"netcluster::supercluster() error: empty cluster.\n";
1191 ID = pList[((*it)[0])].clusterID;
1193 for(i=0; i<
k; i++) {
1194 pix = &(pList[((*it)[
i])]);
1195 if(!pix->
core && core)
continue;
1198 for(j=0; j<pix->
size(); j++) {
1199 a = pix->
data[
j].asnr;
1200 e+=
fabs(a)>1. ?
a : 0.;
1203 a = atype==
'L' ?
L :
e;
1212 for(j=0; j<rate.size(); j++) {
1213 if(rate[j] ==
int(pix->
rate+0.1)) {
1222 rate.push_back(
int(pix->
rate+0.1));
1226 cuts.push_back(
true);
1233 cout<<
"netcluster::supercluster() error: cluster ID mismatch.\n";
1239 if((
int)rate.size()< this->pair+1 || m<nPIX){ sCuts[ID-1] = 1;
continue; }
1242 for(i=0; i<rate.size(); i++) {
1243 if((atype==
'L' && like[i]<S) || (oEo && ampl[
i]<
S))
continue;
1244 if(!pair) { cuts[
i] = cut =
false;
continue; }
1245 for(j=0; j<rate.size(); j++) {
1246 if((atype==
'L' && like[j]<S) || (oEo && ampl[
j]<
S))
continue;
1247 if(rate[i]/2==rate[j] || rate[j]/2==rate[i]) {
1248 cuts[
i] = cuts[
j] = cut =
false;
1252 if(cut || sCuts[ID-1]) { sCuts[ID-1] = 1;
continue; }
1257 for(j=0; j<rate.size(); j++) {
1258 powr[
j] = ampl[
j]/sIZe[
j];
1259 if(atype==
'E' && ampl[j]>a && !cuts[j]) {max=
j; a=ampl[
j];}
1260 if(atype==
'L' && like[j]>a && !cuts[j]) {max=
j; a=like[
j];}
1261 if(atype==
'P' && powr[j]>a && !cuts[j]) {max=
j; a=powr[
j];}
1264 if(a<S) { sCuts[ID-1] = 1;
continue; }
1267 for(j=0; j<rate.size(); j++) {
1268 if(max==j)
continue;
1269 if(atype==
'E' && ampl[j]>a && !cuts[j]) {min=
j; a=ampl[
j];}
1270 if(atype==
'L' && like[j]>a && !cuts[j]) {min=
j; a=like[
j];}
1271 if(atype==
'P' && powr[j]>a && !cuts[j]) {min=
j; a=powr[
j];}
1274 temp.push_back(rate[max]);
1275 temp.push_back(rate[min]);
1277 cTime[ID-1] = cT/nT;
1278 cFreq[ID-1] = cF/nF;
1280 cData[ID-1].cTime = cT/nT;
1281 cData[ID-1].cFreq = cF/nF;
1282 cData[ID-1].energy = E;
1283 cData[ID-1].likenet = E;
1302 size_t I = pList.size();
1306 if(tgap<=0 && fgap<=0)
return 0;
1310 std::vector<int>*
v;
1311 std::vector<int>* u;
1312 double R,
T,
dT,dF,
x,
a,E,prl,qrl;
1314 double ptime, pfreq;
1315 double qtime, qfreq;
1317 size_t nIFO = pList[0].size();
1322 for(i=0; i<I; i++) {
1323 pp[
i] = &(pList[
i]);
1325 if(!(pp[i]->clusterID)) {
1326 cout<<
"defragment: un-clustered pixel list \n";
exit(1);
1328 if(1./R > Tgap) Tgap = 1./R;
1330 if(Tgap<tgap) Tgap = tgap;
1340 for(i=0; i<I; i++) {
1344 if(sCuts[n-1]==1)
continue;
1345 ptime = p->
time/prl;
1348 for(j=i+1; j<I; j++){
1352 if(sCuts[m-1]==1)
continue;
1354 qtime = q->
time/qrl;
1355 if(qtime-ptime > Tgap) {
break;}
1363 cout<<
"netcluster::defragment() error "<<qtime-ptime<<endl;
1369 for(k=0; k<
nIFO; k++) {
1370 a = p->
data[
k].index/prl;
1371 a -= q->
data[
k].index/qrl;
1376 dF =
fabs(qfreq-pfreq) - 0.25*R;
1377 if(his) his->Fill(dT,dF);
1378 if(dT > tgap)
continue;
1379 if(dF > fgap)
continue;
1385 v = &(p->neighbors);
1387 for(k=0; k<v->size(); k++) {
1388 if((*v)[
k] ==
l) {insert=
false;
break;}
1391 if(insert) p->append(l);
1397 v = &(q->neighbors);
1399 for(k=0; k<v->size(); k++) {
1400 if((*v)[
k] ==
l) {insert=
false;
break;}
1403 if(insert) q->append(l);
1407 v = &(this->cList[n-1]);
1408 u = &(this->cList[m-1]);
1409 for(k=0; k<u->size(); k++) {
1410 pList[(*u)[
k]].clusterID =
n;
1411 v->push_back((*u)[k]);
1418 if(ppo==pp) free(pp);
1419 else {cout<<
"netcluster::defragment() free()\n";
exit(1);}
1437 double kk = 256.*Pi/5*pow(G*SM*Pi/C/C/C, 5./3);
1439 std::vector<int>* vint = &this->cList[ID-1];
1440 int V = vint->size();
1443 bool chi2_cut = chi2_thr<0 ? true :
false;
1444 chi2_thr =
fabs(chi2_thr);
1446 double*
x =
new double[V];
1447 double*
y =
new double[V];
1448 double* xerr =
new double[V];
1449 double* yerr =
new double[V];
1450 double* wgt =
new double[V];
1457 this->cData[ID-1].chi2chirp = 0;
1458 this->cData[ID-1].mchirp = 0 ;
1459 this->cData[ID-1].mchirperr = -1;
1460 this->cData[ID-1].tmrgr = 0;
1461 this->cData[ID-1].tmrgrerr = -1;
1462 this->cData[ID-1].chirpEllip = 0;
1463 this->cData[ID-1].chirpEfrac = 0;
1464 this->cData[ID-1].chirpPfrac = 0;
1468 kk *= pow(sF, 8./3);
1470 double xmin,ymin, xmax, ymax;
1471 xmin = ymin = 1e100;
1472 xmax = ymax = -1e100;
1474 double emax = -1e100;
1475 for(
int j=0;
j<V;
j++) {
1479 double zthr = zmax_thr*emax;
1481 for(
int j=0;
j<V;
j++) {
1491 xerr[
np] = 0.5/pix->
rate;
1492 xerr[
np] = xerr[
np]*sqrt(2.);
1496 yerr[
np] = yerr[
np]/sqrt(3.);
1501 yerr[
np] *= 8./3/pow(y[np], 11./3);
1502 y[
np] = 1./pow(y[np], 8./3);
1504 if(x[np]>xmax) xmax = x[
np];
1505 if(x[np]<xmin) xmin = x[
np];
1506 if(y[np]>ymax) ymax = y[
np];
1507 if(y[np]<ymin) ymin = y[
np];
1512 double xcm, ycm, qxx, qyy, qxy;
1513 xcm = ycm = qxx = qyy = qxy = 0;
1515 for(
int i=0;
i<
np; ++
i){
1522 for(
int i=0;
i<
np; ++
i){
1523 qxx += (x[
i] - xcm)*(x[
i] - xcm);
1524 qyy += (y[
i] - ycm)*(y[
i] - ycm);
1525 qxy += (x[
i] - xcm)*(y[
i] - ycm);
1531 double sq_delta = sqrt( (qxx - qyy)*(qxx - qyy) + 4*qxy*qxy );
1532 double lam1 = (qxx + qyy + sq_delta)/2;
1533 double lam2 = (qxx + qyy - sq_delta)/2;
1536 double ellipt =
fabs((lam1 - lam2)/(lam1 + lam2));
1538 const double maxM = 100;
1539 const double stepM = 0.2;
1540 const int massPoints = 1001;
1542 int maxMasses[massPoints];
1545 EndPoint* bint[massPoints];
1546 for(
int j=0;
j<massPoints; ++
j) bint[
j] =
new EndPoint[2*np];
1551 for(
double m = -maxM;
m<maxM + 0.01;
m+=stepM){
1552 double sl = kk*pow(
fabs(
m), 5./3);
1556 for(
int i=0;
i<
np; ++
i){
1557 double Db = sqrt( 2 * (sl*sl*xerr[
i]*xerr[
i] + yerr[
i]*yerr[
i]) );
1558 double bmini = y[
i] - sl*x[
i] - Db;
1559 double bmaxi = bmini + 2*Db;
1560 bint[massIndex][
j].value = bmini;
1561 bint[massIndex][
j].type = 1;
1562 bint[massIndex][++
j].value = bmaxi;
1563 bint[massIndex][j++].type = -1;
1565 qsort(bint[massIndex], 2*np,
sizeof(EndPoint),
compEndP);
1568 for(j=1; j<2*
np; ++
j){
1569 bint[massIndex][
j].type += bint[massIndex][j-1].type;
1570 if(bint[massIndex][j].type>nsel)nsel = bint[massIndex][
j].type;
1574 maxMasses[0] = massIndex;
1577 else if(nsel == nselmax) maxMasses[nmaxm++] = massIndex;
1584 double chi2min = 1e100;
1587 for(
int j=0;
j<nmaxm; ++
j){
1588 double m = -maxM + maxMasses[
j]*stepM;
1589 double sl = kk*pow(
fabs(m), 5./3);
1592 for(
int k=0;
k<2*np-1; ++
k)
if(bint[maxMasses[
j]][
k].type==nselmax)
1593 for(
double b = bint[maxMasses[
j]][
k].
value; b<bint[maxMasses[
j]][
k+1].value; b+=0.0025){
1596 for(
int i=0;
i<
np; ++
i){
1597 double chi2 = y[
i] - sl*x[
i] - b;
1599 chi2 /= (sl*sl*xerr[
i]*xerr[
i] + yerr[
i]*yerr[
i]);
1600 if(chi2>chi2_thr)
continue;
1601 totchi += chi2*wgt[
i];
1604 totchi = totwgt ? totchi/totwgt : 2e100;
1613 for(
int j=0;
j<massPoints; ++
j)
delete [] bint[
j];
1616 double sl = kk*pow(
fabs(m0), 5./3);
1625 for(
int i=0;
i<
np; ++
i){
1627 double chi2 = y[
i] - sl*x[
i] - b0;
1629 chi2 /= (sl*sl*xerr[
i]*xerr[
i] + yerr[
i]*yerr[
i]);
1630 chi2T += chi2*wgt[
i];
1631 if(chi2>chi2_thr)
continue;
1633 if(x[
i]>tmax2) tmax2 = x[
i];
1636 double Efrac = selEn/totEn;
1637 chi2T = chi2T/totEn;
1645 int nifo = pList[0].size();
1646 for(
int i=0;
i<
np; ++
i){
1647 if(x[
i]<tmax2) Pfrac += 1.0;
1648 double chi2 = y[
i] - sl*x[
i] -b0;
1650 chi2 /= (sl*sl*xerr[
i]*xerr[
i] + yerr[
i]*yerr[
i]);
1652 if(chi2>chi2_thr)
continue;
1653 x[
j] = x[
i]; xerr[
j] = xerr[
i];
1654 y[
j] = y[
i]; yerr[
j] = yerr[
i];
1662 for(
int i=0;
i<V; ++
i){
1668 double eT = 0.5/pix->
rate;
1670 double eF = pix->
rate/4;
1677 eF *= 8./3/pow(F, 11./3);
1678 F = 1./pow(F, 8./3);
1680 double chi2 = F - sl*T -b0;
1682 chi2 /= (sl*sl*eT*eT + eF*eF);
1683 if(chi2_cut && chi2<chi2_thr) {
1695 xcm = ycm = qxx = qyy = qxy = 0;
1697 for(
int i=0;
i<
np; ++
i){
1704 for(
int i=0;
i<
np; ++
i){
1705 qxx += (x[
i] - xcm)*(x[
i] - xcm);
1706 qyy += (y[
i] - ycm)*(y[
i] - ycm);
1707 qxy += (x[
i] - xcm)*(y[
i] - ycm);
1713 sq_delta = sqrt( (qxx - qyy)*(qxx - qyy) + 4*qxy*qxy );
1714 lam1 = (qxx + qyy + sq_delta)/2;
1715 lam2 = (qxx + qyy - sq_delta)/2;
1718 double ellipt2 =
fabs((lam1 - lam2)/(lam1 + lam2));
1728 int np2 = np*0.5, Trials=500;
1729 if(np2<3)np2 = np-1;
1731 if(np2<8)Trials = np2;
1732 else if(np2<15) Trials = np2*np2/2;
1733 else if(np2<20) Trials = np2*np2*np2/6;
1734 if(Trials>500) Trials = 500;
1735 if(Trials<0) Trials=0;
1737 this->cData[ID-1].mchpdf.resize(Trials);
1743 for(
int ii=0; ii<Trials; ++ii){
1746 for(
int k,
i=0;
i<np2; ++
i){
1747 do k = rnd.Uniform(0. , np - 1
e-10);
1753 double sx=0, sy=0, sx2=0, sxy=0;
1754 for(
int i=0;
i<
np; ++
i)
if(used[
i]){
1761 double slp = (sy/np2 - sxy/sx)/(sx2/sx - sx/np2);
1762 double b = (sy + slp*sx)/np2;
1764 slpv.
data[ii] = slp;
1765 mchv.
data[ii] = slp>0 ? pow(slp/kk,0.6) : -pow(-slp/kk, 0.6);
1766 bv.
data[ii] = b/slp;
1767 this->cData[ID-1].mchpdf.data[ii] = mchv.
data[ii];
1771 size_t nn = mchv.
size()-1;
1772 size_t ns = size_t(mchv.
size()*0.16);
1773 cData[ID-1].mchirperr = Trials>8 ? ( mchv.
waveSplit(0,nn,nn-ns)-mchv.
waveSplit(0,nn,ns) ) / 2 : 2*mchv.
rms();
1778 sprintf(name,
"netcluster::mchirp5:func_%d", ID);
1781 TGraphErrors *
gr =
new TGraphErrors(np, x, y, xerr, yerr);
1782 TF1 *
f =
new TF1(name,
"[0]*x + [1]", xmin, xmax);
1784 this->cData[ID-1].chirp.Set(np);
1785 for(
int i=0;
i<
np;
i++) {
1786 this->cData[ID-1].chirp.SetPoint(
i,x[
i],y[i]);
1787 this->cData[ID-1].chirp.SetPointError(i,xerr[i],yerr[i]);
1789 this->cData[ID-1].fit.SetName(
TString(
"TGraphErrors_"+
TString(name)).Data());
1790 this->cData[ID-1].chirp.SetName(
TString(
"TF1_"+
TString(name)).Data());
1792 TF1* f = &(this->cData[ID-1].fit);
1793 TGraphErrors* gr = &(this->cData[ID-1].chirp);
1795 *gr = TGraphErrors(np, x, y, xerr, yerr);
1796 *f = TF1(name,
"[0]*x + [1]", xmin, xmax);
1799 f->SetParameter(0, sl);
1800 f->SetParameter(1, b0);
1804 int ndf = f->GetNDF();
1805 double mch = -f->GetParameter(0)/kk;
1806 double relerr =
fabs(f->GetParError(0)/f->GetParameter(0));
1807 if(ndf==0)
return -1;
1808 this->cData[ID-1].mchirp = mch>0 ? pow(mch, 0.6) : -pow(-mch, 0.6);
1809 this->cData[ID-1].tmrgr = -f->GetParameter(1)/f->GetParameter(0);
1810 this->cData[ID-1].tmrgrerr = chi2T;
1811 this->cData[ID-1].chirpEllip = ellipt2;
1812 this->cData[ID-1].chirpEfrac = Efrac;
1813 this->cData[ID-1].chirpPfrac = Pfrac;
1814 this->cData[ID-1].chi2chirp = chi2T;
1816 this->cData[ID-1].tmrgrerr = 0.;
1819 double tmerger = -f->GetParameter(1)/f->GetParameter(0);
1820 for(
int i=0;
i<V; ++
i){
1824 if(T>(tmerger+tmerger_cut)) pix->
likelihood=0;
1828 this->cData[ID-1].fit = *
f;
1852 this->cData[ID-1].chi2chirp = 0;
1853 this->cData[ID-1].mchirp = 0 ;
1854 this->cData[ID-1].mchirperr = -1;
1855 this->cData[ID-1].tmrgr = 0;
1856 this->cData[ID-1].tmrgrerr = -1;
1858 double kf = pow(5./256, 3./8) * pow( C*C*C/G/SM, 5./8) /
Pi;
1859 double kdf = sqrt(0.6*kf*3./8);
1861 std::vector<int>* vint = &this->cList[ID-1];
1862 int V = vint->size();
1866 double minDT=1e10, minFreq=1e10;
1868 for(
int j=0;
j<V;
j++) {
1872 if(pix->
rate/2. < minFreq) minFreq = pix->
rate/2;
1873 if(1./pix->
rate < minDT) minDT = 1./pix->
rate;
1876 int naux = 1./(2*minDT*minFreq) + 0.5;
1881 double*
x =
new double[Vp];
1882 double*
y =
new double[Vp];
1883 double* wgt =
new double[Vp];
1884 bool*
sel =
new bool[Vp];
1891 double xmin,ymin, xmax, ymax;
1892 xmin = ymin = 1e100;
1893 xmax = ymax = -1e100;
1897 for(
int j=0;
j<V;
j++) {
1904 int nx = 1./pix->
rate/minDT + 0.5;
1905 int ny = pix->
rate/2/minFreq + 0.5;
1907 for(
int ix=0; ix<nx; ++ix) {
1908 for(
int iy=0; iy<ny; ++iy){
1909 x[
np] = T - 0.5/pix->
rate + (ix+0.5)*minDT;
1913 if(x[np]>xmax)xmax = x[
np];
1914 if(x[np]<xmin)xmin = x[
np];
1915 if(y[np]>ymax)ymax = y[
np];
1916 if(y[np]<ymin)ymin = y[
np];
1922 const double maxM = 30;
1923 const double stepM = 0.1;
1927 double m0 = 0, t0max = 0;
1928 double t0 = (tmin*2 + tmax)/3;
1957 int tPoints = (tmax + 1 -
t0)/minDT + 1;
1958 double* maxTimes =
new double[tPoints];
1959 double* maxMasses =
new double[tPoints];
1962 EndPoint** mint =
new EndPoint*[tPoints];
1963 for(
int j=0;
j<tPoints; ++
j) mint[
j] =
new EndPoint[2*np];
1966 for(; t0<tmax+1; t0 += minDT){
1968 for(
int i=0;
i<
np; ++
i){
1969 double dt = t0 - x[
i];
1971 double dt38 = sqrt(sqrt(dt));
1974 double b = kdf/sqrt(dt*dt38);
1975 double Delta = sqrt(b*b + 4*a*y[
i]);
1977 mint[tIndex][
j].value = pow( 2*a/(Delta + b), 16./5);
1978 mint[tIndex][
j].type = 1;
1979 mint[tIndex][++
j].value = pow( 2*a/(Delta - b), 16./5);
1980 mint[tIndex][j++].type = -1;
1983 qsort(mint[tIndex], j,
sizeof(EndPoint),
compEndP);
1987 for(
int k=1;
k<
j; ++
k){
1988 mint[tIndex][
k].type += mint[tIndex][
k-1].type;
1989 if(mint[tIndex][
k].type>=nsel){
1990 mmax = (mint[tIndex][
k].value + mint[tIndex][
k+1].value)/2;
1991 nsel = mint[tIndex][
k].type;
1997 maxMasses[0] =
mmax;
2000 else if(nsel == nselmax){ maxMasses[nmaxt] =
mmax; maxTimes[nmaxt++] =
t0;}
2004 t0max = maxTimes[nmaxt-1];
2005 m0 = maxMasses[nmaxt-1];
2007 for(
int j=0;
j<tPoints; ++
j)
delete [] mint[
j];
2010 delete [] maxMasses;
2017 double cf = kf/pow(m0, 5./8);
2018 double cdf = kdf/pow(m0, 5./16);
2019 for(
int i=0;
i<
np; ++
i){
2021 double a = t0max - x[
i];
2023 double b = sqrt(sqrt(a));
2026 double df = cdf/sqrt(b*a);
2027 if(y[
i]>fi+df)
continue;
2028 if(y[
i]<fi-df)
continue;
2030 if(x[
i]>tmax2) tmax2 = x[
i];
2043 for(
int i=0;
i<
np; ++
i){
2045 if(x[
i]<tmax2) frac += 1.0;
2054 double Efrac = selEn/totEn;
2060 double xcm, ycm, qxx, qyy, qxy;
2061 xcm = ycm = qxx = qyy = qxy = 0;
2063 for(
int i=0;
i<
np; ++
i){
2070 for(
int i=0;
i<
np; ++
i){
2071 qxx += (x[
i] - xcm)*(x[
i] - xcm);
2072 qyy += (y[
i] - ycm)*(y[
i] - ycm);
2073 qxy += (x[
i] - xcm)*(y[
i] - ycm);
2079 double sq_delta = sqrt( (qxx - qyy)*(qxx - qyy) + 4*qxy*qxy );
2080 double lam1 = (qxx + qyy + sq_delta)/2;
2081 double lam2 = (qxx + qyy - sq_delta)/2;
2084 double ellipt2 =
fabs((lam1 - lam2)/(lam1 + lam2));
2162 this->cData[ID-1].chi2chirp = Efrac;
2163 this->cData[ID-1].mchirp = m0;
2165 this->cData[ID-1].tmrgr = ellipt2;
2166 this->cData[ID-1].tmrgrerr = frac;
2180 TCanvas*
c =
new TCanvas(
"chirp",
""); c->cd();
2181 this->cData[
id-1].chirp.Draw(
"AP");
2182 this->cData[
id-1].fit.Draw(
"same");
2187 { TCanvas*
c =
new TCanvas(
"cpc",
"", 1200, 800);
2188 TH2F* h2 =
new TH2F(
"h2h",
"", 600, 0, 600, 2048, 0, 2048);
2190 std::vector<vector_int>::iterator it;
2191 for(it=cList.begin(); it != cList.end(); it++){
2192 size_t ID = pList[((*it)[0])].clusterID;
2194 h2->Fill(cTime[ID-1], cFreq[ID-1], cRate[ID-1][2]);
2198 else if(sCuts[ID-1]==1)
printf(
"*");
2200 printf(
"\n# of zero sCuts lusters:%d\n", cntr);
2249 if(!cList.size() || !pList.size())
return out;
2257 size_t out_size = 0;
2262 double logbpp = -
log(
bpp);
2267 double ampbpp = sqrt(2*logbpp-2*
log(1+pow(
log(1+logbpp*(1+1.5*exp(-logbpp))),2)));
2269 int ID,
rate, min_rate, max_rate;
2270 int RATE = abs(type)>2 ? abs(type) : 0;
2273 vector<vector_int>::iterator it;
2275 size_t M = pList.size();
2276 size_t m = index ?
index : index+1;
2278 out.
resize(cList.size());
2285 if(strstr(name,
"ID")) c =
'i';
2286 if(strstr(name,
"size")) c =
'k';
2287 if(strstr(name,
"SIZE")) c =
'K';
2288 if(strstr(name,
"volume")) c =
'v';
2289 if(strstr(name,
"VOLUME")) c =
'V';
2290 if(strstr(name,
"start")) c =
's';
2291 if(strstr(name,
"stop")) c =
'd';
2292 if(strstr(name,
"dura")) c =
'D';
2293 if(strstr(name,
"low")) c =
'l';
2294 if(strstr(name,
"high")) c =
'h';
2295 if(strstr(name,
"energy")) c =
'e';
2296 if(strstr(name,
"subrho")) c =
'R';
2297 if(strstr(name,
"subnet")) c =
'U';
2298 if(strstr(name,
"subnrg")) c =
'u';
2299 if(strstr(name,
"maxnrg")) c =
'm';
2300 if(strstr(name,
"power")) c =
'w';
2301 if(strstr(name,
"conf")) c =
'Y';
2302 if(strstr(name,
"like")) c =
'L';
2303 if(strstr(name,
"null")) c =
'N';
2304 if(strstr(name,
"sign")) c =
'z';
2305 if(strstr(name,
"corr")) c =
'x';
2306 if(strstr(name,
"asym")) c =
'a';
2307 if(strstr(name,
"grand")) c =
'g';
2308 if(strstr(name,
"rate")) c =
'r';
2309 if(strstr(name,
"SNR")) c =
'S';
2310 if(strstr(name,
"hrss")) c =
'H';
2311 if(strstr(name,
"noise")) c =
'n';
2312 if(strstr(name,
"NOISE")) c =
'I';
2313 if(strstr(name,
"elli")) c =
'o';
2314 if(strstr(name,
"psi")) c =
'O';
2315 if(strstr(name,
"phi")) c =
'P';
2316 if(strstr(name,
"theta")) c =
'p';
2317 if(strstr(name,
"time")) c =
't';
2318 if(strstr(name,
"TIME")) c =
'T';
2319 if(strstr(name,
"freq")) c =
'f';
2320 if(strstr(name,
"FREQ")) c =
'F';
2321 if(strstr(name,
"band")) c =
'B';
2322 if(strstr(name,
"chi2")) c =
'C';
2324 if(c==
'0')
return out;
2328 for(it=cList.begin(); it!=cList.end(); it++){
2330 ID = pList[((*it)[0])].clusterID;
2331 if(sCuts[ID-1]>0)
continue;
2332 it_size = it->size();
2333 if(!it_size)
continue;
2339 pv = cRate.size() ? &(cRate[ID-1]) : NULL;
2342 if(type<0) rate = -type;
2343 else if(!pv) rate = 0;
2344 else if(type==1 && pv->size()) rate = (*pv)[0];
2345 else if(pv->size() &&
RATE) rate = ((*pv)[0]==
RATE) ? RATE : -1;
2347 min_rate=std::numeric_limits<int>::max();
2349 for(k=0; k<it_size; k++) {
2352 int prate =
int(pList[M].rate+0.1);
2353 if(rate && prate!=rate)
continue;
2354 if(prate>max_rate) max_rate = prate;
2355 if(prate<min_rate) min_rate = prate;
2357 if(pList[M].core && pList[M].likelihood>0) it_like++;
2358 if(!pList[M].core && core)
continue;
2363 if(!it_core)
continue;
2368 for(k=0; k<it_size; k++){
2371 out.
data[out_size++] = pList[
M].clusterID;
2379 out.
data[out_size++] = c==
'k' ? float(it_core) : float(it_halo);
2384 for(k=0; k<it_size; k++){
2387 out.
data[out_size++] = (c==
'p') ? pList[M].
theta : pList[M].
phi;
2395 for(k=0; k<it_size; k++){
2398 out.
data[out_size++] = (c==
'o') ? pList[M].ellipticity : pList[M].polarisation;
2405 for(k=0; k<it_size; k++){
2408 out.
data[out_size++] = pList[
M].rate;
2417 for(k=0; k<it_size; k++){
2420 if(!index)
continue;
2421 if(skip.
data[k])
continue;
2422 if(pList[M].
size()<
m)
continue;
2423 x = pList[
M].getdata(atype,m-1);
2427 if(c ==
'a') out.
data[out_size++] = mp+mm>0 ? (float(mp)-float(mm))/(mp+mm) : 0;
2428 else out.
data[out_size++] = mp+mm>0 ?
signPDF(mp,mm) : 0;
2437 esub = emax = sum = rho = 0;
2438 for(k=0; k<it_size; k++){
2440 nifo = pList[
M].
size();
2441 if(skip.
data[k])
continue;
2442 a = E = e = nsd = 0;
2443 for(n=0; n<
nifo; n++) {
2444 a+=
fabs(pList[M].getdata(atype,n));
2445 x = pList[
M].getdata(atype,n); x*=
x;
2446 v = pList[
M].data[
n].noiserms; v*=
v;
2447 if(x>E) {E=
x; msd=
v;}
2449 nsd += v>0 ? 1/
v : 0.;
2452 if(nsd==0. && c==
'U') {
2453 cout<<
"netcluster::get():empty noiserms array"<<endl;
exit(0);
2456 a = a>0 ? e/(a*
a) : 1;
2457 rho += (1-
a)*(e-nSUB*2);
2459 x = y*(1+y/(E+1.e-5));
2460 nsd -= msd>0 ? 1./msd : 0;
2461 v = (2*E-
e)*msd*nsd/10.;
2465 sum += (e*x/(x+(v>0?
v:1.e-5)))*(a>0.5?a:0);
2467 sum = sum/(emax+esub+0.01);
2468 if(c==
'u') out.
data[out_size++] = esub;
2469 if(c==
'm') out.
data[out_size++] = emax;
2470 if(c==
'U') out.
data[out_size++] = sum;
2471 if(c==
'R') out.
data[out_size++] = sqrt(rho);
2483 for(k=0; k<it_size; k++){
2486 if(!index)
continue;
2487 if(skip.
data[k])
continue;
2488 if(pList[M].
size()<m)
continue;
2490 x = pList[
M].getdata(atype,m-1);
2491 x/= (atype==
'W' || atype==
'w') ? pList[M].data[m-1].noiserms : 1.;
2492 x/= (atype==
'U' || atype==
'u') ? pList[M].data[m-1].noiserms : 1.;
2495 if(atype==
'R' || atype==
'r'){
2497 a-=
log(1+pow(
log(1+a*(1+1.5*exp(-a))),2));
2502 if(c==
'Y' || c==
'z') {
2503 if(atype==
'R') { y +=
x; mm++; }
2504 if(atype==
'r' && x>0) { y +=
x; mm++; }
2506 else if(c==
'e' || c==
'C') { y += a*
a; mm++; }
2507 else if(a*a>1.) { y += a*
a; mm++; }
2511 if(c==
'Y' || c==
'z') {
2512 a = pow(x+1.11/2,2)/2./1.07;
2513 y+= (a>logbpp) ? a-logbpp : 0.;
2514 if(atype==
'S' || atype==
'W' || atype==
'P' || atype==
'U') mm++;
2515 else if(a>logbpp) mm++;
2517 else if(c==
'e' || c==
'C' || c==
'w') {
2518 if(atype==
'S' || atype==
'W' || atype==
'P'|| atype==
'U') {
2521 else if(x>ampbpp) { y += x*
x; mm++; }
2523 else if(x*x>1.) { y += x*
x; mm++; }
2528 if(c==
'S' && mm) y -= double(mm);
2529 if(c==
'w' && mm) y /= double(mm);
2530 if(c==
'z' && mm) y =
gammaCL(y,mm);
2532 out.
data[out_size++] =
y;
2537 for(k=0; k<it_size; k++){
2540 if(!index)
continue;
2541 if(skip.
data[k])
continue;
2542 if(pList[M].
size()<m)
continue;
2544 x =
fabs(pList[M].getdata(atype,m-1));
2547 out.
data[out_size++] =
y;
2554 for(k=0; k<it_size; k++){
2556 if(skip.
data[k])
continue;
2557 y = 1./pList[
M].
rate;
2558 mm= pList[
M].layers;
2559 x = index ? y*
int(pList[M].data[m-1].index/mm) :
2560 y*
int(pList[M].time/mm);
2564 out.
data[out_size++] = (c==
's') ? a : b;
2571 for(k=0; k<it_size; k++){
2573 if(skip.
data[k])
continue;
2574 mp= size_t(this->rate/pList[M].rate+0.1);
2575 mm= pList[
M].layers;
2576 double dF = mm==mp ? 0. : -0.5;
2577 y = pList[
M].rate/2.;
2578 x = y * (pList[
M].frequency+dF);
2582 out.
data[out_size++] = (c==
'l') ? a : b;
2589 for(k=0; k<it_size; k++){
2591 if(skip.
data[k])
continue;
2593 if(atype==
'S' || atype==
's' || atype==
'P' || atype==
'p' || !index) {
2594 for(i=0; i<pList[
M].size(); i++) {
2595 x += pow(pList[M].data[i].
asnr,2);
2597 x -= 2*pList[
M].likelihood;
2600 b = pList[
M].data[m-1].asnr;
2601 b -= pList[
M].data[m-1].wave/pList[
M].data[m-1].noiserms;
2605 a += pList[
M].likelihood;
2608 out.
data[out_size++] =
a;
2621 if(c==
'F' && (
int)cFreq.size()>ID-1) {
2622 out.
data[out_size++] = cFreq[ID-1];
2625 if(c==
'T' && (
int)cTime.size()>ID-1) {
2626 out.
data[out_size++] = cTime[ID-1];
2630 for(k=0; k<it_size; k++) {
2633 if(!index && atype!=
'L')
continue;
2634 if(skip.
data[k])
continue;
2635 if(pList[M].
size()<m && atype!=
'L')
continue;
2637 mp= size_t(this->rate/pList[M].rate+0.1);
2638 t = 1./pList[
M].rate;
2639 mm= pList[
M].layers;
2640 if(atype==
'S' || atype==
's' || atype==
'P' || atype==
'p') {
2641 x = pList[
M].getdata(atype,m-1);
2644 else if (atype==
'R' || atype==
'r'){
2645 x = pList[
M].getdata(atype,m-1);
2646 x = pow(sqrt(2*1.07*(
fabs(x)-
log(
bpp)))-1.11/2.,2);
2649 x = pList[
M].likelihood;
2653 if(c==
't' || c==
'T' || c==
'D') {
2654 double dT = mm==mp ? 0. : 0.5;
2655 double iT = (pList[
M].time/mm -
dT)*t;
2658 iT = (pList[
M].data[m-1].index/mm -
dT)*t;
2661 double dt = 1./max_rate;
2672 double dF = mm==mp ? 0. : 0.5;
2673 double iF = (pList[
M].frequency - dF)/t/2.;
2675 int n = 1./(min_rate*
t);
2676 double df = min_rate/2.;
2690 a = a>0 ? sqrt(a)*b : min_rate/2.;
2695 a = a>0 ? sqrt(a)*b : 1./max_rate;
2698 out.
data[out_size++] = b>0. ? a/b : -1.;
2707 out.
data[out_size] = 0.;
2709 for(k=0; k<it_size; k++) {
2712 if(!index)
continue;
2713 if(skip.
data[k])
continue;
2714 if(pList[M].
size()<m)
continue;
2716 r = pList[
M].getdata(
'N',m-1);
2721 a = pow(pList[M].getdata(atype,m-1),2);
2722 if(atype==
'S' || atype==
's' || atype==
'P' || atype==
'p') { a -= 1.; a *= r*
r; }
2723 sum += a<0. ? 0. :
a;
2726 sum += c==
'n' ? r*
r : 1./r/
r;
2731 if(c !=
'H' && mp) { sum = sum/double(mp); }
2732 if(c ==
'I' && mp) { sum = 1./sum; }
2733 out.
data[out_size++] = sum>0. ? float(
log(sum)/2./
log(10.)) : 0.;
2737 out.
data[out_size++] = float(it_like);
2742 for(k=0; k<it_size; k++){
2745 out.
data[out_size++] = it_size;
2764 if(!cList.size())
return 0.;
2780 double tsRate = W.
rate();
2781 double fl = tsRate/2.;
2789 vector<vector_int>::iterator it;
2792 size_t M = pList.size();
2796 for(it=cList.begin(); it!=cList.end(); it++){
2798 ID = pList[((*it)[0])].clusterID;
2799 it_size = it->size();
2801 if(ID != cid)
continue;
2802 if(!it_size)
continue;
2808 R = pv->size() ? (*pv)[0] : 0;
2813 for(k=0; k<it_size; k++) {
2818 if(!pList[M].
core)
continue;
2819 if(R &&
int(pix->
rate+0.1)!=R)
continue;
2820 if(!R) R =
int(pix->
rate+0.1);
2822 pixtime = pix->
getdata(
'I',n)/mm;
2823 if(pixtime > max) max = pixtime;
2824 if(pixtime < min) min = pixtime;
2850 W.
start(
double(offset)/R);
2855 if(!it_core)
continue;
2857 for(k=0; k<it_size; k++){
2861 if(skip.
data[k])
continue;
2862 if(!(pix->
size()))
continue;
2864 pixtime = size_t(pix->
getdata(
'I',n)/mm);
2869 if(f > max_layer)
continue;
2870 if(f*R/2. <= fl) { fl = f*R/2.; W.
setlow(fl); }
2871 if((f+1)*R/2. >= fh) { fh = (f+1)*R/2.; W.
sethigh(fh); }
2875 if(t < 0 ||
size_t(t) >= S.
size())
continue;
2876 if(pix->
size() <=
n)
continue;
2879 if(atype==
'W') a /= pix->
getdata(
'N',n);
2883 mp++; sum += 1./a/
a;
2884 temp += pList[
M].time/double(R);
2891 sum = sqrt(
double(mp)/sum);
2915 if(!cList.size())
return z;
2917 bool signal = atype==
'S' || atype==
's';
2918 bool strain = atype==
'w' || atype==
's';
2925 if(maxfLen<fLen) maxfLen=fLen;
2931 std::vector<int>* vint;
2935 cid = this->
get((
char*)
"ID",0,
'S',0);
2939 for(
int k=0;
k<
K;
k++) {
2941 int id = size_t(cid.
data[
k]+0.1);
2942 if(
id!=ID)
continue;
2944 vint = &(this->cList[
id-1]);
2946 int V = vint->size();
2953 double T, a00, a90, rms;
2954 for(
int j=0;
j<V;
j++) {
2955 pix = this->getPixel(
id,
j);
2962 tmin =
int(tmin-maxfLen)-1;
2963 tmax =
int(tmax+maxfLen)+1;
2964 z.
resize(
size_t(this->
rate*(tmax-tmin)+0.1));
2967 int io =
int(tmin*z.
rate()+0.01);
2975 for(
int j=0;
j<V;
j++) {
2976 pix = this->getPixel(
id,
j);
2977 if(!pix->
core)
continue;
2982 a00*= strain ? rms : 1.;
2983 a90*= strain ? rms : 1.;
2987 if(mode < 0) a00=0.;
2988 if(mode > 0) a90=0.;
2993 for(
int i=0;
i<x00.
size();
i++){
2994 if(j00+i<0 || j00+i>=z.
size())
continue;
2995 z.
data[j00+
i] += x00[
i]*a00;
2996 z.
data[j90+
i] += x90[
i]*a90;
3016 size_t I = this->pList.size();
3019 if(app) fp=fopen(fname,
"ab");
3020 else fp=fopen(fname,
"wb");
3023 cout<<
"netcluster::write() error : cannot open file "<<fname<<
"\n";
3028 if(!write(fp,app)) {
fclose(fp);
return 0; };
3031 for(i=0; i<I; i++) {
3032 if(!pList[i].write(fp)) {
fclose(fp);
return 0; }
3046 size_t I = this->pList.size();
3054 double rest = this->nPIX*10+2*this->pair;
3056 db[1] = this->
start;
3059 db[4] = this->
shift;
3061 db[6] = this->
fhigh;
3062 db[7] = (double)this->
run;
3064 if(fwrite(db, 9*
sizeof(
double), 1, fp) !=1) {
3074 for(i=0; i<this->cList.size(); ++
i) {
3075 if(sCuts[i]==1)
continue;
3078 size_t K = v.size();
3082 for(k=0; k<
K; ++
k) {
3083 if(pList[v[k]].tdAmp.size()) skip=
false;
3088 for(k=0; k<
K; k++) pp[k] = &pList[v[k]];
3091 for(k=0; k<
K; k++) {
3092 if(!pp[k]->tdAmp.
size())
continue;
3099 if(k==0) pix.
ellipticity = pList[v[0]].ellipticity;
3100 if(k==1) pix.
ellipticity = pList[v[1]].ellipticity;
3122 FILE *fp = fopen(fname,
"rb");
3125 cout <<
"netcluster::read() error : cannot open file " << fname <<
". \n";
3129 if(!read(fp,0)) {
fclose(fp);
return 0;}
3134 pList.push_back(pix);
3136 end = pList[
i].read(fp);
3140 size_t I = pList.size();
3160 if(fread(db, 9*
sizeof(
double), 1, fp) !=1)
return 0;
3161 int kk =
int(db[8]+0.1);
3162 db[8] += db[8]>0. ? 0.1 : -0.1;
3164 this->
start = db[1];
3167 this->
shift = db[4];
3169 this->
fhigh = db[6];
3170 this->
run =
int(db[7]+0.1);
3172 this->pair = (kk%10)/2;
3177 size_t I = pList.size();
3178 for(i=0; i<I; ++
i) pList[i].clean();
3184 int ID = cList.size()+1;
3186 while(pix.
read(fp)){
3188 if(II<2 && pix.
neighbors.size()<1) stop=
true;
3189 if(II>1 && pix.
neighbors.size()<2) stop=
true;
3190 if((
int)II>nmax) pix.
clean();
3192 pList.push_back(pix);
3199 std::vector<int>
list(II);
3200 std::vector<int> vtof(
NIFO);
3201 std::vector<int> vtmp;
3202 for(i=0; i<II; ++
i) list[i] = I++;
3203 cList.push_back(list);
3204 nTofF.push_back(vtof);
3205 p_Ind.push_back(vtmp);
3228 cout<<
"netcluster::setTDvec() error: empty network.";
3232 cout<<
"netcluster::setTDvec() error: run network::setDelayIndex() first.";
3239 size_t batch = BATCH ?
BATCH : this->
size()+1;
3242 size_t loud = LOUD ?
LOUD : batch;
3254 for(i=0; i<this->cList.size(); i++){
3256 if(this->sCuts[i]==1)
continue;
3257 v = &(this->cList[
i]);
3260 KK = LOUD && K>loud ? loud :
K;
3261 if(this->sCuts[i]==-2) {count+=KK;
continue;}
3265 for(k=0; k<
K; k++) {
3266 pix = &(this->pList[(*v)[
k]]);
3267 if(!pix->
core) skip=
false;
3268 if(pix->
tdAmp.size()) {skip=
false; npix++;}
3270 if(npix==K) {count+=
K;
continue;}
3276 for(k=0; k<
K; k++) pp[k] = &(pList[(*v)[
k]]);
3281 for(k=0; k<KK; k++) {
3284 if(count>=batch) {skip =
true;
break;}
3290 if(!pix->
core) count++;
3292 if(
int(pix->
rate+0.1)!= waveR)
continue;
3294 for(j=0; j<
nIFO; j++) {
3296 ind =
int(pix->
data[j].index);
3298 pix->
tdAmp.push_back(vec);
3306 if(LOUD && npix==KK) this->sCuts[
i] = -2;
3332 cout<<
"netcluster::setTDvec() error: empty network.";
3336 cout<<
"netcluster::setTDvec() error: run network::setDelayIndex() first.";
3340 size_t i,
j,
k,
K,KK,
M;
3341 size_t batch = BATCH ?
BATCH : this->
size()+1;
3344 size_t loud = LOUD ?
LOUD : batch;
3358 for(i=0; i<this->cList.size(); i++){
3360 if(this->sCuts[i]==-1)
continue;
3361 if(this->sCuts[i]==1)
continue;
3362 v = &(this->cList[
i]);
3365 KK = LOUD && K>loud ? loud :
K;
3366 if(this->sCuts[i]==-2) {count+=KK;
continue;}
3370 for(k=0; k<
K; k++) {
3371 pix = &(this->pList[(*v)[
k]]);
3372 if(!pix->
core) skip=
false;
3373 if(pix->
tdAmp.size()) {skip=
false; npix++;}
3375 if(npix==K) {count+=
K;
continue;}
3381 for(k=0; k<
K; k++) pp[k] = &(pList[(*v)[
k]]);
3386 for(k=0; k<KK; k++) {
3389 if(count>=batch) {skip =
true;
break;}
3395 if(!pix->
core) count++;
3398 for(j=0; j<
nIFO; j++) {
3403 ind =
int(pix->
data[j].index);
3406 for(
int qqq=0; qqq<vec.
size(); qqq++){
3407 if(
fabs(vec.
data[qqq])>1.e6) cout<<vec.
data[qqq]<<
" nun in loadTDampSSE\n";
3410 pix->
tdAmp.push_back(vec);
3418 if(LOUD && npix==KK) this->sCuts[
i] = -2;
3441 size_t I = this->pList.size();
3445 if(
TString(froot->GetOption())!=
"CREATE" &&
TString(froot->GetOption())!=
"UPDATE") {
3446 cout<<
"netcluster::write error: input root file wrong mode (must be CREATE or UPDATE) " 3447 <<froot->GetPath()<<endl;
3452 TDirectory* cdtree = tdir!=
"" ? (TDirectory*)froot->Get(tdir) : (TDirectory*)froot;
3453 if(cdtree==NULL) cdtree = froot->mkdir(tdir);
3465 if(irate<0)
sprintf(trName,
"%s-cycle:%d:%d",tname.Data(),cycle,-
irate);
3466 else sprintf(trName,
"%s-cycle:%d",tname.Data(),cycle);
3467 TTree*
tree = (TTree*)cdtree->Get(trName);
3469 tree =
new TTree(trName,trName);
3470 tree->Branch(
"cid",&cid,
"cid/I");
3471 tree->Branch(
"rate",&rate,
"rate/I");
3472 tree->Branch(
"orate",&orate,
"orate/I");
3473 tree->Branch(
"ctime",&ctime,
"ctime/F");
3474 tree->Branch(
"cfreq",&cfreq,
"cfreq/F");
3475 tree->Branch(
"pix",
"netpixel",&pix,32000,0);
3477 tree->SetBranchAddress(
"cid",&cid);
3478 tree->SetBranchAddress(
"rate",&rate);
3479 tree->SetBranchAddress(
"orate",&orate);
3480 tree->SetBranchAddress(
"ctime",&ctime);
3481 tree->SetBranchAddress(
"cfreq",&cfreq);
3482 tree->SetBranchAddress(
"pix",&pix);
3486 tree->SetAutoFlush(0);
3491 TList* ulist = tree->GetUserInfo();
3492 if(ulist->GetSize()>0)
return 1;
3494 nc->
cpf(*
this,
false,0);
3497 nc->SetTitle(title);
3506 for(i=0; i<this->cList.size(); ++
i) {
3507 if(sCuts[i]==1)
continue;
3510 orate = r.size()>0 ? r[0] : 0;
3516 size_t K = v.size();
3519 if((cID!=0)&&(pList[v[0]].clusterID!=cID))
continue;
3522 for(k=0; k<
K; ++
k) {
3523 if(pList[v[k]].tdAmp.size()) skip=
false;
3525 if(app>0 && skip)
continue;
3528 for(k=0; k<
K; k++) pp[k] = &pList[v[k]];
3531 for(k=0; k<
K; k++) {
3532 if(app>0 && !pp[k]->tdAmp.
size())
continue;
3540 if(k==0) pix->
ellipticity = pList[v[0]].ellipticity;
3541 if(k==1) pix->
ellipticity = pList[v[1]].ellipticity;
3586 std::vector<int>
list;
3587 std::vector<int> vtof(
NIFO);
3588 std::vector<int> vtmp;
3589 std::vector<float> varea;
3590 std::vector<float> vpmap;
3593 bool skip = nmax==-2 ? true :
false;
3594 if(nmax<0) nmax=std::numeric_limits<int>::max();
3597 TObject* obj = tdir!=
"" ? froot->Get(tdir) : (TObject*)froot;
3599 cout<<
"netcluster::read error: input dir " << tdir <<
" not exist" << endl;
3602 if(tdir!=
"" && !
TString(obj->ClassName()).Contains(
"TDirectory")) {
3603 cout<<
"netcluster::read error: input dir " << tdir <<
" is not a directory" << endl;
3606 TDirectory* cdtree = tdir!=
"" ? (TDirectory*)froot->Get(tdir) : (TDirectory*)froot;
3608 cout<<
"netcluster::read error: tree dir " << tdir
3609 <<
" not present in input root file " << froot->GetPath() << endl;
3611 }
else cdtree->cd();
3615 if(rate<0)
sprintf(trName,
"%s-cycle:%d:%d",tname.Data(),cycle,-
rate);
3616 else sprintf(trName,
"%s-cycle:%d",tname.Data(),cycle);
3617 TTree*
tree = (TTree*)cdtree->Get(trName);
3618 if(rate<0) {tree->LoadBaskets(100000000);rate=abs(rate);}
3620 cout<<
"netcluster::read error: tree " << trName
3621 <<
" not present in input root file " << froot->GetPath() << endl;
3624 tree->SetBranchAddress(
"cid",&cid);
3625 tree->SetBranchAddress(
"orate",&orate);
3626 tree->SetBranchAddress(
"ctime",&ctime);
3627 tree->SetBranchAddress(
"cfreq",&cfreq);
3628 tree->SetBranchAddress(
"pix",&pix);
3633 if(rate>0)
sprintf(sel,
"rate==%d ",rate);
3635 else sprintf(sel,
"%s && cid==%d",sel,cID);}
3637 TTreeFormula
cut(
"cuts", sel, tree);
3640 if(cdtree->Get(
"htemp")!=NULL) cdtree->Delete(
"htemp");
3643 size_t size = tree->GetEntries();
3647 tree->SetBranchStatus(
"orate",
false);
3648 tree->SetBranchStatus(
"ctime",
false);
3649 tree->SetBranchStatus(
"cfreq",
false);
3650 tree->SetBranchStatus(
"pix",
false);
3651 for(i=0;i<
size;i++) {
3653 if(cut.EvalInstance()==0)
continue;
3658 tree->SetBranchStatus(
"orate",
true);
3659 tree->SetBranchStatus(
"ctime",
true);
3660 tree->SetBranchStatus(
"cfreq",
true);
3661 tree->SetBranchStatus(
"pix",
true);
3665 std::vector<int> clist;
3666 for(i=0;i<
size;i++) clist.push_back(
int(icid[i]+0.5));
3668 removeDuplicates<int>(clist);
3671 if(rate<=0 && cID==0){
3672 TList* ulist = tree->GetUserInfo();
3673 if(ulist->GetSize()==0) {
3674 cout<<
"netcluster::read error: header is null" << endl;
exit(1);
3686 if(rate<0) {cout<<
"netcluster::read error: input rate par must be >= 0" << endl;
exit(1);}
3689 for(
size_t k=0;
k<clist.size();
k++) {
3694 size_t I = pList.size();
3695 if(!skip)
for(i=0; i<I; ++
i) pList[i].clean();
3700 int ID = cList.size()+1;
3702 std::vector<int> crate;
3703 for(i=os;i<
size;i++) {
3704 if(
int(icid[i]+0.5)!=
id)
continue;
3705 tree->GetEntry(
int(entry[i]+0.5));
3707 if(II<2 && pix->neighbors.size()<1) stop=
true;
3708 if(II>1 && pix->
neighbors.size()<2) stop=
true;
3709 if(II>nmax) pix->
clean();
3711 pList.push_back(*pix);
3712 if(orate&&!crate.size()) crate.push_back(orate);
3717 if(!II) {
delete tree;
return clist;}
3721 for(i=0; i<II; ++
i) list.push_back(I++);
3722 cList.push_back(list);
3723 cRate.push_back(crate);
3724 cTime.push_back(ctime);
3725 cFreq.push_back(cfreq);
3726 sArea.push_back(varea);
3727 p_Map.push_back(vpmap);
3728 nTofF.push_back(vtof);
3729 p_Ind.push_back(vtmp);
3730 if(!skip) cData.push_back(cd);
3740 for(
size_t i=0;
i<this->cList.size(); ++
i) {
3741 if(sCuts[
i]==1)
continue;
3744 size_t K = v.size();
3747 for(
size_t k=0;
k<
K; ++
k) {
3748 if(pList[v[
k]].tdAmp.size()) nhpix++;
3754 cout <<
"rate\t= " << this->
rate << endl;
3755 cout <<
"start\t= " << this->
start << endl;
3756 cout <<
"stop\t= " << this->
stop << endl;
3757 cout <<
"shift\t= " << this->
shift << endl;
3758 cout <<
"bpp\t= " << this->
bpp << endl;
3759 cout <<
"flow\t= " << this->
flow << endl;
3760 cout <<
"ghigh\t= " << this->
fhigh << endl;
3761 cout <<
"run\t= " << this->
run << endl;
3762 cout <<
"nPIX\t= " << this->nPIX << endl;
3763 cout <<
"pair\t= " << this->pair << endl;
3765 cout <<
"cList\t= " << this->cList.size() << endl;
3766 cout <<
"pList\t= " << this->pList.size() << endl;
3767 cout <<
"hpList\t= " << nhpix << endl;
wavearray< double > t(hp.size())
detector * getifo(size_t n)
param: detector index
virtual size_t defragment(double T, double F, TH2F *=NULL)
T - maximum time gap in seconds F - maximum frequency gap in Hz.
virtual void resize(unsigned int)
std::vector< int > vector_int
int getBaseWave(int m, int n, SymmArray< double > &w)
size_t write(const char *file, int app=0)
double gammaCL(double x, double n)
std::vector< vector_int > cRate
static double g(double e)
wavearray< double > getMRAwave(network *net, int ID, size_t n, char atype='S', int mode=0)
double min(double x, double y)
virtual void rate(double r)
std::vector< wavearray< float > > tdAmp
int compEndP(const void *p, const void *q)
std::vector< pixel > cluster
wavearray< float > getTDvecSSE(int j, int K, char c, SSeries< double > *pss)
plot hist2D SetName("WSeries-1")
wavearray< double > a(hp.size())
std::vector< int > neighbors
double iGamma(double r, double p)
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\ layers : "<< nLAYERS<< "\ dF(hz) : "<< dF<< "\ dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1) *itime+ifreq;double time=itime *dT;double freq=(ifreq >0) ? ifreq *dF :dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
std::vector< pixdata > data
wavearray< double > get(char *name, size_t index=0, char atype='R', int type=1, bool=true)
param: string with parameter name param: index in the amplitude array, which define detector param: c...
double mchirpTEST(int ID)
WDM< double > wdm(nLAYERS, nLAYERS, 6, 10)
std::slice getSlice(double n)
size_t setcore(bool core, int id=0)
virtual size_t supercluster(char atype, double S, bool core)
param: statistic: E - excess power, L - likelihood param: selection threshold T for likelihood cluste...
std::vector< vector_int > cList
virtual void start(double s)
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
network ** net
NOISE_MDC_SIMULATION.
WDM< double > * getwdm(size_t M)
param: number of wdm layers
virtual void waveSplit(DataType_t **pp, size_t l, size_t r, size_t m) const
virtual size_t size() const
double signPDF(const size_t m, const size_t k)
virtual size_t cluster()
return number of clusters
double getwave(int, WSeries< double > &, char='W', size_t=0)
param: cluster ID param: WSeries where to put the waveform return: noise rms
std::vector< netpixel > pList
double getDelay(const char *c="")
std::vector< WDM< double > * > wdmList
WSeries< double > pTF[nRES]
printf("total live time: non-zero lags = %10.1f \, liveTot)
int compareLIKE(const void *x, const void *y)
virtual wavearray< float > getTDvec(int j, int k, char c='p')
std::vector< float > cFreq
virtual size_t append(netcluster &wc)
param: input netcluster return size of appended pixel list
TString sel("slag[1]:slag[2]")
size_t cpf(const netcluster &, bool=false, int=0)
double mchirp(int ID, double=2.5, double=1.e20, double=0)
size_t loadTDampSSE(network &net, char c, size_t BATCH=10000, size_t LOUD=0)
void removeDuplicates(std::vector< T > &vec)
double GravitationalConstant()
unsigned long nWWS
pointer to wavelet work space
netcluster & operator=(const netcluster &)
std::vector< float > cTime
WSeries< double > * getTFmap()
param: no parameters
int compare_PIX(const void *x, const void *y)
virtual void stop(double s)
double fabs(const Complex &x)
virtual size_t cleanhalo(bool=false)
param: if false - de-cluster pixels return size of the list
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Meyer< double > S(1024, 2)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
std::vector< clusterdata > cData
virtual wavearray< double > select(char *, double)
WaveDWT< DataType_t > * pWavelet
SSeries< double > * getSTFmap(size_t n)
size_t read(const char *)
double getdata(char type='R', size_t n=0)
size_t addhalo(int=0)
param: packet pattern mode return size of the list
virtual void resize(unsigned int)
size_t loadTDamp(network &net, char c, size_t BATCH=10000, size_t LOUD=0)
double SpeedOfLightInVacuo()