Ejemplo n.º 1
0
 def analysis_main(self):
     run = ps.EventListReader(self.simulationFile)
     ringModel_event_infos = []
     medianR_event_infos = []
     knownC_event_infos = []
     hough_event_infos = []
     for event_id, event in enumerate(run):
         photon_clusters = ps.PhotonStreamCluster(event.photon_stream)
         hough_muonFeatures = detection(event, photon_clusters)
         ringM_muonFeatures = dwsrf(event, photon_clusters)
         if hough_muonFeatures["is_muon"]:
             hough_event_info = self.extract_with_hough(
                 event_id, hough_muonFeatures)
             hough_event_infos.append(hough_event_info)
         if ringM_muonFeatures["is_muon"]:
             ringModel_event_info = self.only_ringModel(
                 event_id, ringM_muonFeatures)
             ringModel_event_infos.append(ringModel_event_info)
             medianR_event_info = self.medianR_extraction(
                 ringM_muonFeatures, photon_clusters, event_id)
             medianR_event_infos.append(medianR_event_info)
             knownC_event_info = self.known_center(event_id,
                                                   photon_clusters)
             knownC_event_infos.append(knownC_event_info)
     data_to_be_saved = [
         ringModel_event_infos, medianR_event_infos, knownC_event_infos,
         hough_event_infos
     ]
     methods = ["ringM", "medianR", "knownC", "hough"]
     for method, data in zip(methods, data_to_be_saved):
         self.save_to_file(data, method)
Ejemplo n.º 2
0
def calculate_one_run(inpath, outpath):
    hough_responses = []
    run = ps.EventListReader(inpath)
    number_muons = 0
    for event in run:
        photon_clusters = ps.PhotonStreamCluster(event.photon_stream)
        cherenkov_cluster_mask = photon_clusters.labels >= 0
        cherenkov_point_cloud = photon_clusters.point_cloud
        cherenkov_clusters = cherenkov_point_cloud[cherenkov_cluster_mask]
        point_positions = cherenkov_clusters[:, 0:2]
        muon_props = detection(event, photon_clusters)
        if muon_props["is_muon"]:
            cx = muon_props["muon_ring_cx"]
            cy = muon_props["muon_ring_cy"]
            r = muon_props["muon_ring_r"]
            total_amplitude = evaluate_ring(point_positions, cx, cy, r)
            hough_responses.append(total_amplitude)
            number_muons += 1
    hough_responses = np.multiply(hough_responses, 100)
    psf_values = calculate_PSF(hough_responses)
    psf_error = psf_values * 1 / np.sqrt(number_muons)
    average_psf = float(np.average(psf_values))
    outdir = os.path.dirname(outpath)
    os.makedirs(outdir, exist_ok=True)
    with open(outpath + ".temp", "wt") as fout:
        out = {
            "average_psf": float(np.average(psf_values)),
            "psf_stdev": float(np.std(psf_values)),
            "standard_error": np.average(psf_error),
            "number_muons": number_muons
        }
        fout.write(json.dumps(out))
    os.rename(outpath + ".temp", outpath)
    return 0
Ejemplo n.º 3
0
 def extract_muons_from_run(self):
     run = ps.EventListReader(self.simulationFile)
     event_infos = []
     for i, event in enumerate(run):
         photon_clusters = ps.PhotonStreamCluster(event.photon_stream)
         muon_features = detection(event, photon_clusters)
         if muon_features["is_muon"]:
             event_id = i
             muon_ring_cx = muon_features['muon_ring_cx']
             muon_ring_cy = muon_features['muon_ring_cy']
             muon_ring_r = muon_features['muon_ring_r']
             mean_arrival_time_muon_cluster = muon_features[
                 'mean_arrival_time_muon_cluster']
             muon_ring_overlapp_with_field_of_view = muon_features[
                 'muon_ring_overlapp_with_field_of_view']
             number_of_photons = muon_features['number_of_photons']
             event_info = [
                 event_id, muon_ring_cx, muon_ring_cy, muon_ring_r,
                 mean_arrival_time_muon_cluster,
                 muon_ring_overlapp_with_field_of_view, number_of_photons
             ]
             header = list([
                 "event_id", "muon_ring_cx", "muon_ring_cy", "muon_ring_r",
                 "mean_arrival_time_muon_cluster",
                 "muon_ring_overlapp_with_field_of_view",
                 "number_of_photons"
             ])
             headers = ",".join(header)
             event_infos.append(event_info)
     np.savetxt(self.extracted_muons,
                event_infos,
                delimiter=",",
                comments='',
                header=headers)
