ATLAS Offline Software
TileTBPulseMonitorAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 
10 #include "StoreGate/ReadHandle.h"
11 
12 #include <algorithm>
13 
15 
16  ATH_MSG_INFO("in initialize()");
18 
21  ATH_CHECK( m_cablingSvc.retrieve() );
23 
26 
27  std::vector<std::string> modules;
28  for (int fragID : m_fragIDs) {
29  int ros = fragID >> 8;
30  int drawer = fragID & 0x3F;
31  modules.push_back(TileCalibUtils::getDrawerString(ros, drawer));
32  }
33 
34  using namespace Monitored;
35  m_pulseGroups = buildToolMap<int>(m_tools, "TilePulseShape", modules);
36  m_pulseProfileGroups = buildToolMap<int>(m_tools, "TilePulseShapeProfile", modules);
37 
38  std::ostringstream os;
39  if ( m_fragIDs.size() != 0) {
40  std::sort(m_fragIDs.begin(), m_fragIDs.end());
41  for (int fragID : m_fragIDs) {
42  unsigned int ros = fragID >> 8;
43  unsigned int drawer = fragID & 0xFF;
45  os << " " << module << "/0x" << std::hex << fragID << std::dec;
46  }
47  } else {
48  os << "NONE";
49  }
50 
51  ATH_MSG_INFO("Monitored modules/frag ID:" << os.str());
52 
53  return StatusCode::SUCCESS;
54 }
55 
56 
57 StatusCode TileTBPulseMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
58 
59  // In case you want to measure the execution time
60  auto timer = Monitored::Timer("TIME_execute");
61 
62  using Tile = TileCalibUtils;
63  float amplitude[Tile::MAX_CHAN][Tile::MAX_GAIN];
64  float time[Tile::MAX_CHAN][Tile::MAX_GAIN];
65  float pedestal[Tile::MAX_CHAN][Tile::MAX_GAIN];
66 
68  ATH_CHECK( rawChannelContainer.isValid() );
69 
71  ATH_CHECK( digitsContainer.isValid() );
72 
73  const TileFragHash& rchHashFunc = rawChannelContainer->hashFunc();
74  const TileFragHash& digitsHashFunc = digitsContainer->hashFunc();
75 
76  std::vector<float> times;
77  std::vector<float> amplitudes;
78 
79  for (int fragID : m_fragIDs) {
80 
81  IdentifierHash hash = static_cast<IdentifierHash>(rchHashFunc(fragID));
82  const TileRawChannelCollection* rawChannelCollection = rawChannelContainer->indexFindPtr(hash);
83  if (!rawChannelCollection || rawChannelCollection->empty()) continue;
84 
85 
86  hash = static_cast<IdentifierHash>(digitsHashFunc(fragID));
87  const TileDigitsCollection* digitsCollection = digitsContainer->indexFindPtr(hash);
88  if (!digitsCollection || digitsCollection->empty()) continue;
89 
90  memset(amplitude, 0, sizeof(amplitude));
91  memset(time, 0, sizeof(time));
92  memset(pedestal, 0, sizeof(pedestal));
93 
94  for (const TileRawChannel* rch : *rawChannelCollection) {
95 
96  HWIdentifier adc_id = rch->adc_HWID();
97  int channel = m_tileHWID->channel(adc_id);
98  int adc = m_tileHWID->adc(adc_id);
99 
100  amplitude[channel][adc] = rch->amplitude();
101  time[channel][adc] = rch->time();
102 
103  float ped = rch->pedestal();
104  ped = ped - int( (ped + 500 ) * 1e-4) * 10000; // Remove encoded problems into pedestal
105  pedestal[channel][adc] = ped;
106 
107  }
108 
109  HWIdentifier adc_id = digitsCollection->front()->adc_HWID();
110  int ros = m_tileHWID->ros(adc_id);
111  int drawer = m_tileHWID->drawer(adc_id);
113 
114  for (const TileDigits* tile_digits : *digitsCollection) {
115 
116  adc_id = tile_digits->adc_HWID();
117  int channel = m_tileHWID->channel(adc_id);
118  int adc = m_tileHWID->adc(adc_id);
119 
120  std::vector<float> digits = tile_digits->samples();
121  ATH_MSG_VERBOSE("Ros: " << ros
122  << " drawer: " << drawer
123  << " channel: " << channel
124  << " gain: " << adc
125  << " amp: " << amplitude[channel][adc]
126  << " time: " << time[channel][adc] );
127 
128 
129  std::string channelGainSuffix = "_" + std::to_string(channel) + "_" + std::to_string(adc);
130 
131  times.clear();
132  auto monTimes = Monitored::Collection("time" + channelGainSuffix, times);
133 
134  amplitudes.clear();
135  auto monAmplitude = Monitored::Collection("amplitude" + channelGainSuffix, amplitudes);
136 
137  int sampleIdx = 0;
138  if ( time[channel][adc] != 0 && amplitude[channel][adc] > 0.) {
139  for (double digit : digits) {
140  times.push_back( (sampleIdx - m_t0SamplePosition) * 25. - time[channel][adc] );
141  amplitudes.push_back( (digit - pedestal[channel][adc] ) / amplitude[channel][adc] );
142  ++sampleIdx;
143  }
144  }
145 
146  fill(m_tools[m_pulseGroups.at(module)], monTimes, monAmplitude);
147  fill(m_tools[m_pulseProfileGroups.at(module)], monTimes, monAmplitude);
148  }
149 
150  }
151 
152  fill("TileTBPulseMonExecuteTime", timer);
153 
154  return StatusCode::SUCCESS;
155 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileTBPulseMonitorAlgorithm::m_pulseGroups
std::map< std::string, int > m_pulseGroups
Definition: TileTBPulseMonitorAlgorithm.h:52
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TileTBPulseMonitorAlgorithm::m_digitsContainerKey
SG::ReadHandleKey< TileDigitsContainer > m_digitsContainerKey
Definition: TileTBPulseMonitorAlgorithm.h:37
TileTBPulseMonitorAlgorithm.h
TileTBPulseMonitorAlgorithm.fragID
fragID
Definition: TileTBPulseMonitorAlgorithm.py:166
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TileInfo.h
TileCalibUtils.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
checkRpcDigits.digit
digit
Definition: checkRpcDigits.py:186
TileFragHash
Hash table for Tile fragments (==drawers ==collections in StoreGate)
Definition: TileFragHash.h:24
TileRawData::adc_HWID
HWIdentifier adc_HWID(void) const
Definition: TileRawData.h:53
Example_ReadSampleNoise.drawer
drawer
Definition: Example_ReadSampleNoise.py:39
TileHWID::channel
int channel(const HWIdentifier &id) const
extract channel field from HW identifier
Definition: TileHWID.h:189
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TileTBPulseMonitorAlgorithm::m_pulseProfileGroups
std::map< std::string, int > m_pulseProfileGroups
Definition: TileTBPulseMonitorAlgorithm.h:53
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
TileHWID::ros
int ros(const HWIdentifier &id) const
extract ros field from HW identifier
Definition: TileHWID.h:167
python.PyAthena.module
module
Definition: PyAthena.py:131
TileHWID::adc
int adc(const HWIdentifier &id) const
extract adc field from HW identifier
Definition: TileHWID.h:193
Tile
Definition: TileVolumeBuilder.h:43
TileInfo::ItrigSample
int ItrigSample() const
The sample at which the pulse should ideally peak.
Definition: TileInfo.h:77
TileHWID.h
TileTBPulseMonitorAlgorithm::m_rawChannelContainerKey
SG::ReadHandleKey< TileRawChannelContainer > m_rawChannelContainerKey
Definition: TileTBPulseMonitorAlgorithm.h:34
TileTBPulseMonitorAlgorithm::m_tileHWID
const TileHWID * m_tileHWID
Definition: TileTBPulseMonitorAlgorithm.h:55
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DataVector::front
const T * front() const
Access the first element in the collection as an rvalue.
TileRawChannel
Definition: TileRawChannel.h:35
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthMonitorAlgorithm::fill
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable >> &&variables) const
Fills a vector of variables to a group by reference.
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
maskDeadModules.ros
ros
Definition: maskDeadModules.py:35
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TileTBPulseMonitorAlgorithm::m_tileInfo
const TileInfo * m_tileInfo
Definition: TileTBPulseMonitorAlgorithm.h:56
AthMonitorAlgorithm::m_tools
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
Definition: AthMonitorAlgorithm.h:338
TileDigitsCollection
Definition: TileDigitsCollection.h:18
TileDigits
Definition: TileDigits.h:30
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TileRawChannelCollection
Definition: TileRawChannelCollection.h:12
TileRawDataContainer::hashFunc
const TileFragHash & hashFunc() const
Definition: TileRawDataContainer.h:66
TileTBPulseMonitorAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: TileTBPulseMonitorAlgorithm.cxx:57
Example_ReadSampleNoise.ped
ped
Definition: Example_ReadSampleNoise.py:45
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
IdentifiableContainerMT::indexFindPtr
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
Definition: IdentifiableContainerMT.h:292
TileCalibUtils::getDrawerString
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
Definition: TileCalibUtils.cxx:145
TileHWID::drawer
int drawer(const HWIdentifier &id) const
extract drawer field from HW identifier
Definition: TileHWID.h:171
TileTBPulseMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: TileTBPulseMonitorAlgorithm.cxx:14
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
ReadFloatFromCool.adc
adc
Definition: ReadFloatFromCool.py:48
TileTBPulseMonitorAlgorithm.int
int
Definition: TileTBPulseMonitorAlgorithm.py:160
python.Classes.TileCalibUtils
TileCalibUtils
Definition: TileCalib/TileCalibBlobObjs/python/Classes.py:5
TileTBPulseMonitorAlgorithm::m_fragIDs
Gaudi::Property< std::vector< int > > m_fragIDs
Definition: TileTBPulseMonitorAlgorithm.h:49
TileAANtupleConfig.rawChannelContainer
rawChannelContainer
Definition: TileAANtupleConfig.py:120
TileTBPulseMonitorAlgorithm::m_cablingSvc
ServiceHandle< TileCablingSvc > m_cablingSvc
Name of Tile cabling service.
Definition: TileTBPulseMonitorAlgorithm.h:46
ReadHandle.h
Handle class for reading from StoreGate.
TileTBPulseMonitorAlgorithm::m_tileInfoName
Gaudi::Property< std::string > m_tileInfoName
Definition: TileTBPulseMonitorAlgorithm.h:40
TileTBPulseMonitorAlgorithm::m_t0SamplePosition
int m_t0SamplePosition
Definition: TileTBPulseMonitorAlgorithm.h:57
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
plot_times.times
def times(fn)
Definition: plot_times.py:11