ATLAS Offline Software
PixelClusterTruthDecorator.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 namespace ActsTrk {
12 
13  PixelClusterTruthDecorator::PixelClusterTruthDecorator(const std::string& name, ISvcLocator *pSvcLocator) :
14  AthReentrantAlgorithm(name, pSvcLocator)
15  {}
16 
18 
19  // Read keys
21  ATH_CHECK(m_associationMap_key.initialize());
22 
23  // Write keys
24  ATH_CHECK(m_write_xaod_key.initialize());
25  //ATH_CHECK(m_write_offsets.initialize());
26 
27  return StatusCode::SUCCESS;
28  }
29 
30 StatusCode PixelClusterTruthDecorator::execute(const EventContext& ctx) const {
31 
32  //Mandatory. Require if the algorithm is scheduled.
34 
35  // Get the truth association map
36  const MeasurementToTruthParticleAssociation* measToTruth(nullptr);
37  if (m_useTruthInfo) {
39 
40  if (measToTruthHandle.isValid()) {
41  measToTruth = &*measToTruthHandle;
42  } else {
43  ATH_MSG_ERROR("MeasurementToTruthParticlesAssociation "<<m_associationMap_key.key()<<" not found!");
44  }
45  }
46 
47  // Setup outputs
48  // Create the xAOD container and its auxiliary store:
50  ATH_CHECK(xaod.record(std::make_unique<xAOD::TrackMeasurementValidationContainer>(),
51  std::make_unique<xAOD::TrackMeasurementValidationAuxContainer>()));
52 
53 
54  // loop over collection and convert to xAOD::TrackMeasurementValidation
55  for( const auto* prd : *PixelClusterContainer ){
56 
57  //This needs to be taken care of
58  Identifier clusterId = Identifier((int)prd->identifier());
59  if ( !clusterId.is_valid() ) {
60  ATH_MSG_WARNING("Pixel cluster identifier is not valid");
61  }
62 
64  //unsigned int cluster_idx = xaod->size();
65  xaod->push_back(xprd);
66  //Set Identifier
67  xprd->setIdentifier( clusterId.get_compact() );
68 
69  //Set Global Position
70  auto gpos = prd->globalPosition();
71  xprd->setGlobalPosition(gpos.x(),gpos.y(),gpos.z());
72 
73  auto locpos = prd->localPosition<2>();
74  // Set local error matrix
75  xprd->setLocalPosition(locpos[0], locpos[1]);
76 
77  auto localCov = prd->localCovariance<2>();
78  if(localCov.size() == 1){
79  xprd->setLocalPositionError( localCov(0,0), 0., 0. );
80  } else if(localCov.size() == 4){
81  xprd->setLocalPositionError( localCov(0,0), localCov(1,1), localCov(0,1) );
82  } else {
83  xprd->setLocalPositionError(0.,0.,0.);
84  }
85 
86  // Use the MultiTruth Collection
87  // to get a list of all true particle contributing to the cluster
88  if (measToTruth) {
89 
90  if (prd->index() >= (*measToTruth).size()) {
91  ATH_MSG_ERROR("PRD index "<< prd->index()<<" not present in the measurement to truth vector with size "<<(*measToTruth).size());
92  continue;
93  }
94  auto tps = (*measToTruth)[prd->index()];
95 
96 
97  std::vector<unsigned int> tp_indices;
98  std::vector<unsigned int> tp_barcodes;
99  for (auto tp : tps) {
100  tp_indices.push_back(tp->index());
101  tp_barcodes.push_back(tp->barcode());
102  }
103 
104  //TODO change how to decorate
105  AUXDATA(xprd,std::vector<unsigned int>, truth_index) = tp_indices;
106  AUXDATA(xprd,std::vector<unsigned int>, truth_barcode) = tp_barcodes;
107 
108 
109  }// association map exists
110 
111  }// close loop on clusters
112 
113  ATH_MSG_DEBUG( " recorded PixelPrepData objects: size " << xaod->size() );
114 
115  return StatusCode::SUCCESS;
116 }
117 
119 
120  return StatusCode::SUCCESS;
121  }
122 }
123 
124 
ActsTrk::PixelClusterTruthDecorator::finalize
virtual StatusCode finalize() override
Definition: PixelClusterTruthDecorator.cxx:118
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TrackMeasurementValidationAuxContainer.h
xAOD::TrackMeasurementValidation
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version:
Definition: TrackMeasurementValidation.h:13
ParticleTest.tp
tp
Definition: ParticleTest.py:25
Identifier::get_compact
value_type get_compact() const
Get the compact id.
ActsTrk::PixelClusterTruthDecorator::m_clustercontainer_key
SG::ReadHandleKey< xAOD::PixelClusterContainer > m_clustercontainer_key
Definition: PixelClusterTruthDecorator.h:43
ActsTrk::PixelClusterTruthDecorator::m_write_xaod_key
SG::WriteHandleKey< xAOD::TrackMeasurementValidationContainer > m_write_xaod_key
Definition: PixelClusterTruthDecorator.h:48
ActsTrk::MeasurementToTruthParticleAssociation
Definition: MeasurementToTruthParticleAssociation.h:18
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
ActsTrk::PixelClusterTruthDecorator::PixelClusterTruthDecorator
PixelClusterTruthDecorator(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PixelClusterTruthDecorator.cxx:13
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
PixelClusterTruthDecorator.h
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.
AUXDATA
#define AUXDATA(OBJ, TYP, NAME)
Definition: PixelClusterTruthDecorator.cxx:8
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ActsTrk::PixelClusterTruthDecorator::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: PixelClusterTruthDecorator.cxx:30
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
xAOD::PixelClusterContainer
PixelClusterContainer_v1 PixelClusterContainer
Define the version of the pixel cluster container.
Definition: Event/xAOD/xAODInDetMeasurement/xAODInDetMeasurement/PixelClusterContainer.h:14
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::PixelClusterTruthDecorator::m_useTruthInfo
bool m_useTruthInfo
Definition: PixelClusterTruthDecorator.h:53
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
TrackMeasurementValidation.h
TrackMeasurementValidationContainer.h
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:54
ActsTrk::PixelClusterTruthDecorator::initialize
virtual StatusCode initialize() override
Definition: PixelClusterTruthDecorator.cxx:17
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
ActsTrk::PixelClusterTruthDecorator::m_associationMap_key
SG::ReadHandleKey< MeasurementToTruthParticleAssociation > m_associationMap_key
Definition: PixelClusterTruthDecorator.h:45
Identifier
Definition: IdentifierFieldParser.cxx:14