Go to the documentation of this file.00001 #include "Riostream.h"
00002
00005
00006
00007
00009
00011
00012
00014 Bool_t fft(const char* name1, Option_t* opt = "R2C M", Bool_t draw=kTRUE)
00015 {
00016 if(TGo4AbstractInterface::Instance()==0 || go4!=TGo4AbstractInterface::Instance()) {
00017 std::cout <<"FATAL: Go4 gui macro executed outside Go4 GUI!! returning." << std::endl;
00018 return kFALSE;
00019 }
00020 TString newname;
00021 TString fullname1 = go4->FindItem(name1);
00022 TObject* ob1 = go4->GetObject(fullname1,1000);
00023
00024 if ((ob1==0) || !ob1->InheritsFrom("TH1")) {
00025 std::cout <<"fft could not get histogram "<<fullname1 << std::endl;
00026 return kFALSE;
00027 }
00028
00029 if(ob1->InheritsFrom("TH2") || ob1->InheritsFrom("TH3")){
00030 std::cout <<"fft does not support 2d/3d histogram "<<fullname1 << std::endl;
00031 return kFALSE;
00032 }
00033
00034 TH1* his1=(TH1*)ob1;
00035 TString n1=his1->GetName();
00036 TString t1=his1->GetTitle();
00037 newname.Form("_fft_%s",opt);
00038 TString finalname = n1+newname;
00039 TString finaltitle = t1+newname;
00040
00041
00042
00043 Int_t N = his1->GetNbinsX();
00044 TH1D* result = new TH1D(finalname, finaltitle,N,0,N);
00045 result->SetName(finalname);
00046 result->SetTitle(finaltitle);
00047 result->Reset("");
00048 Double_t *in = new Double_t[N];
00049
00050 for(Int_t ix=0; ix<N;++ix)
00051 {
00052 in[ix]=his1->GetBinContent(ix+1);
00053 }
00054 TVirtualFFT *thefft = TVirtualFFT::FFT(1, &N, opt);
00055 thefft->SetPoints(in);
00056 thefft->Transform();
00057 Double_t re, im;
00058 for (Int_t i=0; i<N; i++) {
00059 thefft->GetPointComplex(i, re, im);
00060 result->SetBinContent(i+1,TMath::Sqrt(re*re + im*im));
00061 }
00062 result->SetDirectory(0);
00063
00064 TString rname = go4->SaveToMemory("FFT", result, kTRUE);
00065 std::cout<< "Saved result histogram to " << rname.Data() <<std::endl;
00066 if(draw){
00067 ViewPanelHandle vpanel = go4->StartViewPanel();
00068 go4->DrawItem(rname, vpanel);
00069 }
00070 return kTRUE;
00071 }