ATLAS Offline Software
CaloAddCellPedShift.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "CaloAddCellPedShift.h"
7 #include "CaloEvent/CaloCell.h"
8 #include "Identifier/Identifier.h"
9 //=== AttributeList
10 #include "CoralBase/Blob.h"
12 //=== CaloCondBlod
15 
16 
17 //__________________________________________________________________________
19 {
20  ATH_MSG_DEBUG ("CaloAddCellPedShift initialize()" );
21 
22  ATH_CHECK( m_caloCoolIdTool.retrieve() );
26  ATH_CHECK( detStore()->retrieve(m_onlineID,"LArOnlineID") );
27  ATH_CHECK( detStore()->retrieve(m_calo_id,"CaloCell_ID") );
28  ATH_CHECK( m_thistSvc.retrieve() );
29 
30  m_tree = new TTree("mytree","Calo Ped ntuple");
31  m_tree->Branch("iCool",&m_iCool,"iCool/I");
32  m_tree->Branch("iSubHash",&m_SubHash,"iSubHash/I");
33  m_tree->Branch("iHash",&m_Hash,"iHash/I");
34  m_tree->Branch("iOffId",&m_OffId,"iOffId/I");
35  m_tree->Branch("eta",&m_eta,"eta/F");
36  m_tree->Branch("phi",&m_phi,"phi/F");
37  m_tree->Branch("layer",&m_layer,"layer/I");
38  m_tree->Branch("iGain",&m_Gain,"iGain/I");
39  m_tree->Branch("bec",&m_bec,"bec/I");
40  m_tree->Branch("posneg",&m_posneg,"posneg/I");
41  m_tree->Branch("FT",&m_FT,"FT/I");
42  m_tree->Branch("slot",&m_slot,"slot/I");
43  m_tree->Branch("channel",&m_channel,"channel/I");
44  m_tree->Branch("Pedestal",&m_ped1,"Pedestal/F");
45  m_tree->Branch("PedestalCorr",&m_ped1corr,"PedestalCorr/F");
46  m_tree->Branch("PedLumi",&m_ped2,"PedLumi/F");
47 
48  ATH_CHECK( m_thistSvc->regTree("/file1/caloped/mytree",m_tree) );
49 
50  ATH_MSG_INFO ( " end of CaloAddCellPedShift::initialize " );
51  return StatusCode::SUCCESS;
52 }
53 
54 
55 //__________________________________________________________________________
57 {
58  ATH_MSG_DEBUG ("CaloAddCellPedShift execute()" );
59  return StatusCode::SUCCESS;
60 }
61 
62 //__________________________________________________________________________
64 {
66 
67  std::vector<float> pedShiftValue;
68  pedShiftValue.resize(ncell,0.);
69 
71  const LArOnOffIdMapping* cabling{*cablingHdl};
72  if(!cabling) {
73  ATH_MSG_ERROR("Do not have cabling mapping from key " << m_cablingKey.key() );
74  return StatusCode::FAILURE;
75  }
76 
77 
79  const CondAttrListCollection* attrListColl=*pedHdl;
80  if (!attrListColl) {
81  ATH_MSG_ERROR("Failed to retrieve CaloPedestal obj with key" << m_pedKey.key());
82  return StatusCode::FAILURE;
83  }
84 
85  std::map<unsigned int, const CaloCondBlobFlt*> pedBlobMap;
86  for (auto iColl=pedHdl->begin();iColl!=pedHdl->end();++iColl) {
87  //=== COOL channel number is system id
88  unsigned int sysId = static_cast<unsigned int>(iColl->first);
89  //=== Get new CaloCondBlobFlt instance, interpreting current BLOB
90  const coral::Blob& blob = (iColl->second)["CaloCondBlob16M"].data<coral::Blob>();
92  //=== store new pointer in map
93  pedBlobMap[sysId] = flt;
94  }//end iColl
95 
96 
97 
98  if (!m_fname.empty()) {
99  FILE* finput = fopen(m_fname.value().c_str(),"r");
100  ATH_MSG_INFO ( " opened file " << m_fname );
101  int bec;
102  int pos_neg;
103  int FT;
104  int slot;
105  int channel;
106  float pedShift;
107  while( fscanf(finput,"%d %d %d %d %d %f",&bec,&pos_neg,&FT,&slot,&channel,&pedShift) != EOF ) {
108  ATH_MSG_INFO ( " read linbe " << bec << " " << pos_neg << " " << FT << " " << slot << " " << channel << " " << pedShift );
109  HWIdentifier hwid = m_onlineID->channel_Id(bec,pos_neg,FT,slot,channel);
110  Identifier id = cabling->cnvToIdentifier( hwid);
112  int ii = (int) (idHash);
113  pedShiftValue[ii] = pedShift;
114  }
115  fclose(finput);
116  ATH_MSG_INFO ( " end of reading file" );
117  }
119  ATH_CHECK(caloMgrHandle.isValid());
120  const CaloDetDescrManager* calodetdescrmgr = *caloMgrHandle;
121 
122  FILE* fp = fopen("calopedestal.txt","w");
123  if (!fp) {
124  ATH_MSG_ERROR("Cannot open file calopedestal.txt for writing");
125  return StatusCode::FAILURE;
126  }
127  ATH_MSG_INFO ( " start loop over Calo cells " << ncell );
128  for (int i=0;i<ncell;i++) {
129  IdentifierHash idHash=i;
130  Identifier id=m_calo_id->cell_id(idHash);
131  const CaloDetDescrElement* calodde = calodetdescrmgr->get_element(id);
132  int subCalo;
133  IdentifierHash idSubHash = m_calo_id->subcalo_cell_hash (idHash, subCalo);
134 
135 #if 0
136  int iCool=-1;
137  if (m_calo_id->is_em(id)) { // EM calo
138  if (m_calo_id->is_em_barrel(id)) {
139  if (m_calo_id->pos_neg(id) > 0 )
140  iCool=2;
141  else
142  iCool=1;
143  }
144  if (m_calo_id->is_em_endcap(id)) {
145  if (m_calo_id->pos_neg(id) > 0 )
146  iCool=3;
147  else
148  iCool=0;
149  }
150 
151  }
152  if (m_calo_id->is_hec(id)) { // HEC
153  iCool=16;
154  }
155  if (m_calo_id->is_fcal(id)) { // Fcal
156  iCool=32;
157  }
158  if (m_calo_id->is_tile(id)) { // Tile
159  iCool=48;
160  }
161 #endif
162  int ii = (int) (idSubHash);
163 
164  int ngain;
165  if (subCalo<3) ngain=3;
166  else ngain=4;
167 
168  for (int igain=0;igain<ngain;igain++) {
169 
171  if (subCalo<3) {
175  }
176  else {
181  }
182 
183  unsigned int dbGain = CaloCondUtils::getDbCaloGain(gain);
184  unsigned int subHash2;
185  unsigned int iCool = m_caloCoolIdTool->getCoolChannelId(idHash,subHash2);
186  const CaloCondBlobFlt* const flt = pedBlobMap.find(iCool)->second;
187  float ped1_old= flt->getData(subHash2,dbGain,0);
188  float ped2= flt->getData(subHash2,dbGain,1);
189 
190  float ped1 = ped1_old + pedShiftValue[i];
191 
192  if (iCool<48) fprintf(fp,"%5u %5d %5d %8.3f %8.3f\n",iCool,ii,gain,ped1,ped2);
193 
194  m_iCool = iCool;
195  m_SubHash=ii;
196  m_Hash=i;
197  m_OffId=(int)(id.get_identifier32().get_compact());
198  m_eta = calodde->eta_raw();
199  m_phi = calodde->phi_raw();
201  m_Gain = gain;
202  if (iCool<48) {
203  HWIdentifier hwid = cabling->createSignalChannelID(id);
204  m_bec= m_onlineID->barrel_ec(hwid);
205  m_posneg= m_onlineID->pos_neg(hwid);
206  m_FT= m_onlineID->feedthrough(hwid);
207  m_slot= m_onlineID->slot(hwid);
208  m_channel= m_onlineID->channel(hwid);
209  } else {
210  m_bec=-1;
211  m_posneg=-1;
212  m_FT=-1;
213  m_slot=-1;
214  m_channel=-1;
215  }
216  m_ped1 = ped1_old;
217  m_ped1corr = ped1;
218  m_ped2 = ped2;
219  m_tree->Fill();
220 
221  if (std::fabs(ped1-ped1_old)>1.)
222  ATH_MSG_WARNING ( " Pedestal shift found for cell " << m_OffId << " HWID: " << m_bec << " " << m_posneg << " " << m_FT << " " << m_slot << " " << m_channel << " iCool " << iCool << " subHash " << ii << " New/Old pedestals " << ped1 << " " << ped1_old );
223 
224  } // loop over gains
225 
226  } // loop over cells
227 
228  fclose(fp);
229  return StatusCode::SUCCESS;
230  }
231 
233 {
234  return StatusCode::SUCCESS;
235 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CaloAddCellPedShift::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: CaloAddCellPedShift.h:55
CaloAddCellPedShift::m_fname
Gaudi::Property< std::string > m_fname
Definition: CaloAddCellPedShift.h:50
CaloAddCellPedShift::m_layer
int m_layer
Definition: CaloAddCellPedShift.h:70
CaloCell_Base_ID::calo_cell_hash
IdentifierHash calo_cell_hash(const Identifier cellId) const
create hash id from 'global' cell id
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
CaloAddCellPedShift::stop
virtual StatusCode stop() override
standard Athena-Algorithm method
Definition: CaloAddCellPedShift.cxx:63
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloAddCellPedShift::m_Hash
int m_Hash
Definition: CaloAddCellPedShift.h:66
CaloCondBlobFlt
Class for storing a number of floats (Flt) and functions on those.
Definition: CaloCondBlobFlt.h:29
CaloAddCellPedShift::m_posneg
int m_posneg
Definition: CaloAddCellPedShift.h:73
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
CaloAddCellPedShift::m_ped2
float m_ped2
Definition: CaloAddCellPedShift.h:79
CaloAddCellPedShift::m_pedKey
SG::ReadCondHandleKey< CondAttrListCollection > m_pedKey
Definition: CaloAddCellPedShift.h:57
CaloCell_Base_ID::is_em_endcap
bool is_em_endcap(const Identifier id) const
test if the id belongs to the EM Endcap
CaloCell_Base_ID::pos_neg
int pos_neg(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
CaloDetDescrManager_Base::get_element
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
Definition: CaloDetDescrManager.cxx:159
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
CaloAddCellPedShift::initialize
virtual StatusCode initialize() override
standard Athena-Algorithm method
Definition: CaloAddCellPedShift.cxx:18
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:1957
CaloAddCellPedShift::m_tree
TTree * m_tree
Definition: CaloAddCellPedShift.h:80
CaloAddCellPedShift::m_eta
float m_eta
Definition: CaloAddCellPedShift.h:68
CaloCell.h
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
CaloAddCellPedShift::finalize
virtual StatusCode finalize() override
standard Athena-Algorithm method
Definition: CaloAddCellPedShift.cxx:232
CaloCell_Base_ID::calo_sample
int calo_sample(const Identifier id) const
returns an int taken from Sampling enum and describing the subCalo to which the Id belongs.
Definition: CaloCell_Base_ID.cxx:141
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
CaloCell_Base_ID::is_tile
bool is_tile(const Identifier id) const
test if the id belongs to the Tiles
HWIdentifier
Definition: HWIdentifier.h:13
LArOnlineID_Base::barrel_ec
int barrel_ec(const HWIdentifier id) const
Return the position barrel or endcap of a hardware cell identifier: barrel_ec = [0,...
Definition: LArOnlineID_Base.cxx:1938
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
CaloCondUtils.h
CaloAddCellPedShift::m_channel
int m_channel
Definition: CaloAddCellPedShift.h:76
CaloAddCellPedShift::m_OffId
int m_OffId
Definition: CaloAddCellPedShift.h:67
CaloAddCellPedShift::m_SubHash
int m_SubHash
Definition: CaloAddCellPedShift.h:65
CaloGain::TILELOWLOW
@ TILELOWLOW
Definition: CaloGain.h:12
CaloCell_Base_ID::is_hec
bool is_hec(const Identifier id) const
test if the id belongs to the HEC
CaloAddCellPedShift::m_bec
int m_bec
Definition: CaloAddCellPedShift.h:72
CaloAddCellPedShift::m_phi
float m_phi
Definition: CaloAddCellPedShift.h:69
CaloDetDescrElement::eta_raw
float eta_raw() const
cell eta_raw
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:350
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
CaloGain::TILEHIGHHIGH
@ TILEHIGHHIGH
Definition: CaloGain.h:15
CaloCell_Base_ID::is_em
bool is_em(const Identifier id) const
test if the id belongs to LArEM
CaloAddCellPedShift::m_ped1
float m_ped1
Definition: CaloAddCellPedShift.h:77
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:1963
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloCell_Base_ID::calo_cell_hash_max
size_type calo_cell_hash_max() const
cell 'global' hash table max size
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloAddCellPedShift::m_thistSvc
ServiceHandle< ITHistSvc > m_thistSvc
Definition: CaloAddCellPedShift.h:53
trigmenu_modify_prescale_json.fp
fp
Definition: trigmenu_modify_prescale_json.py:53
CaloCell_Base_ID::is_fcal
bool is_fcal(const Identifier id) const
test if the id belongs to the FCAL - true also for MiniFCAL
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
LArOnlineID_Base::channel_Id
HWIdentifier channel_Id(int barrel_ec, int pos_neg, int feedthrough, int slot, int channel) const
create channel identifier from fields
Definition: LArOnlineID_Base.cxx:1565
CaloAddCellPedShift::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: CaloAddCellPedShift.h:56
LArOnlineID_Base::pos_neg
int pos_neg(const HWIdentifier id) const
Return the side of a hardware cell identifier pos_neg = [0,1] positive-side or negative-side Barrel...
Definition: LArOnlineID_Base.cxx:1950
CaloAddCellPedShift::m_ped1corr
float m_ped1corr
Definition: CaloAddCellPedShift.h:78
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloCell_Base_ID::subcalo_cell_hash
IdentifierHash subcalo_cell_hash(const Identifier cellId, int &subCalo) const
create hash id from 'global' cell id
WriteCellNoiseToCool.igain
igain
Definition: WriteCellNoiseToCool.py:338
CaloGain::TILEHIGHLOW
@ TILEHIGHLOW
Definition: CaloGain.h:14
LArDigits2NtupleDumper.FT
FT
Definition: LArDigits2NtupleDumper.py:77
CaloCondBlobAlgs_fillNoiseFromASCII.flt
flt
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:96
CaloCell_Base_ID::is_em_barrel
bool is_em_barrel(const Identifier id) const
test if the id belongs to the EM barrel
CaloAddCellPedShift.h
ReadCellNoiseFromCool.ncell
ncell
Definition: ReadCellNoiseFromCool.py:197
CaloGain::TILELOWHIGH
@ TILELOWHIGH
Definition: CaloGain.h:13
CaloAddCellPedShift::m_FT
int m_FT
Definition: CaloAddCellPedShift.h:74
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloGain::LARHIGHGAIN
@ LARHIGHGAIN
Definition: CaloGain.h:18
CaloAddCellPedShift::m_slot
int m_slot
Definition: CaloAddCellPedShift.h:75
CaloCell_Base_ID::cell_id
Identifier cell_id(const int subCalo, const int barec_or_posneg, const int sampling_or_fcalmodule, const int region_or_dummy, const int eta, const int phi) const
Make a cell (== channel) ID from constituting fields and subCalo index; for (Mini)FCAL,...
CaloCondUtils::getDbCaloGain
static unsigned int getDbCaloGain(int caloGain)
Returns the non-negative gainId to be used with the COOL DB.
Definition: CaloCondUtils.cxx:86
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
CaloGain::LARMEDIUMGAIN
@ LARMEDIUMGAIN
Definition: CaloGain.h:18
CaloCondBlobFlt.h
LArOnlineID_Base::feedthrough
int feedthrough(const HWIdentifier id) const
Return the feedthrough of a hardware cell identifier : feedthrough = [0,31] Barrel - A/C side or H/...
Definition: LArOnlineID_Base.cxx:1944
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
CaloCondBlobFlt::getInstance
static CaloCondBlobFlt * getInstance(coral::Blob &blob)
Returns a pointer to a non-const CaloCondBlobFlt.
Definition: CaloCondBlobFlt.cxx:12
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloAddCellPedShift::m_calo_id
const CaloCell_ID * m_calo_id
Definition: CaloAddCellPedShift.h:59
PlotCalibFromCool.ngain
ngain
Definition: PlotCalibFromCool.py:565
CaloAddCellPedShift::m_caloCoolIdTool
ToolHandle< ICaloCoolIdTool > m_caloCoolIdTool
Definition: CaloAddCellPedShift.h:62
CaloGain::LARLOWGAIN
@ LARLOWGAIN
Definition: CaloGain.h:18
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
CaloAddCellPedShift::m_onlineID
const LArOnlineID * m_onlineID
Definition: CaloAddCellPedShift.h:60
CaloAddCellPedShift::m_iCool
int m_iCool
Definition: CaloAddCellPedShift.h:64
CaloGain.h
CaloAddCellPedShift::execute
virtual StatusCode execute() override
standard Athena-Algorithm method
Definition: CaloAddCellPedShift.cxx:56
CaloAddCellPedShift::m_Gain
int m_Gain
Definition: CaloAddCellPedShift.h:71
CaloCondBlobAlgs_fillNoiseFromASCII.blob
blob
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:95
CaloDetDescrElement::phi_raw
float phi_raw() const
cell phi_raw
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:352
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
Identifier
Definition: IdentifierFieldParser.cxx:14