Created
October 28, 2018 15:49
-
-
Save bdorney/af4ae6de82815c34d42b4bf46ce8e463 to your computer and use it in GitHub Desktop.
P5 Sustained Operations gist
This file contains 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
from gempython.gemplotting.mapping.chamberInfo import chamber_config | |
from gempython.utils.nesteddict import nesteddict as ndict | |
import ROOT as r | |
dict_Histos = ndict() | |
for link,chamber in chamber_config.iteritems(): | |
dict_Histos[chamber] = r.TH1F("h_{0}_dV".format(chamber),"Voltage Fluctuations for {0}".format(chamber),500,-0.5,499.5) | |
dict_Histos[chamber].Sumw2() | |
""" | |
If you have a tab delimited file you can fill these histograms easily, example: | |
ChamberName VoltageFluctuation | |
GEMINIm29L1 5 | |
GEMINIm29L1 204 | |
GEMINIm29L1 37 | |
GEMINIm29L1 8 | |
... | |
... | |
""" | |
filename = "/path/to/your/file/file.txt" | |
try: | |
fileFluctuations = open(filename, "r") | |
except Exception as e: | |
print '%s does not seem to exist or is not readable'%(filename) | |
print e | |
exit(os.EX_NOINPUT) | |
pass | |
for i,line in enumerate(fileScanDates): | |
if line[0] == "#": # Allows to comment lines out of the file | |
continue | |
data = line.split("\t") # if you don't use tab delimited put your delimiter here | |
chamber = data[0] | |
voltage = data[1] | |
dict_Histos[chamber].Fill(voltage) | |
filename.close() | |
outPath = "/path/to/your/output/file/" | |
outfilename = outPath + "output.root" | |
outF = r.TFile("/path/to/your/output/file/output.root","RECREATE") | |
for chamber,histo in dict_Histos.iteritems(): | |
outCanv = r.TCanvas("canv_{0}_dV".format(chamber),"Voltage Fluctuations for {0}".format(chamber),600,600) | |
outCanv.cd() | |
histo.Draw("E1") | |
outCanv.SaveAs("{0}/canv_{1}_dV".format(outPath,chamber)) | |
outDir = outF.mkdir(chamber) | |
outDir.cd() | |
outCanv.Write() | |
histo.Write() | |
outF.Close() | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment