ATLAS Offline Software
StripClusterTruthDecorator.cxx
Go to the documentation of this file.
2 
3 //output
7 
8 #define AUXDATA(OBJ, TYP, NAME) \
9  static const SG::AuxElement::Accessor<TYP> acc_##NAME (#NAME); acc_##NAME(*(OBJ))
10 
11 
12 
13 namespace ActsTrk {
14 
16  ISvcLocator *pSvcLocator) :
17  AthReentrantAlgorithm(name, pSvcLocator)
18  {}
19 
20 
22 
23  // Read keys
25  ATH_CHECK(m_associationMap_key.initialize());
26 
27  // Write keys
28  ATH_CHECK(m_write_xaod_key.initialize());
29 
30  return StatusCode::SUCCESS;
31  }
32 
33  StatusCode StripClusterTruthDecorator::execute(const EventContext& ctx) const {
34 
36 
37  if (!StripClusterContainer.isValid()) {
38  ATH_MSG_ERROR("Failed Getting the strip cluster container "<<m_clustercontainer_key);
39  return StatusCode::FAILURE;
40  }
41 
42 
43  const MeasurementToTruthParticleAssociation* measToTruth(nullptr);
44  if (m_useTruthInfo) {
46 
47  if (measToTruthHandle.isValid()) {
48  measToTruth = &*measToTruthHandle;
49  } else {
50  ATH_MSG_ERROR("Measurement to Truth association map "<<m_associationMap_key.key()<<" not found!");
51  }
52  }
53 
54  // Setup outputs
55  // Create the xAOD container and its auxiliary store:
57  ATH_CHECK(xaod.record(std::make_unique<xAOD::TrackMeasurementValidationContainer>(),
58  std::make_unique<xAOD::TrackMeasurementValidationAuxContainer>()));
59 
60 
61  // loop over collection and convert to xAOD::TrackMeasurementValidation
62  for( const auto* prd : *StripClusterContainer ){
63 
64  //This needs to be taken care of
65  Identifier clusterId = Identifier((int)prd->identifier());
66  if ( !clusterId.is_valid() ) {
67  ATH_MSG_WARNING("Strip cluster identifier is not valid");
68  }
69 
71 
72  //unsigned int cluster_idx = xaod->size();
73  xaod->push_back(xprd);
74  //Set Identifier
75  xprd->setIdentifier( clusterId.get_compact() );
76 
77  //Set Global Position
78  auto gpos = prd->globalPosition();
79  xprd->setGlobalPosition(gpos.x(),gpos.y(),gpos.z());
80 
81  auto locpos = prd->localPosition<1>();
82  // Set local error matrix
83  xprd->setLocalPosition(locpos[0], locpos[1]);
84 
85 
86  auto localCov = prd->localCovariance<1>();
87 
88  if(localCov.size() == 1){
89  xprd->setLocalPositionError( localCov(0,0), 0., 0. );
90  } else if(localCov.size() == 4){
91  xprd->setLocalPositionError( localCov(0,0), localCov(1,1), localCov(0,1) );
92  } else {
93  xprd->setLocalPositionError(0.,0.,0.);
94  }
95 
96  // Get a list of all true particle contributing to the cluster
97 
98  if (measToTruth) {
99 
100  if (prd->index() >= (*measToTruth).size()) {
101  ATH_MSG_ERROR("PRD index "<< prd->index()<<" not present in the measurement to truth vector with size "<<(*measToTruth).size());
102  continue;
103  }
104 
105  auto tps = (*measToTruth)[prd->index()];
106 
107  //TODO:: reserve / resize?
108  std::vector<unsigned int> tp_indices;
109  std::vector<unsigned int> tp_barcodes;
110  for (auto tp : tps) {
111  tp_indices.push_back(tp->index());
112  tp_barcodes.push_back(tp->barcode());
113  }
114 
115  //TODO move vectors
116  AUXDATA(xprd,std::vector<unsigned int>, truth_index) = tp_indices;
117  AUXDATA(xprd,std::vector<unsigned int>, truth_barcode) = tp_barcodes;
118 
119  }// association map exists
120 
121  }// close loop on clusters
122 
123  ATH_MSG_DEBUG( " recorded StripPrepData objects: size " << xaod->size() );
124 
125  return StatusCode::SUCCESS;
126  }
127 
128 
130 
131  return StatusCode::SUCCESS;
132  }
133 
134 } // ActsTrk
ActsTrk::StripClusterTruthDecorator::m_clustercontainer_key
SG::ReadHandleKey< xAOD::StripClusterContainer > m_clustercontainer_key
Definition: StripClusterTruthDecorator.h:42
AUXDATA
#define AUXDATA(OBJ, TYP, NAME)
Definition: StripClusterTruthDecorator.cxx:8
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TrackMeasurementValidationAuxContainer.h
xAOD::TrackMeasurementValidation
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version:
Definition: TrackMeasurementValidation.h:13
ActsTrk::StripClusterTruthDecorator::StripClusterTruthDecorator
StripClusterTruthDecorator(const std::string &name, ISvcLocator *pSvcLocator)
Definition: StripClusterTruthDecorator.cxx:15
ParticleTest.tp
tp
Definition: ParticleTest.py:25
Identifier::get_compact
value_type get_compact() const
Get the compact id.
ActsTrk::MeasurementToTruthParticleAssociation
Definition: MeasurementToTruthParticleAssociation.h:18
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
ActsTrk::StripClusterTruthDecorator::m_associationMap_key
SG::ReadHandleKey< MeasurementToTruthParticleAssociation > m_associationMap_key
Definition: StripClusterTruthDecorator.h:45
xAOD::TrackMeasurementValidation_v1
Class describing a TrackMeasurementValidation.
Definition: TrackMeasurementValidation_v1.h:27
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::TrackMeasurementValidation_v1::setLocalPosition
void setLocalPosition(float localX, float localY)
Sets the local position.
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
ActsTrk::StripClusterTruthDecorator::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: StripClusterTruthDecorator.cxx:33
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
xAOD::TrackMeasurementValidation_v1::setIdentifier
void setIdentifier(uint64_t identifier)
Sets the identifier.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::TrackMeasurementValidation_v1::setGlobalPosition
void setGlobalPosition(float globalX, float globalY, float globalZ)
Sets the global position.
Definition: TrackMeasurementValidation_v1.cxx:50
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
xAOD::TrackMeasurementValidation_v1::setLocalPositionError
void setLocalPositionError(float localXError, float localYError, float localXYCorrelation)
Sets the local position error.
Definition: TrackMeasurementValidation_v1.cxx:37
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
ActsTrk::StripClusterTruthDecorator::finalize
virtual StatusCode finalize() override
Definition: StripClusterTruthDecorator.cxx:129
xAOD::StripClusterContainer
StripClusterContainer_v1 StripClusterContainer
Define the version of the strip cluster container.
Definition: StripClusterContainer.h:14
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
StripClusterTruthDecorator.h
TrackMeasurementValidation.h
TrackMeasurementValidationContainer.h
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:54
ActsTrk::StripClusterTruthDecorator::m_useTruthInfo
bool m_useTruthInfo
Definition: StripClusterTruthDecorator.h:52
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
ActsTrk::StripClusterTruthDecorator::initialize
virtual StatusCode initialize() override
Definition: StripClusterTruthDecorator.cxx:21
ActsTrk::StripClusterTruthDecorator::m_write_xaod_key
SG::WriteHandleKey< xAOD::TrackMeasurementValidationContainer > m_write_xaod_key
Definition: StripClusterTruthDecorator.h:47
Identifier
Definition: IdentifierFieldParser.cxx:14