ATLAS Offline Software
Loading...
Searching...
No Matches
L1CaloDumpRampData.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// TrigT1CaloCalibUtils includes
7
8#include <fstream> // std::ofstream
9#include <ios> // std::dec, std::hex
10#include <sstream>
11
12#include <TF1.h>
13#include <TFile.h>
14#include <TGraphErrors.h>
15
18
19L1CaloDumpRampData::L1CaloDumpRampData(const std::string& name, ISvcLocator* pSvcLocator)
20 : AthHistogramAlgorithm(name, pSvcLocator)
21{
22 //declareProperty( "Property", m_nProperty ); //example property declaration
23}
24
25
27
28
30{
31 ATH_MSG_INFO("Initializing " << name() << "...");
32
33 return StatusCode::SUCCESS;
34}
35
36namespace {
37void writeChannel(std::ofstream& S, uint32_t cool, double slope, double offset, double chi)
38{
39 S << "<Channel coolid='0x" << std::hex << cool
40 << std::dec << "' slope='" << slope
41 << "' offset='" << offset
42 << "' chi2='" << chi << "/>\n";
43}
44
45std::string getName(uint32_t cool)
46{
47 std::ostringstream S;
48 S << "0x" << std::hex << cool;
49 return std::string(S.str());
50}
51
52std::string getTitle(uint32_t cool)
53{
54 return "Ramp " + getName(cool);
55}
56
57} // anonymous namespace
58
60{
61 using std::make_unique;
62 ATH_MSG_INFO("Finalizing " << name() << "...");
63
64 const L1CaloRampDataContainer* rampDataContainer = nullptr;
65 CHECK_RECOVERABLE(detStore()->retrieve(rampDataContainer, "/L1CaloRampMaker/L1CaloRampDataContainer"));
66
67 const CondAttrListCollection* energyScanResults = nullptr;
68 CHECK_RECOVERABLE(detStore()->retrieve(energyScanResults, "/TRIGGER/L1Calo/V1/Results/EnergyScanResults"));
69
70 std::ofstream xmlFile("rampdata.xml");
71 xmlFile << "<?xml version='1.0' encoding='utf-8'?>\n"
72 << "<TriggerTowerDecoratorData>\n"
73 << "<default name='slope' />\n";
74
75 std::unique_ptr<TGraphErrors> graph_temp = make_unique<TGraphErrors>();
76 std::unique_ptr<TF1> func = make_unique<TF1>("func", "pol1", 0., 255.);
77 for(const auto & rampDataIt : *rampDataContainer) {
78 auto coolId = rampDataIt.first;
79 const L1CaloRampData& rampData = rampDataIt.second;
80 ATH_MSG_DEBUG("Processing RampData for 0x" << std::hex << coolId << std::dec);
81
82 // create a TGraphErrors of the energy steps
83 graph_temp->SetNameTitle(getName(coolId).c_str(), getTitle(coolId).c_str());
84 TGraphErrors* graph = static_cast<TGraphErrors*>(this->bookGetPointer(*graph_temp));
85
86 unsigned int nSteps = rampData.getNSteps();
87 graph->Set(nSteps);
88 for(unsigned int iStep = 0; iStep < nSteps; ++iStep) {
89 auto dataPoint = rampData.getStep(iStep);
90 if(!dataPoint) {
91 ATH_MSG_WARNING("Recieved nullptr for step " << iStep
92 << " and coolId 0x" << std::hex << coolId << std::dec);
93 continue;
94 }
95
96 if(iStep) {
97 // avoid problems due to saturation effects
98 auto* prevStep = rampData.getStep(iStep - 1);
99 if(prevStep && prevStep->second.mean() > dataPoint->second.mean()) continue;
100 }
101
102 graph->SetPoint(iStep, dataPoint->second.mean(), dataPoint->first.mean());
103 graph->SetPointError(iStep, dataPoint->second.rms(), dataPoint->first.rms());
104 }
105
106 // overlay the fit function
107 auto attrListIt = energyScanResults->chanAttrListPair(coolId);
108 if(attrListIt != energyScanResults->end()) {
109 const auto& attrList = attrListIt->second;
110 double slope = attrList["Slope"].data<double>();
111 double offset = attrList["Offset"].data<double>();
112 double chi2 = attrList["Chi2"].data<double>();
113
114 func->SetParameters(offset, slope);
115 graph->GetListOfFunctions()->Add(func->Clone(("func" + getName(coolId)).c_str()));
116
117 writeChannel(xmlFile, coolId, slope, offset, chi2);
118 } else {
119 ATH_MSG_WARNING("No database entry for 0x" << std::hex
120 << coolId << std::dec);
121 }
122 }
123
124 xmlFile << "</TriggerTowerDecoratorData>\n";
125
126 return StatusCode::SUCCESS;
127}
128
130{
131 return StatusCode::SUCCESS;
132}
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
#define CHECK_RECOVERABLE(EXP)
Evaluate an expression and check for errors.
const ServiceHandle< StoreGateSvc > & detStore() const
AthHistogramAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
TH1 * bookGetPointer(const TH1 &hist, const std::string &tDir="", const std::string &stream="")
Simplify the booking and registering (into THistSvc) of histograms.
TGraph * graph(const std::string &graphName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered TGraphs.
This class is a collection of AttributeLists where each one is associated with a channel number.
const_iterator end() const
const_iterator chanAttrListPair(ChanNum chanNum) const
Access to Chan/AttributeList pairs via channel number: returns map iterator.
virtual StatusCode initialize()
L1CaloDumpRampData(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute()
virtual StatusCode finalize()
Container of L1CaloRampData objects.
Transient class to store the RampData calculated from calibration runs.
unsigned int getNSteps() const
const L1CaloRampDataPoint * getStep(unsigned int step) const
double chi2(TH1 *h0, TH1 *h1)
void writeChannel(const CCIovVectorMap_t &data, const Folder &destination, const std::string &tag)