ATLAS Offline Software
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
29 #include "CaloIdentifier/TileID.h"
32 
33 //TileCalo include
34 #include "TileEvent/TileCell.h"
37 
38 const int max_chan=5216;
39 
40 // Constructor & deconstructor
41 TileCellToNtuple::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 
58 {
59 }
60 
61 // Alg standard interface function
63 {
64  ATH_MSG_INFO( "Initialization started" );
65 
66  // retrieve TileID helper from det store
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
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();
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());
164  m_side[m_nchan]=m_tileID->side(id);
166  m_eta[m_nchan]=m_tileID->tower(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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileCellToNtuple::finalize
StatusCode finalize()
Definition: TileCellToNtuple.cxx:183
max_chan
const int max_chan
Definition: TileCellToNtuple.cxx:38
TileCell
Definition: TileCell.h:57
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TileCellToNtuple::m_module
NTuple::Array< int > m_module
Definition: TileCellToNtuple.h:72
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TileCellToNtuple::initialize
StatusCode initialize()
Definition: TileCellToNtuple.cxx:62
Tile_Base_ID::side
int side(const Identifier &id) const
Definition: Tile_Base_ID.cxx:153
TileCellToNtuple::m_cellContainer
std::string m_cellContainer
Definition: TileCellToNtuple.h:74
skel.it
it
Definition: skel.GENtoEVGEN.py:423
TileCellToNtuple::m_phi
NTuple::Array< int > m_phi
Definition: TileCellToNtuple.h:68
Tile_Base_ID::sample
int sample(const Identifier &id) const
Definition: Tile_Base_ID.cxx:171
CaloCellContainer::beginConstCalo
CaloCellContainer::const_iterator beginConstCalo(CaloCell_ID::SUBCALO caloNum) const
get const iterators on cell of just one calo
Definition: CaloCellContainer.cxx:119
TileCellToNtuple::TileCellToNtuple
TileCellToNtuple(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TileCellToNtuple.cxx:41
TileCellToNtuple::m_energy
NTuple::Array< float > m_energy
Definition: TileCellToNtuple.h:59
TileCellToNtuple::m_channel
NTuple::Array< int > m_channel
Definition: TileCellToNtuple.h:71
Tile_Base_ID::tower
int tower(const Identifier &id) const
Definition: Tile_Base_ID.cxx:165
TileTBID::type
int type(const Identifier &id) const
extract type field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:146
TileCellToNtuple::m_type
NTuple::Array< int > m_type
Definition: TileCellToNtuple.h:70
TileCellToNtuple::m_nchan
NTuple::Item< int > m_nchan
Definition: TileCellToNtuple.h:56
TileTBID::module
int module(const Identifier &id) const
extract module field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:150
TileID.h
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
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
Tile_Base_ID::module
int module(const Identifier &id) const
Definition: Tile_Base_ID.cxx:159
TileCellToNtuple::m_quality
NTuple::Array< float > m_quality
Definition: TileCellToNtuple.h:62
TileCellToNtuple::m_detector
NTuple::Array< int > m_detector
Definition: TileCellToNtuple.h:64
TileCellToNtuple::m_tileTBID
const TileTBID * m_tileTBID
Definition: TileCellToNtuple.h:77
TileCellToNtuple.h
TileCellToNtuple::m_sample
NTuple::Array< int > m_sample
Definition: TileCellToNtuple.h:66
TileCellToNtuple::m_tileID
const TileID * m_tileID
Definition: TileCellToNtuple.h:76
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
TileCellToNtuple::m_scinCells
bool m_scinCells
Definition: TileCellToNtuple.h:54
TileCell.h
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
CaloCell_Base_ID::TILE
@ TILE
Definition: CaloCell_Base_ID.h:46
TileCellToNtuple::m_time
NTuple::Array< float > m_time
Definition: TileCellToNtuple.h:61
TileCellToNtuple::m_ntupleLoc
std::string m_ntupleLoc
Definition: TileCellToNtuple.h:53
TileCellToNtuple::m_ntuplePtr
NTuple::Tuple * m_ntuplePtr
Definition: TileCellToNtuple.h:51
TileCellToNtuple::m_side
NTuple::Array< int > m_side
Definition: TileCellToNtuple.h:65
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
TileCellToNtuple::execute
StatusCode execute()
Definition: TileCellToNtuple.cxx:111
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TileCellToNtuple::m_ntupleID
std::string m_ntupleID
Definition: TileCellToNtuple.h:52
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
TileCellToNtuple::~TileCellToNtuple
virtual ~TileCellToNtuple()
Definition: TileCellToNtuple.cxx:57
TileCellToNtuple::m_eta
NTuple::Array< int > m_eta
Definition: TileCellToNtuple.h:67
CaloCellContainer::endConstCalo
CaloCellContainer::const_iterator endConstCalo(CaloCell_ID::SUBCALO caloNum) const
Definition: CaloCellContainer.cxx:133
TileCellToNtuple::m_enediff
NTuple::Array< float > m_enediff
Definition: TileCellToNtuple.h:60
SelectAllObject.h
Tile_Base_ID::section
int section(const Identifier &id) const
Definition: Tile_Base_ID.cxx:147
Tile_Base_ID::cell_id
Identifier cell_id(const Identifier &any_id) const
Definition: Tile_Base_ID.cxx:581
TileCellToNtuple::m_tolE
NTuple::Item< double > m_tolE
Definition: TileCellToNtuple.h:57
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
TileContainer
Definition: TileContainer.h:38
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
TileCellContainer.h