ATLAS Offline Software
CaloCellContainerCorrectorTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /********************************************************************
6 
7 NAME: CaloCellContaineCorrectorTool
8 PACKAGE: offline/Calorimeter/CaloRec
9 
10 AUTHORS: David Rousseau
11 CREATED: June 5,2004
12 
13 PURPOSE: Apply cell correction to CaloCellContainer
14 
15 ********************************************************************/
16 
19 #include "CaloEvent/CaloCell.h"
21 
22 
24 // CONSTRUCTOR:
26 
28  const std::string& type,
29  const std::string& name,
30  const IInterface* parent)
31  :base_class(type, name, parent),
32  m_cellCorrectionTools(this),
33  m_caloSelection(false) {
34  declareProperty("CaloNums",m_caloNums);
35  declareProperty("CellCorrectionToolNames",m_cellCorrectionTools);
36  m_caloNums.clear();
37  //default: process all calo
38  m_caloNums.push_back( static_cast<int>(CaloCell_ID::NSUBCALO) );
39 }
40 
41 
42 
43 
45 // INITIALIZE:
46 // The initialize method will create all the required algorithm objects
48 
50 
51  //Retrieve tools
52  StatusCode sc = m_cellCorrectionTools.retrieve();
53  if (sc.isFailure()) {
54  msg(MSG::ERROR) << "Unable to retrieve tools " << m_cellCorrectionTools << endmsg;
55  }
56 
57  unsigned int nSubCalo=static_cast<unsigned int>(CaloCell_ID::NSUBCALO) ;
58 
59  //check calo number specified
60  m_caloSelection = true ;
61  if (m_caloNums.empty()) {
62  msg(MSG::WARNING) << " no calo specified for correction. Will do nothing. " << endmsg;
63  return StatusCode::SUCCESS;
64  } else if (m_caloNums.size()>nSubCalo ) {
65  msg(MSG::ERROR) << " More than "
66  << nSubCalo << " calo specified. Must be wrong. Stop." << endmsg;
67  return StatusCode::FAILURE;
68  } else if (m_caloNums.size()==1 && m_caloNums[0]==static_cast<int>(nSubCalo)) {
69  m_caloSelection = false ;
70  ATH_MSG_INFO("Correction will be applied on all calo.");
71  } else {
72  for (unsigned int index=0; index < m_caloNums.size() ; ++index) {
73  if (m_caloNums[index]<0 || m_caloNums[index]>=static_cast<int>(nSubCalo) ) {
74  msg(MSG::ERROR) << "Invalid calo specification:" << m_caloNums[index] << "Stop." << endmsg ;
75  return StatusCode::FAILURE;
76  } else {
77  ATH_MSG_INFO("Correction will be applied on calo:" << static_cast<int>(m_caloNums[index]));
78  }
79  }
80  }
81 
82 
83  ATH_MSG_INFO("Initialization completed successfully");
84  return StatusCode::SUCCESS;
85 
86 }
87 
90  const EventContext& ctx) const
91 {
92  if (!m_caloSelection) {
93  // no selection mode (faster)
94  CaloCellContainer::iterator itrCellBeg=theCont->begin();
95  CaloCellContainer::iterator itrCellEnd=theCont->end();
96 
97  StatusCode sc = processOnCellIterators(itrCellBeg, itrCellEnd, ctx );
98  if (sc.isFailure())
99  msg(MSG::WARNING) << "Failure from processOnCellIterators" << endmsg ;
100  }else {
101  // selection mode
102 
103  for (std::vector<int>::const_iterator itrCalo=m_caloNums.begin();itrCalo!=m_caloNums.end();++itrCalo){
104 
105  CaloCell_ID::SUBCALO caloNum=static_cast<CaloCell_ID::SUBCALO>(*itrCalo);
106 
107  CaloCellContainer::iterator itrCellBeg=theCont->beginCalo(caloNum);
108  CaloCellContainer::iterator itrCellEnd=theCont->endCalo(caloNum);
109 
110  if (!theCont->hasCalo(caloNum))
111  {
112  msg(MSG::WARNING) << " Attempt to apply correction but CaloCellContainer has not been filled for this calo : "
113  << *itrCalo << endmsg ;
114  } else
115  {
116  StatusCode sc=processOnCellIterators(itrCellBeg, itrCellEnd, ctx );
117  if (sc.isFailure())
118  msg(MSG::WARNING) << "Failure from processOnCellIterators for calo "
119  << static_cast<int> (caloNum)
120  << endmsg ;
121 
122  }
123 
124 
125  }
126 
127  }
128 
129 
130 
131  return StatusCode::SUCCESS ;
132 }
133 
134 
137  const CaloCellContainer::iterator & itrCellEnd,
138  const EventContext& ctx) const
139 {
140  // not clear what s the best way to do the loop
142 
143  //if only one tool do not iterate (optimisation)
144  if (m_cellCorrectionTools.size()==1) {
145  const ToolHandle<CaloCellCorrection>& tool = *m_cellCorrectionTools.begin();
146  for (itrCell=itrCellBeg;itrCell!=itrCellEnd;++itrCell) {
147  tool->MakeCorrection (*itrCell, ctx);
148  }
149  }else {
150  for (itrCell=itrCellBeg;itrCell!=itrCellEnd;++itrCell) {
151  for (const ToolHandle<CaloCellCorrection>& tool : m_cellCorrectionTools) {
152  tool->MakeCorrection (*itrCell, ctx);
153  }
154  }
155  }
156 
157  return StatusCode::SUCCESS;
158 }
159 
160 
161 
162 
163 
164 
CaloCellContainerCorrectorTool::initialize
virtual StatusCode initialize() override
Definition: CaloCellContainerCorrectorTool.cxx:49
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloCellContainerCorrectorTool::m_cellCorrectionTools
ToolHandleArray< CaloCellCorrection > m_cellCorrectionTools
Definition: CaloCellContainerCorrectorTool.h:38
index
Definition: index.py:1
CaloCellContainerCorrectorTool::CaloCellContainerCorrectorTool
CaloCellContainerCorrectorTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: CaloCellContainerCorrectorTool.cxx:27
CaloCellContainerCorrectorTool::m_caloSelection
bool m_caloSelection
Definition: CaloCellContainerCorrectorTool.h:40
CaloCell.h
CaloCellContainerCorrectorTool::m_caloNums
std::vector< int > m_caloNums
Definition: CaloCellContainerCorrectorTool.h:35
CaloCellContainer::endCalo
CaloCellContainer::iterator endCalo(CaloCell_ID::SUBCALO caloNum)
Definition: CaloCellContainer.cxx:128
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
CaloCell_ID.h
CaloCellContainerCorrectorTool::processOnCellIterators
StatusCode processOnCellIterators(const CaloCellContainer::iterator &itrCellBeg, const CaloCellContainer::iterator &itrCellEnd, const EventContext &ctx) const
Definition: CaloCellContainerCorrectorTool.cxx:136
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
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
CaloCell_Base_ID::SUBCALO
SUBCALO
enumeration of sub calorimeters
Definition: CaloCell_Base_ID.h:46
test_pyathena.parent
parent
Definition: test_pyathena.py:15
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
CaloCellContainer.h
CaloCellContainerCorrectorTool::process
virtual StatusCode process(CaloCellContainer *theCellContainer, const EventContext &ctx) const override
Definition: CaloCellContainerCorrectorTool.cxx:89
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
CaloCellContainerCorrectorTool.h
CaloCellContainer::beginCalo
CaloCellContainer::iterator beginCalo(CaloCell_ID::SUBCALO caloNum)
get non const iterators on cell of just one calo
Definition: CaloCellContainer.cxx:123
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DeMoScan.index
string index
Definition: DeMoScan.py:364
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
CaloCellContainer::hasCalo
bool hasCalo(const CaloCell_ID::SUBCALO caloNum) const
tell wether it has been filled with cells (maybe none) of a given calo
Definition: CaloCellContainer.cxx:209
CaloCell_Base_ID::NSUBCALO
@ NSUBCALO
Definition: CaloCell_Base_ID.h:46
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.