Truncated TH1

hey rooters,
I just discoverd that the FFT in ROOT is applied to the whole range of the TH1, no matter how I set the range before the FFT. codes below shows what I mean.

func1 = r.TF1('func1','cos(x)',30,100) # chen cheng's note, eq(8)
func1.SetNpx(1000)
func1.SetLineColor(2)

func2 = r.TF1('func2','cos(2*x-4.08)',100,200) # chen cheng's note, eq(8)
func2.SetNpx(1000)
func2.SetLineColor(4)

hist = r.TH1D("hist","title",1143,202*0.1492,1345*0.14923)

for ibin in range(500):
    ibin+=1
    hist.SetBinContent(ibin,func1.Eval(hist.GetBinCenter(ibin)))
    
for ibin in range(1143)[500:]:
    ibin+=1
    hist.SetBinContent(ibin,func2.Eval(hist.GetBinCenter(ibin)))

to see this, you perform FFT right after setting the range

bin_width = hist.GetBinWidth(1) # hist.GetBinCenter(2) - hist.GetBinCenter(1)
print(bin_width)
fft = r.TH1D('fft', 'FFT;f [MHz]; FFT magnitude [arb.]', hist.GetNbinsX(), 0, 1.0/bin_width)
hist.GetXaxis().SetRangeUser(100,200)
hist.FFT(fft, 'MAG')
fft.GetXaxis().SetRangeUser(0.01,fft.GetXaxis().GetXmax()/2) # 0.08 to get rid of the DC component

c = r.TCanvas("c","c",1600,600)
fft.Draw()
c.Draw()

So can I just keep the original TH1D untouched and do fft on the specific ranges on the TH1D ?


ROOT Version: 6.26
Platform: Ubuntu 20.04
Compiler: gcc9


I think @moneta can help.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.