ATLAS Offline Software
FixLArElecCalib.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef FIXLARELECCALIB_H
6 #define FIXLARELECCALIB_H
7 
12 #include "LArCabling/LArOnOffIdMapping.h" //template argument
13 #include "LArRecConditions/LArCalibLineMapping.h" //template argument
14 #include "LArRawConditions/LArMphysOverMcalMC.h" //template argument
15 #include "LArRawConditions/LArShape32MC.h" //typedef
16 #include "LArRawConditions/LArNoiseMC.h" //typedef
17 #include "LArRawConditions/LArRampMC.h" //typedef
18 #include "LArRawConditions/LArAutoCorrMC.h" //typedef
19 #include <string>
20 #include <utility> //std::pair
21 #include <vector>
22 
23 
24 class LArSingleFloatP;
25 class LArEM_ID ;
26 class LArHEC_ID;
27 class LArFCAL_ID;
28 class LArOnlineID;
31 
32 // this class is collection of various fixes, applied to LAr conditions,
33 // when some bug was found.
34 // should serve mainly as example, in case yet another problem will need a fix
36 {
37  public:
38  FixLArElecCalib(const std::string& name,ISvcLocator* pSvcLocator);
39  virtual ~FixLArElecCalib() = default;
40 
41  virtual StatusCode initialize() override;
42  virtual StatusCode execute() override;
43  virtual StatusCode finalize() override {return StatusCode::SUCCESS;}
44  virtual StatusCode stop ATLAS_NOT_THREAD_SAFE () override;
45 
63  StatusCode fix18(const LArCalibLineMapping *clmap);
64 
65  private:
66 
67  SG::ReadCondHandleKey<LArOnOffIdMapping> m_cablingKey{this,"CablingKey","LArOnOffIdMap","SG Key of LArOnOffIdMapping object"};
68  SG::ReadCondHandleKey<LArCalibLineMapping> m_CLKey{this, "CalibLineKey", "LArCalibLineMap", "calib line key"};
69 
70  IntegerProperty m_fixFlag{this, "FixFlag", 1, "which fix to apply"};
71  StringProperty m_g4Phys{this, "G4Phys", "", "which physics list to use"};
72  StringProperty m_infile{this, "InputFile", "", "name of inpput file"};
73 
74  StatusCode ReadFile(const std::string& filename, const LArOnOffIdMapping *cabling, bool EM, bool withGain, int nvar );
75  StatusCode ReadFileAll(const std::string& filename, const LArOnOffIdMapping *cabling, bool withGain, int nvar );
76 
77  StatusCode update_DAC2uA(const std::string& em_filename,const std::string& hec_filename);
78  // FIXME: for future round of developments:
79  // StatusCode update_uA2MeV(const std::string& em_filename,const std::string& hec_filename);
80  // StatusCode update_AC(const std::string& em_filename,const std::string& hec_filename);
81  //StatusCode update_Noise(const std::string& em_filename,const std::string& hec_filename);
82  //StatusCode update_Mphys(const std::string& em_filename,const std::string& hec_filename);
83  //StatusCode update_Ramp(const std::string& em_filename,const std::string& hec_filename);
84  //StatusCode update_Shape(const std::string& em_filename,const std::string& hec_filename);
85 
86  template <class T>
87  StatusCode update_EM_HEC ATLAS_NOT_THREAD_SAFE (const std::string& em_filename,const std::string& hec_filename, const LArOnOffIdMapping *cabling,
88  bool withGain, int nvar);
89  template <class T>
90  StatusCode update_All ATLAS_NOT_THREAD_SAFE (const std::string& filename, const LArOnOffIdMapping *cabling, bool withGain, int nvar);
91 
92  void print_object(const std::string& msg, const LArNoiseMC::LArCondObj& obj);
93  void set_object(LArNoiseMC::LArCondObj& obj, const std::vector<float>& v );
94 
95  void print_object(const std::string& msg, const LArAutoCorrMC::LArCondObj& obj);
96  void set_object(LArAutoCorrMC::LArCondObj& obj, const std::vector<float>& v );
97 
98  void print_object(const std::string& msg, const LArRampMC::LArCondObj& obj);
99  void set_object(LArRampMC::LArCondObj& obj, const std::vector<float>& v );
100 
101  //void print_object(const std::string& msg, const LAruA2MeVMC::LArCondObj& obj);
102  //void set_object(LAruA2MeVMC::LArCondObj& obj, std::vector<float>& v );
103 
104  void print_object(const std::string& msg, const LArShape32MC::LArCondObj& obj);
105  void set_object(LArShape32MC::LArCondObj& obj, const std::vector<float>& v );
106 
107  void print_object(const std::string& msg, const LArSingleFloatP& obj);
108  void set_object(LArSingleFloatP& obj, const std::vector<float>& v );
109 
110  // void print_object(const std::string& msg, const LArDAC2uAMC::LArCondObj& obj);
111  //void set_object(LArDAC2uAMC::LArCondObj& obj, std::vector<float>& v );
112 
113  StatusCode addMphysOverMcal(const LArOnOffIdMapping *cabling) ; // add new one with default for FCAL
114 
115  StatusCode fixDACuAMeV ATLAS_NOT_THREAD_SAFE () ; // remove -100000000
116 
117 
118  StatusCode updateEMfSampl ATLAS_NOT_THREAD_SAFE (const std::string& filename, const LArOnOffIdMapping *cabling);
119  StatusCode updateMinBias ATLAS_NOT_THREAD_SAFE (const std::string& filename, const LArOnOffIdMapping *cabling);
120  StatusCode updateEM_DACuAMeV ATLAS_NOT_THREAD_SAFE (const std::string& filename, const LArOnOffIdMapping *cabling);
122 
131 
132 
133 
134 
135  typedef std::pair<HWIdentifier,std::vector<float> > ROW_t ;
136  typedef std::vector<ROW_t> VROW_t;
137 
139 
140 
141 };
142 
143 template <class T >
144  StatusCode FixLArElecCalib::update_EM_HEC ATLAS_NOT_THREAD_SAFE (const std::string& em_filename,const std::string& hec_filename, const LArOnOffIdMapping *cabling, bool withGain, int nvar)
145 {
146  // read in the file
147 
148  const T * container_c = nullptr;
149  ATH_CHECK( detStore()->retrieve(container_c) );
150 
151  T* container = const_cast<T*>(container_c);
152 
153  typedef typename T::LArCondObj CONDOBJ ;
154 
155  for (int i=0; i<2;++i)
156  { // EM and HEC
157  if( i==0 )
158  {
159  if ( em_filename == "") continue ;
160  bool EM=true;
161  ATH_CHECK( ReadFile(em_filename,cabling,EM,withGain,nvar) );
162  }
163  if( i==1 )
164  {
165  if ( hec_filename == "") continue ;
166  bool EM=false ;
167  ATH_CHECK( ReadFile(hec_filename,cabling,EM,withGain,nvar) );
168  }
169 
170 
171  int ngain=1;
172  if (withGain) ngain=3;
173  for (int igain = 0;igain<ngain;++igain){
174  VROW_t::iterator it = m_cache[igain].begin();
175  VROW_t::iterator it_e = m_cache[igain].end();
176 
177  int n=0;
178  for( ;it!=it_e;++it)
179  {
180  HWIdentifier hid = (*it).first;
181 
182  const CONDOBJ& u = container->get(hid,igain);
183 
184  if( u.isEmpty() )
185  {
186  ATH_MSG_WARNING(" No existing conditions data, adding new one " );
187  CONDOBJ t ;
188  set_object(t,(*it).second) ;
189  container->setPdata(hid,t,igain);
190  }
191  else
192  {
193  print_object(" Old object = ",u);
194 
195  CONDOBJ& u2 = const_cast<CONDOBJ&>(u);
196  set_object(u2,(*it).second) ;
197  }
198 
199  const CONDOBJ& u3 = container->get(hid,igain);
200  print_object(" New object = ",u3);
201 
202  ++n;
203  }
204  ATH_MSG_INFO( " done for gain ="<<igain<<" with "<<n<<" objects");
205 
206  }// gain
207  }// EM HEC
208 
209  ATH_MSG_INFO(" done with EM "<<em_filename<<" and HEC" <<hec_filename );
210  return StatusCode::SUCCESS;
211 }
212 
213 
214 template <class T >
215  StatusCode FixLArElecCalib::update_All ATLAS_NOT_THREAD_SAFE (const std::string& filename, const LArOnOffIdMapping *cabling, bool withGain, int nvar)
216 {
217  // read in the file
218 
219  const T * container_c = nullptr;
220  ATH_CHECK( detStore()->retrieve(container_c) );
221 
222  T* container = const_cast<T*>(container_c);
223 
224  typedef typename T::LArCondObj CONDOBJ ;
225 
226  if ( filename == "") { ATH_MSG_ERROR("No input filename "); return StatusCode::FAILURE; }
227  ATH_CHECK( ReadFileAll(filename, cabling, withGain,nvar) );
228 
229  int ngain=1;
230  if (withGain) ngain=3;
231  for (int igain = 0;igain<ngain;++igain){
232  VROW_t::iterator it = m_cache[igain].begin();
233  VROW_t::iterator it_e = m_cache[igain].end();
234 
235  int n=0;
236  for( ;it!=it_e;++it) {
237  HWIdentifier hid = (*it).first;
238 
239  if(!hid.is_valid()) {
240  ATH_MSG_WARNING(" Not valid hid: 0x" <<hid.getString() );
241  continue;
242  }
243 
244  const CONDOBJ& u = container->get(hid,igain);
245 
246  if( u.isEmpty() ) {
247  ATH_MSG_WARNING(" Not existing conditions data, adding new one " );
248  CONDOBJ t ;
249  set_object(t,(*it).second) ;
250  container->setPdata(hid,t,igain);
251  } else {
252  print_object(" Old object = ",u);
253 
254  CONDOBJ& u2 = const_cast<CONDOBJ&>(u);
255  set_object(u2,(*it).second) ;
256  }
257 
258  const CONDOBJ& u3 = container->get(hid,igain);
259  print_object(" New object = ",u3);
260 
261  ++n;
262  }
263  ATH_MSG_INFO( " done for gain ="<<igain<<" with "<<n<<" objects");
264 
265  }// gain
266 
267  ATH_MSG_INFO(" done with "<<filename );
268  return StatusCode::SUCCESS;
269 }
270 #endif // FixLArElecCalib
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode fix6 ATLAS_NOT_THREAD_SAFE(const LArOnOffIdMapping *cabling)
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
FixLArElecCalib::finalize
virtual StatusCode finalize() override
Definition: FixLArElecCalib.h:43
FixLArElecCalib::ReadFileAll
StatusCode ReadFileAll(const std::string &filename, const LArOnOffIdMapping *cabling, bool withGain, int nvar)
Definition: FixLArElecCalib.cxx:1214
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode fix9 ATLAS_NOT_THREAD_SAFE(const LArOnOffIdMapping *cabling)
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode fix17 ATLAS_NOT_THREAD_SAFE(const LArOnOffIdMapping *cabling)
FixLArElecCalib::m_fixFlag
IntegerProperty m_fixFlag
Definition: FixLArElecCalib.h:70
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode updateMinBias ATLAS_NOT_THREAD_SAFE(const std::string &filename, const LArOnOffIdMapping *cabling)
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode fix7 ATLAS_NOT_THREAD_SAFE(const LArOnOffIdMapping *cabling)
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode fix16 ATLAS_NOT_THREAD_SAFE()
FixLArElecCalib::initialize
virtual StatusCode initialize() override
Definition: FixLArElecCalib.cxx:125
LArSingleFloatP
Definition: LArSingleFloatP.h:11
LArRampP1
Persistent data for LArRamp Copied from LAr.
Definition: LArRampP1.h:24
LArCalibLineMapping
Definition: LArCalibLineMapping.h:17
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
skel.it
it
Definition: skel.GENtoEVGEN.py:407
LArAutoCorrP1
c-struct reproducing the structure of the persistent data
Definition: LArAutoCorrP1.h:25
ATLAS_NOT_THREAD_SAFE
StatusCode FixLArElecCalib::update_EM_HEC ATLAS_NOT_THREAD_SAFE(const std::string &em_filename, const std::string &hec_filename, const LArOnOffIdMapping *cabling, bool withGain, int nvar)
Definition: FixLArElecCalib.h:144
LArMphysOverMcalMC.h
LArHEC_ID
Helper class for LArHEC offline identifiers.
Definition: LArHEC_ID.h:76
FixLArElecCalib::~FixLArElecCalib
virtual ~FixLArElecCalib()=default
FixLArElecCalib::m_sonline_idhelper
const LArOnline_SuperCellID * m_sonline_idhelper
Definition: FixLArElecCalib.h:129
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode fix10 ATLAS_NOT_THREAD_SAFE(const LArOnOffIdMapping *cabling)
FixLArElecCalib::m_hec_idhelper
const LArHEC_ID * m_hec_idhelper
Definition: FixLArElecCalib.h:124
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
FixLArElecCalib::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: FixLArElecCalib.h:67
FixLArElecCalib::m_fcal_idhelper
const LArFCAL_ID * m_fcal_idhelper
Definition: FixLArElecCalib.h:125
HWIdentifier
Definition: HWIdentifier.h:13
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
FixLArElecCalib::m_shec_idhelper
const LArHEC_SuperCell_ID * m_shec_idhelper
Definition: FixLArElecCalib.h:128
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode updateEMfSampl ATLAS_NOT_THREAD_SAFE(const std::string &filename, const LArOnOffIdMapping *cabling)
AthAlgorithm.h
LArEM_SuperCell_ID
Helper class for LArEM offline identifiers for supercells.
Definition: LArEM_SuperCell_ID.h:119
FixLArElecCalib
fix electronic calibration constants for MC.
Definition: FixLArElecCalib.h:36
LArOnOffIdMapping.h
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode updateHADfSampl ATLAS_NOT_THREAD_SAFE(const LArOnOffIdMapping *cabling)
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Ringer::EM
@ EM
Definition: CaloRingsDefs.h:19
FixLArElecCalib::m_em_idhelper
const LArEM_ID * m_em_idhelper
Definition: FixLArElecCalib.h:123
CaloCell_SuperCell_ID
Helper class for offline supercell identifiers.
Definition: CaloCell_SuperCell_ID.h:45
FixLArElecCalib::m_sem_idhelper
const LArEM_SuperCell_ID * m_sem_idhelper
Definition: FixLArElecCalib.h:127
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArRampMC.h
beamspotman.n
n
Definition: beamspotman.py:727
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LArShapeP1
c-struct reproducing the structure of the persistent data
Definition: LArShapeP1.h:16
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode fix5 ATLAS_NOT_THREAD_SAFE(const LArOnOffIdMapping *cabling)
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode fix4 ATLAS_NOT_THREAD_SAFE(const LArOnOffIdMapping *cabling)
FixLArElecCalib::m_online_idhelper
const LArOnlineID * m_online_idhelper
Definition: FixLArElecCalib.h:126
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
WriteCellNoiseToCool.igain
igain
Definition: WriteCellNoiseToCool.py:338
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode fix15 ATLAS_NOT_THREAD_SAFE()
FixLArElecCalib::m_g4Phys
StringProperty m_g4Phys
Definition: FixLArElecCalib.h:71
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode updateEM_DACuAMeV ATLAS_NOT_THREAD_SAFE(const std::string &filename, const LArOnOffIdMapping *cabling)
FixLArElecCalib::fix14
StatusCode fix14(const LArOnOffIdMapping *cabling)
Definition: FixLArElecCalib.cxx:2069
AthAlgorithm
Definition: AthAlgorithm.h:47
LArNoiseP
Definition: LArNoiseP.h:12
ReadCondHandleKey.h
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
FixLArElecCalib::set_object
void set_object(LArNoiseMC::LArCondObj &obj, const std::vector< float > &v)
Definition: FixLArElecCalib.cxx:1290
FixLArElecCalib::execute
virtual StatusCode execute() override
Definition: FixLArElecCalib.cxx:143
HWIdentifier.h
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode fix11 ATLAS_NOT_THREAD_SAFE(const LArOnOffIdMapping *cabling)
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
LArAutoCorrMC.h
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode update_EM_HEC ATLAS_NOT_THREAD_SAFE(const std::string &em_filename, const std::string &hec_filename, const LArOnOffIdMapping *cabling, bool withGain, int nvar)
LArOnlineID
Definition: LArOnlineID.h:21
FixLArElecCalib::print_object
void print_object(const std::string &msg, const LArNoiseMC::LArCondObj &obj)
Definition: FixLArElecCalib.cxx:1281
LArOnline_SuperCellID
Definition: LArOnline_SuperCellID.h:21
FixLArElecCalib::FixLArElecCalib
FixLArElecCalib(const std::string &name, ISvcLocator *pSvcLocator)
Definition: FixLArElecCalib.cxx:111
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
virtual StatusCode stop ATLAS_NOT_THREAD_SAFE() override
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode fix3 ATLAS_NOT_THREAD_SAFE(const LArOnOffIdMapping *cabling)
SG::ReadCondHandleKey< LArOnOffIdMapping >
python.PyAthena.v
v
Definition: PyAthena.py:154
FixLArElecCalib::m_cache
VROW_t m_cache[3]
Definition: FixLArElecCalib.h:138
FixLArElecCalib::fix2
StatusCode fix2(const LArOnOffIdMapping *cabling)
Definition: FixLArElecCalib.cxx:295
Identifier::getString
std::string getString() const
Provide a string form of the identifier - hexadecimal.
Definition: Identifier.cxx:25
FixLArElecCalib::fix13
StatusCode fix13(const LArOnOffIdMapping *cabling)
Definition: FixLArElecCalib.cxx:1726
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArShape32MC.h
LArHEC_SuperCell_ID
Helper class for LArHEC offline identifiers for supercells.
Definition: LArHEC_SuperCell_ID.h:56
FixLArElecCalib::fix18
StatusCode fix18(const LArCalibLineMapping *clmap)
Definition: FixLArElecCalib.cxx:2233
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
FixLArElecCalib::ROW_t
std::pair< HWIdentifier, std::vector< float > > ROW_t
Definition: FixLArElecCalib.h:135
FixLArElecCalib::VROW_t
std::vector< ROW_t > VROW_t
Definition: FixLArElecCalib.h:136
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:23
FixLArElecCalib::fix1
StatusCode fix1(const LArOnOffIdMapping *cabling)
Definition: FixLArElecCalib.cxx:219
FixLArElecCalib::ReadFile
StatusCode ReadFile(const std::string &filename, const LArOnOffIdMapping *cabling, bool EM, bool withGain, int nvar)
Definition: FixLArElecCalib.cxx:1142
PlotCalibFromCool.ngain
ngain
Definition: PlotCalibFromCool.py:565
FixLArElecCalib::addMphysOverMcal
StatusCode addMphysOverMcal(const LArOnOffIdMapping *cabling)
Definition: FixLArElecCalib.cxx:1424
FixLArElecCalib::update_DAC2uA
StatusCode update_DAC2uA(const std::string &em_filename, const std::string &hec_filename)
LArEM_ID
Helper class for LArEM offline identifiers.
Definition: LArEM_ID.h:111
FixLArElecCalib::fix12
StatusCode fix12(const LArOnOffIdMapping *cabling)
Definition: FixLArElecCalib.cxx:1997
FixLArElecCalib::m_CLKey
SG::ReadCondHandleKey< LArCalibLineMapping > m_CLKey
Definition: FixLArElecCalib.h:68
checker_macros.h
Define macros for attributes used to control the static checker.
python.PyAthena.obj
obj
Definition: PyAthena.py:132
LArFCAL_ID
Helper class for LArFCAL offline identifiers.
Definition: LArFCAL_ID.h:49
LArCalibLineMapping.h
FixLArElecCalib::m_infile
StringProperty m_infile
Definition: FixLArElecCalib.h:72
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode fixDACuAMeV ATLAS_NOT_THREAD_SAFE()
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
LArNoiseMC.h
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode update_All ATLAS_NOT_THREAD_SAFE(const std::string &filename, const LArOnOffIdMapping *cabling, bool withGain, int nvar)
FixLArElecCalib::ATLAS_NOT_THREAD_SAFE
StatusCode fix8 ATLAS_NOT_THREAD_SAFE(const LArOnOffIdMapping *cabling)
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
FixLArElecCalib::m_scell_idhelper
const CaloCell_SuperCell_ID * m_scell_idhelper
Definition: FixLArElecCalib.h:130