ATLAS Offline Software
Loading...
Searching...
No Matches
TileCellToNtuple.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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 , m_ntuplePtr(0)
44 , m_ntupleID("h110")
45 , m_ntupleLoc("/FILE1/TileRec")
46 , m_scinCells(true)
47 , m_cellContainer("MBTSContainer") // "TileCellContainerKey";
48 , m_tileID(0)
49 , m_tileTBID(0)
50{
51 declareProperty("TileCellContainer", m_cellContainer);
52 declareProperty("NTupleLoc", m_ntupleLoc);
53 declareProperty("NTupleID", m_ntupleID);
54 declareProperty("ScinCells", m_scinCells);
55}
56
60
61// Alg standard interface function
63{
64 ATH_MSG_INFO( "Initialization started" );
65
66 // retrieve TileID helper from det store
67 CHECK( detStore()->retrieve(m_tileID) );
68 CHECK( detStore()->retrieve(m_tileTBID) );
69
70 m_ntupleLoc="/NTUPLES" + m_ntupleLoc;
71
72 SmartDataPtr<NTuple::Directory> DirPtr(ntupleSvc(), m_ntupleLoc);
73 if(!DirPtr) DirPtr = ntupleSvc()->createDirectory(m_ntupleLoc);
74 if(!DirPtr) {
75 ATH_MSG_ERROR( "Invalid Ntuple Directory: " );
76 return StatusCode::FAILURE;
77 }
78 m_ntuplePtr = ntupleSvc()->book(DirPtr.ptr(), m_ntupleID,
79 CLID_ColumnWiseTuple, "TileCell-Ntuple");
80 if(!m_ntuplePtr) {
81 ATH_MSG_ERROR( "Failed to book ntuple: TileCellNtuple" );
82 return StatusCode::FAILURE;
83 }
84
85 CHECK( m_ntuplePtr->addItem("TileCell/ncell", m_nchan, 0, max_chan) );
86 CHECK( m_ntuplePtr->addItem("TileCell/totalE", m_tolE) );
87 CHECK( m_ntuplePtr->addItem("TileCell/energy", m_nchan, m_energy) );
88
89 if (!m_scinCells)
90 CHECK( m_ntuplePtr->addItem("TileCell/enediff", m_nchan, m_enediff) );
91
92 CHECK( m_ntuplePtr->addItem("TileCell/time", m_nchan, m_time) );
93 CHECK( m_ntuplePtr->addItem("TileCell/quality", m_nchan, m_quality) );
94
95 if (m_scinCells) {
96 CHECK( m_ntuplePtr->addItem("TileCell/type", m_nchan, m_type, -1, 6) );
97 CHECK( m_ntuplePtr->addItem("TileCell/module", m_nchan, m_module, 0, 7) );
98 CHECK( m_ntuplePtr->addItem("TileCell/channel", m_nchan, m_channel, 0, 15) );
99 } else {
100 CHECK( m_ntuplePtr->addItem("TileCell/detector", m_nchan, m_detector, 0, 3) );
101 CHECK( m_ntuplePtr->addItem("TileCell/side", m_nchan, m_side, -1, 1) );
102 CHECK( m_ntuplePtr->addItem("TileCell/sample", m_nchan, m_sample, 0, 3) );
103 CHECK( m_ntuplePtr->addItem("TileCell/eta", m_nchan, m_eta, 0, 15) );
104 CHECK( m_ntuplePtr->addItem("TileCell/phi", m_nchan, m_phi, 0, 63) );
105 }
106
107 ATH_MSG_INFO( "Initialization completed" );
108 return StatusCode::SUCCESS;
109}
110
112{
113 m_nchan=0;
114 m_tolE=0.0;
115
116 if (m_scinCells) {
117
118 // step1: read Cells from TDS
119 const TileCellContainer* CellCnt = nullptr;
120 CHECK( evtStore()->retrieve(CellCnt, m_cellContainer) );
121
122 // step2: to fill items in ntuple
124 TileCellContainer::const_iterator end = CellCnt->end();
125 for(; it != end; ++it) {
126 const TileCell *cell = (const TileCell *)(*it);
127 m_tolE+=cell->energy();
128 m_energy[m_nchan]=cell->energy();
129 m_time[m_nchan]=cell->time();
130 m_quality[m_nchan]=cell->quality();
131
132 Identifier id=cell->ID();
133 m_type[m_nchan]=m_tileTBID->type(id);
134 m_channel[m_nchan]=m_tileTBID->channel(id);
135 m_module[m_nchan]=m_tileTBID->module(id);
136
137 m_nchan++;
138
139 if (m_nchan >= max_chan) break;
140 }
141
142 } else {
143
144
145
146
147 // step1: read Cells from TDS
148 const CaloCellContainer* CellCnt = nullptr;
149 CHECK( evtStore()->retrieve(CellCnt, m_cellContainer) );
150
151 // step2: to fill items in ntuple
154 for(; it != end; ++it) {
155 const TileCell *cell = (const TileCell *)(*it);
156 m_tolE+=cell->energy();
157 m_energy[m_nchan]=cell->energy();
158 m_enediff[m_nchan]=cell->eneDiff();
159 m_time[m_nchan]=cell->time();
160 m_quality[m_nchan]=cell->quality();
161
162 Identifier id=m_tileID->cell_id(cell->subcalo_hash());
163 m_detector[m_nchan]=m_tileID->section(id);
164 m_side[m_nchan]=m_tileID->side(id);
165 m_sample[m_nchan]=m_tileID->sample(id);
166 m_eta[m_nchan]=m_tileID->tower(id);
167 m_phi[m_nchan]=m_tileID->module(id);
168
169 m_nchan++;
170
171 if (m_nchan >= max_chan) break;
172 }
173 }
174
175 // step3: commit ntuple
176 CHECK( ntupleSvc()->writeRecord(m_ntuplePtr) );
177
178 // Execution completed.
179 ATH_MSG_DEBUG( "execute() completed successfully" );
180 return StatusCode::SUCCESS;
181}
182
184{
185 ATH_MSG_INFO( "finalize() successfully" );
186 return StatusCode::SUCCESS;
187}
188
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(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 with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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:838
const_iterator end() const noexcept
const_iterator begin() const noexcept
const TileTBID * m_tileTBID
NTuple::Array< int > m_channel
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
std::string m_cellContainer
NTuple::Array< int > m_phi
StatusCode initialize()
std::string m_ntupleID
NTuple::Array< int > m_sample
NTuple::Item< double > m_tolE
NTuple::Array< float > m_enediff
const TileID * m_tileID
std::string m_ntupleLoc
NTuple::Array< int > m_detector
NTuple::Tuple * m_ntuplePtr