def build_rt_relation(r,t, rt_id): gr=TGraph(len(r)) gr.SetName("gr_" + str(rt_id)) for i in range(0, len(r)): gr.SetPoint(i, r[i], t[i]) sp=TSpline3("sp_" + str(rt_id), gr) up = MuonFixedIdUnpack(rt_id) id_str=up.stationNameString() + "_" + str(up.stationPhi()) + "_" + str(up.stationEta()) gr.Write("gr_" + id_str) sp.Write("sp_" + id_str) return gr, sp
def get_tube_string(tube): try: mid = MuonFixedIdUnpack(tube) string = "%s_%s_%s" % (mid.stationNameString(),mid.stationPhi(),mid.stationEta()) return string except ValueError: # will throw exception if format doesn't match regex MuonFixedIdUnpack(tube) return tube
def ReadRtCool(db_string, folder, tag, run_number): try: db = AtlCoolLib.indirectOpen(db_string, oracle=True, readOnly=True, debug=True) except Exception as e: print('Problem opening database', e) sys.exit(-1) #get folder and tag cool_folder = db.getFolder(folder) cool_tag = ResolveTag(cool_folder, tag) #data to be filled graphs = {} splines = {} iovs = set([]) myiov = (run_number << 32) objs = cool_folder.browseObjects(myiov, myiov, cool.ChannelSelection.all(), cool_tag) for obj in objs: iov = (obj.since(), obj.until()) iovs.add(iov) sp = UnpackData(obj.payload()['data']).split('\n') sp1 = sp[0].split(',') chamber = int(sp1[0]) n_points = int(sp1[1]) sp2 = sp[1].split(',') graphs[chamber] = TGraphErrors(n_points) up = MuonFixedIdUnpack(chamber) if up.stationNameString() == 'XXX': print("Invalid station name in ", obj.payload()['file']) sys.exit(1) nm = up.stationNameString() + "_" + str(up.stationPhi()) + "_" + str( up.stationEta()) # print (nm) ts_applied = TimeSlewingApplied(obj) for i in range(0, n_points): r = float(sp2[3 * i]) t = float(sp2[3 * i + 1]) s = float(sp2[3 * i + 2]) if not ts_applied: t_new = NoTs2Ts(r, t) t = t_new graphs[chamber].SetPoint(i, r, t) graphs[chamber].SetPointError(i, 0, s) splines[chamber] = TSpline3("sp_" + nm, graphs[chamber]) if gDirectory.IsWritable(): splines[chamber].Write("sp_" + nm) graphs[chamber].Write("gr_" + nm) return graphs, splines, iovs
def extract_tubestring(fullstring): mid = MuonFixedIdUnpack() hardware_tubestring = mid.online_re.search(fullstring) software_tubestring = mid.offline_re.search(fullstring) numeric_tubestring = mid.numeric_re.search(fullstring) if (hardware_tubestring): return hardware_tubestring.group() if (software_tubestring): return software_tubestring.group() if (numeric_tubestring): # make sure it is not actually a date datematch = re.compile('(19|20)\d\d(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])') if not datematch.search(fullstring): return numeric_tubestring.group() return False
def dump_rt(ident, rt): up = MuonFixedIdUnpack(ident) if up.stationNameString() == "XXX": sys.stderr.write("WARNING: Unknown station found!\n") return f = file( "calibration/rts/Rt_" + str(up.stationNameString()) + "_" + str(up.stationPhi()) + "_" + str(up.stationEta()) + ".dat", "w") f.write("v1.0 1 Resolution 1 20000 0 0 0 0 dummy 800 ") f.write(str(rt.GetN())) f.write("\n") for i in xrange(rt.GetN()): f.write( str(rt.GetX()[i]) + " " + str(rt.GetY()[i]) + " " + str(rt.GetEY()[i])) f.write("\n")
t = [] v = [] r = array('f', 13 * [0.0]) for i in range(13): r[i] = float(i + 1) tree.Branch("r", r, "r[13]/F") #validflag=[] #adc=[] for i in range(2): t.append(array('f', 13 * [0.0])) v.append(array('f', 13 * [0.0])) tree.Branch("t_" + str(i), t[-1], "t_" + str(i) + "[13]/F") tree.Branch("v_" + str(i), v[-1], "v_" + str(i) + "[13]/F") for ident in all_stations: up = MuonFixedIdUnpack(ident) nm = up.stationNameString() for i in range(0, 3): station_nm[i] = nm[i] station_phi[0] = up.stationPhi() station_eta[0] = up.stationEta() for i in range(2): if not ident in cool_rts[i]: for j in range(13): t[i][j] = -9e9 v[i][j] = -9e9 continue theRt = cool_rts[i][ident] for j in range(13): t[i][j] = theRt.Eval(float(j + 1)) v[i][j] = 1 / theRt.Derivative(float(j + 1))
def get_tube_id(tube): mid=MuonFixedIdUnpack(tube) return mid.identifier
n_points_cool = array('i', [0]) dt13 = array('f', [0.0]) dr13 = array('f', [0.0]) dr = array('f', 100 * [0.0]) dt = array('f', 100 * [0.0]) tree.Branch("n_points", n_points, "n_points/I") tree.Branch("n_points_calib", n_points_calib, "n_points_calib/I") tree.Branch("n_points_cool", n_points_cool, "n_points_cool/I") tree.Branch("dt13", dt13, "dt13/F") tree.Branch("dr13", dr13, "dr13/F") for chamber_id in cool_gr: if chamber_id not in calib_gr: continue region_id[0] = chamber_id up = MuonFixedIdUnpack(chamber_id) st_str = up.stationNameString() for i in range(0, 3): station_nm[i] = st_str[i] station_phi[0] = up.stationPhi() station_eta[0] = up.stationEta() co_gr = cool_gr[chamber_id] co_sp = cool_sp[chamber_id] ca_gr = calib_gr[chamber_id] ca_sp = calib_sp[chamber_id] n_points[0] = min(co_gr.GetN(), ca_gr.GetN(), 100) n_points_calib[0] = ca_gr.GetN() n_points_cool[0] = co_gr.GetN() for i in range(i, n_points[0]): dr[i] = ca_gr.GetX()[i] dt[i] = ca_gr.GetY()[i]
def ReadT0CalibDb(db, reader_passwd, head_id): ra = CalibDbInfo.dbr[CalibDbInfo.calibdb] tns = CalibDbInfo.tns[CalibDbInfo.calibdb] connection=cx_Oracle.connect(ra, reader_passwd, tns) cursor=connection.cursor() data_schema=get_data_schema(cursor, db, head_id) query="select CHAMBER, TUBE_ID, TO_NUMBER(P4), VALIDFLAG, TO_NUMBER(ADC_0) from " + data_schema + ".MDT_TUBE where head_id=:hid and validflag>2 order by chamber" cursor.arraysize = 1000*400 cursor.execute(query, {'hid': head_id}) t0s={} current_values={} prev_chamber=None filled_chambers=set([]) for chamber, tube, t0, validflag, adc in cursor.fetchall(): if prev_chamber != chamber: if prev_chamber: up=MuonFixedIdUnpack(prev_chamber) t0s[(up.stationNameString(), up.stationPhi(), up.stationEta())] = build_t0_vec(current_values) filled_chambers.add(prev_chamber) prev_chamber = chamber current_values={} up=MuonFixedIdUnpack(tube) tid=288 * (up.mdtMultilayer() - 1) + 72 * (up.mdtTubeLayer() - 1) + (up.mdtTube() - 1 ) current_values[tid] = (t0, validflag, adc) up=MuonFixedIdUnpack(prev_chamber) t0s[(up.stationNameString(), up.stationPhi(), up.stationEta())] = build_t0_vec(current_values) return t0s
iovs = set([]) myiov = (run_number << 32) objs = cool_folder.browseObjects(myiov, myiov, cool.ChannelSelection.all(), cool_tag) for obj in objs: iov = (obj.since(), obj.until()) iovs.add(iov) sp = UnpackData(obj.payload()['data']).split('\n') sp1 = sp[0].split(',') chamber = int(sp1[0]) n_points = int(sp1[1]) sp2 = sp[1].split(',') graphs[chamber] = TGraphErrors(n_points) up = MuonFixedIdUnpack(chamber) if up.stationNameString() == 'XXX': print "Invalid station name in ", obj.payload()['file'] sys.exit(1) nm = up.stationNameString() + "_" + str(up.stationPhi()) + "_" + str( up.stationEta()) # print nm ts_applied = TimeSlewingApplied(obj) for i in range(0, n_points): r = float(sp2[3 * i]) t = float(sp2[3 * i + 1]) s = float(sp2[3 * i + 2]) if not ts_applied: t_new = NoTs2Ts(r, t) t = t_new graphs[chamber].SetPoint(i, r, t)