|
| 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