Skip to content

Commit 9e837c9

Browse files
authored
Merge pull request #129 from JeffersonLab/primex_tools
PrimEx tools
2 parents 6b18465 + 8fb7ede commit 9e837c9

File tree

4 files changed

+559
-0
lines changed

4 files changed

+559
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env python
2+
3+
# Plot masked channels in FCAL
4+
# A.S
5+
6+
import os,sys
7+
import rcdb
8+
from ROOT import TFile,TGraph,TH1F,TF1,gRandom, FILE
9+
from optparse import OptionParser
10+
from array import array
11+
from datetime import datetime
12+
import pprint
13+
import math
14+
import MySQLdb
15+
16+
import ccdb
17+
from ccdb import Directory, TypeTable, Assignment, ConstantSet
18+
19+
def LoadCCDB():
20+
sqlite_connect_str = "mysql://ccdb_user@hallddb.jlab.org/ccdb"
21+
# sqlite_connect_str = "sqlite:////home/somov/ccdb.sqlite"
22+
provider = ccdb.AlchemyProvider() # this class has all CCDB manipulation functions
23+
provider.connect(sqlite_connect_str) # use usual connection string to connect to database
24+
provider.authentication.current_user_name = "somov" # to have a name in logs
25+
26+
return provider
27+
28+
def loadCCDBContextList(runPeriod, restVer):
29+
dbhost = "hallddb.jlab.org"
30+
dbuser = 'datmon'
31+
dbpass = ''
32+
dbname = 'data_monitoring'
33+
34+
conn=MySQLdb.connect(host=dbhost, user=dbuser, db=dbname)
35+
curs=conn.cursor()
36+
37+
cmd = "SELECT revision,ccdb_context FROM version_info WHERE run_period=%s AND data_type='recon' AND revision<=%s ORDER BY revision DESC"
38+
curs.execute(cmd, [runPeriod, restVer])
39+
rows=curs.fetchall()
40+
return rows
41+
42+
43+
def main():
44+
45+
VARIATION = "default"
46+
47+
parser = OptionParser(usage = "plot_flux_ccdb.py --begin-run beginRun --end-run endRun")
48+
49+
parser.add_option("-b","--begin-run", dest="begin_run",
50+
help="Starting run for output")
51+
52+
parser.add_option("-e","--end-run", dest="end_run",
53+
help="Ending run for output")
54+
55+
(options, args) = parser.parse_args(sys.argv)
56+
57+
FIRST_RUN = int(options.begin_run)
58+
59+
run_number = FIRST_RUN
60+
61+
OUTPUT_FILE_TAGH = "%d_tagh_ps_acc_cor.txt" %(FIRST_RUN)
62+
63+
print(FIRST_RUN)
64+
65+
66+
67+
ccdb_conn = LoadCCDB()
68+
69+
70+
timing_offsets_assignment = ccdb_conn.get_assignment("/PHOTON_BEAM/pair_spectrometer/fine/adc_timing_offsets",run_number, VARIATION)
71+
72+
timing_offsets = timing_offsets_assignment.constant_set.data_table
73+
74+
75+
OUTPUT_FILE = "adc_time_offsets_%d.txt" %(FIRST_RUN)
76+
77+
data_file = open(OUTPUT_FILE,"w+");
78+
79+
for ii in range(145):
80+
81+
data_file.write("%10.5f %10.5f \n" %(float(timing_offsets[ii][0]),float(timing_offsets[ii][1])))
82+
83+
84+
85+
86+
## main function
87+
if __name__ == "__main__":
88+
main()

