-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.py
74 lines (63 loc) · 2.38 KB
/
info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
###############################
#
# define training related variables as well as other functions
# needed to train
#
##############################
import numpy as np
import pandas as pd
import os
import ROOT
import uproot
import uproot_methods
import pickle
import sys
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
import glob
import matplotlib.pyplot as plt
import root_numpy
#Define variables for bulk training
year = 2016
norm_cut = 10000 ## changing normcut for now because nothing is passing
max_bins = None
title = None
lumi_json = None
hpath = "DQMData/Run {}/DT/Run summary"
plots = [("02-Segments/Wheel0/Sector1/Station1","T0_FromSegm_W0_Sec1_St1")]
#plots=list() #[('02-Segments/Wheel0/Sector13/Station1', 'T0_FromSegm_W0_Sec13_St1')]
#plots.append(('02-Segments/Wheel2/Sector9/Station4','T0_FromSegm_W2_Sec9_St4'))
#plots.append(('02-Segments/Wheel2/Sector11/Station4','T0_FromSegm_W2_Sec11_St4'))
# for Sec in range(1,15):
# for St in [1,2,3,4]:
# plots.append((f'02-Segments/Wheel0/Sector{Sec}/Station{St}', f'T0_FromSegm_W0_Sec{Sec}_St{St}'))
# for Sec in range(1,7):
# for St in [1,2,3,4]:
# plots.append((f'02-Segments/Wheel1/Sector{Sec}/Station{St}', f'T0_FromSegm_W1_Sec{Sec}_St{St}'))
# for W in [0]:
# for Sec in range(1,2):
# for St in [1,2,3,4]:
# plots.append((f'02-Segments/Wheel{W}/Sector{Sec}/Station{St}', f'T0_FromSegm_W{W}_Sec{Sec}_St{St}'))
## define what plots to train
## each tuple is (dirname, histname)
#HistogramIntegral returns the total number of events
def HistogramIntegral(hist):
return sum(hist[0][i] for i in range(len(hist[0])))
## loops through directory in root file and returns the histogram path and a numpy
## of the histogram. This replaces uproot.allItems() as DT plots struggle with uproot
def getTH1(d, h):
keyName = d.GetDirectory(h)
for key in keyName.GetListOfKeys():
obj = keyName.Get(key.GetName())
## this is so we don't return a null pointer
if obj:
objName = obj.GetName()
if obj.IsFolder():
for i in getTH1(d, h+'/'+objName):
yield i
else:
if obj.InheritsFrom('TH1'):
yield (h+'/'+objName, root_numpy.hist2array(obj, return_edges=True))
else:
continue