~maus-release/maus/release

« back to all changes in this revision

Viewing changes to src/common_py/analysis/hit_types.py

  • Committer: Paolo Franchini
  • Date: 2018-06-24 14:27:26 UTC
  • mfrom: (659.2.80 release-candidate)
  • Revision ID: p.franchini@warwick.ac.uk-20180624142726-nbxxyjyer146dr1t
Tags: MAUS-v3.2.0
MAUS-v3.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
  Note that this class is used by the add_hit meth
24
24
"""
25
25
 
26
 
# pylint: disable = W0311, R0902, R0904, R0913, C0103
 
26
# pylint: disable = W0311, R0902, R0904, R0913, C0103, R0914, R0915
27
27
 
28
28
import math
29
29
import analysis.tools as tools
40
40
                      px = 0.0, py = 0.0, pz = 0.0, station = 0, \
41
41
                      time = 0.0, mass = 105.6583715, p_value = 1.0, pid = 13, \
42
42
                      weight = 1.0, \
43
 
                      scifi_track_point = None, virtual_track_point = None ) :
 
43
                      scifi_track_point = None, virtual_track_point = None, \
 
44
                      global_track_point = None ) :
44
45
    """
45
46
      Initialise the object. this can be done in three ways:
46
47
      1. Specify all components by hand
47
48
      2. Build from a sci-fr trackpoint
48
49
      3. Build from a virtual trackpoint
49
50
    """
50
 
    if scifi_track_point is None and virtual_track_point is None :
 
51
    if scifi_track_point is None and virtual_track_point is None and global_track_point is None :
51
52
      self.__x = x
52
53
      self.__y = y
53
54
      self.__z = z
62
63
      self.__weight = weight
63
64
#      self.__reference = reference
64
65
 
65
 
    elif scifi_track_point is not None and virtual_track_point is None :
 
66
    elif scifi_track_point is not None and virtual_track_point is None and global_track_point is None :
66
67
      self.__x = scifi_track_point.pos().x()
67
68
      self.__y = scifi_track_point.pos().y()
68
69
      self.__z = scifi_track_point.pos().z()
82
83
#      else :
83
84
#        self.__reference = reference
84
85
 
85
 
    elif scifi_track_point is None and virtual_track_point is not None :
 
86
    elif scifi_track_point is None and virtual_track_point is not None and global_track_point is None :
86
87
      self.__x = virtual_track_point.GetPosition().x()
87
88
      self.__y = virtual_track_point.GetPosition().y()
88
89
      self.__z = virtual_track_point.GetPosition().z()
101
102
#      else :
102
103
#        self.__reference = reference
103
104
 
 
105
    elif scifi_track_point is None and virtual_track_point is None and global_track_point is not None :
 
106
      self.__x = global_track_point.get_position().X()
 
107
      self.__y = global_track_point.get_position().Y()
 
108
      self.__z = global_track_point.get_position().Z()
 
109
      self.__px = global_track_point.get_momentum().X()
 
110
      self.__py = global_track_point.get_momentum().Y()
 
111
      self.__pz = global_track_point.get_momentum().Z()
 
112
      self.__time = global_track_point.get_position().T()
 
113
      self.__mass = mass
 
114
      self.__p_value = p_value
 
115
      self.__pid = pid
 
116
      self.__station = station
 
117
      self.__weight = weight
 
118
 
104
119
    else :
105
120
      print "WTF!"
106
121
      raise ValueError( 'Please supply precisely one of "virtual_track_point"'+\
388
403
 
389
404
  for key, val in __hit_get_variables.iteritems() :
390
405
    __hit_get_keys.append( key )
 
406
 
 
407
 
 
408
################################################################################
 
409
 
 
410
 
 
411
class AnalysisSpacePoint() :
 
412
  """
 
413
    A simple, unified class that holds the essential information, when copied
 
414
    from MAUS data types, during various analyses.
 
415
 
 
416
    Some syntax was borrowed from XBoa for simplicity and because I like the
 
417
    interface!
 
418
  """
 
419
  def __init__( self, x = 0.0, y = 0.0, z = 0.0, station = 0, \
 
420
                      time = 0.0, weight = 1.0, tof = None, scifi = None ) :
 
421
    """
 
422
      Initialise the object. this can be done in three ways:
 
423
      1. Specify all components by hand
 
424
      2. Build from a sci-fr trackpoint
 
425
      3. Build from a virtual trackpoint
 
