ATLAS Offline Software
Loading...
Searching...
No Matches
TileTTL1ToNtuple.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5//*****************************************************************************
6// Filename : TileTTL1ToNtuple.cxx
7// Author : Gia
8// Created : March, 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
26
27// Calo include
30
31//TileCalo include
34
35TileTTL1ToNtuple::TileTTL1ToNtuple(const std::string& name, ISvcLocator* pSvcLocator)
36 : AthAlgorithm(name, pSvcLocator)
37 , m_ntuplePtr(0)
38 , m_ntupleID("h130")
39 , m_ntupleLoc("/FILE1/TileRec")
40 , m_ttl1Container("TileTTL1Cnt")
41 , m_TT_ID(0)
42 , m_tileTBID(0)
43{
44 declareProperty("TileTTL1Container", m_ttl1Container);
45 declareProperty("NTupleLoc", m_ntupleLoc);
46 declareProperty("NTupleID", m_ntupleID);
47 declareProperty("CommitNtuple", m_commitNtuple = true);
48 declareProperty("MaxLength", m_maxLength = 2048);
49 declareProperty("NSamples", m_nSamples = 7);
50
51}
52
56
57//****************************************************************************
58//* Initialization
59//****************************************************************************
60
62{
63
64 ATH_MSG_INFO( "Initialization started" );
65
66 // retrieve TileID helper from det store
67
68 CHECK( detStore()->retrieve(m_TT_ID) );
69 CHECK( detStore()->retrieve(m_tileTBID) );
70
71 m_ntupleLoc="/NTUPLES" + m_ntupleLoc;
72
73 SmartDataPtr<NTuple::Directory> DirPtr(ntupleSvc(), m_ntupleLoc);
74 if(!DirPtr) DirPtr=ntupleSvc()->createDirectory(m_ntupleLoc);
75 if(!DirPtr) {
76 ATH_MSG_ERROR( "Invalid Ntuple Directory: " );
77 return StatusCode::FAILURE;
78 }
79 m_ntuplePtr=ntupleSvc()->book(DirPtr.ptr(), m_ntupleID,
80 CLID_ColumnWiseTuple, "TileTTL1-Ntuple");
81 if(!m_ntuplePtr) {
82
83 std::string ntupleCompleteID=m_ntupleLoc+"/"+m_ntupleID;
84
85 NTuplePtr nt(ntupleSvc(),ntupleCompleteID);
86 if (!nt) {
87 ATH_MSG_ERROR( "Failed to book or to retrieve ntuple "
88 << ntupleCompleteID );
89 return StatusCode::FAILURE;
90 } else {
91 ATH_MSG_INFO( "Reaccessing ntuple " << ntupleCompleteID );
92 m_ntuplePtr = nt;
93 }
94 }
95
96 CHECK( m_ntuplePtr->addItem("TileTTL1/nttl1",m_nchan,0,m_maxLength) );
97 CHECK( m_ntuplePtr->addItem("TileTTL1/side",m_nchan,m_side,-1,1) );
98 CHECK( m_ntuplePtr->addItem("TileTTL1/eta",m_nchan,m_eta,0,15) );
99 CHECK( m_ntuplePtr->addItem("TileTTL1/phi",m_nchan,m_phi,0,63) );
100 CHECK( m_ntuplePtr->addItem("TileTTL1/samples",m_maxLength,m_nSamples,m_samples) );
101
102 ATH_MSG_INFO( "Initialization completed" );
103 return StatusCode::SUCCESS;
104}
105
106//****************************************************************************
107//* Execution
108//****************************************************************************
109
111{
112
113 // step1: read TileTTL1s from TDS
114 const TileTTL1Container* TTL1Cnt = nullptr;
115 CHECK( evtStore()->retrieve(TTL1Cnt, m_ttl1Container) );
116
117 // step2: put items in ntuple
120
121 m_nchan=0;
122 for(; it != end; ++it) {
123
124 if (m_nchan >= m_maxLength) {
125 ATH_MSG_DEBUG( "Number of ttl1s exceeds maximum ("
126 << m_maxLength << "), ignore all the rest");
127 break;
128 }
129
130 const TileTTL1 * cinp = (*it);
131 Identifier id=cinp->TTL1_ID();
132
133 if (m_tileTBID->is_tiletb(id)) {
134 m_side[m_nchan]=m_tileTBID->type(id);
135 m_eta[m_nchan]=m_tileTBID->channel(id);
136 m_phi[m_nchan]=m_tileTBID->module(id);
137 } else {
138 m_side[m_nchan]=m_TT_ID->pos_neg_z(id);
139 m_eta[m_nchan]=m_TT_ID->eta(id);
140 m_phi[m_nchan]=m_TT_ID->phi(id);
141 }
142
143 std::vector<float> samples = cinp->fsamples();
144 samples.resize(m_nSamples);
145 for(int i=0;i<m_nSamples;++i)
146 m_samples[m_nchan][i] = samples[i];
147
148 if (msgLvl(MSG::VERBOSE)) {
149 msg(MSG::VERBOSE) << " ichan=" << static_cast<int>(m_nchan) << " "
150 << m_side[m_nchan] << " /" << m_eta[m_nchan] << " /"
151 << m_phi[m_nchan] << " samples=";
152
153 for (int i = 0; i < m_nSamples; ++i)
154 msg(MSG::VERBOSE) << samples[i] << " ";
155
156 msg(MSG::VERBOSE) << endmsg;
157 }
158 m_nchan++;
159 }
160
161 // step3: commit ntuple
162 if ( m_commitNtuple ) {
163 ATH_MSG_DEBUG( "Committing Ntuple" );
164 CHECK( ntupleSvc()->writeRecord(m_ntuplePtr) );
165 }
166
167 // Execution completed.
168 ATH_MSG_DEBUG( "execute() completed successfully" );
169 return StatusCode::SUCCESS;
170}
171
172//****************************************************************************
173//* Finalize
174//****************************************************************************
175
177{
178 ATH_MSG_INFO( "finalize() completed successfully" );
179 return StatusCode::SUCCESS;
180}
181
#define endmsg
#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()
TileContainer< TileTTL1 > TileTTL1Container
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
bool msgLvl(const MSG::Level lvl) const
MsgStream & msg() const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
const_iterator begin() const noexcept
const CaloLVL1_ID * m_TT_ID
std::string m_ntupleID
NTuple::Array< int > m_eta
const TileTBID * m_tileTBID
NTuple::Matrix< float > m_samples
NTuple::Tuple * m_ntuplePtr
NTuple::Array< int > m_side
std::string m_ntupleLoc
std::string m_ttl1Container
NTuple::Array< int > m_phi
TileTTL1ToNtuple(const std::string &name, ISvcLocator *pSvcLocator)
NTuple::Item< int > m_nchan
StatusCode initialize()
const Identifier & TTL1_ID() const
Definition TileTTL1.cxx:66
const std::vector< float > & fsamples() const
Definition TileTTL1.cxx:77