21 #include "TTreeFormula.h"
31 std::sort(vec.begin(), vec.end());
32 vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
58 typedef struct{
double value;
int type;} EndPoint;
61 { EndPoint*
a = (EndPoint*)p;
62 EndPoint* b = (EndPoint*)q;
63 if(a->value > b->value)
return 1;
114 size_t nbig = abs(nBIG);
122 std::vector<int> refI;
123 std::vector<float> refF;
124 std::vector<vector_int>::const_iterator it;
135 this->nPIX = value.
nPIX;
138 this->pair = value.
pair;
140 if(!value.
cList.size()) {
141 this->pList = value.
pList;
143 return this->pList.size();
146 for(it=value.
cList.begin(); it!=value.
cList.end(); it++){
148 ID = value.
pList[(*it)[0]].clusterID;
150 if(value.
sCuts[ID-1]>0)
continue;
151 if(nBIG>0 && K>nbig)
continue;
152 if(nBIG<0 && K<nbig)
continue;
154 vr = value.
cRate[ID-1];
158 R =
int(value.
pList[(*it)[k]].rate+0.1);
164 this->pList.reserve(N+2);
166 for(it=value.
cList.begin(); it!=value.
cList.end(); it++){
169 ID = value.
pList[(*it)[0]].clusterID;
170 if(value.
sCuts[ID-1]>0)
continue;
173 vr = value.
cRate[ID-1];
180 pix = value.
pList[(*it)[
k]];
181 R =
int(value.
pList[(*it)[k]].rate+0.1);
184 if(vr[0] != R)
continue;
190 n = this->pList.size();
193 this->pList[n-1].append(1);
199 if(!
id.
size()) cout<<
"netcluster::cpf() error: empty cluster.";
202 cData.push_back(value.
cData[ID-1]);
205 p_Ind.push_back(refI);
206 p_Map.push_back(refF);
207 sArea.push_back(refF);
208 nTofF.push_back(refI);
209 cTime.push_back(value.
cTime[ID-1]);
210 cFreq.push_back(value.
cFreq[ID-1]);
212 return this->pList.size();
219 this->cpf(value,
false);
231 for(i=0; i<this->cList.size(); i++){
233 v = &(this->cList[
i]);
237 if(
id && this->pList[(*v)[k]].clusterID !=
id)
continue;
238 this->pList[(*v)[
k]].core =
core;
250 if(!this->pList.size())
return 0;
252 if(!this->nSUB) this->nSUB=(2*
iGamma(pList[0].
size()-1,0.314));
259 if(strstr(name,
"subnet")) {
260 out = this->
get(
const_cast<char*
>(
"subnet"),0,
'S');
261 for(
int i=0;
i<I;
i++){
263 if(aa<thr) this->ignore(ID.
data[
i]);
267 if(strstr(name,
"subrho")) {
268 out = this->
get(
const_cast<char*
>(
"subrho"),0,
'S');
269 for(
int i=0;
i<I;
i++){
271 if(aa<thr) this->ignore(ID.
data[
i]);
275 if(strstr(name,
"SUBCUT")) {
279 double prl,qrl,ptime,qtime,pfreq,qfreq;
280 int N = pList.size();
284 for(
int i=0;
i<I;
i++){
287 aa = aa*(1+aa/max.
data[
i]);
289 if(out.
data[
i]>thr)
continue;
290 this->ignore(ID.
data[
i]);
295 for(
int n=0;
n<
N;
n++) {
302 for(
int k;
k<
K;
k++){
308 if(
fabs(qfreq-pfreq)>128 &&
309 fabs(qtime-ptime)>0.125)
continue;
322 if(!pList.size() || !cList.size())
return 0;
328 int K = pList.size();
331 vector<vector_int>::iterator it;
333 for(it=this->cList.begin(); it != this->cList.end(); it++) {
335 pix = &(this->pList[((*it)[0])]);
337 if(this->sCuts[ID-1]==0)
continue;
339 for(
size_t n=0;
n<it->size();
n++) {
340 pix = &(this->pList[((*it)[
n])]);
360 size_t K = this->pList.size();
371 q = &(this->pList[
k]);
372 u = &(this->pList[
k].neighbors);
379 cout<<
"netcluster::delink(): cluster ID mismatch"<<endl;
396 size_t n = this->pList.size();
398 size_t M = this->pList[0].layers;
399 double R = this->pList[0].rate;
406 if(n==1)
return this->
cluster();
412 for(i=0; i<
n; i++) { pp[
i] = &(pList[
i]); pp[
i]->
neighbors.clear();}
418 bool isWavelet = (size_t(this->
rate/R+0.1) == pp[
i]->
layers) ?
true :
false;
421 cout<<
"netcluster::cluster(int,int) applied to mixed pixel list"<<endl;
423 for(j=i+1; j<
n; j++){
431 if(index < 0) cout<<
"netcluster::cluster(int,int) sort error"<<endl;
433 if(index/M > kt)
break;
435 if(index > kt)
break;
460 vector<float> refArea;
463 size_t n = pList.size();
465 if(!pList.size())
return 0;
480 for(i=0; i<
n; i++) pList[i].clusterID = 0;
485 if(pList[i].clusterID)
continue;
486 pList[
i].clusterID = ++nCluster;
489 cRate.push_back(refRate);
490 cTime.push_back(-1.);
491 cFreq.push_back(-1.);
492 p_Ind.push_back(refRate);
493 p_Map.push_back(refArea);
494 sArea.push_back(refArea);
495 nTofF.push_back(refRate);
496 refMask.resize(volume);
497 cList.push_back(refMask);
498 cData.push_back(refCD);
502 vector<vector_int>::iterator it;
504 if(!cList.size())
return 0;
506 for(it=cList.begin(); it != cList.end(); it++) {
511 if(pList[i].clusterID == nCluster) (*it)[m++] =
i;
514 if(it->size() !=
m) {
515 cout<<
"cluster::cluster() size mismatch error: ";
516 cout<<m<<
" size="<<it->size()<<
" "<<nCluster<<endl;
546 if(!pList.size() || !cList.size())
return 0;
553 vector<vector_int>::iterator it;
555 std::vector<int>*
pr;
556 std::vector<int> refI;
557 std::vector<float> refF;
563 for(it=x.
cList.begin(); it != x.
cList.end(); it++) {
565 pix = &(x.
pList[((*it)[0])]);
567 if(x.
sCuts[ID-1]>0)
continue;
569 pr = n ? &(x.
cRate[ID-1]) : NULL;
573 for(i=0; i<it->size(); i++) {
574 pix = &(x.
pList[((*it)[
i])]);
585 if(!i) cout<<
"netcluster::cleanhalo() error: empty cluster.";
589 cData.push_back(x.
cData[ID-1]);
591 if(pr) cRate.push_back(*pr);
592 p_Ind.push_back(refI);
593 p_Map.push_back(refF);
594 sArea.push_back(refF);
595 nTofF.push_back(refI);
596 cTime.push_back(x.
cTime[ID-1]);
597 cFreq.push_back(x.
cFreq[ID-1]);
603 pList[
id[i-1]].append(
id[i]-
id[i-1]);
604 pList[
id[
i]].append(
id[i-1]-
id[i]);
617 if(!pList.size() || !cList.size())
return 0;
618 if(mode==0)
return pList.size();
629 vector<vector_int>::iterator it;
632 std::vector<int> nid;
633 std::vector<int>* pn;
634 std::vector<int> refI;
635 std::vector<float> refF;
640 for(k=0; k<9; k++) {nid.push_back(0); jj.push_back(0);}
642 for(it=x.
cList.begin(); it != x.
cList.end(); it++) {
644 pix = &(x.
pList[((*it)[0])]);
646 if(x.
sCuts[ID-1]>0)
continue;
651 for(i=0; i<it->size(); i++) {
652 pix = &(x.
pList[((*it)[
i])]);
659 for(i=0; i<it->size(); i++) {
660 pix = &(x.
pList[((*it)[
i])]);
663 if(!(J%M) || !((J-1)%M) || !((J-2)%M) || !((J+1)%M))
continue;
667 jj[1]=J-M+1; jj[2]=J+1; jj[3]=J+M+1;
668 jj[4]=J-M-1; jj[5]=J-1; jj[6]=J+M-1;
671 jj[1]=J-M-1; jj[2]=J+M+1; K=3;
672 }
else if(mode==-3) {
673 jj[1]=J+M-1; jj[2]=J-M+1; K=3;
675 jj[1]=J-2*M-2; jj[2]=J+2*M+3;
676 jj[3]=J-M-1; jj[4]=J+M+1; K=5;
677 }
else if(mode==-5) {
678 jj[1]=J+2*M-2; jj[2]=J-2*M+3;
679 jj[3]=J+M-1; jj[4]=J-M+1; K=5;
681 jj[1]=J-M-1; jj[2]=J+M+1;
682 jj[3]=J+M-1; jj[4]=J-M+1; K=5;
685 for(k=0; k<
K; k++) nid[k]=0;
686 for(j=0; j<
id.size(); j++) {
687 PIX = &(this->pList[
id[
j]]);
692 if(J==jj[k]) nid[
k] =
id[
j]+1;
698 if(nid[k]!=0)
continue;
702 for(n=0; n<
nIFO; n++) {
703 pix->
data[
n].index+=jj[
k]-jj[0];
709 pn = &(this->pList[nid[0]-1].neighbors);
712 for(j=0; j<pn->size(); j++)
713 if(nid[k]==(*pn)[
j]+1) save=
false;
714 if(save) pn->push_back(nid[k]-1);
720 cData.push_back(x.
cData[ID-1]);
721 cRate.push_back(refI);
722 p_Ind.push_back(refI);
723 p_Map.push_back(refF);
724 sArea.push_back(refF);
725 nTofF.push_back(refI);
726 cTime.push_back(x.
cTime[ID-1]);
727 cFreq.push_back(x.
cFreq[ID-1]);
730 if(!i) cout<<
"netcluster::addhalo() error: empty cluster.";
733 pList[
id[i-1]].append(
id[0]-
id[i-1]);
734 pList[
id[0]].append(
id[i-1]-
id[0]);
736 pList[
id[i-1]].append(
id[i]-
id[i-1]);
737 pList[
id[
i]].append(
id[i-1]-
id[i]);
757 size_t on = pList.size();
764 if(!in) {
return on; }
769 printf(
"\n netcluster::append(): cluster type mismatch");
775 this->pList.reserve(in+on+2);
792 size_t n = pList.size();
812 for(i=0; i<
n; i++) { pp[
i] = &(pList[
i]);}
824 for(j=i+1; j<
n; j++){
831 if(qtime<ptime-eps) cout<<
"netcluster::merge() error"<<endl;
833 if(qtime-ptime > 1.)
break;
834 if(
fabs(qtime-ptime) > eps)
continue;
840 if(
fabs(pfreq-qfreq) > eps)
continue;
850 if((*v)[k] == l) {insert=
false;
break;}
852 if(insert) p->append(l);
862 if((*v)[k] == l) {insert=
false;
break;}
864 if(insert) q->append(l);
869 if(ppo==pp) free(pp);
870 else {cout<<
"netcluster::cluster() free()\n";
exit(1);}
876 std::vector<vector_int>::iterator it;
878 std::vector<int>
rate;
879 std::vector<int> temp;
880 std::vector<int> sIZe;
881 std::vector<bool> cuts;
882 std::vector<double> ampl;
883 std::vector<double> powr;
884 std::vector<double> like;
886 double a,
L,
e,tt,cT,cF,
nT,nF;
892 bool oEo = atype==
'E' || atype==
'P';
894 for(it=cList.begin(); it != cList.end(); it++) {
896 if(!k) cout<<
"netcluster::supercluster() error: empty cluster.\n";
910 ID = pList[((*it)[0])].clusterID;
913 pix = &(pList[((*it)[
i])]);
914 if(!pix->
core && core)
continue;
917 for(j=0; j<pix->
size(); j++) {
918 a = pix->
data[
j].asnr;
919 e+=
fabs(a)>1. ? a*a-1 : 0.;
922 a = atype==
'L' ? L :
e;
924 mm = size_t(this->rate*tt+0.1);
925 cT += (pix->
time/mm + 0.5)*
a;
931 for(j=0; j<rate.size(); j++) {
932 if(rate[j] ==
int(pix->
rate+0.1)) {
941 rate.push_back(
int(pix->
rate+0.1));
945 cuts.push_back(
true);
952 cout<<
"netcluster::merge() error: cluster ID mismatch.\n";
958 if(rate.size()<size_t(1+this->pair) || m<nPIX){ sCuts[ID-1] =
true;
continue; }
961 for(i=0; i<rate.size(); i++) {
962 if((atype==
'L' && like[i]<S) || (oEo && ampl[
i]<
S))
continue;
963 if(!pair) { cuts[
i] = cut =
false;
continue; }
964 for(j=0; j<rate.size(); j++) {
965 if((atype==
'L' && like[j]<S) || (oEo && ampl[
j]<
S))
continue;
966 if(rate[i]/2==rate[j] || rate[j]/2==rate[i]) {
967 cuts[
i] = cuts[
j] = cut =
false;
971 if(cut || sCuts[ID-1]) { sCuts[ID-1] =
true;
continue; }
976 for(j=0; j<rate.size(); j++) {
977 powr[
j] = ampl[
j]/sIZe[
j];
978 if(atype==
'E' && ampl[j]>a && !cuts[j]) {max=
j; a=ampl[
j];}
979 if(atype==
'L' && like[j]>a && !cuts[j]) {max=
j; a=like[
j];}
980 if(atype==
'P' && powr[j]>a && !cuts[j]) {max=
j; a=powr[
j];}
983 if(a<S) { sCuts[ID-1] =
true;
continue; }
986 for(j=0; j<rate.size(); j++) {
988 if(atype==
'E' && ampl[j]>a && !cuts[j]) {min=
j; a=ampl[
j];}
989 if(atype==
'L' && like[j]>a && !cuts[j]) {min=
j; a=like[
j];}
990 if(atype==
'P' && powr[j]>a && !cuts[j]) {max=
j; a=powr[
j];}
993 temp.push_back(rate[max]);
994 temp.push_back(rate[min]);
1031 size_t n = pList.size();
1038 std::vector<int>*
v;
1039 double eps,E,R,
T,
dT,dF,prl,qrl,aa;
1041 double ptime, pfreq;
1042 double qtime, qfreq;
1044 size_t nIFO = pList[0].size();
1052 for(i=0; i<
n; i++) {
1053 pp[
i] = &(pList[
i]);
1055 if(1./R > Tgap) Tgap = 1./R;
1066 for(i=0; i<
n; i++) {
1069 ptime = p->
time/prl;
1072 for(j=i+1; j<
n; j++){
1076 qtime = q->
time/qrl;
1077 if(qtime-ptime > Tgap) {
break;}
1083 cout<<
"netcluster::supercluster() error "<<qtime-ptime<<endl;
1091 for(k=0; k<
nIFO; k++) {
1092 aa = p->
data[
k].index/prl;
1093 aa-= q->
data[
k].index/qrl;
1098 dF =
fabs(qfreq-pfreq) - 0.5*R;
1099 eps = (dT>0?dT*R:0) + (dF>0?dF*T:0);
1100 if(his) his->Fill(eps);
1101 if(gap < eps)
continue;
1107 v = &(p->neighbors);
1110 for(k=0; k<
m; k++) {
1111 if((*v)[k] == l) {insert=
false;
break;}
1114 if(insert) p->append(l);
1120 v = &(q->neighbors);
1123 for(k=0; k<
m; k++) {
1124 if((*v)[k] == l) {insert=
false;
break;}
1127 if(insert) q->append(l);
1131 if(ppo==pp) free(pp);
1132 else {cout<<
"netcluster::supercluster() free()\n";
exit(1);}
1138 std::vector<vector_int>::iterator it;
1140 std::vector<int>
rate;
1141 std::vector<int> temp;
1142 std::vector<int> sIZe;
1143 std::vector<bool> cuts;
1144 std::vector<double> ampl;
1145 std::vector<double> powr;
1146 std::vector<double> like;
1148 double a,
L,
e,tt,cT,cF,
nT,nF;
1154 bool oEo = atype==
'E' || atype==
'P';
1156 for(it=cList.begin(); it != cList.end(); it++) {
1158 if(!k) cout<<
"netcluster::supercluster() error: empty cluster.\n";
1172 ID = pList[((*it)[0])].clusterID;
1174 for(i=0; i<
k; i++) {
1175 pix = &(pList[((*it)[
i])]);
1176 if(!pix->
core && core)
continue;
1179 for(j=0; j<pix->
size(); j++) {
1180 a = pix->
data[
j].asnr;
1181 e+=
fabs(a)>1. ? a : 0.;
1184 a = atype==
'L' ? L :
e;
1193 for(j=0; j<rate.size(); j++) {
1194 if(rate[j] ==
int(pix->
rate+0.1)) {
1203 rate.push_back(
int(pix->
rate+0.1));
1207 cuts.push_back(
true);
1214 cout<<
"netcluster::supercluster() error: cluster ID mismatch.\n";
1220 if((
int)rate.size()< this->pair+1 || m<nPIX){ sCuts[ID-1] = 1;
continue; }
1223 for(i=0; i<rate.size(); i++) {
1224 if((atype==
'L' && like[i]<S) || (oEo && ampl[
i]<
S))
continue;
1225 if(!pair) { cuts[
i] = cut =
false;
continue; }
1226 for(j=0; j<rate.size(); j++) {
1227 if((atype==
'L' && like[j]<S) || (oEo && ampl[
j]<
S))
continue;
1228 if(rate[i]/2==rate[j] || rate[j]/2==rate[i]) {
1229 cuts[
i] = cuts[
j] = cut =
false;
1233 if(cut || sCuts[ID-1]) { sCuts[ID-1] = 1;
continue; }
1238 for(j=0; j<rate.size(); j++) {
1239 powr[
j] = ampl[
j]/sIZe[
j];
1240 if(atype==
'E' && ampl[j]>a && !cuts[j]) {max=
j; a=ampl[
j];}
1241 if(atype==
'L' && like[j]>a && !cuts[j]) {max=
j; a=like[
j];}
1242 if(atype==
'P' && powr[j]>a && !cuts[j]) {max=
j; a=powr[
j];}
1245 if(a<S) { sCuts[ID-1] = 1;
continue; }
1248 for(j=0; j<rate.size(); j++) {
1249 if(max==j)
continue;
1250 if(atype==
'E' && ampl[j]>a && !cuts[j]) {min=
j; a=ampl[
j];}
1251 if(atype==
'L' && like[j]>a && !cuts[j]) {min=
j; a=like[
j];}
1252 if(atype==
'P' && powr[j]>a && !cuts[j]) {min=
j; a=powr[
j];}
1255 temp.push_back(rate[max]);
1256 temp.push_back(rate[min]);
1258 cTime[ID-1] = cT/
nT;
1259 cFreq[ID-1] = cF/nF;
1261 cData[ID-1].cTime = cT/
nT;
1262 cData[ID-1].cFreq = cF/nF;
1263 cData[ID-1].energy = E;
1264 cData[ID-1].likenet = E;
1283 size_t I = pList.size();
1287 if(tgap<=0 && fgap<=0)
return 0;
1291 std::vector<int>*
v;
1292 std::vector<int>* u;
1293 double R,
T,
dT,dF,
x,
a,E,prl,qrl;
1295 double ptime, pfreq;
1296 double qtime, qfreq;
1298 size_t nIFO = pList[0].size();
1303 for(i=0; i<I; i++) {
1304 pp[
i] = &(pList[
i]);
1306 if(!(pp[i]->clusterID)) {
1307 cout<<
"defragment: un-clustered pixel list \n";
exit(1);
1309 if(1./R > Tgap) Tgap = 1./R;
1311 if(Tgap<tgap) Tgap = tgap;
1321 for(i=0; i<I; i++) {
1325 if(sCuts[n-1]==1)
continue;
1326 ptime = p->
time/prl;
1329 for(j=i+1; j<I; j++){
1333 if(sCuts[m-1]==1)
continue;
1335 qtime = q->
time/qrl;
1336 if(qtime-ptime > Tgap) {
break;}
1344 cout<<
"netcluster::defragment() error "<<qtime-ptime<<endl;
1350 for(k=0; k<
nIFO; k++) {
1351 a = p->
data[
k].index/prl;
1352 a -= q->
data[
k].index/qrl;
1357 dF =
fabs(qfreq-pfreq) - 0.25*R;
1358 if(his) his->Fill(dT,dF);
1359 if(dT > tgap)
continue;
1360 if(dF > fgap)
continue;
1366 v = &(p->neighbors);
1368 for(k=0; k<v->size(); k++) {
1369 if((*v)[
k] ==
l) {insert=
false;
break;}
1372 if(insert) p->append(l);
1378 v = &(q->neighbors);
1380 for(k=0; k<v->size(); k++) {
1381 if((*v)[
k] ==
l) {insert=
false;
break;}
1384 if(insert) q->append(l);
1388 v = &(this->cList[n-1]);
1389 u = &(this->cList[m-1]);
1390 for(k=0; k<u->size(); k++) {
1391 pList[(*u)[
k]].clusterID =
n;
1392 v->push_back((*u)[k]);
1399 if(ppo==pp) free(pp);
1400 else {cout<<
"netcluster::defragment() free()\n";
exit(1);}
1418 double kk = 256.*Pi/5*pow(G*SM*Pi/C/C/C, 5./3);
1420 std::vector<int>* vint = &this->cList[ID-1];
1421 int V = vint->size();
1424 bool chi2_cut = chi2_thr<0 ?
true :
false;
1425 chi2_thr =
fabs(chi2_thr);
1427 double*
x =
new double[V];
1428 double*
y =
new double[V];
1429 double* xerr =
new double[V];
1430 double* yerr =
new double[V];
1431 double* wgt =
new double[V];
1438 this->cData[ID-1].chi2chirp = 0;
1439 this->cData[ID-1].mchirp = 0 ;
1440 this->cData[ID-1].mchirperr = -1;
1441 this->cData[ID-1].tmrgr = 0;
1442 this->cData[ID-1].tmrgrerr = -1;
1443 this->cData[ID-1].chirpEllip = 0;
1444 this->cData[ID-1].chirpEfrac = 0;
1445 this->cData[ID-1].chirpPfrac = 0;
1449 kk *= pow(sF, 8./3);
1451 double xmin,ymin, xmax, ymax;
1452 xmin = ymin = 1e100;
1453 xmax = ymax = -1e100;
1455 double emax = -1e100;
1456 for(
int j=0;
j<V;
j++) {
1460 double zthr = zmax_thr*emax;
1462 for(
int j=0;
j<V;
j++) {
1472 xerr[
np] = 0.5/pix->
rate;
1473 xerr[
np] = xerr[
np]*sqrt(2.);
1477 yerr[
np] = yerr[
np]/sqrt(3.);
1482 yerr[
np] *= 8./3/pow(y[np], 11./3);
1483 y[
np] = 1./pow(y[np], 8./3);
1485 if(x[np]>xmax) xmax = x[
np];
1486 if(x[np]<xmin) xmin = x[
np];
1487 if(y[np]>ymax) ymax = y[
np];
1488 if(y[np]<ymin) ymin = y[
np];
1493 double xcm, ycm, qxx, qyy, qxy;
1494 xcm = ycm = qxx = qyy = qxy = 0;
1496 for(
int i=0;
i<
np; ++
i){
1503 for(
int i=0;
i<
np; ++
i){
1504 qxx += (x[
i] - xcm)*(x[
i] - xcm);
1505 qyy += (y[
i] - ycm)*(y[
i] - ycm);
1506 qxy += (x[
i] - xcm)*(y[
i] - ycm);
1512 double sq_delta = sqrt( (qxx - qyy)*(qxx - qyy) + 4*qxy*qxy );
1513 double lam1 = (qxx + qyy + sq_delta)/2;
1514 double lam2 = (qxx + qyy - sq_delta)/2;
1517 double ellipt =
fabs((lam1 - lam2)/(lam1 + lam2));
1519 const double maxM = 100;
1520 const double stepM = 0.2;
1521 const int massPoints = 1001;
1523 int maxMasses[massPoints];
1526 EndPoint* bint[massPoints];
1527 for(
int j=0;
j<massPoints; ++
j) bint[
j] =
new EndPoint[2*np];
1532 for(
double m = -maxM;
m<maxM + 0.01;
m+=stepM){
1533 double sl = kk*pow(
fabs(
m), 5./3);
1537 for(
int i=0;
i<
np; ++
i){
1538 double Db = sqrt( 2 * (sl*sl*xerr[
i]*xerr[
i] + yerr[
i]*yerr[
i]) );
1539 double bmini = y[
i] - sl*x[
i] - Db;
1540 double bmaxi = bmini + 2*Db;
1541 bint[massIndex][
j].value = bmini;
1542 bint[massIndex][
j].type = 1;
1543 bint[massIndex][++
j].value = bmaxi;
1544 bint[massIndex][j++].type = -1;
1546 qsort(bint[massIndex], 2*np,
sizeof(EndPoint),
compEndP);
1549 for(j=1; j<2*
np; ++
j){
1550 bint[massIndex][
j].type += bint[massIndex][j-1].type;
1551 if(bint[massIndex][j].type>nsel)nsel = bint[massIndex][
j].type;
1555 maxMasses[0] = massIndex;
1558 else if(nsel == nselmax) maxMasses[nmaxm++] = massIndex;
1565 double chi2min = 1e100;
1568 for(
int j=0;
j<nmaxm; ++
j){
1569 double m = -maxM + maxMasses[
j]*stepM;
1570 double sl = kk*pow(
fabs(m), 5./3);
1573 for(
int k=0;
k<2*np-1; ++
k)
if(bint[maxMasses[
j]][
k].type==nselmax)
1574 for(
double b = bint[maxMasses[
j]][
k].
value; b<bint[maxMasses[
j]][
k+1].value; b+=0.0025){
1577 for(
int i=0;
i<
np; ++
i){
1578 double chi2 = y[
i] - sl*x[
i] - b;
1580 chi2 /= (sl*sl*xerr[
i]*xerr[
i] + yerr[
i]*yerr[
i]);
1581 if(chi2>chi2_thr)
continue;
1582 totchi += chi2*wgt[
i];
1585 totchi = totwgt ? totchi/totwgt : 2e100;
1594 for(
int j=0;
j<massPoints; ++
j)
delete [] bint[
j];
1597 double sl = kk*pow(
fabs(m0), 5./3);
1606 for(
int i=0;
i<
np; ++
i){
1608 double chi2 = y[
i] - sl*x[
i] - b0;
1610 chi2 /= (sl*sl*xerr[
i]*xerr[
i] + yerr[
i]*yerr[
i]);
1611 chi2T += chi2*wgt[
i];
1612 if(chi2>chi2_thr)
continue;
1614 if(x[
i]>tmax2) tmax2 = x[
i];
1617 double Efrac = selEn/totEn;
1618 chi2T = chi2T/totEn;
1626 int nifo = pList[0].size();
1627 for(
int i=0;
i<
np; ++
i){
1628 if(x[
i]<tmax2) Pfrac += 1.0;
1629 double chi2 = y[
i] - sl*x[
i] -b0;
1631 chi2 /= (sl*sl*xerr[
i]*xerr[
i] + yerr[
i]*yerr[
i]);
1633 if(chi2>chi2_thr)
continue;
1634 x[
j] = x[
i]; xerr[
j] = xerr[
i];
1635 y[
j] = y[
i]; yerr[
j] = yerr[
i];
1643 for(
int i=0;
i<V; ++
i){
1649 double eT = 0.5/pix->
rate;
1651 double eF = pix->
rate/4;
1658 eF *= 8./3/pow(F, 11./3);
1659 F = 1./pow(F, 8./3);
1661 double chi2 = F - sl*T -b0;
1663 chi2 /= (sl*sl*eT*eT + eF*eF);
1664 if(chi2_cut && chi2<chi2_thr) {
1676 xcm = ycm = qxx = qyy = qxy = 0;
1678 for(
int i=0;
i<
np; ++
i){
1685 for(
int i=0;
i<
np; ++
i){
1686 qxx += (x[
i] - xcm)*(x[
i] - xcm);
1687 qyy += (y[
i] - ycm)*(y[
i] - ycm);
1688 qxy += (x[
i] - xcm)*(y[
i] - ycm);
1694 sq_delta = sqrt( (qxx - qyy)*(qxx - qyy) + 4*qxy*qxy );
1695 lam1 = (qxx + qyy + sq_delta)/2;
1696 lam2 = (qxx + qyy - sq_delta)/2;
1699 double ellipt2 =
fabs((lam1 - lam2)/(lam1 + lam2));
1709 int np2 = np*0.5, Trials=500;
1710 if(np2<3)np2 = np-1;
1712 if(np2<8)Trials = np2;
1713 else if(np2<15) Trials = np2*np2/2;
1714 else if(np2<20) Trials = np2*np2*np2/6;
1715 if(Trials>500) Trials = 500;
1716 if(Trials<0) Trials=0;
1718 this->cData[ID-1].mchpdf.resize(Trials);
1724 for(
int ii=0; ii<Trials; ++ii){
1727 for(
int k,
i=0;
i<np2; ++
i){
1728 do k = rnd.Uniform(0. , np - 1
e-10);
1734 double sx=0, sy=0, sx2=0, sxy=0;
1735 for(
int i=0;
i<
np; ++
i)
if(used[
i]){
1742 double slp = (sy/np2 - sxy/sx)/(sx2/sx - sx/np2);
1743 double b = (sy + slp*sx)/np2;
1745 slpv.
data[ii] = slp;
1746 mchv.
data[ii] = slp>0 ? pow(slp/kk,0.6) : -pow(-slp/kk, 0.6);
1747 bv.
data[ii] = b/slp;
1748 this->cData[ID-1].mchpdf.data[ii] = mchv.
data[ii];
1752 size_t nn = mchv.
size()-1;
1753 size_t ns = size_t(mchv.
size()*0.16);
1754 cData[ID-1].mchirperr = Trials>8 ? ( mchv.
waveSplit(0,nn,nn-ns)-mchv.
waveSplit(0,nn,ns) ) / 2 : 2*mchv.
rms();
1759 sprintf(name,
"netcluster::mchirp5:func_%d", ID);
1762 TGraphErrors *
gr =
new TGraphErrors(np, x, y, xerr, yerr);
1763 TF1 *
f =
new TF1(name,
"[0]*x + [1]", xmin, xmax);
1765 this->cData[ID-1].chirp.Set(np);
1766 for(
int i=0;
i<
np;
i++) {
1767 this->cData[ID-1].chirp.SetPoint(
i,x[
i],y[i]);
1768 this->cData[ID-1].chirp.SetPointError(i,xerr[i],yerr[i]);
1770 this->cData[ID-1].fit.SetName(
TString(
"TGraphErrors_"+
TString(name)).Data());
1771 this->cData[ID-1].chirp.SetName(
TString(
"TF1_"+
TString(name)).Data());
1773 TF1* f = &(this->cData[ID-1].fit);
1774 TGraphErrors* gr = &(this->cData[ID-1].chirp);
1776 *gr = TGraphErrors(np, x, y, xerr, yerr);
1777 *f = TF1(name,
"[0]*x + [1]", xmin, xmax);
1780 f->SetParameter(0, sl);
1781 f->SetParameter(1, b0);
1785 int ndf = f->GetNDF();
1786 double mch = -f->GetParameter(0)/kk;
1787 double relerr =
fabs(f->GetParError(0)/f->GetParameter(0));
1788 if(ndf==0)
return -1;
1789 this->cData[ID-1].mchirp = mch>0 ? pow(mch, 0.6) : -pow(-mch, 0.6);
1790 this->cData[ID-1].tmrgr = -f->GetParameter(1)/f->GetParameter(0);
1791 this->cData[ID-1].tmrgrerr = chi2T;
1792 this->cData[ID-1].chirpEllip = ellipt2;
1793 this->cData[ID-1].chirpEfrac = Efrac;
1794 this->cData[ID-1].chirpPfrac = Pfrac;
1795 this->cData[ID-1].chi2chirp = chi2T;
1797 this->cData[ID-1].tmrgrerr = 0.;
1800 double tmerger = -f->GetParameter(1)/f->GetParameter(0);
1801 for(
int i=0;
i<V; ++
i){
1805 if(T>(tmerger+tmerger_cut)) pix->
likelihood=0;
1809 this->cData[ID-1].fit = *
f;
1833 this->cData[ID-1].chi2chirp = 0;
1834 this->cData[ID-1].mchirp = 0 ;
1835 this->cData[ID-1].mchirperr = -1;
1836 this->cData[ID-1].tmrgr = 0;
1837 this->cData[ID-1].tmrgrerr = -1;
1839 double kf = pow(5./256, 3./8) * pow( C*C*C/G/SM, 5./8) /
Pi;
1840 double kdf = sqrt(0.6*kf*3./8);
1842 std::vector<int>* vint = &this->cList[ID-1];
1843 int V = vint->size();
1847 double minDT=1e10, minFreq=1e10;
1849 for(
int j=0;
j<V;
j++) {
1853 if(pix->
rate/2. < minFreq) minFreq = pix->
rate/2;
1854 if(1./pix->
rate < minDT) minDT = 1./pix->
rate;
1857 int naux = 1./(2*minDT*minFreq) + 0.5;
1862 double*
x =
new double[Vp];
1863 double*
y =
new double[Vp];
1864 double* wgt =
new double[Vp];
1865 bool*
sel =
new bool[Vp];
1872 double xmin,ymin, xmax, ymax;
1873 xmin = ymin = 1e100;
1874 xmax = ymax = -1e100;
1878 for(
int j=0;
j<V;
j++) {
1885 int nx = 1./pix->
rate/minDT + 0.5;
1886 int ny = pix->
rate/2/minFreq + 0.5;
1888 for(
int ix=0; ix<nx; ++ix) {
1889 for(
int iy=0; iy<ny; ++iy){
1890 x[
np] = T - 0.5/pix->
rate + (ix+0.5)*minDT;
1894 if(x[np]>xmax)xmax = x[
np];
1895 if(x[np]<xmin)xmin = x[
np];
1896 if(y[np]>ymax)ymax = y[
np];
1897 if(y[np]<ymin)ymin = y[
np];
1903 const double maxM = 30;
1904 const double stepM = 0.1;
1908 double m0 = 0, t0max = 0;
1909 double t0 = (tmin*2 + tmax)/3;
1938 int tPoints = (tmax + 1 -
t0)/minDT + 1;
1939 double* maxTimes =
new double[tPoints];
1940 double* maxMasses =
new double[tPoints];
1943 EndPoint** mint =
new EndPoint*[tPoints];
1944 for(
int j=0;
j<tPoints; ++
j) mint[
j] =
new EndPoint[2*np];
1947 for(; t0<tmax+1; t0 += minDT){
1949 for(
int i=0;
i<
np; ++
i){
1950 double dt = t0 - x[
i];
1952 double dt38 = sqrt(sqrt(dt));
1955 double b = kdf/sqrt(dt*dt38);
1956 double Delta = sqrt(b*b + 4*a*y[
i]);
1958 mint[tIndex][
j].value = pow( 2*a/(Delta + b), 16./5);
1959 mint[tIndex][
j].type = 1;
1960 mint[tIndex][++
j].value = pow( 2*a/(Delta - b), 16./5);
1961 mint[tIndex][j++].type = -1;
1964 qsort(mint[tIndex], j,
sizeof(EndPoint),
compEndP);
1968 for(
int k=1;
k<
j; ++
k){
1969 mint[tIndex][
k].type += mint[tIndex][
k-1].type;
1970 if(mint[tIndex][
k].type>=nsel){
1971 mmax = (mint[tIndex][
k].value + mint[tIndex][
k+1].value)/2;
1972 nsel = mint[tIndex][
k].type;
1978 maxMasses[0] =
mmax;
1981 else if(nsel == nselmax){ maxMasses[nmaxt] =
mmax; maxTimes[nmaxt++] =
t0;}
1985 t0max = maxTimes[nmaxt-1];
1986 m0 = maxMasses[nmaxt-1];
1988 for(
int j=0;
j<tPoints; ++
j)
delete [] mint[
j];
1991 delete [] maxMasses;
1998 double cf = kf/pow(m0, 5./8);
1999 double cdf = kdf/pow(m0, 5./16);
2000 for(
int i=0;
i<
np; ++
i){
2002 double a = t0max - x[
i];
2004 double b = sqrt(sqrt(a));
2007 double df = cdf/sqrt(b*a);
2008 if(y[
i]>fi+df)
continue;
2009 if(y[
i]<fi-df)
continue;
2011 if(x[
i]>tmax2) tmax2 = x[
i];
2024 for(
int i=0;
i<
np; ++
i){
2026 if(x[
i]<tmax2) frac += 1.0;
2035 double Efrac = selEn/totEn;
2041 double xcm, ycm, qxx, qyy, qxy;
2042 xcm = ycm = qxx = qyy = qxy = 0;
2044 for(
int i=0;
i<
np; ++
i){
2051 for(
int i=0;
i<
np; ++
i){
2052 qxx += (x[
i] - xcm)*(x[
i] - xcm);
2053 qyy += (y[
i] - ycm)*(y[
i] - ycm);
2054 qxy += (x[
i] - xcm)*(y[
i] - ycm);
2060 double sq_delta = sqrt( (qxx - qyy)*(qxx - qyy) + 4*qxy*qxy );
2061 double lam1 = (qxx + qyy + sq_delta)/2;
2062 double lam2 = (qxx + qyy - sq_delta)/2;
2065 double ellipt2 =
fabs((lam1 - lam2)/(lam1 + lam2));
2143 this->cData[ID-1].chi2chirp = Efrac;
2144 this->cData[ID-1].mchirp = m0;
2146 this->cData[ID-1].tmrgr = ellipt2;
2147 this->cData[ID-1].tmrgrerr = frac;
2161 TCanvas*
c =
new TCanvas(
"chirp",
""); c->cd();
2162 this->cData[
id-1].chirp.Draw(
"AP");
2163 this->cData[
id-1].fit.Draw(
"same");
2168 { TCanvas*
c =
new TCanvas(
"cpc",
"", 1200, 800);
2169 TH2F* h2 =
new TH2F(
"h2h",
"", 600, 0, 600, 2048, 0, 2048);
2171 std::vector<vector_int>::iterator it;
2172 for(it=cList.begin(); it != cList.end(); it++){
2173 size_t ID = pList[((*it)[0])].clusterID;
2175 h2->Fill(cTime[ID-1], cFreq[ID-1], cRate[ID-1][2]);
2179 else if(sCuts[ID-1]==1)
printf(
"*");
2181 printf(
"\n# of zero sCuts lusters:%d\n", cntr);
2230 if(!cList.size() || !pList.size())
return out;
2238 size_t out_size = 0;
2243 double logbpp = -
log(
bpp);
2244 double nsd,msd,esub,emax,
rho,subnet;
2248 double ampbpp = sqrt(2*logbpp-2*
log(1+pow(
log(1+logbpp*(1+1.5*exp(-logbpp))),2)));
2250 int ID,
rate, min_rate, max_rate;
2251 int RATE = abs(type)>2 ? abs(type) : 0;
2254 vector<vector_int>::iterator it;
2256 size_t M = pList.size();
2257 size_t m = index ? index : index+1;
2259 out.
resize(cList.size());
2266 if(strstr(name,
"ID")) c =
'i';
2267 if(strstr(name,
"size")) c =
'k';
2268 if(strstr(name,
"SIZE")) c =
'K';
2269 if(strstr(name,
"volume")) c =
'v';
2270 if(strstr(name,
"VOLUME")) c =
'V';
2271 if(strstr(name,
"start")) c =
's';
2272 if(strstr(name,
"stop")) c =
'd';
2273 if(strstr(name,
"dura")) c =
'D';
2274 if(strstr(name,
"low")) c =
'l';
2275 if(strstr(name,
"high")) c =
'h';
2276 if(strstr(name,
"energy")) c =
'e';
2277 if(strstr(name,
"subrho")) c =
'R';
2278 if(strstr(name,
"subnet")) c =
'U';
2279 if(strstr(name,
"subnrg")) c =
'u';
2280 if(strstr(name,
"maxnrg")) c =
'm';
2281 if(strstr(name,
"power")) c =
'w';
2282 if(strstr(name,
"conf")) c =
'Y';
2283 if(strstr(name,
"like")) c =
'L';
2284 if(strstr(name,
"null")) c =
'N';
2285 if(strstr(name,
"sign")) c =
'z';
2286 if(strstr(name,
"corr")) c =
'x';
2287 if(strstr(name,
"asym")) c =
'a';
2288 if(strstr(name,
"grand")) c =
'g';
2289 if(strstr(name,
"rate")) c =
'r';
2290 if(strstr(name,
"SNR")) c =
'S';
2291 if(strstr(name,
"hrss")) c =
'H';
2292 if(strstr(name,
"noise")) c =
'n';
2293 if(strstr(name,
"NOISE")) c =
'I';
2294 if(strstr(name,
"elli")) c =
'o';
2295 if(strstr(name,
"psi")) c =
'O';
2296 if(strstr(name,
"phi")) c =
'P';
2297 if(strstr(name,
"theta")) c =
'p';
2298 if(strstr(name,
"time")) c =
't';
2299 if(strstr(name,
"TIME")) c =
'T';
2300 if(strstr(name,
"freq")) c =
'f';
2301 if(strstr(name,
"FREQ")) c =
'F';
2302 if(strstr(name,
"band")) c =
'B';
2303 if(strstr(name,
"chi2")) c =
'C';
2305 if(c==
'0')
return out;
2309 for(it=cList.begin(); it!=cList.end(); it++){
2311 ID = pList[((*it)[0])].clusterID;
2312 if(sCuts[ID-1]>0)
continue;
2313 it_size = it->size();
2314 if(!it_size)
continue;
2320 pv = cRate.size() ? &(cRate[ID-1]) : NULL;
2323 if(type<0) rate = -type;
2324 else if(!pv) rate = 0;
2325 else if(type==1 && pv->size()) rate = (*pv)[0];
2326 else if(pv->size() &&
RATE) rate = ((*pv)[0]==
RATE) ? RATE : -1;
2328 min_rate=std::numeric_limits<int>::max();
2330 for(k=0; k<it_size; k++) {
2333 int prate =
int(pList[M].rate+0.1);
2334 if(rate && prate!=rate)
continue;
2335 if(prate>max_rate) max_rate = prate;
2336 if(prate<min_rate) min_rate = prate;
2338 if(pList[M].core && pList[M].likelihood>0) it_like++;
2339 if(!pList[M].core && core)
continue;
2344 if(!it_core)
continue;
2349 for(k=0; k<it_size; k++){
2352 out.
data[out_size++] = pList[
M].clusterID;
2360 out.
data[out_size++] = c==
'k' ? float(it_core) : float(it_halo);
2365 for(k=0; k<it_size; k++){
2368 out.
data[out_size++] = (c==
'p') ? pList[M].
theta : pList[M].
phi;
2376 for(k=0; k<it_size; k++){
2379 out.
data[out_size++] = (c==
'o') ? pList[M].ellipticity : pList[M].polarisation;
2386 for(k=0; k<it_size; k++){
2389 out.
data[out_size++] = pList[
M].rate;
2398 for(k=0; k<it_size; k++){
2401 if(!index)
continue;
2402 if(skip.
data[k])
continue;
2403 if(pList[M].
size()<
m)
continue;
2404 x = pList[
M].getdata(atype,m-1);
2408 if(c ==
'a') out.
data[out_size++] = mp+mm>0 ? (float(mp)-float(mm))/(mp+mm) : 0;
2409 else out.
data[out_size++] = mp+mm>0 ?
signPDF(mp,mm) : 0;
2418 esub = emax = sum = rho = 0;
2419 for(k=0; k<it_size; k++){
2421 nifo = pList[
M].
size();
2422 if(skip.
data[k])
continue;
2423 a = E = e = nsd = 0;
2424 for(n=0; n<
nifo; n++) {
2425 a+=
fabs(pList[M].getdata(atype,n));
2426 x = pList[
M].getdata(atype,n); x*=
x;
2427 v = pList[
M].data[
n].noiserms; v*=
v;
2428 if(x>E) {E=
x; msd=
v;}
2430 nsd += v>0 ? 1/v : 0.;
2433 if(nsd==0. && c==
'U') {
2434 cout<<
"netcluster::get():empty noiserms array"<<endl;
exit(0);
2437 a = a>0 ? e/(a*
a) : 1;
2438 rho += (1-
a)*(e-nSUB*2);
2440 x = y*(1+y/(E+1.e-5));
2441 nsd -= msd>0 ? 1./msd : 0;
2442 v = (2*E-
e)*msd*nsd/10.;
2446 sum += (e*x/(x+(v>0?v:1.e-5)))*(a>0.5?a:0);
2448 sum = sum/(emax+esub+0.01);
2449 if(c==
'u') out.
data[out_size++] = esub;
2450 if(c==
'm') out.
data[out_size++] = emax;
2451 if(c==
'U') out.
data[out_size++] = sum;
2452 if(c==
'R') out.
data[out_size++] = sqrt(rho);
2464 for(k=0; k<it_size; k++){
2467 if(!index)
continue;
2468 if(skip.
data[k])
continue;
2469 if(pList[M].
size()<m)
continue;
2471 x = pList[
M].getdata(atype,m-1);
2472 x/= (atype==
'W' || atype==
'w') ? pList[M].data[m-1].noiserms : 1.;
2473 x/= (atype==
'U' || atype==
'u') ? pList[M].data[m-1].noiserms : 1.;
2476 if(atype==
'R' || atype==
'r'){
2478 a-=
log(1+pow(
log(1+a*(1+1.5*exp(-a))),2));
2483 if(c==
'Y' || c==
'z') {
2484 if(atype==
'R') { y +=
x; mm++; }
2485 if(atype==
'r' && x>0) { y +=
x; mm++; }
2487 else if(c==
'e' || c==
'C') { y += a*
a; mm++; }
2488 else if(a*a>1.) { y += a*
a; mm++; }
2492 if(c==
'Y' || c==
'z') {
2493 a = pow(x+1.11/2,2)/2./1.07;
2494 y+= (a>logbpp) ? a-logbpp : 0.;
2495 if(atype==
'S' || atype==
'W' || atype==
'P' || atype==
'U') mm++;
2496 else if(a>logbpp) mm++;
2498 else if(c==
'e' || c==
'C' || c==
'w') {
2499 if(atype==
'S' || atype==
'W' || atype==
'P'|| atype==
'U') {
2502 else if(x>ampbpp) { y += x*
x; mm++; }
2504 else if(x*x>1.) { y += x*
x; mm++; }
2509 if(c==
'S' && mm) y -= double(mm);
2510 if(c==
'w' && mm) y /= double(mm);
2511 if(c==
'z' && mm) y =
gammaCL(y,mm);
2513 out.
data[out_size++] =
y;
2518 for(k=0; k<it_size; k++){
2521 if(!index)
continue;
2522 if(skip.
data[k])
continue;
2523 if(pList[M].
size()<m)
continue;
2525 x =
fabs(pList[M].getdata(atype,m-1));
2528 out.
data[out_size++] =
y;
2535 for(k=0; k<it_size; k++){
2537 if(skip.
data[k])
continue;
2538 y = 1./pList[
M].
rate;
2539 mm= pList[
M].layers;
2540 x = index ? y*
int(pList[M].data[m-1].index/mm) :
2545 out.
data[out_size++] = (c==
's') ? a : b;
2552 for(k=0; k<it_size; k++){
2554 if(skip.
data[k])
continue;
2555 mp= size_t(this->rate/pList[M].rate+0.1);
2556 mm= pList[
M].layers;
2557 double dF = mm==mp ? 0. : -0.5;
2558 y = pList[
M].rate/2.;
2559 x = y * (pList[
M].frequency+dF);
2563 out.
data[out_size++] = (c==
'l') ? a : b;
2570 for(k=0; k<it_size; k++){
2572 if(skip.
data[k])
continue;
2574 if(atype==
'S' || atype==
's' || atype==
'P' || atype==
'p' || !index) {
2575 for(i=0; i<pList[
M].size(); i++) {
2576 x += pow(pList[M].data[i].
asnr,2);
2578 x -= 2*pList[
M].likelihood;
2581 b = pList[
M].data[m-1].asnr;
2582 b -= pList[
M].data[m-1].wave/pList[
M].data[m-1].noiserms;
2586 a += pList[
M].likelihood;
2589 out.
data[out_size++] =
a;
2602 if(c==
'F' && (
int)cFreq.size()>ID-1) {
2603 out.
data[out_size++] = cFreq[ID-1];
2606 if(c==
'T' && (
int)cTime.size()>ID-1) {
2607 out.
data[out_size++] = cTime[ID-1];
2611 for(k=0; k<it_size; k++) {
2614 if(!index && atype!=
'L')
continue;
2615 if(skip.
data[k])
continue;
2616 if(pList[M].
size()<m && atype!=
'L')
continue;
2618 mp= size_t(this->rate/pList[M].rate+0.1);
2619 t = 1./pList[
M].rate;
2620 mm= pList[
M].layers;
2621 if(atype==
'S' || atype==
's' || atype==
'P' || atype==
'p') {
2622 x = pList[
M].getdata(atype,m-1);
2625 else if (atype==
'R' || atype==
'r'){
2626 x = pList[
M].getdata(atype,m-1);
2627 x = pow(sqrt(2*1.07*(
fabs(x)-
log(
bpp)))-1.11/2.,2);
2630 x = pList[
M].likelihood;
2634 if(c==
't' || c==
'T' || c==
'D') {
2635 double dT = mm==mp ? 0. : 0.5;
2636 double iT = (pList[
M].time/mm -
dT)*t;
2639 iT = (pList[
M].data[m-1].index/mm -
dT)*t;
2642 double dt = 1./max_rate;
2653 double dF = mm==mp ? 0. : 0.5;
2654 double iF = (pList[
M].frequency - dF)/t/2.;
2656 int n = 1./(min_rate*
t);
2657 double df = min_rate/2.;
2671 a = a>0 ? sqrt(a)*b : min_rate/2.;
2676 a = a>0 ? sqrt(a)*b : 1./max_rate;
2679 out.
data[out_size++] = b>0. ? a/b : -1.;
2688 out.
data[out_size] = 0.;
2690 for(k=0; k<it_size; k++) {
2693 if(!index)
continue;
2694 if(skip.
data[k])
continue;
2695 if(pList[M].
size()<m)
continue;
2697 r = pList[
M].getdata(
'N',m-1);
2702 a = pow(pList[M].getdata(atype,m-1),2);
2703 if(atype==
'S' || atype==
's' || atype==
'P' || atype==
'p') { a -= 1.; a *= r*
r; }
2704 sum += a<0. ? 0. :
a;
2707 sum += c==
'n' ? r*r : 1./r/
r;
2712 if(c !=
'H' && mp) { sum = sum/double(mp); }
2713 if(c ==
'I' && mp) { sum = 1./sum; }
2714 out.
data[out_size++] = sum>0. ? float(
log(sum)/2./
log(10.)) : 0.;
2718 out.
data[out_size++] = float(it_like);
2723 for(k=0; k<it_size; k++){
2726 out.
data[out_size++] = it_size;
2745 if(!cList.size())
return 0.;
2761 double tsRate = W.
rate();
2762 double fl = tsRate/2.;
2770 vector<vector_int>::iterator it;
2773 size_t M = pList.size();
2777 for(it=cList.begin(); it!=cList.end(); it++){
2779 ID = pList[((*it)[0])].clusterID;
2780 it_size = it->size();
2782 if(ID != cid)
continue;
2783 if(!it_size)
continue;
2789 R = pv->size() ? (*pv)[0] : 0;
2794 for(k=0; k<it_size; k++) {
2799 if(!pList[M].
core)
continue;
2800 if(R &&
int(pix->
rate+0.1)!=R)
continue;
2801 if(!R) R =
int(pix->
rate+0.1);
2803 pixtime = pix->
getdata(
'I',n)/mm;
2804 if(pixtime > max) max = pixtime;
2805 if(pixtime < min) min = pixtime;
2831 W.
start(
double(offset)/R);
2836 if(!it_core)
continue;
2838 for(k=0; k<it_size; k++){
2842 if(skip.
data[k])
continue;
2843 if(!(pix->
size()))
continue;
2845 pixtime = size_t(pix->
getdata(
'I',n)/mm);
2850 if(f > max_layer)
continue;
2851 if(f*R/2. <= fl) { fl = f*R/2.; W.
setlow(fl); }
2852 if((f+1)*R/2. >= fh) { fh = (f+1)*R/2.; W.
sethigh(fh); }
2856 if(t < 0 ||
size_t(t) >= S.
size())
continue;
2857 if(pix->
size() <=
n)
continue;
2860 if(atype==
'W') a /= pix->
getdata(
'N',n);
2864 mp++; sum += 1./a/
a;
2865 temp += pList[
M].time/double(R);
2872 sum = sqrt(
double(mp)/sum);
2896 if(!cList.size())
return z;
2898 bool signal = atype==
'S' || atype==
's';
2899 bool strain = atype==
'w' || atype==
's';
2906 if(maxfLen<fLen) maxfLen=fLen;
2912 std::vector<int>* vint;
2916 cid = this->
get((
char*)
"ID",0,
'S',0);
2920 for(
int k=0;
k<
K;
k++) {
2922 int id = size_t(cid.
data[
k]+0.1);
2923 if(
id!=ID)
continue;
2925 vint = &(this->cList[
id-1]);
2927 int V = vint->size();
2934 double T, a00, a90, rms;
2935 for(
int j=0;
j<V;
j++) {
2936 pix = this->getPixel(
id,
j);
2943 tmin =
int(tmin-maxfLen)-1;
2944 tmax =
int(tmax+maxfLen)+1;
2945 z.
resize(
size_t(this->
rate*(tmax-tmin)+0.1));
2948 int io =
int(tmin*z.
rate()+0.01);
2956 for(
int j=0;
j<V;
j++) {
2957 pix = this->getPixel(
id,
j);
2958 if(!pix->
core)
continue;
2963 a00*= strain ? rms : 1.;
2964 a90*= strain ? rms : 1.;
2968 if(mode < 0) a00=0.;
2969 if(mode > 0) a90=0.;
2974 for(
int i=0;
i<x00.
size();
i++){
2975 if(j00+i<0 || j00+i>=z.
size())
continue;
2976 z.
data[j00+
i] += x00[
i]*a00;
2977 z.
data[j90+
i] += x90[
i]*a90;
2997 size_t I = this->pList.size();
3000 if(app) fp=fopen(fname,
"ab");
3001 else fp=fopen(fname,
"wb");
3004 cout<<
"netcluster::write() error : cannot open file "<<fname<<
"\n";
3009 if(!write(fp,app)) {
fclose(fp);
return 0; };
3012 for(i=0; i<I; i++) {
3013 if(!pList[i].write(fp)) {
fclose(fp);
return 0; }
3027 size_t I = this->pList.size();
3035 double rest = this->nPIX*10+2*this->pair;
3037 db[1] = this->
start;
3040 db[4] = this->
shift;
3042 db[6] = this->
fhigh;
3043 db[7] = (double)this->
run;
3045 if(fwrite(db, 9*
sizeof(
double), 1, fp) !=1) {
3055 for(i=0; i<this->cList.size(); ++
i) {
3056 if(sCuts[i]==1)
continue;
3059 size_t K = v.size();
3063 for(k=0; k<
K; ++
k) {
3064 if(pList[v[k]].tdAmp.size()) skip=
false;
3069 for(k=0; k<
K; k++) pp[k] = &pList[v[k]];
3072 for(k=0; k<
K; k++) {
3073 if(!pp[k]->tdAmp.
size())
continue;
3080 if(k==0) pix.
ellipticity = pList[v[0]].ellipticity;
3081 if(k==1) pix.
ellipticity = pList[v[1]].ellipticity;
3103 FILE *fp = fopen(fname,
"rb");
3106 cout <<
"netcluster::read() error : cannot open file " << fname <<
". \n";
3110 if(!read(fp,0)) {
fclose(fp);
return 0;}
3115 pList.push_back(pix);
3117 end = pList[
i].read(fp);
3121 size_t I = pList.size();
3141 if(fread(db, 9*
sizeof(
double), 1, fp) !=1)
return 0;
3142 int kk =
int(db[8]+0.1);
3143 db[8] += db[8]>0. ? 0.1 : -0.1;
3145 this->
start = db[1];
3148 this->
shift = db[4];
3150 this->
fhigh = db[6];
3151 this->
run =
int(db[7]+0.1);
3153 this->pair = (kk%10)/2;
3158 size_t I = pList.size();
3159 for(i=0; i<I; ++
i) pList[i].clean();
3165 int ID = cList.size()+1;
3167 while(pix.
read(fp)){
3169 if(II<2 && pix.
neighbors.size()<1) stop=
true;
3170 if(II>1 && pix.
neighbors.size()<2) stop=
true;
3171 if((
int)II>nmax) pix.
clean();
3173 pList.push_back(pix);
3180 std::vector<int>
list(II);
3181 std::vector<int> vtof(
NIFO);
3182 std::vector<int> vtmp;
3183 for(i=0; i<II; ++
i) list[i] = I++;
3184 cList.push_back(list);
3185 nTofF.push_back(vtof);
3186 p_Ind.push_back(vtmp);
3209 cout<<
"netcluster::setTDvec() error: empty network.";
3213 cout<<
"netcluster::setTDvec() error: run network::setDelayIndex() first.";
3220 size_t batch = BATCH ? BATCH : this->
size()+1;
3223 size_t loud = LOUD ? LOUD : batch;
3235 for(i=0; i<this->cList.size(); i++){
3237 if(this->sCuts[i]==1)
continue;
3238 v = &(this->cList[
i]);
3241 KK = LOUD && K>loud ? loud :
K;
3242 if(this->sCuts[i]==-2) {count+=KK;
continue;}
3246 for(k=0; k<
K; k++) {
3247 pix = &(this->pList[(*v)[
k]]);
3248 if(!pix->
core) skip=
false;
3249 if(pix->
tdAmp.size()) {skip=
false; npix++;}
3251 if(npix==K) {count+=
K;
continue;}
3257 for(k=0; k<
K; k++) pp[k] = &(pList[(*v)[
k]]);
3262 for(k=0; k<KK; k++) {
3265 if(count>=batch) {skip =
true;
break;}
3271 if(!pix->
core) count++;
3273 if(
int(pix->
rate+0.1)!= waveR)
continue;
3275 for(j=0; j<
nIFO; j++) {
3277 ind =
int(pix->
data[j].index);
3279 pix->
tdAmp.push_back(vec);
3287 if(LOUD && npix==KK) this->sCuts[
i] = -2;
3313 cout<<
"netcluster::setTDvec() error: empty network.";
3317 cout<<
"netcluster::setTDvec() error: run network::setDelayIndex() first.";
3321 size_t i,
j,
k,
K,KK,
M;
3322 size_t batch = BATCH ? BATCH : this->
size()+1;
3325 size_t loud = LOUD ? LOUD : batch;
3339 for(i=0; i<this->cList.size(); i++){
3341 if(this->sCuts[i]==-1)
continue;
3342 if(this->sCuts[i]==1)
continue;
3343 v = &(this->cList[
i]);
3346 KK = LOUD && K>loud ? loud :
K;
3347 if(this->sCuts[i]==-2) {count+=KK;
continue;}
3351 for(k=0; k<
K; k++) {
3352 pix = &(this->pList[(*v)[
k]]);
3353 if(!pix->
core) skip=
false;
3354 if(pix->
tdAmp.size()) {skip=
false; npix++;}
3356 if(npix==K) {count+=
K;
continue;}
3362 for(k=0; k<
K; k++) pp[k] = &(pList[(*v)[
k]]);
3367 for(k=0; k<KK; k++) {
3370 if(count>=batch) {skip =
true;
break;}
3376 if(!pix->
core) count++;
3379 for(j=0; j<
nIFO; j++) {
3384 ind =
int(pix->
data[j].index);
3387 for(
int qqq=0; qqq<vec.
size(); qqq++){
3388 if(
fabs(vec.
data[qqq])>1.e6) cout<<vec.
data[qqq]<<
" nun in loadTDampSSE\n";
3391 pix->
tdAmp.push_back(vec);
3399 if(LOUD && npix==KK) this->sCuts[
i] = -2;
3422 size_t I = this->pList.size();
3426 if(
TString(froot->GetOption())!=
"CREATE" &&
TString(froot->GetOption())!=
"UPDATE") {
3427 cout<<
"netcluster::write error: input root file wrong mode (must be CREATE or UPDATE) "
3428 <<froot->GetPath()<<endl;
3433 TDirectory* cdtree = tdir!=
"" ? (TDirectory*)froot->Get(tdir) : (TDirectory*)froot;
3434 if(cdtree==NULL) cdtree = froot->mkdir(tdir);
3446 if(irate<0)
sprintf(trName,
"%s-cycle:%d:%d",tname.Data(),cycle,-
irate);
3447 else sprintf(trName,
"%s-cycle:%d",tname.Data(),cycle);
3448 TTree*
tree = (TTree*)cdtree->Get(trName);
3450 tree =
new TTree(trName,trName);
3451 tree->Branch(
"cid",&cid,
"cid/I");
3452 tree->Branch(
"rate",&rate,
"rate/I");
3453 tree->Branch(
"orate",&orate,
"orate/I");
3454 tree->Branch(
"ctime",&ctime,
"ctime/F");
3455 tree->Branch(
"cfreq",&cfreq,
"cfreq/F");
3456 tree->Branch(
"pix",
"netpixel",&pix,32000,0);
3458 tree->SetBranchAddress(
"cid",&cid);
3459 tree->SetBranchAddress(
"rate",&rate);
3460 tree->SetBranchAddress(
"orate",&orate);
3461 tree->SetBranchAddress(
"ctime",&ctime);
3462 tree->SetBranchAddress(
"cfreq",&cfreq);
3463 tree->SetBranchAddress(
"pix",&pix);
3467 tree->SetAutoFlush(0);
3472 TList* ulist = tree->GetUserInfo();
3473 if(ulist->GetSize()>0)
return 1;
3475 nc->
cpf(*
this,
false,0);
3478 nc->SetTitle(title);
3487 for(i=0; i<this->cList.size(); ++
i) {
3488 if(sCuts[i]==1)
continue;
3491 orate = r.size()>0 ? r[0] : 0;
3497 size_t K = v.size();
3500 if((cID!=0)&&(pList[v[0]].clusterID!=cID))
continue;
3503 for(k=0; k<
K; ++
k) {
3504 if(pList[v[k]].tdAmp.size()) skip=
false;
3506 if(app>0 && skip)
continue;
3509 for(k=0; k<
K; k++) pp[k] = &pList[v[k]];
3512 for(k=0; k<
K; k++) {
3513 if(app>0 && !pp[k]->tdAmp.
size())
continue;
3521 if(k==0) pix->
ellipticity = pList[v[0]].ellipticity;
3522 if(k==1) pix->
ellipticity = pList[v[1]].ellipticity;
3567 std::vector<int>
list;
3568 std::vector<int> vtof(
NIFO);
3569 std::vector<int> vtmp;
3570 std::vector<float> varea;
3571 std::vector<float> vpmap;
3574 bool skip = nmax==-2 ?
true :
false;
3575 if(nmax<0) nmax=std::numeric_limits<int>::max();
3578 TObject* obj = tdir!=
"" ? froot->Get(tdir) : (TObject*)froot;
3580 cout<<
"netcluster::read error: input dir " << tdir <<
" not exist" << endl;
3583 if(tdir!=
"" && !
TString(obj->ClassName()).Contains(
"TDirectory")) {
3584 cout<<
"netcluster::read error: input dir " << tdir <<
" is not a directory" << endl;
3587 TDirectory* cdtree = tdir!=
"" ? (TDirectory*)froot->Get(tdir) : (TDirectory*)froot;
3589 cout<<
"netcluster::read error: tree dir " << tdir
3590 <<
" not present in input root file " << froot->GetPath() << endl;
3592 }
else cdtree->cd();
3596 if(rate<0)
sprintf(trName,
"%s-cycle:%d:%d",tname.Data(),cycle,-
rate);
3597 else sprintf(trName,
"%s-cycle:%d",tname.Data(),cycle);
3598 TTree*
tree = (TTree*)cdtree->Get(trName);
3599 if(rate<0) {tree->LoadBaskets(100000000);rate=abs(rate);}
3601 cout<<
"netcluster::read error: tree " << trName
3602 <<
" not present in input root file " << froot->GetPath() << endl;
3605 tree->SetBranchAddress(
"cid",&cid);
3606 tree->SetBranchAddress(
"orate",&orate);
3607 tree->SetBranchAddress(
"ctime",&ctime);
3608 tree->SetBranchAddress(
"cfreq",&cfreq);
3609 tree->SetBranchAddress(
"pix",&pix);
3614 if(rate>0)
sprintf(sel,
"rate==%d ",rate);
3616 else sprintf(sel,
"%s && cid==%d",sel,cID);}
3618 TTreeFormula
cut(
"cuts", sel, tree);
3621 if(cdtree->Get(
"htemp")!=NULL) cdtree->Delete(
"htemp");
3624 size_t size = tree->GetEntries();
3628 tree->SetBranchStatus(
"orate",
false);
3629 tree->SetBranchStatus(
"ctime",
false);
3630 tree->SetBranchStatus(
"cfreq",
false);
3631 tree->SetBranchStatus(
"pix",
false);
3632 for(i=0;i<
size;i++) {
3634 if(cut.EvalInstance()==0)
continue;
3639 tree->SetBranchStatus(
"orate",
true);
3640 tree->SetBranchStatus(
"ctime",
true);
3641 tree->SetBranchStatus(
"cfreq",
true);
3642 tree->SetBranchStatus(
"pix",
true);
3646 std::vector<int> clist;
3647 for(i=0;i<
size;i++) clist.push_back(
int(icid[i]+0.5));
3649 removeDuplicates<int>(clist);
3652 if(rate<=0 && cID==0){
3653 TList* ulist = tree->GetUserInfo();
3654 if(ulist->GetSize()==0) {
3655 cout<<
"netcluster::read error: header is null" << endl;
exit(1);
3667 if(rate<0) {cout<<
"netcluster::read error: input rate par must be >= 0" << endl;
exit(1);}
3670 for(
size_t k=0;
k<clist.size();
k++) {
3675 size_t I = pList.size();
3676 if(!skip)
for(i=0; i<I; ++
i) pList[i].clean();
3681 int ID = cList.size()+1;
3683 std::vector<int> crate;
3684 for(i=os;i<
size;i++) {
3685 if(
int(icid[i]+0.5)!=
id)
continue;
3686 tree->GetEntry(
int(entry[i]+0.5));
3688 if(II<2 && pix->neighbors.size()<1) stop=
true;
3689 if(II>1 && pix->
neighbors.size()<2) stop=
true;
3690 if(II>nmax) pix->
clean();
3692 pList.push_back(*pix);
3693 if(orate&&!crate.size()) crate.push_back(orate);
3698 if(!II) {
delete tree;
return clist;}
3702 for(i=0; i<II; ++
i) list.push_back(I++);
3703 cList.push_back(list);
3704 cRate.push_back(crate);
3705 cTime.push_back(ctime);
3706 cFreq.push_back(cfreq);
3707 sArea.push_back(varea);
3708 p_Map.push_back(vpmap);
3709 nTofF.push_back(vtof);
3710 p_Ind.push_back(vtmp);
3711 if(!skip) cData.push_back(cd);
3721 for(
size_t i=0;
i<this->cList.size(); ++
i) {
3722 if(sCuts[
i]==1)
continue;
3725 size_t K = v.size();
3728 for(
size_t k=0;
k<
K; ++
k) {
3729 if(pList[v[
k]].tdAmp.size()) nhpix++;
3735 cout <<
"rate\t= " << this->
rate << endl;
3736 cout <<
"start\t= " << this->
start << endl;
3737 cout <<
"stop\t= " << this->
stop << endl;
3738 cout <<
"shift\t= " << this->
shift << endl;
3739 cout <<
"bpp\t= " << this->
bpp << endl;
3740 cout <<
"flow\t= " << this->
flow << endl;
3741 cout <<
"ghigh\t= " << this->
fhigh << endl;
3742 cout <<
"run\t= " << this->
run << endl;
3743 cout <<
"nPIX\t= " << this->nPIX << endl;
3744 cout <<
"pair\t= " << this->pair << endl;
3746 cout <<
"cList\t= " << this->cList.size() << endl;
3747 cout <<
"pList\t= " << this->pList.size() << endl;
3748 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
virtual size_t size() const
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)
printf("total live time: non-zero lags = %10.1f \n", liveTot)
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<< "\t layers : "<< nLAYERS<< "\t dF(hz) : "<< dF<< "\t 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)
network ** net
NOISE_MDC_SIMULATION.
WDM< double > * getwdm(size_t M)
param: number of wdm layers
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]
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
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
TString sel("slag[1]:rho[1]")
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)
virtual void waveSplit(DataType_t **pp, size_t l, size_t r, size_t m) const
size_t loadTDamp(network &net, char c, size_t BATCH=10000, size_t LOUD=0)
double SpeedOfLightInVacuo()