426
    """
 
427
    if tof is None and scifi is None :
 
428
      self.__x = x
 
429
      self.__y = y
 
430
      self.__z = z
 
431
      self.__time = time
 
432
      self.__station = station
 
433
      self.__weight = weight
 
434
 
 
435
    elif scifi is not None and tof is None :
 
436
      self.__x = scifi.pos().x()
 
437
      self.__y = scifi.pos().y()
 
438
      self.__z = scifi.pos().z()
 
439
      self.__time = time
 
440
      self.__station = tools.calculate_plane_id(scifi.tracker(), \
 
441
          scifi.station(), 1)
 
442
      self.__weight = weight
 
443
 
 
444
    elif scifi is None and tof is not None :
 
445
      self.__x = tof.GetGlobalPosX()
 
446
      self.__y = tof.GetGlobalPosY()
 
447
      self.__z = tof.GetGlobalPosZ()
 
448
      self.__time = tof.GetTime()
 
449
      self.__station = tof.GetStation()
 
450
      self.__weight = weight
 
451
 
 
452
    else :
 
453
      print "WTF!"
 
454
      raise ValueError( 'Please supply precisely one of "virtual_track_point"'+\
 
455
                 ' or "scifi_track_point", or specify all values explicitly.' )
 
456
 
 
457
 
 
458
  def __str__( self ) :
 
459
    """
 
460
      Return a string of the parameters.
 
461
      Mostly useful for debuging.
 
462
    """
 
463
    return '(' + str( self.__x ) + ',' +\
 
464
                 str( self.__y ) + ',' +\
 
465
                 str( self.__z ) + '):[' +\
 
466
                 str( self.__time ) +\
 
467
                 str( self.__station ) + ']'
 
468
 
 
469
 
 
470
  def __repr__( self ) :
 
471
    """
 
472
      Return a string of the parameters.
 
473
      Mostly useful for debuging.
 
474
    """
 
475
    return '(' + str( self.__x ) + ',' +\
 
476
                 str( self.__y ) + ',' +\
 
477
                 str( self.__z ) + '):[' +\
 
478
                 str( self.__time ) +\
 
479
                 str( self.__station ) + ']'
 
480
 
 
481
 
 
482
 
 
483
  def set_x( self, val ) :
 
484
    """
 
485
      Set the x position
 
486
    """
 
487
    self.__x = val
 
488
 
 
489
  def set_y( self, val ) :
 
490
    """
 
491
      Set the y position
 
492
    """
 
493
    self.__y = val
 
494
 
 
495
  def set_z( self, val ) :
 
496
    """
 
497
      Set the z position
 
498
    """
 
499
    self.__z = val
 
500
 
 
501
  def set_time( self, val ) :
 
502
    """
 
503
      Set the time
 
504
    """
 
505
    self.__time = val
 
506
 
 
507
  def set_station( self, station ) :
 
508
    """
 
509
      Set the station ID
 
510
    """
 
511
    self.__station = station
 
512
 
 
513
  def set_weight( self, w ) :
 
514
    """
 
515
      Set the statistical weight of the hit
 
516
    """
 
517
    self.__weight = w
 
518
 
 
519
 
 
520
  def get_x( self ) :
 
521
    """
 
522
      Get the x position
 
523
    """
 
524
    return self.__x
 
525
 
 
526
  def get_y( self ) :
 
527
    """
 
528
      Get the y position
 
529
    """
 
530
    return self.__y
 
531
 
 
532
  def get_z( self ) :
 
533
    """
 
534
      Get the z position
 
535
    """
 
536
    return self.__z
 
537
 
 
538
  def get_time( self ) :
 
539
    """
 
540
      Get the time
 
541
    """
 
542
    return self.__time
 
543
 
 
544
  def get_r( self ) :
 
545
    """
 
546
      Get the position radius
 
547
    """
 
548
    return math.sqrt( self.__x**2 + self.__y**2 )
 
549
 
 
550
  def get_phi( self ) :
 
551
    """
 
552
      Get the Phi angle (Position)
 
553
    """
 
554
    return math.atan2( self.__y, self.__x )
 
555
 
 
556
  def get_station( self ) :
 
557
    """
 
558
      Get the particle ID
 
559
    """
 
560
    return self.__station
 
561
 
 
562
 
 
563
  def get_weight( self ) :
 
564
    """
 
565
      Return the statistical weight of the hit
 
566
    """
 
567
    return self.__weight
 
568
 
 
569
 
 
570
  def get( self, string ) :
 
571
    """
 
572
      Return the value of the variable described in the string
 
573
    """
 
574
    if not string in AnalysisSpacePoint.__hit_get_keys :
 
575
      return None
 
576
    else :
 
577
      return AnalysisSpacePoint.__hit_get_variables[ string ]( self )
 
578
 
 
579
 
 
580
  def get_as_vector( self ) :
 
581
    """
 
582
      Returns the 6D phase-space vector corresponding to the particle.
 
583
      [t, x, y, z]
 
584
    """
 
585
    return [self.__time, self.__x, self.__y, self.__z]
 
586
 
 
587
 
 
588
  def get_variable_list() :
 
589
    """
 
590
        Return the list of variables that the user can request
 
591
    """
 
592
    return AnalysisSpacePoint.__hit_get_keys
 
593
  get_variable_list = staticmethod( get_variable_list )
 
594
 
 
595
 
 
596
 
 
597
  __hit_get_keys = []
 
598
  __hit_get_variables = { 'x':get_x, 'y':get_y, 'z':get_z,
 
599
                              't':get_time, 'r':get_r, 'station':get_station }
 
600
 
 
601
  for key, val in __hit_get_variables.iteritems() :
 
602
    __hit_get_keys.append( key )