Project

General

Profile

Example Analysis Code » python_analysis_example.py

Dobbs, Adam, 03 August 2015 13:51

 
1
#!/usr/bin/env python
2

    
3
import libMausCpp
4
from ROOT import *
5

    
6
# Set up the ROOT file and data pointer
7
f1 = TFile("maus_output.root")
8
t1 = f1.Get("Spill")
9
data_ptr = MAUS.Data()
10
t1.SetBranchAddress("data", data_ptr)
11

    
12
# Create the histogram
13
h1 = TH1D("h1", "Spacepoint NPE", 100, 0, 150);
14
h1.GetXaxis().SetTitle("Number of photoelectrons")
15
h1.SetLineColor(kBlue)
16

    
17
# Loop over all spills
18
for i in range(1, t1.GetEntries()):
19
    t1.GetEntry(i) # Update the spill pointed to by data_ptr
20
    spill = data_ptr.GetSpill()
21
    if spill.GetDaqEventType() == "physics_event":
22
        # Loop over recon events in spill
23
        for j in range(spill.GetReconEvents().size()):
24
            sfevt = spill.GetReconEvents()[j].GetSciFiEvent()
25
            # Loop over spacepoints
26
            for k in range(sfevt.spacepoints().size()):
27
                spoint = sfevt.spacepoints()[k]
28
                h1.Fill(spoint.get_npe())
29

    
30
# Draw the histogram
31
c1 = TCanvas("c1", "SciFi Spacepoint NPE", 900, 600)
32
h1.Draw()
33
raw_input("Press Enter to finish...")
(4-4/5)