All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
convert_Noise_ROOTtoJSON.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # coding: utf-8
3 import ROOT
4 from ROOT import TCanvas, TPad, TFormula, TF1, TPaveLabel, TH1F, TFile
5 import sys
6 import json
7 import os
8 import numpy
9 
10 #Run Script in the same directory with 4 Fillipo's noise files : "dataFFTHistosEE.root","dataFFTHistosEW.root","dataFFTHistosWE.root","dataFFTHistosWW.root"
11 #Script will produce 8 .json.bz2 files (4 for int noise and 4 for coh). These files can be copied to WireCellData
12 
13 def get_freq_amps(hist):
14  freq=[]
15  amps=[]
16  for i in range(0,hist.GetXaxis().GetNbins()):
17  freq.append(hist.GetBinLowEdge(i+1)*pow(10,-6))
18  amps.append(hist.GetBinContent(i+1)*pow(10,-9)*3.3*pow(10,3)/4095.0)#*pow(10,-9))#*pow(10,-9))
19  for i in range(hist.GetXaxis().GetNbins(),0,-1):
20  amps.append(hist.GetBinContent(i)*pow(10,-9)*3.3*pow(10,3)/4095.0)#*pow(10,-9))
21  for i in range(0,hist.GetXaxis().GetNbins()):
22  freq.append(hist.GetBinLowEdge(hist.GetXaxis().GetNbins()+1)*pow(10,-6)+hist.GetBinLowEdge(i+1)*pow(10,-6))
23  return freq,amps
24 
25 def load_noise_spectra(filenames):
26  noise_type = "int"
27  for filename in filenames:
28 
29  noises = list()
30  modelFile = TFile.Open(filename,"READ")
31  tpcName=filename.replace('.root','')
32  tpcName=tpcName[-2:]
33  powerHist_ind1 = modelFile.Get(noise_type+"powerI1")
34  fr_ind1,amps_ind1 = get_freq_amps(powerHist_ind1)
35  powerHist_ind2 = modelFile.Get(noise_type+"powerI2")
36  fr_ind2,amps_ind2 = get_freq_amps(powerHist_ind2)
37  powerHist_coll = modelFile.Get(noise_type+"powerC")
38  fr_coll,amps_coll = get_freq_amps(powerHist_coll)
39  freq = [fr_ind1,fr_ind2,fr_coll]
40  amps = [amps_ind1,amps_ind2,amps_coll]
41  gain = [8.811970678500002e-10,8.811970678500002e-10,8.811970678500002e-10]
42  period = [400.0,400.0,400.0]
43  nsamples = [powerHist_ind1.GetXaxis().GetNbins()*2,powerHist_ind2.GetXaxis().GetNbins()*2,powerHist_coll.GetXaxis().GetNbins()*2]
44  shaping = [1.3,1.3,1.3]
45  wirelen = [8949.51,3658.0939799999996,3658.0939799999996]
46  const = [0.0,0.0,0.0]
47  for n in range(0,3):
48  ns = { 'period' : period[n],
49  'nsamples' : nsamples[n],
50  'gain' : gain[n],
51  'shaping' : shaping[n],
52  'wirelen': wirelen[n],
53  'const' : const[n],
54  'plane' : n,
55  'tpcname' : tpcName,
56  'freqs' : list(freq[n]),
57  'amps' : list(amps[n])
58  }
59  noises.append(ns)
60  json_format = json.dumps(noises,indent=4)
61  int_noise_file = open('icarus_noise_model_'+noise_type+'_TPC'+tpcName+'.json','w')
62  int_noise_file.write(json_format)
63  int_noise_file.close()
64  return 1
65 
67  noise_type = "coh"
68  for filename in filenames:
69  noises = list()
70  modelFile = TFile.Open(filename,"READ")
71  tpcName=filename.replace('.root','')
72  tpcName=tpcName[-2:]
73  powerHist_ind1 = modelFile.Get(noise_type+"powerI1")
74  fr_ind1,amps_ind1 = get_freq_amps(powerHist_ind1)
75  powerHist_ind2 = modelFile.Get(noise_type+"powerI2")
76  fr_ind2,amps_ind2 = get_freq_amps(powerHist_ind2)
77  powerHist_coll = modelFile.Get(noise_type+"powerC")
78  fr_coll,amps_coll = get_freq_amps(powerHist_coll)
79  freq = [fr_ind1,fr_ind2,fr_coll]
80  amps = [amps_ind1,amps_ind2,amps_coll]
81  gain = [8.811970678500002e-10,8.811970678500002e-10,8.811970678500002e-10]
82  period = [400.0,400.0,400.0]
83  nsamples = [powerHist_ind1.GetXaxis().GetNbins()*2,powerHist_ind2.GetXaxis().GetNbins()*2,powerHist_coll.GetXaxis().GetNbins()*2]
84  shaping = [1.3,1.3,1.3]
85  const = [0.0,0.0,0.0]
86 
87  #Due to the bug in WC code 1st set of channels has only channel 0 (it will have NO coherent noise)
88  #the next group would be 31 channel and the rest are all 32 channel group
89  ns_0 = { 'period' : period[0],
90  'nsamples' : nsamples[0],
91  'gain' : gain[0],
92  'shaping' : shaping[0],
93  'wire-delta': 1.0,
94  'const' : const[0],
95  'tpcname' : tpcName,
96  'freqs' : list(freq[0]),
97  'amps' : list(amps[0])
98  }
99  noises.append(ns_0)
100  ns_1 = { 'period' : period[0],
101  'nsamples' : nsamples[0],
102  'gain' : gain[0],
103  'shaping' : shaping[0],
104  'wire-delta': 31.0,
105  'const' : const[0],
106  'tpcname' : tpcName,
107  'freqs' : list(freq[0]),
108  'amps' : list(amps[0])
109  }
110  noises.append(ns_1)
111  #Group for induction 1 tarts from 1 to accomodate for the bug
112  for group in range(1,66):#72
113  ns = { 'period' : period[0],
114  'nsamples' : nsamples[0],
115  'gain' : gain[0],
116  'shaping' : shaping[0],
117  'wire-delta': 32.0,
118  'const' : const[0],
119  'tpcname' : tpcName,
120  'freqs' : list(freq[0]),
121  'amps' : list(amps[0])
122  }
123  noises.append(ns)
124  for group in range(0,175):#180
125  ns = { 'period' : period[0],
126  'nsamples' : nsamples[0],
127  'gain' : gain[0],
128  'shaping' : shaping[0],
129  'wire-delta': 32.0,
130  'const' : const[0],
131  'tpcname' : tpcName,
132  'freqs' : list(freq[1]),
133  'amps' : list(amps[1])
134  }
135  noises.append(ns)
136  for group in range(0,175):#180
137  ns = { 'period' : period[0],
138  'nsamples' : nsamples[0],
139  'gain' : gain[0],
140  'shaping' : shaping[0],
141  'wire-delta': 32.0,
142  'const' : const[0],
143  'tpcname' : tpcName,
144  'freqs' : list(freq[2]),
145  'amps' : list(amps[2])
146  }
147  noises.append(ns)
148  json_format = json.dumps(noises,indent=4)
149  int_noise_file = open('icarus_noise_model_'+noise_type+'_TPC'+tpcName+'.json','w')
150  int_noise_file.write(json_format)
151  int_noise_file.close()
152  return 1
153 
154 print("Start Job")
155 json_out_int = load_noise_spectra(["dataFFTHistosEE.root","dataFFTHistosEW.root","dataFFTHistosWE.root","dataFFTHistosWW.root"])
156 json_out_coh = load_coherent_noise_spectra(["dataFFTHistosEE.root","dataFFTHistosEW.root","dataFFTHistosWE.root","dataFFTHistosWW.root"])
157 #compress files to make tham wirecell compatable
158 bashCommand = "bzip2 -zf icarus_noise_model_*"
159 os.system(bashCommand)
160 print("Finished Job")
do one_file $F done echo for F in find $TOP name CMakeLists txt print
list
Definition: file_to_url.sh:28
open(RACETRACK) or die("Could not open file $RACETRACK for writing")