ATLAS Offline Software
Loading...
Searching...
No Matches
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
27#include <cmath>
28using std::pow;
29
30LArRampFCalCorr::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
45StatusCode 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();
73 module = LArRampFCalCorr::toMod(slot);
74 if (it->m_vRamp.size() != 2 || !m_onlineHelper->isFCALchannel(chid)
75 || module == -1) continue;
76 slot = m_onlineHelper->slot(chid);
77 channel = m_onlineHelper->channel(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();
89 module = LArRampFCalCorr::toMod(slot);
90 if (it->m_vRamp.size() != 2 || !m_onlineHelper->isFCALchannel(chid)
91 || module == -1) continue;
92 slot = m_onlineHelper->slot(chid);
93 channel = m_onlineHelper->channel(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();
114 module = LArRampFCalCorr::toMod(slot);
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!
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
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
constexpr int pow(int base, int exp) noexcept
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
ConstConditionsMapIterator begin(unsigned int gain) const
get iterator for all channels for a gain
ConstConditionsMapIterator end(unsigned int gain) const
end of all channels for this gain
LArRampComplete::ConstConditionsMapIterator LArRampIt
const LArOnlineID * m_onlineHelper
static int toMod(int &slot)
StatusCode execute()
LArRampFCalCorr(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initialize()
std::vector< float > m_vRamp
Definition LArRampP1.h:30