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 TH1F* his = Getwf(i, GetEventIndex(eventnr));
34
35 for (int j = 0; j < size; j++) {
36 if (j < binNumber) yvals[j] = his->GetBinContent(j + 1);
37 else yvals[j] = 0.;
38 }
39
40 TVirtualFFT* ffthis = TVirtualFFT::FFT(1, &size, "R2C ES");
41 ffthis->SetPoints(yvals);
42 ffthis->Transform();
43 ffthis->GetPointsComplex(refft, imfft);
44
45 TGraph* re = new TGraph(size, xvals, refft);
46 TGraph* im = new TGraph(size, xvals, imfft);
47
48 // draw to canvas
49 fftc->cd(i + 1);
50 stringstream renamess; renamess << "Channel " << active_channels[i] << ", event " << eventnr << ", Re(FFT(data))";
51 re->SetTitle(renamess.str().c_str());
52 re->Draw("AL");
53 gPad->Modified();
54 if (xmin != 0. || xmax != 0.) re->GetXaxis()->SetLimits(xmin, xmax);
55 //re->GetYaxis()->SetRangeUser(-1*size, size);
56
57 imfftc->cd(i + 1);
58 stringstream imnamess; imnamess << "Channel " << active_channels[i] << ", event " << eventnr << ", Im(FFT(data))";
59 im->SetTitle(imnamess.str().c_str());
60 im->Draw("AL");
61 gPad->Modified();
62 if (xmin != 0. || xmax != 0.) im->GetXaxis()->SetLimits(xmin, xmax);
63 //im->GetYaxis()->SetRangeUser(-1*size, size);
64
65 delete ffthis;
66 }
67 fftc->Update();
68 imfftc->Update();
69
70 root_out->WriteObject(fftc, name.Data());
71 root_out->WriteObject(imfftc, imname.Data());
72
73 delete[] yvals;
74 delete[] refft;
75 delete[] imfft;
76 delete[] xvals;
77}
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:97
TH1F * Getwf(int)
Helper that returns the waveform histogram for a certain waveform number number.
Definition ReadRun.cc:2547
vector< int > active_channels
Stores the numbers of the active channels.
Definition ReadRun.h:290
int GetEventIndex(unsigned int)
Returns index of a certain event number (if data files are read in parallel threads)
Definition ReadRun.cc:2597
TFile * root_out
Stores results of analysis.
Definition ReadRun.h:338
int binNumber
Number of bins (always 1024 samples per waveform). Do not change!
Definition ReadRun.h:280
int nchannels
Number of active channels in data.
Definition ReadRun.h:265
float SP
Sampling: ns per bin of data, sampling rate 3.2 GS/s -> 0.3125 ns.
Definition ReadRun.h:274
vector< int > plot_active_channels
Stores the numbers of the active channels which should be plotted.
Definition ReadRun.h:295