ATLAS Offline Software
TileDigitsToNtuple.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 : TileDigitsToNtuple.cxx
7 // Author :
8 // Created :
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"
31 
32 //TileCalo include
37 
38 
39 TileDigitsToNtuple::TileDigitsToNtuple(const std::string& name, ISvcLocator* pSvcLocator)
40  : AthAlgorithm(name, pSvcLocator)
41  , m_tileID(0)
42  , m_tileHWID(0)
43  , m_tileTBID(0)
44  , m_ntuplePtr(0)
45  , m_nSamples(7)
46 {
47  declareProperty("TileDigitsContainer", m_digitsContainer = "TileDigitsFlt");
48  declareProperty("NTupleLoc", m_ntupleLoc = "/TILE/TileRec");
49  declareProperty("NTupleID", m_ntupleID = "h40");
50  declareProperty("CommitNtuple", m_commitNtuple = true);
51  declareProperty("TileInfoName", m_infoName = "TileInfo");
52  declareProperty("SaveMaxChannels", m_saveMaxChannels = 12288);
53  declareProperty("SaveAll", m_saveAll = true);
54  declareProperty("SaveE4prAndMBTS", m_saveE4prAndMBTS = true);
55 }
56 
58 {
59 }
60 
61 //****************************************************************************
62 //* Initialization
63 //****************************************************************************
64 
66 
67  ATH_MSG_INFO( "Initialization started" );
68 
69  // retrieve TileID helper from det store
73 
74  const TileInfo* tileInfo = nullptr;
75  CHECK( detStore()->retrieve(tileInfo, m_infoName) );
76  m_nSamples = tileInfo->NdigitSamples(); // number of time slices for each chan
77 
78  m_ntupleLoc = "/NTUPLES" + m_ntupleLoc;
79  std::string ntupleCompleteID = m_ntupleLoc + "/" + m_ntupleID;
80  NTuplePtr nt(ntupleSvc(), ntupleCompleteID);
81 
82  if ( nt ) { // Check if already booked
83  m_ntuplePtr = nt;
84  ATH_MSG_INFO( "Reaccessing ntuple " << ntupleCompleteID );
85  } else {
86  m_ntuplePtr = ntupleSvc()->book(ntupleCompleteID, CLID_ColumnWiseTuple, "TileDigits-Ntuple");
87  if (m_ntuplePtr) {
88 
89  CHECK( m_ntuplePtr->addItem("TileDigits/n_channels", m_nChannel, 0, m_saveMaxChannels) );
90 
91  CHECK( m_ntuplePtr->addItem("TileDigits/ros", m_nChannel, m_ros, 0, 4) );
92  CHECK( m_ntuplePtr->addItem("TileDigits/drawer", m_nChannel, m_drawer, 0, 63) );
93  CHECK( m_ntuplePtr->addItem("TileDigits/channel", m_nChannel, m_channel, 0, 47) );
94  CHECK( m_ntuplePtr->addItem("TileDigits/gain", m_nChannel, m_gain, 0, 1) );
95 
96  CHECK( m_ntuplePtr->addItem("TileDigits/side", m_nChannel, m_side, -1, 1) );
97  CHECK( m_ntuplePtr->addItem("TileDigits/section", m_nChannel, m_section, 0, 15) );
98  CHECK( m_ntuplePtr->addItem("TileDigits/phi", m_nChannel, m_phi, 0, 63) );
99  CHECK( m_ntuplePtr->addItem("TileDigits/eta", m_nChannel, m_eta, 0, 15) );
100 
101  CHECK( m_ntuplePtr->addItem("TileDigits/samples", m_nChannel, m_samples, m_nSamples) );
102 
103  if (!m_saveAll && !m_saveE4prAndMBTS) {
104  CHECK( m_ntuplePtr->addItem("TileDigits/sample", m_nChannel, m_sample, 0, 15) );
105  CHECK( m_ntuplePtr->addItem("TileDigits/pmt", m_nChannel, m_pmt, 0, 1) );
106  CHECK( m_ntuplePtr->addItem("TileDigits/adc", m_nChannel, m_adc, 0, 1) );
107  }
108 
109  } else {
110  ATH_MSG_ERROR( "Failed to book or to retrieve ntuple " << ntupleCompleteID );
111  return StatusCode::FAILURE;
112  }
113  ATH_MSG_INFO( "Finished booking ntuple " << ntupleCompleteID );
114  }
115 
116  ATH_MSG_INFO( "Initialization completed" );
117  return StatusCode::SUCCESS;
118 }
119 
120 //****************************************************************************
121 //* Execution
122 //****************************************************************************
123 
125 
126  // step1: read TileDigitss from TDS
127  const TileDigitsContainer* digitsContainer = nullptr;
128  CHECK( evtStore()->retrieve(digitsContainer, m_digitsContainer) );
129 
130  m_nChannel = 0;
131 
132  SelectAllObject<TileDigitsContainer> allTileDigits(digitsContainer);
133 
134  for (const TileDigits* tile_digits : allTileDigits) {
135 
136  HWIdentifier adc_hwid = tile_digits->adc_HWID();
137  Identifier adc_id = tile_digits->adc_ID();
138 
139  std::vector<float> samples = tile_digits->samples();
140  int n_samples = samples.size();
141 
142  if (m_saveAll) {
143  m_ros[m_nChannel] = m_tileHWID->ros(adc_hwid);
144  m_drawer[m_nChannel] = m_tileHWID->drawer(adc_hwid);
145  m_channel[m_nChannel] = m_tileHWID->channel(adc_hwid);
146  m_gain[m_nChannel] = m_tileHWID->adc(adc_hwid);
147 
148  if (m_tileTBID->is_tiletb(adc_id)) {
150  m_side[m_nChannel] = m_tileTBID->side(adc_id);
151  m_phi[m_nChannel] = m_tileTBID->phi(adc_id);
152  m_eta[m_nChannel] = m_tileTBID->eta(adc_id);
153  } else {
154  m_section[m_nChannel] = m_tileID->section(adc_id);
155  m_side[m_nChannel] = m_tileID->side(adc_id);
156  m_phi[m_nChannel] = m_tileID->module(adc_id);
157  m_eta[m_nChannel] = m_tileID->tower(adc_id);
158  }
159 
160  for (int i = 0; i < n_samples && i < m_nSamples; ++i) m_samples[m_nChannel][i] = samples[i];
161 
162  ++m_nChannel;
163 
164  } else if (m_saveE4prAndMBTS) {
165  if (m_tileTBID->is_tiletb(adc_id)) {
166  m_ros[m_nChannel] = m_tileHWID->ros(adc_hwid);
167  m_drawer[m_nChannel] = m_tileHWID->drawer(adc_hwid);
168  m_channel[m_nChannel] = m_tileHWID->channel(adc_hwid);
169  m_gain[m_nChannel] = m_tileHWID->adc(adc_hwid);
170 
172  m_side[m_nChannel] = m_tileTBID->side(adc_id);
173  m_phi[m_nChannel] = m_tileTBID->phi(adc_id);
174  m_eta[m_nChannel] = m_tileTBID->eta(adc_id);
175 
176  for (int i = 0; i < n_samples && i < m_nSamples; ++i) m_samples[m_nChannel][i] = samples[i];
177 
178  ++m_nChannel;
179  }
180  } else {
181  if (!m_tileTBID->is_tiletb(adc_id)) {
182  m_ros[m_nChannel] = m_tileHWID->ros(adc_hwid);
183  m_drawer[m_nChannel] = m_tileHWID->drawer(adc_hwid);
184  m_channel[m_nChannel] = m_tileHWID->channel(adc_hwid);
185  m_gain[m_nChannel] = m_tileHWID->adc(adc_hwid);
186 
187  m_section[m_nChannel] = m_tileID->section(adc_id);
188  m_side[m_nChannel] = m_tileID->side(adc_id);
189  m_phi[m_nChannel] = m_tileID->module(adc_id);
190  m_eta[m_nChannel] = m_tileID->tower(adc_id);
191 
192  m_sample[m_nChannel] = m_tileID->sample(adc_id);
193  m_pmt[m_nChannel] = m_tileID->pmt(adc_id);
194  m_adc[m_nChannel] = m_tileID->adc(adc_id);
195 
196  for (int i = 0; i < n_samples && i < m_nSamples; ++i) m_samples[m_nChannel][i] = samples[i];
197 
198  ++m_nChannel;
199  }
200  }
201 
202  if (m_nChannel >= m_saveMaxChannels) {
203  ATH_MSG_DEBUG( "Number of channels exceeds maximum (" << m_saveMaxChannels << "), ignore all the rest" );
204  break;
205  }
206  }
207 
208 
209  if ( m_commitNtuple ) {
210  ATH_MSG_DEBUG( "Committing Ntuple" );
211  CHECK( ntupleSvc()->writeRecord(m_ntuplePtr) );
212  }
213 
214  // Execution completed.
215  ATH_MSG_DEBUG( "execute() completed successfully" );
216  return StatusCode::SUCCESS;
217 }
218 
219 //****************************************************************************
220 //* Finalize
221 //****************************************************************************
222 
224  ATH_MSG_INFO( "finalize() completed successfully" );
225  return StatusCode::SUCCESS;
226 }
227 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileDigitsToNtuple::m_tileID
const TileID * m_tileID
Definition: TileDigitsToNtuple.h:53
TileDigitsToNtuple::m_side
NTuple::Array< short > m_side
Definition: TileDigitsToNtuple.h:71
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
TileInfo::NdigitSamples
int NdigitSamples() const
Returns the number of sammples (digits) per event.
Definition: TileInfo.h:75
TileDigitsToNtuple::m_phi
NTuple::Array< short > m_phi
Definition: TileDigitsToNtuple.h:72
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Tile_Base_ID::pmt
int pmt(const Identifier &id) const
Definition: Tile_Base_ID.cxx:180
TileDigitsToNtuple::m_tileTBID
const TileTBID * m_tileTBID
Definition: TileDigitsToNtuple.h:55
TileDigitsToNtuple::m_ros
NTuple::Array< short > m_ros
Definition: TileDigitsToNtuple.h:65
TileDigitsToNtuple::m_infoName
std::string m_infoName
Definition: TileDigitsToNtuple.h:81
Tile_Base_ID::side
int side(const Identifier &id) const
Definition: Tile_Base_ID.cxx:153
Tile_Base_ID::sample
int sample(const Identifier &id) const
Definition: Tile_Base_ID.cxx:171
TileInfo.h
TileDigitsToNtuple::m_ntuplePtr
NTuple::Tuple * m_ntuplePtr
Definition: TileDigitsToNtuple.h:57
Tile_Base_ID::tower
int tower(const Identifier &id) const
Definition: Tile_Base_ID.cxx:165
TileDigitsToNtuple.h
TileInfo
Definition: TileInfo.h:49
TileDigitsToNtuple::m_saveMaxChannels
int m_saveMaxChannels
Definition: TileDigitsToNtuple.h:82
TileDigitsContainer
Definition: TileDigitsContainer.h:13
TileDigitsToNtuple::m_drawer
NTuple::Array< short > m_drawer
Definition: TileDigitsToNtuple.h:66
HWIdentifier
Definition: HWIdentifier.h:13
TileHWID::channel
int channel(const HWIdentifier &id) const
extract channel field from HW identifier
Definition: TileHWID.h:189
TileID.h
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
TileDigitsToNtuple::m_saveE4prAndMBTS
bool m_saveE4prAndMBTS
Definition: TileDigitsToNtuple.h:85
TileDigitsToNtuple::TileDigitsToNtuple
TileDigitsToNtuple(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TileDigitsToNtuple.cxx:39
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
TileTBID.h
Tile_Base_ID::adc
int adc(const Identifier &id) const
Definition: Tile_Base_ID.cxx:186
SelectAllObjectMT
Definition: SelectAllObjectMT.h:11
TileHWID.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TileDigitsToNtuple::m_saveAll
bool m_saveAll
Definition: TileDigitsToNtuple.h:84
Tile_Base_ID::module
int module(const Identifier &id) const
Definition: Tile_Base_ID.cxx:159
lumiFormat.i
int i
Definition: lumiFormat.py:85
TileDigitsContainer.h
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
TileTBID::section
int section(const Identifier &id) const
extract section field from TileTB identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:142
TileDigitsToNtuple::m_nChannel
NTuple::Item< short > m_nChannel
Definition: TileDigitsToNtuple.h:63
TileDigitsToNtuple::execute
StatusCode execute()
Definition: TileDigitsToNtuple.cxx:124
TileDigitsToNtuple::m_tileHWID
const TileHWID * m_tileHWID
Definition: TileDigitsToNtuple.h:54
TileDigitsToNtuple::m_commitNtuple
bool m_commitNtuple
Definition: TileDigitsToNtuple.h:60
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
TileDigitsToNtuple::finalize
StatusCode finalize()
Definition: TileDigitsToNtuple.cxx:223
TileDigitsToNtuple::m_nSamples
int m_nSamples
Definition: TileDigitsToNtuple.h:83
AthAlgorithm
Definition: AthAlgorithm.h:47
TileDigitsToNtuple::m_pmt
NTuple::Array< short > m_pmt
Definition: TileDigitsToNtuple.h:75
TileDigitsToNtuple::m_ntupleLoc
std::string m_ntupleLoc
Definition: TileDigitsToNtuple.h:59
TileDigitsToNtuple::initialize
StatusCode initialize()
Definition: TileDigitsToNtuple.cxx:65
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TileDigits
Definition: TileDigits.h:30
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TileDigitsToNtuple::~TileDigitsToNtuple
virtual ~TileDigitsToNtuple()
Definition: TileDigitsToNtuple.cxx:57
TileDigitsToNtuple::m_eta
NTuple::Array< short > m_eta
Definition: TileDigitsToNtuple.h:73
TileDigitsToNtuple::m_digitsContainer
std::string m_digitsContainer
Definition: TileDigitsToNtuple.h:80
TileHWID::drawer
int drawer(const HWIdentifier &id) const
extract drawer field from HW identifier
Definition: TileHWID.h:171
TileDigitsToNtuple::m_samples
NTuple::Matrix< short > m_samples
Definition: TileDigitsToNtuple.h:78
TileDigitsToNtuple::m_adc
NTuple::Array< short > m_adc
Definition: TileDigitsToNtuple.h:76
TileTBID::phi
int phi(const Identifier &id) const
extract phi field from MBTS identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:165
TileDigitsToNtuple::m_ntupleID
std::string m_ntupleID
Definition: TileDigitsToNtuple.h:58
TileDigitsToNtuple::m_channel
NTuple::Array< short > m_channel
Definition: TileDigitsToNtuple.h:67
TileDigitsToNtuple::m_sample
NTuple::Array< short > m_sample
Definition: TileDigitsToNtuple.h:74
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
TileTBID::eta
int eta(const Identifier &id) const
extract eta field from MBTS identifier
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:169
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
TileDigitsToNtuple::m_section
NTuple::Array< short > m_section
Definition: TileDigitsToNtuple.h:70
TileDigitsToNtuple::m_gain
NTuple::Array< short > m_gain
Definition: TileDigitsToNtuple.h:68
TileTBID::side
int side(const Identifier &id) const
define synonyms for minimum bias scintillators
Definition: Calorimeter/CaloIdentifier/CaloIdentifier/TileTBID.h:161
Identifier
Definition: IdentifierFieldParser.cxx:14