ATLAS Offline Software
Loading...
Searching...
No Matches
L1CaloLinearCalibration.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "CoralBase/Blob.h"
8#include "GaudiKernel/MsgStream.h"
11
17
18#include <TF1.h>
19#include <TGraphErrors.h>
20
21L1CaloLinearCalibration::L1CaloLinearCalibration(const std::string& name, ISvcLocator *pSvcLocator)
22 : AthAlgorithm(name, pSvcLocator),
26{
27 declareProperty("L1CaloRampDataContainerKey", m_l1CaloRampDataContainerKey);
28}
29
33
42
44{
45 return StatusCode::SUCCESS;
46}
47
49{
50 StatusCode sc;
51
52 const L1CaloRampDataContainer *rampData;
53 sc = detStore()->retrieve(rampData, m_l1CaloRampDataContainerKey);
54 if(sc.isFailure()) {
55 msg(MSG::FATAL) << "Could not retrieve L1CaloRampDataContainer." << endmsg;
56 return sc;
57 }
58
61 std::vector<double> x, ex, y, ey;
62 std::unique_ptr<TGraphErrors> graph(nullptr);
63 std::unique_ptr<TF1> func(new TF1("func", "pol1", 5., 255.));
64 double val(0.);
65 int errCount = 0;
66 for(; it != itEnd; ++it) {
67 x.clear(); ex.clear(); y.clear(); ey.clear();
68 func->SetParameters(0., 1.);
69
70 // we plot calo over adc. in this way the slope is the calibration constant
71 for(unsigned int step = 0; step < it->second.getNSteps(); ++step) {
72 // protection against NaN - don't have a better idea right now, suggestions welcome
73 val = it->second.getLevel1(step)->mean();
74 if(val != val) continue;
75 val = it->second.getLevel1(step)->rms();
76 if(val != val) continue;
77 val = it->second.getCalo(step)->mean();
78 if(val != val) continue;
79 val = it->second.getCalo(step)->rms();
80 if(val != val) continue;
81
82 if(step && it->second.getLevel1(step)->mean() < x.back()) {
83 //msg(MSG::WARNING) << "Decreasing step energy - ignoring." << endmsg;
84 errCount++;
85 continue;
86 }
87
88 x.push_back(it->second.getLevel1(step)->mean());
89 // add the systematic error because of intrinsic resolution
90 ex.push_back(sqrt(it->second.getLevel1(step)->rms()*it->second.getLevel1(step)->rms() + 0.0052083333333333348));
91 y.push_back(it->second.getCalo(step)->mean());
92 ey.push_back(it->second.getCalo(step)->rms());
93 }
94 graph.reset(new TGraphErrors(x.size(), &x.front(), &y.front(), &ex.front(), &ey.front()));
95
96 if(graph->Fit(func.get(), "QRF0") != 0) {
97 // if fit failed, don't store fit data for now
98 L1CaloEnergyScanResults energyScanResults(it->first,
99 0.,
100 -1.,
101 -1.,
102 1,
103 coral::Blob(0),
105 ChanFitErrorCode(0x1));
106 m_energyScanResultsContainer->addEnergyScanResults(it->first, energyScanResults);
107 } else {
108 L1CaloEnergyScanResults energyScanResults(it->first,
109 func->GetParameter(0),
110 func->GetParameter(1),
111 func->GetChisquare(),
112 func->GetNDF(),
113 coral::Blob(0),
115 ChanFitErrorCode(0x0));
116 m_energyScanResultsContainer->addEnergyScanResults(it->first, energyScanResults);
117 }
118 }
119
120 if (errCount > 0) {
121 msg(MSG::WARNING) << "Decreasing step energy - ignoring. ("
122 << errCount << " occurances)" << endmsg;
123 }
124
125 sc = detStore()->record(dynamic_cast<CondAttrListCollection*>(m_energyScanResultsContainer->makePersistent()),
126 m_energyScanResultsContainer->coolOutputKey());
127 if(sc.isFailure()) {
128 msg(MSG::FATAL) << "Could not record EnergyScanResultsContainer." << endmsg;
129 return sc;
130 }
131 m_energyScanRunInfoContainer->setRunNumber(rampData->runNumber());
132 m_energyScanRunInfoContainer->setGainStrategy(rampData->gainStrategy());
133 sc = detStore()->record(dynamic_cast<AthenaAttributeList*>(m_energyScanRunInfoContainer->makePersistent()),
134 m_energyScanRunInfoContainer->coolOutputKey());
135 if(sc.isFailure()) {
136 msg(MSG::FATAL) << "Could not record EnergyScanRunInfoContainer." << endmsg;
137 return sc;
138 }
139
140 return StatusCode::SUCCESS;
141}
#define endmsg
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
static Double_t sc
#define y
#define x
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
An AttributeList represents a logical row of attributes in a metadata table.
ChanFitErrorCode stores information about the calibration fit quality.
This class is a collection of AttributeLists where each one is associated with a channel number.
Container of L1CaloEnergyScanResults objects, inherit from the abstract base class AbstractL1CaloCond...
Class that holds transient information about the calibration for trigger towers.
Container of L1CaloEnergyScanRunInfo metadata, inherit from the abstract base class AbstractL1CaloCon...
std::unique_ptr< L1CaloEnergyScanResultsContainer > m_energyScanResultsContainer
std::unique_ptr< L1CaloEnergyScanRunInfoContainer > m_energyScanRunInfoContainer
L1CaloLinearCalibration(const std::string &name, ISvcLocator *pSvcLocator)
Container of L1CaloRampData objects.
const std::string & gainStrategy() const
L1CaloRampDataMap::const_iterator const_iterator
const_iterator begin() const