Project

General

Profile

Example Analysis Code » python_analysis_example_crosslinks.py

Dobbs, Adam, 01 October 2015 13:43

 
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 pat rec straight tracks
26
            for k in range(sfevt.straightprtracks().size()):
27
                trk = sfevt.straightprtracks()[k]
28
                # Loop over seed spacepoints
29
                for l in range(trk.get_spacepoints_pointers().size()):
30
                    spoint = trk.get_spacepoints_pointers()[l]
31
                    h1.Fill(spoint.get_npe())
32

    
33
# Draw the histogram
34
c1 = TCanvas("c1", "SciFi Spacepoint NPE", 900, 600)
35
h1.Draw()
36
raw_input("Press Enter to finish...")
(5-5/5)