ATLAS Offline Software
TRTRetriever.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TRTRetriever.h"
6 #include "StoreGate/DataHandle.h"
7 #include "JiveXML/DataType.h"
8 
11 #include "InDetIdentifier/TRT_ID.h"
13 
14 // ReadHandle
15 #include "StoreGate/ReadHandle.h"
16 
17 namespace JiveXML {
18 
25  TRTRetriever::TRTRetriever(const std::string& type,const std::string& name,const IInterface* parent):
27  {
28  //Declare the interface
29  declareInterface<IDataRetriever>(this);
30 
31  //And properties
32  declareProperty("TRTTruthMap" , m_TRTTruthMapKey = "PRD_MultiTruthTRT");
33  }
34 
36  ATH_CHECK( m_geo.retrieve() );
40  return StatusCode::SUCCESS;
41  }
42 
43  StatusCode TRTRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
44  //be verbose
45  ATH_MSG_DEBUG( "Retrieving " << dataTypeName() );
46 
47  //First try to retrieve the DriftCircleContainer
49  if ( !DriftCircleContainer.isValid() ) {
50  ATH_MSG_DEBUG( "Unable to retrive TRT_DriftCircleContainer with name " << m_TRTDriftCircleCollKey.key() );
51  return StatusCode::RECOVERABLE;
52  }
53 
54  //Also try to obtain the truth container
56  if ( m_useTRTTruthMap ) {
57  TRTMultiTruthMap = SG::makeHandle(m_TRTTruthMapKey);
58  if ( !TRTMultiTruthMap.isValid() ){
59  //Only warn if this container is not available
60  ATH_MSG_DEBUG( "Unable to retrieve PRD_MultiTruthCollection with name " << m_TRTTruthMapKey.key() );
61  }
62  }
63 
64  //Get total size of all all drift circles in all collections
65  unsigned long NDriftCircleTotal = 0;
66  //Loop over collections in container
67  for (const auto DriftCircleColl : *DriftCircleContainer)
68  NDriftCircleTotal += DriftCircleColl->size();
69 
70  //be verbose
71  ATH_MSG_VERBOSE( "Reserving space for " << NDriftCircleTotal << " entries" );
72 
73  //Rerserve space in the map
74  DataVect rhoz; rhoz.reserve(NDriftCircleTotal);
75  DataVect phi; phi.reserve(NDriftCircleTotal);
76  DataVect driftR; driftR.reserve(NDriftCircleTotal);
77  DataVect threshold; threshold.reserve(NDriftCircleTotal);
78  DataVect ident; ident.reserve(NDriftCircleTotal);
79  DataVect sub; sub.reserve(NDriftCircleTotal);
80  DataVect noise; noise.reserve(NDriftCircleTotal);
81  DataVect timeOverThreshold; timeOverThreshold.reserve(NDriftCircleTotal);
82  DataVect bitPattern; bitPattern.reserve(NDriftCircleTotal);
83  DataVect numBarcodes; numBarcodes.reserve(NDriftCircleTotal);
84  DataVect barcodes; barcodes.reserve(NDriftCircleTotal); //< on average less than one, so this should be enough
85 
86  //Now loop over container to retrieve the data
87  for (const auto DriftCircleColl : *DriftCircleContainer) {
88 
90  for (const auto driftcircle : *DriftCircleColl){
91 
92  //Get the drift cirlce itself and its unique identifier
93 
94  //In verbose mode, print out drift circle information
95  ATH_MSG_VERBOSE( "Retrieving information from " << (*driftcircle) );
96 
97  Identifier id = driftcircle->identify();
98 
99  //Check if it is valid
100  if (! id.is_valid()) {
101  ATH_MSG_DEBUG( "Ignoring TRT_DriftCircle with invalid identifier " << id );
102  continue;
103  }
104 
105  //Store the identifier
106  ident.push_back(DataType(id.get_compact()));
107 
112  const InDetDD::TRT_BaseElement* element = m_geo->TRTGeoManager()->getElement(m_geo->TRTIDHelper()->layer_id(id));
113 
114  //get global coord of straw
115  Amg::Vector3D global = element->strawTransform(m_geo->TRTIDHelper()->straw(id))*Amg::Vector3D(0.,0.,0.);
116 
117  //store the phi value
118  phi.push_back(DataType( (global.phi()<0) ? global.phi() + 2*M_PI : global.phi()));
119 
120  //store rho for barrel and z for endcap
121  if (element->type()==InDetDD::TRT_BaseElement::BARREL)
122  rhoz.push_back(DataType(global.perp()*CLHEP::mm/CLHEP::cm));
123  else if (element->type()==InDetDD::TRT_BaseElement::ENDCAP)
124  rhoz.push_back(DataType(global.z()*CLHEP::mm/CLHEP::cm));
125  else
126  ATH_MSG_VERBOSE( "Unknown TRT base element of type " << element->type() );
127 
128  //Store local position parameters
129  driftR.push_back(DataType((driftcircle->localPosition())[Trk::driftRadius]*CLHEP::mm/CLHEP::cm));
130 
131  //Get subdetector number
132  switch ( m_geo->TRTIDHelper()->barrel_ec(id) ) {
133  case -2 : sub.push_back(DataType( 0 )); break;
134  case -1 : sub.push_back(DataType( 1 )); break;
135  case 1 : sub.push_back(DataType( 2 )); break;
136  case 2 : sub.push_back(DataType( 3 )); break;
137  default : sub.push_back(DataType(-1 ));
138  }
139 
140  //Store threshold related parameters
141  threshold.push_back(DataType(driftcircle->highLevel()));
142  timeOverThreshold.push_back(DataType(driftcircle->timeOverThreshold()));
143  noise.push_back(DataType(driftcircle->isNoise()));
144  bitPattern.push_back(DataType(driftcircle->getWord()));
145 
149  if ( !m_useTRTTruthMap || !TRTMultiTruthMap.isValid() ) continue;
150 
151  //Count number of barcodes we get
152  int NBarcodes = 0;
153  //Loop over associated truth tracks with same id
154  using iter = PRD_MultiTruthCollection::const_iterator;
155  std::pair<iter,iter> equalIDRange = TRTMultiTruthMap->equal_range(id);
156  for ( iter TRTMultiTruthMapItr = equalIDRange.first; TRTMultiTruthMapItr != equalIDRange.second; ++TRTMultiTruthMapItr){
157  NBarcodes++;
158  barcodes.push_back(DataType(TRTMultiTruthMapItr->second.barcode()));
159  }
160  numBarcodes.push_back(DataType(NBarcodes));
161  } //loop over collection
162  }//loop over container
163 
164  //Add everything to our data map
166  dataMap["rhoz"]=rhoz;
167  dataMap["phi"]=phi;
168  dataMap["driftR"]=driftR;
169  dataMap["threshold"]=threshold;
170  dataMap["id"]=ident;
171  dataMap["sub"]=sub;
172  dataMap["noise"]=noise;
173  dataMap["timeOverThreshold"]=timeOverThreshold;
174  dataMap["bitPattern"]=bitPattern;
175 
176  //Only write truth association tags if we processed truth
177  if ( numBarcodes.size() > 0 ){
178  //Add barcodes counter
179  dataMap["numBarcodes"]=numBarcodes;
180  // Compute the "multiple" for barcodes and put the vector in the map.
181  std::string bctag = "barcodes multiple=\""+DataType(barcodes.size()/double(numBarcodes.size())).toString()+"\"";
182  dataMap[bctag]=barcodes;
183  }
184 
185  //be verbose
186  ATH_MSG_DEBUG( dataTypeName() << ": " << rhoz.size() );
187 
188  //forward data to formating tool and return
189  return FormatTool->AddToEvent(dataTypeName(), "", &dataMap);
190  }
191 }
192 
DataType.h
TRT_DetectorManager.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
JiveXML::DataVect
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition: DataType.h:58
DataType
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Definition: RoIBResultByteStreamTool.cxx:25
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
JiveXML::TRTRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
Definition: TRTRetriever.cxx:43
InDetDD::global
@ global
Definition: InDetDD_Defs.h:16
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
DataHandle.h
ParamDefs.h
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
cm
const double cm
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
JiveXML::TRTRetriever::initialize
virtual StatusCode initialize()
initialize only geo model tool
Definition: TRTRetriever.cxx:35
python.Dumpers.barcodes
def barcodes(beg, end, sz)
Definition: Dumpers.py:2800
InDetDD::TRT_BaseElement::ENDCAP
@ ENDCAP
Definition: TRT_BaseElement.h:61
LArHistMerge_trf.dataMap
dataMap
Definition: LArHistMerge_trf.py:218
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
Trk::driftRadius
@ driftRadius
trt, straws
Definition: ParamDefs.h:53
InDetDD::TRT_BaseElement::BARREL
@ BARREL
Definition: TRT_BaseElement.h:61
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
InDetDD::TRT_BaseElement::type
virtual TRT_BaseElement::Type type() const =0
Type information: returns BARREL or ENDCAP.
JiveXML::TRTRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type.
Definition: TRTRetriever.h:55
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:22
TRTRetriever.h
TRT_BaseElement.h
JiveXML::TRTRetriever::m_useTRTTruthMap
bool m_useTRTTruthMap
The StoreGate key for the TRT MultiTruthMap with the track associations.
Definition: TRTRetriever.h:69
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
threshold
Definition: chainparser.cxx:74
TRT::Hit::ident
@ ident
Definition: HitInfo.h:77
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
JiveXML::TRTRetriever::m_geo
const ToolHandle< IInDetGeoModelTool > m_geo
A tool handle to the geo model tool.
Definition: TRTRetriever.h:64
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
InDetDD::TRT_BaseElement::strawTransform
const Amg::Transform3D & strawTransform(unsigned int straw) const
Straw transform - fast access in array, in Tracking frame: Amg.
Definition: TRT_BaseElement.cxx:89
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
JiveXML::TRTRetriever::TRTRetriever
TRTRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: TRTRetriever.cxx:25
timeOverThreshold
double timeOverThreshold(unsigned int m_word)
Definition: driftCircle.h:116
python.CaloScaleNoiseConfig.default
default
Definition: CaloScaleNoiseConfig.py:79
ReadHandle.h
Handle class for reading from StoreGate.
AthAlgTool
Definition: AthAlgTool.h:26
JiveXML::TRTRetriever::m_TRTDriftCircleCollKey
SG::ReadHandleKey< InDet::TRT_DriftCircleContainer > m_TRTDriftCircleCollKey
The StoreGate key for the TRT Cluster collection to retrieve.
Definition: TRTRetriever.h:67
dumpTgcDigiThreshold.threshold
list threshold
Definition: dumpTgcDigiThreshold.py:34
JiveXML::TRTRetriever::m_TRTTruthMapKey
SG::ReadHandleKey< PRD_MultiTruthCollection > m_TRTTruthMapKey
Definition: TRTRetriever.h:70
WriteCellNoiseToCool.noise
noise
Definition: WriteCellNoiseToCool.py:380
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57
Identifier
Definition: IdentifierFieldParser.cxx:14