ATLAS Offline Software
L1CaloDumpRampData.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // TrigT1CaloCalibUtils includes
6 #include "L1CaloDumpRampData.h"
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 
19 L1CaloDumpRampData::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 
36 namespace {
37 void 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 
45 std::string getName(uint32_t cool)
46 {
47  std::ostringstream S;
48  S << "0x" << std::hex << cool;
49  return std::string(S.str());
50 }
51 
52 std::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(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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CondAttrListCollection::end
const_iterator end() const
Definition: CondAttrListCollection.h:315
L1CaloDumpRampData.h
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
L1CaloDumpRampData::L1CaloDumpRampData
L1CaloDumpRampData(const std::string &name, ISvcLocator *pSvcLocator)
Definition: L1CaloDumpRampData.cxx:19
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
L1CaloDumpRampData::finalize
virtual StatusCode finalize()
Definition: L1CaloDumpRampData.cxx:59
AthHistogramming::graph
TGraph * graph(const std::string &graphName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered TGraphs.
Definition: AthHistogramming.cxx:492
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
JetTiledMap::S
@ S
Definition: TiledEtaPhiMap.h:44
L1CaloDumpRampData::initialize
virtual StatusCode initialize()
Definition: L1CaloDumpRampData.cxx:29
dumpTruth.getName
getName
Definition: dumpTruth.py:34
cool
Definition: CoolTagInfo.h:12
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
L1CaloRampData::getStep
const L1CaloRampDataPoint * getStep(unsigned int step) const
Definition: L1CaloRampData.cxx:79
L1CaloRampDataContainer.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:523
L1CaloRampData::getNSteps
unsigned int getNSteps() const
Definition: L1CaloRampData.cxx:75
L1CaloRampDataContainer
Container of L1CaloRampData objects.
Definition: L1CaloRampDataContainer.h:23
checkCorrelInHIST.nSteps
int nSteps
Definition: checkCorrelInHIST.py:458
AthHistogramAlgorithm
Definition: AthHistogramAlgorithm.h:32
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CondAttrListCollection::chanAttrListPair
const_iterator chanAttrListPair(ChanNum chanNum) const
Access to Chan/AttributeList pairs via channel number: returns map iterator.
Definition: CondAttrListCollection.h:301
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
L1CaloDumpRampData::execute
virtual StatusCode execute()
Definition: L1CaloDumpRampData.cxx:129
CHECK_RECOVERABLE
#define CHECK_RECOVERABLE(EXP)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:487
writeChannel
void writeChannel(const CCIovVectorMap_t &data, const Folder &destination, const std::string &tag)
Definition: openCoraCool.cxx:748
L1CaloDumpRampData::~L1CaloDumpRampData
virtual ~L1CaloDumpRampData()
Definition: L1CaloDumpRampData.cxx:26
L1CaloRampData
Transient class to store the RampData calculated from calibration runs.
Definition: L1CaloRampData.h:42
AthHistogramming::bookGetPointer
TH1 * bookGetPointer(const TH1 &hist, const std::string &tDir="", const std::string &stream="")
Simplify the booking and registering (into THistSvc) of histograms.
Definition: AthHistogramming.h:260