ATLAS Offline Software
EventInfoPixelDecorator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // EventInfoPixelDecorator.cxx, (c) ATLAS Detector software
8 // Author: David Salek (David.Salek@cern.ch)
9 // Decorator tool to store per-module summary information for pixel clusters
10 
18 #include <vector>
19 #include <string>
20 
21 namespace DerivationFramework {
22 
24  const std::string& name,
25  const IInterface* parent) :
27  {
28  declareInterface<DerivationFramework::IAugmentationTool>(this);
29  }
30 
32  {
33  ATH_MSG_VERBOSE("initialize() ...");
34 
35  if (m_selectionString.empty()) {
36  ATH_MSG_FATAL("No inner detector track selection string provided!");
37  return StatusCode::FAILURE;
38  } else {ATH_MSG_INFO("Selection string for the per-module pixel cluster decoration: " << m_selectionString);}
39 
40  if (m_decorationPrefix.empty()) {
41  ATH_MSG_WARNING("No decoration prefix name provided for the output of EventInfoPixelDecorator!");
42  }
43 
44  if (m_eventInfoKey.key().empty()) {
45  ATH_MSG_ERROR("No collection provided for EventInfoPixelDecorator!");
46  return StatusCode::FAILURE;
47  }
49 
50  //check xAOD::TrackMeasurementValidation collection
51  ATH_CHECK(m_pixelKey.initialize());
52  ATH_MSG_INFO("Using " << m_pixelKey.key() << " as the source collection for EventInfoPixelDecorator.");
53 
54  // Set up the text-parsing machinery
55  if (!m_selectionString.empty()) {
57  }
58 
59  {
60  std::vector<std::string> names;
61  names.resize(kNIntDecor);
62  names[kperModuleMultiplicity] ="perModuleMultiplicity";
63  names[klayer] ="layer";
64  names[keta_module] ="eta_module";
65  names[kphi_module] ="phi_module";
67  }
68 
69  return StatusCode::SUCCESS;
70  }
71 
73  {
74  ATH_MSG_VERBOSE("finalize() ...");
75  ATH_MSG_INFO("Processed "<< m_ntot <<" measurements, "<< m_npass<< " were used for the per-module summary");
77  return StatusCode::SUCCESS;
78  }
79 
81  {
82  ATH_MSG_DEBUG("Adding per-module information to EventInfo");
83  const EventContext& ctx = Gaudi::Hive::currentContext();
84 
86  CHECK( eventInfo.isValid() ? StatusCode::SUCCESS : StatusCode::FAILURE);
87 
88  // Get the cluster container
90  if (!clusters.isValid()) {
91  ATH_MSG_ERROR ("Couldn't retrieve TrackMeasurementValidationContainer with key" << m_pixelKey.key());
92  return StatusCode::FAILURE;
93  }
94 
95  // Check the event contains clusters
96  unsigned int nClusters = clusters->size();
97  if (nClusters==0) return StatusCode::SUCCESS;
98 
99  // Set up a mask with the same entries as the full collection
100  std::vector<bool> mask;
101  mask.assign(nClusters,false); // default: don't keep anything
102  m_ntot += nClusters;
103 
104  // Execute the text parser and update the mask
105  if (m_parser) {
106  std::vector<int> entries = m_parser->evaluateAsVector();
107  unsigned int nEntries = entries.size();
108  // check the sizes are compatible
109  if (nClusters != nEntries ) {
110  ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used the same collection as the input collection??");
111  return StatusCode::FAILURE;
112  } else {
113  // set mask
114  for (unsigned int i=0; i<nClusters; ++i) if (entries[i]==1) mask[i]=true;
115  }
116  }
117  // Count the mask
118  unsigned int n_pass=0;
119  for (unsigned int i=0; i<nClusters; ++i) {
120  if (mask[i]) ++n_pass;
121  }
122  m_npass += n_pass;
123 
124  // fill the per-module information
125  std::array<std::vector<int>,kNIntDecor> vec;
126 
127  unsigned int i=0;
128  std::vector<int> keys;
129  for (const xAOD::TrackMeasurementValidation* clusIt : *clusters) {
130 
131  if( !mask[++i] ) continue;
132 
133  static const SG::AuxElement::Accessor<int> acc_layer("layer");
134  int clus_layer = acc_layer(*clusIt);
135  static const SG::AuxElement::Accessor<int> acc_eta_module("eta_module");
136  int clus_eta_module = acc_eta_module(*clusIt);
137  static const SG::AuxElement::Accessor<int> acc_phi_module("phi_module");
138  int clus_phi_module = acc_phi_module(*clusIt);
139 
140  int key = clus_layer * 10000 + clus_eta_module * 100 + clus_phi_module;
141  unsigned int index = 9999;
142  for( unsigned int j = 0; j < keys.size() ; j++ )
143  if( key == keys[j] ){
144  index = j;
145  break;
146  }
147  if( index == 9999 ){
148  keys.push_back( key );
149  vec[klayer].push_back( clus_layer );
150  vec[keta_module].push_back( clus_eta_module );
151  vec[kphi_module].push_back( clus_phi_module );
152  vec[kperModuleMultiplicity].push_back( 1 );
153  } else {
154  assert(index < vec[kperModuleMultiplicity].size());
156  }
157  }
158 
159  std::vector<SG::WriteDecorHandle<xAOD::EventInfo,std::vector<int> > > int_decor_handles(createDecorators<xAOD::EventInfo,std::vector<int> >(m_intDecorKeys,ctx));
160  assert(int_decor_handles.size() == kNIntDecor);
161  for(unsigned int decorate_i=0; decorate_i<int_decor_handles.size(); ++decorate_i) {
162  int_decor_handles[decorate_i](*eventInfo) = std::move(vec[decorate_i]);
163  }
164 
165  return StatusCode::SUCCESS;
166  }
167 
168 }
DecoratorUtils.h
SGxAODProxyLoader.h
ExpressionParserUserBase< AthAlgTool, 1 >::finalizeParser
StatusCode finalizeParser()
DerivationFramework::EventInfoPixelDecorator::kphi_module
@ kphi_module
Definition: EventInfoPixelDecorator.h:51
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DerivationFramework::createDecoratorKeys
void createDecoratorKeys(T_Parent &parent, const SG::ReadHandleKey< T_Cont > &container_key, const std::string &prefix, const std::vector< std::string > &decor_names, std::vector< SG::WriteDecorHandleKey< T_Cont > > &decor_out)
Definition: DecoratorUtils.h:20
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthMsgStreamMacros.h
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
ExpressionParserUserBase< AthAlgTool, 1 >::m_parser
std::conditional< NUM_PARSER==1, std::unique_ptr< ExpressionParsing::ExpressionParser >, std::array< std::unique_ptr< ExpressionParsing::ExpressionParser >, NUM_PARSER > >::type m_parser
Definition: ExpressionParserUser.h:100
DerivationFramework::EventInfoPixelDecorator::m_ntot
std::atomic< unsigned int > m_ntot
Definition: EventInfoPixelDecorator.h:38
DerivationFramework::EventInfoPixelDecorator::finalize
StatusCode finalize()
Definition: EventInfoPixelDecorator.cxx:72
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
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
DerivationFramework::EventInfoPixelDecorator::m_pixelKey
SG::ReadHandleKey< xAOD::TrackMeasurementValidationContainer > m_pixelKey
Definition: EventInfoPixelDecorator.h:46
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
DerivationFramework::EventInfoPixelDecorator::kNIntDecor
@ kNIntDecor
Definition: EventInfoPixelDecorator.h:52
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
xAOD::TrackMeasurementValidation_v1
Class describing a TrackMeasurementValidation.
Definition: TrackMeasurementValidation_v1.h:27
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SGNTUPProxyLoader.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
python.subdetectors.mmg.names
names
Definition: mmg.py:8
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
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
DerivationFramework::EventInfoPixelDecorator::keta_module
@ keta_module
Definition: EventInfoPixelDecorator.h:50
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
DerivationFramework::EventInfoPixelDecorator::m_npass
std::atomic< unsigned int > m_npass
Definition: EventInfoPixelDecorator.h:39
ExpressionParserUser< AthAlgTool >::initializeParser
StatusCode initializeParser(const ExpressionParsing::SelectionArg< 1 > &selection_string)
ExpressionParserUser
Definition: ExpressionParserUser.h:107
DerivationFramework::EventInfoPixelDecorator::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: EventInfoPixelDecorator.cxx:80
EventAuxInfo.h
DerivationFramework::EventInfoPixelDecorator::kperModuleMultiplicity
@ kperModuleMultiplicity
Definition: EventInfoPixelDecorator.h:48
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DerivationFramework::EventInfoPixelDecorator::m_selectionString
Gaudi::Property< std::string > m_selectionString
Definition: EventInfoPixelDecorator.h:36
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
MultipleProxyLoader.h
DerivationFramework::EventInfoPixelDecorator::EventInfoPixelDecorator
EventInfoPixelDecorator(const std::string &type, const std::string &name, const IInterface *parent)
Definition: EventInfoPixelDecorator.cxx:23
DeMoScan.index
string index
Definition: DeMoScan.py:362
DerivationFramework::EventInfoPixelDecorator::klayer
@ klayer
Definition: EventInfoPixelDecorator.h:49
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DerivationFramework::EventInfoPixelDecorator::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: EventInfoPixelDecorator.h:42
DerivationFramework::createDecorators
std::vector< SG::WriteDecorHandle< T_Cont, T > > createDecorators(const std::vector< SG::WriteDecorHandleKey< T_Cont > > &keys, const EventContext &ctx)
Definition: DecoratorUtils.h:51
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
entries
double entries
Definition: listroot.cxx:49
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
DerivationFramework::EventInfoPixelDecorator::m_intDecorKeys
std::vector< SG::WriteDecorHandleKey< xAOD::EventInfo > > m_intDecorKeys
Definition: EventInfoPixelDecorator.h:53
AthAlgTool
Definition: AthAlgTool.h:26
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73
DerivationFramework::EventInfoPixelDecorator::initialize
StatusCode initialize()
Definition: EventInfoPixelDecorator.cxx:31
DerivationFramework::EventInfoPixelDecorator::m_decorationPrefix
Gaudi::Property< std::string > m_decorationPrefix
Definition: EventInfoPixelDecorator.h:44
EventInfoPixelDecorator.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37