ATLAS Offline Software
TileRawChannelNoiseFilter.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 // Tile includes
13 
14 // Atlas includes
16 #include "Identifier/Identifier.h"
17 #include "StoreGate/ReadHandle.h"
19 #include "GaudiKernel/ThreadLocalContext.h"
20 
21 
22 //========================================================
23 // constructor
25  const std::string& name, const IInterface* parent)
26  : base_class(type, name, parent)
27  , m_tileHWID(0)
28  , m_truncationThresholdOnAbsEinSigma(3.0) // 3 sigma of ADC HF noise by default
29  , m_minimumNumberOfTruncatedChannels(0.6) // at least 60% of channels should be below threshold
30  , m_useTwoGaussNoise(false) // do not use 2G - has no sense for ADC HF noise for the moment
31  , m_useGapCells(false) // use gap cells for noise filter as all normal cells
32  , m_tileInfo(0)
33 {
34 
35  declareProperty("TruncationThresholdOnAbsEinSigma", m_truncationThresholdOnAbsEinSigma);
36  declareProperty("MinimumNumberOfTruncatedChannels", m_minimumNumberOfTruncatedChannels);
37  declareProperty("UseTwoGaussNoise", m_useTwoGaussNoise);
38  declareProperty("UseGapCells", m_useGapCells);
39  declareProperty("MaxNoiseSigma", m_maxNoiseSigma = 5.0, "Channels with noise more than that value are igonred in calculation of correction");
40  declareProperty("TileInfoName", m_infoName = "TileInfo");
41 }
42 
43 //========================================================
44 // Initialize
46  ATH_MSG_INFO("Initializing...");
47 
48  if (msgLvl(MSG::DEBUG)) {
49  msg(MSG::DEBUG) << "TruncationThresholdOnAbsEinSigma = "
51  msg(MSG::DEBUG) << "MinimumNumberOfTruncatedChannels = "
53  msg(MSG::DEBUG) << "UseTwoGaussNoise = "
54  << ((m_useTwoGaussNoise)?"true":"false") << endmsg;
55  msg(MSG::DEBUG) << "UseGapCells = "
56  << ((m_useGapCells)?"true":"false") << endmsg;
57  }
58 
60 
62 
64 
66 
67  //=== get TileInfo
69  m_ADCmaskValueMinusEps = m_tileInfo->ADCmaskValue() - 0.01; // indicates channels which were masked in background dataset
70 
72 
73  return StatusCode::SUCCESS;
74 }
75 
76 // ============================================================================
77 // process container
79 TileRawChannelNoiseFilter::process (TileMutableRawChannelContainer& rchCont, const EventContext& ctx) const
80 {
81  ATH_MSG_DEBUG("in TileRawChannelNoiseFilter::process()");
82 
83  TileRawChannelUnit::UNIT rChUnit = rchCont.get_unit();
84  std::string units[8] = { "ADC counts", "pC", "CspC", "MeV",
85  "online ADC counts", "online pC", "online CspC", "online MeV" };
86 
87  if (rChUnit > TileRawChannelUnit::ADCcounts
89 
90  ATH_MSG_ERROR( "Units in container is " << units[rChUnit] );
91  ATH_MSG_ERROR( "Due to non-linear CIS constants noise filter is possible only with ADC counts ");
92  ATH_MSG_ERROR( "Please, disable CIS calibration in optimal filter " );
93 
94  return StatusCode::FAILURE;
95  }
96 
97  bool undoOnlCalib = (rChUnit > TileRawChannelUnit::OnlineADCcounts);
98  ATH_MSG_VERBOSE( "Units in container is " << units[rChUnit] );
99 
100  // Now retrieve the TileDQStatus
101  const TileDQstatus* DQstatus = SG::makeHandle (m_DQstatusKey, ctx).get();
102 
104  ATH_CHECK( emScale.isValid() );
105 
107  ATH_CHECK( badChannels.isValid() );
108 
110  ATH_CHECK( sampleNoise.isValid() );
111 
112  for (IdentifierHash hash : rchCont.GetAllCurrentHashes()) {
113  TileRawChannelCollection* coll = rchCont.indexFindPtr (hash);
114 
115  /* Get drawer ID and build drawer index. */
116  HWIdentifier drawer_id = m_tileHWID->drawer_id(coll->identify());
117  int ros = m_tileHWID->ros(drawer_id);
118  int drawer = m_tileHWID->drawer(drawer_id);
119  unsigned int drawerIdx = TileCalibUtils::getDrawerIdx(ros, drawer);
120  bool eb = (ros > 2);
121  bool ebspD4 = ((ros == 3 && drawer == 14) || (ros == 4 && drawer == 17));
122  bool ebNsp = !ebspD4 && eb;
123  bool ebspC10 = (ebNsp && ((drawer>37 && drawer<42) || (drawer>53 && drawer<58) ) );
124 
125  static const int maxChannelDrawer = 48; // number of channels in one drawer
126  static const int maxChannel = 12; // number of channels per motherboard
127  static const int maxMOB = 4; // number of motherboards in one drawer
128 
129  float calib[maxChannelDrawer];
130  float commonmode[maxMOB];
131  int nemptychan[maxMOB];
132  int ngoodchan[maxMOB];
133  int chanmap[maxChannelDrawer];
134  memset(calib, 0, sizeof(calib));
135  memset(commonmode, 0, sizeof(commonmode));
136  memset(nemptychan, 0, sizeof(nemptychan));
137  memset(ngoodchan, 0, sizeof(ngoodchan));
138  memset(chanmap, 0, sizeof(chanmap));
139 
140  // iterate over all channels in a collection
141  for (const TileRawChannel* rch : *coll) {
142  HWIdentifier adc_id = rch->adc_HWID();
143  //int index,pmt;
144  //Identifier cell_id = rch->cell_ID_index(index,pmt);
145  //if ( index == -1 ) continue; // this is to ignore disconnected channels - just for tests
146  //if ( index < 0 ) continue; // this is to ingnore disconnected channels and MBTS - just for tests
147 
148  int chan = m_tileHWID->channel(adc_id);
149  int gain = m_tileHWID->adc(adc_id);
150  int mob = chan / maxChannel;
151  bool empty = (eb && ( (chan > 41) || (chan > 23 && chan < 30) || (ebspD4 && chan < 3) ) );
152 
153  // use only good channel
154  float ped=rch->pedestal();
155  if (empty || ped > 59500. || (ped > m_ADCmaskValueMinusEps && ped < 39500.) // all bad patterns, ped=m_tileInfo->ADCmaskValue(), underflow, overflow (see TileRawChannelMaker.cxx for the logic)
156  || badChannels->getAdcStatus(adc_id).isBad()
157  || (!DQstatus->isAdcDQgood(ros, drawer, chan, gain))) continue;
158 
159 
160  bool usechan = m_useGapCells || // always true if we want to use gap cells
161  ( ! ( ( ebNsp && (chan==0 || chan==1 || chan==12 || chan==13)) ||
162  ( ebspC10 && (chan==4 || chan==5)) ||
163  ( ebspD4 && (chan==18 || chan==19 || chan==12 || chan==13)) ) );
164 
165  ++chanmap[chan];
166  // do not count good channels twice
167  if (chanmap[chan] < 2 && usechan) ++ngoodchan[mob];
168  // use only high gain
169  if (gain != TileHWID::HIGHGAIN) continue;
170 
171  float amp = rch->amplitude();
172  if (undoOnlCalib) {
173  calib[chan] = emScale->undoOnlineChannelCalibration(drawerIdx, chan, gain, 1.0, rChUnit);
174  amp *= calib[chan];
175  } else {
176  calib[chan] = 1.0;
177  }
178 
179 
180  if (usechan) {
181 
182  float noise_sigma = 1.5; // default value of HFN in high gain channel
183  if (m_useTwoGaussNoise) {
184  //float sigma1 = m_tileToolNoiseSample->getHfn1(drawerIdx, chan, gain, ctx);
185  //float sigma2 = m_tileToolNoiseSample->getHfn2(drawerIdx, chan, gain, ctx);
186  //float norm = m_tileToolNoiseSample->getHfnNorm(drawerIdx, chan, gain, ctx);
187  // still need to define noise_sigma in this case
188  // noise_sigma = ...
189  } else {
190  // take single gauss noise sigma from DB (high frequency noise)
191  noise_sigma = sampleNoise->getHfn(drawerIdx, chan, gain);
192  }
193 
194  float significance = 999.999;
195  if ((noise_sigma != 0.0)
196  && (noise_sigma < m_maxNoiseSigma)
197  /* && (!m_tileBadChanTool->getAdcStatus(drawerIdx, chan, gain).isNoisy()) */) {
198 
199  significance = fabs(amp / noise_sigma); // caluclate signal/noise ratio
200  } else {
201  --ngoodchan[mob]; // ignore completely channels with zero sigma
202  }
203 
204  ATH_MSG_VERBOSE( "HWID " << m_tileHWID->to_string(adc_id)
205  << " calib " << 1. / calib[chan]
206  << " amp " << amp
207  << " noise " << noise_sigma
208  << " significance " << significance );
209 
210  if (significance > m_truncationThresholdOnAbsEinSigma) continue;
211 
212  commonmode[mob] += amp;
213  ++nemptychan[mob];
214 
215  } else {
216 
217  ATH_MSG_VERBOSE( "HWID " << m_tileHWID->to_string(adc_id)
218  << " calib " << 1. / calib[chan]
219  << " amp " << amp
220  << " channel is not used" );
221  }
222 
223  }
224 
225  int ncorr = 0;
227 
228  for (int k = 0; k < maxMOB; k++) {
229 
231  nchmin = ceil(m_minimumNumberOfTruncatedChannels * ngoodchan[k]);
232  if (nchmin < 2) nchmin = 2;
233  }
234 
235  if (nemptychan[k] >= nchmin) {
236  commonmode[k] /= nemptychan[k];
237  ++ncorr;
238 
239  ATH_MSG_VERBOSE( "ros " << ros
240  << " drawer " << std::setw(2) << drawer
241  << " mb " << k << " mean " << commonmode[k]
242  << " taken from " << nemptychan[k] << " channels"
243  << " nchgood " << ngoodchan[k]
244  << " nchmin " << nchmin );
245 
246  } else {
247  if (msgLvl(MSG::VERBOSE)) {
248  if (commonmode[k] != 0.0) {
249  msg(MSG::VERBOSE) << "ros " << ros
250  << " drawer " << std::setw(2) << drawer
251  << " mb " << k
252  << " mean is zero instead of " << commonmode[k] << " / " << nemptychan[k]
253  << " nchgood " << ngoodchan[k]
254  << " nchmin " << nchmin
255  << endmsg;
256  } else {
257  msg(MSG::VERBOSE) << "ros "
258  << ros << " drawer " << std::setw(2) << drawer
259  << " mb " << k
260  << " mean is zero - nothing to correct"
261  << " nchgood " << ngoodchan[k]
262  << " nchmin " << nchmin
263  << endmsg;
264  }
265  }
266  commonmode[k] = 0.0;
267  }
268  }
269 
270  if (ncorr == 0) continue; // nothing to correct
271 
272  // iterate over all channels in a collection again
273  for (TileRawChannel* rch : *coll) {
274  int chan = m_tileHWID->channel(rch->adc_HWID());
275  int gain = m_tileHWID->adc(rch->adc_HWID());
276 
277  // use only good channel and high gain - for them calib was set to non-zero value above
278  if (calib[chan] > 0.0 && gain == TileHWID::HIGHGAIN) {
279  // correct amplitude directly in channel
280  // (will change this to set() method once it is available in TileRawChannel)
281  int mob = chan/maxChannel;
282  if (undoOnlCalib)
283  rch->setAmplitude (rch->amplitude() - commonmode[mob] / calib[chan]);
284  else
285  rch->setAmplitude (rch->amplitude() - commonmode[mob]);
286  rch->setPedestal (rch->pedestal() + commonmode[mob]);
287  }
288  }
289  }
290 
291  return StatusCode::SUCCESS;
292 }
293 
294 // ============================================================================
295 // finalize
297  return StatusCode::SUCCESS;
298 }
299 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileRawChannelNoiseFilter::m_useGapCells
bool m_useGapCells
Definition: TileRawChannelNoiseFilter.h:89
TileRawChannelNoiseFilter::finalize
virtual StatusCode finalize() override
AlgTool finalize method.
Definition: TileRawChannelNoiseFilter.cxx:296
TileRawChannel.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TileRawChannelNoiseFilter::m_ADCmaskValueMinusEps
float m_ADCmaskValueMinusEps
indicates channels which were masked in background dataset
Definition: TileRawChannelNoiseFilter.h:94
TileRawChannelNoiseFilter::m_minimumNumberOfTruncatedChannels
float m_minimumNumberOfTruncatedChannels
Definition: TileRawChannelNoiseFilter.h:87
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:205
TileRawChannelNoiseFilter::m_sampleNoiseKey
SG::ReadCondHandleKey< TileSampleNoise > m_sampleNoiseKey
Name of TileSampleNoise in condition store.
Definition: TileRawChannelNoiseFilter.h:72
TileInfo.h
TileCalibUtils.h
TileSampleNoise::getHfn
float getHfn(unsigned int drawerIdx, unsigned int channel, unsigned int adc) const
Definition: TileSampleNoise.h:51
TileRawChannelUnit::OnlineADCcounts
@ OnlineADCcounts
Definition: TileRawChannelUnit.h:21
TileRawChannelNoiseFilter::m_tileInfo
const TileInfo * m_tileInfo
Definition: TileRawChannelNoiseFilter.h:93
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
HWIdentifier
Definition: HWIdentifier.h:13
TileHWID::HIGHGAIN
@ HIGHGAIN
Definition: TileHWID.h:73
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
Example_ReadSampleNoise.drawer
drawer
Definition: Example_ReadSampleNoise.py:39
ReadCondHandle.h
TileHWID::channel
int channel(const HWIdentifier &id) const
extract channel field from HW identifier
Definition: TileHWID.h:189
TileHWID::ros
int ros(const HWIdentifier &id) const
extract ros field from HW identifier
Definition: TileHWID.h:167
TileInfo::ADCmaskValue
int ADCmaskValue() const
Returns the overlay magic number that indicates channels which were masked in background dataset.
Definition: TileInfo.h:73
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:269
TileRawChannelContainer.h
TileDQstatus
Class that holds Data Quality fragment information and provides functions to extract the data quality...
Definition: TileDQstatus.h:49
TileRawChannelNoiseFilter::m_DQstatusKey
SG::ReadHandleKey< TileDQstatus > m_DQstatusKey
Definition: TileRawChannelNoiseFilter.h:82
TileHWID::adc
int adc(const HWIdentifier &id) const
extract adc field from HW identifier
Definition: TileHWID.h:193
TileHWID.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TileMutableDataContainer
Helper for holding non-const raw data prior to recording in SG.
Definition: TileMutableDataContainer.h:52
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TileRawChannelNoiseFilter::m_maxNoiseSigma
float m_maxNoiseSigma
Definition: TileRawChannelNoiseFilter.h:90
TileRawChannel
Definition: TileRawChannel.h:35
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
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
TileRawChannelUnit::UNIT
UNIT
Definition: TileRawChannelUnit.h:16
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
TileRawChannelNoiseFilter::m_emScaleKey
SG::ReadCondHandleKey< TileEMScale > m_emScaleKey
Name of TileEMScale in condition store.
Definition: TileRawChannelNoiseFilter.h:66
TileRawDataCollection::identify
ID identify() const
Definition: TileRawDataCollection.h:71
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
TileRawChannelNoiseFilter::process
virtual StatusCode process(TileMutableRawChannelContainer &rchCont, const EventContext &ctx) const override
process the coherent noise subtruction algorithm and correct TileRawChannel amplitudes
Definition: TileRawChannelNoiseFilter.cxx:79
TileHWID::drawer_id
HWIdentifier drawer_id(int frag) const
ROS HWIdentifer.
Definition: TileHWID.cxx:186
TileMutableDataContainer::indexFindPtr
Collection * indexFindPtr(IdentifierHash hash)
Look up a (non-const) collection via hash.
TileRawChannelNoiseFilter::m_truncationThresholdOnAbsEinSigma
float m_truncationThresholdOnAbsEinSigma
Definition: TileRawChannelNoiseFilter.h:86
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TileRawChannelCollection
Definition: TileRawChannelCollection.h:12
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
TileRawChannelNoiseFilter::m_useTwoGaussNoise
bool m_useTwoGaussNoise
Definition: TileRawChannelNoiseFilter.h:88
TileRawChannelNoiseFilter::m_infoName
std::string m_infoName
Definition: TileRawChannelNoiseFilter.h:92
perfmonmt-refit.units
string units
Definition: perfmonmt-refit.py:77
Example_ReadSampleNoise.ped
ped
Definition: Example_ReadSampleNoise.py:45
TileBadChannels::getAdcStatus
const TileBchStatus & getAdcStatus(const HWIdentifier adc_id) const
Return Tile ADC status.
Definition: TileBadChannels.cxx:24
PlotSFuncertainty.calib
calib
Definition: PlotSFuncertainty.py:110
TileRawChannelNoiseFilter.h
TileEMScale::undoOnlineChannelCalibration
float undoOnlineChannelCalibration(unsigned int drawerIdx, unsigned int channel, unsigned int adc, float amplitude, TileRawChannelUnit::UNIT onlUnit) const
Undo the calibration applied in ROD signal reconstruction.
Definition: TileEMScale.cxx:97
TileRawChannelNoiseFilter::initialize
virtual StatusCode initialize() override
AlgTool initialize method.
Definition: TileRawChannelNoiseFilter.cxx:45
TileMutableRawChannelContainer.h
Helper for holding non-const raw data prior to recording in SG.
TileHWID::drawer
int drawer(const HWIdentifier &id) const
extract drawer field from HW identifier
Definition: TileHWID.h:171
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
TileRawChannelNoiseFilter::m_tileHWID
const TileHWID * m_tileHWID
Pointer to TileHWID.
Definition: TileRawChannelNoiseFilter.h:61
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
TileRawChannelNoiseFilter::m_badChannelsKey
SG::ReadCondHandleKey< TileBadChannels > m_badChannelsKey
Name of TileBadChannels in condition store.
Definition: TileRawChannelNoiseFilter.h:78
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
TileRawChannelNoiseFilter::TileRawChannelNoiseFilter
TileRawChannelNoiseFilter(const std::string &type, const std::string &name, const IInterface *parent)
AlgTool like constructor.
Definition: TileRawChannelNoiseFilter.cxx:24
TileCalibUtils::getDrawerIdx
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
Definition: TileCalibUtils.cxx:60
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
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.
IdentifierHash
Definition: IdentifierHash.h:38
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
TileBchStatus::isBad
bool isBad() const
Definition: TileBchStatus.h:145
TileRawChannelUnit::ADCcounts
@ ADCcounts
Definition: TileRawChannelUnit.h:17
fitman.k
k
Definition: fitman.py:528