ATLAS Offline Software
RPCRawDataMonUtils.py
Go to the documentation of this file.
1 #
2 #Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 #
4 
5 import ROOT
6 
7 
8 def creatGraph(xs, ys, x_errs, y_errs, g_name, g_title, g_Xtitle, g_Ytitle):
9  if len(xs) == 0:
10  return ROOT.TGraph()
11 
12  import array
13  x_arr = array.array("f",xs)
14  y_arr = array.array("f",ys)
15  x_err_arr = array.array("f",x_errs)
16  y_err_arr = array.array("f",y_errs)
17 
18  g1 = ROOT.TGraphErrors(len(x_arr),x_arr,y_arr, x_err_arr, y_err_arr)
19 
20  g1.SetNameTitle(g_name, g_title)
21  g1.SetMarkerSize(0.5)
22  g1.GetXaxis().SetTitle(g_Xtitle)
23  g1.GetYaxis().SetTitle(g_Ytitle)
24  g1.GetYaxis().SetRangeUser(0.8*min(y_arr),1.2*max(y_arr))
25 
26  return g1
27 
28 
35 def linearFit(h_temp, opt="QNS+"):
36  default_dic = {"p0": 0., "p0_err":0., "p1": -1., "p1_err":-1., "chi2":-1., "mean":0., "mean_err":0.}
37  # Qtag, un-fit-able
38  # -1 -- null graph
39  # 0 -- normal
40  # 1 -- N points = 1
41  # 2 -- N points = 2
42  # 3 -- N points = 0
43 
44  Qtag = 0
45  if not h_temp:
46  Qtag = -1
47  return (Qtag, default_dic)
48 
49  if h_temp.GetN()< 2:
50  Qtag = 1
51  return (Qtag, default_dic)
52 
53  # fit_result = h_temp.Fit("pol1", opt, "", 0, 2.2)
54  fit_result = h_temp.Fit("pol1", opt)
55 
56  par_a = round(fit_result.Value(0), 2)
57  par_a_E = round(fit_result.ParError(0), 2)
58  par_b = round(fit_result.Value(1), 2)
59  par_b_E = round(fit_result.ParError(1), 2)
60 
61  if fit_result.Ndf() == 0:
62  Qtag = 2
63  chi2 = 0
64  else:
65  chi2 = round(fit_result.Chi2()/fit_result.Ndf(), 2)
66 
67  mean = round(h_temp.GetMean(2), 2)
68  mean_rms= round(h_temp.GetRMS(2), 2)
69 
70  dic = {"p0": par_a, "p0_err":par_a_E, "p1": par_b, "p1_err":par_b_E, "chi2":chi2, "mean":mean, "mean_err":mean_rms}
71  return (Qtag, dic)
72 
73 # ================================================================================================
74 
76 class Panel():
77  panel_name = ''
78 
79  # -----------------------------------------------------------------------
80  def __init__(self, properties, index):
81  # def __init__(self, panel_name):
82  self.index = index
83  self.setPanelProp(properties)
84 
85  # -----------------------------------------------------------------------
86  def getSector(self):
87  myphi_part = (2 * self.stationPhi) - 1
88  if (self.stationName == 3 or self.stationName == 5 or self.stationName == 8 or self.stationName == 9 or self.stationName == 10) :
89  myphi_part += 1
90 
91  sector = myphi_part
92  if self.stationEta < 0:
93  sector = -sector
94 
95  if (self.stationName == 2 or self.stationName == 3 or self.stationName == 8 or self.stationName == 53) :
96  layer = (self.doubletR-1)*2 + self.gasGap
97  else:
98  layer = 4+(self.doubletR-1)*2 + self.gasGap
99 
100  return (sector, layer)
101 
102  # -----------------------------------------------------------------------
103  def getPanelName(self):
104  self.stationNames = {2:'BML', 3:'BMS', 4:'BOL', 5:'BOS', 8:'BMF' , 9:'BOF', 10:'BOG', 53:'BME'}
105 
106  str_name = self.stationNames[self.stationName]
107  str_eta = str(abs(self.stationEta))
108  str_dPhi = "DP" + str(self.doubletPhi) + "."
109  str_gap = "Ly" + str(self.gasGap - 1) + "."
110  str_dZ = "DZ" + str(self.doubletZ)
111 
112  myphi_part = (2 * self.stationPhi) - 1
113 
114  if self.stationEta > 0:
115  str_side = "A"
116  elif self.stationEta < 0:
117  str_side = "C"
118  else:
119  str_side = "N" # N: NULL, "ETA NOT DEFINED"
120 
121  if (self.stationName == 3 or self.stationName == 5 or self.stationName == 8 or self.stationName == 9 or self.stationName == 10) :
122  myphi_part += 1
123 
124  if myphi_part < 10:
125  str_phi = "0" + str(myphi_part)
126  else:
127  str_phi = str(myphi_part)
128 
129  if ((self.stationName == 2 and self.doubletR == 1) or
130  (self.stationName == 3 and self.doubletR == 1) or
131  (self.stationName == 53 and self.doubletR == 1) or
132  (self.stationName == 8 and self.doubletR == 1)):
133  str_PICO = ".CO."
134  elif ((self.stationName == 2 and self.doubletR == 2) or
135  (self.stationName == 3 and self.doubletR == 2) or
136  (self.stationName == 53 and self.doubletR == 2) or
137  (self.stationName == 8 and self.doubletR == 2)):
138  str_PICO = ".PI."
139  elif ((self.stationName == 4 and self.doubletR == 1) or
140  (self.stationName == 5 and self.doubletR == 1) or
141  (self.stationName == 9 and self.doubletR == 1) or
142  (self.stationName == 10 and self.doubletR == 1)):
143  str_PICO = ".CO."
144  else:
145  str_PICO = ".NU"+str(self.doubletR)+"." # NU: NULL, Not defined
146 
147  if(self.measPhi == 0):
148  str_ETAPHI = "ETA."
149  else:
150  str_ETAPHI = "PHI."
151 
152  self.panel_name = str_name + str_eta + str_side + str_phi + str_PICO + str_dPhi + str_gap + str_dZ + str_ETAPHI
153  return self.panel_name
154 
155  # -----------------------------------------------------------------------
156  def setPanelProp(self, properties):
157  self.properties = properties
158 
159  self.stationName = self.properties["stationName"]
160  self.stationPhi = self.properties["stationPhi"]
161  self.stationEta = self.properties["stationEta"]
162  self.doubletR = self.properties["doubletR"]
163  self.doubletPhi = self.properties["doubletPhi"]
164  self.doubletZ = self.properties["doubletZ"]
165  self.gasGap = self.properties["gasGap"]
166  self.measPhi = self.properties["measPhi"]
167 
168  # -----------------------------------------------------------------------
169  def getLocalPos(self):
170  etaStation = abs(self.stationEta)
171  (sector, layer) = self.getSector()
172 
173  if self.stationName == 10 : #'BOG':
174  etaStation = 2*etaStation
175  elif self.stationName == 9:
176  etaStation = 2*etaStation-1
177 
178  if abs(sector) == 13 and self.stationName == 2: #BME BML
179  etaStation += 1
180 
181  return [etaStation, self.doubletZ, self.doubletPhi, self.measPhi]
182 
183 
184 if __name__ == '__main__':
185  print ("RPCRawDataMonUtils: Hello, World !")
RPCRawDataMonUtils.Panel
Definition: RPCRawDataMonUtils.py:76
RPCRawDataMonUtils.Panel.stationName
stationName
Definition: RPCRawDataMonUtils.py:88
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
RPCRawDataMonUtils.creatGraph
def creatGraph(xs, ys, x_errs, y_errs, g_name, g_title, g_Xtitle, g_Ytitle)
Definition: RPCRawDataMonUtils.py:8
RPCRawDataMonUtils.Panel.doubletR
doubletR
Definition: RPCRawDataMonUtils.py:129
RPCRawDataMonUtils.Panel.stationNames
stationNames
Definition: RPCRawDataMonUtils.py:104
RPCRawDataMonUtils.Panel.gasGap
gasGap
Definition: RPCRawDataMonUtils.py:165
RPCRawDataMonUtils.Panel.getLocalPos
def getLocalPos(self)
Definition: RPCRawDataMonUtils.py:169
RPCRawDataMonUtils.Panel.properties
properties
Definition: RPCRawDataMonUtils.py:157
RPCRawDataMonUtils.Panel.stationEta
stationEta
Definition: RPCRawDataMonUtils.py:161
RPCRawDataMonUtils.Panel.doubletPhi
doubletPhi
Definition: RPCRawDataMonUtils.py:163
RPCRawDataMonUtils.Panel.doubletZ
doubletZ
Definition: RPCRawDataMonUtils.py:164
RPCRawDataMonUtils.Panel.__init__
def __init__(self, properties, index)
Definition: RPCRawDataMonUtils.py:80
RPCRawDataMonUtils.Panel.index
index
Definition: RPCRawDataMonUtils.py:82
RPCRawDataMonUtils.Panel.measPhi
measPhi
Definition: RPCRawDataMonUtils.py:147
RPCRawDataMonUtils.linearFit
def linearFit(h_temp, opt="QNS+")
return type values: 1 : normal 0 : fit fail or (Not exist this quantity of certain panel) -1 : number...
Definition: RPCRawDataMonUtils.py:35
RPCRawDataMonUtils.Panel.getPanelName
def getPanelName(self)
Definition: RPCRawDataMonUtils.py:103
RPCRawDataMonUtils.Panel.getSector
def getSector(self)
Definition: RPCRawDataMonUtils.py:86
RPCRawDataMonUtils.Panel.setPanelProp
def setPanelProp(self, properties)
Definition: RPCRawDataMonUtils.py:156
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
str
Definition: BTagTrackIpAccessor.cxx:11
RPCRawDataMonUtils.Panel.panel_name
string panel_name
Definition: RPCRawDataMonUtils.py:77
RPCRawDataMonUtils.Panel.stationPhi
stationPhi
Definition: RPCRawDataMonUtils.py:160