ATLAS Offline Software
TileRawChannelMaker.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 // Tile includes
8 
9 // Atlas includes
11 // access all RawChannels inside container
13 #include "StoreGate/ReadHandle.h"
14 
15 // Gaudi includes
16 
17 #include <algorithm>
18 #include <set>
19 
26  ISvcLocator* pSvcLocator)
27  : AthAlgorithm(name, pSvcLocator)
28  , m_fitOverflow(false)
29  , m_tileInfo(0)
30  , m_ADCmaxMinusEps(0)
31 {
32  declareProperty("FitOverflow", m_fitOverflow, "Fit or not overflows");
33  declareProperty("TileInfoName", m_infoName = "TileInfo");
34 
37  m_overflowReplaceChi2Cut = 40000.0;
38 }
39 
44 }
45 
50 
51  ATH_MSG_DEBUG( "starting to retrieve list " << m_tileRawChannelBuilderList);
53 
55 
57  ATH_MSG_INFO( "TileRawChannelBuilder list is empty - will not do anything");
58  m_fitOverflow = false;
59  }
60 
61  if (m_fitOverflow) {
63  } else {
65  }
66 
68 
69  ATH_MSG_INFO( "Initialization completed successfully");
70 
71  // TileInfo
73  m_ADCmaxMinusEps = m_tileInfo->ADCmax() - 0.01; // indicates channels which were masked in background dataset
74 
75  return StatusCode::SUCCESS;
76 }
77 
82 
83  const EventContext& ctx = Gaudi::Hive::currentContext();
84 
85  // get named TileDigitsContaner from TES
87 
88  if (!digitsContaner.isValid()) {
89  ATH_MSG_WARNING( "Can't retrieve TileDigitsContainer '"
90  << m_digitsContainerKey.key() << "' from TDS" );
91 
92  return StatusCode::SUCCESS;
93  }
94 
95  ATH_MSG_DEBUG( "Got TileDigitsContainer '" << m_digitsContainerKey.key() << "'" );
96 
97  // create RawChannel Containers for all sub-algs
98  for (ToolHandle<TileRawChannelBuilder>& rawChannelBuilder : m_tileRawChannelBuilderList) {
99  ATH_CHECK( rawChannelBuilder->createContainer(ctx) );
100  rawChannelBuilder->resetDrawer();
101  }
102 
103  // clean memory about overflows
104  if (m_fitOverflow) {
105  for (ToolHandle<TileRawChannelBuilder>& rawChannelBuilder : m_tileRawChannelBuilderList) {
106  rawChannelBuilder->resetOverflows();
107  }
108  }
109 
110  // Iterate over all collections (drawers) with digits
111  for (const TileDigitsCollection* digitsCollection : *digitsContaner) {
112 
113  // Iterate over all sub-algs
114  for (ToolHandle<TileRawChannelBuilder>& rawChannelBuilder : m_tileRawChannelBuilderList) {
115  // reconstruct all channels in one drawer
116  ATH_CHECK( rawChannelBuilder->build(digitsCollection, ctx) );
117  }
118 
119  }
120 
121  if (m_fitOverflow
122  && !(*m_tileRawChannelBuilderList.begin())->getOverflowedChannels().empty()) {
124  }
125 
126  // commit RawChannel Containers for all sub-algs
127  for (ToolHandle<TileRawChannelBuilder>& rawChannelBuilder : m_tileRawChannelBuilderList) {
128  ATH_CHECK( rawChannelBuilder->commitContainer(ctx) );
129  }
130 
131  ATH_MSG_DEBUG( "execute completed successfully" );
132 
133  return StatusCode::SUCCESS;
134 }
135 
140 
141  ATH_MSG_INFO(" finalize completed successfully" );
142 
143  return StatusCode::SUCCESS;
144 }
145 
146 void TileRawChannelMaker::fitOverflowedChannels(const EventContext& ctx) {
147 
148  for (ToolHandle<TileRawChannelBuilder> rawChannelBuilder : m_tileRawChannelBuilderList) {
149 
150  Overflows_t overflows = rawChannelBuilder->getOverflowedChannels();
151 
152  for (std::pair<TileRawChannel*, const TileDigits*>& overflow : overflows) {
153 
154  TileRawChannel* rwCh = overflow.first;
155  const TileDigits* pDigits = overflow.second;
156 
157  TileRawChannel* fittedRwCh = m_tileRawChannelBuilderFitOverflow->rawChannel(pDigits, ctx);
158 
159  bool fitOK = ( ( fabs(fittedRwCh->time()) < m_overflowReplaceTimeCut ) &&
160  ( fittedRwCh->pedestal() < m_overflowReplacePedestalCut ) &&
161  ( fittedRwCh->quality() < m_overflowReplaceChi2Cut ) );
162 
163  int nSatSamples = 0;
164  std::vector<double> digits = pDigits->get_digits();
165  for (size_t ii = 0; ii<digits.size(); ii++) {
166  if (digits[ii] > m_ADCmaxMinusEps) nSatSamples++;
167  }
168 
169  // NOTE: Optimal filtering is always run first and the fit method is used just in cases when there is an overflow.
170  // NOTE: Mathematically, a maximum pedestal range is [-460.607488, 4556.603392] and it happens for the phase 0.1 ns.
171  // Therefore, we use the following intervals:
172  // - if optimal filtering is used: (-500, 4600)
173  // - if fit method is used: (5000, 9095)
174  // NOTE: Overlay magic number is 4800.
175 
176  if ( !fitOK || nSatSamples > 2) {
177  // If the fit is bad, reset the energy.
178  //The same if the number of saturated samples is 3 (or bigger)
179 
180  //If we reject pulse, the quality must be above 9999 in order to mask the
181  // channel. So we set it at 10000 * nSatSamples. But if the fit completely fails,
182  // the quality is 100000, and we can keep this info in quality as well.
183  float quality = 10000. * ( (nSatSamples) ? nSatSamples : 9);
184  if (fittedRwCh->quality() > 99999.9) quality += 100000.;
185  rwCh->insert(0.0, 0.0, quality);
186 
187  // 20000 - Indicates overflow, 9400 - indicates bad fit or >2 saturations.
188  // 30000 - Indicates overflow + underflow, 9400 - indicates bad fit or >2 saturations.
189  float pedestal = (rwCh->pedestal() < 29500.) ? (29400.)
190  : (39400.);
191  ATH_MSG_DEBUG("Overflow " << (std::string)(*rwCh) <<
192  " change ped from " << rwCh->pedestal() << " to " << pedestal);
193  rwCh->setPedestal(pedestal);
194  } else {
195  //If the fit is OK replace
196 
197  //The range of the quality factor is very different in the fit (0-100k)
198  //than in the OF (0-255). So we rescale by a factor of 400.
199  rwCh->insert(fittedRwCh->amplitude(),
200  fittedRwCh->time(),
201  fittedRwCh->quality()*(1./400.));
202  // 20000 - Indicates overflow, 5000 - indicates fitted
203  // 30000 - Indicates overflow + underflow, 5000 - indicates fitted.
204  float pedestal = (rwCh->pedestal() < 29500.) ? fittedRwCh->pedestal() + 25000.
205  : fittedRwCh->pedestal() + 35000.;
206  ATH_MSG_DEBUG("Overflow " << (std::string)(*rwCh) <<
207  " change ped from " << rwCh->pedestal() << " to " << pedestal);
208  rwCh->setPedestal(pedestal);
209  }
210 
211  }
212  }
213 
214 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileRawChannelMaker::fitOverflowedChannels
void fitOverflowedChannels(const EventContext &ctx)
Definition: TileRawChannelMaker.cxx:146
TileRawChannelMaker::m_overflowReplacePedestalCut
float m_overflowReplacePedestalCut
Definition: TileRawChannelMaker.h:80
TileRawChannel::insert
int insert(float amplitude, float time, float quality)
Definition: TileRawChannel.cxx:80
TileRawChannelMaker::m_overflowReplaceChi2Cut
float m_overflowReplaceChi2Cut
Definition: TileRawChannelMaker.h:81
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TileRawChannelMaker::m_fitOverflow
bool m_fitOverflow
Definition: TileRawChannelMaker.h:75
TileRawChannel::pedestal
float pedestal(void) const
Definition: TileRawChannel.h:106
TileInfo.h
TileRawChannelMaker::execute
virtual StatusCode execute() override
Execute.
Definition: TileRawChannelMaker.cxx:81
TileRawChannel::setPedestal
void setPedestal(float ped)
Definition: TileRawChannel.h:94
TileRawChannelMaker::m_tileRawChannelBuilderList
ToolHandleArray< TileRawChannelBuilder > m_tileRawChannelBuilderList
Vector of builder algtools.
Definition: TileRawChannelMaker.h:72
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
TileRawChannelMaker::~TileRawChannelMaker
virtual ~TileRawChannelMaker()
Destructor.
Definition: TileRawChannelMaker.cxx:43
TileRawChannel::time
float time(int ind=0) const
Definition: TileRawChannel.h:103
Overflows_t
std::vector< std::pair< TileRawChannel *, const TileDigits * > > Overflows_t
Definition: TileRawChannelBuilder.h:55
TileRawChannelMaker::TileRawChannelMaker
TileRawChannelMaker(const std::string &name, ISvcLocator *pSvcLocator)
Standard constructor.
Definition: TileRawChannelMaker.cxx:25
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
TileRawChannel::quality
float quality(int ind=0) const
Definition: TileRawChannel.h:105
TileRawChannelMaker::m_tileRawChannelBuilderFitOverflow
ToolHandle< TileRawChannelBuilder > m_tileRawChannelBuilderFitOverflow
Definition: TileRawChannelMaker.h:76
TileDigits::get_digits
std::vector< double > get_digits(void) const
Definition: TileDigits.h:65
TileRawChannel::amplitude
float amplitude(int ind=0) const
Definition: TileRawChannel.h:101
TileRawChannelMaker::m_infoName
std::string m_infoName
Definition: TileRawChannelMaker.h:84
TileRawChannelMaker::m_overflowReplaceTimeCut
float m_overflowReplaceTimeCut
Definition: TileRawChannelMaker.h:79
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
TileRawChannel
Definition: TileRawChannel.h:35
TileRawChannelMaker::m_tileInfo
const TileInfo * m_tileInfo
Definition: TileRawChannelMaker.h:85
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TileRawChannelMaker::initialize
virtual StatusCode initialize() override
Initialize algorithm.
Definition: TileRawChannelMaker.cxx:49
TileRawChannelMaker::finalize
virtual StatusCode finalize() override
Finalize.
Definition: TileRawChannelMaker.cxx:139
TileDigitsCollection
Definition: TileDigitsCollection.h:18
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.
TileRawChannelMaker::m_ADCmaxMinusEps
float m_ADCmaxMinusEps
Definition: TileRawChannelMaker.h:86
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SelectAllObject.h
ReadHandle.h
Handle class for reading from StoreGate.
TileRawChannelMaker.h
TileInfo::ADCmax
int ADCmax() const
Returns the maximum ADC output (10 bits --> 1023)
Definition: TileInfo.h:71
TileRawChannelMaker::m_digitsContainerKey
SG::ReadHandleKey< TileDigitsContainer > m_digitsContainerKey
Definition: TileRawChannelMaker.h:60