ATLAS Offline Software
LArRawChannelBuilderToolAverage.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 
7 #include "GaudiKernel/MsgStream.h"
8 
9 #include "LArRawEvent/LArDigit.h"
10 #include "CLHEP/Units/SystemOfUnits.h"
11 
13 #include "Identifier/Identifier.h"
15 #include <cmath>
16 
17 using CLHEP::nanosecond;
18 using CLHEP::picosecond;
19 
20 #define MAXINT 2147483000
21 #define MAXINT2 -2147483000
22 
23 
24 
26  const std::string& name,
27  const IInterface* parent):
29  m_emId(nullptr),
30  m_fcalId(nullptr),
31  m_hecId(nullptr),
32  m_onlineHelper(nullptr)
33 {
34  m_helper = new LArRawChannelBuilderStatistics( 1, // number of possible errors
35  0x01); // bit pattern special for this tool,
36  // to be stored in "uint16_t provenance"
37  m_helper->setErrorString(0, "no errors");
38 
39  declareProperty("AverageSamplesEM",m_averageSamplesEM=5);
40  declareProperty("AverageSamplesHEC",m_averageSamplesHEC=5);
41  declareProperty("AverageSamplesFCAL",m_averageSamplesFCAL=3);
42  declareProperty("AverageScaleEM",m_averageScaleEM=2.6);
43  declareProperty("AverageScaleHEC",m_averageScaleHEC=2.6);
44  declareProperty("AverageScaleFCAL",m_averageScaleFCAL=1.8);
45 
46  declareProperty("NScan", m_nScan=32);
47 }
48 
50 {
51  const CaloCell_ID* idHelper = nullptr;
52  ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
53  m_emId=idHelper->em_idHelper();
54  m_fcalId=idHelper->fcal_idHelper();
55  m_hecId=idHelper->hec_idHelper();
56 
57 
58  ATH_CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
59  return StatusCode::SUCCESS;
60 }
61 
63  float pedestal,
64  const std::vector<float>& ramps,
65  MsgStream* /* plog */ )
66 {
68  //int nMin = 0;
69  unsigned int nAverage = 1;
70  float myScale = 1;
71 
73  nAverage = m_averageSamplesEM;
74  myScale = m_averageScaleEM;
75  }
76  else if (m_onlineHelper->isFCALchannel(chid) ) {
77  nAverage = m_averageSamplesFCAL;
78  myScale = m_averageScaleFCAL;
79  }
80  else if (m_onlineHelper->isHECchannel(chid) ) {
81  nAverage = m_averageSamplesHEC;
82  myScale = m_averageScaleHEC;
83  }
84 
85  // look for maximum of all possible windows of size nAverage
86  long sum=0;
87  unsigned nSummedSamples=0;
88  for( unsigned int i=m_parent->curr_shiftTimeSamples;
89  i<(m_parent->curr_shiftTimeSamples+nAverage) &&
90  i<m_parent->curr_nsamples; i++,nSummedSamples++ )
91  sum += digit->samples()[i];
92 
93  long max=sum;
94  unsigned int maxsample=m_parent->curr_shiftTimeSamples;
95 
96  unsigned int nmax = m_parent->curr_shiftTimeSamples+1+m_nScan;
97  if(nmax>m_parent->curr_nsamples-nAverage+1)
98  nmax = m_parent->curr_nsamples-nAverage+1 ;
99 
100  for( unsigned int i=m_parent->curr_shiftTimeSamples+1;
101  i<nmax; i++ )
102  {
103  sum += digit->samples()[i+nAverage-1] - digit->samples()[i-1];
104  if(sum>max)
105  {
106  max=sum;
107  maxsample=i;
108  }
109  }
110 
111  float ADCPeak = (max - nSummedSamples*pedestal)/myScale;
112  float power=1;
113  float energy=0;
114  for( unsigned int i=0; i<ramps.size(); i++)
115  {
116  energy += ramps[i] * power;
117  power *= ADCPeak;
118  }
119 
120  // LArRawChannel has a non-standard unit of pico-second.
121  int time=int((25.0 * nanosecond /picosecond) * maxsample );
122  uint16_t iquality=0;
123 
124  // store which tool created this channel
125  uint16_t iprovenance=0;
126  iprovenance |= m_parent->qualityBitPattern;
127  iprovenance |= m_helper->returnBitPattern();
128  iprovenance = iprovenance & 0x3FFF;
129 
130  const float fMAXINT = static_cast<float>(MAXINT);
131  const float fMAXINT2 = static_cast<float>(MAXINT2);
132 
133  if (time>MAXINT) time=MAXINT;
134  if (time<MAXINT2) time=MAXINT2;
135 
136  if (energy>fMAXINT) energy=fMAXINT;
137  if (energy<fMAXINT2) energy=fMAXINT2;
138 
139 
140  // Suppress false positive seen with gcc.
141 #if __GNUC__ >= 11 && __GNUC__ <= 13
142 # pragma GCC diagnostic push
143 # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
144 #endif
145  (this->*m_buildIt)((int)(floor(energy+0.5)),time,iquality,iprovenance,digit);
146 #if __GNUC__ >= 11 && __GNUC__ <= 13
147 # pragma GCC diagnostic pop
148 #endif
149 
151 
152  return true;
153 }
154 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArRawChannelBuilderToolAverage::m_emId
const LArEM_ID * m_emId
Definition: LArRawChannelBuilderToolAverage.h:46
LArRawChannelBuilderToolAverage::m_averageSamplesHEC
int m_averageSamplesHEC
Definition: LArRawChannelBuilderToolAverage.h:42
max
#define max(a, b)
Definition: cfImp.cxx:41
python.SystemOfUnits.nanosecond
int nanosecond
Definition: SystemOfUnits.py:119
CaloCell_ID::em_idHelper
const LArEM_ID * em_idHelper() const
access to EM idHelper
Definition: CaloCell_ID.h:63
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
LArRawChannelBuilderToolAverage::m_averageScaleFCAL
float m_averageScaleFCAL
Definition: LArRawChannelBuilderToolAverage.h:43
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArRawChannelBuilderToolAverage::m_averageScaleHEC
float m_averageScaleHEC
Definition: LArRawChannelBuilderToolAverage.h:43
LArRawChannelBuilderToolAverage::m_averageSamplesEM
int m_averageSamplesEM
Definition: LArRawChannelBuilderToolAverage.h:42
LArRawChannelBuilderStatistics::setErrorString
void setErrorString(unsigned int nerr, const std::string &s)
Definition: LArRawChannelBuilderStatistics.cxx:69
MAXINT2
#define MAXINT2
Definition: LArRawChannelBuilderToolAverage.cxx:21
checkRpcDigits.digit
digit
Definition: checkRpcDigits.py:186
LArRawChannelBuilderStatistics
Returns various counters from the LArRawChannel building.
Definition: LArRawChannelBuilderStatistics.h:21
HWIdentifier
Definition: HWIdentifier.h:13
LArRawChannelBuilderStatistics::incrementErrorCount
void incrementErrorCount(unsigned int nerr)
Definition: LArRawChannelBuilderStatistics.cxx:34
CaloCell_ID.h
CaloCell_ID::hec_idHelper
const LArHEC_ID * hec_idHelper() const
access to HEC idHelper
Definition: CaloCell_ID.h:69
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
LArRawChannelBuilderParams::curr_shiftTimeSamples
int curr_shiftTimeSamples
Definition: LArRawChannelBuilderParams.h:31
LArOnlineID_Base::isFCALchannel
bool isFCALchannel(const HWIdentifier id) const
Definition: LArOnlineID_Base.cxx:1657
LArRawChannelBuilderToolAverage::m_fcalId
const LArFCAL_ID * m_fcalId
Definition: LArRawChannelBuilderToolAverage.h:47
LArOnlineID::isEMECchannel
bool isEMECchannel(const HWIdentifier id) const override final
Definition: LArOnlineID.cxx:774
LArDigit.h
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
LArDigit
Liquid Argon digit base class.
Definition: LArDigit.h:25
lumiFormat.i
int i
Definition: lumiFormat.py:92
LArRawChannelBuilderToolBase::energy
int energy()
Definition: LArRawChannelBuilderToolBase.h:46
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
test_pyathena.parent
parent
Definition: test_pyathena.py:15
LArRawChannelBuilderToolBase
Base tool to make the interface with the driver.
Definition: LArRawChannelBuilderToolBase.h:33
LArRawChannelBuilderToolAverage::m_nScan
unsigned int m_nScan
Definition: LArRawChannelBuilderToolAverage.h:44
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
LArRawChannelBuilderToolBaseClass::m_helper
LArRawChannelBuilderStatistics * m_helper
Definition: LArRawChannelBuilderToolBaseClass.h:82
LArRawChannelBuilderToolAverage::m_onlineHelper
const LArOnlineID * m_onlineHelper
Definition: LArRawChannelBuilderToolAverage.h:50
MAXINT
#define MAXINT
Definition: LArRawChannelBuilderToolAverage.cxx:20
LArRawChannelBuilderToolBase::m_buildIt
void(LArRawChannelBuilderToolBase::* m_buildIt)(int energy, int time, uint16_t quality, uint16_t provenance, const LArDigit *digit)
Definition: LArRawChannelBuilderToolBase.h:57
LArRawChannelBuilderToolAverage::m_hecId
const LArHEC_ID * m_hecId
Definition: LArRawChannelBuilderToolAverage.h:48
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArRawChannelBuilderToolAverage::m_averageScaleEM
float m_averageScaleEM
Definition: LArRawChannelBuilderToolAverage.h:43
LArRawChannelBuilderToolAverage::LArRawChannelBuilderToolAverage
LArRawChannelBuilderToolAverage(const std::string &type, const std::string &name, const IInterface *parent)
Definition: LArRawChannelBuilderToolAverage.cxx:25
LArOnlineID_Base::isEMBchannel
bool isEMBchannel(const HWIdentifier id) const
Definition: LArOnlineID_Base.cxx:1652
LArRawChannelBuilderToolAverage::initTool
StatusCode initTool()
Definition: LArRawChannelBuilderToolAverage.cxx:49
LArRawChannelBuilderToolAverage::buildRawChannel
bool buildRawChannel(const LArDigit *digit, float pedestal, const std::vector< float > &ramps, MsgStream *pLog)
Definition: LArRawChannelBuilderToolAverage.cxx:62
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
LArRawChannelBuilderToolAverage.h
LArRawChannelBuilderToolAverage::m_averageSamplesFCAL
int m_averageSamplesFCAL
Definition: LArRawChannelBuilderToolAverage.h:42
LArOnlineID::isHECchannel
bool isHECchannel(const HWIdentifier id) const override final
Definition: LArOnlineID.cxx:734
LArRawChannelBuilderParams::curr_nsamples
unsigned int curr_nsamples
Definition: LArRawChannelBuilderParams.h:30
LArRawChannelBuilderToolBase::time
int time()
Definition: LArRawChannelBuilderToolBase.h:47
LArRawChannelBuilderStatistics::returnBitPattern
unsigned int returnBitPattern() const
Definition: LArRawChannelBuilderStatistics.cxx:85
LArRawChannelBuilderParams::curr_chid
HWIdentifier curr_chid
Definition: LArRawChannelBuilderParams.h:24
LArRawChannelBuilderParams::qualityBitPattern
unsigned int qualityBitPattern
Definition: LArRawChannelBuilderParams.h:34
LArRawChannelBuilderToolBaseClass::m_parent
LArRawChannelBuilderParams * m_parent
Definition: LArRawChannelBuilderToolBaseClass.h:80
nmax
const int nmax(200)
python.SystemOfUnits.picosecond
int picosecond
Definition: SystemOfUnits.py:123
CaloCell_ID::fcal_idHelper
const LArFCAL_ID * fcal_idHelper() const
access to FCAL idHelper
Definition: CaloCell_ID.h:75
LArOnlineID.h