Skip to content

Instantly share code, notes, and snippets.

@gadamc
Created March 28, 2012 20:22
Show Gist options
  • Save gadamc/2230191 to your computer and use it in GitHub Desktop.
Save gadamc/2230191 to your computer and use it in GitHub Desktop.
use KData and the KChamonixKAmpSite to measure the power spectrum of noise events.
#!/usr/bin/env python
import operator
from ROOT import *
#make sure you $> source /sps/edelweis/kdata/code/dev/config/setup_kdata.sh (or .csh if you use tcsh or csh)
gSystem.Load('libkds')
gSystem.Load('libkpta')
gSystem.Load('libkamping')
f = KDataReader('/sps/edelweis/kdata/data/raw/ma22a000_000.root') # all data in /sps/edelweis/kdata/data/raw. ex: /sps/edelweis/kdata/data/raw/ma22a000_000.root
myChannel = 'chalA FID808'
outputHistFile = 'myOutfile.root'
cham = KChamonixKAmpSite()
#these are the parameters of the KEraPeakFinder. See the webpage: https://edwdev-ik.fzk.de/kdata_dev_ref/KEraPeakFinder.html
cham.GetHeatPeakDetector().SetNumRms(2.3)
cham.GetHeatPeakDetector().SetOrder(5)
e = f.GetEvent()
for i in range(f.GetEntries()):
f.GetEntry(i)
if operator.mod(i,100) == 0: print i
for j in range(e.GetNumBoloPulses()):
pulse = e.GetBoloPulse(j)
if pulse.GetChannelName() != myChannel:
continue
cham.ScoutKampSite( pulse ,e)
print 'number of noise events found', cham.GetNumNoiseEventsFound(myChannel)
powerVec = cham.GetNoisePower(myChannel)
hist = TH1D('noisepower', 'noisepower', powerVec.size(), 0, powerVec.size())
for i in range(powerVec.size()):
hist.SetBinContent(i+1, powerVec[i])
c1 = TCanvas()
c1.SetLogx()
c1.SetLogy()
hist.Draw()
raw_input('hit enter to close')
ff = TFile.Open(outputHistFile, 'recreate')
hist.Write()
ff.Close()
#open root file by starting ROOT
# $> root
# root [0] TFile f("myOutfile.root")
# root [1] f.ls()
# root [2] noisepower.Draw()
# root [3] c1.SetLogx()
# root [4] c1.SetLogy()
# root [5] noisepower.Draw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment