ATLAS Offline Software
CaloEstimatedGainTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3  */
12 #include "CaloEstimatedGainTool.h"
13 #include "TileEvent/TileCell.h"
14 #include "CaloEvent/CaloCell.h"
16 #include "CaloDetDescr/CaloDetDescrElement.h"
19 
20 
22 {
23  m_LowGainThresh[CaloCell_ID::LAREM] = 3900;//ADC counts in MediumGain
24  m_HighGainThresh[CaloCell_ID::LAREM] = 1300;//ADC counts in MediumGain
25  m_LowGainThresh[CaloCell_ID::LARHEC] = 2500;//ADC counts in MediumGain
26  m_HighGainThresh[CaloCell_ID::LARHEC] = 0;//-> high-gain never used for HEC
27  m_LowGainThresh[CaloCell_ID::LARFCAL] = 2000.;//ADC counts
28  m_HighGainThresh[CaloCell_ID::LARFCAL] = 1100.;//ADC counts
29  m_LowGainThresh[CaloCell_ID::TILE] = 0.;// unit ?
31 
32  const CaloCell_ID* calocell_id;
33  ATH_CHECK( detStore()->retrieve (calocell_id, "CaloCell_ID") );
34  m_lar_em_id = calocell_id->em_idHelper();
35 
36  ATH_CHECK( detStore()->retrieve (m_tileInfo, "TileInfo") );
37 
38  ATH_CHECK( m_tileIdTransforms.retrieve() );
39  ATH_CHECK( m_tileToolEmscale.retrieve() );
40  ATH_CHECK( m_tileToolNoiseSample.retrieve() );
41 
43 
44  return StatusCode::SUCCESS;
45 }
46 
47 
49 CaloEstimatedGainTool::estimatedGain (const EventContext& ctx,
50  const CaloCell& caloCell,
51  const Step step) const
52 {
53  return estimatedGain (ctx, caloCell, *caloCell.caloDDE(), step);
54 }
55 
56 
58 CaloEstimatedGainTool::estimatedGain (const EventContext& ctx,
59  const CaloCell& caloCell,
60  const CaloDetDescrElement& caloDDE,
61  const Step step) const
62 {
63  CaloCell_ID::SUBCALO iCalo = caloDDE.getSubCalo();
64 
65  if (iCalo == CaloCell_ID::LAREM ||
66  iCalo == CaloCell_ID::LARHEC ||
67  iCalo == CaloCell_ID::LARFCAL)
68  {
69  return estimatedLArGain (ctx, iCalo, caloDDE, caloCell.energy(), step);
70  }
71  else if (iCalo == CaloCell_ID::TILE)
72  {
73  return estimatedTileGain (ctx, caloCell, caloDDE, step);
74  }
75  else
76  {
77  ATH_MSG_WARNING("CaloEstimatedGainTool::estimatedGain wrong id ! "
78  << m_lar_em_id->show_to_string (caloDDE.identify()) );
79  return CaloGain::INVALIDGAIN;
80  }
81 }
82 
83 
85 CaloEstimatedGainTool::estimatedGain (const EventContext& ctx,
86  const CaloDetDescrElement& caloDDE,
87  const float energy,
88  const Step step) const
89 {
90  CaloCell_ID::SUBCALO iCalo = caloDDE.getSubCalo();
91 
92  if (iCalo == CaloCell_ID::LAREM ||
93  iCalo == CaloCell_ID::LARHEC ||
94  iCalo == CaloCell_ID::LARFCAL)
95  {
96  return estimatedLArGain (ctx, iCalo, caloDDE, energy, step);
97  }
98  else if (iCalo == CaloCell_ID::TILE)
99  {
100  ATH_MSG_WARNING("CaloEstimatedGainTool::estimatedGain NOT IMPLEMENTED FOR TILE "
101  <<"with these arguments! "
102  << m_lar_em_id->show_to_string (caloDDE.identify()) );
103  return CaloGain::INVALIDGAIN;
104  }
105  else
106  {
107  ATH_MSG_WARNING("CaloEstimatedGainTool::estimatedGain wrong id ! "
108  << m_lar_em_id->show_to_string (caloDDE.identify()) );
109  return CaloGain::INVALIDGAIN;
110  }
111 }
112 
113 
116  const CaloCell_ID::SUBCALO iCalo,
117  const CaloDetDescrElement& caloDDE,
118  const float energy,
119  const Step step) const
120 {
121  //returns the gain of a cell according to the energy
122  //(converts in ADC counts in MediumGain and uses thresholds in ADC counts
123  //to determine the gain)
124 
125  // the function could be called before (step=0, RawChannels)
126  // or after (step=1, Cells) LArG3Escale
127 
129 
130  //--EM/HEC--
131  if( iCalo == CaloCell_ID::LAREM ||
132  iCalo == CaloCell_ID::LARHEC ||
133  iCalo == CaloCell_ID::LARFCAL )
134  {
135  //We choose the gain in applying thresholds on the energy
136  //converted in ADC counts in MediumGain (index "1" of adc2mev(id,1)).
137  //Indeed, thresholds in ADC counts are defined with respect
138  //to the MediumGain.
139  //
140  // 1300 3900
141  // ---------------|----------------|-------------> ADC counts in MediumGain
142  // HighGain <--- MediumGain ---> LowGain
143 
144  float adc=0.;
145 
146  //Cells (with E scale and weights from LArG3Escale)
147  if (step == Step::CELLS)
148  adc = energy / (adc2mev (ctx, caloDDE, CaloGain::LARMEDIUMGAIN)) + 1000;
149  //RawChannels
150  else if (step == Step::RAWCHANNELS)
151  {
152  adc = energy / (adc2mev (ctx, caloDDE, CaloGain::LARMEDIUMGAIN)) + 1000;
153  }
154  else
155  {
156  ATH_MSG_WARNING( "CaloEstimatedGainTool::estimatedGain wrong step" );
157  }
158 
160  else if (adc > m_LowGainThresh[iCalo]) igain = CaloGain::LARLOWGAIN;
162  }
163 
164  return igain;
165 }
166 
167 
170  const CaloCell& caloCell,
171  const CaloDetDescrElement& caloDDE,
172  const Step /*step*/) const
173 {
174  const TileCell& tileCell = dynamic_cast<const TileCell&> (caloCell);
175 
176  // threshold (1023 counts) is the same for all channels
177  double threshold = m_tileInfo->ADCmax();
178 
179  // xxx
180  static TileHWID const * const tileHWID = TileCablingService::getInstance()->getTileHWID();
181  static const IdContext chContext = tileHWID->channel_context();
182 
183  HWIdentifier hwid1;
184  tileHWID->get_id (caloDDE.onl1(), hwid1, &chContext ); // pmt id
185  hwid1 = tileHWID->adc_id (hwid1, TileHWID::HIGHGAIN); // high gain ADC id
186 
187  unsigned int drawerIdx1(0), channel1(0), adc1(0);
188  m_tileIdTransforms->getIndices (hwid1, drawerIdx1, channel1, adc1);
189 
190  // first PMT, convert energy to ADC counts
191  double amplitude1 = tileCell.ene1();
192  amplitude1 /= m_tileToolEmscale->channelCalib (drawerIdx1, channel1, adc1, 1.0,
195 
196  double pedestal1 = m_tileToolNoiseSample->getPed (drawerIdx1, channel1, adc1, TileRawChannelUnit::ADCcounts, ctx);
197 
198  int igain1;
199 
200  if (amplitude1 + pedestal1 < threshold ) {
201  igain1 = TileID::HIGHGAIN;
202  } else {
203  igain1 = TileID::LOWGAIN;
204  }
205 
206  // second PMT, if it exists
207  if (caloDDE.onl2() != TileID::NOT_VALID_HASH ) {
208 
209  HWIdentifier hwid2;
210  tileHWID->get_id( caloDDE.onl2(), hwid2, &chContext ); // pmt id
211  hwid2 = tileHWID->adc_id (hwid2, TileHWID::HIGHGAIN); // high gain ADC id
212 
213  unsigned int drawerIdx2(0), channel2(0), adc2(0);
214  m_tileIdTransforms->getIndices (hwid2, drawerIdx2, channel2, adc2);
215 
216  // first PMT, convert energy to ADC counts
217  double amplitude2 = tileCell.ene2();
218  amplitude2 /= m_tileToolEmscale->channelCalib (drawerIdx2, channel2, adc2, 1.0,
221 
222  double pedestal2 = m_tileToolNoiseSample->getPed (drawerIdx2, channel2, adc2, TileRawChannelUnit::ADCcounts, ctx);
223 
224  if (amplitude2 + pedestal2 < threshold) {
225  // igain2 high
227  } else {
228  // igain2 low
230  }
231  // nb. Having HIGHLOW in two places seems wrong, but that's what the
232  // original code was doing.
233  }
234 
235  // igain2 doesn't exist.
237 }
238 
239 
240 float CaloEstimatedGainTool::adc2mev (const EventContext& ctx,
241  const CaloDetDescrElement& caloDDE,
242  CaloGain::CaloGain gain) const
243 {
245  const auto& p = adc2mev->ADC2MEV (caloDDE.identify(), gain);
246  if (p.size() >= 2) {
247  return p[1];
248  }
249  return 0;
250 }
CaloEstimatedGainTool::estimatedGain
virtual CaloGain::CaloGain estimatedGain(const EventContext &ctx, const CaloCell &caloCell, const Step step) const override
Definition: CaloEstimatedGainTool.cxx:49
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileCell
Definition: TileCell.h:57
CaloDetDescrElement::onl2
IdentifierHash onl2() const
cell online identifier 2
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:408
CaloCell_Base_ID::LARFCAL
@ LARFCAL
Definition: CaloCell_Base_ID.h:46
CaloEstimatedGainTool.h
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
CaloEstimatedGainTool::m_adc2mevKey
SG::ReadCondHandleKey< LArADC2MeV > m_adc2mevKey
Definition: CaloEstimatedGainTool.h:79
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
TileHWID::get_id
virtual int get_id(const IdentifierHash &hash_id, HWIdentifier &id, const IdContext *context=0) const
create compact HW ID from hash id (return == 0 for OK)
Definition: TileHWID.cxx:490
CaloCell_ID::em_idHelper
const LArEM_ID * em_idHelper() const
access to EM idHelper
Definition: CaloCell_ID.h:63
TileCablingService::getInstance
static const TileCablingService * getInstance()
get pointer to service instance
Definition: TileCablingService.cxx:24
TileCell::ene1
float ene1(void) const
get energy of first PMT
Definition: TileCell.h:193
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
TileHWID::channel_context
IdContext channel_context(void) const
idContext for channels
Definition: TileHWID.cxx:477
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
CaloEstimatedGainTool::m_HighGainThresh
float m_HighGainThresh[m_nCalos]
Definition: CaloEstimatedGainTool.h:85
CaloCell.h
CaloEstimatedGainTool::m_tileIdTransforms
ToolHandle< TileCondIdTransforms > m_tileIdTransforms
Definition: CaloEstimatedGainTool.h:91
TileInfo.h
Tile_Base_ID::HIGHGAIN
@ HIGHGAIN
Definition: Tile_Base_ID.h:57
CaloCell_Base_ID::LARHEC
@ LARHEC
Definition: CaloCell_Base_ID.h:46
HWIdentifier
Definition: HWIdentifier.h:13
TileHWID::HIGHGAIN
@ HIGHGAIN
Definition: TileHWID.h:73
CaloGain::TILELOWLOW
@ TILELOWLOW
Definition: CaloGain.h:12
Tile_Base_ID::NOT_VALID_HASH
@ NOT_VALID_HASH
Definition: Tile_Base_ID.h:264
ReadCondHandle.h
CaloCell::energy
double energy() const
get energy (data member)
Definition: CaloCell.h:311
CaloDetDescrElement::getSubCalo
CaloCell_ID::SUBCALO getSubCalo() const
cell subcalo
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:433
CaloGain::TILEHIGHHIGH
@ TILEHIGHHIGH
Definition: CaloGain.h:15
CaloDetDescrElement::onl1
IdentifierHash onl1() const
cell online identifier 1
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:404
CaloGain::INVALIDGAIN
@ INVALIDGAIN
Definition: CaloGain.h:18
CaloEstimatedGainTool::m_tileToolEmscale
ToolHandle< TileCondToolEmscale > m_tileToolEmscale
Definition: CaloEstimatedGainTool.h:95
TileHWID
Helper class for TileCal online (hardware) identifiers.
Definition: TileHWID.h:49
CaloEstimatedGainTool::m_tileInfo
const TileInfo * m_tileInfo
Definition: CaloEstimatedGainTool.h:88
CaloDetDescrElement::identify
Identifier identify() const override final
cell identifier
Definition: CaloDetDescrElement.cxx:64
CaloEstimatedGainTool::adc2mev
float adc2mev(const EventContext &ctx, const CaloDetDescrElement &caloDDE, const CaloGain::CaloGain gain) const
Definition: CaloEstimatedGainTool.cxx:240
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
ICaloEstimatedGainTool::Step::RAWCHANNELS
@ RAWCHANNELS
ICaloEstimatedGainTool::Step
Step
Definition: ICaloEstimatedGainTool.h:36
ICaloEstimatedGainTool::Step::CELLS
@ CELLS
CaloGain::TILEONELOW
@ TILEONELOW
Definition: CaloGain.h:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CaloEstimatedGainTool::m_tileToolNoiseSample
ToolHandle< TileCondToolNoiseSample > m_tileToolNoiseSample
Definition: CaloEstimatedGainTool.h:99
CaloCell::caloDDE
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition: CaloCell.h:305
CaloCell_Base_ID::SUBCALO
SUBCALO
enumeration of sub calorimeters
Definition: CaloCell_Base_ID.h:46
TileCell.h
TileRawChannelUnit::MegaElectronVolts
@ MegaElectronVolts
Definition: TileRawChannelUnit.h:20
TileCablingService::getTileHWID
const TileHWID * getTileHWID() const
Definition: TileCablingService.h:271
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Tile_Base_ID::LOWGAIN
@ LOWGAIN
Definition: Tile_Base_ID.h:57
CaloCell_Base_ID::TILE
@ TILE
Definition: CaloCell_Base_ID.h:46
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
WriteCellNoiseToCool.igain
igain
Definition: WriteCellNoiseToCool.py:338
CaloGain::TILEHIGHLOW
@ TILEHIGHLOW
Definition: CaloGain.h:14
CaloEstimatedGainTool::initialize
virtual StatusCode initialize() override
Definition: CaloEstimatedGainTool.cxx:21
CaloEstimatedGainTool::m_lar_em_id
const LArEM_ID * m_lar_em_id
Definition: CaloEstimatedGainTool.h:87
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
threshold
Definition: chainparser.cxx:74
CaloEstimatedGainTool::estimatedTileGain
CaloGain::CaloGain estimatedTileGain(const EventContext &ctx, const CaloCell &caloCell, const CaloDetDescrElement &caloDDE, const Step) const
Definition: CaloEstimatedGainTool.cxx:169
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloGain::LARHIGHGAIN
@ LARHIGHGAIN
Definition: CaloGain.h:18
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
TileHWID::adc_id
HWIdentifier adc_id(int ros, int drawer, int channel, int adc) const
adc HWIdentifer
Definition: TileHWID.cxx:228
CaloGain::LARMEDIUMGAIN
@ LARMEDIUMGAIN
Definition: CaloGain.h:18
TileCell::ene2
float ene2(void) const
get energy of second PMT
Definition: TileCell.h:195
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
AtlasDetectorID::show_to_string
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
Definition: AtlasDetectorID.cxx:574
ReadFloatFromCool.adc
adc
Definition: ReadFloatFromCool.py:48
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloEstimatedGainTool::m_LowGainThresh
float m_LowGainThresh[m_nCalos]
Definition: CaloEstimatedGainTool.h:84
LArCellBinning.step
step
Definition: LArCellBinning.py:158
CaloEstimatedGainTool::estimatedLArGain
CaloGain::CaloGain estimatedLArGain(const EventContext &ctx, const CaloCell_ID::SUBCALO iCalo, const CaloDetDescrElement &caloDDE, const float energy, const Step step) const
Definition: CaloEstimatedGainTool.cxx:115
CaloIdManager.h
CaloGain::LARLOWGAIN
@ LARLOWGAIN
Definition: CaloGain.h:18
CaloCell_Base_ID::LAREM
@ LAREM
Definition: CaloCell_Base_ID.h:46
IdContext
class IdContext
Definition: IdContext.h:34
CaloGain::TILEONEHIGH
@ TILEONEHIGH
Definition: CaloGain.h:17
TileInfo::ADCmax
int ADCmax() const
Returns the maximum ADC output (10 bits --> 1023)
Definition: TileInfo.h:71
TileRawChannelUnit::ADCcounts
@ ADCcounts
Definition: TileRawChannelUnit.h:17