ATLAS Offline Software
TileRawChannelToNtuple.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 : TileRawChannelToNtuple.cxx
7 // Author : Zhifang
8 // Created : Nov, 2002
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"
30 
31 //TileCalo include
35 
36 const int max_chan=12288;
37 
38 // Constructor & deconstructor
39 TileRawChannelToNtuple::TileRawChannelToNtuple(const std::string& name, ISvcLocator* pSvcLocator)
40  : AthAlgorithm(name, pSvcLocator)
41  , m_ntuplePtr(0)
42  , m_ntupleID("h70")
43  , m_ntupleLoc("/FILE1/TileRec")
44  , m_rawChannelContainer("TileRawChannelCnt")
45  , m_tileID(0)
46  , m_tileHWID(0)
47 {
48  declareProperty("TileRawChannelContainer", m_rawChannelContainer);
49  declareProperty("NTupleLoc", m_ntupleLoc);
50  declareProperty("NTupleID", m_ntupleID);
51 }
52 
54 {
55 }
56 
57 // Alg standard interface function
59 {
60 
61  ATH_MSG_INFO( "Initialization started" );
62 
63  // retrieve TileID helper from det store
64 
67 
68  m_ntupleLoc="/NTUPLES" + m_ntupleLoc;
69 
70  SmartDataPtr<NTuple::Directory> DirPtr(ntupleSvc(), m_ntupleLoc);
71  if(!DirPtr) DirPtr = ntupleSvc()->createDirectory(m_ntupleLoc);
72  if(!DirPtr) {
73  ATH_MSG_ERROR( "Invalid Ntuple Directory: " );
74  return StatusCode::FAILURE;
75  }
76  m_ntuplePtr=ntupleSvc()->book(DirPtr.ptr(), m_ntupleID,
77  CLID_ColumnWiseTuple, "TileRC-Ntuple");
78  if(!m_ntuplePtr) {
79 
80  std::string ntupleCompleteID=m_ntupleLoc+"/"+m_ntupleID;
81 
82  NTuplePtr nt(ntupleSvc(),ntupleCompleteID);
83  if (!nt) {
84  ATH_MSG_ERROR( "Failed to book or to retrieve ntuple "
85  << ntupleCompleteID );
86  return StatusCode::FAILURE;
87  } else {
88  ATH_MSG_INFO( "Reaccessing ntuple " << ntupleCompleteID );
89  m_ntuplePtr = nt;
90  }
91  }
92 
93  CHECK( m_ntuplePtr->addItem("TileRC/nchan",m_nchan,0,max_chan) );
94  CHECK( m_ntuplePtr->addItem("TileRC/totalE",m_tolE) );
95 
96  CHECK( m_ntuplePtr->addItem("TileRC/energy",m_nchan,m_energy) );
97  CHECK( m_ntuplePtr->addItem("TileRC/time",m_nchan,m_time) );
98  CHECK( m_ntuplePtr->addItem("TileRC/quality",m_nchan,m_quality) );
99 
100  CHECK( m_ntuplePtr->addItem("TileRC/detector",m_nchan,m_detector,0,3) );
101  CHECK( m_ntuplePtr->addItem("TileRC/side",m_nchan,m_side,-1,1) );
102  CHECK( m_ntuplePtr->addItem("TileRC/sample",m_nchan,m_sample,-1,3) );
103  CHECK( m_ntuplePtr->addItem("TileRC/eta",m_nchan,m_eta,-1,15) );
104  CHECK( m_ntuplePtr->addItem("TileRC/phi",m_nchan,m_phi,0,63) );
105  CHECK( m_ntuplePtr->addItem("TileRC/pmt",m_nchan,m_pmt,-1,1) );
106  CHECK( m_ntuplePtr->addItem("TileRC/channel",m_nchan,m_channel,0,47) );
107  CHECK( m_ntuplePtr->addItem("TileRC/gain",m_nchan,m_gain,0,2) );
108 
109  ATH_MSG_INFO( "Initialization completed" );
110  return StatusCode::SUCCESS;
111 }
112 
114 {
115 
116  // step1: read RCs from TDS
117  const TileRawChannelContainer* RawChannelCnt;
118  CHECK( evtStore()->retrieve(RawChannelCnt, m_rawChannelContainer) );
119 
120  // step2: to fill items in ntuple
121  SelectAllObject<TileRawChannelContainer> selRCs(RawChannelCnt);
124  m_nchan=0;
125  m_tolE=0.0;
126  for(; it != end; ++it) {
127  m_tolE+=(*it)->amplitude();
128  m_energy[m_nchan]=(*it)->amplitude();
129  m_time[m_nchan]=(*it)->time();
130  m_quality[m_nchan]=(*it)->quality();
131 
132  HWIdentifier hwid=(*it)->adc_HWID();
133 
134  Identifier id=(*it)->adc_ID();
135  if (id.is_valid() ) {
136 
138  m_side[m_nchan]=m_tileID->side(id);
140  m_eta[m_nchan]=m_tileID->tower(id);
142  m_pmt[m_nchan]=m_tileID->pmt(id);
144  m_gain[m_nchan]=m_tileHWID->adc(hwid);
145 
146  } else {
147 
148  m_detector[m_nchan]=(m_tileHWID->ros(hwid)+1)/2;
149  m_side[m_nchan]=(m_tileHWID->ros(hwid)%2)*2-1;
150  m_sample[m_nchan]=-1;
151  m_eta[m_nchan]=-1;
152  m_phi[m_nchan]=m_tileHWID->drawer(hwid);
153  m_pmt[m_nchan]=-1;
155  m_gain[m_nchan]=m_tileHWID->adc(hwid);
156  }
157 
158  m_nchan++;
159 
160  if (m_nchan >= max_chan) break;
161  }
162 
163  // step3: commit ntuple
164  CHECK( ntupleSvc()->writeRecord(m_ntuplePtr) );
165 
166  // Execution completed.
167  ATH_MSG_DEBUG( "execute() completed successfully" );
168  return StatusCode::SUCCESS;
169 }
170 
172 {
173  ATH_MSG_INFO( "finalize() successfully" );
174  return StatusCode::SUCCESS;
175 }
176 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileRawChannelContainer
Definition: TileRawChannelContainer.h:13
TileRawChannelToNtuple::m_sample
NTuple::Array< int > m_sample
Definition: TileRawChannelToNtuple.h:64
TileRawChannelToNtuple::m_side
NTuple::Array< int > m_side
Definition: TileRawChannelToNtuple.h:63
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SelectAllObjectMT::end
const_iterator end()
Definition: SelectAllObjectMT.h:131
TileRawChannelToNtuple::m_ntuplePtr
NTuple::Tuple * m_ntuplePtr
Definition: TileRawChannelToNtuple.h:51
TileRawChannelToNtuple::execute
StatusCode execute()
Definition: TileRawChannelToNtuple.cxx:113
TileRawChannelToNtuple::m_ntupleID
std::string m_ntupleID
Definition: TileRawChannelToNtuple.h:52
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TileRawChannelToNtuple::initialize
StatusCode initialize()
Definition: TileRawChannelToNtuple.cxx:58
Tile_Base_ID::pmt
int pmt(const Identifier &id) const
Definition: Tile_Base_ID.cxx:180
Tile_Base_ID::side
int side(const Identifier &id) const
Definition: Tile_Base_ID.cxx:153
skel.it
it
Definition: skel.GENtoEVGEN.py:423
Tile_Base_ID::sample
int sample(const Identifier &id) const
Definition: Tile_Base_ID.cxx:171
TileRawChannelToNtuple.h
Tile_Base_ID::tower
int tower(const Identifier &id) const
Definition: Tile_Base_ID.cxx:165
TileRawChannelToNtuple::m_detector
NTuple::Array< int > m_detector
Definition: TileRawChannelToNtuple.h:62
HWIdentifier
Definition: HWIdentifier.h:13
TileHWID::channel
int channel(const HWIdentifier &id) const
extract channel field from HW identifier
Definition: TileHWID.h:189
TileRawChannelToNtuple::m_ntupleLoc
std::string m_ntupleLoc
Definition: TileRawChannelToNtuple.h:53
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
TileHWID::ros
int ros(const HWIdentifier &id) const
extract ros field from HW identifier
Definition: TileHWID.h:167
TileRawChannelContainer.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TileHWID::adc
int adc(const HWIdentifier &id) const
extract adc field from HW identifier
Definition: TileHWID.h:193
SelectAllObjectMT::begin
const_iterator begin()
Definition: SelectAllObjectMT.h:115
SelectAllObjectMT
Definition: SelectAllObjectMT.h:11
max_chan
const int max_chan
Definition: TileRawChannelToNtuple.cxx:36
TileHWID.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
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
TileRawChannelToNtuple::m_phi
NTuple::Array< int > m_phi
Definition: TileRawChannelToNtuple.h:66
TileRawChannelToNtuple::m_nchan
NTuple::Item< int > m_nchan
Definition: TileRawChannelToNtuple.h:55
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SelectAllObjectMT::const_iterator
Definition: SelectAllObjectMT.h:22
TileRawChannelToNtuple::finalize
StatusCode finalize()
Definition: TileRawChannelToNtuple.cxx:171
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TileRawChannelToNtuple::m_time
NTuple::Array< float > m_time
Definition: TileRawChannelToNtuple.h:59
TileRawChannelToNtuple::m_rawChannelContainer
std::string m_rawChannelContainer
Definition: TileRawChannelToNtuple.h:71
TileRawChannelToNtuple::m_tolE
NTuple::Item< double > m_tolE
Definition: TileRawChannelToNtuple.h:56
TileRawChannelToNtuple::TileRawChannelToNtuple
TileRawChannelToNtuple(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TileRawChannelToNtuple.cxx:39
TileRawChannelToNtuple::m_gain
NTuple::Array< int > m_gain
Definition: TileRawChannelToNtuple.h:69
TileRawChannelToNtuple::m_tileID
const TileID * m_tileID
Definition: TileRawChannelToNtuple.h:73
TileRawChannelToNtuple::m_quality
NTuple::Array< float > m_quality
Definition: TileRawChannelToNtuple.h:60
TileHWID::drawer
int drawer(const HWIdentifier &id) const
extract drawer field from HW identifier
Definition: TileHWID.h:171
TileRawChannelToNtuple::~TileRawChannelToNtuple
virtual ~TileRawChannelToNtuple()
Definition: TileRawChannelToNtuple.cxx:53
TileRawChannelToNtuple::m_energy
NTuple::Array< float > m_energy
Definition: TileRawChannelToNtuple.h:58
TileRawChannelToNtuple::m_eta
NTuple::Array< int > m_eta
Definition: TileRawChannelToNtuple.h:65
SelectAllObject.h
Tile_Base_ID::section
int section(const Identifier &id) const
Definition: Tile_Base_ID.cxx:147
beamspotnt.nt
def nt
Definition: bin/beamspotnt.py:1063
TileRawChannelToNtuple::m_pmt
NTuple::Array< int > m_pmt
Definition: TileRawChannelToNtuple.h:67
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
TileRawChannelToNtuple::m_tileHWID
const TileHWID * m_tileHWID
Definition: TileRawChannelToNtuple.h:74
TileRawChannelToNtuple::m_channel
NTuple::Array< int > m_channel
Definition: TileRawChannelToNtuple.h:68