WaveformGraph.cxx
1 #include "WaveformGraph.h"
2 #include "CorrelationFactory.h"
3 #include "TButton.h"
4 #include "TList.h"
5 #include "TCanvas.h"
6 #include "TStyle.h"
7 #include "TAxis.h"
8 #include <iostream>
9 using namespace std;
10 
11 #include "FFTtools.h"
12 
13 static Int_t zoomCounter=0;
14 
15 ClassImp(WaveformGraph);
16 
18 
19  : TGraph(),fNewCanvas(0)
20 
21 {
22  this->SetEditable(kFALSE);
23 }
24 
25 
26 WaveformGraph::WaveformGraph(int N, const Int_t *x, const Int_t *y)
27 
28  : TGraph(N,x,y),fNewCanvas(0)
29 {
30  this->SetEditable(kFALSE);
31 }
32 
33 WaveformGraph::WaveformGraph(int N, const Float_t *x, const Float_t *y)
34 
35  : TGraph(N,x,y),fNewCanvas(0)
36 {
37  this->SetEditable(kFALSE);
38 }
39 
40 WaveformGraph::WaveformGraph(int N, const Double_t *x, const Double_t *y)
41 
42  : TGraph(N,x,y),fNewCanvas(0)
43 {
44  this->SetEditable(kFALSE);
45 }
46 
48 {
49  // std::cout << "~WaveformGraph" << std::endl;
50 }
51 
52 void WaveformGraph::ExecuteEvent(Int_t event, Int_t px, Int_t py)
53 {
54  static int keyWasPressed=0;
55  switch (event) {
56  case kKeyPress:
57  // std::cout << "kKeyPress" << std::endl;
58  keyWasPressed=1;
59  break;
60  case kButtonPress:
61  // cout << "kButtonPress" << endl;
62  break;
63 
64  case kButton1Double:
65  // std::cout << "kButtonDoubleClick" << std::endl;
66  // new TCanvas();
67  break;
68 
69  case kButton1Down:
70  // std::cout << "kButton1Down" << std::endl;
71  if(!keyWasPressed) {
72  if(!fNewCanvas) drawInNewCanvas();
73  else this->TGraph::ExecuteEvent(event,px,py);
74  }
75  else {
76  // std::cout << "ctrl + click\n";
78  keyWasPressed=0;
79  }
80 
81  break;
82 
83  default:
84  this->TGraph::ExecuteEvent(event,px,py);
85  break;
86  }
87 }
88 
89 void WaveformGraph::drawInNewCanvas()
90 {
91  char graphTitle[180];
92  char graphName[180];
93  gStyle->SetTitleH(0.1);
94  gStyle->SetOptTitle(1);
95  gStyle->SetPadLeftMargin(0.15);
96  gStyle->SetPadRightMargin(0.1);
97  gStyle->SetPadTopMargin(0.1);
98  gStyle->SetPadBottomMargin(0.1);
99  gStyle->SetCanvasDefW(600);
100  gStyle->SetCanvasDefH(400);
101  // gROOT->ForceStyle();
102  WaveformGraph *thisCopy = (WaveformGraph*)this->Clone();
103  thisCopy->GetXaxis()->SetLabelSize(0.06);
104  thisCopy->GetXaxis()->SetTitleSize(0.06);
105  thisCopy->GetYaxis()->SetLabelSize(0.06);
106  thisCopy->GetYaxis()->SetTitleSize(0.06);
107  thisCopy->GetXaxis()->SetTitle("Time (ns)");
108  thisCopy->GetYaxis()->SetTitle("Voltage (mV-ish)");
109 
110 
111  if(fChan!=8) {
112  sprintf(graphTitle,"Ant %d%c%c (%s Ring -- Phi %d -- SURF %d -- Chan %d)",
114 
115  }
116  else {
117  sprintf(graphTitle,"Clock SURF %d -- Chan %d",fSurf+1,fChan+1);
118  }
119  sprintf(graphName,"grZoom%d",zoomCounter++);
120  thisCopy->SetName(graphName);
121  thisCopy->SetTitle(graphTitle);
122  // std::cout << graphName << "\t" << graphTitle << "\n";
123  TCanvas *can = new TCanvas();
124  can->SetLeftMargin(0.15);
125  can->SetBottomMargin(0.15);
126  can->SetTopMargin(0.1);
127  can->SetRightMargin(0.1);
128  thisCopy->Draw("al");
129  int numPoints=thisCopy->GetN();
130  can->Modified();
131  can->Update();
132 
133 
134  // fNewCanvas=1;
135 
136 }
137 
138 //______________________________________________________________________________
140 {
141  char graphTitle[180];
142  gStyle->SetTitleH(0.1);
143  gStyle->SetLabelSize(0.1,"xy");
144  gStyle->SetTitleSize(0.1,"xy");
145  gStyle->SetTitleOffset(0.5,"y");
146  gStyle->SetOptTitle(1);
147  gStyle->SetCanvasDefW(600);
148  gStyle->SetCanvasDefH(400);
149  // gROOT->ForceStyle();
150 
151  TCanvas *can = new TCanvas();
152  can->SetLeftMargin(0.15);
153  can->SetBottomMargin(0.15);
154  can->SetTopMargin(0.1);
155  can->SetRightMargin(0.1);
156 
157  TGraph *grFFT = this->getFFT();
158  grFFT->GetXaxis()->SetLabelSize(0.06);
159  grFFT->GetXaxis()->SetTitleSize(0.06);
160  grFFT->GetYaxis()->SetLabelSize(0.06);
161  grFFT->GetYaxis()->SetTitleSize(0.06);
162  grFFT->GetXaxis()->SetTitle("Frequency (MHz)");
163  grFFT->GetYaxis()->SetTitle("dB (m maybe)");
164 
165  if(fChan!=8) {
166  sprintf(graphTitle,"Ant %d%c%c (%s Ring -- Phi %d -- SURF %d -- Chan %d)",
168  }
169  else {
170  sprintf(graphTitle,"Clock SURF %d -- Chan %d",fSurf+1,fChan+1);
171  }
172 
173  grFFT->SetTitle(graphTitle);
174  grFFT->Draw("al");
175 
176  // printf("WaveformGraph::DrawFFT: not yet implemented\n");
177 }
178 
179 //______________________________________________________________________________
180 void WaveformGraph::DrawHilbert()
181 {
182  char graphTitle[180];
183  gStyle->SetTitleH(0.1);
184  gStyle->SetLabelSize(0.1,"xy");
185  gStyle->SetTitleSize(0.1,"xy");
186  gStyle->SetTitleOffset(0.5,"y");
187  gStyle->SetOptTitle(1);
188  gStyle->SetCanvasDefW(600);
189  gStyle->SetCanvasDefH(400);
190  // gROOT->ForceStyle();
191 
192  TCanvas *can = new TCanvas();
193  can->SetLeftMargin(0.15);
194  can->SetBottomMargin(0.15);
195  can->SetTopMargin(0.1);
196  can->SetRightMargin(0.1);
197 
198  TGraph *grHilbert = this->getHilbert();
199  grHilbert->GetXaxis()->SetLabelSize(0.06);
200  grHilbert->GetXaxis()->SetTitleSize(0.06);
201  grHilbert->GetYaxis()->SetLabelSize(0.06);
202  grHilbert->GetYaxis()->SetTitleSize(0.06);
203  grHilbert->GetXaxis()->SetTitle("Time (ns)");
204  grHilbert->GetYaxis()->SetTitle("Voltage^2 (mv^2) ");
205  if(fChan!=8) {
206 
207  sprintf(graphTitle,"Ant %d%c%c (%s Ring -- Phi %d -- SURF %d -- Chan %d)",
209  }
210  else {
211  sprintf(graphTitle,"Clock SURF %d -- Chan %d",fSurf+1,fChan+1);
212  }
213  grHilbert->SetTitle(graphTitle);
214  grHilbert->Draw("al");
215 
216  // printf("WaveformGraph::DrawFFT: not yet implemented\n");
217 }
218 
220 {
221  Double_t newX[248],newY[248];
222  TGraph *grInt = FFTtools::getInterpolatedGraph(this,1./2.6);
223  Int_t numSamps=grInt->GetN();
224  Double_t *xVals=grInt->GetX();
225  Double_t *yVals=grInt->GetY();
226  for(int i=0;i<248;i++) {
227  if(i<numSamps) {
228  newX[i]=xVals[i];
229  newY[i]=yVals[i];
230  }
231  else {
232  newX[i]=newX[i-1]+(1./2.6);
233  newY[i]=0;
234  }
235  }
236  TGraph *grNew = new TGraph(248,newX,newY);
237  TGraph *grFFT = FFTtools::makePowerSpectrumMilliVoltsNanoSecondsdB(grNew);
238  delete grNew;
239  delete grInt;
240  return grFFT;
241 }
242 
243 
245 {
246  TGraph *grInt = FFTtools::getInterpolatedGraph(this,1./2.6);
247  TGraph *grHilbert = FFTtools::getHilbertEnvelope(grInt);
248  delete grInt;
249  return grHilbert;
250 }
251 
252 void WaveformGraph::AddToCorrelation()
253 {
255 }
TGraph * getHilbert()
Returns a pointer to a TGraph containing the hilbert envelope of the waveform.
TGraph * getFFT()
Returns a pointer to a TGraph containing the PSD of the waveform.
TGraph * getHilbertEnvelope(const TGraph *grWave)
The Hilbert envelope of the input TGraph. This is defined as e_i=sqrt(v_i^2 + h_i^2), where e_i, v_i and h_i are the i-th sample of the envelope, input graph and hilbert transform of the input graph repsectively.
Definition: FFTtools.cxx:964
AnitaPol::AnitaPol_t fPol
Used in labelling.
Definition: WaveformGraph.h:42
AnitaRing::AnitaRing_t fRing
Used in labelling.
Definition: WaveformGraph.h:41
char ringAsChar(AnitaRing::AnitaRing_t ring)
Returns the ring as a character string.
STL namespace.
static CorrelationFactory * Instance()
Instance generator.
TGraph * getInterpolatedGraph(const TGraph *grIn, Double_t deltaT)
Interpolation Routines that use ROOT::Math::Interpolator.
Definition: FFTtools.cxx:32
const char * ringAsString(AnitaRing::AnitaRing_t ring)
Returns the ring as a character string.
The graph class that inherits from ROOT&#39;s TGraph.
Definition: WaveformGraph.h:14
Int_t fChan
Used in labelling.
Definition: WaveformGraph.h:38
void DrawFFT()
Draws the PSD of the waveform in a new window (NB: It is the MENU desigination that ROOT uses to add ...
virtual ~WaveformGraph()
Destructor.
WaveformGraph()
Constructor.
Int_t fPhi
Used in labelling.
Definition: WaveformGraph.h:39
char polAsChar(AnitaPol::AnitaPol_t pol)
Returns the polarisation as a character string.
void addWaveformToCorrelation(WaveformGraph *inputWave)
Adds a a waveform to the correlation.
Int_t fSurf
Used in labelling.
Definition: WaveformGraph.h:37