ATLAS Offline Software
LArTTCellMap.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "GaudiKernel/MsgStream.h"
11 #include "GaudiKernel/ServiceHandle.h"
12 
13 #include "StoreGate/StoreGateSvc.h"
14 
15 #include <iostream>
16 
18  : AthMessaging ("LArTTCellMap")
19 {
20 }
21 
22 
24 {
25 
26 }
27 
28 
30 {
31 
32  convert_to_P(m);
33 
34  ATH_MSG_DEBUG( " LArTTCell size = "<<m.size() );
35 
36  ServiceHandle<StoreGateSvc> detStore ("DetectorStore", "LArTTCellMap");
37 
38  const LArEM_ID* em_id = nullptr;
39  const LArHEC_ID* hec_id = nullptr;
40  const LArFCAL_ID* fcal_id = nullptr;
41  const CaloLVL1_ID* lvl1_id = nullptr;
42 
43  StatusCode status=detStore->retrieve(em_id);
44  if(status.isFailure()){
45  ATH_MSG_ERROR( "Cannot retrieve em_id" );
46  }
47  status=detStore->retrieve(hec_id);
48  if(status.isFailure()){
49  ATH_MSG_ERROR( "Cannot retrieve hec_id" );
50  }
51  status=detStore->retrieve(fcal_id);
52  if(status.isFailure()){
53  ATH_MSG_ERROR( "Cannot retrieve fcal_id" );
54  }
55  status=detStore->retrieve(lvl1_id);
56  if(status.isFailure()){
57  ATH_MSG_ERROR( "Cannot retrieve lvl1_id" );
58  }
59  LArTTCell::const_iterator it = m.begin();
60  LArTTCell::const_iterator it_e = m.end();
61 
62  // useful in debug phase; can be removed afterwards
63  std::set<Identifier> cellIdSet;
64 
65  try {
66  for (; it!=it_e; ++it) {
67  const LArTTCell_t& t = *it;
68 
69  Identifier id ;
70 
71  if(t.det==0){
72  // EM
73  id = em_id->channel_id(t.pn,t.sample,t.region,t.eta,t.phi);
74  } else if(t.det==1){
75  // HEC
76  id = hec_id->channel_id(t.pn,t.sample,t.region,t.eta,t.phi);
77  } else if(t.det==2){
78  // FCAL sample==region
79  id = fcal_id->channel_id(t.pn,t.region,t.eta,t.phi);
80 
81  } else {
82  ATH_MSG_ERROR( " Wrong input Detector Number " << t.det );
83  }
84 
85  Identifier sid = lvl1_id->layer_id(t.tpn,t.tsample,t.tregion,t.teta,t.tphi,t.layer);
86 
87  ATH_MSG_VERBOSE( " db struct= "
88  <<" det="<<t.det
89  <<" pn="<<t.pn
90  <<" region="<<t.region
91  <<" sample="<<t.sample
92  <<" eta="<<t.eta<<" phi="<<t.phi
93  <<" trig pn="<<t.tpn
94  <<" trig region="<<t.tregion
95  <<" trig sample="<<t.tsample
96  <<" trig eta="<<t.teta<<" trig phi="<<t.tphi
97  <<" layer="<<t.layer );
98  ATH_MSG_VERBOSE( " lvl1 id = " << sid<<" offline id ="<<id );
99 
100  if(!(cellIdSet.insert(id)).second) {
101  ATH_MSG_ERROR( " Duplicate cell id "
102  << lvl1_id->show_to_string(id)
103  << " in TT= "
104  << lvl1_id->show_to_string(sid) );
105  }
106  m_cell2ttIdMap[id] = sid;
107 
108  std::map<Identifier,std::vector<Identifier> >::const_iterator it_find = m_tt2cellIdMap.find(sid);
109  if(it_find==m_tt2cellIdMap.end()) {
110  // a vector of Ids does not already exist for this sid, we reserve the number of elements
111  int nElements = 1;
112 
113  if(t.tsample==0) {
114  if(t.tregion==0) {
115  if(t.layer==0) {
116  nElements = 4;
117  } else if(t.layer==1) {
118  nElements = 32;
119  } else if(t.layer==2) {
120  nElements = 16;
121  } else if(t.layer==3) {
122  nElements = 8;
123  }
124 
125  } else if(t.tregion==1) {
126  nElements = 4;
127  } else if(t.tregion==2) {
128  nElements = 2;
129  } else if(t.tregion==3) {
130  nElements = 16;
131  }
132 
133  } else if(t.tsample==1) {
134  if(t.tregion==3) {
135  if(t.layer==0) {
136  nElements = 8;
137  } else if(t.layer==1) {
138  nElements = 4;
139  }
140  }
141  }
142  m_tt2cellIdMap[sid].reserve(nElements);
143  }
144  m_tt2cellIdMap[sid].push_back(id);
145  }
146  }
147 
148 
149  catch (LArID_Exception& except) {
150  ATH_MSG_ERROR( " Failed in LArTTCellMap::set " );
151  ATH_MSG_ERROR( (std::string) except );
152  }
153 
154  ATH_MSG_DEBUG( " LArTTCellMap::set : number of cell Ids="<<m_cell2ttIdMap.size() );
155 
156  detStore->release() ;
157 
158  return;
159 
160 }
161 
163 {
164 
165  std::map<Identifier,Identifier>::const_iterator it =m_cell2ttIdMap.find(id);
166 
167  if(it!=m_cell2ttIdMap.end()){
168  return (*it).second;
169  }
170 
171  ATH_MSG_ERROR( " Offline TT ID not found for cell "<< id );
172 
173  return Identifier();
174 
175 }
176 
177 
178 
179 
180 
181 const std::vector<Identifier>&
183 {
184 
185  std::map<Identifier,std::vector<Identifier> >::const_iterator
186  it=m_tt2cellIdMap.find(sid);
187 
188  if(it!=m_tt2cellIdMap.end()){
189  return (*it).second;
190  }
191 
192  ATH_MSG_VERBOSE( " vector of offline cell ID not found, TT id = " <<sid.get_compact() );
193 
194  static const std::vector<Identifier> v;
195  return v ;
196 
197 }
198 
200 {
201  return &m_persData;
202 }
203 
205 {
206  return &m_persData;
207 }
208 
210 {
211 
212  LArTTCell::const_iterator it = d.begin();
213  LArTTCell::const_iterator it_e = d.end();
214 
215  for ( ;it!=it_e;++it){
216  const LArTTCell_t& t = *it;
218 
219  t2.det = t.det;
220  t2.pn = t.pn;
221  t2.sample = t.sample;
222  t2.region = t.region;
223  t2.eta = t.eta;
224  t2.phi = t. phi;
225 
226  t2.tpn = t.tpn ;
227  t2.tsample = t.tsample;
228  t2.tregion = t.tregion;
229  t2.teta = t.teta;
230  t2.tphi = t.tphi;
231  t2.layer = t.layer;
232 
233  m_persData.m_v.push_back(t2);
234  }
235 
236 }
237 
238 
240 {
241 
242  std::vector<LArTTCell_P::__t>::const_iterator it = p.m_v.begin();
243  std::vector<LArTTCell_P::__t>::const_iterator it_e = p.m_v.end();
244 
245  d.clear();
246  for ( ;it!=it_e;++it){
247  const LArTTCell_P::__t& t = *it;
248  LArTTCell_t t2 ;
249 
250  t2.det = t.det ;
251  t2.pn = t.pn ;
252  t2.region = t.region;
253  t2.sample = t.sample;
254  t2.eta = t.eta ;
255  t2.phi = t.phi ;
256 
257  t2.tpn = t.tpn ;
258  t2.tregion = t.tregion;
259  t2.tsample = t.tsample;
260  t2.teta = t.teta ;
261  t2.tphi = t.tphi ;
262  t2.layer = t.layer ;
263 
264  d.push_back(t2);
265  }
266 
267 }
268 
270 {
271  LArTTCell d ;
272  convert_to_D(p,d);
273  set(d);
274  m_persData.m_version = p.m_version;
275  return ;
276 }
LArTTCellMap::m_tt2cellIdMap
std::map< Identifier, std::vector< Identifier > > m_tt2cellIdMap
Definition: LArTTCellMap.h:72
LArTTCellMap::set
void set(const PDATA &t)
initialize from Nova
Definition: LArTTCellMap.cxx:29
LArTTCellMap::convert_to_D
void convert_to_D(const LArTTCell_P &t, LArTTCell &d)
Definition: LArTTCellMap.cxx:239
LArEM_ID.h
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
hist_file_dump.d
d
Definition: hist_file_dump.py:137
LArTTCellMap::whichTTID
Identifier whichTTID(const Identifier &id) const
return the offline id (CaloLVL1_ID) of the TT to which a cell (CaloCell_ID) belongs
Definition: LArTTCellMap.cxx:162
skel.it
it
Definition: skel.GENtoEVGEN.py:423
LArTTCellMap::createCellIDvec
const std::vector< Identifier > & createCellIDvec(const Identifier &id) const
Return a vector of offline Identifiers (corresponding helpers = LArEM_ID, LArHEC_ID,...
Definition: LArTTCellMap.cxx:182
LArHEC_ID
Helper class for LArHEC offline identifiers.
Definition: LArHEC_ID.h:85
LArTTCell
std::vector< LArTTCell_t > LArTTCell
Definition: LArTTCell.h:35
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
LArHEC_ID.h
LArEM_Base_ID::channel_id
Identifier channel_id(const ExpandedIdentifier &exp_id) const
Build a cell identifier from an expanded identifier.
LArTTCellMap::LArTTCellMap
LArTTCellMap()
Definition: LArTTCellMap.cxx:17
CaloLVL1_ID::layer_id
Identifier layer_id(int pos_neg_z, int sampling, int region, int eta, int phi, int layer) const
build a layer identifier
Definition: CaloLVL1_ID.h:530
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArTTCellMap.h
LArTTCellMap::getP
const LArTTCell_P * getP() const
return the persistified map
Definition: LArTTCellMap.cxx:199
LArTTCellMap::convert_to_P
void convert_to_P(const LArTTCell &t)
Definition: LArTTCellMap.cxx:209
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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
LArFCAL_Base_ID::channel_id
Identifier channel_id(const ExpandedIdentifier &exp_id) const
cell identifier for a channel from ExpandedIdentifier
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
LArTTCell_P
This is a database object holding the offline TT-cell map.
Definition: LArTTCell_P.h:23
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
CaloLVL1_ID
Helper class for offline TT identifiers.
Definition: CaloLVL1_ID.h:66
LArTTCell_P::LArTTCell_P_t
Structure of the map.
Definition: LArTTCell_P.h:28
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:191
LArTTCell_P::m_version
int m_version
Definition: LArTTCell_P.h:56
LArHEC_Base_ID::channel_id
Identifier channel_id(const ExpandedIdentifier &exp_id) const
channel identifier for a channel from ExpandedIdentifier
LArTTCell_t
Structure definition of the LArTTCellMap.
Definition: LArTTCell.h:18
LArTTCellMap::m_cell2ttIdMap
std::map< Identifier, Identifier > m_cell2ttIdMap
Definition: LArTTCellMap.h:71
python.PyAthena.v
v
Definition: PyAthena.py:157
LArFCAL_ID.h
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
CaloLVL1_ID.h
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
AtlasDetectorID::show_to_string
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
Definition: AtlasDetectorID.cxx:574
LArTTCell_P::m_v
std::vector< __t > m_v
Definition: LArTTCell_P.h:54
LArEM_ID
Helper class for LArEM offline identifiers.
Definition: LArEM_ID.h:118
merge.status
status
Definition: merge.py:17
LArTTCellMap::~LArTTCellMap
~LArTTCellMap()
Definition: LArTTCellMap.cxx:23
LArFCAL_ID
Helper class for LArFCAL offline identifiers.
Definition: LArFCAL_ID.h:60
StoreGateSvc.h
LArID_Exception
Exception class for LAr Identifiers.
Definition: LArID_Exception.h:20
ServiceHandle< StoreGateSvc >
LArTTCellMap::m_persData
LArTTCell_P m_persData
Definition: LArTTCellMap.h:76