ATLAS Offline Software
LArCellBuilderFromLArRawChannelTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 // implementation of LArCellBuilderFromLArRawChannelTool
7 // H.Ma Mar 2001
8 
9 // Updated Jun 10, 2001. H. Ma
10 // made a tool June 2, 2004 D. Rousseau
11 // Major overhaul, Feb 2008, W.Lampl
12 // Migrate to athenaMT, March 2018, W.Lampl
13 
14 
16 #include "LArRecEvent/LArCell.h"
23 
24 #include "StoreGate/ReadHandle.h"
26 #include "GaudiKernel/SystemOfUnits.h"
27 
28 #include <bitset>
29 
30 
32 
34 
35  ATH_CHECK( detStore()->retrieve (m_caloCID, "CaloCell_ID") );
36 
38  ATH_CHECK( detStore()->retrieve(m_onlineID, "LArOnlineID") );
39 
40  if (!m_missingFebKey.key().empty()) {
41  ATH_CHECK( m_missingFebKey.initialize() );
42  }
43  else {
44  if (m_addDeadOTX) {
45  ATH_MSG_ERROR( "Configuration problem: 'addDeadOTX' set, but no missing FEB container given." );
46  return StatusCode::FAILURE;
47  }
48  }
49 
51 
52  //Compute total number of cells
53  m_nTotalCells=0;
54 
55  IdentifierHash caloCellMin, caloCellMax ;
56  m_caloCID->calo_cell_hash_range(CaloCell_ID::LAREM,caloCellMin,caloCellMax);
57  m_nTotalCells+=caloCellMax-caloCellMin;
58  m_caloCID->calo_cell_hash_range(CaloCell_ID::LARHEC,caloCellMin,caloCellMax);
59  m_nTotalCells+=caloCellMax-caloCellMin;
60  m_caloCID->calo_cell_hash_range(CaloCell_ID::LARFCAL,caloCellMin,caloCellMax);
61  m_nTotalCells+=caloCellMax-caloCellMin;
62 
64  ATH_MSG_DEBUG("Initial size of DataPool<LArCell>: " << m_initialDataPoolSize);
65 
66  ATH_MSG_DEBUG("Initialisating finished");
67  return StatusCode::SUCCESS;
68 }
69 
70 
71 
72 // ========================================================================================== //
75  const EventContext& ctx) const
76 {
77  if (theCellContainer->ownPolicy() == SG::OWN_ELEMENTS) {
78  ATH_MSG_ERROR( "Called with a CaloCellContainer with wrong ownership policy! Need a VIEW container!" );
79  return StatusCode::FAILURE;
80  }
81 
83  if(!rawColl.isValid()) {
84  ATH_MSG_ERROR( " Can not retrieve LArRawChannelContainer: "
85  << m_rawChannelsKey.key() );
86  return StatusCode::FAILURE;
87  }
88 
89  const size_t nRawChannels=rawColl->size();
90  if (nRawChannels==0) {
91  ATH_MSG_WARNING( "Got empty LArRawChannel container. Do nothing" );
92  return StatusCode::SUCCESS;
93  }
94  else
95  ATH_MSG_DEBUG("Got " << nRawChannels << " LArRawChannels");
96 
97 
98  unsigned nCellsAdded=0;
99  std::bitset<CaloCell_ID::NSUBCALO> includedSubcalos;
100  // resize calo cell container to correct size
101  if (!theCellContainer->empty()) {
102  ATH_MSG_WARNING( "Container should be empty! Clear now.");
103  theCellContainer->clear();
104  }
105 
107 
109  const LArOnOffIdMapping* cabling=*cablingHdl;
110 
112  const CaloDetDescrManager* caloDDM = *caloMgrHandle;
113 
114  theCellContainer->resize(m_nTotalCells);
115 
116  for (const LArRawChannel& rawChan : *rawColl) {
117  const HWIdentifier hwid=rawChan.channelID();
118  const IdentifierHash onlHash=m_onlineID->channel_Hash(hwid);
119  if( cabling->isOnlineConnectedFromHash(onlHash)) {
120  const IdentifierHash oflHash= cabling->oflHashFromOnlHash(onlHash);
121  const Identifier id=m_caloCID->cell_id(oflHash);
122  const CaloDetDescrElement * theDDE=caloDDM->get_element(oflHash);
123 
124  LArCell *pCell = pool.nextElementPtr();
125 
126  *pCell = LArCell (theDDE,
127  id,
128  rawChan.energy(),
129  rawChan.time()*Gaudi::Units::picosecond/Gaudi::Units::nanosecond, // convert time from ps (LArRawChannel) to ns
130  rawChan.quality(),
131  rawChan.provenance(),
132  rawChan.gain());
133 
134  if ((*theCellContainer)[oflHash]) {
135  ATH_MSG_WARNING("Channel added twice! Data corruption? hash="
136  << oflHash << " online ID=0x" << std::hex
137  << hwid.get_identifier32().get_compact() << std::dec
138  << " " << m_onlineID->channel_name(hwid));
139  } else {
140  (*theCellContainer)[oflHash] = pCell;
141  ++nCellsAdded;
142  includedSubcalos.set(m_caloCID->sub_calo(oflHash));
143  }
144  }//end if connected
145  }//end loop over LArRawChannelContainer
146 
147  //Now add in dummy cells (if requested)
148  unsigned nMissingButPresent=0;
149 
150  if (m_addDeadOTX) {
152  const LArBadFebCont::BadChanVec& allMissingFebs=(*missingFebHdl)->fullCont();
153 
154  for (const LArBadFebCont::BadChanEntry& it : allMissingFebs) {
155  const LArBadFeb& febstatus=it.second;
156  if (febstatus.deadReadout() || febstatus.deadAll() || febstatus.deactivatedInOKS() ) {
157  const HWIdentifier febId(it.first);
158  //Loop over channels belonging to this FEB
159  const int chansPerFeb=m_onlineID->channelInSlotMax(febId);
160  for (int ch=0; ch<chansPerFeb; ++ch) {
161  const HWIdentifier hwid = m_onlineID->channel_Id(febId, ch);
162  if ( cabling->isOnlineConnected(hwid)) {
163  const Identifier id=cabling->cnvToIdentifier(hwid);
164  const IdentifierHash hashid= m_caloCID->calo_cell_hash(id);
165  const CaloDetDescrElement * theDDE=caloDDM->get_element(hashid);
166  LArCell *pCell = pool.nextElementPtr();
167  *pCell = LArCell (theDDE,
168  id,
169  0.0, //energy
170  0.0, //time
171  0.0, //quality;
172  0x0A00, // 0x0800 (dead) + 0x0200 (to indicate missing readout)
174 
175 
176  if ((*theCellContainer)[hashid]) {
177  ++nMissingButPresent;
178  ATH_MSG_DEBUG("The supposedly missing channel with online ID=0x" << std::hex
179  << hwid.get_identifier32().get_compact() << std::dec
180  << " " << m_onlineID->channel_name(hwid)
181  << " is actually present in the LArRawChannel container");
182  }
183  else {
184  (*theCellContainer)[hashid]=pCell;
185  ++nCellsAdded;
186  includedSubcalos.set(m_caloCID->sub_calo(hashid));
187  }
188  }//end if connected
189  }//end loop over channels of one missing FEB
190  }//end if is dead/missing FEB
191  }//end loop over bad/missing FEBs
192  }//end if m_addDeadOTX
193 
194  //Set the 'hasCalo' variable of CaloCellContainer
195  for (int iCalo=0;iCalo<CaloCell_ID::NSUBCALO;++iCalo) {
196  if (includedSubcalos.test(iCalo))
197  theCellContainer->setHasCalo(static_cast<CaloCell_ID::SUBCALO>(iCalo));
198  }
199 
200  if (nMissingButPresent)
201  ATH_MSG_WARNING( "A total of " << nMissingButPresent
202  << " supposedly missing channels where present in the LArRawChannelContainer" );
203 
204  if (nCellsAdded!=m_nTotalCells) {
205  ATH_MSG_DEBUG("Filled only " << nCellsAdded << " out of " << m_nTotalCells << " cells. Removing holes");
206  auto end1=std::remove(theCellContainer->begin(),theCellContainer->end(),nullptr);
207  theCellContainer->erase(end1,theCellContainer->end());
208  ATH_MSG_DEBUG("Shrunk the cell container to " << theCellContainer->size() << " (" << m_nTotalCells-nCellsAdded << " cells missing)");
209  }//end if nCellsAdded!=m_nTotalCells
210  else
211  ATH_MSG_DEBUG("All " << nCellsAdded << " cells filled (no holes)");
212 
213  return StatusCode::SUCCESS;
214 }
LArCellBuilderFromLArRawChannelTool.h
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CaloCell_Base_ID::LARFCAL
@ LARFCAL
Definition: CaloCell_Base_ID.h:46
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
LArOnlineID_Base::channel_Hash
IdentifierHash channel_Hash(HWIdentifier channelId) const
Create channel_hash from channel_Id.
Definition: LArOnlineID_Base.cxx:1632
CaloCell_Base_ID::calo_cell_hash
IdentifierHash calo_cell_hash(const Identifier cellId) const
create hash id from 'global' cell id
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
python.SystemOfUnits.nanosecond
int nanosecond
Definition: SystemOfUnits.py:119
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CaloCellContainer::setHasCalo
void setHasCalo(const CaloCell_ID::SUBCALO caloNum)
set which calo has been filled.
Definition: CaloCellContainer.cxx:213
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
CaloDetDescrManager_Base::get_element
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
Definition: CaloDetDescrManager.cxx:159
pool
pool namespace
Definition: libname.h:15
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
skel.it
it
Definition: skel.GENtoEVGEN.py:396
LArBadFeb::deadReadout
bool deadReadout() const
FEB is not sending readout data, but the L1 trigger path is working.
Definition: LArBadFeb.h:33
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
CaloCell_Base_ID::LARHEC
@ LARHEC
Definition: CaloCell_Base_ID.h:46
LArBadXCont::BadChanVec
std::vector< BadChanEntry > BadChanVec
Definition: LArBadChannelCont.h:32
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
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
LArCellBuilderFromLArRawChannelTool::m_rawChannelsKey
SG::ReadHandleKey< LArRawChannelContainer > m_rawChannelsKey
rdo container name (jO)
Definition: LArCellBuilderFromLArRawChannelTool.h:88
LArCellBuilderFromLArRawChannelTool::process
virtual StatusCode process(CaloCellContainer *theCellContainer, const EventContext &ctx) const override
process method as defined in ICaloCellMaker interface
Definition: LArCellBuilderFromLArRawChannelTool.cxx:74
ReadCondHandle.h
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
CaloCell_ID.h
PixelModuleFeMask_create_db.remove
string remove
Definition: PixelModuleFeMask_create_db.py:83
CaloDetDescriptor.h
Definition of CaloDetDescriptor.
LArCellBuilderFromLArRawChannelTool::m_initialDataPoolSize
Gaudi::Property< int > m_initialDataPoolSize
Initial size of DataPool<LArCell>
Definition: LArCellBuilderFromLArRawChannelTool.h:90
LArOnOffIdMapping.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::OWN_ELEMENTS
@ OWN_ELEMENTS
this data object owns its elements
Definition: OwnershipPolicy.h:17
LArRawChannel
Liquid Argon ROD output object base class.
Definition: LArRawChannel.h:40
CaloCell_Base_ID::calo_cell_hash_range
void calo_cell_hash_range(const Identifier id, IdentifierHash &caloCellMin, IdentifierHash &caloCellMax) const
to loop on 'global' cell hashes of one sub-calorimeter alone
LArOnlineID_Base::channelInSlotMax
int channelInSlotMax(const HWIdentifier Id) const
Return the Maximum channel number of a given feb slot.
Definition: LArOnlineID_Base.cxx:287
LArCellBuilderFromLArRawChannelTool::m_addDeadOTX
Gaudi::Property< bool > m_addDeadOTX
activate addition of missing cells from dead OTX
Definition: LArCellBuilderFromLArRawChannelTool.h:89
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
LArBadFeb::deadAll
bool deadAll() const
FEB is completely missing, e.g. powered off.
Definition: LArBadFeb.h:30
CaloCell_Base_ID::SUBCALO
SUBCALO
enumeration of sub calorimeters
Definition: CaloCell_Base_ID.h:46
LArCellBuilderFromLArRawChannelTool::m_onlineID
const LArOnlineID * m_onlineID
Definition: LArCellBuilderFromLArRawChannelTool.h:97
LArOnlineID_Base::channel_Id
HWIdentifier channel_Id(int barrel_ec, int pos_neg, int feedthrough, int slot, int channel) const
create channel identifier from fields
Definition: LArOnlineID_Base.cxx:1565
CaloCell_Base_ID::sub_calo
int sub_calo(const Identifier id) const
returns an int taken from SUBCALO enum and describing the subCalo to which the Id belongs.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArBadXCont::BadChanEntry
std::pair< ChanId_t, LArBC_t > BadChanEntry
Definition: LArBadChannelCont.h:31
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
LArCellBuilderFromLArRawChannelTool::m_missingFebKey
SG::ReadCondHandleKey< LArBadFebCont > m_missingFebKey
Definition: LArCellBuilderFromLArRawChannelTool.h:99
LArCellBuilderFromLArRawChannelTool::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: LArCellBuilderFromLArRawChannelTool.h:96
LArCellBuilderFromLArRawChannelTool::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: LArCellBuilderFromLArRawChannelTool.h:101
DataVector::clear
void clear()
Erase all the elements in the collection.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
DataVector::resize
void resize(size_type sz)
Resizes the collection to the specified number of elements.
LArBadFeb
Definition: LArBadFeb.h:10
LArCell.h
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArCell
Data object for LAr calorimeter readout cell.
Definition: LArCell.h:53
CaloGain::LARHIGHGAIN
@ LARHIGHGAIN
Definition: CaloGain.h:18
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
CaloCell_Base_ID::cell_id
Identifier cell_id(const int subCalo, const int barec_or_posneg, const int sampling_or_fcalmodule, const int region_or_dummy, const int eta, const int phi) const
Make a cell (== channel) ID from constituting fields and subCalo index; for (Mini)FCAL,...
LArBadFeb::deactivatedInOKS
bool deactivatedInOKS() const
Deactivated in OKS.
Definition: LArBadFeb.h:39
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DataPool
a typed memory pool that saves time spent allocation small object. This is typically used by containe...
Definition: DataPool.h:47
DataVector::ownPolicy
SG::OwnershipPolicy ownPolicy() const
Return the ownership policy setting for this container.
CaloIdManager.h
CaloCell_Base_ID::NSUBCALO
@ NSUBCALO
Definition: CaloCell_Base_ID.h:46
LArCellBuilderFromLArRawChannelTool::m_nTotalCells
unsigned m_nTotalCells
Number of cells, set in Initialize()
Definition: LArCellBuilderFromLArRawChannelTool.h:93
ReadHandle.h
Handle class for reading from StoreGate.
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
DataVector::erase
iterator erase(iterator position)
Remove element at a given position.
CaloCell_Base_ID::LAREM
@ LAREM
Definition: CaloCell_Base_ID.h:46
LArOnlineID_Base::channel_name
std::string channel_name(const HWIdentifier id) const
Return a string corresponding to a feedthrough name given an identifier.
Definition: LArOnlineID_Base.cxx:219
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
LArCellBuilderFromLArRawChannelTool::initialize
virtual StatusCode initialize() override
Initialize method.
Definition: LArCellBuilderFromLArRawChannelTool.cxx:31
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
python.SystemOfUnits.picosecond
int picosecond
Definition: SystemOfUnits.py:123
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
LArCellBuilderFromLArRawChannelTool::m_caloCID
const CaloCell_ID * m_caloCID
Definition: LArCellBuilderFromLArRawChannelTool.h:98
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
Identifier
Definition: IdentifierFieldParser.cxx:14