ATLAS Offline Software
CaloThinCellsInAODAlg.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
3  */
12 #include "StoreGate/ReadHandle.h"
13 
18 {
19  ATH_MSG_INFO("Thinning cells from '"<< m_clusterCntKey.key()<<"' container with "<< m_clusterPtCut <<" MeV and "<< m_clusterEtaCut <<".");
20  if (!m_isMC) ATH_MSG_INFO("Outputs are: CaloCells ('"<< m_caloCellOutputKey.key() <<"'), rawCh ('"<< m_rawChOutputKey.key()<<"') and digits ('"<< m_digitsOutputKey.key() <<"').");
21  else ATH_MSG_INFO("Outputs are: CaloCells ('"<< m_caloCellOutputKey.key() <<"'), rawCh ('"<< m_rawChOutputKey.key()<<"'), digits ('"<< m_digitsOutputKey.key() <<"') and hits ('"<< m_hitsOutputKey.key() <<"')");
22 
24 
25  // inputs
31 
32  // outputs
34  ATH_CHECK(m_digitsOutputKey.initialize());
36  ATH_CHECK(m_caloCellOutputKey.initialize());
37 
38  // calo id helpers
39  ATH_CHECK(detStore()->retrieve(m_onlineID, "LArOnlineID"));
40  ATH_CHECK(detStore()->retrieve(m_caloCellId,"CaloCell_ID"));
41 
42  return StatusCode::SUCCESS;
43 }
44 
49 StatusCode CaloThinCellsInAODAlg::execute (const EventContext& ctx) const
50 {
51  ATH_MSG_DEBUG("Executing CaloThinCellsInAODAlg...");
52 
54  const LArOnOffIdMapping* larCabling=*cablingHdl;
55 
56  //Get event inputs from read handles:
60  SG::ReadHandle<LArDigitContainer> inputDigitsContainer(m_digitsInputKey,ctx);
61 
62  // Write to the new containers
64  ATH_CHECK(outputCells.record(std::make_unique<ConstCaloCellCont_t>(SG::VIEW_ELEMENTS)));
65 
67  ATH_CHECK(outputDigits.record(std::make_unique<ConstLArDigitCont_t>(SG::VIEW_ELEMENTS)));
68 
70  ATH_CHECK(outputRawChannels.record(std::make_unique<LArRawChannelContainer>()));
71 
73  ATH_CHECK(outputHits.record(std::make_unique<LArHitContainer>()));
74 
75  std::bitset<200000> keepCellSet;
76  size_t nCellsAllClus = 0;
77 
78  for (const xAOD::CaloCluster* clus : *clusterContainer){
79 
80  // cluster filters
81  if (clus->pt() < m_clusterPtCut) continue;
82  if (std::abs(clus->eta()) > m_clusterEtaCut) continue;
83 
84  ATH_MSG_DEBUG("Cluster pt: "<< clus->pt()<<", eta/phi: "<< clus->eta() <<" / "<< clus->phi());
85 
86  const CaloClusterCellLink* cellLinks = clus->getCellLinks();
87 
88  if (!cellLinks){
89  ATH_MSG_DEBUG( " Cluster without cell links found in collection: " << m_clusterCntKey.key() << " ===> cells cannot be written in AOD as requested ! " );
90  continue;
91  }
92  if (cellLinks->getCellContainerLink().dataID() != m_caloCellInputKey.key()) {
93  ATH_MSG_DEBUG( " Cluster points to cell container " << cellLinks->getCellContainerLink().dataID() << " which is different from the cell container being thinned: " << m_caloCellInputKey.key() << "; cluster skipped.");
94  continue;
95  }
96 
97  nCellsAllClus += cellLinks->size();
100  for (; it != end; ++it) {
101  if (it.index() >= inputCellContainer->size()) {
102  ATH_MSG_DEBUG( " Cell index " << it.index() << " is larger than the number of cells in " << m_caloCellInputKey.key() << " (" << inputCellContainer->size() << ")" );
103  continue;
104  }
105  const CaloCell* cell = (*it); //get the caloCells
106 
107  Identifier cellId = cell->ID();
108 
109  if (m_caloCellId->is_em_barrel(cellId)){ // cells belong to EM Barrel
110  HWIdentifier chhwid = larCabling->createSignalChannelID(cellId);
111  IdentifierHash chOnlHash = m_onlineID->channel_Hash(chhwid);
112 
113  if (!keepCellSet.test(chOnlHash)){
114  keepCellSet.set(chOnlHash);
115  outputCells->push_back(cell);
116  }
117  }
118  }//end loop over calo cell links
119  } // end loop over clusters
120  ATH_MSG_DEBUG("\tTotal Copied " << outputCells->size() << " of " << nCellsAllClus << " calo cells, linked to CaloCluster.");
121 
122  if (keepCellSet.any()){
123  //start loop over raw channels
124  for(const LArRawChannel& chan : *inputRawChContainer) {
125  const IdentifierHash onlHash=m_onlineID->channel_Hash(chan.hardwareID());
126  if (keepCellSet.test(onlHash)) {
127  outputRawChannels->push_back(chan);
128  }
129  }
130  ATH_MSG_DEBUG("\tCopied " << outputRawChannels->size() << " of " << (*inputRawChContainer).size() << " raw channels.");
131 
132  //start loop over digits
133  for (const LArDigit* dig : *inputDigitsContainer) {
134  const IdentifierHash onlHash=m_onlineID->channel_Hash(dig->hardwareID());
135  if (keepCellSet.test(onlHash)) {
136  outputDigits->push_back(dig);
137  }
138  } //end loop over input container
139  ATH_MSG_DEBUG("\tCopied " << outputDigits->size() << " of " << inputDigitsContainer->size() << " digits.");
140  }
141 
142  //(MC) start loop over hits container
143  if (m_isMC){
144  if (keepCellSet.any()){
145  SG::ReadHandle<LArHitContainer> inputHitsContainer(m_hitsInputKey,ctx);
146 
147  for (const LArHit* hit : *inputHitsContainer) {
148  const HWIdentifier hwid = larCabling->createSignalChannelID(hit->cellID());
149  const IdentifierHash onlHash = m_onlineID->channel_Hash(hwid);
150 
151  if (keepCellSet.test(onlHash)) {
152  LArHit* clusHit = new LArHit(hit->cellID(),hit->energy(),hit->time());
153  clusHit->finalize();
154  outputHits->push_back(clusHit);
155  }
156  } //end loop over input container
157 
158  ATH_MSG_DEBUG("\tCopied " << outputHits->size() << " of " << inputHitsContainer->size() << " hits.");
159  } // end keepCellSet.any()
160  } // end-if MC
161 
162  return StatusCode::SUCCESS;
163 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArOnlineID_Base::channel_Hash
IdentifierHash channel_Hash(HWIdentifier channelId) const
Create channel_hash from channel_Id.
Definition: LArOnlineID_Base.cxx:1636
CaloThinCellsInAODAlg::m_caloCellOutputKey
SG::WriteHandleKey< ConstCaloCellCont_t > m_caloCellOutputKey
Definition: CaloThinCellsInAODAlg.h:71
CaloThinCellsInAODAlg.h
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloThinCellsInAODAlg::m_clusterPtCut
Gaudi::Property< float > m_clusterPtCut
Definition: CaloThinCellsInAODAlg.h:52
CaloThinCellsInAODAlg::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: CaloThinCellsInAODAlg.h:56
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
LArHit::finalize
void finalize()
The method to be called at the end of event by SD.
Definition: LArHit.h:143
skel.it
it
Definition: skel.GENtoEVGEN.py:423
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
HWIdentifier
Definition: HWIdentifier.h:13
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
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
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
CaloThinCellsInAODAlg::initialize
virtual StatusCode initialize() override
Gaudi initialize method.
Definition: CaloThinCellsInAODAlg.cxx:17
CaloThinCellsInAODAlg::m_caloCellId
const CaloCell_ID * m_caloCellId
Definition: CaloThinCellsInAODAlg.h:46
AthenaHitsVector::push_back
void push_back(T *t)
Definition: AthenaHitsVector.h:153
CaloThinCellsInAODAlg::m_digitsOutputKey
SG::WriteHandleKey< ConstLArDigitCont_t > m_digitsOutputKey
Definition: CaloThinCellsInAODAlg.h:69
LArDigit
Liquid Argon digit base class.
Definition: LArDigit.h:25
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
CaloThinCellsInAODAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Execute the algorithm.
Definition: CaloThinCellsInAODAlg.cxx:49
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
CaloThinCellsInAODAlg::m_digitsInputKey
SG::ReadHandleKey< LArDigitContainer > m_digitsInputKey
Definition: CaloThinCellsInAODAlg.h:60
CaloThinCellsInAODAlg::m_isMC
Gaudi::Property< bool > m_isMC
Definition: CaloThinCellsInAODAlg.h:54
CaloThinCellsInAODAlg::m_clusterCntKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterCntKey
Definition: CaloThinCellsInAODAlg.h:65
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
LArOnOffIdMapping::createSignalChannelID
HWIdentifier createSignalChannelID(const Identifier &id) const
create a HWIdentifier from an Identifier (not inline)
Definition: LArOnOffIdMapping.h:126
CaloCell_Base_ID::is_em_barrel
bool is_em_barrel(const Identifier id) const
test if the id belongs to the EM barrel
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArHit
Class to store hit energy and time in LAr cell from G4 simulation.
Definition: LArHit.h:25
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
CaloThinCellsInAODAlg::m_rawChInputKey
SG::ReadHandleKey< LArRawChannelContainer > m_rawChInputKey
Definition: CaloThinCellsInAODAlg.h:61
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CaloThinCellsInAODAlg::m_rawChOutputKey
SG::WriteHandleKey< LArRawChannelContainer > m_rawChOutputKey
Definition: CaloThinCellsInAODAlg.h:70
CaloThinCellsInAODAlg::m_hitsInputKey
SG::ReadHandleKey< LArHitContainer > m_hitsInputKey
Definition: CaloThinCellsInAODAlg.h:59
AthenaHitsVector::size
size_type size() const
Definition: AthenaHitsVector.h:151
ReadHandle.h
Handle class for reading from StoreGate.
IdentifierHash
Definition: IdentifierHash.h:38
CaloThinCellsInAODAlg::m_caloCellInputKey
SG::ReadHandleKey< CaloCellContainer > m_caloCellInputKey
Definition: CaloThinCellsInAODAlg.h:62
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
CaloThinCellsInAODAlg::m_clusterEtaCut
Gaudi::Property< float > m_clusterEtaCut
Definition: CaloThinCellsInAODAlg.h:53
CaloThinCellsInAODAlg::m_hitsOutputKey
SG::WriteHandleKey< LArHitContainer > m_hitsOutputKey
Definition: CaloThinCellsInAODAlg.h:68
CaloThinCellsInAODAlg::m_onlineID
const LArOnlineID * m_onlineID
Definition: CaloThinCellsInAODAlg.h:45
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20