Ejemplo n.º 4
0
 def run_detection(self, inpath):
     run = ps.EventListReader(inpath)
     path = os.path.normpath(inpath)
     split_path = path.split(os.sep)
     oa_name = split_path[-2]
     oa = re.split('_', oa_name)[2]
     preferences = self.read_preferencesFile()
     number_of_muons = preferences['--number_of_muons']
     found_muons = 0
     for event in run:
         clusters = ps.PhotonStreamCluster(event.photon_stream)
         muon_props = detection(event, clusters)
         if muon_props["is_muon"]:
             found_muons += 1
     return oa, found_muons, number_of_muons
Ejemplo n.º 5
0
 def run_job(self, job):
     results = []
     inpath = job["inpath"]
     output_path_responseH = job["output_path_responseH"]
     output_path_stdevR = job["output_path_stdevR"]
     output_path_responseR = job["output_path_responseR"]
     output_path_stdevH = job["output_path_stdevH"]
     muonCountH = 0
     muonCountR = 0
     run = ps.EventListReader(inpath)
     muon_ring_featuresR = []
     muon_ring_featuresH = []
     fuzziness_stdParamRs = []
     fuzziness_stdParamHs = []
     normed_responseRs = []
     normed_responseHs = []
     fuzz_paramsH = []
     for event_id, event in enumerate(run):
         photon_clusters = ps.PhotonStreamCluster(event.photon_stream)
         muon_propsR = ringM_detection(event, photon_clusters)
         muon_propsH = detection(event, photon_clusters)
         if muon_propsH["is_muon"]:
             muonCountH += 1
             normed_responseH, fuzziness_stdParamH = (
                 self.get_fuzziness_parameters(photon_clusters,
                                               muon_propsH))
             muon_ring_featureH = [
                 muon_propsH["muon_ring_cx"], muon_propsH["muon_ring_cy"],
                 muon_propsH["muon_ring_r"]
             ]
             muon_ring_featuresH.append(muon_ring_featureH)
             fuzziness_stdParamHs.append(fuzziness_stdParamH)
             normed_responseHs.append(normed_responseH)
         if muon_propsR["is_muon"]:
             muonCountR += 1
             normed_responseR, fuzziness_stdParamR = (
                 self.get_fuzziness_parameters(photon_clusters,
                                               muon_propsR))
             muon_ring_featureR = [
                 muon_propsR["muon_ring_cx"], muon_propsR["muon_ring_cy"],
                 muon_propsR["muon_ring_r"]
             ]
             fuzziness_stdParamRs.append(fuzziness_stdParamR)
             normed_responseRs.append(normed_responseR)
             muon_ring_featuresR.append(muon_ring_featureR)
     fact_path = fact.path.parse(inpath)
     night = fact_path["night"]
     run = fact_path["run"]
     filename = str(night) + "_" + str(run) + ".csv"
     output_dirR = os.path.dirname(output_path_stdevR)
     output_dirH = os.path.dirname(output_path_stdevH)
     if not os.path.isdir(output_dirR):
         os.makedirs(output_dirR, exist_ok=True)
     if not os.path.isdir(output_dirH):
         os.makedirs(output_dirH, exist_ok=True)
     self.save_to_file("ringM", output_dirR, filename, muon_ring_featuresR)
     self.save_to_file("hough", output_dirH, filename, muon_ring_featuresH)
     self.save_fuzz_param(output_path_stdevR, fuzziness_stdParamRs,
                          muonCountR)
     self.save_fuzz_param(output_path_responseR, normed_responseRs,
                          muonCountR)
     self.save_fuzz_param(output_path_stdevH, fuzziness_stdParamHs,
                          muonCountH)
     self.save_fuzz_param(output_path_responseH, normed_responseHs,
                          muonCountH)
     return 0