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 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 
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:169
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:206
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:224
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:572
RegSelSiLUT::initialise
void initialise()
Definition: RegSelSiLUT.cxx:139
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
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:169
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:228
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:364
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
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
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.
Identifier
Definition: IdentifierFieldParser.cxx:14