3 import AthenaPython.PyAthena
as PyAthena
4 from array
import array
6 from PyKernel
import PyKernel
14 """ Test reading back in conditions data. """
15 def __init__(self, name="L1CaloDumpRampDataAlgorithm"):
16 super(L1CaloDumpRampDataAlgorithm, self).
__init__(name=name)
20 self.
detectorStore = PyAthena.py_svc(
"StoreGateSvc/DetectorStore")
23 self.
msg.failure(
"Problem retrieving DetectorStore")
24 return PyAthena.StatusCode.Failure
26 return PyAthena.StatusCode.Success
29 """ Read L1CaloRampData in finalize, nothing to do here. """
30 return PyAthena.StatusCode.Success
34 rampDataContainer = PyKernel.retrieveDet(PyAthena.L1CaloRampDataContainer,
35 "/L1CaloRampMaker/L1CaloRampDataContainer")
36 energyScanResults = PyKernel.retrieveDet(PyAthena.CondAttrListCollection,
37 "/TRIGGER/L1Calo/V1/Results/EnergyScanResults")
39 rampDataContainer =
None
41 if rampDataContainer
is None:
42 self.
msg.
error(
"Error retrieve L1Calo data.")
43 return PyAthena.StatusCode.Failure
51 xmlfile =
open(
"rampdata.xml",
"w")
52 func = ROOT.TF1(
"func",
"pol1", 0., 255.)
53 xml_channel =
"<Channel coolid='0x%x' slope='%.4f' offset='%.4f' chi2='%.4f' />\n"
54 isfinite = scipy.isfinite
56 xmlfile.write(
"""<?xml version='1.0' encoding='utf-8'?>
57 <TriggerTowerDecoratorData>
58 <default name='slope' />
61 rootfile = ROOT.TFile.Open(
"graphs.root",
"RECREATE")
63 self.
msg.
error(
"Could not open root file.")
64 return PyAthena.StatusCode.Failure
66 for rampDataContainerIt
in rampDataContainer:
72 coolId, rampData = (rampDataContainerIt.first, rampDataContainerIt.second)
73 for step
in range(rampData.getNSteps()):
74 if step != 0
and rampData.getLevel1(step).
mean() < x[-1]:
76 x.append(rampData.getLevel1(step).
mean())
77 ex.append(rampData.getLevel1(step).
rms())
78 y.append(rampData.getCalo(step).
mean())
79 ey.append(rampData.getCalo(step).
rms())
81 if len(x) == 0:
continue
83 ramp = ROOT.TGraphErrors(len(x), x, y, ex, ey)
84 except Exception
as e:
85 traceback.print_exc(e)
88 attrList = energyScanResults.attributeList(coolId)
90 slope = attrList[
"Slope"]
91 offset = attrList[
"Offset"]
92 chi2 = attrList[
"Chi2"]
93 func.SetParameters(offset, slope)
96 self.
msg.warning(
"Could not obtain fit data from database.")
98 func.SetParameters(0., 1.)
99 ramp.Fit(func,
"QFR0")
100 slope = func.GetParameter(1)
101 offset = func.GetParameter(0)
102 chi2 = func.GetChisquare()
104 if isfinite(chi2)
and isfinite(offset)
and isfinite(slope):
105 ramp.GetListOfFunctions().Add(func.Clone(
"func_0x%x" % coolId))
106 xmlfile.write(xml_channel % (coolId, slope, offset, chi2))
108 ramp.SetName(
"0x%x" % coolId)
109 ramp.SetTitle(
"Ramp 0x%x" % coolId)
114 except Exception
as e:
115 traceback.print_exc(e)
117 xmlfile.write(
"</TriggerTowerDecoratorData>\n")
119 return PyAthena.StatusCode.Success