Logo coherent WaveBurst  
Library Reference Guide
Logo
TreeTest_CTFmod.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Serena Vinciguerra
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 #define XIFO 4
20 
21 #pragma GCC system_header
22 
23 #include "cwb.hh"
24 #include "config.hh"
25 #include "network.hh"
26 #include "wavearray.hh"
27 #include "TString.h"
28 #include "TObjArray.h"
29 #include "TObjString.h"
30 #include "TPaletteAxis.h"
31 #include "TMultiLayerPerceptron.h"
32 #include "TMLPAnalyzer.h"
33 #include "TRandom.h"
34 #include "TComplex.h"
35 #include "TMath.h"
36 #include "mdc.hh"
37 #include "watplot.hh"
38 #include <vector>
39 
40 
41 /*
42  nn_otree->Branch("dt_corepixels",&dt,NPIX,0);
43  //char deltat_l[1024];
44  //sprintf(deltat_l,"dt_corepixels[%i]",NPIX);
45  //nn_otree->Branch("dt_corepixels",&deltat,deltat_l);
46  nn_otree->Branch("index",&ind,"ind/I");
47  nn_otree->Branch("t_duration",&dT,"duration/D");
48  nn_otree->Branch("f_duration",&dF,"f_duration/D");
49  nn_otree->Branch("central_f",&Fc,"central_f/D");
50 
51 */
52 
53 
54 
55 //#define differentW
56 
57 //#define SIG_FILE "/home/serena.vinciguerra/test0/S6D_R11_SIM_EOBNRv2_advL1H1V1_2G_run1_2/merge/NN_wave_S6D_R11_SIM_EOBNRv2_advL1H1V1_2G_run1_2.M1.root"
58 //#define BG_FILE "/home/serena.vinciguerra/test0/S6D_R11_BKG_L1H1V1_2G_MP_run1/merge/NN_wave_S6D_R11_BKG_L1H1V1_2G_MP_run1.M1.root"
59 #define nIFO 3
60 #define NPIX 20
61 using namespace std;
62 
63 void TreeTest_CTFmod(TString ifileS,TString ifileB,TString ofile,int const y=1, int const NDIM=8,int const nINP=64){
64 
65 
66 /*if(ifileS!=0)
67 //{
68  // SIGNAL
69  TChain TreeS("waveburst");//cerca il Tree "waveburst nei file
70  TreeS.Add(ifileS.Data());//determina i file
71  netevent entryS(&TreeS,nIFO);
72  int entriesS = entryS.GetEntries();
73  cout << "Sig entries : " << entriesS << endl;
74  std::vector<double>* frameS = new vector<double>;
75  entryS.fChain->SetBranchAddress("nnframe", &frameS);//fa esattamente come ha fatto per le altre variabili nella macro netevent.cc
76 //}
77 
78 //if(ifileB!=0)
79 //{
80 
81  TChain TreeB("waveburst");//cerca il Tree "waveburst nei file
82  TreeB.Add(ifileB.Data());//determina i file
83  netevent entryB(&TreeB,nIFO);
84  int entriesB = entryB.GetEntries();
85  cout << "Bg entries : " << entriesB << endl;
86  std::vector<double>* frameB = new vector<double>;
87  entryB.fChain->SetBranchAddress("nnframe", &frameB);//fa esattamente come ha fatto per le altre variabili nella macro netevent.cc
88 // }
89 */
90 
91  //cout<<"frame "<<(*frame)[0]<<endl;
92  TTree* nnTree2 = new TTree ("nnTree","nnTree");
93 // netevent nn(Tree,nIFO);
94  nnTree2->SetDirectory(0);
95 
96  // add leaf
97  Int_t type;
98  float s[nINP];
99  Float_t x[nINP];
100  for (int jj=0; jj<nINP;jj++) x[jj]=0.;
101  char ilabel[nINP][16];
102  double dt[NPIX];
103  for (int jj=0; jj<NPIX;jj++) dt[jj]=0.;
104  char ilabeldt[NPIX][16];
105  double dT=0.;
106  double Fc=0.;
107  double dF=0.;
108 
109  //costruzione una foglia per ogni input
110  for(int i=0;i<nINP;i++) {
111  sprintf(ilabel[i],"x%i",i+1);
112  char tlabel[16]; sprintf(tlabel,"x%i/F",i+1);
113  nnTree2->Branch(ilabel[i], &x[i], tlabel);
114  }
115 
116 //costruzione una foglia per ogni dt
117  for(int i=0;i<NPIX;i++) {
118  sprintf(ilabeldt[i],"dt%i",i+1);
119  char tlabeldt[16]; sprintf(tlabeldt,"dt%i/D",i+1);
120  nnTree2->Branch(ilabeldt[i], &dt[i], tlabeldt);
121  }
122 //add info time-frequncy plane
123  nnTree2->Branch("duration", &dT, "duration/D");
124  nnTree2->Branch("frequency_width", &dF, "frequency_width/D");
125  nnTree2->Branch("central_frequency", &Fc, "central_frequency/D");
126 
127 
128  //costruzione foglie peso e tipo
129  nnTree2->Branch("type",&type,"type/I");
130  int yi=0;
131  yi=y;
132  int nDim=0;
133  nDim=NDIM;
134  int nInp=0;
135  nInp=nINP;
136 int index=0;
137 int entriesTot=0;
138  nnTree2->Branch("amplitude_mode",&yi,"amplitude_mode/I");
139  nnTree2->Branch("Matrix_dim",&nDim,"Matrix_dim/I");
140  nnTree2->Branch("#inputs",&nInp,"#inputs/I");
141  nnTree2->Branch("index",&index,"index/I");
142  nnTree2->Branch("#Entries_type",&entriesTot,"#Entries_type/I");
143 char fname[516];
144  nnTree2->Branch("Files_name",&fname,"Files_name/C");
145 
146 #ifdef differentW
147  char wlabel[nINP][16];
148  float w[nINP];
149  for(int i=0;i<nINP;i++) {
150  sprintf(wlabel[i],"w%d",i+1);
151  char llabel[16]; sprintf(llabel,"w%d/F",i+1);
152  nnTree2->Branch(ilabel[i], &w[i], tlabel);
153  w[i]=1;
154  }
155 
156 #else
157  float w;
158  nnTree2->Branch("w",&w,"w/F");
159  w=1;
160 #endif
161 
162 cout<<"fine definizione foglie"<<endl;
163 if(ifileS!=0)
164 {
165  TChain TreeS("waveburst");//cerca il Tree "waveburst nei file
166  TreeS.Add(ifileS.Data());//determina i file
167  netevent entryS(&TreeS,nIFO);
168  entriesTot = entryS.GetEntries();
169  cout << "Sig entries : " << entriesTot << endl;
170  std::vector<double>* frameS = new vector<double>;
171  entryS.fChain->SetBranchAddress("nnframe", &frameS);//fa esattamente come ha fatto per le altre variabili nella macro netevent.cc
172  std::vector<double>* dtvS = new vector<double>;
173  entryS.fChain->SetBranchAddress("dt_corepixels", &dtvS);//fa esattamente come ha fatto per le altre variabili nella macro netevent.cc
174 
175  double dTS;
176  double dFS;
177  double FcS;
178 
179  entryS.fChain->SetBranchAddress("t_duration", &dTS);//fa esattamente come ha fatto per le altre variabili nella macro netevent.cc
180  entryS.fChain->SetBranchAddress("f_duration", &dFS);//fa esattamente come ha fatto per le altre variabili nella macro netevent.cc
181  entryS.fChain->SetBranchAddress("central_f", &FcS);//fa esattamente come ha fatto per le altre variabili nella macro netevent.cc
182 
183  type = 1;
184  sprintf(fname,"%s",ifileS.Data());
185  cout<<fname<<endl;
186  for(int n=0;n<entryS.GetEntries();n++) {
187  TreeS.GetEntry(n);
188  dT=dTS;
189  dF=dFS;
190  Fc=FcS;
191  for (int j=0;j<NPIX;j++) dt[j]=(*dtvS)[j];
192  for (int j=0;j<nINP;j++)
193  //for (int j=0;j<nINP;j++)
194  { if(yi==0){
195  if((*frameS)[j]>0.001) x[j]=1;
196  else x[j]=0;
197  }
198  //else x[j]=frameS->at(j);
199  else x[j]=(*frameS)[j];
200  }
201  index=index+1;
202  nnTree2->Fill();
203  }
204 }
205 cout<<"Fine ciclo sul segnale"<<endl;
206 if(ifileB!=0)
207  {
208  TChain TreeB("waveburst");//cerca il Tree "waveburst nei file
209  TreeB.Add(ifileB.Data());//determina i file
210  netevent entryB(&TreeB,nIFO);
211  entriesTot = entryB.GetEntries();
212  cout << "Bg entries : " << entriesTot << endl;
213  std::vector<double>* frameB = new vector<double>;
214  entryB.fChain->SetBranchAddress("nnframe", &frameB);//fa esattamente come ha fatto per le altre variabili nella macro netevent.cc
215  std::vector<double>* dtvB = new vector<double>;
216  entryB.fChain->SetBranchAddress("dt_corepixels", &dtvB);//fa esattamente come ha fatto per le altre variabili nella macro netevent.cc
217 
218  double dTB;
219  double dFB;
220  double FcB;
221 
222  entryB.fChain->SetBranchAddress("t_duration", &dTB);//fa esattamente come ha fatto per le altre variabili nella macro netevent.cc
223  entryB.fChain->SetBranchAddress("f_duration", &dFB);//fa esattamente come ha fatto per le altre variabili nella macro netevent.cc
224  entryB.fChain->SetBranchAddress("central_f", &FcB);//fa esattamente come ha fatto per le altre variabili nella macro netevent.cc
225 
226  type = 0;
227  sprintf(fname,"%s",ifileB.Data());
228  cout<<fname<<endl;
229  for(int n=0;n<entryB.GetEntries();n++) {
230  TreeB.GetEntry(n);
231  dT=dTB;
232  dF=dFB;
233  Fc=FcB;
234  for (int j=0;j<NPIX;j++) dt[j]=(*dtvB)[j];
235  for (int j=0;j<nINP;j++)
236  //for (int j=0;j<nINP;j++)
237  { if(yi==0){
238  if((*frameB)[j]>0.001) x[j]=1;
239  else x[j]=0;
240  }
241  //else x[j]=frameB->at(j);
242  else x[j]=(*frameB)[j];
243  }
244  index=index+1;
245  nnTree2->Fill();
246  }
247 }
248 cout<<"fine ciclo sul Bg"<<endl;
249 //SAVE THE TREE
250 /*
251 TString ofileS(ifileS.Data());
252 ofileS.ReplaceAll(".root","_nnTree");
253 TString ofileB(ifileB.Data());
254 ofileB.ReplaceAll(".root","_nnTree");
255 */
256 char nomefile[516];
257 sprintf(nomefile,"nnTREE/nnTree_%s.root",ofile.Data());
258 //char nomefile[516]="nnTREE/nnTree_S6D_and_SIM0run3.root";
259 TFile* f=new TFile(nomefile,"RECREATE");
260 nnTree2->Write();
261 f->Close();
262 
263 }
char ofile[1024]
int n
Definition: cwb_net.C:28
TString("c")
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
STL namespace.
void TreeTest_CTFmod(TString ifileS, TString ifileB, TString ofile, int const y=1, int const NDIM=8, int const nINP=64)
TTree * fChain
root input file cointainig the analyzed TTree
Definition: netevent.hh:63
int j
Definition: cwb_net.C:28
i drho i
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
Definition: ComputeSNR.C:75
wavearray< double > w
Definition: Test1.C:27
char fname[1024]
double dt
s s
Definition: cwb_net.C:155
#define nIFO
wavearray< int > index
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
double dT
Definition: testWDM_5.C:12
Int_t GetEntries()
Definition: netevent.cc:403
#define NPIX
wavearray< double > y
Definition: Test10.C:31