Created
October 26, 2017 09:06
-
-
Save Gotoryoo/c3964b1e38f48f160c61fa5c12be83c9 to your computer and use it in GitHub Desktop.
2017年10月26日に実施したプログラム勉強会で作成したpythonコードです。パターンマッチをして二次元ヒストグラムを作成します。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Thu Oct 26 16:31:23 2017 | |
@author: GTR | |
""" | |
import numpy as np | |
import cv2 | |
import re | |
import pandas as pd | |
from os.path import join, relpath | |
from glob import glob | |
import itertools | |
import ROOT | |
import math | |
from array import array | |
ROOT.std.__file__ = 'dummy_for_old_pyastro' | |
ROOT.gROOT.Reset() | |
path = "C:\\Users\\GTR\\Documents\\lab_log\\log\\programtraining" | |
path_dbeam = path + "\\" + "beam_4372-2_d.txt" | |
path_ubeam = path + "\\" + "beam_4372-2_u.txt" | |
fp_dbeam = open(path_dbeam,'r') | |
fp_ubeam = open(path_ubeam,'r') | |
data_dbeam = [] | |
data_ubeam = [] | |
for line in fp_dbeam: | |
data = {} | |
itemList = re.split("\s+", line.strip()) | |
if "#" in line: | |
continue | |
data['x'] = float(itemList[0]) | |
data['y'] = float(itemList[1]) | |
data_dbeam.append(data) | |
for line in fp_ubeam: | |
data = {} | |
itemList = re.split("\s+", line.strip()) | |
if itemList[0] == '#detectorx[mm]': | |
continue | |
data['x'] = float(itemList[0]) | |
data['y'] = float(itemList[1]) | |
data_ubeam.append(data) | |
c1 = ROOT.TCanvas('c1','Example with Formula',200,10,700,700) | |
h2dydx_dif = ROOT.TH2D("h2dydx","diff;x[mm];y[mm]",80, -0.4, 0.4, 80, -0.4, 0.4) | |
for dbeam , ubeam in itertools.product(data_dbeam,data_ubeam): | |
dx = dbeam['x']- ubeam['x'] | |
dy = dbeam['y']- ubeam['y'] | |
h2dydx_dif.Fill(dx,dy) | |
h2dydx_dif.Draw('colz') | |
mean_x = h2dydx_dif.GetMean(1) | |
mean_y = h2dydx_dif.GetMean(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment