diff --git a/scripts/checkPulseData.py b/scripts/checkPulseData.py index 572b85d..9a012f5 100644 --- a/scripts/checkPulseData.py +++ b/scripts/checkPulseData.py @@ -12,39 +12,41 @@ # Voltage steps voltMapTT = [None] * 11 -voltMapTT[0] = 400 -voltMapTT[1] = 350 -voltMapTT[2] = 300 -voltMapTT[3] = 250 -voltMapTT[4] = 225 -voltMapTT[5] = 200 -voltMapTT[6] = 175 -voltMapTT[7] = 150 -voltMapTT[8] = 125 -voltMapTT[9] = 100 -voltMapTT[10] = 60 +voltMapTT[0] = 400 +voltMapTT[1] = 350 +voltMapTT[2] = 300 +voltMapTT[3] = 250 +voltMapTT[4] = 225 +voltMapTT[5] = 200 +voltMapTT[6] = 175 +voltMapTT[7] = 150 +voltMapTT[8] = 125 +voltMapTT[9] = 100 +voltMapTT[10] = 60 voltMapIT = [None] * 11 -voltMapIT[0] = 300 -voltMapIT[1] = 200 -voltMapIT[2] = 170 -voltMapIT[3] = 140 -voltMapIT[4] = 120 -voltMapIT[5] = 105 -voltMapIT[6] = 90 -voltMapIT[7] = 75 -voltMapIT[8] = 60 -voltMapIT[9] = 40 -voltMapIT[10] = 20 +voltMapIT[0] = 300 +voltMapIT[1] = 200 +voltMapIT[2] = 170 +voltMapIT[3] = 140 +voltMapIT[4] = 120 +voltMapIT[5] = 105 +voltMapIT[6] = 90 +voltMapIT[7] = 75 +voltMapIT[8] = 60 +voltMapIT[9] = 40 +voltMapIT[10] = 20 # Time steps + + def get_tmap(): timeMap = [None] * 6 - timeMap[0] = 0.0 - timeMap[1] = -60.0 - timeMap[2] = -30.0 - timeMap[3] = 30.0 - timeMap[4] = 60.0 - timeMap[5] = 90.0 + timeMap[0] = 0.0 + timeMap[1] = -60.0 + timeMap[2] = -30.0 + timeMap[3] = 30.0 + timeMap[4] = 60.0 + timeMap[5] = 90.0 return timeMap @@ -79,7 +81,9 @@ # Helpers for string formatting # based on http://stackoverflow.com/a/23305496/3324012 class StringTemplate(object): + class FormatDict(dict): + def __missing__(self, key): return "{" + key + "}" @@ -92,14 +96,15 @@ def format(self, *args, **kwargs): mapping = StringTemplate.FormatDict(*args, **kwargs) - self.substituted_str = self.formatter.vformat(self.substituted_str, (), mapping) + self.substituted_str = self.formatter.vformat( + self.substituted_str, (), mapping) return self.substituted_str class Table(dict): '''Dictionary tweaked for conversion into pandas DataFrame - - Dictionary conversion into DataFrames is faster than + + Dictionary conversion into DataFrames is faster than appending rows to a DataFrame, as pointed out here: http://stackoverflow.com/a/17496530/3324012 ''' @@ -123,7 +128,7 @@ datafile = r.TFile(location + 'CCEScan.root', 'read') - # Select detector + # Select detector detector = 'TT' nstrips = [3, 5, 7] layer = 'TTaU' @@ -132,7 +137,6 @@ nstrips = [7] layer = 'T3X2' - # Load fill numbers with open(macros + 'Fills.dat', 'rb') as f: fills = f.read().splitlines() @@ -143,13 +147,15 @@ sectors = f.read().splitlines() # Load voltage map vmap = get_vmap(detector) - + # String templates access = StringTemplate('{DET}/{LAY}/{SEC}/{FILL}/v_{CS}_val{NS}') access = access.format(DET=detector, LAY=layer) - warning = StringTemplate('{LAY}/{SEC} on fill {FILL}: pulse is monotonic for ns={NS}, Vbias={V}: \t {PULSE}') + warning = StringTemplate( + '{LAY}/{SEC} on fill {FILL}: pulse is monotonic for ns={NS}, Vbias={V}: \t {PULSE}') warning = warning.format(LAY=layer) - not_found = StringTemplate('{LAY}/{SEC} on fill {FILL}: calibration step {CS} not found for ns={NS}') + not_found = StringTemplate( + '{LAY}/{SEC} on fill {FILL}: calibration step {CS} not found for ns={NS}') not_found = not_found.format(LAY=layer) # Init dictionary for data frame @@ -162,7 +168,7 @@ # Loop on voltages for vstep in range(11): pulse = [] - for cstep in range(6*vstep, 6*vstep + 6): + for cstep in range(6 * vstep, 6 * vstep + 6): try: data = datafile.Get(access.format(NS=ns, FILL=fill, @@ -178,10 +184,11 @@ pulse.append(None) pulse = build_pulse(pulse) # Append this occurrence to the data frame dictionary - table.append(detector, sector, fill, ns, vmap[vstep], pulse) + table.append(detector, sector, fill, + ns, vmap[vstep], pulse) if is_monotonic(pulse): if VERBOSE: - pulse = [round(v,2) for v in pulse] + pulse = [round(v, 2) for v in pulse] print(warning.format(NS=ns, FILL=fill, SEC=sector,