PrimEx/fcal_masks/fcal_mask.py

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
#!/usr/bin/env python
2+
3+
# Plot masked channels in FCAL
4+
# A.S
5+
6+
import os,sys
7+
import rcdb
8+
from ROOT import TFile,TGraph,TH1F,TF1,gRandom, FILE
9+
from optparse import OptionParser
10+
from array import array
11+
from datetime import datetime
12+
import pprint
13+
import math
14+
import MySQLdb
15+
16+
import ccdb
17+
from ccdb import Directory, TypeTable, Assignment, ConstantSet
18+
19+
def LoadCCDB():
20+
sqlite_connect_str = "mysql://ccdb_user@hallddb.jlab.org/ccdb"
21+
# sqlite_connect_str = "sqlite:////home/somov/ccdb.sqlite"
22+
provider = ccdb.AlchemyProvider() # this class has all CCDB manipulation functions
23+
provider.connect(sqlite_connect_str) # use usual connection string to connect to database
24+
provider.authentication.current_user_name = "somov" # to have a name in logs
25+
26+
return provider
27+
28+
def loadCCDBContextList(runPeriod, restVer):
29+
dbhost = "hallddb.jlab.org"
30+
dbuser = 'datmon'
31+
dbpass = ''
32+
dbname = 'data_monitoring'
33+
34+
conn=MySQLdb.connect(host=dbhost, user=dbuser, db=dbname)
35+
curs=conn.cursor()
36+
37+
cmd = "SELECT revision,ccdb_context FROM version_info WHERE run_period=%s AND data_type='recon' AND revision<=%s ORDER BY revision DESC"
38+
curs.execute(cmd, [runPeriod, restVer])
39+
rows=curs.fetchall()
40+
return rows
41+
42+
43+
def main():
44+
45+
VARIATION = "default"
46+
47+
parser = OptionParser(usage = "plot_flux_ccdb.py --begin-run beginRun --end-run endRun")
48+
49+
parser.add_option("-b","--begin-run", dest="begin_run",
50+
help="Starting run for output")
51+
52+
parser.add_option("-e","--end-run", dest="end_run",
53+
help="Ending run for output")
54+
55+
(options, args) = parser.parse_args(sys.argv)
56+
57+
FIRST_RUN = int(options.begin_run)
58+
59+
run_number = FIRST_RUN
60+
61+
OUTPUT_FILE_TAGH = "%d_tagh_ps_acc_cor.txt" %(FIRST_RUN)
62+
63+
print(FIRST_RUN)
64+
65+
66+
ccdb_conn = LoadCCDB()
67+
68+
69+
aaa = TH1F("TAGH Tagged Flux","TAGH Tagged Flux",300,0.5,299.5)
70+
71+
72+
block_quality_assignment = ccdb_conn.get_assignment("/FCAL/block_quality",run_number, VARIATION)
73+
74+
block_quality = block_quality_assignment.constant_set.data_table
75+
76+
77+
78+
kBeamHoleSize = 3
79+
80+
blockSize = 4.0157
81+
82+
radius = 120.471
83+
84+
85+
MidBlock = 29
86+
87+
innerRadius = ( int(kBeamHoleSize) - 1 ) / 2. * float(blockSize) * math.sqrt(2.)
88+
89+
innerRadius *= 1.01
90+
91+
92+
mod_x = []
93+
mod_y = []
94+
95+
index = 0
96+
97+
98+
for row_tmp in range(59):
99+
for column_tmp in range(59):
100+
101+
x_block = (int(column_tmp) - MidBlock ) * float(blockSize)
102+
y_block = (int(row_tmp) - MidBlock ) * float(blockSize)
103+
104+
thisRadius = math.sqrt(x_block*x_block + y_block*y_block)
105+
106+
if thisRadius < radius:
107+
if thisRadius > innerRadius:
108+
109+
print(thisRadius)
110+
111+
mod_x.append(row_tmp)
112+
mod_y.append(column_tmp)
113+
114+
index = index + 1
115+
116+
117+
118+
print("Dead Channels \n");
119+
120+
121+
dead_all = 0
122+
dead_inner = 0
123+
124+
susp_all = 0
125+
susp_inner = 0
126+
127+
128+
for ii in range(2800):
129+
130+
quality = int(block_quality[ii][0])
131+
132+
if int(block_quality[ii][0]) == 1:
133+
134+
135+
row_cent = mod_x[ii] - 29
136+
column_cent = mod_y[ii] - 29
137+
138+
module_y = float(row_cent*4.)
139+
module_x = float(column_cent*4.)
140+
141+
142+
143+
print("Run %d %d %d %d %d \n" %(run_number,ii, int(block_quality[ii][0]),mod_x[ii],mod_y[ii]))
144+
145+
print("Row = %d Column = %d X = %f Y = %f \n"%(row_cent,column_cent, module_x, module_y))
146+
147+
dead_all = dead_all + 1
148+
149+
if abs(module_x) < 40 and abs(module_y) < 40:
150+
151+
dead_inner = dead_inner + 1;
152+
153+
154+
print("\n");
155+
print("\n");
156+
157+
158+
print("Suspicious Channels \n");
159+
160+
for ii in range(2800):
161+
162+
quality = int(block_quality[ii][0])
163+
164+
if int(block_quality[ii][0]) == 5:
165+
166+
167+
row_cent = mod_x[ii] - 29
168+
column_cent = mod_y[ii] - 29
169+
170+
module_y = float(row_cent*4.)
171+
module_x = float(column_cent*4.)
172+
173+
174+
175+
susp_all = susp_all + 1
176+
177+
if abs(module_x) < 40 and abs(module_y) < 40:
178+
179+
susp_inner = susp_inner + 1;
180+
181+
182+
# Print all bad channels
183+
184+
print("Run %d %d %d %d %d \n" %(run_number,ii, int(block_quality[ii][0]),
185+
mod_x[ii],mod_y[ii]))
186+
187+
print("Row = %d Column = %d X = %f Y = %f \n"%(row_cent,column_cent,
188+
module_x, module_y))
189+
190+
191+
192+
193+
194+
print("\n");
195+
print("\n");
196+
197+
198+
print("Dead Channels: ALL (INNER) = %d (%d) Susp Channels: ALL(INNER) %d (%d) \n"%(dead_all,dead_inner,susp_all,susp_inner) );
199+
200+
201+
202+
203+
# print("Run %d %d %d %d %d\n" %(run_number,ii, int(block_quality[ii][0]),row,column))
204+
# print(block_quality[ii][0])
205+
206+
207+
208+
## main function
209+
if __name__ == "__main__":
210+
main()

0 commit comments

Comments
 (0)