ATLAS Offline Software
LArDigitThinner.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "LArDigitThinner.h"
12 
13 #include <bitset>
14 #include <limits>
15 #include <cstdlib>
16 
18  ISvcLocator* pSvcLocator) :
19  AthReentrantAlgorithm(name, pSvcLocator)
20  , m_onlineID(nullptr)
21  , m_caloCellId(nullptr) {
22  declareProperty("EnergyCuts_Barrel", m_energyCuts_barrel);
23  declareProperty("EnergyCuts_Endcap", m_energyCuts_endcap);
24  declareProperty("EnergyCut_HEC", m_energyCut_hec = 5000);
25  declareProperty("EnergyCut_FCAL", m_energyCut_fcal = 20000);
26 }
27 
29 
30 
32 
36  ATH_CHECK(m_outputKey.initialize());
37 
38  ATH_CHECK(detStore()->retrieve(m_onlineID, "LArOnlineID"));
39  ATH_CHECK(detStore()->retrieve(m_caloCellId,"CaloCell_ID"));
40 
41 
42  //Fix up jobOptions if needed:
43  int defaultCuts_barrel[] = { 1000, 1000, 1000, 1000 };
44  int defaultCuts_endcap[] = { 2000, 2000, 2000, 2000 };
45 
46  if (m_energyCuts_barrel.size() != 4) {
47  msg(MSG::WARNING) << "Only " << m_energyCuts_barrel.size()
48  << " energy cut values provided for the endcap : reverting to default" << endmsg;
49  for (size_t i=0;i<4;++i) m_energyCuts_barrel.push_back(defaultCuts_barrel[i]);
50  }
51 
52  if (m_energyCuts_endcap.size() != 4) {
53  msg(MSG::WARNING) << "Only " << m_energyCuts_endcap.size()
54  << " energy cut values provided for the endcap : reverting to default" << endmsg;
55  for (size_t i=0;i<4;++i) m_energyCuts_endcap.push_back(defaultCuts_endcap[i]);
56  }
57 
58  msg(MSG::INFO) << "Energy cuts (Barrel) : ";
59  for (unsigned int i = 0; i < 4; i++) msg() << m_energyCuts_barrel[i] << " ";
60  msg(MSG::INFO) << "GeV" << endmsg;
61 
62  msg() << MSG::INFO << "Energy cuts (Endcap) : ";
63  for (unsigned int i = 0; i < 4; i++) msg() << m_energyCuts_endcap[i] << " ";
64  msg() << MSG::INFO << "GeV" << endmsg;
65 
66  return StatusCode::SUCCESS;
67 }
68 
69 
70 const std::vector<int>&
71 LArDigitThinner::initCutValues(const EventContext& ctx) const
72 {
73  if (!m_energyCuts.isValid()) {
74  //Note that the cut values per online-ID depends on the LAr-cabling. Even the cabling is
75  //formally a time-dependent condition, it changes very rarely. Therefore putting it
76  //into a ConditionsContainer filled by a dedicated conditions algorithm seems an
77  //unecessary overkill.
78 
79  std::vector<int> energyCuts;
81 
82 
84  const LArOnOffIdMapping* cabling=*cablingHdl;
85 
86 
88  HWIdentifier chid=cabling->createSignalChannelID(id);
89  IdentifierHash onlHash=m_onlineID->channel_Hash(chid);
90  int sampling = m_caloCellId->sampling(id);
91  if (sampling < 0) continue;
92  if (m_caloCellId->is_em_barrel(id)) {
93  energyCuts[onlHash]=m_energyCuts_barrel[sampling];
94  }
95  else { //endcap
96  energyCuts[onlHash]=m_energyCuts_endcap[sampling];
97  continue;
98  }
99  }//end loop over EM cells;
100 
102  HWIdentifier chid=cabling->createSignalChannelID(id);
103  IdentifierHash onlHash=m_onlineID->channel_Hash(chid);
104  energyCuts[onlHash]= m_energyCut_hec;
105  }//End loop over HEC cells
106 
108  HWIdentifier chid=cabling->createSignalChannelID(id);
109  IdentifierHash onlHash=m_onlineID->channel_Hash(chid);
110  energyCuts[onlHash]= m_energyCut_fcal;
111  }//end loop over FCAL cells
112 
113  m_energyCuts.set (std::move (energyCuts));
114 
115  ATH_MSG_INFO("Done filling cache of cut values");
116  }
117 
118  return *m_energyCuts.ptr();
119 }
120 
121 
123 {
124  return StatusCode::SUCCESS;
125 }
126 
127 
128 StatusCode LArDigitThinner::execute(const EventContext& ctx) const {
129 
130  const std::vector<int>& energyCuts = initCutValues(ctx); //Should return right away if the cut values are already initialized
131 
132  //Get event inputs from read handles:
133  SG::ReadHandle<LArDigitContainer> inputContainer(m_inputKey,ctx);
134  SG::ReadHandle<LArRawChannelContainer> larRawChannelContainer(m_rawChannelKey,ctx);
135 
136  // Create the new digit container
137  SG::WriteHandle<ConstDigitCont_t> outputContainer(m_outputKey,ctx);
138 
139  ATH_CHECK(outputContainer.record(std::make_unique<ConstDigitCont_t>(SG::VIEW_ELEMENTS)));
140 
141 
142  std::bitset<200000> keepSet;
143 
144  for(const LArRawChannel& chan : *larRawChannelContainer) {
145  const IdentifierHash onlHash=m_onlineID->channel_Hash(chan.hardwareID());
146  if (abs(chan.energy())>=energyCuts[onlHash]) {
147  keepSet.set(onlHash);
148  }
149  }//end loop over raw channels
150 
151 
152  //start loop over digits
153  for (const LArDigit* dig : *inputContainer) {
154  const IdentifierHash onlHash=m_onlineID->channel_Hash(dig->hardwareID());
155  if (keepSet.test(onlHash)) {
156  outputContainer->push_back(dig);
157  }
158  }//end loop over input container
159 
160  ATH_MSG_DEBUG("Copied " << outputContainer->size() << " of "
161  << inputContainer->size() << " digits.");
162 
163  return StatusCode::SUCCESS;
164 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CaloCell_Base_ID::LARFCAL
@ LARFCAL
Definition: CaloCell_Base_ID.h:46
LArOnlineID_Base::channel_Hash
IdentifierHash channel_Hash(HWIdentifier channelId) const
Create channel_hash from channel_Id.
Definition: LArOnlineID_Base.cxx:1636
LArDigitThinner::m_caloCellId
const CaloCell_ID * m_caloCellId
Definition: LArDigitThinner.h:65
LArDigitThinner::m_energyCut_fcal
int m_energyCut_fcal
Definition: LArDigitThinner.h:60
CxxUtils::CachedValue::ptr
const T * ptr() const
Return a pointer to the cached value.
max
#define max(a, b)
Definition: cfImp.cxx:41
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
LArDigitThinner::m_energyCuts
CxxUtils::CachedValue< std::vector< int > > m_energyCuts
Definition: LArDigitThinner.h:76
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CxxUtils::CachedValue::isValid
bool isValid() const
Test to see if the value is valid.
LArDigitThinner::m_energyCuts_barrel
std::vector< int > m_energyCuts_barrel
Definition: LArDigitThinner.h:59
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
CaloCell_Base_ID::LARHEC
@ LARHEC
Definition: CaloCell_Base_ID.h:46
HWIdentifier
Definition: HWIdentifier.h:13
LArDigitThinner::LArDigitThinner
LArDigitThinner(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArDigitThinner.cxx:17
LArDigitThinner::m_rawChannelKey
SG::ReadHandleKey< LArRawChannelContainer > m_rawChannelKey
Definition: LArDigitThinner.h:71
LArDigitThinner::m_energyCut_hec
int m_energyCut_hec
Definition: LArDigitThinner.h:60
CaloCell_ID.h
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
LArDigitThinner.h
LArDigitThinner::initialize
StatusCode initialize() override
Definition: LArDigitThinner.cxx:31
LArDigit
Liquid Argon digit base class.
Definition: LArDigit.h:25
lumiFormat.i
int i
Definition: lumiFormat.py:92
LArRawChannel
Liquid Argon ROD output object base class.
Definition: LArRawChannel.h:40
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
CaloCell_Base_ID::sampling
int sampling(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
LArDigitThinner::m_inputKey
SG::ReadHandleKey< LArDigitContainer > m_inputKey
Definition: LArDigitThinner.h:70
LArDigitThinner::execute
StatusCode execute(const EventContext &ctx) const override
Definition: LArDigitThinner.cxx:128
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
LArDigitThinner::initCutValues
const std::vector< int > & initCutValues(const EventContext &ctx) const
Definition: LArDigitThinner.cxx:71
CaloCell_Base_ID::cell_range
id_range cell_range(void) const
Range over full set of Identifiers (LAr + Tiles)
CaloCell_Base_ID::is_em_barrel
bool is_em_barrel(const Identifier id) const
test if the id belongs to the EM barrel
HWIdentifier.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArOnlineID_Base::channelHashMax
size_type channelHashMax(void) const
Define channel hash tables max size.
Definition: LArOnlineID_Base.cxx:1901
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CxxUtils::CachedValue::set
void set(const T &val) const
Set the value, assuming it is currently invalid.
LArDigitContainer.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
LArDigitThinner::finalize
StatusCode finalize() override
Definition: LArDigitThinner.cxx:122
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArDigitThinner::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: LArDigitThinner.h:67
LArDigitThinner::m_onlineID
const LArOnlineID * m_onlineID
Definition: LArDigitThinner.h:64
IdentifierHash
Definition: IdentifierHash.h:38
CaloCell_Base_ID::LAREM
@ LAREM
Definition: CaloCell_Base_ID.h:46
LArDigitThinner::~LArDigitThinner
~LArDigitThinner()
LArDigitThinner::m_energyCuts_endcap
std::vector< int > m_energyCuts_endcap
Definition: LArDigitThinner.h:59
LArDigitThinner::m_outputKey
SG::WriteHandleKey< ConstDigitCont_t > m_outputKey
Definition: LArDigitThinner.h:74
LArRawChannelContainer.h
LArOnlineID.h
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20