ATLAS Offline Software
LArRawChannelBuilderToolCubic.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 
10 #include "Identifier/Identifier.h"
11 #include "LArRawEvent/LArDigit.h"
12 
13 #include "CLHEP/Units/SystemOfUnits.h"
14 #include <cmath>
15 
16 using CLHEP::ns;
17 using CLHEP::nanosecond;
18 using CLHEP::picosecond;
19 
20 #define MAXINT 2147483000
21 #define MAXINT2 -2147483000
22 
23 
25  const std::string& name,
26  const IInterface* parent):
28  m_fcalId(nullptr)
29 {
30  m_helper = new LArRawChannelBuilderStatistics( 3, // number of possible errors
31  0x04); // bit pattern special for this tool,
32  // to be stored in "uint16_t provenance"
33  m_helper->setErrorString(0, "no errors");
34  m_helper->setErrorString(1, "Fit failed");
35  m_helper->setErrorString(2, "is FCAL");
36 
37  declareProperty("UseMaxSample", m_useMaxSample = false);
38  declareProperty("minADCforCubic", m_minADC=30);
39 
40 }
41 
43 {
44  const CaloCell_ID* idHelper = nullptr;
45  ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
46  m_fcalId=idHelper->fcal_idHelper();
47 
48  return StatusCode::SUCCESS;
49 }
50 
52  float pedestal,
53  const std::vector<float>& ramps,
54  MsgStream* pLog)
55 {
56  float ADCPeak=0;
57 
58  bool CubicFailed=false;
59 
60  float time=0;
61 
62  // use fixed sample
63  unsigned int maxSample = m_parent->curr_shiftTimeSamples+2 ;
64 
65  // use max Sample
66  if(m_useMaxSample)
67  maxSample = m_parent->curr_maxsample ;
68 
69 
70  if( maxSample>= digit->samples().size() )
71  return false;
72 
73  // apply min ADC cut.
74  if( (digit->samples()[maxSample]-pedestal) < m_minADC )
75  return false;
76 
77 
78  // FCAL needs special treatment
80  {
81  if(bool(pLog))
82  (*pLog) << MSG::VERBOSE << "FCAL using special reconstuction !" << endmsg;
83 
84  unsigned int it0;
85 
86  const float invT[3][3]
87  = { { 1, 0, 0 },
88  { -1.5, 2, -0.5 },
89  { 0.5, -1, 0.5 } };
90 
91  // peak slice very early
92  if ( (maxSample) <= 1 )
93  {
94  it0 = 1;
95  } else if ( (maxSample) >= (m_parent->curr_nsamples) )
96  {
97  // peak is late
98  it0 = (m_parent->curr_nsamples) - 3;
99  } else {
100  // peak in safe region
101  it0 = (maxSample) - 1;
102  }
103 
104  // Quadratic interpolation using
105  // 3 samples to be used start at 0 <= t0 <= nsamples-3
106  float A[3] = {0, 0, 0};
107  float dtmax = 0.0;
108  // S = TA -> A = inv(T)S
109  for (int ia = 0; ia < 3; ia++)
110  for (int it = 0; it < 3; it++)
111  A[ia] += invT[ia][it] * (digit->samples()[it0+it] - (pedestal));
112 
113  // fit parameters
114  if ( not ( CubicFailed = ( A[2] == 0 ) ) ) {
115  dtmax = -1.0 * A[1] / 2.0 / A[2];
116  if ( ! ( CubicFailed = ( dtmax < 0 || dtmax > 2 ) ) ) {
117  //time = (float(it0) + dtmax) * 25.0 * nanosecond; // nsec
118  time=dtmax*25.0*ns;
119  for(int ia = 0; ia < 3; ia++)
120  ADCPeak += A[ia] * pow(dtmax, ia);
121  }
122  }
123  }else{
124 
125  unsigned int it0;
126  const float invT[4][4]
127  = { { 1, 0, 0, 0},
128  { -1.83333, 3, -1.5, 0.333333},
129  { 1, -2.5, 2, -0.5},
130  {-0.166666, 0.5, -0.5, 0.166666} };
131 
132  // peak slice very early
133  if ( (maxSample) <= 1 )
134  {
135  it0 = 1;
136  } else if ( (maxSample) >= (m_parent->curr_nsamples) - 2 )
137  { // peak is late
138  it0 = (m_parent->curr_nsamples) - 4;
139  } else { // peak in safe region
140  it0 = ( digit->samples()[(maxSample)-2] > digit->samples()[(maxSample)+2] )
141  ? (maxSample) - 2
142  : (maxSample) - 1;
143  }
144 
145  // 4 samples to be used start at 0 <= t0 <= nsamples-4
146  float A[4] = {0, 0, 0, 0};
147  float dtmax = 0.0;
148  float disc;
149  // S = TA -> A = inv(T)S
150  for (int ia = 0; ia < 4; ia++)
151  for (int it = 0; it < 4; it++)
152  A[ia] += invT[ia][it] * (digit->samples()[it0+it] - (pedestal));
153 
154  // fit parameters
155  disc = A[2]*A[2] - 3*A[1]*A[3];
156  if ( ! ( CubicFailed = ( disc < 0 || A[3] == 0 ) ) ) {
157  dtmax = (-A[2]-std::sqrt(disc))/(A[3]*3);
158  if ( ! ( CubicFailed = ( dtmax < 0 || dtmax > 3 ) ) ) {
159  time = (float(it0) + dtmax) * (25.0 * nanosecond/picosecond); // nsec
160  for(int ia = 0; ia < 4; ia++)
161  ADCPeak += A[ia] * pow(dtmax, ia);
162  }
163  }
164 
165  if(CubicFailed)
166  {
168  return false;
169  }
170  }
171 
172  float power=1;
173  float energy=0;
174  for( unsigned int i=0; i<ramps.size(); i++)
175  {
176  energy += ramps[i] * power;
177  power *= ADCPeak;
178  }
179 
180  // store which tools created this channel
181  uint16_t iquality=0;
182  uint16_t iprovenance=0;
183 
184  iprovenance |= m_parent->qualityBitPattern;
185  iprovenance |= m_helper->returnBitPattern();
186  iprovenance = iprovenance & 0x3FFF;
187 
188  const float fMAXINT = static_cast<float>(MAXINT);
189  const float fMAXINT2 = static_cast<float>(MAXINT2);
190 
191  if (time>fMAXINT) time=fMAXINT;
192  if (time<fMAXINT2) time=fMAXINT2;
193 
194  if (energy>fMAXINT) energy=fMAXINT;
195  if (energy<fMAXINT2) energy=fMAXINT2;
196 
197 
198  // Suppress false positive seen wth gcc.
199 #if __GNUC__ >= 11 && __GNUC__ <= 13
200 # pragma GCC diagnostic push
201 # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
202 #endif
203  (this->*m_buildIt)((int)(floor(energy+0.5)),(int)floor(time+0.5),iquality,iprovenance,digit);
204 #if __GNUC__ >= 11 && __GNUC__ <= 13
205 # pragma GCC diagnostic pop
206 #endif
207 
209 
210  return true;
211 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
python.SystemOfUnits.nanosecond
int nanosecond
Definition: SystemOfUnits.py:119
AtlasDetectorID::is_lar_fcal
bool is_lar_fcal(Identifier id) const
Definition: AtlasDetectorID.h:839
LArRawChannelBuilderToolCubic.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
skel.it
it
Definition: skel.GENtoEVGEN.py:423
LArRawChannelBuilderStatistics::setErrorString
void setErrorString(unsigned int nerr, const std::string &s)
Definition: LArRawChannelBuilderStatistics.cxx:69
MAXINT
#define MAXINT
Definition: LArRawChannelBuilderToolCubic.cxx:20
checkRpcDigits.digit
digit
Definition: checkRpcDigits.py:186
LArRawChannelBuilderStatistics
Returns various counters from the LArRawChannel building.
Definition: LArRawChannelBuilderStatistics.h:21
LArRawChannelBuilderStatistics::incrementErrorCount
void incrementErrorCount(unsigned int nerr)
Definition: LArRawChannelBuilderStatistics.cxx:34
CaloCell_ID.h
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
dqt_zlumi_alleff_HIST.A
A
Definition: dqt_zlumi_alleff_HIST.py:110
LArRawChannelBuilderToolCubic::initTool
StatusCode initTool()
Definition: LArRawChannelBuilderToolCubic.cxx:42
LArDigit.h
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
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
LArRawChannelBuilderToolCubic::buildRawChannel
bool buildRawChannel(const LArDigit *digit, float pedestal, const std::vector< float > &ramps, MsgStream *pLog)
Definition: LArRawChannelBuilderToolCubic.cxx:51
test_pyathena.parent
parent
Definition: test_pyathena.py:15
LArRawChannelBuilderToolBase
Base tool to make the interface with the driver.
Definition: LArRawChannelBuilderToolBase.h:33
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
LArRawChannelBuilderToolBase::m_buildIt
void(LArRawChannelBuilderToolBase::* m_buildIt)(int energy, int time, uint16_t quality, uint16_t provenance, const LArDigit *digit)
Definition: LArRawChannelBuilderToolBase.h:57
LArRawChannelBuilderParams::curr_maxsample
unsigned int curr_maxsample
Definition: LArRawChannelBuilderParams.h:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArRawChannelBuilderToolCubic::m_useMaxSample
bool m_useMaxSample
Definition: LArRawChannelBuilderToolCubic.h:37
LArRawChannelBuilderToolBaseClass::currentID
Identifier currentID()
Definition: LArRawChannelBuilderToolBaseClass.cxx:94
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
LArRawChannelBuilderToolCubic::LArRawChannelBuilderToolCubic
LArRawChannelBuilderToolCubic(const std::string &type, const std::string &name, const IInterface *parent)
Definition: LArRawChannelBuilderToolCubic.cxx:24
MAXINT2
#define MAXINT2
Definition: LArRawChannelBuilderToolCubic.cxx:21
python.SystemOfUnits.ns
int ns
Definition: SystemOfUnits.py:130
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
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::qualityBitPattern
unsigned int qualityBitPattern
Definition: LArRawChannelBuilderParams.h:34
LArRawChannelBuilderToolBaseClass::m_parent
LArRawChannelBuilderParams * m_parent
Definition: LArRawChannelBuilderToolBaseClass.h:80
LArRawChannelBuilderToolCubic::m_fcalId
const LArFCAL_ID * m_fcalId
Definition: LArRawChannelBuilderToolCubic.h:38
readCCLHist.float
float
Definition: readCCLHist.py:83
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
LArRawChannelBuilderToolCubic::m_minADC
int m_minADC
Definition: LArRawChannelBuilderToolCubic.h:39