ATLAS Offline Software
Loading...
Searching...
No Matches
CalibCoolCompareT0.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3
4import sys
5import getopt
6import CalibdDbDefaults
7
8cool_database_strings=[CalibDbDefaults.cool_database_string, CalibDbDefaults.cool_database_string]
9cool_folders=[CalibDbDefaults.cool_folders[calibtype], CalibDbDefaults.cool_folders[calibtype]]
10cool_tags=['COMCOND-BLKPST-004-07', 'COMCOND-BLKPST-004-07']
11run_numbers=[None, None]
12
13def printhelp(argv0):
14 sys.stderr.write("Usage: " + argv0 + " [-h] [-s <cool database string>] [-f <cool folder>] [-t <cool tag>] <run number 1> [-s <cool database string>] [-f <cool folder>] [-t <cool tag>] <run number 2> <root file>\n")
15 sys.exit(1)
16
17theArgs=sys.argv[1:]
18
19for i in range(2):
20 optlist, args = getopt.getopt(theArgs, 'hs:f:t:')
21
22 for opt, oa in optlist:
23 if opt=='-s':
24 if oa[-2:]=='db':
25 cool_database_strings[i] = 'sqlite://;schema=' + oa + ';dbname=COMP200'
26 cool_tags[i]=''
27 else:
28 cool_database_strings[i] = oa
29 continue
30 if opt=='-f':
31 cool_folders[i]=oa
32 continue
33 if opt=='-t':
34 cool_tags[i]=oa
35 continue
36 if opt=='-h':
37 printhelp(sys.argv[0])
38 continue
39 if len(args)<2:
40 sys.stderr.write("Error in commandline!\n")
41 printhelp(sys.argv[0])
42 try:
43 run_numbers[i]=int(args[0])
44 except ValueError:
45 sys.stderr.write("Error in commandline!\n")
46 printhelp(sys.argv[0])
47 theArgs=args[1:]
48
49if len(theArgs)!=1:
50 sys.stderr.write("Error in commandline!\n")
51 printhelp(sys.argv[0])
52
53outfile_nm=theArgs[0]
54
55print (cool_database_strings)
56print (cool_folders)
57print (cool_tags)
58print (run_numbers)
59print (outfile_nm)
60
61sys.argv=[sys.argv[0], '-b']
62
63from ROOT import *
64from array import *
65
67
68cool_t0s=[]
69
70for i in range(2):
71 if not cool_tags[i]:
72 cool_tags[i] = GetFolderTag(cool_database_strings[i], cool_folders[i])
73 print ("Cool database: " + cool_database_strings[i] + " " + cool_folders[i] + " " + cool_tags[i] + " " + str(run_numbers[i]))
74 cool_t0s.append(ReadT0Cool(cool_database_strings[i], cool_folders[i], cool_tags[i], run_numbers[i]))
75
76
77all_stations=set(cool_t0s[0].keys()).union(set(cool_t0s[1].keys()))
78
79
80outfile=TFile(outfile_nm, "RECREATE")
81tree=TTree("tree", "t0 differences")
82
83station_nm=array('c', "BIL\0")
84station_phi=array('i', [0])
85station_eta=array('i', [0])
86tree.Branch("station_nm", station_nm, "station_nm/C")
87tree.Branch("station_phi", station_phi, "station_phi/I")
88tree.Branch("station_eta", station_eta, "station_eta/I")
89
90n_tubes=[]
91t0=[]
92t0_mean=[]
93t0_min=[]
94t0_max=[]
95#validflag=[]
96#adc=[]
97for i in range(2):
98 n_tubes.append(array('i', [0]))
99 tree.Branch("n_tubes_" + str(i), n_tubes[-1], "n_tubes_" + str(i) + "/I")
100 t0.append(array('f', 432*[0.0]))
101 tree.Branch("t0_" + str(i), t0[-1], "t0_" + str(i) + "[n_tubes_" + str(i) + "]/F")
102 t0_mean.append(array('f', [0.0]))
103 tree.Branch("t0_mean_" + str(i), t0_mean[-1], "t0_mean_" + str(i) + "/F")
104 t0_min.append(array('f', [0.0]))
105 tree.Branch("t0_min_" + str(i), t0_min[-1], "t0_min_" + str(i) + "/F")
106 t0_max.append(array('f', [0.0]))
107 tree.Branch("t0_max_" + str(i), t0_max[-1], "t0_max_" + str(i) + "/F")
108
109
110for ident in all_stations:
111 for i in range(0,3):
112 station_nm[i]=ident[0][i]
113 station_phi[0]=ident[1]
114 station_eta[0]=ident[2]
115 for i in range(2):
116 if not ident in cool_t0s[i]:
117 n_tubes[i][0]=0
118 t0_mean[i][0]=9e9
119 t0_min[i][0]=9e9
120 t0_max[i][0]=9e9
121 continue
122 t0_mean[i][0]=0.0
123 t0_min[i][0]=9e9
124 t0_max[i][0]=-9e9
125 theT0s=cool_t0s[i][ident]
126 n_tubes[i][0]=len(theT0s)
127 for j in range(n_tubes[i][0]):
128 t0_mean[i][0]+=theT0s[j][0]
129 if t0_min[i][0]>theT0s[j][0]:
130 t0_min[i][0]=theT0s[j][0]
131 if t0_max[i][0]<theT0s[j][0]:
132 t0_max[i][0]=theT0s[j][0]
133 t0[i][j]=theT0s[j][0]
134 t0_mean[i][0]/=float(n_tubes[i][0])
135 tree.Fill()
136outfile.Write()
137
138
139
140
141
STL class.
STL class.