ATLAS Offline Software
TileTBHitToNtuple.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 : TileTBHitToNtuple.cxx
7 // Author : Anna
8 // Created : June, 2004
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 
29 //TileCalo include
34 
35 const int max_chan=99999;
36 
37 // Constructor & deconstructor
38 TileTBHitToNtuple::TileTBHitToNtuple(const std::string& name, ISvcLocator* pSvcLocator)
39  : AthAlgorithm(name, pSvcLocator)
40  , m_ntuplePtr(0)
41  , m_ntupleID("h31")
42  , m_ntupleLoc("/FILE1/TileRec")
43  , m_hitContainer("TileTBHits") //name of hit vector for ancillary detectors
44  , m_tileTBID(0)
45 {
46  declareProperty("TileHitContainer", m_hitContainer);
47  declareProperty("NTupleLoc", m_ntupleLoc);
48  declareProperty("NTupleID", m_ntupleID);
49 }
50 
52 {
53 }
54 
55 // Alg standard interface function
57 {
58 
59  ATH_MSG_INFO( "Initialization started" );
60 
61  // retrieve TileTBID helper from det store
62 
64 
65  m_ntupleLoc="/NTUPLES" + m_ntupleLoc;
66 
67  SmartDataPtr<NTuple::Directory> DirPtr(ntupleSvc(), m_ntupleLoc);
68  if (!DirPtr) DirPtr = ntupleSvc()->createDirectory(m_ntupleLoc);
69  if(!DirPtr) {
70  ATH_MSG_ERROR( "Invalid Ntuple Directory: " );
71  return StatusCode::FAILURE;
72  }
73  m_ntuplePtr=ntupleSvc()->book(DirPtr.ptr(), m_ntupleID,
74  CLID_ColumnWiseTuple, "TileTBHit-Ntuple");
75  if(!m_ntuplePtr) {
76 
77  std::string ntupleCompleteID=m_ntupleLoc+"/"+m_ntupleID;
78 
79  NTuplePtr nt(ntupleSvc(),ntupleCompleteID);
80  if (!nt) {
81  ATH_MSG_ERROR( "Failed to book or to retrieve ntuple "
82  << ntupleCompleteID );
83  return StatusCode::FAILURE;
84  } else {
85  ATH_MSG_INFO( "Reaccessing ntuple " << ntupleCompleteID );
86  m_ntuplePtr = nt;
87  }
88  }
89 
90  CHECK( m_ntuplePtr->addItem("TileTBHit/nchan",m_nchan,0,max_chan) );
91  CHECK( m_ntuplePtr->addItem("TileTBHit/energy",m_nchan,m_energy) );
92  CHECK( m_ntuplePtr->addItem("TileTBHit/time",m_nchan,m_time) );
93  CHECK( m_ntuplePtr->addItem("TileTBHit/type",m_nchan,m_type,-1,6) );
94  CHECK( m_ntuplePtr->addItem("TileTBHit/module", m_nchan, m_module,0,7) );
95  CHECK( m_ntuplePtr->addItem("TileTBHit/channel",m_nchan,m_channel,0,15) );
96  CHECK( m_ntuplePtr->addItem("TileTBHit/totalE",m_tolE) );
97 
98  ATH_MSG_INFO( "Initialization completed" );
99  return StatusCode::SUCCESS;
100 }
101 
103 {
104 
105  // step1: read Hit for ancillary
106  const TileHitVector* HitCnt = nullptr;
107  CHECK( evtStore()->retrieve(HitCnt, m_hitContainer) );
108 
109  m_nchan=0;
110  m_tolE=0.0;
111  for (const TileHit& cinp : *HitCnt) {
112  m_tolE+=cinp.energy();
113  m_energy[m_nchan]=cinp.energy();
114  m_time[m_nchan]=cinp.time();
115 
116  Identifier id=cinp.identify();
120 
121  m_nchan++;
122 
123  if (m_nchan >= max_chan) break;
124  }
125 
126  // step3: commit ntuple
127  CHECK( ntupleSvc()->writeRecord(m_ntuplePtr) );
128 
129  // Execution completed.
130  ATH_MSG_DEBUG( "execute() completed successfully" );
131  return StatusCode::SUCCESS;
132 }
133 
135 {
136  ATH_MSG_INFO( "finalize() successfully" );
137  return StatusCode::SUCCESS;
138 }
139 
TileTBHitToNtuple::m_energy
NTuple::Array< float > m_energy
Definition: TileTBHitToNtuple.h:57
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileTBHitToNtuple::m_ntuplePtr
NTuple::Tuple * m_ntuplePtr
Definition: TileTBHitToNtuple.h:50
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
AtlasHitsVector
Definition: AtlasHitsVector.h:33
TileTBHitToNtuple::m_ntupleID
std::string m_ntupleID
Definition: TileTBHitToNtuple.h:51
TileTBHitToNtuple::finalize
StatusCode finalize()
Definition: TileTBHitToNtuple.cxx:134
TileTBHitToNtuple::m_type
NTuple::Array< int > m_type
Definition: TileTBHitToNtuple.h:60
TileTBID::type
int type(const Identifier &id) const
extract type field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:146
TileTBHitToNtuple::m_time
NTuple::Array< float > m_time
Definition: TileTBHitToNtuple.h:58
TileTBHitToNtuple::initialize
StatusCode initialize()
Definition: TileTBHitToNtuple.cxx:56
TileTBID::module
int module(const Identifier &id) const
extract module field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:150
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
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
TileTBHitToNtuple::m_hitContainer
std::string m_hitContainer
Definition: TileTBHitToNtuple.h:64
TileTBHitToNtuple::m_nchan
NTuple::Item< int > m_nchan
Definition: TileTBHitToNtuple.h:54
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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
TileTBHitToNtuple::execute
StatusCode execute()
Definition: TileTBHitToNtuple.cxx:102
TileTBHitToNtuple::~TileTBHitToNtuple
virtual ~TileTBHitToNtuple()
Definition: TileTBHitToNtuple.cxx:51
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
TileTBHitToNtuple::m_channel
NTuple::Array< int > m_channel
Definition: TileTBHitToNtuple.h:61
TileTBHitToNtuple.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
TileTBHitToNtuple::m_ntupleLoc
std::string m_ntupleLoc
Definition: TileTBHitToNtuple.h:52
TileHitVector.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TileTBHitToNtuple::m_tileTBID
const TileTBID * m_tileTBID
Definition: TileTBHitToNtuple.h:66
TileHit
Definition: TileSimEvent/TileSimEvent/TileHit.h:30
TileTBHitToNtuple::m_tolE
NTuple::Item< double > m_tolE
Definition: TileTBHitToNtuple.h:55
TileHitContainer.h
TileTBHitToNtuple::m_module
NTuple::Array< int > m_module
Definition: TileTBHitToNtuple.h:62
SelectAllObject.h
beamspotnt.nt
def nt
Definition: bin/beamspotnt.py:1063
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
TileTBHitToNtuple::TileTBHitToNtuple
TileTBHitToNtuple(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TileTBHitToNtuple.cxx:38
max_chan
const int max_chan
Definition: TileTBHitToNtuple.cxx:35