2
# This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
4
# MAUS is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
9
# MAUS is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with MAUS. If not, see <http://www.gnu.org/licenses/>.
19
Defines the AnalysisHit class.
21
A generic hit class that can be used to simplify the analysis of track data.
23
Note that this class is used by the add_hit meth
26
# pylint: disable = W0311, R0902, R0904, R0913, C0103
33
A simple, unified class that holds the essential information, when copied
34
from MAUS data types, during various analyses.
36
Some syntax was borrowed from XBoa for simplicity and because I like the
39
def __init__( self, x = 0.0, y = 0.0, z = 0.0, \
40
px = 0.0, py = 0.0, pz = 0.0, \
41
time = 0.0, mass = 105.6583715, p_value = 1.0, pid = 13, \
42
scifi_track_point = None, virtual_track_point = None ) :
44
Initialise the object. this can be done in three ways:
45
1. Specify all components by hand
46
2. Build from a sci-fr trackpoint
47
3. Build from a virtual trackpoint
49
if scifi_track_point is None and virtual_track_point is None :
58
self.__p_value = p_value
60
# self.__reference = reference
62
elif scifi_track_point is not None and virtual_track_point is None :
63
self.__x = scifi_track_point.pos().x()
64
self.__y = scifi_track_point.pos().y()
65
self.__z = scifi_track_point.pos().z()
66
self.__px = scifi_track_point.mom().x()
67
self.__py = scifi_track_point.mom().y()
68
self.__pz = scifi_track_point.mom().z()
71
self.__p_value = p_value
73
# if reference is None :
74
# self.__reference = str(scifi_track_point.tracker())+"."+\
75
# str(scifi_track_point.station())+"."+str(scifi_track_point.plane())
77
# self.__reference = reference
78
if math.isnan(self.__x) :
79
raise ValueError("NaN Values Received from Scifi Track Point")
81
elif scifi_track_point is None and virtual_track_point is not None :
82
self.__x = virtual_track_point.GetPosition().x()
83
self.__y = virtual_track_point.GetPosition().y()
84
self.__z = virtual_track_point.GetPosition().z()
85
self.__px = virtual_track_point.GetMomentum().x()
86
self.__py = virtual_track_point.GetMomentum().y()
87
self.__pz = virtual_track_point.GetMomentum().z()
88
self.__time = virtual_track_point.GetTime()
91
self.__pid = virtual_track_point.GetParticleId()
92
# self.__reference = reference
93
# if reference is None :
94
# self.__reference = virtual_track_point.GetStationId()
96
# self.__reference = reference
100
raise ValueError( 'Please supply precisely one of "virtual_track_point"'+\
101
' or "scifi_track_point", or specify all values explicitly.' )
104
def __str__( self ) :
106
Return a string of the parameters.
107
Mostly useful for debuging.
109
return '(' + str( self.__x ) + ',' +\
110
str( self.__y ) + ',' +\
111
str( self.__z ) + '):[' +\
112
str( self.__px ) + ',' +\
113
str( self.__py ) + ',' +\
114
str( self.__pz ) + ']'
115
# str( self.__reference )
118
def __repr__( self ) :
120
Return a string of the parameters.
121
Mostly useful for debuging.
123
return '(' + str( self.__x ) + ',' +\
124
str( self.__y ) + ',' +\
125
str( self.__z ) + '):[' +\
126
str( self.__px ) + ',' +\
127
str( self.__py ) + ',' +\
128
str( self.__pz ) + ']'
129
# str( self.__reference )
133
def set_x( self, val ) :
139
def set_y( self, val ) :
145
def set_z( self, val ) :
151
def set_px( self, val ) :
157
def set_py( self, val ) :
163
def set_pz( self, val ) :
169
def set_time( self, val ) :
175
def set_mass( self, val ) :
181
def set_p_value( self, val ) :
187
def set_pid( self, val ) :
193
# def set_reference( self, string ) :
194
# self.__reference = string
232
def get_time( self ) :
240
Get the total momentum
242
if math.isnan(math.sqrt( self.__px**2 + self.__py**2 + self.__pz**2 )) :
243
print "ISNAN!!!", self
244
return math.sqrt( self.__px**2 + self.__py**2 + self.__pz**2 )
248
Get the position radius
250
return math.sqrt( self.__x**2 + self.__y**2 )
252
def get_energy( self ) :
256
return math.sqrt( self.get_mass()**2 + self.get_p()**2 )
260
Get the transverse momentum
262
return math.sqrt( self.__px**2 + self.__py**2 )
268
return self.get_px() / self.get_pz()
274
return self.get_py() / self.get_pz()
276
def get_mass( self ) :
282
def get_p_value( self ) :
286
return self.__p_value
288
def get_pid( self ) :
295
# def get_reference( self ) :
296
# return self.__reference
300
def get( self, string ) :
302
Return the value of the variable described in the string
304
if not string in AnalysisHit.__hit_get_keys :
307
return AnalysisHit.__hit_get_variables[ string ]( self )
310
def get_variable_list() :
312
Return the list of variables that the user can request
314
return AnalysisHit.__hit_get_keys
315
get_variable_list = staticmethod( get_variable_list )
320
__hit_get_variables = { 'x':get_x, 'y':get_y, 'z':get_z,
321
'px':get_px, 'py':get_py, 'pz':get_pz,
322
'mx':get_mx, 'my':get_my,
323
't':get_time, 'p':get_p, 'r':get_r,
324
'E':get_energy, 'pt':get_pt, 'm':get_mass,
325
'mass':get_mass, 'energy':get_energy,
326
'pvalue':get_p_value, 'pid':get_pid }
328
for key, val in __hit_get_variables.iteritems() :
329
__hit_get_keys.append( key )