wavecatcher-analysis
Loading...
Searching...
No Matches
FFT_WF.cc
Go to the documentation of this file.
1#include "FFT_WF.h"
2
11void FFT_WF::PrintFFTWF(int eventnr, float xmin, float xmax, int multiplier) {
12 // plot waveforms of all channels for a given event number eventnr and add the determined integration windows to the plot
13 TString name(Form("fft_waveforms_event__%04d", eventnr));
14 TCanvas* fftc = new TCanvas(name.Data(), name.Data(), 600, 400);
16
17 TString imname(Form("fft_im_waveforms_event__%04d", eventnr));
18 TCanvas* imfftc = new TCanvas(imname.Data(), imname.Data(), 600, 400);
20
21 int size = binNumber * multiplier;
22 double* xvals = new double[size];
23 for (int i = 0; i < size; i++) {
24 xvals[i] = static_cast<double>(i) / (SP * static_cast<double>(size));
25 }
26
27 double* refft = new double[size];
28 double* imfft = new double[size];
29
30 double* yvals = new double[size]{};
31
32 for (int i = 0; i < nchannels; i++) {
33 int wf_index = GetWaveformIndex(eventnr, i);
34
35 for (int j = 0; j < binNumber; j++) yvals[j] = static_cast<double>(rundata[wf_index][j]);
36
37 TVirtualFFT* ffthis = TVirtualFFT::FFT(1, &size, "R2C ES");
38 ffthis->SetPoints(yvals);
39 ffthis->Transform();
40 ffthis->GetPointsComplex(refft, imfft);
41
42 TGraph* re = new TGraph(size, xvals, refft);
43 TGraph* im = new TGraph(size, xvals, imfft);
44
45 // draw to canvas
46 fftc->cd(i + 1);
47 stringstream renamess; renamess << "Channel " << active_channels[i] << ", event " << eventnr << ", Re(FFT(data))";
48 re->SetTitle(renamess.str().c_str());
49 re->Draw("AL");
50 gPad->Modified();
51 if (xmin != 0. || xmax != 0.) re->GetXaxis()->SetLimits(xmin, xmax);
52 //re->GetYaxis()->SetRangeUser(-1*size, size);
53
54 imfftc->cd(i + 1);
55 stringstream imnamess; imnamess << "Channel " << active_channels[i] << ", event " << eventnr << ", Im(FFT(data))";
56 im->SetTitle(imnamess.str().c_str());
57 im->Draw("AL");
58 gPad->Modified();
59 if (xmin != 0. || xmax != 0.) im->GetXaxis()->SetLimits(xmin, xmax);
60 //im->GetYaxis()->SetRangeUser(-1*size, size);
61
62 delete ffthis;
63 }
64 fftc->Update();
65 imfftc->Update();
66
67 root_out->WriteObject(fftc, name.Data());
68 root_out->WriteObject(imfftc, imname.Data());
69
70 delete[] yvals;
71 delete[] refft;
72 delete[] imfft;
73 delete[] xvals;
74}
void PrintFFTWF(int=1, float=0., float=0., int=1)
Print Fourier transform of waveforms.
Definition FFT_WF.cc:11
static void SplitCanvas(TCanvas *&, vector< int >, vector< int >)
Helper to split canvas according to the number of channels to be plotted.
Definition Helpers.cc:121
vector< int > active_channels
Stores the numbers of the active channels.
Definition ReadRun.h:311
vector< vector< float > > rundata
Stores waveforms.
Definition ReadRun.h:132
TFile * root_out
Stores results of analysis.
Definition ReadRun.h:360
virtual int GetWaveformIndex(int, int)
Returns index of a certain event number (if data files are read in parallel threads)
Definition ReadRun.cc:2763
int binNumber
Number of bins (usually 1024 samples per waveform).
Definition ReadRun.h:301
int nchannels
Number of active channels in data.
Definition ReadRun.h:284
float SP
Sampling: ns per bin of data, sampling rate 3.2 GS/s -> 0.3125 ns.
Definition ReadRun.h:293
vector< int > plot_active_channels
Stores the numbers of the active channels which should be plotted.
Definition ReadRun.h:316