~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to bin/user/scifi/tracker_resolution_plots.py

MAUS-v2.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
import array
50
50
 
51
51
# Third Party library import statements
 
52
import json
52
53
import event_loader
53
54
import analysis
54
55
from analysis import tools
101
102
INVERSE_PLANE_DICT = {}
102
103
TRACKER_PLANE_RADIUS = 150.0
103
104
 
 
105
SELECT_EVENTS = False
 
106
GOOD_EVENTS = {}
 
107
 
104
108
 
105
109
def get_pz_bin(pz) :
106
110
  offset = pz - PZ_MIN
863
867
      for plot_axis in [ "residual_pt", "residual_pz" ] :
864
868
        plot = plot_dict[tracker][component+plot_axis]
865
869
 
866
 
        errors = array.array( 'd' )
 
870
        rms_error = array.array( 'd' )
867
871
        bin_size = array.array( 'd' )
868
872
        bins = array.array( 'd' )
869
873
        rms = array.array( 'd' )
 
874
        mean = array.array( 'd' )
 
875
        mean_error = array.array( 'd' )
870
876
 
871
 
#        width = int( plot.GetNbinsX() / RESOLUTION_BINS )
872
877
        width = plot.GetXaxis().GetBinWidth(1)
873
878
        for i in range( 0, plot.GetXaxis().GetNbins() ) :
874
879
          projection = plot.ProjectionY( \
875
880
      tracker+component+plot_axis+'_pro_'+str(i), i, (i+1) )
876
 
#      tracker+component+plot_axis+'_pro_'+str(i), i*width, (i+1)*width )
877
881
 
878
 
#          plot_mean = plot.GetXaxis().GetBinCenter( i*width ) + width*0.5
879
882
          plot_mean = plot.GetXaxis().GetBinCenter( i ) + width
880
 
          _, _, pro_std, pro_std_err = \
 
883
          pro_mean, pro_mean_err, pro_std, pro_std_err = \
881
884
                                        analysis.tools.fit_gaussian(projection)
882
885
 
883
886
          bin_size.append( width*0.5 )
884
 
          errors.append( pro_std_err )
885
887
          bins.append( plot_mean )
886
888
          rms.append( pro_std )
 
889
          rms_error.append( pro_std_err )
 
890
          mean.append( pro_mean )
 
891
          mean_error.append( pro_mean_err )
887
892
 
888
893
        if len(bins) != 0 :
889
894
          resolution_graph = ROOT.TGraphErrors( len(bins), \
890
 
                                                  bins, rms, bin_size, errors )
 
895
                                               bins, rms, bin_size, rms_error )
 
896
          bias_graph = ROOT.TGraphErrors( len(bins), \
 
897
                                             bins, mean, bin_size, mean_error )
891
898
        else :
892
899
          resolution_graph = None
 
900
          bias_graph = None
893
901
 
894
902
        plot_dict[tracker][component+plot_axis+'_resolution'] = \
895
903
                                                               resolution_graph
 
904
        plot_dict[tracker][component+plot_axis+'_bias'] = bias_graph
896
905
  return data_dict
897
906
 
898
907
 
951
960
                                         "momentum to consider for analysis." )
952
961
 
953
962
 
 
963
  parser.add_argument( '--selection_file', default=None, \
 
964
                 help='Name of a JSON file containing the events to analyses' )
 
965
 
 
966
 
954
967
 
955
968
  parser.add_argument( '--not_require_cluster', action="store_true", \
956
969
        help="Don't require a cluster in the reference plane" )
979
992
    PT_MIN = namespace.pt_window[0]
980
993
    PT_MAX = namespace.pt_window[1]
981
994
    PT_BIN_WIDTH = namespace.pt_bin
 
995
 
 
996
    if namespace.selection_file is not None :
 
997
      SELECT_EVENTS = True
 
998
      with open(namespace.selection_file, 'r') as infile :
 
999
        GOOD_EVENTS = json.load(infile)
 
1000
    else :
 
1001
      SELECT_EVENTS = False
982
1002
  except BaseException as ex:
983
1003
    raise
984
1004
  else :
1006
1026
    try :
1007
1027
      while file_reader.next_event() and \
1008
1028
               file_reader.get_total_num_events() != namespace.max_num_events :
 
1029
 
 
1030
        if SELECT_EVENTS :
 
1031
          filename = file_reader.get_current_filename()
 
1032
          spill = str(file_reader.get_current_spill_number())
 
1033
          event = file_reader.get_current_event_number()
 
1034
          if filename not in GOOD_EVENTS :
 
1035
            continue
 
1036
          if spill not in GOOD_EVENTS[filename] :
 
1037
            continue
 
1038
          if event not in GOOD_EVENTS[filename][spill] :
 
1039
            continue
 
1040
 
1009
1041
        try :
1010
1042
          sys.stdout.write( 
1011
1043
              '  Spill ' + str(file_reader.get_current_spill_number()) + \