ATLAS Offline Software
Loading...
Searching...
No Matches
TileCellToNtuple.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5//*****************************************************************************
6// Filename : TileCellToNtuple.cxx
7// Author : Zhifang
8// Created : Jan, 2003
9//
10// DESCRIPTION:
11// Implement the algorithm
12//
13// HISTORY:
14//
15// BUGS:
16//
17//*****************************************************************************
18
19//Gaudi Includes
20#include "GaudiKernel/INTupleSvc.h"
21#include "GaudiKernel/IDataProviderSvc.h"
22#include "GaudiKernel/SmartDataPtr.h"
23
24//Atlas include
27
28// Calo include
32
33//TileCalo include
34#include "TileEvent/TileCell.h"
37
38const int max_chan=5216;
39
40// Constructor & deconstructor
41TileCellToNtuple::TileCellToNtuple(const std::string& name, ISvcLocator* pSvcLocator)
42 : AthAlgorithm(name, pSvcLocator)
43{
44}
45
49
50// Alg standard interface function
52{
53 ATH_MSG_INFO( "Initialization started" );
54
55 // retrieve TileID helper from det store
56 CHECK( detStore()->retrieve(m_tileID) );
57 CHECK( detStore()->retrieve(m_tileTBID) );
58
59 m_ntupleLoc="/NTUPLES" + m_ntupleLoc.value();
60
61 SmartDataPtr<NTuple::Directory> DirPtr(ntupleSvc(), m_ntupleLoc);
62 if(!DirPtr) DirPtr = ntupleSvc()->createDirectory(m_ntupleLoc);
63 if(!DirPtr) {
64 ATH_MSG_ERROR( "Invalid Ntuple Directory: " );
65 return StatusCode::FAILURE;
66 }
67 m_ntuplePtr = ntupleSvc()->book(DirPtr.ptr(), m_ntupleID,
68 CLID_ColumnWiseTuple, "TileCell-Ntuple");
69 if(!m_ntuplePtr) {
70 ATH_MSG_ERROR( "Failed to book ntuple: TileCellNtuple" );
71 return StatusCode::FAILURE;
72 }
73
74 CHECK( m_ntuplePtr->addItem("TileCell/ncell", m_nchan, 0, max_chan) );
75 CHECK( m_ntuplePtr->addItem("TileCell/totalE", m_tolE) );
76 CHECK( m_ntuplePtr->addItem("TileCell/energy", m_nchan, m_energy) );
77
78 if (!m_scinCells)
79 CHECK( m_ntuplePtr->addItem("TileCell/enediff", m_nchan, m_enediff) );
80
81 CHECK( m_ntuplePtr->addItem("TileCell/time", m_nchan, m_time) );
82 CHECK( m_ntuplePtr->addItem("TileCell/quality", m_nchan, m_quality) );
83
84 if (m_scinCells) {
85 CHECK( m_ntuplePtr->addItem("TileCell/type", m_nchan, m_type, -1, 6) );
86 CHECK( m_ntuplePtr->addItem("TileCell/module", m_nchan, m_module, 0, 7) );
87 CHECK( m_ntuplePtr->addItem("TileCell/channel", m_nchan, m_channel, 0, 15) );
88 } else {
89 CHECK( m_ntuplePtr->addItem("TileCell/detector", m_nchan, m_detector, 0, 3) );
90 CHECK( m_ntuplePtr->addItem("TileCell/side", m_nchan, m_side, -1, 1) );
91 CHECK( m_ntuplePtr->addItem("TileCell/sample", m_nchan, m_sample, 0, 3) );
92 CHECK( m_ntuplePtr->addItem("TileCell/eta", m_nchan, m_eta, 0, 15) );
93 CHECK( m_ntuplePtr->addItem("TileCell/phi", m_nchan, m_phi, 0, 63) );
94 }
95
96 ATH_MSG_INFO( "Initialization completed" );
97 return StatusCode::SUCCESS;
98}
99
100StatusCode TileCellToNtuple::execute(const EventContext& /*ctx*/)
101{
102 m_nchan=0;
103 m_tolE=0.0;
104
105 if (m_scinCells) {
106
107 // step1: read Cells from TDS
108 const TileCellContainer* CellCnt = nullptr;
109 CHECK( evtStore()->retrieve(CellCnt, m_cellContainer.value()) );
110
111 // step2: to fill items in ntuple
113 TileCellContainer::const_iterator end = CellCnt->end();
114 for(; it != end; ++it) {
115 const TileCell *cell = (const TileCell *)(*it);
116 m_tolE+=cell->energy();
117 m_energy[m_nchan]=cell->energy();
118 m_time[m_nchan]=cell->time();
119 m_quality[m_nchan]=cell->quality();
120
121 Identifier id=cell->ID();
122 m_type[m_nchan]=m_tileTBID->type(id);
123 m_channel[m_nchan]=m_tileTBID->channel(id);
124 m_module[m_nchan]=m_tileTBID->module(id);
125
126 m_nchan++;
127
128 if (m_nchan >= max_chan) break;
129 }
130
131 } else {
132
133
134
135
136 // step1: read Cells from TDS
137 const CaloCellContainer* CellCnt = nullptr;
138 CHECK( evtStore()->retrieve(CellCnt, m_cellContainer.value()) );
139
140 // step2: to fill items in ntuple
143 for(; it != end; ++it) {
144 const TileCell *cell = (const TileCell *)(*it);
145 m_tolE+=cell->energy();
146 m_energy[m_nchan]=cell->energy();
147 m_enediff[m_nchan]=cell->eneDiff();
148 m_time[m_nchan]=cell->time();
149 m_quality[m_nchan]=cell->quality();
150
151 Identifier id=m_tileID->cell_id(cell->subcalo_hash());
152 m_detector[m_nchan]=m_tileID->section(id);
153 m_side[m_nchan]=m_tileID->side(id);
154 m_sample[m_nchan]=m_tileID->sample(id);
155 m_eta[m_nchan]=m_tileID->tower(id);
156 m_phi[m_nchan]=m_tileID->module(id);
157
158 m_nchan++;
159
160 if (m_nchan >= max_chan) break;
161 }
162 }
163
164 // step3: commit ntuple
165 CHECK( ntupleSvc()->writeRecord(m_ntuplePtr) );
166
167 // Execution completed.
168 ATH_MSG_DEBUG( "execute() completed successfully" );
169 return StatusCode::SUCCESS;
170}
171
173{
174 ATH_MSG_INFO( "finalize() successfully" );
175 return StatusCode::SUCCESS;
176}
177
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
INTupleSvc * ntupleSvc()
const int max_chan
TileContainer< TileCell > TileCellContainer
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
ServiceHandle< StoreGateSvc > & evtStore()
const ServiceHandle< StoreGateSvc > & detStore() const
Container class for CaloCell.
CaloCellContainer::const_iterator beginConstCalo(CaloCell_ID::SUBCALO caloNum) const
get const iterators on cell of just one calo
CaloCellContainer::const_iterator endConstCalo(CaloCell_ID::SUBCALO caloNum) const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:861
const_iterator end() const noexcept
const_iterator begin() const noexcept
const TileTBID * m_tileTBID
NTuple::Array< int > m_channel
Gaudi::Property< std::string > m_ntupleID
Gaudi::Property< std::string > m_ntupleLoc
NTuple::Array< int > m_eta
TileCellToNtuple(const std::string &name, ISvcLocator *pSvcLocator)
NTuple::Array< float > m_time
NTuple::Array< int > m_side
NTuple::Array< int > m_type
NTuple::Array< float > m_quality
NTuple::Array< int > m_module
NTuple::Item< int > m_nchan
NTuple::Array< float > m_energy
NTuple::Array< int > m_phi
StatusCode initialize()
Gaudi::Property< bool > m_scinCells
Gaudi::Property< std::string > m_cellContainer
NTuple::Array< int > m_sample
NTuple::Item< double > m_tolE
NTuple::Array< float > m_enediff
const TileID * m_tileID
StatusCode execute(const EventContext &ctx)
Execute method.
NTuple::Array< int > m_detector
NTuple::Tuple * m_ntuplePtr