ATLAS Offline Software
TileRawChannelBuilderManyAmps.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 // small hack to enable datapool usage
7 // Tile includes
10 #include "TileEvent/TileDigits.h"
11 #include "CaloIdentifier/TileID.h"
16 
17 // Gaudi includes
18 #include "Gaudi/Property.h"
19 
20 //Atlas includes
21 #include "AthAllocators/DataPool.h"
23 
24 
25 // lang include
26 #include <algorithm>
27 #include <cmath>
28 
29 // C++ STL includes
30 #include <vector>
31 
32 
37  const std::string& name, const IInterface *parent)
39  , m_tileFilterManagerHi(0)
40  , m_tileFilterManagerLo(0)
41 {
42  //declare interfaces
43  declareInterface< TileRawChannelBuilder >( this );
44  declareInterface< TileRawChannelBuilderManyAmps >(this);
45 
46  m_rawChannelContainerKey = "TileRawChannelManyAmps";
47 
48  //declare properties
49  declareProperty("FilterMode", m_digitFilterMode = 2); // can be 2 or 3
50  declareProperty("FilterLevel", m_digitFilterLevel = 5); // number of parameters for fit (3-9 for mode 2)
51  declareProperty("FilterTester", m_digitFilterTest = 0); // non-zero means call Tester (during initialization phase).
52 }
53 
54 
59 }
60 
61 
66 
67  ATH_MSG_INFO( "TileRawChannelBuilderManyAmps::initialize()" );
68 
70 
71  // init in superclass
73 
74 
75  // **************************************************************************************
76  ATH_MSG_INFO( " TileRawChannelBuilderManyAmps init:"
77  << " FilterMode=" << m_digitFilterMode
78  << ", FilterLevel=" << m_digitFilterLevel
79  << ", FilterTest=" << m_digitFilterTest );
80 
81  if (!(m_digitFilterMode == 2) && !(m_digitFilterMode == 3)) { // filter mode different from 2 or 3
82 
83  ATH_MSG_WARNING( "Wrong Filter mode defined: FilterMode=" << m_digitFilterMode );
84  ATH_MSG_WARNING( "Switching to FilterMode=2" );
86  }
87 
88  // if( (m_digitFilterMode == 2) || (m_digitFilterMode == 3) ) {
89  /* Get information needed to initialize TileFilterManager. */
90  int Nsamp = m_tileInfo->NdigitSamples();
91  // Set maximum number of parameters to fit, using FilterLevel
92  int nParamMax = m_digitFilterLevel;
93  if (nParamMax > Nsamp + 1) nParamMax = Nsamp;
94  if (nParamMax < 3) nParamMax = 3;
95  int InTsamp = m_tileInfo->ItrigSample();
96  int jBsamp = 0;
97  int jEsamp = Nsamp - 1;
98  int jBcross = 0;
99  int jEcross = Nsamp - 1;
100  int Nshape = m_tileInfo->NdigitSamples();
101  int InTshape = m_tileInfo->ItrigSample(); // need new method to give this !!!
102  std::vector<double> ShapeXHi = m_tileInfo->digitsShapeHi();
103  std::vector<double> ShapeXLo = m_tileInfo->digitsShapeLo();
104 
105  bool lVerbose = msgLvl(MSG::VERBOSE);
107  Nsamp, InTsamp, jBsamp, jEsamp, jBcross, jEcross, Nshape, InTshape, ShapeXHi, lVerbose);
108 
110  Nsamp, InTsamp, jBsamp, jEsamp, jBcross, jEcross, Nshape, InTshape, ShapeXLo, lVerbose);
111 
112  // Run TileFilterTester if m_digitFilterTest in non-zero).
113 
114  if (m_digitFilterTest > 0) {
115 
117  , m_digitFilterMode, m_digitFilterTest, lVerbose);
118 
119  tFilterTestHi->genEvents(10);
120  delete tFilterTestHi;
121 
123  , m_digitFilterMode, m_digitFilterTest, lVerbose);
124 
125  tFilterTestLo->genEvents(10);
126  delete tFilterTestLo;
127  } // end FilterTest
128 
129  ATH_MSG_DEBUG( "TileRawChannelBuilderManyAmps::initialize() completed successfully" );
130 
131  return StatusCode::SUCCESS;
132 }
133 
138 
139  ATH_MSG_DEBUG( "Finalizing" );
140  delete m_tileFilterManagerHi;
141  delete m_tileFilterManagerLo;
142  return StatusCode::SUCCESS;
143 }
144 
145 TileRawChannel* TileRawChannelBuilderManyAmps::rawChannel(const TileDigits* tiledigits, const EventContext& ctx) {
146 
147  ++m_chCounter;
148 
149  const HWIdentifier adcId = tiledigits->adc_HWID();
150  unsigned int drawerIdx(0), channel(0), gain(0);
151  m_tileIdTransforms->getIndices(adcId, drawerIdx, channel, gain);
152 
153  bool lVerbose(false);
154  if (msgLvl(MSG::VERBOSE)) {
155  msg(MSG::VERBOSE) << "Running ManyAmps Fit for TileRawChannel with HWID "
156  << m_tileHWID->to_string(adcId) << endmsg;
157  lVerbose = true;
158  }
159 
160 
161  /* get pedestal value assumed for reconstruction */
162  //double digSigma = m_tileInfo->DigitsResolution(gain);
163  // new way to get channel-dependent sigma:
164  // but we lost difference between sigma used in digitization and
165  // sigma assumed in reconstruction - it's the same sigma now
166  double digSigma = m_tileToolNoiseSample->getHfn(drawerIdx, channel, gain, TileRawChannelUnit::ADCcounts, ctx);
167 
168  /* Get vector of time-slice amplitudes. */
169  std::vector<float> digits = tiledigits->samples();
170  double amp_ch = 0; // Fitted amplitude of RC (to be returned from Filtering code).
171  double err_ch; // Error in amp_ch (from Filtering code)
172  double ped_ch; // Fitted pedestal of raw channel (from Filtering).
173  double chisq_ch = 0.; // Chisq resulting from Filtering.
174  double t_ch = 0.; // Fitted time to be supplied by Filtering code
175  // ---------------------------------------------------------------------------------------
176 
177  //int icode = 0;
178 
179  // Instantiate tResult, which will collect results from Filtering code.
180  TileFilterResult tResult(digits, digSigma);
181  // Call Fitter to extract the in-time pulse height and related info.
182  if (TileID::HIGHGAIN == gain)
183  /*icode =*/m_tileFilterManagerHi->fitDigits(tResult, lVerbose);
184 
185  if (TileID::LOWGAIN == gain)
186  /*icode =*/m_tileFilterManagerLo->fitDigits(tResult, lVerbose);
187 
188  tResult.getInTime(amp_ch, err_ch, ped_ch, chisq_ch, t_ch);
189 
190  ATH_MSG_VERBOSE( " TileRawChannelBuilderManyAmps: return from FilterManager/Fitter."
191  << ", chisq_ch=" << chisq_ch );
192 
193  // convert to pCb (if needed)
194  if (m_calibrateEnergy) {
195  amp_ch = m_tileToolEmscale->doCalibCis(drawerIdx, channel, gain, amp_ch);
196  }
197  // we know that time is zero here, put negative chi^2 to indicate that
198  chisq_ch = -fabs(chisq_ch);
199 
200  // TileRawChannel *rawCh = new TileRawChannel(adcId,amp_ch,t_ch,chisq_ch);
202  TileRawChannel *rawCh = tileRchPool.nextElementPtr();
203  rawCh->assign (adcId, amp_ch, t_ch, chisq_ch, 0);
204  ATH_MSG_VERBOSE( "Creating RawChannel"
205  << " a=" << amp_ch
206  << " t=" << t_ch
207  << " q=" << chisq_ch );
208 
209  if (TileID::HIGHGAIN == gain) {
210  ++m_nChH;
211  m_RChSumH += amp_ch;
212  } else {
213  ++m_nChL;
214  m_RChSumL += amp_ch;
215  }
216 
217  return rawCh;
218 }
TileRawChannelBuilderManyAmps::m_tileToolNoiseSample
ToolHandle< TileCondToolNoiseSample > m_tileToolNoiseSample
Definition: TileRawChannelBuilderManyAmps.h:58
TileFilterTester.h
TileRawChannelBuilder::m_dataPoollSize
int m_dataPoollSize
Definition: TileRawChannelBuilder.h:204
TileRawChannel.h
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
TileRawChannelBuilder::m_tileToolEmscale
ToolHandle< TileCondToolEmscale > m_tileToolEmscale
Definition: TileRawChannelBuilder.h:166
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TileRawChannelBuilder::m_chCounter
unsigned int m_chCounter
Definition: TileRawChannelBuilder.h:196
TileInfo::NdigitSamples
int NdigitSamples() const
Returns the number of sammples (digits) per event.
Definition: TileInfo.h:75
TileFilterManager.h
TileRawChannelBuilder::m_calibrateEnergy
bool m_calibrateEnergy
Definition: TileRawChannelBuilder.h:142
TileRawChannelBuilderManyAmps::m_tileFilterManagerLo
TileFilterManager * m_tileFilterManagerLo
Definition: TileRawChannelBuilderManyAmps.h:56
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TileFilterManager::fitDigits
int fitDigits(TileFilterResult &tRes, bool lDebug=false)
Definition: TileFilterManager.cxx:160
TileFilterResult::getInTime
double getInTime(double &, double &, double &, double &, double &)
Definition: TileFilterResult.cxx:93
TileRawChannelBuilder::m_tileHWID
const TileHWID * m_tileHWID
Definition: TileRawChannelBuilder.h:161
TileRawChannelBuilderManyAmps.h
TileInfo::digitsShapeHi
const std::vector< double > & digitsShapeHi() const
Return high gain shape vector to multiply the amplitude of a TileHit to produce TileDigit.
Definition: TileInfo.h:174
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
TileRawChannelBuilder::initialize
virtual StatusCode initialize()
Initializer.
Definition: TileRawChannelBuilder.cxx:98
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
TileInfo.h
Tile_Base_ID::HIGHGAIN
@ HIGHGAIN
Definition: Tile_Base_ID.h:57
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TileRawData::adc_HWID
HWIdentifier adc_HWID(void) const
Definition: TileRawData.h:53
TileFilterManager
Auxiliary class for TileRawChannelMakerManyAmps.
Definition: TileFilterManager.h:34
HWIdentifier
Definition: HWIdentifier.h:13
TileFilterTester
Auxiliary class for TileRawChannelMakerManyAmps.
Definition: TileFilterTester.h:26
TileID.h
TileRawChannelBuilderManyAmps::initialize
virtual StatusCode initialize() override
Initialize.
Definition: TileRawChannelBuilderManyAmps.cxx:65
TileRawChannel::assign
void assign(const HWIdentifier &id, float amplitude, float time, float quality, float ped=0.0)
Definition: TileRawChannel.h:63
TileRawChannelContainer.h
TileRawChannelBuilder::m_rChType
TileFragHash::TYPE m_rChType
Definition: TileRawChannelBuilder.h:136
TileInfo::ItrigSample
int ItrigSample() const
The sample at which the pulse should ideally peak.
Definition: TileInfo.h:77
TileRawChannelBuilder::m_nChL
int m_nChL
Definition: TileRawChannelBuilder.h:198
TileHWID.h
TileRawChannelBuilder::m_rawChannelContainerKey
SG::WriteHandleKey< TileRawChannelContainer > m_rawChannelContainerKey
Definition: TileRawChannelBuilder.h:129
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TileRawChannelBuilder::m_tileIdTransforms
ToolHandle< TileCondIdTransforms > m_tileIdTransforms
Definition: TileRawChannelBuilder.h:172
TileRawChannelBuilder::m_nChH
int m_nChH
Definition: TileRawChannelBuilder.h:199
TileRawChannel
Definition: TileRawChannel.h:35
test_pyathena.parent
parent
Definition: test_pyathena.py:15
TileRawChannelBuilder::m_RChSumL
double m_RChSumL
Definition: TileRawChannelBuilder.h:200
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
Tile_Base_ID::LOWGAIN
@ LOWGAIN
Definition: Tile_Base_ID.h:57
TileRawChannelBuilder
Definition: TileRawChannelBuilder.h:59
DataPool::nextElementPtr
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
TileDigits::samples
const std::vector< float > & samples() const
Definition: TileDigits.h:58
DataPool.h
TileRawChannelBuilder::m_tileInfo
const TileInfo * m_tileInfo
Definition: TileRawChannelBuilder.h:216
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.
TileRawChannelBuilderManyAmps::TileRawChannelBuilderManyAmps
TileRawChannelBuilderManyAmps(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition: TileRawChannelBuilderManyAmps.cxx:36
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TileRawChannelBuilderManyAmps::m_digitFilterTest
int m_digitFilterTest
Definition: TileRawChannelBuilderManyAmps.h:51
TileRawChannelBuilder::m_RChSumH
double m_RChSumH
Definition: TileRawChannelBuilder.h:201
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
TileRawChannelBuilderManyAmps::rawChannel
virtual TileRawChannel * rawChannel(const TileDigits *digits, const EventContext &ctx) override
Builder virtual method to be implemented by subclasses.
Definition: TileRawChannelBuilderManyAmps.cxx:145
TileRawChannelBuilderManyAmps::m_tileFilterManagerHi
TileFilterManager * m_tileFilterManagerHi
Definition: TileRawChannelBuilderManyAmps.h:55
TileFragHash::ManyAmps
@ ManyAmps
Definition: TileFragHash.h:35
DataPool
a typed memory pool that saves time spent allocation small object. This is typically used by containe...
Definition: DataPool.h:47
TileFilterResult
Auxiliary class for TileRawChannelMakerManyAmps.
Definition: TileFilterResult.h:22
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
TileInfo::digitsShapeLo
const std::vector< double > & digitsShapeLo() const
Return low gain shape vector to multiply the amplitude of a TileHit to produce TileDigit.
Definition: TileInfo.h:176
TileDigits.h
TileFilterTester::genEvents
void genEvents(int nEvent)
Definition: TileFilterTester.cxx:74
TileRawChannelBuilderManyAmps::~TileRawChannelBuilderManyAmps
~TileRawChannelBuilderManyAmps()
Destructor.
Definition: TileRawChannelBuilderManyAmps.cxx:58
TileRawChannelUnit::ADCcounts
@ ADCcounts
Definition: TileRawChannelUnit.h:17
TileRawChannelBuilderManyAmps::finalize
virtual StatusCode finalize() override
Finalize.
Definition: TileRawChannelBuilderManyAmps.cxx:137
TileRawChannelBuilderManyAmps::m_digitFilterLevel
int m_digitFilterLevel
Definition: TileRawChannelBuilderManyAmps.h:50
TileRawChannelBuilderManyAmps::m_digitFilterMode
int m_digitFilterMode
Definition: TileRawChannelBuilderManyAmps.h:49