ATLAS Offline Software
LArRampFCalCorr.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //***************************************************************************
6 //
7 // LArRampFCalCorr.cxx - Algorithm to normalize FCal Ramps and correct
8 // for baseplane faults.
9 //
10 // Author: Alan Robinson <fbfree@interchange.ubc.ca>
11 // Created: August 28, 2007
12 //
13 //***************************************************************************
14 
15 #include "GaudiKernel/MsgStream.h"
16 #include "GaudiKernel/ISvcLocator.h"
17 
19 
21 
25 
26 #include "StoreGate/StoreGateSvc.h"
27 #include <cmath>
28 using std::pow;
29 
30 LArRampFCalCorr::LArRampFCalCorr(const std::string& name,ISvcLocator* pSvcLocator)
31  :AthAlgorithm(name, pSvcLocator),
32  m_onlineHelper(nullptr)
33 {
34  declareProperty("Threshold", m_threshold = 1.0); // Baseplane problem threshold at HIGH gain.
35 }
36 
38 
40  ATH_MSG_DEBUG ( " in initialize() " );
41  ATH_CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
42  return StatusCode::SUCCESS;
43 }
44 
45 StatusCode LArRampFCalCorr::execute() {return StatusCode::SUCCESS;}
46 
48 
49  ATH_MSG_DEBUG ( " in stop() " );
50 
51  const LArRampComplete* ramp = nullptr;
52  ATH_CHECK( detStore()->retrieve(ramp) );
53  ATH_MSG_DEBUG ( "found LarRampComplete" );
54 
55  HWIdentifier chid;
56  std::vector<int> badChan;
57  int channel{}, module{};
58  int slot = 0;
59  double avg[3];
60  int numChan[3];
61  // float gainRatio[3] = {1, 9.3, 93}; // Gain ratio high:medium:low
62 
63  for ( int gain = 0 ; gain < 3 ; gain++ ){ // loop on possible gains
64  badChan.clear();
65 
66  for (int i=0; i<3; i++){
67  avg[i] = 0.; numChan[i] = 0;
68  }
69 
70  // Flag bad channels
71  for ( LArRampIt it = ramp->begin(gain); it != ramp->end(gain); ++it) {
72  chid = it.channelId();
74  if (it->m_vRamp.size() != 2 || !m_onlineHelper->isFCALchannel(chid)
75  || module == -1) continue;
76  slot = m_onlineHelper->slot(chid);
78  ATH_MSG_VERBOSE ( slot << " " << channel );
79  if (it->m_vRamp[1] > m_threshold*std::pow(10.0,(int)gain)){ // Note: ramp contains inverse of slope. Therefore, baseplane problems have a high value.
80  ATH_MSG_DEBUG ( "Bad chan: slot" << slot << " chan: " << channel
81  << " amp " << it->m_vRamp[1] );
82  badChan.push_back(channel); // Record baseplane faults.
83  }
84  }
85 
86  // Create normalization average
87  for ( LArRampIt it = ramp->begin(gain); it != ramp->end(gain); ++it) {
88  chid = it.channelId();
90  if (it->m_vRamp.size() != 2 || !m_onlineHelper->isFCALchannel(chid)
91  || module == -1) continue;
92  slot = m_onlineHelper->slot(chid);
94  if (std::find(badChan.begin(), badChan.end(), channel)==badChan.end()){ // If this calib line doen't have a baseplane fault.
95  avg[module] += 1.0 / it->m_vRamp[1];
96  numChan[module]++;
97  }
98  }
99 
100  for (int i=0; i<3; i++) // Average slope over each module
101  if (numChan[i] != 0 && avg[i] != 0.0)
102  avg[i] /= numChan[i]; // avg[i] *= gainRatio[gain] / numChan[i];
103  else
104  avg[i] = 1.0; // avg[i] = gainRatio[gain];
105 
106  ATH_MSG_DEBUG ( "Averages modules 1: " << avg[0] << " 2: " << avg[1]
107  << " 3: " << avg[2] );
108  ATH_MSG_DEBUG ( "NumChan modules 1: " << numChan[0] << " 2: " << numChan[1]
109  << " 3: " << numChan[2] );
110 
111  // Apply corrections
112  for ( LArRampIt it = ramp->begin(gain); it != ramp->end(gain); ++it) {
113  chid = it.channelId();
115  if (it->m_vRamp.size() == 2 && m_onlineHelper->isFCALchannel(chid) && module != -1){
116  //LArRampP& rampP = const_cast<LArRampP&> (*it); // avoid direct use of payload object!
117  LArRampComplete::LArCondObj& rampP = const_cast<LArRampComplete::LArCondObj&> (*it);
118  slot = m_onlineHelper->slot(chid);
119  channel = m_onlineHelper->channel(chid);
120  if (std::find(badChan.begin(), badChan.end(), channel)==badChan.end())
121  rampP.m_vRamp[1] *= avg[module]; // Normalize the ramp
122  else if (rampP.m_vRamp[1] > m_threshold*pow(10.,gain))
123  rampP.m_vRamp[1] = 1.0; // Write default value
124  else
125  rampP.m_vRamp[1] *= 1.027 * avg[module]; // Correct the amplitude and normalize
126  } else
127  ATH_MSG_DEBUG ( "Channel 0x" << std::hex << chid << std::dec
128  << " Slot " << slot << " Chan " << channel
129  << " No normalization applied." );
130  //larRampComplete->set(chid, gain, rampP.m_vRamp); // Rerecords all channels. Including those not normalized
131  }
132  } // end loop over gains
133  ATH_MSG_INFO ( "Completed LArRampFCalCorr" );
134 
135  return StatusCode::SUCCESS;
136 }
137 
138 // Map slot number to an FCal module
139 int LArRampFCalCorr::toMod(int& slot){
140  if (slot == 9 || (slot > 0 && slot < 8))
141  return 0;
142  else if (slot >= 10 && slot < 14)
143  return 1;
144  else if (slot == 14 || slot == 15)
145  return 2;
146  else return -1;
147 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArRampComplete.h
LArRampFCalCorr::toMod
static int toMod(int &slot)
Definition: LArRampFCalCorr.cxx:139
LArRampFCalCorr::~LArRampFCalCorr
~LArRampFCalCorr()
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
LArRampComplete
Definition: LArRampComplete.h:50
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArConditionsContainerDB::iteratorT
Declaration of const iterator.
Definition: LArConditionsContainerDB.h:72
LArRampP1
Persistent data for LArRamp Copied from LAr.
Definition: LArRampP1.h:24
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
skel.it
it
Definition: skel.GENtoEVGEN.py:423
LArOnlineID_Base::slot
int slot(const HWIdentifier id) const
Return the slot number of a hardware cell identifier: slot = [1,15] Slot-ID in top part of the crat...
Definition: LArOnlineID_Base.cxx:1961
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
HWIdentifier
Definition: HWIdentifier.h:13
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
LArRampP1::m_vRamp
std::vector< float > m_vRamp
Definition: LArRampP1.h:30
LArRampFCalCorr::stop
StatusCode stop()
Definition: LArRampFCalCorr.cxx:47
python.PyAthena.module
module
Definition: PyAthena.py:134
LArOnlineID_Base::isFCALchannel
bool isFCALchannel(const HWIdentifier id) const
Definition: LArOnlineID_Base.cxx:1657
LArOnlineID_Base::channel
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Definition: LArOnlineID_Base.cxx:1967
LArRampFCalCorr::LArRampFCalCorr
LArRampFCalCorr(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArRampFCalCorr.cxx:30
LArConditionsContainer::end
ConstConditionsMapIterator end(unsigned int gain) const
end of all channels for this gain
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Recovery.avg
def avg(a, b)
Definition: Recovery.py:79
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
LArRampFCalCorr::execute
StatusCode execute()
Definition: LArRampFCalCorr.cxx:45
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
IdentifierHash.h
LArRampFCalCorr.h
LArRampFCalCorr::m_threshold
float m_threshold
Definition: LArRampFCalCorr.h:44
LArRampFCalCorr::initialize
StatusCode initialize()
Definition: LArRampFCalCorr.cxx:39
LArConditionsContainer::begin
ConstConditionsMapIterator begin(unsigned int gain) const
get iterator for all channels for a gain
LArRampFCalCorr::m_onlineHelper
const LArOnlineID * m_onlineHelper
Definition: LArRampFCalCorr.h:42
CaloGain.h
StoreGateSvc.h
LArOnlineID.h