ATLAS Offline Software
TRT_RegSelCondAlg.cxx
Go to the documentation of this file.
1 
15 #include "GaudiKernel/EventIDRange.h"
17 
18 
21 
22 #include "GaudiKernel/MsgStream.h"
23 
26 
27 #include "InDetIdentifier/TRT_ID.h"
28 
29 #include "Identifier/Identifier.h"
31 
33 
34 #include <iostream>
35 #include <fstream>
36 #include <string>
37 #include <cmath>
38 
40 
41 #include "RegSelLUT/RegSelSiLUT.h"
42 
43 #include "TRT_RegSelCondAlg.h"
44 
45 
46 
47 
48 TRT_RegSelCondAlg::TRT_RegSelCondAlg(const std::string& name, ISvcLocator* pSvcLocator):
49  AthReentrantAlgorithm( 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() ");
63  ATH_CHECK(m_tableKey.initialize());
64  ATH_MSG_INFO("TRT_RegSelCondAlg::initialize() " << m_tableKey );
65  return StatusCode::SUCCESS;
66 }
67 
68 
69 
70 
71 StatusCode 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 Tool Service
100  IToolSvc* toolSvc;
101  if (StatusCode::SUCCESS != service("ToolSvc", toolSvc)) {
102  msg(MSG::ERROR) << " Can't get ToolSvc " << endmsg;
103  return StatusCode::FAILURE;
104  }
105 
106 
107 
108  // Get TRT cabling mapping
109 
110  ServiceHandle<ITRT_CablingSvc> mapping( "TRT_CablingSvc", name() );
111 
112  if ( mapping.retrieve().isFailure() ) {
113  msg(MSG::ERROR) << " Can't get TRT CablingSvc " << endmsg;
114  return StatusCode::FAILURE;
115  }
116 
117 
118  // Get the id helper
119  const TRT_ID* idHelper = nullptr;
120  if ( detStore()->retrieve( idHelper, "TRT_ID" ).isFailure() ) {
121  msg(MSG::FATAL) << "Could not get TRT ID helper" << endmsg;
122  return StatusCode::FAILURE;
123  }
124 
125  EventIDRange id_range;
126 
127  if( !trtDetEleHandle.range( id_range ) ) {
128  ATH_MSG_ERROR("Failed to retrieve validity range for " << trtDetEleHandle.key());
129  return StatusCode::FAILURE;
130  }
131 
132 
133  // Try and iterate over all elements.
134  // There is no iterator but we can get the elements via the idHash.
135 
136  unsigned int maxHash = idHelper->straw_layer_hash_max();
137 
138  // create the new TRT look up table
139 
140  std::unique_ptr<RegSelSiLUT> rd = std::make_unique<RegSelSiLUT>(RegSelSiLUT::TRT);
141 
142  constexpr double twoPi=2.*M_PI;
143  constexpr double InnerRadiusOfStraw = 2.; //hardcoded. No method? (it will NEVER change anyway)
144 
145  for (unsigned int index = 0; index < maxHash; index++) {
146  IdentifierHash idHash = index;
147  Identifier id = idHelper->layer_id(idHash);
148  int idBarrelEndcap = idHelper->barrel_ec(id);
149  int idSide = (idBarrelEndcap > 0);
150  int idLayerWheel = idHelper->layer_or_wheel(id);
151  int idPhiModule = idHelper->phi_module(id);
152  int idStrawLayer = idHelper->straw_layer(id);
153  const InDetDD::TRT_BarrelElement* Belement = nullptr;
154  const InDetDD::TRT_EndcapElement* Eelement = nullptr;
155  Identifier idelement;
156  double phiMin,phiMax,rz;
157  if (idHelper->is_barrel(id)) {
158  Belement = elements->getBarrelDetElement(idSide, idLayerWheel, idPhiModule, idStrawLayer);
159  idelement = Belement->identify();
160  int Nstraws = Belement->nStraws();
161  const int theLastStraw=Nstraws-1;
162  double Length = Belement->strawLength();
163  double x0 = Belement->strawXPos(0);
164  double x1 = Belement->strawXPos(theLastStraw);
165  double y0 = Belement->strawYPos(0);
166  double y1 = Belement->strawYPos(theLastStraw);
167  double r0 = sqrt(x0*x0 + y0*y0);
168  double r1 = sqrt(x1*x1 + y1*y1);
169  phiMin = std::atan2(y0,x0) - std::atan2(InnerRadiusOfStraw,r0); // over 0?
170  while (phiMin > M_PI) phiMin -= twoPi; //isnt there a 'mod' operation alternative??
171  while (phiMin < -M_PI) phiMin += twoPi;
172  phiMax = std::atan2(y1,x1) + std::atan2(InnerRadiusOfStraw,r1); // over 0?
173  while (phiMax > M_PI) phiMax -= twoPi;
174  while (phiMax < -M_PI) phiMax += twoPi;
175  double zmin = Belement->strawZPos(theLastStraw) - Length*0.5;
176  double zmax = Belement->strawZPos(theLastStraw) + Length*0.5;
177  double rmin = ( r0<r1 ? r0 : r1 ) - InnerRadiusOfStraw;
178  double rmax = ( r1>r0 ? r1 : r0 ) + InnerRadiusOfStraw;
179  std::vector<uint32_t> vrob = mapping->getRobID(idelement);
180  for (unsigned int ii=0 ; ii < vrob.size(); ++ii) {
181  RegSelModule smod( zmin, zmax, rmin, rmax, phiMin, phiMax, idLayerWheel, idSide, vrob[ii], idHash);
182  rd->addModule(smod);
183  }
184  } else {
185  Eelement = elements->getEndcapDetElement(idSide, idLayerWheel, idStrawLayer, idPhiModule);
186  idelement = Eelement->identify();
187  int Nstraws = Eelement->getDescriptor()->nStraws();
188  double pitch = Eelement->getDescriptor()->strawPitch();
189  double phi0 = Eelement->getDescriptor()->startPhi();
190  double length = Eelement->getDescriptor()->strawLength();
191  double radius = Eelement->getDescriptor()->innerRadius ();
192  //check the following line, was HepGeom::Point3D<double>
193  Amg::Vector3D center = Eelement->transform() * Amg::Vector3D(0,0,0);
194  double dphi = std::atan2(InnerRadiusOfStraw, radius );
195  phiMin = phi0 - dphi;
196  while (phiMin > M_PI) phiMin -= twoPi;
197  while (phiMin < -M_PI) phiMin += twoPi;
198  phiMax = phi0 + pitch * (Nstraws-1) + dphi;
199  while (phiMax > M_PI) phiMax -= twoPi;
200  while (phiMax < -M_PI) phiMax += twoPi;
201  rz = center.z();
202  //why was this variable set twice to different things?.. and then never used?
203  //double R = rz >= 0 ? radius : radius + length;
204  //double R = rz >= 0 ? radius + length : radius ;
205  // MS: infor for new maps
206  double zmin = rz-InnerRadiusOfStraw;
207  double zmax = rz+InnerRadiusOfStraw;
208  double rmin = radius;
209  double rmax = radius+length;
210  std::vector<uint32_t> vrob = mapping->getRobID(idelement);
211  for (unsigned int ii=0 ; ii < vrob.size(); ++ii) {
212  RegSelModule smod( zmin, zmax, rmin, rmax, phiMin, phiMax, idLayerWheel, idSide+2, vrob[ii], idHash);
213  rd->addModule(smod);
214  }
215  }
216  }
217 
218 
219 
220  // initialise and save the new look up table
221  ATH_MSG_DEBUG( " initialising new trt map " );
222 
223  rd->initialise();
224 
225  // write out new new LUT to a file if need be
226  if ( m_printTable ) rd->write( name()+".map" );
227 
228  IRegSelLUTCondData* rcd = new IRegSelLUTCondData( std::move(rd) );
229 
230  try {
234  // SG::WriteCondHandle<IRegSelLUTCondData> lutCondData( m_tableKey, ctx );
235  if( lutCondData.record( id_range, rcd ).isFailure() ) {
236  ATH_MSG_ERROR( "Could not record " << m_tableKey
237  << " " << lutCondData.key()
238  << " with range " << id_range );
239  return StatusCode::FAILURE;
240  }
241  ATH_MSG_INFO( "RegSelCondAlg LUT recorded: " << m_tableKey);
242  }
243  catch (...) {
244  ATH_MSG_ERROR("TRT_RegSelCondAlg::execute() failed to record table: " << m_tableKey);
245  return StatusCode::FAILURE;
246  }
247 
248 
249  ATH_MSG_DEBUG("TRT_RegSelCondAlg::execute() -- exit -- ");
250 
251  return StatusCode::SUCCESS;
252 }
253 
254 
255 
256 
257 
258 
259 
260 
261 
262 
263 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
InDetDD::TRT_BarrelElement::strawXPos
double strawXPos(unsigned int i) const
Get X Position: DEPRECATED.
RegSelModule
Definition: RegSelModule.h:38
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
RegSelCondData
Definition: RegSelCondData.h:25
TRT_ID::layer_id
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:500
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
InDetDD::TRT_BarrelElement
Definition: TRT_BarrelElement.h:44
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
InDetDD::TRT_EndcapDescriptor::innerRadius
double & innerRadius()
The inner radius:
Definition: TRT_EndcapDescriptor.cxx:49
TRT_RegSelCondAlg::TRT_RegSelCondAlg
TRT_RegSelCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TRT_RegSelCondAlg.cxx:48
PixelAthClusterMonAlgCfg.zmin
zmin
Definition: PixelAthClusterMonAlgCfg.py:176
index
Definition: index.py:1
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
InDetDD::TRT_DetElementContainer
Class to hold different TRT detector elements structures.
Definition: TRT_DetElementContainer.h:25
TRT_RegSelCondAlg::m_trtDetEleContKey
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetEleContKey
Definition: TRT_RegSelCondAlg.h:51
TRT_ID::straw_layer_hash_max
size_type straw_layer_hash_max(void) const
Definition: TRT_ID.h:920
InDetAccessor::phi0
@ phi0
Definition: InDetAccessor.h:33
InDetDD::TRT_BaseElement::nStraws
unsigned int nStraws() const
Number of straws in the element.
TRT_RegSelCondAlg.h
emacs: this is -*- c++ -*-
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
M_PI
#define M_PI
Definition: ActiveFraction.h:11
InDetDD::TRT_EndcapElement
Definition: TRT_EndcapElement.h:44
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:205
RegSelSiLUT.h
emacs: this is -*- c++ -*-
InDetDD::TRT_EndcapDescriptor::nStraws
unsigned int & nStraws()
The number of straws in a module:
Definition: TRT_EndcapDescriptor.cxx:33
SG::ReadCondHandle::range
bool range(EventIDRange &r)
Definition: ReadCondHandle.h:223
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:157
find_tgc_unfilled_channelids.mapping
mapping
Definition: find_tgc_unfilled_channelids.py:17
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
RegSelSiLUT::write
void write(std::ostream &s=std::cout) const
Definition: RegSelSiLUT.cxx:543
RegSelSiLUT::initialise
void initialise()
Definition: RegSelSiLUT.cxx:110
TRT_EndcapElement.h
SG::WriteCondHandle::fullKey
const DataObjID & fullKey() const
Definition: WriteCondHandle.h:41
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
RegSelSiLUT::TRT
@ TRT
Definition: RegSelSiLUT.h:45
TRT_RegSelCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TRT_RegSelCondAlg.cxx:71
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
InDetDD::TRT_BarrelElement::strawLength
virtual const double & strawLength() const override final
Get the length of the straws (active length):
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
WriteCondHandle.h
InDetDD::TRT_EndcapElement::getDescriptor
const TRT_EndcapDescriptor * getDescriptor() const
Returns a pointer to a descriptor, giving common information on module construction.
Definition: TRT_EndcapElement.cxx:82
TRT_PAI_physicsConstants::r0
const double r0
electron radius{cm}
Definition: TRT_PAI_physicsConstants.h:20
PixelAthClusterMonAlgCfg.zmax
zmax
Definition: PixelAthClusterMonAlgCfg.py:176
TRT_RegSelCondAlg::m_printTable
bool m_printTable
Definition: TRT_RegSelCondAlg.h:48
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
InDetDD::TRT_BaseElement::identify
virtual Identifier identify() const override final
identifier of this detector element:
TRT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: TRT_ID.h:866
TRT_ID::straw_layer
int straw_layer(const Identifier &id) const
Definition: TRT_ID.h:893
TRT_ID::layer_or_wheel
int layer_or_wheel(const Identifier &id) const
Definition: TRT_ID.h:884
TRT_BarrelElement.h
ITRT_CablingSvc.h
InDetDD::TRT_EndcapDescriptor::startPhi
double & startPhi()
The starting phi (angular!!)
Definition: TRT_EndcapDescriptor.cxx:41
InDetDD::TRT_DetElementContainer::getBarrelDetElement
const TRT_BarrelElement * getBarrelDetElement(unsigned int positive, unsigned int moduleIndex, unsigned int phiIndex, unsigned int strawLayerIndex) const
Definition: TRT_DetElementContainer.cxx:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
SG::WriteCondHandle::key
const std::string & key() const
Definition: WriteCondHandle.h:40
IdentifierHash.h
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
SiDetectorElementCollection.h
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
TRT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: TRT_ID.h:875
RegSelSiLUT::addModule
void addModule(RegSelModule &module)
Definition: RegSelSiLUT.h:71
ParticleGun_SamplingFraction.radius
radius
Definition: ParticleGun_SamplingFraction.py:96
SiDetectorElement.h
InDetDD::TRT_EndcapDescriptor::strawPitch
double & strawPitch()
The straw pitch (angular!!)
Definition: TRT_EndcapDescriptor.cxx:37
DeMoScan.index
string index
Definition: DeMoScan.py:362
TRT_ID
Definition: TRT_ID.h:84
TRT_ID::is_barrel
bool is_barrel(const Identifier &id) const
Test for barrel.
Definition: TRT_ID.h:857
InDetDD::TRT_BarrelElement::strawZPos
double strawZPos(unsigned int i) const
Get Z Position: (active center) DEPRECATED.
InDetDD::TRT_EndcapDescriptor::strawLength
double & strawLength()
Definition: TRT_EndcapDescriptor.cxx:45
TRT_RegSelCondAlg::m_tableKey
SG::WriteCondHandleKey< IRegSelLUTCondData > m_tableKey
Output conditions object.
Definition: TRT_RegSelCondAlg.h:55
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:248
TRT_Numerology.h
TRT_RegSelCondAlg::initialize
virtual StatusCode initialize() override
Definition: TRT_RegSelCondAlg.cxx:59
SG::ReadCondHandle::key
const std::string & key() const
Definition: ReadCondHandle.h:59
IdentifierHash
Definition: IdentifierHash.h:38
InDetDD::TRT_DetElementContainer::getEndcapDetElement
const TRT_EndcapElement * getEndcapDetElement(unsigned int positive, unsigned int wheelIndex, unsigned int strawLayerIndex, unsigned int phiIndex) const
Definition: TRT_DetElementContainer.cxx:62
InDetDD::TRT_BarrelElement::strawYPos
double strawYPos(unsigned int i) const
Get Y Position: DEPRECATED.
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
IRegSelLUTCondData
RegSelCondData< IRegSelLUT > IRegSelLUTCondData
Definition: IRegSelLUTCondData.h:20
ServiceHandle< ITRT_CablingSvc >
InDetDD::TRT_BaseElement::transform
virtual const Amg::Transform3D & transform() const override final
Element Surface: Get Transform of element in Tracking frame: Amg.