ATLAS Offline Software
Loading...
Searching...
No Matches
LArGeoWeightsFill.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "LArGeoWeightsFill.h"
8#include "CaloDetDescr/CaloDetDescrElement.h"
9#include <fstream>
10
12#include "CoralBase/Blob.h"
13#include "CoralBase/Attribute.h"
14#include "CoralBase/AttributeList.h"
15#include "CoralBase/AttributeListSpecification.h"
16#include "CoolKernel/StorageType.h"
17
18
20
21
23
24 ATH_MSG_DEBUG ( "start initialize()" );
25 ATH_CHECK( detStore()->retrieve(m_onlineID,"LArOnlineID") );
26 ATH_CHECK( m_cablingKey.initialize() );
27 ATH_CHECK( m_caloMgrKey.initialize() );
28 ATH_CHECK( m_ttService.retrieve() );
29 return StatusCode::SUCCESS;
30}
31
33
34 ATH_MSG_DEBUG ( "start stop()" );
35
36 const unsigned hashMax=m_onlineID->channelHashMax();
37
38 if (m_fill) {
39
40 ATH_MSG_INFO ( "Filling database" );
41
42 coral::AttributeListSpecification* spec = new coral::AttributeListSpecification();
43 //cool::RecordSpecification* spec = new cool::RecordSpecification();
44 spec->extend("costheta", "blob");
45 spec->extend("sinthetacosphi", "blob");
46 spec->extend("sinthetasinphi", "blob");
47 spec->extend("offlineTTid","blob");
48
50 coral::Blob& costhetaBlob = (*attr)["costheta"].data<coral::Blob>();
51 coral::Blob& sinthetacosphiBlob = (*attr)["sinthetacosphi"].data<coral::Blob>();
52 coral::Blob& sinthetasinphiBlob = (*attr)["sinthetasinphi"].data<coral::Blob>();
53 coral::Blob& offlineTTidBlob = (*attr)["offlineTTid"].data<coral::Blob>();
54
55
56 costhetaBlob.resize(hashMax*sizeof(float));
57 sinthetacosphiBlob.resize(hashMax*sizeof(float));
58 sinthetasinphiBlob.resize(hashMax*sizeof(float));
59 offlineTTidBlob.resize(hashMax*sizeof(uint32_t));
60
61 float* pcostheta=static_cast<float*>(costhetaBlob.startingAddress());
62 float* psinthetacosphi=static_cast<float*>(sinthetacosphiBlob.startingAddress());
63 float* psinthetasinphi=static_cast<float*>(sinthetasinphiBlob.startingAddress());
64 uint32_t* pofflineTTid=static_cast<uint32_t*>(offlineTTidBlob.startingAddress());
65
66 ATH_CHECK( detStore()->record(attr,m_key) );
67
69 ATH_CHECK(caloMgrHandle.isValid());
70 const CaloDetDescrManager *theCaloDDM = *caloMgrHandle;
71 ATH_MSG_INFO ( "theCaloDDM retrieved" );
73 const LArOnOffIdMapping* cabling{*cablingHdl};
74 if(!cabling) {
75 ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
76 return StatusCode::FAILURE;
77 }
78
79 for (unsigned hs=0;hs<hashMax;++hs) {
80 const HWIdentifier chid=m_onlineID->channel_Id(hs);
81
82 if(!cabling->isOnlineConnected(chid)){
83 ATH_MSG_DEBUG ( "cell chid: " << chid.get_compact() << " not connected channel, skip " );
84 //Set values for disconnected cells to 0
85 pcostheta[hs]=0.0;
86 psinthetacosphi[hs]=0.0;
87 psinthetasinphi[hs]=0.0;
88 pofflineTTid[hs]=0;
89 continue;
90 }
91 const Identifier id=cabling->cnvToIdentifier(chid);
92 const CaloDetDescrElement *caloDDE = theCaloDDM->get_element(id);
93 if(!caloDDE){
94 ATH_MSG_ERROR ( "Failed to return CaloDetDescrElement" );
95 return StatusCode::FAILURE;
96 }
97 ATH_MSG_DEBUG ( "hash, eta, phi: " << caloDDE->calo_hash() << ", " << caloDDE->eta() << ", " << caloDDE->phi() );
98
99 const float eta = caloDDE->eta();
100 const float phi = caloDDE->phi();
101 const float v = 1./cosh(eta); // sintheta
102 const float costheta=tanh(eta);
103 const float sinthetacosphi=v*cos(phi);
104 const float sinthetasinphi=v*sin(phi);
105
106 pcostheta[hs]=costheta;
107 psinthetacosphi[hs]=sinthetacosphi;
108 psinthetasinphi[hs]=sinthetasinphi;
109 pofflineTTid[hs]=m_ttService->whichTTID(id).get_identifier32().get_compact();
110 } // end loop over hash ids
111 }//end if FILL
112
113
114 if (m_dump) {
115
116 const AthenaAttributeList* attr=0;
117
118 ATH_CHECK( detStore()->retrieve(attr,m_key) );
119
120 const coral::Blob& costhetaBlob = (*attr)["costheta"].data<coral::Blob>();
121 const coral::Blob& sinthetacosphiBlob = (*attr)["sinthetacosphi"].data<coral::Blob>();
122 const coral::Blob& sinthetasinphiBlob = (*attr)["sinthetasinphi"].data<coral::Blob>();
123 const coral::Blob& offlineTTidBlob = (*attr)["offlineTTid"].data<coral::Blob>();
124
125 const float* pcostheta=static_cast<const float*>(costhetaBlob.startingAddress());
126 const float* psinthetacosphi=static_cast<const float*>(sinthetacosphiBlob.startingAddress());
127 const float* psinthetasinphi=static_cast<const float*>(sinthetasinphiBlob.startingAddress());
128 const uint32_t* pofflineTTid=static_cast<const uint32_t*>(offlineTTidBlob.startingAddress());
129
130
131 std::ostream *out = &(std::cout);
132 std::ofstream outfile;
133 if (m_outFileName.size()) {
134 outfile.open(m_outFileName,std::ios::out);
135 if (outfile.is_open()) {
136 ATH_MSG_INFO ( "Writing to file " << m_outFileName );
137 out = &outfile;
138 }
139 else
140 ATH_MSG_ERROR ( "Failed to open file " << m_outFileName );
141 }
142
143 for (unsigned hs=0;hs<hashMax;++hs) {
144 const HWIdentifier chid=m_onlineID->channel_Id(hs);
145 (*out) << std::hex << chid.get_identifier32().get_compact() << std::dec << " "
146 << pcostheta[hs] << " " << psinthetacosphi[hs] << " " << psinthetasinphi[hs]
147 << " 0x"<< std::hex << pofflineTTid[hs] << std::dec << std::endl;
148 }
149
150
151 if (outfile.is_open())
152 outfile.close();
153 }// end if m_dump
154
155 return StatusCode::SUCCESS;
156}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
const ServiceHandle< StoreGateSvc > & detStore() const
An AttributeList represents a logical row of attributes in a metadata table.
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...
value_type get_compact() const
Get the compact id.
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
StringProperty m_outFileName
ToolHandle< CaloTriggerTowerService > m_ttService
BooleanProperty m_dump
const LArOnlineID * m_onlineID
BooleanProperty m_fill
virtual StatusCode stop() override
StringProperty m_key
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
virtual StatusCode initialize() override
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey