ATLAS Offline Software
TileCellToTTL1.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 // Filename : TileCellToTTL1.cxx
7 // Author : Monica Dunford
8 // Created : Oct, 2009
9 //
10 // DESCRIPTION:
11 // This is a tool which builds the L1 tower energy from the energy measured
12 // by the tile cells. This tool is useful for L1Calo to compare their
13 // tower energy to that measured by the digital readout in tile
14 //
15 //
16 // HISTORY:
17 //
18 // BUGS:
19 //
20 //*****************************************************************************
21 
22 // Tile includes
23 #include "TileCellToTTL1.h"
25 
26 // Calo includes
27 #include "CaloIdentifier/TileID.h"
29 
30 // Atlas includes
31 #include "StoreGate/ReadHandle.h"
32 #include "StoreGate/WriteHandle.h"
34 
35 //C++ STL includes
36 #include <vector>
37 
38 //
39 // Constructor
40 //
41 TileCellToTTL1::TileCellToTTL1(const std::string& name, ISvcLocator* pSvcLocator)
42  : AthAlgorithm(name, pSvcLocator)
43  , m_tileID(0)
44  , m_TT_ID(0)
45  , m_tileCablingService(0)
46 {
47 
48 }
49 
51 }
52 
53 //
54 // Alg standard initialize function
55 //
57 
58  // retrieve CaloLVL1_ID, TileID, from det store
61 
63 
65  ATH_CHECK( m_ttl1CellContainerKey.initialize() );
66 
67  ATH_MSG_INFO( "TileCellToTTL1 initialization completed");
68 
69  return StatusCode::SUCCESS;
70 }
71 /*==========================================================================*/
72 //
73 // Begin Execution Phase.
74 //
76 
77  ATH_MSG_DEBUG( "Executing TileCellToTTL1");
78 
79  // -------------------------------------------------
80  // Load the TileCell container
81  // -------------------------------------------------
82 
84  ATH_CHECK( cellContainer.isValid() );
85 
86  // -------------------------------------------------
87  // Create TTL1 container and other arrays
88  // -------------------------------------------------
90 
91  // Register the TTL1 container in the TES
92  ATH_CHECK( ttl1CellContainer.record(std::make_unique<TileTTL1CellContainer>()) );
93  ATH_MSG_DEBUG( "TileTTL1Container registered successfully (" << m_ttl1CellContainerKey.key() << ")");
94 
95  int ttNpmt[32][64]; // array of TT occupancy
96  Identifier ttId[32][64]; // array of TT identifiers
97  float ttAmp[32][64]; // array of all TT amplitudes
98  uint16_t ttStatusCells[32][64]; // array of TT status of cells
99  uint16_t ttStatusChans[32][64]; // array of TT status of channels
100  float ttTimeAve[32][64]; // array of TT time average
101  float ttCorrFact[32][64]; // array of TT correction factor
102 
103  // clear the arrays
104  for (int i = 0; i < 32; i++) {
105  for (int j = 0; j < 64; j++) {
106  ttNpmt[i][j] = 0;
107  ttId[i][j] = 0;
108  ttAmp[i][j] = 0.0;
109  ttStatusCells[i][j] = 0;
110  ttStatusChans[i][j] = 0;
111  ttTimeAve[i][j] = 0.0;
112  ttCorrFact[i][j] = 1.0; // this is a place holder for now, set to 1.0
113  }
114  }
115 
116  // -------------------------------------------------
117  // Loop over all cells
118  // -------------------------------------------------
119 
120  for (const CaloCell* cell : *cellContainer) {
121 
122  // keep only cells from TileCal calorimeter barrel or extended barrel
123  Identifier cell_id = cell->ID();
124  if (!(m_tileID->is_tile(cell_id))) continue;
125 
126  const TileCell* tilecell = dynamic_cast<const TileCell*>(cell);
127  if (!tilecell) continue;
128 
129  float cell_ene = cell->energy();
130  float cell_time = cell->time();
131 
132  int bad_cell = tilecell->badcell();
133  int bad_chan[2];
134  bad_chan[0] = tilecell->badch1();
135  bad_chan[1] = tilecell->badch2();
136 
137  // In order to make sure that the D-cells are correctly added
138  // across two towers. Loop over the two PMTs in each cell
139  // for each PMT reduce the cell energy by 50%.
140 
141  for (int ipmt = 0; ipmt < 2; ipmt++) {
142  Identifier pmt_id = m_tileID->pmt_id(cell_id, ipmt);
143  Identifier tt_id = m_tileCablingService->pmt2tt_id(pmt_id);
144 
145  // remove the E-cells
146  int sample = m_tileID->sample(pmt_id);
147  if (sample == TileID::SAMP_E) continue;
148 
149  // if in the negative eta region add 16 to the ieta offset arrays
150  int eta_offset = 0;
151  if (m_tileID->is_negative(pmt_id))
152  eta_offset = 16;
153 
154  // the D0 cell is not being split correctly across cells
155  int ieta = m_TT_ID->eta(tt_id);
156  if (sample == TileID::SAMP_D && ieta == 0 && ipmt == 1)
157  eta_offset = 16;
158 
159  ieta += eta_offset;
160  int iphi = m_TT_ID->phi(tt_id);
161 
162  // Sum the tower energy
163  // already exists - just add charge
164  // reduce cell energy by 50% because we are loop over both pmts in cell
165  if (ttNpmt[ieta][iphi] > 0) {
166  ttAmp[ieta][iphi] += cell_ene * 0.5;
167  ttNpmt[ieta][iphi]++;
168  ttStatusCells[ieta][iphi] += (uint16_t) bad_cell;
169  ttStatusChans[ieta][iphi] += (uint16_t) bad_chan[ipmt];
170  ttTimeAve[ieta][iphi] += cell_time;
171 
172  // rawChannel in new TT
173  } else {
174  ttId[ieta][iphi] = tt_id;
175  ttNpmt[ieta][iphi]++;
176  ttAmp[ieta][iphi] = cell_ene * 0.5;
177  ttStatusCells[ieta][iphi] = (uint16_t) bad_cell;
178  ttStatusChans[ieta][iphi] = (uint16_t) bad_chan[ipmt];
179  ttTimeAve[ieta][iphi] = cell_time;
180  }
181 
182  } // end of loop over pmts in the cell
183  } // end loop over cells
184 
185  for (int ieta = 0; ieta < 32; ieta++) {
186  for (int iphi = 0; iphi < 64; iphi++) {
187 
188  // don't load towers that are empty
189  if (ttNpmt[ieta][iphi] == 0) continue;
190 
191  float time_ave = ttTimeAve[ieta][iphi] / ((float) ttNpmt[ieta][iphi]);
192 
193  uint16_t qual = 0;
194  if (ttStatusChans[ieta][iphi] == ttNpmt[ieta][iphi])
196  if (ttStatusCells[ieta][iphi] > 0)
198  if (ttStatusChans[ieta][iphi] > 0)
200 
201  ttl1CellContainer->push_back(std::make_unique<TileTTL1Cell>(ttId[ieta][iphi],
202  ttAmp[ieta][iphi],
203  time_ave,
204  ttCorrFact[ieta][iphi],
205  qual));
206 
207  }
208  }
209 
210 
211  // Execution completed
212  ATH_MSG_DEBUG( "TileCellToTTL1 execution completed.");
213 
214  return StatusCode::SUCCESS;
215 }
216 
218 
219  ATH_MSG_INFO( "TileCellToTTL1::finalize() end");
220 
221  return StatusCode::SUCCESS;
222 }
223 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileCell::badcell
virtual bool badcell(void) const override final
check if whole cell is bad (i.e.
Definition: TileCell.h:220
TileCell
Definition: TileCell.h:57
TileTTL1Cell::MASK_BADCELL
@ MASK_BADCELL
Definition: TileTTL1Cell.h:44
TileCellToTTL1::m_TT_ID
const CaloLVL1_ID * m_TT_ID
Definition: TileCellToTTL1.h:77
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TileCablingService::pmt2tt_id
Identifier pmt2tt_id(const Identifier &id) const
Definition: TileCablingService.cxx:375
TileCablingService::getInstance
static const TileCablingService * getInstance()
get pointer to service instance
Definition: TileCablingService.cxx:24
TileCellToTTL1::m_cellContainerKey
SG::ReadHandleKey< CaloCellContainer > m_cellContainerKey
Definition: TileCellToTTL1.h:67
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TileCell::badch1
bool badch1(void) const
check if first PMT is in bad channel list and masked
Definition: TileCell.h:215
TileCellToTTL1::TileCellToTTL1
TileCellToTTL1(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TileCellToTTL1.cxx:41
Tile_Base_ID::sample
int sample(const Identifier &id) const
Definition: Tile_Base_ID.cxx:171
Tile_Base_ID::SAMP_E
@ SAMP_E
Definition: Tile_Base_ID.h:55
TileID.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TileTTL1Cell::MASK_BADCHAN
@ MASK_BADCHAN
Definition: TileTTL1Cell.h:45
CaloLVL1_ID::phi
int phi(const Identifier id) const
return phi according to :
Definition: CaloLVL1_ID.h:659
TileCellToTTL1::execute
StatusCode execute()
Definition: TileCellToTTL1.cxx:75
WriteHandle.h
Handle class for recording to StoreGate.
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:100
TileCablingService.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
TileCellToTTL1::initialize
StatusCode initialize()
Definition: TileCellToTTL1.cxx:56
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
TileCell::badch2
bool badch2(void) const
check if second PMT is in bad channel list and masked
Definition: TileCell.h:218
TileCellToTTL1::m_ttl1CellContainerKey
SG::WriteHandleKey< TileTTL1CellContainer > m_ttl1CellContainerKey
Definition: TileCellToTTL1.h:70
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
AtlasDetectorID::is_tile
bool is_tile(Identifier id) const
Definition: AtlasDetectorID.h:695
TileCellToTTL1::finalize
StatusCode finalize()
Definition: TileCellToTTL1.cxx:217
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
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
CaloLVL1_ID::eta
int eta(const Identifier id) const
return eta according to :
Definition: CaloLVL1_ID.h:653
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Tile_Base_ID::SAMP_D
@ SAMP_D
Definition: Tile_Base_ID.h:55
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
CaloLVL1_ID.h
TileCellToTTL1::m_tileID
const TileID * m_tileID
Definition: TileCellToTTL1.h:76
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
Tile_Base_ID::pmt_id
Identifier pmt_id(const Identifier &any_id) const
Definition: Tile_Base_ID.cxx:640
Tile_Base_ID::is_negative
bool is_negative(const Identifier &id) const
Definition: Tile_Base_ID.cxx:241
beamspotman.qual
qual
Definition: beamspotman.py:481
TileTTL1Cell::MASK_BADTOWER
@ MASK_BADTOWER
Definition: TileTTL1Cell.h:43
TileCellToTTL1.h
ReadHandle.h
Handle class for reading from StoreGate.
TileCellToTTL1::~TileCellToTTL1
virtual ~TileCellToTTL1()
Definition: TileCellToTTL1.cxx:50
readCCLHist.float
float
Definition: readCCLHist.py:83
TileCellToTTL1::m_tileCablingService
const TileCablingService * m_tileCablingService
Definition: TileCellToTTL1.h:78