#include "TObject.h" // define the Scope class and make it inherit from TObject so that we can write // Scope to a ROOT file class Scope : public TObject { private: Int_t nentries; TBranch *b_voltagesI; TBranch *b_voltagesQ; TBranch *b_timestamps; TFile *f = 0; TTree *T = 0; public: Double_t NoisePower; Double_t NoisePowerDensity[10000]; // Array dimension must be as large as MemDepth Double_t RMSVoltage; void Print() const; void Read(), GetNoisePower(), FFTScopeTraces(), PlotOneScopeTrace(), PlotNoiseTemperature(), PlotJustNoiseTemperature(), PlotNoiseTemperatureFull(), PlotSomething(); void CloseFileandTree(); void Scope::Scope() { printf("testing Scope init\n"); } void Scope::Print() const { printf("Scope says hi\n");} void Scope::FFTScopeTraces(){ printf("FFTScopeTraces is called\n"); Double_t voltages[20000]; // Must be 2x as large as MemDepth this->Read(); b_voltagesI->SetAddress(voltages); nentries = (Int_t)b_voltagesI->GetEntries(); //nentries = 100; printf("fftscopetraces says fs is %f\n", Fs); TH1D *hscopetrace = new TH1D("hscopetrace", "Scope Trace; channels; Volts", (int)NBins, 0., NBins); TH1 *hm_tot=0; hm_tot = hscopetrace->FFT(hm_tot, "MAG_AVG"); for (Int_t i=0;iGetEntry(i); // fill the histogram with the voltages for (Int_t j=0; j<(int)NBins; j++) hscopetrace->SetBinContent(j, voltages[j]); TH1 *hm=0; TVirtualFFT::SetTransform(0); hm = hscopetrace->FFT(hm, "MAG"); for (Int_t j=0; j<(int)NBins; j++) hm_tot->SetBinContent(j, hm_tot->GetBinContent(j)+hm->GetBinContent(j)); delete hm; } hm_tot->Scale(1./(double)nentries); //Power spectral density histo from scope traces. TH1F *hpsd = new TH1F("hpsd", "power; Hz; V^2/Hz on oscilloscope", (int)NBins, 0., Fs); for (Int_t i=2; i<(int)NBins; i++) { hpsd->SetBinContent(i,hm_tot->GetBinContent(i)*hm_tot->GetBinContent(i)/NBins/NBins/(Fs/NBins)); // V^2/Hz. } hpsd->DrawCopy(); delete hpsd; delete hscopetrace; delete hm_tot; delete voltages; this->CloseFileandTree(); } void Scope::PlotSomething(){ double MemDepth=10000.; TCanvas *c = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("something else"); if (c) delete c; c = new TCanvas("something else","Not bleeping Scope Data",1000,400); TH1F *hscopetrace = new TH1F("hscopetrace", "Scope Trace; channels;Volts", (int)MemDepth, 0., MemDepth); for (Int_t j=0;j<(int)MemDepth; j++) hscopetrace->SetBinContent(j, (double)j); hscopetrace->DrawCopy(); c->Update(); delete hscopetrace; printf("made it\n"); } void Scope::Read(){ if (!(fname && *fname)) printf("oops\n"); // just a precaution if (T) {delete T; T = 0;} // make sure you delete it, if it already exists if (f) {delete f; f = 0;} // make sure you close the file, if it is opened f = new TFile(fname, "READ"); if (!f) return; // just a precaution T = (TTree *)f->FindObjectAny("T"); if (!T) printf("double oops\n"); // just a precaution b_voltagesI = T->GetBranch("voltages_chan1"); b_voltagesQ = T->GetBranch("voltages_chan2"); b_timestamps = T->GetBranch("timestamps"); #if 0 /* 0 or 1 */ if (T) {delete T; T = 0;} // make sure you delete it, if it already exists if (f) {delete f; f = 0;} // make sure you close the file, if it is opened #endif /* 0 or 1 */ } void Scope::CloseFileandTree(){ #if 1 /* 0 or 1 */ if (T) {delete T; T = 0;} // make sure you delete it, if it already exists if (f) {delete f; f = 0;} // make sure you close the file, if it is opened #endif /* 0 or 1 */ } // Define the class for the cint dictionary ClassDef (Scope,1) }; // Call the ClassImp macro to give the ABC class RTTI and full I/O capabilities. #if !defined(__CINT__) ClassImp(Scope); #endif