ATLAS Offline Software
LArSCSimpleMaker.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 // +======================================================================+
6 // + +
7 // + Author ........: Denis Oliveira Damazio +
8 // + Institute .....: BNL +
9 // + Creation date .: 17/06/2012 +
10 // + Moved to MT : 20/02/2021
11 // + +
12 // +======================================================================+
13 //
14 // ........ includes
15 //
16 #include "LArSCSimpleMaker.h"
21 #include "StoreGate/StoreGateSvc.h"
23 #include <cmath>
25 #include <random>
26 
27 #include <mutex>
28 
33  ISvcLocator* pSvcLocator)
34  : AthReentrantAlgorithm(name, pSvcLocator),
35  m_calo_id_manager(nullptr)
36 {
37 }
38 
42  ATH_CHECK( m_scidtool.retrieve() );
44  ATH_CHECK( detStore()->retrieve (m_calo_id_manager, "CaloIdManager") );
47  return StatusCode::SUCCESS;
48 }
49 
53 StatusCode LArSCSimpleMaker::execute(const EventContext& context) const
54 {
55 
56  // conditions
57  const CaloNoiseSigmaDiff* noise_per_cell = nullptr;
58  if ( m_compNoise ){
59  SG::ReadCondHandle<CaloNoiseSigmaDiff> noise_per_cell_handle(m_noise_per_cell_Key,context);
60  if ( not noise_per_cell_handle.isValid() ) {
61  ATH_MSG_DEBUG("Found invalid read handle for CaloNoiseSigmaDiff");
62  return StatusCode::FAILURE;
63  }
64  noise_per_cell = noise_per_cell_handle.cptr();
65  } // end of if n_compNoise
66 
67  // Not really a condition, but almost
68  const CaloBCIDAverage* caloLumiBCID = nullptr;
69  if (m_addBCID ) {
70  SG::ReadHandle<CaloBCIDAverage> caloLumiBCIDHandle(m_bcidAvgKey, context);
71  if ( not caloLumiBCIDHandle.isValid() ) {
72  ATH_MSG_DEBUG("Found invalid read handle for CaloBCIDAverage");
73  return StatusCode::FAILURE;
74  }
75  caloLumiBCID = caloLumiBCIDHandle.cptr();
76  } // end of if m_addBCID
77 
79  const CaloCell_ID * calo_cell_id = m_calo_id_manager->getCaloCell_ID();
80 
82  const TileID * tile_cell_id = m_calo_id_manager->getTileID();
83 
84  int hash_max = calo_sc_id->calo_cell_hash_max();
85  DataPool<CaloCell> dataPool;
86  if (dataPool.allocated()==0)
87  dataPool.reserve (hash_max);
88 
89  auto cellsHandle = SG::makeHandle( m_cellContainerKey, context );
90  if ( not cellsHandle.isValid() ) {
91  ATH_MSG_ERROR("Did not get CaloCellContainer input");
92  return StatusCode::FAILURE;
93  }
94 
95  const CaloCellContainer* cells = cellsHandle.cptr();
96  ATH_MSG_DEBUG("Got a CaloCellContainer input");
97 
98  std::vector<float> energies (hash_max,0);
99  std::vector<float> enTime (hash_max,0);
100  std::vector<float> enForTime (hash_max,0);
101  std::vector<bool> timeDef (hash_max,false);
102  std::vector<uint16_t> gains (hash_max,0);
103  std::vector<uint16_t> qualities (hash_max,0);
104  std::vector<float> sigma_noise_per_scell(hash_max,0);
105 
106  for (const CaloCell* cell : *cells) {
107  Identifier cell_id = cell->ID();
108  Identifier sCellID = m_scidtool->offlineToSuperCellID (cell_id);
109 
110  if (!sCellID.is_valid()) {
111  // ATH_MSG_WARNING( " SC ID not valid " << sCellID.get_identifier32().get_compact() << " offline id = " << cell->ID().get_identifier32().get_compact() );
112  // calo_sc_id->print(cell->ID());
113  continue;
114  }
115  IdentifierHash hash, cell_hash;
116  hash = calo_sc_id->calo_cell_hash (sCellID);
117  assert (hash < energies.size() );
118  float pedestalshift = 0.0;
119  if ( m_addBCID ) pedestalshift = caloLumiBCID->average(cell_id);
120  energies[hash] += cell->energy() + pedestalshift;
121  if ( m_compNoise && cell->gain() == CaloGain::LARHIGHGAIN ){
122  cell_hash = calo_cell_id->calo_cell_hash(cell_id);
123  sigma_noise_per_scell[hash]+=(*noise_per_cell)[cell_hash];
124  }
125  uint16_t prov = cell->provenance();
126  if ( ((prov & 0x2000) == 0x2000) && (cell->et()>50) ) {
127  // time defined for one of the cells
128  timeDef[hash] = true;
129  enForTime[hash] += cell->energy();
130  enTime[hash] += cell->energy()*cell->time();
131  }
132 
133  gains[hash] = std::max(gains[hash],(uint16_t)cell->gain());
134  if ( qualities[hash] + (int) cell->quality() > 65535 ){
135  qualities[hash] = 65535 ;
136  }else
137  {
138  qualities[hash] += cell->quality();
139  }
140 
141  if ( calo_cell_id->is_tile(cell_id) && tile_cell_id->sampling(cell_id)==TileID::SAMP_D){
142  // Special case for SAMP_D in tile. Signal is split into two SCs
143  int section = tile_cell_id->section (cell_id);
144  int side = tile_cell_id->side (cell_id);
145  int module = tile_cell_id->module (cell_id);
146  int tower = tile_cell_id->tower (cell_id);
147 
148  int section1 = section;
149  int section2 = section;
150  int side1 = side;
151  int side2 = side;
152  int tower1= tower;
153  int tower2= tower-1;
154 
155  if (tower ==0){
156  side1 = -1;
157  side2 = 1;
158  tower1=0;
159  tower2=0;
160  }
161  if (tower==10){
162  section2 = TileID::BARREL;
163  section1 = TileID::EXTBAR;
164  }
165 
166 
167  Identifier sc_id1 = tile_sc_id->cell_id(section1,side1,module,tower1,0);
168  Identifier sc_id2 = tile_sc_id->cell_id(section2,side2,module,tower2,0);
169 
170 
171  int hash1 = calo_sc_id->calo_cell_hash (sc_id1);
172  int hash2 = calo_sc_id->calo_cell_hash (sc_id2);
173 
174  energies[hash1] += cell->energy()*0.5;
175  energies[hash2] += cell->energy()*0.5;
176  }
177 
178 
179  }
180 
181  SG::WriteHandle<CaloCellContainer> scellContainerHandle( m_sCellContainerKey, context);
182  auto superCellContainer = std::make_unique<CaloCellContainer> ();
183 
185  const CaloSuperCellDetDescrManager* caloMgr = *caloSuperCellMgrHandle;
186 
187  superCellContainer->reserve(energies.size());
188 
189  std::default_random_engine generator;
190  for (unsigned int i=0; i < energies.size(); i++) {
191 
192  const CaloDetDescrElement* dde = caloMgr->get_element (i);
193  if (!dde) {
194  // ATH_MSG_WARNING( " Not valid DDE, hash index = "<< i );
195  continue;
196  }
197 
198  // More noise
199  float add_noise = 0.0;
200  IdentifierHash hash = dde->calo_hash();
201  if ( (!dde->is_tile()) && (sigma_noise_per_scell[hash] > 0.0) ){
202  std::normal_distribution<double> distribution(0.0,sigma_noise_per_scell[hash] );
203  add_noise = distribution(generator);
204  }
205  energies[i]+=add_noise;
206 
207  //CaloCell* ss = dataPool.nextElementPtr();
208  CaloCell* ss = new CaloCell();
209  ss->setCaloDDE( caloMgr->get_element (i));
210  ss->setEnergy( energies[i] );
211  uint16_t prov (0);
212  if ( timeDef[i] ){
213  float time = enTime[i] / enForTime[i]; // if timeDef is true, enForTime is > 10
214  float et = ss->et();
215  ss->setTime( time );
216  prov = LArProv::QTPRESENT;// 0x2000;
217  if(et>10e3 && time>-8 && time<16) prov |= LArProv::SCTIMEPASS;//0x200;
218  else if(et<=10e3 && std::abs(time)<8) prov |= LArProv::SCTIMEPASS;//0x200;
219  } else ss->setTime( 999.0 ); // makes sure it will fail some BCID
220 
221  ss->setQuality( qualities[i] );
222  if (calo_sc_id->is_tile(ss->ID()))
223  {
224  ss->setProvenance( 0 );
225  ss->setGain( (CaloGain::CaloGain) 0 );
226  }
227  else
228  {
229  ss->setProvenance( prov );
230  ss->setGain( CaloGain::LARHIGHGAIN );
231  }
232  superCellContainer->push_back(ss);
233 
234  }
235  ATH_CHECK( scellContainerHandle.record( std::move(superCellContainer) ) );
236 
237  return StatusCode::SUCCESS;
238 }
239 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:271
CaloNoiseSigmaDiff
std::vector< float > CaloNoiseSigmaDiff
NAME : CaloNoiseSigmaDiff.h PACKAGE : Calorimeter/CaloConditions.
Definition: CaloNoiseSigmaDiff.h:20
et
Extra patterns decribing particle interation process.
LArSCSimpleMaker::execute
StatusCode execute(const EventContext &context) const
Algorithm execute method.
Definition: LArSCSimpleMaker.cxx:53
LArSCSimpleMaker::m_noise_per_cell_Key
SG::ReadCondHandleKey< CaloNoiseSigmaDiff > m_noise_per_cell_Key
Property SG Key for the Expected Noise Sigma diff in diff gains.
Definition: LArSCSimpleMaker.h:73
CaloCell_Base_ID::calo_cell_hash
IdentifierHash calo_cell_hash(const Identifier cellId) const
create hash id from 'global' cell id
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
LArSCSimpleMaker::m_scidtool
ToolHandle< ICaloSuperCellIDTool > m_scidtool
Property: Offline / supercell mapping tool.
Definition: LArSCSimpleMaker.h:58
max
#define max(a, b)
Definition: cfImp.cxx:41
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
DataPool::reserve
void reserve(unsigned int size)
Set the desired capacity.
LArSCSimpleMaker::m_compNoise
Gaudi::Property< bool > m_compNoise
Definition: LArSCSimpleMaker.h:80
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
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
Tile_Base_ID::side
int side(const Identifier &id) const
Definition: Tile_Base_ID.cxx:153
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
Tile_SuperCell_ID
Helper class for Tile offline identifiers for supercells.
Definition: Tile_SuperCell_ID.h:64
Tile_Base_ID::tower
int tower(const Identifier &id) const
Definition: Tile_Base_ID.cxx:165
CaloIdManager::getTile_SuperCell_ID
const Tile_SuperCell_ID * getTile_SuperCell_ID(void) const
Definition: CaloIdManager.cxx:130
CaloCell_Base_ID::is_tile
bool is_tile(const Identifier id) const
test if the id belongs to the Tiles
Tile_Base_ID::BARREL
@ BARREL
Definition: Tile_Base_ID.h:48
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
LArSCSimpleMaker::m_sCellContainerKey
SG::WriteHandleKey< CaloCellContainer > m_sCellContainerKey
Property: SG key for the output supercell LAr channel container.
Definition: LArSCSimpleMaker.h:68
LArSCSimpleMaker::m_calo_id_manager
const CaloIdManager * m_calo_id_manager
Entry point for calorimeter ID helpers.
Definition: LArSCSimpleMaker.h:89
ICaloSuperCellIDTool.h
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
DataPool::allocated
unsigned int allocated()
return size already allocated OK
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
CaloSuperCellDetDescrManager
Definition: CaloDetDescrManager.h:490
TRT::Hit::side
@ side
Definition: HitInfo.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
python.PyAthena.module
module
Definition: PyAthena.py:134
Tile_Base_ID::EXTBAR
@ EXTBAR
Definition: Tile_Base_ID.h:48
CaloIdManager::getTileID
const TileID * getTileID(void) const
Definition: CaloIdManager.cxx:100
LArSCSimpleMaker::initialize
StatusCode initialize()
Standard Gaudi initialize method.
Definition: LArSCSimpleMaker.cxx:39
CaloDetDescrElement::calo_hash
IdentifierHash calo_hash() const
cell calo hash
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:412
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
Tile_Base_ID::module
int module(const Identifier &id) const
Definition: Tile_Base_ID.cxx:159
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
CaloCell_SuperCell_ID
Helper class for offline supercell identifiers.
Definition: CaloCell_SuperCell_ID.h:48
lumiFormat.i
int i
Definition: lumiFormat.py:92
TileID
Helper class for TileCal offline identifiers.
Definition: TileID.h:68
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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
LArProv::QTPRESENT
@ QTPRESENT
Definition: LArProvenance.h:33
CaloCell_SuperCell_ID.h
Helper class for offline supercell identifiers.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloBCIDAverage
Definition: CaloBCIDAverage.h:16
Tile_Base_ID::sampling
int sampling(const Identifier &id) const
Definition: Tile_Base_ID.h:164
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
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
LArProv::SCTIMEPASS
@ SCTIMEPASS
Definition: LArProvenance.h:29
LArSCSimpleMaker::LArSCSimpleMaker
LArSCSimpleMaker(const std::string &name, ISvcLocator *pSvcLocator)
Standard Gaudi algorithm constructor.
Definition: LArSCSimpleMaker.cxx:32
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
CaloDetDescrElement::is_tile
bool is_tile() const
cell belongs to Tile
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:442
LArSCSimpleMaker::m_caloSuperCellMgrKey
SG::ReadCondHandleKey< CaloSuperCellDetDescrManager > m_caloSuperCellMgrKey
Definition: LArSCSimpleMaker.h:85
LArSCSimpleMaker::m_cellContainerKey
SG::ReadHandleKey< CaloCellContainer > m_cellContainerKey
Property: SG key for the input calorimeter cell container.
Definition: LArSCSimpleMaker.h:63
LArSCSimpleMaker::m_addBCID
Gaudi::Property< bool > m_addBCID
Definition: LArSCSimpleMaker.h:82
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CaloIdManager::getCaloCell_ID
const CaloCell_ID * getCaloCell_ID(void) const
Access to IdHelper.
Definition: CaloIdManager.cxx:63
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloGain::LARHIGHGAIN
@ LARHIGHGAIN
Definition: CaloGain.h:18
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
CaloBCIDAverage::average
float average(const Identifier &id) const
Definition: CaloBCIDAverage.h:27
Tile_Base_ID::SAMP_D
@ SAMP_D
Definition: Tile_Base_ID.h:55
SG::WriteHandle< CaloCellContainer >
mc.generator
generator
Configure Herwig7 These are the commands corresponding to what would go into the regular Herwig infil...
Definition: mc.MGH7_FxFx_H71-DEFAULT_test.py:18
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
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
CaloIdManager::getCaloCell_SuperCell_ID
const CaloCell_SuperCell_ID * getCaloCell_SuperCell_ID(void) const
Definition: CaloIdManager.cxx:110
LArProvenance.h
DataPool
a typed memory pool that saves time spent allocation small object. This is typically used by containe...
Definition: DataPool.h:47
CaloIdManager.h
Tile_Base_ID::section
int section(const Identifier &id) const
Definition: Tile_Base_ID.cxx:147
LArSCSimpleMaker::m_bcidAvgKey
SG::ReadHandleKey< CaloBCIDAverage > m_bcidAvgKey
Property SG Key for the CaloLumiBCID.
Definition: LArSCSimpleMaker.h:77
LArSCSimpleMaker.h
IdentifierHash
Definition: IdentifierHash.h:38
section
void section(const std::string &sec)
Definition: TestTriggerMenuAccess.cxx:22
Tile_Base_ID::cell_id
Identifier cell_id(const Identifier &any_id) const
Definition: Tile_Base_ID.cxx:581
IGeoModelSvc.h
StoreGateSvc.h
CaloCell_Base_ID::calo_cell_hash_max
size_type calo_cell_hash_max(void) const
cell 'global' hash table max size
SG::ReadCondHandle::cptr
const_pointer_type cptr()
Definition: ReadCondHandle.h:67