ATLAS Offline Software
CalibDbCompareT0.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 # we may want to modify to take reader password from CalibDbInfo for convenience
16 
17 def printhelp(argv0):
18  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")
19  sys.exit(1)
20 
21 optlist, args = getopt.gnu_getopt(sys.argv, 'hs:f:t:')
22 if not len(args)==5:
23  printhelp(args[0])
24 
25 for opt, oa in optlist:
26  if opt=='-s':
27  if oa[-2:]=='db':
28  cool_database_string = 'sqlite://;schema=' + oa + ';dbname=' + dbname
29  cool_tag=''
30  else:
31  cool_database_string = oa
32  continue
33  if opt=='-f':
34  cool_folder=oa
35  continue
36  if opt=='-t':
37  cool_tag=oa
38  continue
39 
40 run_number=int(args[1])
41 asp=args[2].split("/")
42 db=asp[0]
43 head_id=int(asp[1])
44 reader_password=args[3]
45 root_filename=args[4]
46 
47 sys.argv=[ sys.argv[0], '-b' ]
48 from ROOT import *
49 from array import *
52 
53 if not cool_tag:
54  cool_tag = GetFolderTag(cool_database_string, cool_folder)
55 
56 
57 print ("Cool database: " + cool_database_string + " " + cool_folder + " " + cool_tag + " " + str(run_number))
58 cool_t0s=ReadT0Cool(cool_database_string, cool_folder, cool_tag, run_number)
59 
60 print ("Calibration database: " + db + "/" + str(head_id))
61 calib_t0s=ReadT0CalibDb(db, reader_password, head_id)
62 print (len(calib_t0s), "chambers in calibration databse")
63 
64 outfile=TFile(root_filename, "RECREATE")
65 tree=TTree("tree", "t0 differences")
66 
67 station_nm=array('c', "BIL\0")
68 station_phi=array('i', [0])
69 station_eta=array('i', [0])
70 tree.Branch("station_nm", station_nm, "station_nm/C")
71 tree.Branch("station_phi", station_phi, "station_phi/I")
72 tree.Branch("station_eta", station_eta, "station_eta/I")
73 n_tubes=array('i', [0])
74 n_tubes_calib=array('i', [0])
75 n_tubes_cool=array('i', [0])
76 dt0=array('f', 432*[0.0])
77 t0_cool=array('f', 432*[0.0])
78 t0_calib=array('f', 432*[0.0])
79 d_validflag=array('i', 432*[0])
80 validflag_cool=array('i', 432*[0])
81 validflag_calib=array('i', 432*[0])
82 d_adc=array('f', 432*[0])
83 tree.Branch("n_tubes", n_tubes, "n_tubes/I")
84 tree.Branch("n_tubes_calib", n_tubes_calib, "n_tubes_calib/I")
85 tree.Branch("n_tubes_cool", n_tubes_cool, "n_tubes_cool/I")
86 tree.Branch("dt0", dt0, "dt0[n_tubes]/F")
87 
88 tree.Branch("t0_cool", t0_cool, "t0_cool[n_tubes]/F")
89 tree.Branch("t0_calib", t0_calib, "t0_calib[n_tubes]/F")
90 
91 
92 tree.Branch("d_validflag", d_validflag, "d_validflag[n_tubes]/I")
93 tree.Branch("validflag_cool", validflag_cool, "validflag_cool[n_tubes]/I")
94 tree.Branch("validflag_calib", validflag_calib, "validflag_calib[n_tubes]/I")
95 tree.Branch("d_adc", d_adc, "d_adc[n_tubes]/F")
96 
97 for chamber_id in cool_t0s:
98  if chamber_id not in calib_t0s:
99  n_tubes[0]=0
100  continue
101  for i in range(0,3):
102  station_nm[i]=chamber_id[0][i]
103  print (station_nm)
104  station_phi[0]=chamber_id[1]
105  station_eta[0]=chamber_id[2]
106  cot0s=cool_t0s[chamber_id]
107  cat0s=calib_t0s[chamber_id]
108  n_tubes[0]=min(len(cot0s), len(cat0s))
109  n_tubes_calib[0]=len(cat0s)
110  n_tubes_cool[0]=len(cot0s)
111  for i in range(0, n_tubes[0]):
112  dt0[i]=cot0s[i][0] - cat0s[i][0]
113  d_validflag[i]=cot0s[i][1] - cat0s[i][1]
114  validflag_cool[i]=cot0s[i][1]
115  validflag_calib[i]=cat0s[i][1]
116  d_adc[i]=cot0s[i][2] - cat0s[i][2]
117  t0_cool[i]=cot0s[i][0]
118  t0_calib[i]=cat0s[i][0]
119  tree.Fill()
120 
121 outfile.Write()
122 
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ReadCool.ReadT0Cool
def ReadT0Cool(db_string, folder, tag, run_number)
Definition: MuonSpectrometer/MuonCalib/MuonCalibDbOperations/python/ReadCool.py:123
CalibDbCompareT0.printhelp
def printhelp(argv0)
Definition: CalibDbCompareT0.py:17
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ReadCalibDb.ReadT0CalibDb
def ReadT0CalibDb(db, reader_passwd, head_id)
Definition: ReadCalibDb.py:73
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
str
Definition: BTagTrackIpAccessor.cxx:11
Trk::split
@ split
Definition: LayerMaterialProperties.h:38