ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_RegSelCondAlg.cxx
Go to the documentation of this file.
1
13
14
15#include "GaudiKernel/EventIDRange.h"
17
18
21
22#include "GaudiKernel/MsgStream.h"
23
26
28
29#include "Identifier/Identifier.h"
31
33
34#include <iostream>
35#include <fstream>
36#include <string>
37#include <cmath>
38
40
42
43#include "TRT_RegSelCondAlg.h"
44
45
46
47
48TRT_RegSelCondAlg::TRT_RegSelCondAlg(const std::string& name, ISvcLocator* pSvcLocator):
49 AthCondAlgorithm( name, pSvcLocator ),
50 m_printTable(false)
51{
52 ATH_MSG_DEBUG( "TRT_RegSelCondAlg::TRT_RegSelCondAlg() " << this->name() );
53 declareProperty( "PrintTable", m_printTable=false );
54}
55
56
57
58
60{
61 ATH_MSG_DEBUG("TRT_RegSelCondAlg::initialize() ");
62 ATH_CHECK(m_trtDetEleContKey.initialize());
63 ATH_CHECK(m_tableKey.initialize());
64 ATH_MSG_INFO("TRT_RegSelCondAlg::initialize() " << m_tableKey );
65 return StatusCode::SUCCESS;
66}
67
68
69
70
71StatusCode TRT_RegSelCondAlg::execute(const EventContext& ctx) const
72{
73
74 ATH_MSG_DEBUG( "Creating region selector table" );
75
77 if (lutCondData.isValid()) {
83 ATH_MSG_DEBUG("CondHandle " << lutCondData.fullKey() << " is already valid." );
84 return StatusCode::SUCCESS;
85 }
86
87
88 // Get TRT Detector Elements
90 const InDetDD::TRT_DetElementContainer* elements(*trtDetEleHandle);
91 if (not trtDetEleHandle.isValid() or elements==nullptr) {
92 ATH_MSG_FATAL(m_trtDetEleContKey.fullKey() << " is not available.");
93 return StatusCode::FAILURE;
94 }
95
96 ATH_MSG_DEBUG( "Retrieved Condition Object with TRT Detector Elements: " << m_trtDetEleContKey.fullKey() );
97
98
99 // Get TRT cabling mapping
100 ServiceHandle<ITRT_CablingSvc> mapping( "TRT_CablingSvc", name() );
101
102 if ( mapping.retrieve().isFailure() ) {
103 msg(MSG::ERROR) << " Can't get TRT CablingSvc " << endmsg;
104 return StatusCode::FAILURE;
105 }
106
107
108 // Get the id helper
109 const TRT_ID* idHelper = nullptr;
110 if ( detStore()->retrieve( idHelper, "TRT_ID" ).isFailure() ) {
111 msg(MSG::FATAL) << "Could not get TRT ID helper" << endmsg;
112 return StatusCode::FAILURE;
113 }
114
115 EventIDRange id_range;
116
117 if( !trtDetEleHandle.range( id_range ) ) {
118 ATH_MSG_ERROR("Failed to retrieve validity range for " << trtDetEleHandle.key());
119 return StatusCode::FAILURE;
120 }
121
122
123 // Try and iterate over all elements.
124 // There is no iterator but we can get the elements via the idHash.
125
126 unsigned int maxHash = idHelper->straw_layer_hash_max();
127
128 // create the new TRT look up table
129
130 std::unique_ptr<RegSelSiLUT> rd = std::make_unique<RegSelSiLUT>(RegSelSiLUT::TRT);
131
132 constexpr double twoPi=2.*M_PI;
133 constexpr double InnerRadiusOfStraw = 2.; //hardcoded. No method? (it will NEVER change anyway)
134
135 for (unsigned int index = 0; index < maxHash; index++) {
136 IdentifierHash idHash = index;
137 Identifier id = idHelper->layer_id(idHash);
138 int idBarrelEndcap = idHelper->barrel_ec(id);
139 int idSide = (idBarrelEndcap > 0);
140 int idLayerWheel = idHelper->layer_or_wheel(id);
141 int idPhiModule = idHelper->phi_module(id);
142 int idStrawLayer = idHelper->straw_layer(id);
143 const InDetDD::TRT_BarrelElement* Belement = nullptr;
144 const InDetDD::TRT_EndcapElement* Eelement = nullptr;
145 Identifier idelement;
146 double phiMin,phiMax,rz;
147 if (idHelper->is_barrel(id)) {
148 Belement = elements->getBarrelDetElement(idSide, idLayerWheel, idPhiModule, idStrawLayer);
149 idelement = Belement->identify();
150 int Nstraws = Belement->nStraws();
151 const int theLastStraw=Nstraws-1;
152 double Length = Belement->strawLength();
153 double x0 = Belement->strawXPos(0);
154 double x1 = Belement->strawXPos(theLastStraw);
155 double y0 = Belement->strawYPos(0);
156 double y1 = Belement->strawYPos(theLastStraw);
157 double r0 = sqrt(x0*x0 + y0*y0);
158 double r1 = sqrt(x1*x1 + y1*y1);
159 phiMin = std::atan2(y0,x0) - std::atan2(InnerRadiusOfStraw,r0); // over 0?
160 while (phiMin > M_PI) phiMin -= twoPi; //isnt there a 'mod' operation alternative??
161 while (phiMin < -M_PI) phiMin += twoPi;
162 phiMax = std::atan2(y1,x1) + std::atan2(InnerRadiusOfStraw,r1); // over 0?
163 while (phiMax > M_PI) phiMax -= twoPi;
164 while (phiMax < -M_PI) phiMax += twoPi;
165 double zmin = Belement->strawZPos(theLastStraw) - Length*0.5;
166 double zmax = Belement->strawZPos(theLastStraw) + Length*0.5;
167 double rmin = ( r0<r1 ? r0 : r1 ) - InnerRadiusOfStraw;
168 double rmax = ( r1>r0 ? r1 : r0 ) + InnerRadiusOfStraw;
169 std::vector<uint32_t> vrob = mapping->getRobID(idelement);
170 for (unsigned int ii=0 ; ii < vrob.size(); ++ii) {
171 RegSelModule smod( zmin, zmax, rmin, rmax, phiMin, phiMax, idLayerWheel, idSide, vrob[ii], idHash);
172 rd->addModule(smod);
173 }
174 } else {
175 Eelement = elements->getEndcapDetElement(idSide, idLayerWheel, idStrawLayer, idPhiModule);
176 idelement = Eelement->identify();
177 int Nstraws = Eelement->getDescriptor()->nStraws();
178 double pitch = Eelement->getDescriptor()->strawPitch();
179 double phi0 = Eelement->getDescriptor()->startPhi();
180 double length = Eelement->getDescriptor()->strawLength();
181 double radius = Eelement->getDescriptor()->innerRadius ();
182 //check the following line, was HepGeom::Point3D<double>
183 Amg::Vector3D center = Eelement->transform() * Amg::Vector3D(0,0,0);
184 double dphi = std::atan2(InnerRadiusOfStraw, radius );
185 phiMin = phi0 - dphi;
186 while (phiMin > M_PI) phiMin -= twoPi;
187 while (phiMin < -M_PI) phiMin += twoPi;
188 phiMax = phi0 + pitch * (Nstraws-1) + dphi;
189 while (phiMax > M_PI) phiMax -= twoPi;
190 while (phiMax < -M_PI) phiMax += twoPi;
191 rz = center.z();
192 //why was this variable set twice to different things?.. and then never used?
193 //double R = rz >= 0 ? radius : radius + length;
194 //double R = rz >= 0 ? radius + length : radius ;
195 // MS: infor for new maps
196 double zmin = rz-InnerRadiusOfStraw;
197 double zmax = rz+InnerRadiusOfStraw;
198 double rmin = radius;
199 double rmax = radius+length;
200 std::vector<uint32_t> vrob = mapping->getRobID(idelement);
201 for (unsigned int ii=0 ; ii < vrob.size(); ++ii) {
202 RegSelModule smod( zmin, zmax, rmin, rmax, phiMin, phiMax, idLayerWheel, idSide+2, vrob[ii], idHash);
203 rd->addModule(smod);
204 }
205 }
206 }
207
208
209
210 // initialise and save the new look up table
211 ATH_MSG_DEBUG( " initialising new trt map " );
212
213 rd->initialise();
214
215 // write out new new LUT to a file if need be
216 if ( m_printTable ) rd->write( name()+".map" );
217
218 IRegSelLUTCondData* rcd = new IRegSelLUTCondData( std::move(rd) );
219
220 try {
224 // SG::WriteCondHandle<IRegSelLUTCondData> lutCondData( m_tableKey, ctx );
225 if( lutCondData.record( id_range, rcd ).isFailure() ) {
226 ATH_MSG_ERROR( "Could not record " << m_tableKey
227 << " " << lutCondData.key()
228 << " with range " << id_range );
229 return StatusCode::FAILURE;
230 }
231 ATH_MSG_INFO( "RegSelCondAlg LUT recorded: " << m_tableKey);
232 }
233 catch (...) {
234 ATH_MSG_ERROR("TRT_RegSelCondAlg::execute() failed to record table: " << m_tableKey);
235 return StatusCode::FAILURE;
236 }
237
238
239 ATH_MSG_DEBUG("TRT_RegSelCondAlg::execute() -- exit -- ");
240
241 return StatusCode::SUCCESS;
242}
243
244
245
246
247
248
249
250
251
252
253
#define M_PI
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
double length(const pvec &v)
RegSelCondData< IRegSelLUT > IRegSelLUTCondData
static Double_t rz
emacs: this is -*- c++ -*-
This is an Identifier helper class for the TRT subdetector.
emacs: this is -*- c++ -*-
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Base class for conditions algorithms.
This is a "hash" representation of an Identifier.
Extended TRT_BaseElement to describe a TRT readout element, this is a planar layer with n ( order of ...
double strawXPos(unsigned int i) const
Get X Position: DEPRECATED.
double strawZPos(unsigned int i) const
Get Z Position: (active center) DEPRECATED.
virtual const double & strawLength() const override final
Get the length of the straws (active length):
double strawYPos(unsigned int i) const
Get Y Position: DEPRECATED.
unsigned int nStraws() const
Number of straws in the element.
virtual Identifier identify() const override final
identifier of this detector element:
virtual const Amg::Transform3D & transform() const override final
Element Surface: Get Transform of element in Tracking frame: Amg.
Class to hold different TRT detector elements structures.
const TRT_EndcapElement * getEndcapDetElement(unsigned int positive, unsigned int wheelIndex, unsigned int strawLayerIndex, unsigned int phiIndex) const
const TRT_BarrelElement * getBarrelDetElement(unsigned int positive, unsigned int moduleIndex, unsigned int phiIndex, unsigned int strawLayerIndex) const
double & strawPitch()
The straw pitch (angular!
double & startPhi()
The starting phi (angular!
unsigned int & nStraws()
The number of straws in a module:
double & innerRadius()
The inner radius:
Extended class of a TRT_BaseElement to describe a readout elment in the endcap.
const TRT_EndcapDescriptor * getDescriptor() const
Returns a pointer to a descriptor, giving common information on module construction.
bool range(EventIDRange &r)
const std::string & key() const
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
This is an Identifier helper class for the TRT subdetector.
Definition TRT_ID.h:82
int phi_module(const Identifier &id) const
Definition TRT_ID.h:806
Identifier layer_id(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer) const
For an individual straw layer.
Definition TRT_ID.h:494
size_type straw_layer_hash_max() const
Definition TRT_ID.h:851
bool is_barrel(const Identifier &id) const
Test for barrel.
Definition TRT_ID.h:788
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition TRT_ID.h:797
int layer_or_wheel(const Identifier &id) const
Definition TRT_ID.h:815
int straw_layer(const Identifier &id) const
Definition TRT_ID.h:824
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetEleContKey
TRT_RegSelCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteCondHandleKey< IRegSelLUTCondData > m_tableKey
Output conditions object.
virtual StatusCode initialize() override
Eigen::Matrix< double, 3, 1 > Vector3D
Definition index.py:1