def calc_run_stats(run_id): """Calculates all the run statistics for a run for the database.""" srk_settings, run_settings = srkdata.get_settings_from_database(run_id) # Calculate all the statistics related to each orientation p_stats = calc_orientation_stats(run_id, True) a_stats = calc_orientation_stats(run_id, False) # Check if data for both orientations exists both_orientations = False if len(p_stats) > 0 or len(a_stats) > 0: both_orientations = True p_stats['DipolePositionBelowChamber'] = get_dist_bottom_from_pos(srk_settings['DipolePosition'], srk_settings['ChamberHeight']) pos = [float(x) for x in srk_settings['DipolePosition'].split(' ')] # Splits up space separates position list p_stats['DipolePositionX'] = pos[0] # Return here if both orientations if not both_orientations: return srkdata.merge_dicts(p_stats, a_stats) # Calculate stats related to frequency difference between orientaitons run_stats = srkdata.default_delta_omega_stats() if run_settings['RunType'] == 'deltaOmega': # ufloat - floats with uncertainty p_phase = ufloat(p_stats['Par_PhiMean'], p_stats['Par_PhiError']) a_phase = ufloat(a_stats['Anti_PhiMean'], a_stats['Anti_PhiError']) delta_phase = p_phase - a_phase elif run_settings['RunType'] == 'deltaOmegaSame': dp = calc_delta_stats_same_tracks(run_id) delta_phase = ufloat(dp[0], dp[1] / run_settings['NumTracksPer']) else: return srkdata.merge_dicts(p_stats, a_stats) print str(run_id) + ":" print "Delta Phase: " + str(delta_phase) delta_omega = delta_phase / srk_settings['TimeLimit'] print "Delta Omega: " + str(delta_omega) if srk_settings['E0FieldStrength'] == 0.: false_edm = ufloat(0., 0.) else: false_edm = calc_false_edm(delta_omega, srk_settings['E0FieldStrength']) print "False EDM: " + str(false_edm) run_stats['DeltaPhase'] = delta_phase.nominal_value run_stats['DeltaPhaseError'] = delta_phase.std_dev run_stats['DeltaOmega'] = delta_omega.nominal_value run_stats['DeltaOmegaError'] = delta_omega.std_dev run_stats['FalseEDM'] = false_edm.nominal_value run_stats['FalseEDMError'] = false_edm.std_dev pr_stats = calc_dipole_predictions_pignol_and_rocia(srk_settings) return srkdata.merge_dicts(run_stats, p_stats, a_stats, pr_stats)
def calc_orientation_stats(run_id, is_parallel): """Calc stats related to an orientation of the E0 and B0 fields (parallel and anti-parallel)""" if is_parallel: letter = 'P' run_type = 'Par' else: letter = 'A' run_type = 'Anti' file_path = srkdata.srkglobal.results_dir + "Results_RID" + str(run_id) + "_" + letter + ".root" stats = calc_stats_for_results_file(file_path) if len(stats) == 0: return {} stats = srkdata.prefix_dict_keys(stats, run_type + '_') srk_settings, run_settings = srkdata.get_settings_from_database(run_id) pr_stats = calc_dipole_predictions_pignol_and_rocia(srk_settings) return srkdata.merge_dicts(stats, pr_stats)
def calc_orientation_stats(run_id, is_parallel): """Calc stats related to an orientation of the E0 and B0 fields (parallel and anti-parallel)""" if is_parallel: letter = 'P' run_type = 'Par' else: letter = 'A' run_type = 'Anti' file_path = srkdata.srkglobal.results_dir + "Results_RID" + str( run_id) + "_" + letter + ".root" stats = calc_stats_for_results_file(file_path) if len(stats) == 0: return {} stats = srkdata.prefix_dict_keys(stats, run_type + '_') srk_settings, run_settings = srkdata.get_settings_from_database(run_id) pr_stats = calc_dipole_predictions_pignol_and_rocia(srk_settings) return srkdata.merge_dicts(stats, pr_stats)
def calc_run_stats(run_id): """Calculates all the run statistics for a nedm-type run for the database.""" srk_settings, run_settings = srkdata.get_settings_from_database(run_id) # Calculate all the statistics related to each orientation p_stats = calc_orientation_stats(run_id, True) a_stats = calc_orientation_stats(run_id, False) # Check if data for both orientations exists both_orientations = False if len(p_stats) > 0 or len(a_stats) > 0: both_orientations = True p_stats['DipolePositionBelowChamber'] = get_dist_bottom_from_pos( srk_settings['DipolePosition'], srk_settings['ChamberHeight']) pos = [float(x) for x in srk_settings['DipolePosition'].split(' ') ] # Splits up space separates position list p_stats['DipolePositionX'] = pos[0] # Return here if both orientations if not both_orientations: return srkdata.merge_dicts(p_stats, a_stats) # Calculate stats related to frequency difference between orientaitons run_stats = srkdata.default_delta_omega_stats() if run_settings['RunType'] == 'deltaOmega': # ufloat - floats with uncertainty p_phase = ufloat(p_stats['Par_PhiMean'], p_stats['Par_PhiError']) a_phase = ufloat(a_stats['Anti_PhiMean'], a_stats['Anti_PhiError']) delta_phase = p_phase - a_phase elif run_settings['RunType'] == 'deltaOmegaSame': dp = calc_delta_stats_same_tracks(run_id) delta_phase = ufloat(dp[0], dp[1] / run_settings['NumTracksPer']) else: return srkdata.merge_dicts(p_stats, a_stats) print str(run_id) + ":" print "Delta Phase: " + str(delta_phase) delta_omega = delta_phase / srk_settings['TimeLimit'] print "Delta Omega: " + str(delta_omega) if srk_settings['E0FieldStrength'] == 0.: false_edm = ufloat(0., 0.) else: false_edm = calc_false_edm(delta_omega, srk_settings['E0FieldStrength']) print "False EDM: " + str(false_edm) run_stats['DeltaPhase'] = delta_phase.nominal_value run_stats['DeltaPhaseError'] = delta_phase.std_dev run_stats['DeltaOmega'] = delta_omega.nominal_value run_stats['DeltaOmegaError'] = delta_omega.std_dev run_stats['FalseEDM'] = false_edm.nominal_value run_stats['FalseEDMError'] = false_edm.std_dev pr_stats = calc_dipole_predictions_pignol_and_rocia(srk_settings) return srkdata.merge_dicts(run_stats, p_stats, a_stats, pr_stats)