ATLAS Offline Software
TileTTL1ToNtuple.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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 
35 TileTTL1ToNtuple::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 
54 {
55 }
56 
57 //****************************************************************************
58 //* Initialization
59 //****************************************************************************
60 
62 {
63 
64  ATH_MSG_INFO( "Initialization started" );
65 
66  // retrieve TileID helper from det store
67 
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;
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)) {
137  } else {
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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
TileTBID::is_tiletb
bool is_tiletb(const Identifier &id) const
Test ID if it is TileTBID.
Definition: TileTBID.cxx:87
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TileTTL1::TTL1_ID
const Identifier & TTL1_ID() const
Definition: TileTTL1.cxx:66
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TileTTL1::fsamples
const std::vector< float > & fsamples() const
Definition: TileTTL1.cxx:77
TileTTL1ToNtuple::~TileTTL1ToNtuple
virtual ~TileTTL1ToNtuple()
Definition: TileTTL1ToNtuple.cxx:53
TileTTL1ToNtuple::m_eta
NTuple::Array< int > m_eta
Definition: TileTTL1ToNtuple.h:61
TileTTL1ToNtuple::m_nSamples
int m_nSamples
Definition: TileTTL1ToNtuple.h:56
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TileTTL1
Definition: TileTTL1.h:26
AthCommonMsg< Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
TileTTL1ToNtuple::m_tileTBID
const TileTBID * m_tileTBID
Definition: TileTTL1ToNtuple.h:69
TileTBID::type
int type(const Identifier &id) const
extract type field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:146
TileTTL1ToNtuple::m_samples
NTuple::Matrix< float > m_samples
Definition: TileTTL1ToNtuple.h:64
TileTBID::module
int module(const Identifier &id) const
extract module field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:150
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
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
CaloLVL1_ID::phi
int phi(const Identifier id) const
return phi according to :
Definition: CaloLVL1_ID.h:659
TileTTL1ToNtuple::m_ntupleLoc
std::string m_ntupleLoc
Definition: TileTTL1ToNtuple.h:53
TileTTL1ToNtuple::initialize
StatusCode initialize()
Definition: TileTTL1ToNtuple.cxx:61
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TileTBID.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TileTTL1ToNtuple::m_ntupleID
std::string m_ntupleID
Definition: TileTTL1ToNtuple.h:52
lumiFormat.i
int i
Definition: lumiFormat.py:85
TileTTL1ToNtuple::m_ttl1Container
std::string m_ttl1Container
Definition: TileTTL1ToNtuple.h:66
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
TileTTL1ToNtuple::TileTTL1ToNtuple
TileTTL1ToNtuple(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TileTTL1ToNtuple.cxx:35
TileTTL1ToNtuple::m_phi
NTuple::Array< int > m_phi
Definition: TileTTL1ToNtuple.h:62
TileTTL1ToNtuple::m_nchan
NTuple::Item< int > m_nchan
Definition: TileTTL1ToNtuple.h:58
TileTTL1ToNtuple::finalize
StatusCode finalize()
Definition: TileTTL1ToNtuple.cxx:176
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
TileTTL1Container.h
TileTBID::channel
int channel(const Identifier &id) const
extract channel field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:154
AthAlgorithm
Definition: AthAlgorithm.h:47
TileTTL1ToNtuple::m_commitNtuple
bool m_commitNtuple
Definition: TileTTL1ToNtuple.h:54
TileTTL1ToNtuple::m_maxLength
int m_maxLength
Definition: TileTTL1ToNtuple.h:55
TileTTL1ToNtuple::m_TT_ID
const CaloLVL1_ID * m_TT_ID
Definition: TileTTL1ToNtuple.h:68
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
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
CaloLVL1_ID::pos_neg_z
int pos_neg_z(const Identifier id) const
return pos_neg_z according to :
Definition: CaloLVL1_ID.h:635
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
CaloLVL1_ID.h
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
TileTTL1ToNtuple::m_ntuplePtr
NTuple::Tuple * m_ntuplePtr
Definition: TileTTL1ToNtuple.h:51
beamspotnt.nt
def nt
Definition: bin/beamspotnt.py:1063
TileTTL1ToNtuple.h
TileTTL1ToNtuple::execute
StatusCode execute()
Definition: TileTTL1ToNtuple.cxx:110
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
TileContainer
Definition: TileContainer.h:38
TileTTL1ToNtuple::m_side
NTuple::Array< int > m_side
Definition: TileTTL1ToNtuple.h:60
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Identifier
Definition: IdentifierFieldParser.cxx:14