ATLAS Offline Software
LArGeoWeightsFill.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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 LArGeoWeightsFill::LArGeoWeightsFill(const std::string& name, ISvcLocator* pSvcLocator) :
19  AthAlgorithm(name,pSvcLocator),
20  m_onlineID(0),
21  m_ttService("CaloTriggerTowerService")
22 {
23  declareProperty("Key",m_key="GeoWeights");
24  declareProperty("Dump",m_dump=false);
25  declareProperty("OutFile",m_outFileName="out.txt");
26  //declareProperty("InFile",m_inFileName="");
27 
28  declareProperty("Fill",m_fill=true);
29 }
30 
32 
33 
35 
36  ATH_MSG_DEBUG ( "start initialize()" );
37  ATH_CHECK( detStore()->retrieve(m_onlineID,"LArOnlineID") );
40  ATH_CHECK( m_ttService.retrieve() );
41  return StatusCode::SUCCESS;
42 }
43 
45 
46  ATH_MSG_DEBUG ( "start stop()" );
47 
48  const unsigned hashMax=m_onlineID->channelHashMax();
49 
50  if (m_fill) {
51 
52  ATH_MSG_INFO ( "Filling database" );
53 
54  coral::AttributeListSpecification* spec = new coral::AttributeListSpecification();
55  //cool::RecordSpecification* spec = new cool::RecordSpecification();
56  spec->extend("costheta", "blob");
57  spec->extend("sinthetacosphi", "blob");
58  spec->extend("sinthetasinphi", "blob");
59  spec->extend("offlineTTid","blob");
60 
62  coral::Blob& costhetaBlob = (*attr)["costheta"].data<coral::Blob>();
63  coral::Blob& sinthetacosphiBlob = (*attr)["sinthetacosphi"].data<coral::Blob>();
64  coral::Blob& sinthetasinphiBlob = (*attr)["sinthetasinphi"].data<coral::Blob>();
65  coral::Blob& offlineTTidBlob = (*attr)["offlineTTid"].data<coral::Blob>();
66 
67 
68  costhetaBlob.resize(hashMax*sizeof(float));
69  sinthetacosphiBlob.resize(hashMax*sizeof(float));
70  sinthetasinphiBlob.resize(hashMax*sizeof(float));
71  offlineTTidBlob.resize(hashMax*sizeof(uint32_t));
72 
73  float* pcostheta=static_cast<float*>(costhetaBlob.startingAddress());
74  float* psinthetacosphi=static_cast<float*>(sinthetacosphiBlob.startingAddress());
75  float* psinthetasinphi=static_cast<float*>(sinthetasinphiBlob.startingAddress());
76  uint32_t* pofflineTTid=static_cast<uint32_t*>(offlineTTidBlob.startingAddress());
77 
78  ATH_CHECK( detStore()->record(attr,m_key) );
79 
81  ATH_CHECK(caloMgrHandle.isValid());
82  const CaloDetDescrManager *theCaloDDM = *caloMgrHandle;
83  ATH_MSG_INFO ( "theCaloDDM retrieved" );
85  const LArOnOffIdMapping* cabling{*cablingHdl};
86  if(!cabling) {
87  ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
88  return StatusCode::FAILURE;
89  }
90 
91  for (unsigned hs=0;hs<hashMax;++hs) {
92  const HWIdentifier chid=m_onlineID->channel_Id(hs);
93 
94  if(!cabling->isOnlineConnected(chid)){
95  ATH_MSG_DEBUG ( "cell chid: " << chid.get_compact() << " not connected channel, skip " );
96  //Set values for disconnected cells to 0
97  pcostheta[hs]=0.0;
98  psinthetacosphi[hs]=0.0;
99  psinthetasinphi[hs]=0.0;
100  pofflineTTid[hs]=0;
101  continue;
102  }
103  const Identifier id=cabling->cnvToIdentifier(chid);
104  const CaloDetDescrElement *caloDDE = theCaloDDM->get_element(id);
105  if(!caloDDE){
106  ATH_MSG_ERROR ( "Failed to return CaloDetDescrElement" );
107  return StatusCode::FAILURE;
108  }
109  ATH_MSG_DEBUG ( "hash, eta, phi: " << caloDDE->calo_hash() << ", " << caloDDE->eta() << ", " << caloDDE->phi() );
110 
111  const float eta = caloDDE->eta();
112  const float phi = caloDDE->phi();
113  const float v = 1./cosh(eta); // sintheta
114  const float costheta=tanh(eta);
115  const float sinthetacosphi=v*cos(phi);
116  const float sinthetasinphi=v*sin(phi);
117 
118  pcostheta[hs]=costheta;
119  psinthetacosphi[hs]=sinthetacosphi;
120  psinthetasinphi[hs]=sinthetasinphi;
121  pofflineTTid[hs]=m_ttService->whichTTID(id).get_identifier32().get_compact();
122  } // end loop over hash ids
123  }//end if FILL
124 
125 
126  if (m_dump) {
127 
128  const AthenaAttributeList* attr=0;
129 
130  ATH_CHECK( detStore()->retrieve(attr,m_key) );
131 
132  const coral::Blob& costhetaBlob = (*attr)["costheta"].data<coral::Blob>();
133  const coral::Blob& sinthetacosphiBlob = (*attr)["sinthetacosphi"].data<coral::Blob>();
134  const coral::Blob& sinthetasinphiBlob = (*attr)["sinthetasinphi"].data<coral::Blob>();
135  const coral::Blob& offlineTTidBlob = (*attr)["offlineTTid"].data<coral::Blob>();
136 
137  const float* pcostheta=static_cast<const float*>(costhetaBlob.startingAddress());
138  const float* psinthetacosphi=static_cast<const float*>(sinthetacosphiBlob.startingAddress());
139  const float* psinthetasinphi=static_cast<const float*>(sinthetasinphiBlob.startingAddress());
140  const uint32_t* pofflineTTid=static_cast<const uint32_t*>(offlineTTidBlob.startingAddress());
141 
142 
143  std::ostream *out = &(std::cout);
144  std::ofstream outfile;
145  if (m_outFileName.size()) {
146  outfile.open(m_outFileName.c_str(),std::ios::out);
147  if (outfile.is_open()) {
148  ATH_MSG_INFO ( "Writing to file " << m_outFileName );
149  out = &outfile;
150  }
151  else
152  ATH_MSG_ERROR ( "Failed to open file " << m_outFileName );
153  }
154 
155  for (unsigned hs=0;hs<hashMax;++hs) {
156  const HWIdentifier chid=m_onlineID->channel_Id(hs);
157  (*out) << std::hex << chid.get_identifier32().get_compact() << std::dec << " "
158  << pcostheta[hs] << " " << psinthetacosphi[hs] << " " << psinthetasinphi[hs]
159  << " 0x"<< std::hex << pofflineTTid[hs] << std::dec << std::endl;
160  }
161 
162 
163  if (outfile.is_open())
164  outfile.close();
165  }// end if m_dump
166 
167  return StatusCode::SUCCESS;
168 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArGeoWeightsFill::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: LArGeoWeightsFill.h:27
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
CaloCondBlobAlgs_fillNoiseFromASCII.spec
spec
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:47
LArGeoWeightsFill::initialize
virtual StatusCode initialize() override
Definition: LArGeoWeightsFill.cxx:34
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
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
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
LArGeoWeightsFill::m_fill
bool m_fill
Definition: LArGeoWeightsFill.h:34
LArGeoWeightsFill::stop
virtual StatusCode stop() override
Definition: LArGeoWeightsFill.cxx:44
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Identifier::get_compact
value_type get_compact() const
Get the compact id.
LArGeoWeightsFill::m_outFileName
std::string m_outFileName
Definition: LArGeoWeightsFill.h:35
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
HWIdentifier
Definition: HWIdentifier.h:13
AthenaAttributeList.h
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
LArGeoWeightsFill::m_onlineID
const LArOnlineID * m_onlineID
Definition: LArGeoWeightsFill.h:29
CaloCell_ID.h
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
LArGeoWeightsFill::m_ttService
ToolHandle< CaloTriggerTowerService > m_ttService
Definition: LArGeoWeightsFill.h:37
LArGeoWeightsFill::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: LArGeoWeightsFill.h:26
LArGeoWeightsFill::~LArGeoWeightsFill
~LArGeoWeightsFill()
Definition: LArGeoWeightsFill.cxx:31
CaloDetDescrElement::calo_hash
IdentifierHash calo_hash() const
cell calo hash
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:412
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CreatePhysValWebPage.hs
hs
Definition: CreatePhysValWebPage.py:107
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthenaAttributeList
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
Definition: PersistentDataModel/PersistentDataModel/AthenaAttributeList.h:45
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
LArOnlineID_Base::channelHashMax
size_type channelHashMax(void) const
Define channel hash tables max size.
Definition: LArOnlineID_Base.cxx:1897
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArGeoWeightsFill::m_key
std::string m_key
Definition: LArGeoWeightsFill.h:32
python.PyAthena.v
v
Definition: PyAthena.py:154
LArGeoWeightsFill::m_dump
bool m_dump
Definition: LArGeoWeightsFill.h:34
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
LArGeoWeightsFill::LArGeoWeightsFill
LArGeoWeightsFill(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArGeoWeightsFill.cxx:18
CaloDetDescrElement::eta
float eta() const
cell eta
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:344
CaloDetDescrElement::phi
float phi() const
cell phi
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:346
LArGeoWeightsFill.h
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42
LArOnlineID.h
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
Identifier
Definition: IdentifierFieldParser.cxx:14