ATLAS Offline Software
Loading...
Searching...
No Matches
CaloMBTSRetriever.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#include "CaloMBTSRetriever.h"
6
7#include "CLHEP/Units/SystemOfUnits.h"
8
10
11#include "CaloDetDescr/CaloDetDescrElement.h"
12#include "TileEvent/TileCell.h"
20
21namespace JiveXML {
22
29 CaloMBTSRetriever::CaloMBTSRetriever(const std::string& type,const std::string& name,const IInterface* parent):
30 AthAlgTool(type,name,parent),
31 m_tileTBID(nullptr)
32 {
33 //Only declare the interface
34 declareInterface<IDataRetriever>(this);
35
36 declareProperty("MBTSThreshold", m_mbtsThreshold = 0.05);
37 declareProperty("RetrieveMBTS" , m_mbts = true);
38 declareProperty("DoMBTSDigits", m_mbtsdigit=false);
39 declareProperty("DoMBTSCellDetails", m_mbtsCellDetails = false);
40
41 // TileDigitsContainer names: {"TileDigitsCnt","TileDigitsFlt"};
42 declareProperty("TileDigitsContainer" ,m_sgKeyTileDigits = "",
43 "Input collection to retrieve Tile digits, used when doTileDigit is True");
44
45 // TileRawChannelContainer names: {"TileRawChannelOpt2","TileRawChannelOpt","TileRawChannelFixed",
46 // "TileRawChannelFitCool","TileRawChannelFit",
47 // "TileRawChannelCnt","TileRawChannelFlt"};
48 declareProperty("TileRawChannelContainer" ,m_sgKeyTileRawChannel = "",
49 "Input collection to retrieve Tile raw channels, used when DoMBTSCellDetails is True.");
50 }
51
55
57
58 ATH_MSG_DEBUG( "Initialising Tool" );
59
60 ATH_CHECK(m_sgKeyMBTS.initialize());
61
62 //=== get TileCondToolTiming
63 ATH_CHECK( m_tileToolTiming.retrieve() );
64
65 //=== get TileCondToolEmscale
66 ATH_CHECK( m_tileToolEmscale.retrieve() );
67
69
71
72 return StatusCode::SUCCESS;
73 }
74
78 StatusCode CaloMBTSRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
79
80 ATH_MSG_DEBUG( "in retrieve()" );
81
83 if (!cellContainerMBTS.isValid()){
84 ATH_MSG_WARNING( "Could not retrieve MBTS Cells " );
85 }
86 else{
87 if (m_mbts) {
88 DataMap data = getMBTSData(&(*cellContainerMBTS));
89 ATH_CHECK( FormatTool->AddToEvent(dataTypeName(), m_sgKeyMBTS.key(), &data) );
90 ATH_MSG_DEBUG( "MBTS retrieved" );
91 }
92 }
93
94 //MBTS cells retrieved okay
95 return StatusCode::SUCCESS;
96 }
97
98
103 const DataMap CaloMBTSRetriever::getMBTSData(const TileCellContainer* tileMBTSCellContainer) {
104
105 ATH_MSG_DEBUG( "getMBTSData()" );
106
108
109 DataVect energy; energy.reserve(tileMBTSCellContainer->size());
110 DataVect label; label.reserve(tileMBTSCellContainer->size());
111 DataVect phi; phi.reserve(tileMBTSCellContainer->size());
112 DataVect eta; eta.reserve(tileMBTSCellContainer->size());
113 DataVect sampling; sampling.reserve(tileMBTSCellContainer->size());
114 DataVect timeVec; timeVec.reserve(tileMBTSCellContainer->size());
115 DataVect quality; quality.reserve(tileMBTSCellContainer->size());
116 DataVect type; type.reserve(tileMBTSCellContainer->size());
117 DataVect channel; channel.reserve(tileMBTSCellContainer->size());
118 DataVect module; module.reserve(tileMBTSCellContainer->size());
119 DataVect cellPedestal; cellPedestal.reserve(tileMBTSCellContainer->size());
120 DataVect cellRawAmplitude; cellRawAmplitude.reserve(tileMBTSCellContainer->size());
121 DataVect cellRawTime; cellRawTime.reserve(tileMBTSCellContainer->size());
122 DataVect adcCounts; adcCounts.reserve(tileMBTSCellContainer->size() * 10);
123
124 std::string adcCountsStr="adcCounts multiple=\"0\"";
125 const TileHWID* tileHWID = nullptr;
126 const TileInfo* tileInfo = nullptr;
127 const TileCablingService* cabling=nullptr;
130 bool offlineRch = false;
131
132 if ( detStore()->retrieve(m_tileTBID).isFailure() ) {
133 ATH_MSG_ERROR( "in getMBTSData(), Could not retrieve m_tileTBID" );
134 }
135
136 if ( detStore()->retrieve(tileHWID).isFailure() ) {
137 ATH_MSG_ERROR( "in getMBTSData(), Could not retrieve TileHWID" );
138 }
139
140 if ( detStore()->retrieve(tileInfo, "TileInfo").isFailure() ) {
141 ATH_MSG_ERROR( "in getMBTSData(), Could not retrieve TileInfo" );
142 }
143
145 if (m_mbtsCellDetails) {
146 RawChannelCnt = SG::makeHandle(m_sgKeyTileRawChannel);
147 if (!RawChannelCnt.isValid()){
148 ATH_MSG_WARNING( "Could not retrieve TileRawChannel " );
149 }
150 else{
151 RChUnit = RawChannelCnt->get_unit();
152 offlineRch = (RChUnit<TileRawChannelUnit::OnlineADCcounts &&
153 RawChannelCnt->get_type() != TileFragHash::OptFilterDsp);
154 }
155 }
156
158 if (m_mbtsdigit) {
159 tileDigits = SG::makeHandle(m_sgKeyTileDigits);
160 if (!tileDigits.isValid()){
161 ATH_MSG_WARNING( "Could not retrieve TileDigits " );
162 }
163 }
164
165 // from: TileCalorimeter/TileRec/src/TileCellToNtuple.cxx
166
167 std::string MBTS_ID;
168 int nchan =0;
169 int nTileSamples=0;
170 const int max_chan=5216;
171 double energyMeV = 0.;
172 double phiMBTS = 0.;
173 double amplitude = 0.;
174 unsigned long int cellid;
175 std::map<unsigned long int,double> theMbtspedestal;
176 std::map<unsigned long int,double> theMbtsrawamp;
177 std::map<unsigned long int,double> theMbtsrawtime;
178 std::map<unsigned long int,std::vector<float> > theMbtsdigit;
179 std::string myCellRawTimeStr = "0.";
180
181 //Loop over TileRawChannel to get Pedestal and raw amplitude and time
182
183 if (m_mbtsCellDetails && RawChannelCnt.isValid()) {
184 if (offlineRch) {
185
186 for (const auto rawChannel : *RawChannelCnt) {
187 for (const auto cell : *rawChannel) {
188 Identifier pmt_id = cell->pmt_ID();
189 if (!m_tileTBID->is_tiletb(pmt_id)) continue;
190 Identifier id = cell->cell_ID();
191 cellid = id.get_identifier32().get_compact();
192 HWIdentifier hwid=cell->adc_HWID();
193 int adc = tileHWID->adc(hwid);
194 int channel = tileHWID->channel(hwid);
195 int drawer = tileHWID->drawer(hwid);
196 int ros = tileHWID->ros(hwid);
197 int drawerIdx = TileCalibUtils::getDrawerIdx(ros,drawer);
198
199 amplitude = cell->amplitude();
200 //Change amplitude units to ADC counts
202 amplitude /= m_tileToolEmscale->channelCalib(drawerIdx, channel, adc, 1.0, TileRawChannelUnit::ADCcounts, RChUnit);
203 } else if (RChUnit > TileRawChannelUnit::OnlineADCcounts) {
204 amplitude = m_tileToolEmscale->undoOnlCalib(drawerIdx, channel, adc, amplitude, RChUnit);
205 }
206 theMbtspedestal.insert(std::make_pair( cellid, cell->pedestal() ) );
207 theMbtsrawamp.insert(std::make_pair( cellid, amplitude ));
208 theMbtsrawtime.insert(std::make_pair( cellid, cell->time(cell->uncorrTime()) ));
209 break;
210
211 }
212 }
213 }
214 }
215
216 //Loop over TileDigits to retrieve MBTS digits
217
218 if (m_mbtsdigit && tileDigits.isValid()) {
219
220 //----- get tile digits--------------------------
221
222 // tile digits loop
223 for (const auto digitChannel : *tileDigits) {
224
225 for (const auto cell : *digitChannel) {
226
227 Identifier pmt_id = cell->pmt_ID();
228 if (!m_tileTBID->is_tiletb(pmt_id)) continue;
229
230 Identifier id = cell->cell_ID();
231 cellid = id.get_identifier32().get_compact();
232
233 nTileSamples = cell->NtimeSamples();
234 std::vector<float> tileSamples = cell->samples();
235 theMbtsdigit.insert(std::make_pair( cellid, tileSamples));
236 break;
237
238 }
239 }//for TileDigitContainer loop
240 } //if (m_mbtsdigit)
241
242 //Loop Over TileCellContainer to retrieve MBTSCell information
243
244 for (const auto cell : *tileMBTSCellContainer) {
245
246 int qual = cell->quality();
247 if (cell->badcell()) qual = -qual;
248
249 timeVec.push_back(DataType( cell->time() ));
250 quality.push_back(DataType( qual ));
251
252 if ( cell->energy() >= m_mbtsThreshold ) {
253 energyMeV = cell->energy(); // roughly correct: energy unit is pC, which is 95% MeV
254 }else{
255 energyMeV = 0.;
256 }
257 energy.push_back(DataType( energyMeV )); // write in MeV
258
259 Identifier id=cell->ID();
260
261 //TileCell/type is "side" +/- 1
262 //TileCell/module is "phi" 0-7
263 //TileCell/channel is "eta" 0-1 zero is closer to beam pipe
264
265 type.push_back(DataType( m_tileTBID->type(id) ));
266 channel.push_back(DataType( m_tileTBID->channel(id) ));
267 module.push_back(DataType( m_tileTBID->module(id) ));
268
269 MBTS_ID = "type_" + DataType( m_tileTBID->type(id) ).toString() + "_ch_" +
270 DataType( m_tileTBID->channel(id) ).toString() + "_mod_" +
271 DataType( m_tileTBID->module(id) ).toString();
272
273 label.push_back(DataType( MBTS_ID ));
274
275 eta.push_back(DataType( 5.0*m_tileTBID->type(id) ));
276
277 phiMBTS = (M_PI/8)+(2*M_PI/8)*int(m_tileTBID->module(id));
278 phi.push_back(DataType( phiMBTS ));
279 sampling.push_back(DataType( m_tileTBID->channel(id) ));
280
281 if (m_mbtsCellDetails && RawChannelCnt.isValid()) {
282
283 cellPedestal.push_back(DataType( theMbtspedestal[id.get_identifier32().get_compact()] ));
284 cellRawAmplitude.push_back(DataType( theMbtsrawamp[id.get_identifier32().get_compact()] ));
285 myCellRawTimeStr = DataType(theMbtsrawtime[id.get_identifier32().get_compact()]).toString();
286
287 if ( myCellRawTimeStr.find('n') == 1 ) myCellRawTimeStr="0.";
288 cellRawTime.push_back( myCellRawTimeStr );
289
290 // this can rarely be '-nan', but checking this each time may make code slow ?
291 }
292 else { // don't have TileRawChannel container (for DPF input)
293
294 float maxTime = (tileInfo->NdigitSamples()/2) * 25;
295 int gain = cell->gain();
296
297 if (gain<0 || gain>1) { //invalid gain - channel missing
298 cellRawAmplitude.push_back(DataType(0));
299 cellRawTime.push_back(DataType(0));
300 cellPedestal.push_back(DataType(0)); //There is no pedestal in DPD .
301 }
302 else {
303
304 HWIdentifier hwid = tileHWID->adc_id(cabling->s2h_channel_id(id),gain);
305 int adc = tileHWID->adc(hwid);
306 int channel = tileHWID->channel(hwid);
307 int drawer = tileHWID->drawer(hwid);
308 int ros = tileHWID->ros(hwid);
309 int drawerIdx = TileCalibUtils::getDrawerIdx(ros,drawer);
310 float scale = m_tileToolEmscale->channelCalib(drawerIdx, channel, adc, 1.0,
312 float amp;
313
314 if ( cell->energy() >= m_mbtsThreshold ) amp = cell->energy()/scale;
315 else amp = 0.0;
316 float time = cell->time();
317
318 if ((qual != 0 || amp != 0.0) && (fabs(time) < maxTime && time != 0.0)) {
319 time += m_tileToolTiming->getSignalPhase(drawerIdx, channel, adc);
320 }
321
322 cellRawAmplitude.push_back(DataType(amp));
323 cellRawTime.push_back(DataType(time));
324 cellPedestal.push_back(DataType(0)); //There is no pedestal in DPD . This line is temporary.
325 }
326 }
327
328
329 if (m_mbtsdigit && tileDigits.isValid()) {
330
331 if ( !theMbtsdigit[id.get_identifier32().get_compact()].empty() ) {
332 for (int i=0; i<nTileSamples; i++) {
333 adcCountsStr="adcCounts multiple=\""+DataType(nTileSamples).toString()+"\"";
334 adcCounts.push_back(DataType( int(theMbtsdigit[id.get_identifier32().get_compact()][i]) ));
335 }
336 }
337 else {
338 for (int i=0; i<nTileSamples; i++) {
339 adcCountsStr="adcCounts multiple=\""+DataType(nTileSamples).toString()+"\"";
340 adcCounts.push_back(DataType(0));
341 }
342 }
343 }
344
345
346 ATH_MSG_DEBUG( "MBTS no: " << nchan << ", type_chan_mod: " << MBTS_ID
347 << ", energy MeV pC: " << energyMeV );
348
349 nchan++;
350
351 if (nchan >= max_chan) break;
352
353 }//TileCell Loop
354
355 if (!theMbtspedestal.empty()) theMbtspedestal.clear();
356 if (!theMbtsrawamp.empty() ) theMbtsrawamp.clear();
357 if (!theMbtsrawtime.empty()) theMbtsrawtime.clear();
358
359 // write values into DataMap
360 const auto nentries = phi.size();
361 DataMap["energy"] = std::move(energy);
362 DataMap["label"] = std::move(label);
363 DataMap["phi"] = std::move(phi);
364 DataMap["eta"] = std::move(eta);
365 DataMap["sampling"] = std::move(sampling);
366 DataMap["time"] = std::move(timeVec);
367 DataMap["quality"] = std::move(quality);
368 DataMap["type"] = std::move(type);
369 DataMap["channel"] = std::move(channel);
370 DataMap["module"] = std::move(module);
371 DataMap["cellPedestal"] = std::move(cellPedestal);
372 DataMap["cellRawAmplitude"] = std::move(cellRawAmplitude);
373 DataMap["cellRawTime"] = std::move(cellRawTime);
374 DataMap[adcCountsStr] = std::move(adcCounts);
375
376 //Be verbose
377 ATH_MSG_DEBUG( dataTypeName() << " retrieved with " << nentries << " entries" );
378
379 //All collections retrieved okay
380 return DataMap;
381
382 } // getMBTSData
383
384 //--------------------------------------------------------------------------
385
386} // JiveXML namespace
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
const int max_chan
TileContainer< TileCell > TileCellContainer
static const Attributes_t empty
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
size_type size() const noexcept
CaloMBTSRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
const DataMap getMBTSData(const TileCellContainer *tileMBTSCellContainer)
Retrieve MBTS cell location and details.
SG::ReadHandleKey< TileCellContainer > m_sgKeyMBTS
properties:
SG::ReadHandleKey< TileRawChannelContainer > m_sgKeyTileRawChannel
ToolHandle< TileCondToolEmscale > m_tileToolEmscale
StatusCode initialize()
Default AthAlgTool methods.
ToolHandle< TileCondToolTiming > m_tileToolTiming
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
virtual std::string dataTypeName() const
Return the name of the data type.
SG::ReadHandleKey< TileDigitsContainer > m_sgKeyTileDigits
virtual bool isValid() override final
Can the handle be successfully dereferenced?
static const TileCablingService * getInstance()
get pointer to service instance
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
Helper class for TileCal online (hardware) identifiers.
Definition TileHWID.h:49
int channel(const HWIdentifier &id) const
extract channel field from HW identifier
Definition TileHWID.h:189
int adc(const HWIdentifier &id) const
extract adc field from HW identifier
Definition TileHWID.h:193
int drawer(const HWIdentifier &id) const
extract drawer field from HW identifier
Definition TileHWID.h:171
HWIdentifier adc_id(int ros, int drawer, int channel, int adc) const
adc HWIdentifer
Definition TileHWID.cxx:229
int ros(const HWIdentifier &id) const
extract ros field from HW identifier
Definition TileHWID.h:167
int NdigitSamples() const
Returns the number of sammples (digits) per event.
Definition TileInfo.h:75
std::string label(const std::string &format, int i)
Definition label.h:19
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
std::map< std::string, DataVect > DataMap
Definition DataType.h:59
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition DataType.h:58
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())