Project

General

Profile

Feature #1152 » Test_Cuts.py

Carlisle, Timothy, 07 December 2012 12:34

 
1
from xboa  import *
2
from xboa.Hit   import Hit
3
from xboa.Bunch import Bunch
4
import sys
5
import os
6
import subprocess
7
from array import array
8
import math
9
import operator
10

    
11
import ROOT 
12

    
13
#some input data
14
filename = sys.argv[1]
15
filetype = "maus_root_virtual_hit"
16

    
17
print "First loading the data... "
18
bunch_list = Bunch.new_list_from_read_builtin(filetype, filename)
19

    
20
# now load the ROOT file
21

    
22
root_file = ROOT.TFile(filename, "READ") # pylint: disable = E1101
23

    
24
# and set up the data tree to be filled by ROOT IO
25

    
26
data = ROOT.MAUS.Data() # pylint: disable = E1101
27
tree = root_file.Get("Spill")
28
tree.SetBranchAddress("data", data)
29

    
30
bunch_list = Bunch.new_list_from_read_builtin(filetype, filename)
31

    
32
print " no. Virtual Planes: " + str( len(bunch_list) )
33

    
34
emittance4, beta4, Pt = array( 'd' ), array( 'd' ), array('d')
35
Bz, x, y, z, Pz, Px, Energy, Amplitude = array( 'd' ), array( 'd' ), array( 'd' ), array( 'd' ), array( 'd' ), array( 'd' ), array( 'd'), array( 'd')
36

    
37
Nmu = array( 'd' )
38

    
39

    
40
bunch = bunch_list[0]
41

    
42
bunch.root_histogram('pz','MeV/c')
43
raw_input('Press Enter to exit')
44

    
45

    
46
# LOCAL CUT
47
bunch.cut({'pz':199.}, operator.le)
48
bunch.root_histogram('pz','MeV/c')
49

    
50
for i in range( len(bunch) ):
51
    hit = bunch[i]
52
    print str(i) + " " + str(hit['pz']) +  " local: " + str(hit['local_weight']) + " global: " + str(hit['global_weight'])
53

    
54
# reset weights, to check global cut
55
bunch.clear_weights()
56

    
57
raw_input('Press Enter to exit')
58

    
59
#GLOBAL CUT 
60
bunch.cut({'pz':199.}, operator.le, global_cut=True)
61
bunch.root_histogram('pz','MeV/c')
62
for i in range( len(bunch) ):
63
    hit = bunch[i]
64
    print str(i) + " " + str(hit['pz']) +  " local: " + str(hit['local_weight']) + " global: " + str(hit['global_weight'])
65
    
66
raw_input('Press Enter to exit')
67

    
68

    
69

    
70
    
(4-4/4)