67 #include <boost/any.hpp> 73 #define YEAR (24*3600*365.) 75 #define nCUT_MAX 20 // number of PP cut max defined in the input config file 77 #define nBKG_MAX 10 // number of loudest background listed 79 #define nIFAR 14 // number of ifar factor used to print inital/final detections 81 #define SIGMA_FACTOR 1. // factor used to rescale input sigma 83 #define CHECK_DNEVT_VS_IFAR // enable dnevt vs IFAR check -> the increment of detected events must be >=0 for each IFAR 111 int GetSelectedEvents(TTree* tree_BKG, TTree* tree_SIM,
TString user_cut,
int ncut,
double* cut_thr,
double& rho_thr);
114 void PrintPPCuts(
int nevt_new,
int nevt_old,
int ncut,
double* cut_thr,
double rho_thri,
TString user_cut,
bool bppcuts,
bool beff,
bool bbcut);
132 if(ofname.EndsWith(
".out")) {
134 cout << endl <<
"TunePPCutsTool.C - Error : ofname extension must be '.out' !!!" << endl << endl;
exit(1);
138 gOFNAME = ofname.ReplaceAll(
".out",TString::Format(
"_IFAR_%.2f.out",IFAR));
143 if(
gNBKG==0) {cout << endl <<
"IFAR too high -> nBKG = 0, macro aborted" << endl << endl;
exit(1);}
146 cout <<
"--------------------------------------------------------------------------------------------" << endl;
147 cout <<
" Input Parameters " << endl;
148 cout <<
"--------------------------------------------------------------------------------------------" << endl;
150 cout <<
" IFAR = " << IFAR <<
" (years) ->" <<
"\tnBKG = " <<
gNBKG <<
"\tnCTRY = " 153 cout <<
" gOFNAME = " <<
gOFNAME << endl;
156 gErrorIgnoreLevel = kError;
163 cout <<
" " << ifile_BKG << endl;
165 TFile *rfile_BKG = TFile::Open(ifile_BKG);
166 if(rfile_BKG==NULL) {cout <<
"Error opening file: " << ifile_BKG << endl;
exit(1);}
168 TTree* tree_BKG = (TTree *) gROOT->FindObject(
"waveburst");
169 if(tree_BKG==NULL) {cout <<
"waveburst tree not found !!!" << endl;
exit(1);}
174 TList* ifoList = tree_BKG->GetUserInfo();
176 for (
int n=0;
n<ifoList->GetSize();
n++) {
179 ifo.push_back(dParams[
n].
name);
184 cout <<
"ifo names are not contained in the input wave root file: " <<
IFILE_BKG << endl;
188 int nIFO = ifoList->GetSize();
193 gZL_CUT = TCut(
"gZL_CUT",TString::Format(
"(lag[%d]==0) && (slag[%d]==0)",nIFO,nIFO).Data());
200 cout <<
" " << ifile_SIM << endl;
202 TFile *rfile_SIM = TFile::Open(ifile_SIM);
203 if(rfile_SIM==NULL) {cout <<
"Error opening file: " << ifile_SIM << endl;
exit(1);}
205 TTree* tree_SIM = (TTree *) gROOT->FindObject(
"waveburst");
206 if(tree_SIM==NULL) {cout <<
"waveburst tree not found !!!" << endl;
exit(1);}
213 ifile_MDC.ReplaceAll(
"wave_",
"mdc_");
214 cout <<
" " << ifile_MDC << endl;
216 TFile *rfile_MDC = TFile::Open(ifile_MDC);
217 if(rfile_MDC==NULL) {cout <<
"Error opening file: " << ifile_MDC << endl;
exit(1);}
219 TTree* tree_MDC = (TTree *) gROOT->FindObject(
"mdc");
220 if(tree_MDC==NULL) {cout <<
"mdc tree not found !!!" << endl;
exit(1);}
223 gNMDC = tree_MDC->GetEntries();
224 cout << endl <<
" gNMDC = " <<
gNMDC <<
" (injections)" << endl << endl;
231 TTree* mtree_BKG = tree_BKG->CloneTree();
232 TTree* mtree_SIM = tree_SIM->CloneTree();
238 std::stringstream pp_cuts(
PP_CUTS);
244 cout << endl <<
" bin1_cut_standard ..." << endl << endl;
245 cout <<
" -> " << bin_cut_standard.GetTitle() << endl << endl;
246 cout << endl <<
" bin1_cut_basic ..." << endl << endl;
267 cout << endl <<
" background covariance matrix ..." << endl << endl;
269 cout << endl <<
" simulation covariance matrix ..." << endl << endl;
279 int nevt_std =
GetSelectedEvents(mtree_BKG, mtree_SIM, bin_cut_standard.GetTitle(), 0, NULL, rho_thr);
280 cout << endl <<
" nevt standard = " << nevt_std << endl << endl;
281 if(nevt_std==0) {cout << endl <<
" Error - input IFAR is too low ..." << endl << endl;
exit(1);}
294 double rho_thr_max=0.0;
295 int nevt_max=nevt_std;
300 cout << endl <<
"Initial tuning ..." << endl << endl;
302 for(
int k=0;
k<
gNCUT;
k++) cut_thr_max[
k]=cut_mean[
k];
305 cout <<
" " <<
i <<
" -> " <<
gCUT_NAME[
i] <<
" ..." << endl;
306 for(
int k=0;
k<
gNCUT;
k++) cut_thr[
k]=cut_thr_max[
k];
310 int nevt_new =
GetSelectedEvents(mtree_BKG, mtree_SIM, user_cut, gNCUT, cut_thr, rho_thr);
311 #ifdef CHECK_DNEVT_VS_IFAR 314 bool check_dnevt =
true;
316 if(nevt_new>nevt_max && check_dnevt==
true) {
318 cout << endl <<
" " <<
gCUT_NAME[
i] <<
" : standard = " <<
gCUT_MEA[
i] <<
" -> tuned = " << cut_thr[
i] << endl;
319 PrintPPCuts(nevt_new, nevt_std, gNCUT, cut_thr, rho_thr, user_cut,
false,
true,
false);
322 for(
int i=0;i<
gNCUT;i++) cut_mean[i]=cut_thr[i];
325 for(
int i=0;i<
gNCUT;i++) cut_thr_max[i]=cut_thr[i];
338 cout << endl <<
"Central tuning ..." << endl << endl;
340 if(
i%1000==0) cout <<
"Loop ->\t" <<
i <<
" / " << gNCTRY << endl;
343 cut_thr[
i]=gRandom->Gaus(cut_mean[
i],cut_sigma[i]);
348 int nevt_new =
GetSelectedEvents(mtree_BKG, mtree_SIM, user_cut, gNCUT, cut_thr, rho_thr);
349 #ifdef CHECK_DNEVT_VS_IFAR 352 bool check_dnevt =
true;
354 if(nevt_new>nevt_max && check_dnevt==
true) {
356 PrintPPCuts(nevt_new, nevt_std, gNCUT, cut_thr, rho_thr, user_cut,
false,
true,
false);
359 for(
int i=0;
i<
gNCUT;
i++) cut_mean[
i]=cut_thr[
i];
362 for(
int i=0;
i<
gNCUT;
i++) cut_thr_max[
i]=cut_thr[
i];
373 cout << endl <<
"Final tuning ..." << endl << endl;
377 cout <<
" " <<
i <<
" -> " <<
gCUT_NAME[
i] <<
" ..." << endl;
378 for(
int k=0;
k<
gNCUT;
k++) cut_thr[
k]=cut_thr_max[
k];
382 int nevt_new =
GetSelectedEvents(mtree_BKG, mtree_SIM, user_cut, gNCUT, cut_thr, rho_thr);
383 #ifdef CHECK_DNEVT_VS_IFAR 386 bool check_dnevt =
true;
388 if(nevt_new>nevt_max && check_dnevt==
true) {
390 cout << endl <<
" " <<
gCUT_NAME[
i] <<
" : standard = " <<
gCUT_MEA[
i] <<
" -> tuned = " << cut_thr[
i] << endl;
391 PrintPPCuts(nevt_new, nevt_std, gNCUT, cut_thr, rho_thr, user_cut,
false,
true,
false);
394 for(
int i=0;i<
gNCUT;i++) cut_mean[i]=cut_thr[i];
397 for(
int i=0;i<
gNCUT;i++) cut_thr_max[i]=cut_thr[i];
408 if(rho_thr_max==0.0) {
418 cout <<
"-------------------------------------------------------------------------" << endl;
419 cout <<
"IFAR = " << IFAR <<
" (years) " <<
"\tnBKG = " <<
gNBKG << endl;
420 cout <<
"nCTRY = " << gNCTRY <<
"\tnIFTRY = " <<
gNIFTRY << endl;
421 cout <<
"-------------------------------------------------------------------------" << endl;
426 PrintPPCuts(nevt_max, nevt_std, gNCUT, cut_thr_max, rho_thr_max, user_cut,
true,
true,
false);
443 if(user_cut!=
"") cut = TString::Format(
"(%s)",user_cut.Data());
444 if(cut!=
"" && ncut>0) cut = cut +
" && ";
445 for(
int i=0;
i<ncut;
i++) {
446 TString sAND =
i==ncut-1 ?
"" :
"&&";
447 cut = cut + TString::Format(
"(%s%s%f)%s",
gCUT_NAME[
i].Data(),
gCUT_CMP[
i].Data(),cut_thr[
i],sAND.Data());
450 TString cut_bkg = cut + TString::Format(
" && !(%s)",
gZL_CUT.GetTitle());
451 tree_BKG->Draw(sel, cut_bkg,
"goff");
452 int nBKG = (Int_t)tree_BKG->GetSelectedRows();
458 int *
index =
new Int_t[nBKG];
459 double*
value = tree_BKG->GetV1();
460 TMath::Sort(nBKG,value,index,
true);
461 rho_thr = value[index[
gNBKG]];
464 cut = cut + TString::Format(
" && rho[1]>%f",rho_thr);
465 tree_SIM->Draw(sel,cut,
"goff");
466 ndet_SIM = (Int_t)tree_SIM->GetSelectedRows();
476 if(user_cut!=
"") cut = TString::Format(
"(%s)",user_cut.Data());
477 if(cut!=
"" && ncut>0) cut = cut +
" && ";
478 for(
int i=0;
i<ncut;
i++) {
479 TString sAND =
i==ncut-1 ?
"" :
"&&";
480 cut = cut + TString::Format(
"(%s%s%f)%s",
gCUT_NAME[
i].Data(),
gCUT_CMP[
i].Data(),cut_thr[
i],sAND.Data());
484 cout << endl << label <<
" PP cuts string ..." << endl;
485 cout << endl << cut << endl << endl;
488 cout << endl << label <<
" Loudest background list ..." << endl;
489 TString cut_bkg = cut + TString::Format(
" && !(%s)",
gZL_CUT.GetTitle());
490 tree_BKG->Draw(
"rho[1]",cut_bkg.Data(),
"goff");
491 int ndet_BKG = (Int_t)tree_BKG->GetSelectedRows();
492 int *
index =
new Int_t[ndet_BKG];
493 double*
value = tree_BKG->GetV1();
494 TMath::Sort(ndet_BKG,value,index,
true);
495 double rho_sup = value[index[0]];
497 for(
int i=0;
i<nLoudest;
i++) cout <<
"\t" <<
i <<
" -> \t" << value[index[
i]] << endl;
502 void PrintPPCuts(
int nevt_new,
int nevt_old,
int ncut,
double* cut_thr,
double rho_thr,
TString user_cut,
bool bppcuts,
bool beff,
bool bppcut) {
507 cout << endl <<
" PP cuts list ..." << endl << endl;
509 sprintf(sout,
"%*s %*s %*s %*s %*s %*s", 25,
"name", 5,
"cmp", 10,
"tuned", 10,
"mean", 14,
"mean-tuned", 12,
"increment");
510 cout << endl << sout << endl << endl;
511 for(
int i=0;
i<ncut;
i++) {
513 sprintf(sout,
"%*s %*s %*.2f %*.2f %*.2f %*.1f %s", 25,
gCUT_NAME[
i].Data(), 5,
gCUT_CMP[
i].Data(), 10, cut_thr[
i], 10,
gCUT_MEA[i], 14, cut_thr[i]-
gCUT_MEA[i], 10, dthr,
"%");
514 cout << sout << endl;
520 double dnevt = (nevt_new-nevt_old)/
double(nevt_old);
522 cout <<
" @ rho[1] > " << rho_thr <<
"\t -> nevt_new = " << nevt_new <<
"\t -> dnevt = " << 100.*dnevt <<
" %" << endl;
530 if(user_cut!=
"") cut = TString::Format(
" (%s)",user_cut.Data());
531 if(cut!=
"" && ncut>0) cut = cut +
" && ";
532 for(
int i=0;
i<ncut;
i++) {
533 TString sAND =
i==ncut-1 ?
"" :
"&&";
534 cut = cut + TString::Format(
"(%s%s%f)%s",
gCUT_NAME[
i].Data(),
gCUT_CMP[
i].Data(),cut_thr[
i],sAND.Data());
536 cout << endl << cut << endl << endl;
546 if((fp = fopen(ofname, mode)) == NULL ) {
547 cout <<
" DumpPPCuts error: cannot open file " << ofname <<
". \n";
557 if(!app)
fprintf(fp,
"\n%s\n\n",sout);
561 for(
int i=0;
i<ncut;
i++)
sprintf(sout,
"%s %*.4f",sout,15,cut_thr[
i]);
563 if(app)
fprintf(fp,
"%s\n",sout);
566 if(app && ncut==0)
fprintf(fp,
"\n");
579 if((fp = fopen(ofname, mode)) == NULL) {
580 cout <<
" DumpIncrementalDetectionsVsIFAR error: cannot open file " << ofname <<
". \n";
583 if(fp!=NULL)
fprintf(fp,
"\n\nDump incremental detections: tuned/standard vs IFAR\n\n");
589 double difar = (ifar_max-ifar_min)/
nIFAR;
592 cout <<
"Dump incremental detections: tuned/standard vs IFAR" << endl;
594 double ifar = ifar_min;
595 int gNBKG_save =
gNBKG;
603 double rho_thr_std, rho_thr_tuned;
605 int nevt_std =
GetSelectedEvents(tree_BKG, tree_SIM, bin_cut_standard.GetTitle(), 0, NULL, rho_thr_std);
608 if(nevt_std!=0 && nevt_tuned!=0) {
611 double dnevt = (nevt_tuned-nevt_std)/
double(nevt_std);
612 sprintf(sout,
" @ ifar = %.2f (@ rho(std)=%.2f -> %d bkg) -> nevt(std/tuned) = %d/%d (@ rho=%.2f) -> dnevt = %.2f %s", \
613 ifar, rho_thr_std,
gNBKG, nevt_std, nevt_tuned, rho_thr_tuned, 100.*dnevt,
"%");
614 cout << sout << endl;
615 if(fp!=NULL)
fprintf(fp,
"%s\n",sout);
633 double difar = (ifar_max-ifar_min)/
nIFAR;
635 bool check_dnevt=
true;
636 double ifar = ifar_min;
637 int gNBKG_save =
gNBKG;
645 double rho_thr_std, rho_thr_tuned;
647 int nevt_std =
GetSelectedEvents(tree_BKG, tree_SIM, bin_cut_standard.GetTitle(), 0, NULL, rho_thr_std);
650 if(nevt_std!=0 && nevt_tuned!=0) {
652 double dnevt = (nevt_tuned-nevt_std)/
double(nevt_std);
653 if(dnevt<0) check_dnevt=
false;
655 if(
gNBKG==1 || check_dnevt==
false)
break;
670 in->getline(str,1024);
671 if (!in->good())
break;
672 if(str[0] !=
'#' && str[0] !=
' ') size++;
674 in->clear(ios::goodbit);
675 in->seekg(0, ios::beg);
679 char xname[256], xcmp[256];
680 double xmean, xsigma, xmin, xmax;
683 cout << endl <<
" Input cut list ..." << endl;
685 sprintf(sout,
"%*s %*s %*s %*s %*s %*s %*s %*s", 3,
"id" , 25,
"name", 10,
"cmp", 10,
"mean", 10,
"sigma", 10,
"min", 10,
"max", 15,
"tune-enabled");
686 cout << endl << sout << endl << endl;
689 in->getline(str,1024);
690 if (!in->good())
break;
691 in->seekg(fpos, ios::beg);
692 *in >> xname >> xcmp >> xmean >> xsigma >> xmin >> xmax >> xenabled;
693 if(in->good() && !(xname[0] ==
'#' || xname[0]==
'\0' || xname[0] ==
' ')) {
697 sigma[ncut]= xenabled==0 ? 0 : xsigma;
700 sprintf(sout,
"%*d %*s %*s %*.2f %*.2f %*.2f %*.2f %*d", 3, ncut+1 , 25, xname, 10, xcmp, 10, xmean, 10, xsigma, 10, xmin, 10, xmax, 10, xenabled);
701 cout << sout << endl;
712 int entries = tree->GetEntries();
718 value[
i] =
new double[entries];
719 double*
val = tree->GetV1();
720 for(
int j=0;
j<entries;
j++) value[i][
j]=val[
j];
723 TPrincipal pca(gNCUT,
"ND");
726 for(
int i=0;
i<entries;
i++) {
732 TMatrixD* matrix = (TMatrixD*)pca.GetCovarianceMatrix();
736 TMatrixD nmatrix = *matrix;
737 for(
int i=0;
i<matrix->GetNrows();
i++) {
738 for(
int j=0;
j<matrix->GetNcols();
j++) {
739 nmatrix(
i,
j)/=sqrt((*matrix)(
i,
i) * (*matrix)(
j,
j));
747 matrix->Print(
"f= %11.0f");
749 matrix->Print(
"f= %11.3g");
753 cout <<
" list of loudest correlation (>30%) ... " << endl;
756 for(
int i=0;
i<matrix->GetNrows();
i++) {
757 for(
int j=0;
j<matrix->GetNcols();
j++) {
759 sprintf(sout,
" %*s vs %*s %*s = %*.2f %s", 35,
gCUT_NAME[
i].Data(), 15,
gCUT_NAME[
j].Data(), 15,
" -> correlation", 7, (*matrix)(
i,
j),
"%");
760 cout << sout << endl;
767 for(
int i=0;
i<
gNCUT;
i++)
delete [] value[
i];
detectorParams getDetectorParams()
double min(double x, double y)
network ** net
NOISE_MDC_SIMULATION.
fprintf(stdout,"start=%f duration=%f rate=%f\, x.start(), x.size()/x.rate(), x.rate())
TString sel("slag[1]:slag[2]")
double fabs(const Complex &x)
strcpy(RunLabel, RUN_LABEL)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)