ATLAS Offline Software
Loading...
Searching...
No Matches
TileHitToNtuple.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 : TileHitToNtuple.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
27
28// Calo include
30
31//TileCalo include
34
35TileHitToNtuple::TileHitToNtuple(const std::string& name, ISvcLocator* pSvcLocator)
36 : AthAlgorithm(name, pSvcLocator)
37{
38}
39
43
44//****************************************************************************
45//* Initialization
46//****************************************************************************
47
49{
50
51 ATH_MSG_INFO( "Initialization started" );
52
53 // retrieve TileID helper from det store
54 CHECK( detStore()->retrieve(m_tileID) );
55
56 m_ntupleLoc="/NTUPLES" + m_ntupleLoc.value();
57
58 SmartDataPtr<NTuple::Directory> DirPtr(ntupleSvc(), m_ntupleLoc);
59 if(!DirPtr) DirPtr=ntupleSvc()->createDirectory(m_ntupleLoc);
60 if(!DirPtr) {
61 ATH_MSG_ERROR( "Invalid Ntuple Directory: " );
62 return StatusCode::FAILURE;
63 }
64 m_ntuplePtr=ntupleSvc()->book(DirPtr.ptr(), m_ntupleID,
65 CLID_ColumnWiseTuple, "TileHit-Ntuple");
66 if(!m_ntuplePtr) {
67
68 std::string ntupleCompleteID=m_ntupleLoc+"/"+m_ntupleID;
69
70 NTuplePtr nt(ntupleSvc(),ntupleCompleteID);
71 if (!nt) {
72 ATH_MSG_ERROR( "Failed to book or to retrieve ntuple "
73 << ntupleCompleteID );
74 return StatusCode::FAILURE;
75 } else {
76 ATH_MSG_INFO( "Reaccessing ntuple " << ntupleCompleteID );
77 m_ntuplePtr = nt;
78 }
79 }
80
81 CHECK( m_ntuplePtr->addItem("TileHit/nhit",m_nchan,0,m_maxLength.value()) );
82 CHECK( m_ntuplePtr->addItem("TileHit/totalE",m_tolE) );
83
84 CHECK( m_ntuplePtr->addItem("TileHit/energy",m_nchan,m_energy) );
85 CHECK( m_ntuplePtr->addItem("TileHit/time",m_nchan,m_time) );
86
87 CHECK( m_ntuplePtr->addItem("TileHit/detector",m_nchan,m_detector,0,3) );
88 CHECK( m_ntuplePtr->addItem("TileHit/side",m_nchan,m_side,-1,1) );
89 CHECK( m_ntuplePtr->addItem("TileHit/sample",m_nchan,m_sample,0,3) );
90 CHECK( m_ntuplePtr->addItem("TileHit/pmt", m_nchan, m_pmt,0,1) );
91 CHECK( m_ntuplePtr->addItem("TileHit/eta",m_nchan,m_eta,0,15) );
92 CHECK( m_ntuplePtr->addItem("TileHit/phi",m_nchan,m_phi,0,63) );
93
94 ATH_MSG_INFO( "Initialization completed" );
95 return StatusCode::SUCCESS;
96}
97
98//****************************************************************************
99//* Execution
100//****************************************************************************
101
102StatusCode TileHitToNtuple::execute(const EventContext& /*ctx*/)
103{
104
105 // step1: read TileHits from TDS
106 const TileHitContainer* HitCnt = nullptr;
107 CHECK( evtStore()->retrieve(HitCnt, m_hitContainer.value()) );
108
109 // step2: put items in ntuple
110 SelectAllObject<TileHitContainer> selHits(HitCnt);
111 SelectAllObject<TileHitContainer>::const_iterator it=selHits.begin();
112 SelectAllObject<TileHitContainer>::const_iterator end=selHits.end();
113
114 m_nchan=0;
115 m_tolE=0.0;
116 int n_hit = 0;
117 for(; it != end; ++it) {
118
119 const TileHit * cinp = (*it);
120 Identifier id=cinp->identify();
121
122 int size = cinp->size();
123 for(int i=0;i<size;++i)
124 {
125 m_tolE+=cinp->energy(i);
126 m_energy[m_nchan]=cinp->energy(i);
127 m_time[m_nchan]=cinp->time(i);
128
129 m_detector[m_nchan]=m_tileID->section(id);
130 m_side[m_nchan]=m_tileID->side(id);
131 m_sample[m_nchan]=m_tileID->sample(id);
132 m_pmt[m_nchan]=m_tileID->pmt(id);
133 m_eta[m_nchan]=m_tileID->tower(id);
134 m_phi[m_nchan]=m_tileID->module(id);
135
136 m_nchan++;
137 if (m_nchan >= m_maxLength) break;
138 }
139
140 if (msgLvl(MSG::VERBOSE)) {
141 msg(MSG::VERBOSE) << " iHit=" << n_hit << " id="
142 << m_tileID->to_string(id, -1) << " ener=";
143
144 for (int i = 0; i < size; ++i)
145 msg(MSG::VERBOSE) << cinp->energy(i) << " ";
146
147 msg(MSG::VERBOSE) << "time=";
148 for (int i = 0; i < size; ++i)
149 msg(MSG::VERBOSE) << cinp->time() << " ";
150
151 msg(MSG::VERBOSE) << endmsg;
152 }
153
154 ++n_hit;
155 if (m_nchan >= m_maxLength) {
156 ATH_MSG_DEBUG( "Number of hits exceeds maximum (" << m_maxLength.value()
157 << "), ignore all the rest" );
158 break;
159 }
160 }
161
162 // step3: commit ntuple
163 if ( m_commitNtuple ) {
164 ATH_MSG_DEBUG( "Committing Ntuple" );
165 CHECK( ntupleSvc()->writeRecord(m_ntuplePtr) );
166 }
167
168 // Execution completed.
169 ATH_MSG_DEBUG( "execute() completed successfully" );
170 return StatusCode::SUCCESS;
171}
172
173//****************************************************************************
174//* Finalize
175//****************************************************************************
176
178{
179 ATH_MSG_INFO( "finalize() completed successfully" );
180 return StatusCode::SUCCESS;
181}
182
#define endmsg
#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.
SelectAllObjectMT< DCC, OBJECT > SelectAllObject
INTupleSvc * ntupleSvc()
size_t size() const
Number of registered mappings.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
ServiceHandle< StoreGateSvc > & evtStore()
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
const_iterator end()
const_iterator begin()
Gaudi::Property< std::string > m_hitContainer
Gaudi::Property< int > m_maxLength
NTuple::Array< int > m_detector
NTuple::Array< float > m_energy
NTuple::Array< int > m_sample
NTuple::Item< double > m_tolE
NTuple::Array< int > m_side
Gaudi::Property< std::string > m_ntupleLoc
NTuple::Array< int > m_eta
Gaudi::Property< std::string > m_ntupleID
virtual ~TileHitToNtuple()
StatusCode finalize()
TileHitToNtuple(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< bool > m_commitNtuple
StatusCode execute(const EventContext &ctx)
Execute method.
const TileID * m_tileID
NTuple::Array< int > m_phi
StatusCode initialize()
NTuple::Tuple * m_ntuplePtr
NTuple::Array< float > m_time
NTuple::Array< int > m_pmt
NTuple::Item< int > m_nchan
float time(int ind=0) const
Return time of ind-th sub-hit.
float energy(int ind=0) const
Return energy of ind-th sub-hit.
Identifier identify(void) const
Return logical ID of the pmt.
int size(void) const
Return length of energy/time vectors.