ATLAS Offline Software
TileRawChannelMaker.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 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 {
31  declareProperty("FitOverflow", m_fitOverflow, "Fit or not overflows");
32  declareProperty("TileInfoName", m_infoName = "TileInfo");
33 
36  m_overflowReplaceChi2Cut = 40000.0;
37 }
38 
43 }
44 
49 
50  ATH_MSG_DEBUG( "starting to retrieve list " << m_tileRawChannelBuilderList);
52 
54 
56  ATH_MSG_INFO( "TileRawChannelBuilder list is empty - will not do anything");
57  m_fitOverflow = false;
58  }
59 
60  if (m_fitOverflow) {
62  } else {
64  }
65 
67 
68  ATH_MSG_INFO( "Initialization completed successfully");
69 
70  // TileInfo
72  m_ADCmaxMinusEps = m_tileInfo->ADCmax() - 0.01; // indicates channels which were masked in background dataset
73 
74  return StatusCode::SUCCESS;
75 }
76 
81 
82  const EventContext& ctx = Gaudi::Hive::currentContext();
83 
84  // get named TileDigitsContaner from TES
86 
87  if (!digitsContaner.isValid()) {
88  ATH_MSG_WARNING( "Can't retrieve TileDigitsContainer '"
89  << m_digitsContainerKey.key() << "' from TDS" );
90 
91  return StatusCode::SUCCESS;
92  }
93 
94  ATH_MSG_DEBUG( "Got TileDigitsContainer '" << m_digitsContainerKey.key() << "'" );
95 
96  // create RawChannel Containers for all sub-algs
97  for (ToolHandle<TileRawChannelBuilder>& rawChannelBuilder : m_tileRawChannelBuilderList) {
98  ATH_CHECK( rawChannelBuilder->createContainer(ctx) );
99  rawChannelBuilder->resetDrawer();
100  }
101 
102  // clean memory about overflows
103  if (m_fitOverflow) {
104  for (ToolHandle<TileRawChannelBuilder>& rawChannelBuilder : m_tileRawChannelBuilderList) {
105  rawChannelBuilder->resetOverflows();
106  }
107  }
108 
109  // Iterate over all collections (drawers) with digits
110  for (const TileDigitsCollection* digitsCollection : *digitsContaner) {
111 
112  // Iterate over all sub-algs
113  for (ToolHandle<TileRawChannelBuilder>& rawChannelBuilder : m_tileRawChannelBuilderList) {
114  // reconstruct all channels in one drawer
115  ATH_CHECK( rawChannelBuilder->build(digitsCollection, ctx) );
116  }
117 
118  }
119 
120  if (m_fitOverflow
121  && !(*m_tileRawChannelBuilderList.begin())->getOverflowedChannels().empty()) {
123  }
124 
125  // commit RawChannel Containers for all sub-algs
126  for (ToolHandle<TileRawChannelBuilder>& rawChannelBuilder : m_tileRawChannelBuilderList) {
127  ATH_CHECK( rawChannelBuilder->commitContainer(ctx) );
128  }
129 
130  ATH_MSG_DEBUG( "execute completed successfully" );
131 
132  return StatusCode::SUCCESS;
133 }
134 
139 
140  ATH_MSG_INFO(" finalize completed successfully" );
141 
142  return StatusCode::SUCCESS;
143 }
144 
145 void TileRawChannelMaker::fitOverflowedChannels(const EventContext& ctx) {
146 
147  for (ToolHandle<TileRawChannelBuilder> rawChannelBuilder : m_tileRawChannelBuilderList) {
148 
149  Overflows_t overflows = rawChannelBuilder->getOverflowedChannels();
150 
151  for (std::pair<TileRawChannel*, const TileDigits*>& overflow : overflows) {
152 
153  TileRawChannel* rwCh = overflow.first;
154  const TileDigits* pDigits = overflow.second;
155 
156  TileRawChannel* fittedRwCh = m_tileRawChannelBuilderFitOverflow->rawChannel(pDigits, ctx);
157 
158  bool fitOK = ( ( fabs(fittedRwCh->time()) < m_overflowReplaceTimeCut ) &&
159  ( fittedRwCh->pedestal() < m_overflowReplacePedestalCut ) &&
160  ( fittedRwCh->quality() < m_overflowReplaceChi2Cut ) );
161 
162  int nSatSamples = 0;
163  std::vector<double> digits = pDigits->get_digits();
164  for (size_t ii = 0; ii<digits.size(); ii++) {
165  if (digits[ii] > m_ADCmaxMinusEps) nSatSamples++;
166  }
167 
168  // NOTE: Optimal filtering is always run first and the fit method is used just in cases when there is an overflow.
169  // NOTE: Mathematically, a maximum pedestal range is [-460.607488, 4556.603392] and it happens for the phase 0.1 ns.
170  // Therefore, we use the following intervals:
171  // - if optimal filtering is used: (-500, 4600)
172  // - if fit method is used: (5000, 9095)
173  // NOTE: Overlay magic number is 4800.
174 
175  if ( !fitOK || nSatSamples > 2) {
176  // If the fit is bad, reset the energy.
177  //The same if the number of saturated samples is 3 (or bigger)
178 
179  //If we reject pulse, the quality must be above 9999 in order to mask the
180  // channel. So we set it at 10000 * nSatSamples. But if the fit completely fails,
181  // the quality is 100000, and we can keep this info in quality as well.
182  float quality = 10000. * ( (nSatSamples) ? nSatSamples : 9);
183  if (fittedRwCh->quality() > 99999.9) quality += 100000.;
184  rwCh->insert(0.0, 0.0, quality);
185 
186  // 20000 - Indicates overflow, 9400 - indicates bad fit or >2 saturations.
187  // 30000 - Indicates overflow + underflow, 9400 - indicates bad fit or >2 saturations.
188  float pedestal = (rwCh->pedestal() < 29500.) ? (29400.)
189  : (39400.);
190  ATH_MSG_DEBUG("Overflow " << (std::string)(*rwCh) <<
191  " change ped from " << rwCh->pedestal() << " to " << pedestal);
192  rwCh->setPedestal(pedestal);
193  } else {
194  //If the fit is OK replace
195 
196  //The range of the quality factor is very different in the fit (0-100k)
197  //than in the OF (0-255). So we rescale by a factor of 400.
198  rwCh->insert(fittedRwCh->amplitude(),
199  fittedRwCh->time(),
200  fittedRwCh->quality()*(1./400.));
201  // 20000 - Indicates overflow, 5000 - indicates fitted
202  // 30000 - Indicates overflow + underflow, 5000 - indicates fitted.
203  float pedestal = (rwCh->pedestal() < 29500.) ? fittedRwCh->pedestal() + 25000.
204  : fittedRwCh->pedestal() + 35000.;
205  ATH_MSG_DEBUG("Overflow " << (std::string)(*rwCh) <<
206  " change ped from " << rwCh->pedestal() << " to " << pedestal);
207  rwCh->setPedestal(pedestal);
208  }
209 
210  }
211  }
212 
213 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileRawChannelMaker::fitOverflowedChannels
void fitOverflowedChannels(const EventContext &ctx)
Definition: TileRawChannelMaker.cxx:145
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:80
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:42
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:48
TileRawChannelMaker::finalize
virtual StatusCode finalize() override
Finalize.
Definition: TileRawChannelMaker.cxx:138
TileDigitsCollection
Definition: TileDigitsCollection.h:18
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
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