ATLAS Offline Software
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 
21 L1CaloLinearCalibration::L1CaloLinearCalibration(const std::string& name, ISvcLocator *pSvcLocator)
22  : AthAlgorithm(name, pSvcLocator),
23  m_l1CaloRampDataContainerKey(""),
24  m_energyScanResultsContainer(0),
25  m_energyScanRunInfoContainer(0)
26 {
27  declareProperty("L1CaloRampDataContainerKey", m_l1CaloRampDataContainerKey);
28 }
29 
31 {
32 }
33 
35 {
36 
39 
40  return StatusCode::SUCCESS;
41 }
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 
60  L1CaloRampDataContainer::const_iterator itEnd = rampData->end();
61  std::vector<double> x, ex, y, ey;
62  boost::scoped_ptr<TGraphErrors> graph(0);
63  boost::scoped_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 }
L1CaloCoolChannelId.h
L1CaloRampDataContainer::begin
const_iterator begin() const
Definition: L1CaloRampDataContainer.h:40
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
ChanFitErrorCode.h
L1CaloLinearCalibration.h
L1CaloLinearCalibration::~L1CaloLinearCalibration
virtual ~L1CaloLinearCalibration()
Definition: L1CaloLinearCalibration.cxx:30
L1CaloRampDataContainer::runNumber
unsigned int runNumber() const
Definition: L1CaloRampDataContainer.h:43
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
L1CaloRampDataContainer::end
const_iterator end() const
Definition: L1CaloRampDataContainer.h:41
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
skel.it
it
Definition: skel.GENtoEVGEN.py:423
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
x
#define x
AthenaAttributeList.h
L1CaloLinearCalibration::execute
StatusCode execute()
Definition: L1CaloLinearCalibration.cxx:43
L1CaloEnergyScanResults
Class that holds transient information about the calibration for trigger towers.
Definition: L1CaloEnergyScanResults.h:19
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
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
L1CaloLinearCalibration::m_energyScanResultsContainer
boost::scoped_ptr< L1CaloEnergyScanResultsContainer > m_energyScanResultsContainer
Definition: L1CaloLinearCalibration.h:42
L1CaloRampDataContainer.h
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
L1CaloRampDataContainer::const_iterator
L1CaloRampDataMap::const_iterator const_iterator
Definition: L1CaloRampDataContainer.h:26
AthenaAttributeList
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
Definition: PersistentDataModel/PersistentDataModel/AthenaAttributeList.h:45
L1CaloRampDataContainer
Container of L1CaloRampData objects.
Definition: L1CaloRampDataContainer.h:23
L1CaloLinearCalibration::m_l1CaloRampDataContainerKey
std::string m_l1CaloRampDataContainerKey
Definition: L1CaloLinearCalibration.h:40
L1CaloEnergyScanResultsContainer.h
AthAlgorithm
Definition: AthAlgorithm.h:47
L1CaloRampDataContainer::gainStrategy
std::string gainStrategy() const
Definition: L1CaloRampDataContainer.h:44
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
L1CaloLinearCalibration::initialize
StatusCode initialize()
Definition: L1CaloLinearCalibration.cxx:34
L1CaloLinearCalibration::m_energyScanRunInfoContainer
boost::scoped_ptr< L1CaloEnergyScanRunInfoContainer > m_energyScanRunInfoContainer
Definition: L1CaloLinearCalibration.h:43
L1CaloEnergyScanRunInfoContainer.h
y
#define y
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArCellBinning.step
step
Definition: LArCellBinning.py:158
L1CaloEnergyScanResultsContainer
Container of L1CaloEnergyScanResults objects, inherit from the abstract base class AbstractL1CaloCond...
Definition: L1CaloEnergyScanResultsContainer.h:28
L1CaloLinearCalibration::finalize
StatusCode finalize()
Definition: L1CaloLinearCalibration.cxx:48
L1CaloEnergyScanRunInfoContainer
Container of L1CaloEnergyScanRunInfo metadata, inherit from the abstract base class AbstractL1CaloCon...
Definition: L1CaloEnergyScanRunInfoContainer.h:28
ChanFitErrorCode
ChanFitErrorCode stores information about the calibration fit quality.
Definition: ChanFitErrorCode.h:17
L1CaloEnergyScanResults::NotUsed
@ NotUsed
Definition: L1CaloEnergyScanResults.h:22
L1CaloLinearCalibration::L1CaloLinearCalibration
L1CaloLinearCalibration(const std::string &name, ISvcLocator *pSvcLocator)
Definition: L1CaloLinearCalibration.cxx:21