ATLAS Offline Software
Loading...
Searching...
No Matches
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
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() );
23 ATH_CHECK( m_cablingKey.initialize() );
24 ATH_CHECK( m_caloMgrKey.initialize() );
25 ATH_CHECK( m_pedKey.initialize() );
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{
65 int ncell=m_calo_id->calo_cell_hash_max();
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);
111 IdentifierHash idHash = m_calo_id->calo_cell_hash(id);
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) {
172 if (igain==0) gain=CaloGain::LARHIGHGAIN;
173 if (igain==1) gain=CaloGain::LARMEDIUMGAIN;
174 if (igain==2) gain=CaloGain::LARLOWGAIN;
175 }
176 else {
177 if (igain==0) gain=CaloGain::TILELOWLOW;
178 if (igain==1) gain=CaloGain::TILELOWHIGH;
179 if (igain==2) gain=CaloGain::TILEHIGHLOW;
180 if (igain==3) gain=CaloGain::TILEHIGHHIGH;
181 }
182
183 unsigned int dbGain = CaloCondUtils::getDbCaloGain(gain);
184 unsigned int subHash2;
185 unsigned int iCool = m_caloCoolIdTool->getCoolChannelId(idHash,subHash2);
186 auto it = pedBlobMap.find(iCool);
187 if (it == pedBlobMap.end()) {
188 ATH_MSG_ERROR("Bad system id " << iCool);
189 fclose(fp);
190 return StatusCode::FAILURE;
191 }
192 const CaloCondBlobFlt* const flt = it->second;
193 float ped1_old= flt->getData(subHash2,dbGain,0);
194 float ped2= flt->getData(subHash2,dbGain,1);
195
196 float ped1 = ped1_old + pedShiftValue[i];
197
198 if (iCool<48) fprintf(fp,"%5u %5d %5d %8.3f %8.3f\n",iCool,ii,gain,ped1,ped2);
199
200 m_iCool = iCool;
201 m_SubHash=ii;
202 m_Hash=i;
203 m_OffId=(int)(id.get_identifier32().get_compact());
204 m_eta = calodde->eta_raw();
205 m_phi = calodde->phi_raw();
206 m_layer = m_calo_id->calo_sample(id);
207 m_Gain = gain;
208 if (iCool<48) {
209 HWIdentifier hwid = cabling->createSignalChannelID(id);
210 m_bec= m_onlineID->barrel_ec(hwid);
211 m_posneg= m_onlineID->pos_neg(hwid);
212 m_FT= m_onlineID->feedthrough(hwid);
213 m_slot= m_onlineID->slot(hwid);
214 m_channel= m_onlineID->channel(hwid);
215 } else {
216 m_bec=-1;
217 m_posneg=-1;
218 m_FT=-1;
219 m_slot=-1;
220 m_channel=-1;
221 }
222 m_ped1 = ped1_old;
223 m_ped1corr = ped1;
224 m_ped2 = ped2;
225 m_tree->Fill();
226
227 if (std::fabs(ped1-ped1_old)>1.)
228 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 );
229
230 } // loop over gains
231
232 } // loop over cells
233
234 fclose(fp);
235 return StatusCode::SUCCESS;
236 }
237
239{
240 return StatusCode::SUCCESS;
241}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
const ServiceHandle< StoreGateSvc > & detStore() const
ServiceHandle< ITHistSvc > m_thistSvc
const LArOnlineID * m_onlineID
SG::ReadCondHandleKey< CondAttrListCollection > m_pedKey
const CaloCell_ID * m_calo_id
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
virtual StatusCode finalize() override
standard Athena-Algorithm method
ToolHandle< ICaloCoolIdTool > m_caloCoolIdTool
virtual StatusCode initialize() override
standard Athena-Algorithm method
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
virtual StatusCode execute() override
standard Athena-Algorithm method
Gaudi::Property< std::string > m_fname
virtual StatusCode stop() override
standard Athena-Algorithm method
Class for storing a number of floats (Flt) and functions on those.
static CaloCondBlobFlt * getInstance(coral::Blob &blob)
Returns a pointer to a non-const CaloCondBlobFlt.
static unsigned int getDbCaloGain(int caloGain)
Returns the non-negative gainId to be used with the COOL DB.
This class groups all DetDescr information related to a CaloCell.
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
This class provides the client interface for accessing the detector description information common to...
This class is a collection of AttributeLists where each one is associated with a channel number.
This is a "hash" representation of an Identifier.
@ LARMEDIUMGAIN
Definition CaloGain.h:18
@ TILELOWLOW
Definition CaloGain.h:12
@ LARLOWGAIN
Definition CaloGain.h:18
@ TILELOWHIGH
Definition CaloGain.h:13
@ TILEHIGHLOW
Definition CaloGain.h:14
@ TILEHIGHHIGH
Definition CaloGain.h:15
@ LARHIGHGAIN
Definition CaloGain.h:18