ATLAS Offline Software
ConversionFinder.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 /***************************************************************************
6  ConversionFinder.cxx - Description
7  -------------------
8  begin : 10-11-2005
9  authors : Tatjana Lenz
10  email : tatjana.lenz@cern.ch
11  changes :
12  ***************************************************************************/
14 
17 #include "GaudiKernel/MsgStream.h"
18 #include "GaudiKernel/EventContext.h"
19 
21 #include "xAODTracking/Vertex.h"
23 
25 
26 
27 namespace InDet
28 {
29  ConversionFinder::ConversionFinder(const std::string& name, ISvcLocator* pSvcLocator)
30  : AthAlgorithm(name, pSvcLocator),
31  m_tracksName("InDetTrackParticles"),
32  m_InDetConversionOutputName("InDetConversion"),
33  m_EMExtrapolationTool("EMExtrapolationTools"),
34  m_doExtrapolation(false)
35  {
36  /* Retrieve StoreGate container and tool names from job options */
37  declareProperty("TracksName",m_tracksName);
38  declareProperty("InDetConversionOutputName", m_InDetConversionOutputName);
39  declareProperty("ExtrapolationTool", m_EMExtrapolationTool, "Handle of the extrapolation tool");
40  declareProperty("doExtrapolation", m_doExtrapolation );
41  }
42 
43  ConversionFinder::~ConversionFinder()= default;
44 
46  {
47  ATH_CHECK( m_VertexFinderTool.retrieve() );
48 
49  m_doExtrapolation &= !m_EMExtrapolationTool.name().empty();
50  ATH_CHECK( m_EMExtrapolationTool.retrieve( EnableTool {m_doExtrapolation} ) );
51 
52  ATH_CHECK( m_tracksName.initialize() );
53  ATH_CHECK( m_InDetConversionOutputName.initialize() );
54  resetStatistics();
55 
56  return StatusCode::SUCCESS;
57  }
58 
60  {
61  if ( msg().level() == MSG::INFO ){
62  msg(MSG::INFO) <<"Summary: "<<endmsg;
63  std::cout<< "------------------------------------------------------------"<<std::endl;
64  std::cout<< "Processed: " << m_events_processed<< " events " <<std::endl;
65  std::cout<< "Stored : " << m_Gamma_stored<<" Conversions " <<std::endl;
66  std::cout<< "------------------------------------------------------------"<<std::endl;
67  std::cout<< "| Double Conversions Si-Si Si-TRT TRT-TRT |"<<std::endl;
68  std::cout<<"| "<<
69  std::setw(10)<<m_Double_Conversions<<
70  std::setw(18)<<m_SiSi_Conversions<<
71  std::setw(11)<<m_SiTrt_Conversions<<
72  std::setw(13)<<m_TrtTrt_Conversions<<" |"<<
73  std::endl;
74  std::cout<< "------------------------------------------------------------" <<std::endl;
75  std::cout<< "| Single Conversions Si TRT |"<<std::endl;
76  std::cout<<"| "<<
77  std::setw(10)<<m_Single_Conversions<<
78  std::setw(25)<<m_Si_Conversions<<
79  std::setw(19)<<m_Trt_Conversions<<" |"<<
80  std::endl;
81  std::cout<< "------------------------------------------------------------" <<std::endl;
82  }
83  return StatusCode::SUCCESS;
84  }
85 
86  void ConversionFinder::resetStatistics() {
87  m_events_processed = 0;
88  m_Gamma_stored = 0;
89  m_Double_Conversions = 0;
90  m_Single_Conversions = 0;
91  m_SiSi_Conversions = 0;
92  m_SiTrt_Conversions = 0;
93  m_TrtTrt_Conversions = 0;
94  m_Si_Conversions = 0;
95  m_Trt_Conversions = 0;
96  }
97 
98  namespace {
99  class cleanup_pair : public std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
100  {
101  public:
102  explicit cleanup_pair(const std::pair<xAOD::VertexContainer*,
103  xAOD::VertexAuxContainer*>& a_pair)
104  : std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>(a_pair)
105  {}
106  ~cleanup_pair() {
107  delete this->first;
108  delete this->second;
109  }
110  xAOD::VertexContainer* releaseFirst() {
112  this->first=nullptr;
113  return tmp;
114  }
115  xAOD::VertexAuxContainer* releaseSecond() {
117  this->second=nullptr;
118  return tmp;
119  }
120  };
121  }
122 
124  {
125 
126  const EventContext& ctx =Algorithm::getContext();
127  m_events_processed++;
128 
129  SG::ReadHandle<xAOD::TrackParticleContainer> trackParticleCollection(m_tracksName,ctx);
130  if ( !trackParticleCollection.isValid())
131  {
132  ATH_MSG_WARNING( "Could not find xAOD::TrackParticleContainer " << m_tracksName << " in StoreGate.");
133  // @TODO change to failure
134  return StatusCode::SUCCESS;
135  }
136 
137  cleanup_pair conversions( m_VertexFinderTool->findVertex ( trackParticleCollection.cptr() ) );
138 
139  if (!conversions.first || !conversions.second)
140  {
141  ATH_MSG_WARNING("Null pointer to conversion container");
142  return StatusCode::SUCCESS;
143  }
144  ATH_MSG_DEBUG("New conversion container size: " << conversions.first->size());
145 
146  m_Gamma_stored += conversions.first->size();
147 
148 
149  // Decorate the vertices with the momentum at the conversion point and
150  // etaAtCalo, phiAtCalo (extrapolate each vertex)
151  if(m_doExtrapolation){
152  float etaAtCalo = -9999., phiAtCalo = -9999.;
153  for (xAOD::Vertex *vertex : *(conversions.first))
154  {
155 
156  Amg::Vector3D momentum(0., 0., 0.);
157  for (unsigned int i = 0; i < vertex->nTrackParticles(); ++i){
158  momentum += m_EMExtrapolationTool->getMomentumAtVertex(ctx,*vertex, i);
159  }
160  static const SG::AuxElement::Accessor<float> accx("px");
161  static const SG::AuxElement::Accessor<float> accy("py");
162  static const SG::AuxElement::Accessor<float> accz("pz");
163  accx(*vertex) = momentum.x();
164  accy(*vertex) = momentum.y();
165  accz(*vertex) = momentum.z();
166  if (!m_EMExtrapolationTool->getEtaPhiAtCalo(ctx, vertex, &etaAtCalo, &phiAtCalo)) {
167  ATH_MSG_DEBUG("getEtaPhiAtCalo failed!");
168  }
169 
170  // Decorate vertex with etaAtCalo, phiAtCalo
171  static const SG::AuxElement::Accessor<float> acceta("etaAtCalo");
172  static const SG::AuxElement::Accessor<float> accphi("phiAtCalo");
173  acceta(*vertex) = etaAtCalo;
174  accphi(*vertex) = phiAtCalo;
175  }
176  }
177 
178  analyzeResults(conversions.first);
179 
180  SG::WriteHandle<xAOD::VertexContainer> output(m_InDetConversionOutputName,ctx);
181  if (output.record( std::unique_ptr<xAOD::VertexContainer>(conversions.releaseFirst()) ,
182  std::unique_ptr<xAOD::VertexAuxContainer>(conversions.releaseSecond())).isFailure()) {
183  ATH_MSG_ERROR("Failed to record conversion vertices " << m_InDetConversionOutputName.key());
184  return StatusCode::FAILURE;
185  }
186 
187  return StatusCode::SUCCESS;
188  }
189 
190  void ConversionFinder::analyzeResults(xAOD::VertexContainer* convContainer) {
191 
192  for ( auto fz : *convContainer){
193 
194  int numTracksPerVertex = fz->nTrackParticles();
195  if (numTracksPerVertex == 2) m_Double_Conversions++;
196  else m_Single_Conversions++;
197 
198  bool isTrt1 = false; bool isSi1 = false; bool isTrt2 = false; bool isSi2 = false;
199  for (unsigned int i = 0; i < fz->nTrackParticles() ; ++i) {
200  const auto *trackParticle = fz->trackParticle( i );
201  if(!trackParticle) continue;
202  uint8_t temp(0);
203  uint8_t ncl(0);
204  uint8_t ntrt(0);
205 
206  if( trackParticle->summaryValue( temp , xAOD::numberOfPixelHits) ) ncl += temp;
207  if( trackParticle->summaryValue( temp , xAOD::numberOfSCTHits) ) ncl += temp;
208  if( trackParticle->summaryValue( temp , xAOD::numberOfTRTHits) ) ntrt += temp;
209  if(i==0) {
210  if(ncl>0) isSi1 = true;
211  if(ncl==0 && ntrt>0) isTrt1 = true;
212  }
213  if(i==1) {
214  if(ncl>0) isSi2 = true;
215  if(ncl==0 && ntrt>0) isTrt2 = true;
216  }
217 
218  //Decide on the type of track combination in vertex
219  if(numTracksPerVertex==2){
220  if (isSi1 && isSi2) m_SiSi_Conversions++;
221  else if(isTrt1 && isTrt2) m_TrtTrt_Conversions++;
222  else m_SiTrt_Conversions++;
223  }
224  if(numTracksPerVertex==1){
225  if(isSi1) m_Si_Conversions++;
226  if(isTrt1) m_Trt_Conversions++;
227  }
228  }
229  }
230  }
231 }
232 
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:53
xAOD::VertexAuxContainer_v1
Temporary container used until we have I/O for AuxStoreInternal.
Definition: VertexAuxContainer_v1.h:32
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:575
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
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
InDet
DUMMY Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
initialize
void initialize()
Definition: run_EoverP.cxx:894
xAOD::numberOfPixelHits
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].
Definition: TrackingPrimitives.h:259
xAOD::numberOfTRTHits
@ numberOfTRTHits
number of TRT hits [unit8_t].
Definition: TrackingPrimitives.h:275
IEMExtrapolationTools.h
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
TrackCollection.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrackSummary.h
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Vertex.h
AthAlgorithm
Definition: AthAlgorithm.h:47
merge.output
output
Definition: merge.py:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
ConversionFinder.h
TrackParticle.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DeMoScan.first
bool first
Definition: DeMoScan.py:534
xAOD::numberOfSCTHits
@ numberOfSCTHits
number of hits in SCT [unit8_t].
Definition: TrackingPrimitives.h:268
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
InDet::ConversionFinder::ConversionFinder
ConversionFinder(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ConversionFinder.cxx:36
VertexAuxContainer.h