ATLAS Offline Software
TileRawChannelTimeMonitorAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 #include "StoreGate/ReadHandle.h"
11 
13 
14  ATH_MSG_DEBUG("in initialize()");
15 
16  // initialize superclass
18 
20 
21  ATH_CHECK( m_cablingSvc.retrieve() );
22  m_cabling = m_cablingSvc->cablingService();
23 
29 
30  using Tile = TileCalibUtils;
31  using namespace Monitored;
32  const int nDigitizers = 8;
33 
34  m_timeGroups = buildToolMap<int>(m_tools, "TileAverageTime", Tile::MAX_ROS - 1);
35  m_uncorrTimeGroups = buildToolMap<int>(m_tools, "TileAverageUncorrectedTime", Tile::MAX_ROS - 1);
36  m_timeLBGroups = buildToolMap<int>(m_tools, "TileAverageTimeLB", Tile::MAX_ROS - 1);
37  m_timeDiffLBGroups = buildToolMap<int>(m_tools, "TileAverageTimeDifferenceLB", m_partitionTimeDifferencePairs.size());
38  m_digiTimeLBGroups = buildToolMap<std::vector<std::vector<int>>>(m_tools, "TileDigitizerTimeLB",
39  Tile::MAX_ROS - 1, Tile::MAX_DRAWER, nDigitizers);
40 
41  m_amplitudeGroups = buildToolMap<int>(m_tools, "TileAverageAmplitude", Tile::MAX_ROS - 1);
42 
43  return StatusCode::SUCCESS;
44 }
45 
46 
48 
49  using Tile = TileCalibUtils;
50 
51  // In case you want to measure the execution time
52  auto timer = Monitored::Timer("TIME_execute");
53 
54  const xAOD::EventInfo* eventInfo = GetEventInfo(ctx).get();
55 
56  unsigned int lvl1TriggerType = eventInfo->level1TriggerType();
57  if (!m_triggerTypes.empty()
58  && std::find( m_triggerTypes.begin(), m_triggerTypes.end(), lvl1TriggerType) == m_triggerTypes.end()) {
59  fill("TileRawChanTimeMonExecuteTime", timer);
60  return StatusCode::SUCCESS;
61  }
62 
63  std::vector<int> drawers[Tile::MAX_ROS - 1];
64  std::vector<int> channels[Tile::MAX_ROS - 1];
65  std::vector<double> channelTimes[Tile::MAX_ROS - 1];
66  std::vector<double> channelUncorrectedTimes[Tile::MAX_ROS - 1];
67  std::vector<double> channelAmplitudes[Tile::MAX_ROS - 1];
68 
69  const TileDQstatus* dqStatus = SG::makeHandle(m_DQstatusKey, ctx).get();
70  const TileDCSState* dcsState = m_checkDCS ? SG::ReadCondHandle(m_DCSStateKey, ctx).cptr() : nullptr;
71 
73  ATH_CHECK( emScale.isValid() );
74 
76 
78  ATH_CHECK( rawChannelContainer.isValid() );
79 
80  TileRawChannelUnit::UNIT rawChannelUnit = rawChannelContainer->get_unit();
81 
82  for (const TileRawChannelCollection* rawChannelCollection : *rawChannelContainer) {
83  if (rawChannelCollection->empty() ) continue;
84 
85  HWIdentifier adc_id = rawChannelCollection->front()->adc_HWID();
86  int ros = m_tileHWID->ros(adc_id);
87  int drawer = m_tileHWID->drawer(adc_id);
88  unsigned int drawerIdx = TileCalibUtils::getDrawerIdx(ros, drawer);
89  int partition = ros - 1;
90 
91  for (const TileRawChannel* rawChannel : *rawChannelCollection) {
92 
93  adc_id = rawChannel->adc_HWID();
94  int channel = m_tileHWID->channel(adc_id);
95  int adc = m_tileHWID->adc(adc_id);
96 
98  ATH_MSG_VERBOSE(m_tileHWID->to_string(adc_id) << ": channlel is disconnected => skipping!");
99  continue;
100  }
101 
102  if (!(dqStatus->isAdcDQgood(ros, drawer, channel, adc))) {
103  ATH_MSG_VERBOSE(m_tileHWID->to_string(adc_id) << ": DQ is BAD => skipping!");
104  continue;
105  }
106 
107  if (m_checkDCS && dcsState->isStatusBad(ros, drawer, channel)) {
108  ATH_MSG_VERBOSE(m_tileHWID->to_string(adc_id) << ": DCS is Bad => skipping!");
109  continue;
110  }
111 
112  TileBchStatus status = badChannels->getAdcStatus(adc_id);
113  if (status.isBad() || status.isBadTiming()) {
114  ATH_MSG_VERBOSE(m_tileHWID->to_string(adc_id) << ": Status or Timing is BAD => skipping!");
115  continue;
116  }
117 
118  if (rawChannel->amplitude() < m_energyThresholds[adc]) {
119  ATH_MSG_VERBOSE(m_tileHWID->to_string(adc_id) << ": Energy is below threshold => skipping!");
120  continue;
121  }
122 
123  drawers[partition].push_back(drawer);
124  channels[partition].push_back(channel);
125  channelTimes[partition].push_back(rawChannel->time());
126  channelUncorrectedTimes[partition].push_back(rawChannel->uncorrTime());
127 
128  float amplitude = rawChannel->amplitude();
129  amplitude = emScale->calibrateChannel(drawerIdx, channel, adc, amplitude, rawChannelUnit, TileRawChannelUnit::PicoCoulombs);
130  channelAmplitudes[partition].push_back(amplitude);
131  }
132  }
133 
134  float partitionTime[4] = {0};
135 
136  for (unsigned int partition = 0; partition < Tile::MAX_ROS - 1; ++partition) {
137  int nChannels = 0;
138  double averagePartitionTime = 0.0;
139  std::vector<double>& times = channelTimes[partition];
140 
141  for (unsigned int channelIdx = 0; channelIdx < channels[partition].size(); ++ channelIdx) {
142  int channel = channels[partition][channelIdx];
143  if ( (partition > 1) // EB, exclude some channels (most likely single PMT) from calculating average time
144  && (channel < 6 || channel == 12 || channel == 13 || channel == 18 || channel == 19) ) continue;
145 
146  averagePartitionTime += times[channelIdx];
147  ++nChannels;
148  }
149 
150  if (nChannels > 0) {
151  averagePartitionTime /= nChannels;
152  partitionTime[partition] = averagePartitionTime - m_partitionTimeCorrection[partition];
153 
154  std::transform(times.begin(), times.end(), times.begin(),
155  [averagePartitionTime] (double time) {return time - averagePartitionTime;});
156  }
157  }
158 
159  static const int channel2digitizer[48] = {7, 7, 7, 7, 7, 7,
160  6, 6, 6, 6, 6, 6,
161  5, 5, 5, 5, 5, 5,
162  4, 4, 4, 4, 4, 4,
163  3, 3, 3, 3, 3, 3,
164  2, 2, 2, 2, 2, 2,
165  1, 1, 1, 1, 1, 1,
166  0, 0, 0, 0, 0, 0};
167 
168  unsigned int lumiBlock = eventInfo->lumiBlock();
169  auto monLumiBlock = Monitored::Scalar<double>("lumiBlock", lumiBlock);
170 
171  for (unsigned int partition = 0; partition < Tile::MAX_ROS - 1; ++partition) {
172  if (!channelTimes[partition].empty()) {
173  auto monModule = Monitored::Collection("module", drawers[partition]);
174  auto monChannel = Monitored::Collection("channel", channels[partition]);
175  auto monTime = Monitored::Collection("time", channelTimes[partition]);
176  fill(m_tools[m_timeGroups[partition]], monModule, monChannel, monTime);
177 
178  auto monUncorrTime = Monitored::Collection("time", channelUncorrectedTimes[partition]);
179  fill(m_tools[m_uncorrTimeGroups[partition]], monModule, monChannel, monUncorrTime);
180 
181  auto monPartitionTime = Monitored::Scalar<float>("time", partitionTime[partition]);
182  fill(m_tools[m_timeLBGroups[partition]], monLumiBlock, monPartitionTime);
183 
184  auto monAmplitude = Monitored::Collection("amplitude", channelAmplitudes[partition]);
185  fill(m_tools[m_amplitudeGroups[partition]], monModule, monChannel, monAmplitude);
186 
187  for (unsigned int channelIdx = 0; channelIdx < channels[partition].size(); ++ channelIdx) {
188  int drawer = drawers[partition][channelIdx];
189  int digitizer = channel2digitizer[ channels[partition][channelIdx] ];
190  auto monTime = Monitored::Scalar<double>("time", channelTimes[partition][channelIdx]);
191  fill(m_tools[m_digiTimeLBGroups[partition][drawer][digitizer]], monLumiBlock, monTime);
192  }
193 
194  }
195  }
196 
197  for (unsigned int pairIdx = 0; pairIdx < m_partitionTimeDifferencePairs.size(); ++pairIdx) {
198  const std::pair<int, int>& partitionPair = m_partitionTimeDifferencePairs[pairIdx];
199  int partition1 = partitionPair.first;
200  int partition2 = partitionPair.second;
201  auto monTime = Monitored::Scalar<double>("time", partitionTime[partition1] - partitionTime[partition2]);
202  fill(m_tools[m_timeDiffLBGroups[pairIdx]], monLumiBlock, monTime);
203  }
204 
205  fill("TileRawChanTimeMonExecuteTime", timer);
206 
207  return StatusCode::SUCCESS;
208 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileRawChannelTimeMonitorAlgorithm::m_DQstatusKey
SG::ReadHandleKey< TileDQstatus > m_DQstatusKey
Definition: TileRawChannelTimeMonitorAlgorithm.h:55
TileRawChannelTimeMonitorAlgorithm::m_amplitudeGroups
std::vector< int > m_amplitudeGroups
Definition: TileRawChannelTimeMonitorAlgorithm.h:93
TileRawChannelTimeMonitorAlgorithm::m_rawChannelContainerKey
SG::ReadHandleKey< TileRawChannelContainer > m_rawChannelContainerKey
Definition: TileRawChannelTimeMonitorAlgorithm.h:58
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TileRawChannelTimeMonitorAlgorithm::m_digiTimeLBGroups
std::vector< std::vector< std::vector< int > > > m_digiTimeLBGroups
Definition: TileRawChannelTimeMonitorAlgorithm.h:92
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
TileCalibUtils.h
TileRawChannelTimeMonitorAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: TileRawChannelTimeMonitorAlgorithm.cxx:47
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TileRawChannelUnit::PicoCoulombs
@ PicoCoulombs
Definition: TileRawChannelUnit.h:18
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
TileDCSState::isStatusBad
bool isStatusBad(unsigned int ros, unsigned int drawer) const
Return true if given Tile drawer considered as bad by summary drawer states per LVPS otherwise return...
Definition: TileDCSState.h:320
Example_ReadSampleNoise.drawer
drawer
Definition: Example_ReadSampleNoise.py:39
TileRawChannelTimeMonitorAlgorithm::m_cabling
const TileCablingService * m_cabling
Definition: TileRawChannelTimeMonitorAlgorithm.h:86
ReadCondHandle.h
TileHWID::channel
int channel(const HWIdentifier &id) const
extract channel field from HW identifier
Definition: TileHWID.h:189
TileRawChannelTimeMonitorAlgorithm::m_timeLBGroups
std::vector< int > m_timeLBGroups
Definition: TileRawChannelTimeMonitorAlgorithm.h:90
TileRawChannelTimeMonitorAlgorithm.h
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
dq_defect_copy_defect_database.channels
def channels
Definition: dq_defect_copy_defect_database.py:56
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
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
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
TileRawChannelTimeMonitorAlgorithm::m_partitionTimeDifferencePairs
Gaudi::Property< std::vector< std::pair< int, int > > > m_partitionTimeDifferencePairs
Definition: TileRawChannelTimeMonitorAlgorithm.h:52
TileEMScale::calibrateChannel
float calibrateChannel(unsigned int drawerIdx, unsigned int channel, unsigned int adc, float amplitude, TileRawChannelUnit::UNIT rawDataUnitIn, TileRawChannelUnit::UNIT rawDataUnitOut) const
Calibrate a Tile channel.
Definition: TileEMScale.cxx:136
TileDQstatus
Class that holds Data Quality fragment information and provides functions to extract the data quality...
Definition: TileDQstatus.h:49
TileHWID::adc
int adc(const HWIdentifier &id) const
extract adc field from HW identifier
Definition: TileHWID.h:193
Tile
Definition: TileVolumeBuilder.h:43
TileHWID.h
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
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
TileRawChannelTimeMonitorAlgorithm::m_uncorrTimeGroups
std::vector< int > m_uncorrTimeGroups
Definition: TileRawChannelTimeMonitorAlgorithm.h:89
AthMonitorAlgorithm::GetEventInfo
SG::ReadHandle< xAOD::EventInfo > GetEventInfo(const EventContext &) const
Return a ReadHandle for an EventInfo object (get run/event numbers, etc.)
Definition: AthMonitorAlgorithm.cxx:107
TileRawChannelTimeMonitorAlgorithm::m_timeGroups
std::vector< int > m_timeGroups
Definition: TileRawChannelTimeMonitorAlgorithm.h:88
TileRawChannelUnit::UNIT
UNIT
Definition: TileRawChannelUnit.h:16
xAOD::EventInfo_v1::lumiBlock
uint32_t lumiBlock() const
The current event's luminosity block number.
TileRawChannelTimeMonitorAlgorithm::m_timeDiffLBGroups
std::vector< int > m_timeDiffLBGroups
Definition: TileRawChannelTimeMonitorAlgorithm.h:91
TileDQstatus::isAdcDQgood
bool isAdcDQgood(int partition, int drawer, int ch, int gain) const
returns status of single ADC returns False if there are any errors
Definition: TileDQstatus.cxx:178
TileRawChannelTimeMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: TileRawChannelTimeMonitorAlgorithm.cxx:12
TileRawChannelTimeMonitorAlgorithm::m_badChannelsKey
SG::ReadCondHandleKey< TileBadChannels > m_badChannelsKey
Name of TileBadChannels in condition store.
Definition: TileRawChannelTimeMonitorAlgorithm.h:70
AthMonitorAlgorithm::m_tools
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
Definition: AthMonitorAlgorithm.h:338
TileRawChannelTimeMonitorAlgorithm::m_cablingSvc
ServiceHandle< TileCablingSvc > m_cablingSvc
Name of Tile cabling service.
Definition: TileRawChannelTimeMonitorAlgorithm.h:82
TileRawChannelCollection
Definition: TileRawChannelCollection.h:12
TileRawChannelTimeMonitorAlgorithm::m_tileHWID
const TileHWID * m_tileHWID
Definition: TileRawChannelTimeMonitorAlgorithm.h:85
TileRawChannelTimeMonitorAlgorithm::m_emScaleKey
SG::ReadCondHandleKey< TileEMScale > m_emScaleKey
Name of TileEMScale in condition store.
Definition: TileRawChannelTimeMonitorAlgorithm.h:76
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
TileBadChannels::getAdcStatus
const TileBchStatus & getAdcStatus(const HWIdentifier adc_id) const
Return Tile ADC status.
Definition: TileBadChannels.cxx:24
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
python.Classes.TileBchStatus
TileBchStatus
Definition: TileCalib/TileCalibBlobObjs/python/Classes.py:16
TileCablingService::isDisconnected
bool isDisconnected(int ros, int drawer, int channel) const
Definition: TileCablingService.cxx:2461
TileHWID::drawer
int drawer(const HWIdentifier &id) const
extract drawer field from HW identifier
Definition: TileHWID.h:171
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
ReadFloatFromCool.adc
adc
Definition: ReadFloatFromCool.py:48
python.Classes.TileCalibUtils
TileCalibUtils
Definition: TileCalib/TileCalibBlobObjs/python/Classes.py:5
StateLessPT_NewConfig.partition
partition
Definition: StateLessPT_NewConfig.py:49
TileRawChannelTimeMonitorAlgorithm::m_DCSStateKey
SG::ReadCondHandleKey< TileDCSState > m_DCSStateKey
Name of TileDCSState object in condition store.
Definition: TileRawChannelTimeMonitorAlgorithm.h:64
xAOD::EventInfo_v1::level1TriggerType
uint16_t level1TriggerType() const
The Level-1 trigger type.
TileDCSState
Condition object to keep Tile DCS status from DB.
Definition: TileDCSState.h:24
TileRawChannelTimeMonitorAlgorithm::m_energyThresholds
Gaudi::Property< std::vector< double > > m_energyThresholds
Definition: TileRawChannelTimeMonitorAlgorithm.h:45
TileRawChannelTimeMonitorAlgorithm::m_checkDCS
Gaudi::Property< bool > m_checkDCS
Definition: TileRawChannelTimeMonitorAlgorithm.h:40
merge.status
status
Definition: merge.py:17
TileCalibUtils::getDrawerIdx
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
Definition: TileCalibUtils.cxx:60
TileAANtupleConfig.rawChannelContainer
rawChannelContainer
Definition: TileAANtupleConfig.py:120
TileRawChannelTimeMonitorAlgorithm::m_triggerTypes
Gaudi::Property< std::vector< unsigned int > > m_triggerTypes
Definition: TileRawChannelTimeMonitorAlgorithm.h:42
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
TileHWID::to_string
std::string to_string(const HWIdentifier &id, int level=0) const
extract all fields from HW identifier HWIdentifier get_all_fields ( const HWIdentifier & id,...
Definition: TileHWID.cxx:49
ReadHandle.h
Handle class for reading from StoreGate.
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:327
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
plot_times.times
def times(fn)
Definition: plot_times.py:11
TileRawChannelTimeMonitorAlgorithm::m_partitionTimeCorrection
Gaudi::Property< std::vector< double > > m_partitionTimeCorrection
Definition: TileRawChannelTimeMonitorAlgorithm.h:48
SG::ReadCondHandle::cptr
const_pointer_type cptr()
Definition: ReadCondHandle.h:67