ATLAS Offline Software
CalibDbCompareRT.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 
5 import getopt
6 import sys
7 import CalibDbDefaults
8 
9 calibtype = 'rt'
10 cool_database_string = CalibDbDefaults.cool_database_string
11 cool_folder = CalibDbDefaults.cool_folders[calibtype]
12 cool_tag = CalibDbDefaults.cool_tags[calibtype]
13 dbname = CalibDbDefaults.cool_dbname
14 
15 def printhelp(argv0):
16  sys.stderr.write("Usage: " + argv0 + " [-h] [-s <cool database string>] [-f <cool folder>] [-t <cool tag>] <run number> <calib db>/<head id> <reader password> <root file>\n")
17  sys.exit(1)
18 
19 optlist, args = getopt.gnu_getopt(sys.argv, 'hs:f:t:')
20 if not len(args)==5:
21  printhelp(args[0])
22 
23 for opt, oa in optlist:
24  if opt=='-s':
25  if oa[-2:]=='db':
26  cool_database_string = 'sqlite://;schema=' + oa + ';dbname=' + dbname
27  cool_tag=''
28  else:
29  cool_database_string = oa
30  continue
31  if opt=='-f':
32  cool_folder=oa
33  continue
34  if opt=='-t':
35  cool_tag=oa
36  continue
37 
38 run_number=int(args[1])
39 asp=args[2].split("/")
40 db=asp[0]
41 head_id=int(asp[1])
42 reader_password=args[3]
43 root_filename=args[4]
44 
45 sys.argv=[ sys.argv[0], '-b' ]
46 from ROOT import *
47 from array import *
51 
52 
53 outfile=TFile(root_filename, "RECREATE")
54 
55 if not cool_tag:
56  cool_tag = GetFolderTag(cool_database_string, cool_folder)
57 
58 outfile.mkdir("cool").cd()
59 print ("Cool database: " + cool_database_string + " " + cool_folder + " " + cool_tag + " " + str(run_number))
60 cool_gr, cool_sp, dummy=ReadRtCool(cool_database_string, cool_folder, cool_tag, run_number)
61 
62 outfile.mkdir("calibdb").cd()
63 print ("Calibration database: " + db + "/" + str(head_id))
64 calib_gr, calib_sp=ReadRtCalibDb(db, reader_password, head_id)
65 
66 outfile.cd()
67 tree=TTree("tree", "rt differences")
68 region_id=array('i', [0])
69 station_nm=array('c', "BIL\0")
70 station_phi=array('i', [0])
71 station_eta=array('i', [0])
72 tree.Branch("region_id", region_id, "region_id/I")
73 tree.Branch("station_nm", station_nm, "station_nm/C")
74 tree.Branch("station_phi", station_phi, "station_phi/I")
75 tree.Branch("station_eta", station_eta, "station_eta/I")
76 n_points=array('i', [0])
77 n_points_calib=array('i', [0])
78 n_points_cool=array('i', [0])
79 dt13=array('f', [0.0])
80 dr13=array('f', [0.0])
81 dr=array('f', 100*[0.0])
82 dt=array('f', 100*[0.0])
83 tree.Branch("n_points", n_points, "n_points/I")
84 tree.Branch("n_points_calib", n_points_calib, "n_points_calib/I")
85 tree.Branch("n_points_cool", n_points_cool, "n_points_cool/I")
86 tree.Branch("dt13", dt13, "dt13/F")
87 tree.Branch("dr13", dr13, "dr13/F")
88 
89 for chamber_id in cool_gr:
90  if chamber_id not in calib_gr:
91  continue
92  region_id[0]=chamber_id
93  up=MuonFixedIdUnpack(chamber_id)
94  st_str=up.stationNameString()
95  for i in range(0,3):
96  station_nm[i]=st_str[i]
97  station_phi[0]=up.stationPhi()
98  station_eta[0]=up.stationEta()
99  co_gr=cool_gr[chamber_id]
100  co_sp=cool_sp[chamber_id]
101  ca_gr=calib_gr[chamber_id]
102  ca_sp=calib_sp[chamber_id]
103  n_points[0] = min(co_gr.GetN(), ca_gr.GetN(), 100)
104  n_points_calib[0] = ca_gr.GetN()
105  n_points_cool[0] = co_gr.GetN()
106  for i in range(i, n_points[0]):
107  dr[i]=ca_gr.GetX()[i]
108  dt[i]=ca_gr.GetY()[i]
109  dt13[0] = ca_sp.Eval(13.0) - co_sp.Eval(13.0)
110  dr13[0] = dt13[0] / ca_sp.Derivative(13.0)
111  tree.Fill()
112 
113 outfile.Write()
114 
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MuonFixedIdUnpack
Definition: MuonFixedIdUnpack.py:1
ReadCalibDb.ReadRtCalibDb
def ReadRtCalibDb(db, reader_passwd, head_id)
Definition: ReadCalibDb.py:32
MuonFixedIdUnpack
CalibDbCompareRT.printhelp
def printhelp(argv0)
Definition: CalibDbCompareRT.py:15
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
min
#define min(a, b)
Definition: cfImp.cxx:40
array
ReadCool.GetFolderTag
def GetFolderTag(db_string, folder)
Definition: MuonSpectrometer/MuonCalib/MuonCalibDbOperations/python/ReadCool.py:159
ReadCalibDb
ReadCool
calibdata.cd
cd
Definition: calibdata.py:51
str
Definition: BTagTrackIpAccessor.cxx:11
ReadCool.ReadRtCool
def ReadRtCool(db_string, folder, tag, run_number)
Definition: MuonSpectrometer/MuonCalib/MuonCalibDbOperations/python/ReadCool.py:70
Trk::split
@ split
Definition: LayerMaterialProperties.h:38