Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DrawInspiralFeatures.C
Go to the documentation of this file.
1 {
2  //
3  // Show how to use Toolbox to get signal envelop / instantaneous frequency, WignerVille Transform, ...
4  // Author : Gabriele Vedovato
5 
6  #define DRAW_WIGNER_VILLE
7  //#define DRAW_IFREQUENCY
8  //#define DRAW_ENVELOPE
9  //#define DRAW_ENVELOPE_EXTREME
10  //#define DRAW_FREQUENCY_EXTREME
11 
12 
13  #include <vector>
14 
15  CWB::mdc MDC;
16 
17  // ---------------------------------
18  // set inspiral parms
19  // ---------------------------------
21  inspOptions = "--time-step 60.0 --time-interval 3 ";
22  inspOptions+= "--dir . ";
23  inspOptions+= "--l-distr random ";
24  inspOptions+= "--gps-start-time 931072130 --gps-end-time 933491330 ";
25  inspOptions+= "--d-distr volume --m-distr totalMassRatio --i-distr uniform ";
26  inspOptions+= "--f-lower 10.000000 ";
27  inspOptions+= "--min-mass1 25.000000 --max-mass1 225.000000 ";
28  inspOptions+= "--min-mass2 25.000000 --max-mass2 225.000000 ";
29  inspOptions+= "--min-mtotal 50.000000 --max-mtotal 250.000000 ";
30  inspOptions+= "--min-mratio 0.25 --max-mratio 1.000000 ";
31  inspOptions+= "--min-distance 1000000.0 --max-distance 1500000.0 ";
32  inspOptions+= "--approximant EOBNRv2pseudoFourPN --disable-spin ";
33  inspOptions+= "--taper-injection start --seed 123456789 ";
34  inspOptions+= "--output inspirals.xml "; // set output xml file
35 
36  // set and write xml file
37  MDC.SetInspiral("EOBNRv2",inspOptions);
38 
39  // set inspiral using xml file (speedup GetInspiral method)
40  TString inspOptions="--xml inspirals.xml";
41  MDC.SetInspiral("EOBNRv2",inspOptions);
42 
43  // Get the first waveform hp,hx components starting from gps = 931072130
44  wavearray<double> hp = MDC.GetInspiral("hp",931072130,931072230);
45  wavearray<double> hx = MDC.GetInspiral("hx",931072130,931072230);
46  cout << "size : " << hp.size() << " rate : " << hp.rate() << " start : " << (int)hp.start() << endl;
47  hp.start(0); // set start to 0 (needed by draw Method)
48  hx.start(0);
49  MDC.Draw(hp,MDC_TIME);
50  //MDC.Draw(hx,MDC_TIME,"same",kRed);
51 
52  //MDC.Draw(hp,MDC_FFT); // draw hp in frequency domain
53  //MDC.Draw(hp,MDC_TF); // draw hp in time-frequency domain;
54 
55 #ifdef DRAW_ENVELOPE
56  // Get hp envelope
58  MDC.Draw(ehp,MDC_TIME,"same",kRed);
59 #endif
60 
61 #ifdef DRAW_IFREQUENCY
62  // Get hp instantaneous frequency
64  MDC.Draw(fhp,MDC_TIME);
65 #endif
66 
67 #ifdef DRAW_WIGNER_VILLE
68  // draw Wigner-Ville transform
69  wavearray<double> xhp(hp.size()/64);
70  xhp.rate(hp.rate()/64); xhp.start(hp.start());
71  for(int i=0;i<xhp.size();i++) xhp[i]=hp[i*64]; // decimated hp
73  int N = sqrt(wvhp.size());
74  double dt = 1./wvhp.rate();
75  double df = wvhp.rate()/N;
76 
77  TH2D* h2 = new TH2D("h2","h2",N,0,N*dt,N,0,N*df);
78  h2->SetStats(kFALSE);
79  h2->SetTitle("Wigner Ville Transform");
80  h2->GetXaxis()->SetTitle("Time (sec)");
81  h2->GetYaxis()->SetTitle("freq (Hz)");
82 
83  for(int n=0; n<N; n++) {
84  for(int m=0; m<N; m++) {
85  if(wvhp[n*N+m]>0) h2->Fill(m*dt,n*df,wvhp[n*N+m]);
86  }
87  }
88 
89  h2->Draw("colz");
90 #endif
91 
92  // Draw envelope/frequency extreme of signal
93  wavearray<double> t(hp.size());
94  wavearray<double> f(hp.size());
95  wavearray<double> a(hp.size());
96  int size=0;
97  double dt = 1./hp.rate();
99  for (int i=1;i<hp.size()-1;i++) {
101  if((amplitude!=0)&&(omega!=0)) {
102  t[size]=dt*(i-1)-(phase/omega);
103  a[size]=fabs(amplitude);
104  f[size]=omega/TMath::TwoPi();
105  size++;
106  }
107  }
108 
109 #ifdef DRAW_ENVELOPE_EXTREME
110  TGraph* agr = new TGraph(size,t.data,a.data);
111  agr->SetLineColor(kBlue);
112  agr->SetMarkerColor(kBlue);
113  agr->SetMarkerStyle(20);
114  agr->SetMarkerSize(1);
115  fgr->SetTitle("Envelope");
116  agr->GetHistogram()->GetXaxis()->SetTitle("Time (sec)");
117  agr->GetHistogram()->GetYaxis()->SetTitle("amplitude (Hz)");
118  //agr->Draw("ALP");
119  agr->Draw("SAME");
120 #endif
121 
122 #ifdef DRAW_FREQUENCY_EXTREME
123  TGraph* fgr = new TGraph(size,t.data,f.data);
124  fgr->SetLineColor(kRed);
125  fgr->SetMarkerColor(kRed);
126  fgr->SetMarkerStyle(20);
127  fgr->SetMarkerSize(1);
128  fgr->SetTitle("Frequency");
129  fgr->GetHistogram()->GetYaxis()->SetRangeUser(0,256);
130  fgr->GetHistogram()->GetXaxis()->SetTitle("Time (sec)");
131  fgr->GetHistogram()->GetYaxis()->SetTitle("freq (Hz)");
132  fgr->Draw("ALP");
133  //fgr->Draw("SAME");
134 #endif
135 
136 }
wavearray< double > t(hp.size())
virtual size_t size() const
Definition: wavearray.hh:127
Definition: mdc.hh:172
double omega
static wavearray< double > getWignerVilleTransform(wavearray< double > x)
Definition: Toolbox.cc:6187
watplot * Draw(TString name, int id=0, TString polarization="hp", MDC_DRAW type=MDC_TIME, TString options="ALP", Color_t color=kBlack)
Definition: mdc.cc:2288
wavearray< double > hp
cout<< "size : "<< hp.size()<< " rate : "<< hp.rate()<< " start : "<< (int) hp.start()<< endl;hp.start(0);hx.start(0);MDC.Draw(hp, MDC_TIME);wavearray< double > xhp(hp.size()/64)
virtual void rate(double r)
Definition: wavearray.hh:123
wavearray< double > a(hp.size())
int n
Definition: cwb_net.C:10
TString("c")
double phase
wavearray< double > hx
CWB::mdc * MDC
static wavearray< double > getHilbertIFrequency(wavearray< double > x)
Definition: Toolbox.cc:6151
int m
Definition: cwb_net.C:10
virtual void start(double s)
Definition: wavearray.hh:119
i drho i
#define N
TString inspOptions
Definition: mdc.hh:216
i() int(T_cor *100))
int size
double dt
double fabs(const Complex &x)
Definition: numpy.cc:37
double df
wavearray< double > f(hp.size())
static void getSineFittingParams(double a, double b, double c, double rate, double &amplitude, double &omega, double &phase)
Definition: Toolbox.cc:6281
DataType_t * data
Definition: wavearray.hh:301
double amplitude
static wavearray< double > getHilbertEnvelope(wavearray< double > x)
Definition: Toolbox.cc:6131