示例#1
0
def update_schema():
    from soudan_database import SoudanServer, RunDocumentClass

    server = SoudanServer()
    
    for id in server.get_database():
        run_doc = server.get_run(id)
        run_doc = RunDocumentClass.update_schema(run_doc)
        print "Updating run number: %s" % run_doc.id
        server.insert_rundoc(run_doc)
示例#2
0
def processSpectrum(pfn_dir, divide_by_number = 1, outputfile='temp.root', \
                    force_overwrite=False, hist_name='hist', \
		    energy_scale='*1', cuts='', use_baseline_cut=False, \
                    opposite_baseline_cut=False):
    tree_name = '%sTree' % hist_name
    server = SoudanServer()
    file_list = server.get_accepted_runs()
    
    number_of_sigma = 2
    mass_of_detector = 0.528 # in kg
    file_to_output = TFile("%s" % outputfile, 'UPDATE')
    tree_in_file = file_to_output.Get(tree_name)
    hist = TH1D(hist_name, hist_name, 8192, 0, eval("8192%s" % energy_scale))
    hist.Rebin(divide_by_number)
    hist.GetXaxis().SetTitle("Energy (keV)")
    hist.GetYaxis().SetTitle("Counts/keV/kg/day")

    total_time = 0
    for id in file_list:
        print id
        rundoc = server.get_run(id.id) 
        file_name = eval("rundoc.output_data_file_tier_3.%s.pfn" % pfn_dir)
        open_file = TFile(file_name)
        main_tree = open_file.Get("wf_analysis") 
        coinc_tree = open_file.Get("event_coincidence") 
        main_tree.AddFriend(coinc_tree)
        real_cuts = cuts
        main_tree.GetEntry(0)
        if use_baseline_cut:
            not_string = ""
            if opposite_baseline_cut:
                not_string = "!"
            additional_cuts = " && %s(abs(fitConstant-%f) <= 3*%f) " % (not_string, \
               rundoc.baseline_dict.average_fit_constant, \
               rundoc.baseline_dict.average_fit_rms)
            real_cuts += additional_cuts 
        file_to_output.cd()
        main_tree.Draw("-energy%s>> +%s" % (energy_scale, hist.GetName()),real_cuts, "goff")
        open_file.Close()
        total_time += rundoc.livetime.run_seconds


    total_time /= (3600.*24.)
    hist.Scale(1./(mass_of_detector*hist.GetBinWidth(1)*total_time))
    file_to_output.cd()
    hist.Write(hist.GetName(), TObject.kOverwrite)
    file_to_output.Close()
示例#3
0
def look_at_number_of_entries_in_file():

    server = SoudanServer()
    tree = ROOT.TTree("temp", "temp")
    num_entries = array.array('d', [0])
    tree.Branch("entries", num_entries, "num_entries/D")
    for id in server.get_database():
        print id
        rundoc = server.get_run(id) 
        if not rundoc: continue
        num_entries[0] = rundoc.number_of_entries_in_tier1_root_tree/\
                         float(rundoc.livetime.run_seconds)
        tree.Fill()

    open_file = ROOT.TFile("temp.root", "recreate")
    hist = ROOT.TH1D("hist", "hist", 1000, 0, 1000)
    tree.Draw("entries >> hist")
    raw_input("enter")
    hist.Write()
示例#4
0
def processSpectrum(doc_list, input_directory='..', type='pulser',\
                    hist_name='hist', \
		    energy_scale='*1', cuts='', use_baseline_cut=False, opposite_baseline_cut=False):
    import re
    from array import array
    from ROOT import TFile, TH1D, TTree, TObject, TEventList, gROOT
    from soudan_database import SoudanServer
    
    number_of_sigma = 3
    hist = TH1D(hist_name, hist_name, 8192, 0, eval("8192%s" % energy_scale))
    hist.GetXaxis().SetTitle("Energy (keV)")
    hist.GetYaxis().SetTitle("Counts")

    server = SoudanServer()

    for run_number in doc_list:
        doc = server.get_run(run_number.id) 
        try:
            string_of_file_name = eval('doc.output_data_file_tier_3.%s.lfn' % type)
        except:
            print "Incorrect type"
            continue
        print doc._get_id()
        open_file = TFile("%s/%s" % (input_directory,string_of_file_name))
        main_tree = open_file.Get("wf_analysis") 
        coinc_tree = open_file.Get("event_coincidence") 
        main_tree.AddFriend(coinc_tree)
        real_cuts = cuts
        if use_baseline_cut:
            not_string = ""
            if opposite_baseline_cut:
                not_string = "!"
            additional_cuts = " && %s(abs(fitConstant-%f) <= %f*%f) " % \
                 (not_string, doc.baseline_dict.average_fit_constant,\
                   number_of_sigma, doc.baseline_dict.average_fit_rms)
            real_cuts += additional_cuts 
        gROOT.cd()
        main_tree.Draw("-energy%s>> +%s" % (energy_scale, hist.GetName()),real_cuts, "goff")
        open_file.Close()

    return hist