ATLAS Offline Software
ConversionFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
24 
25 namespace InDet
26 {
27  ConversionFinder::ConversionFinder(const std::string& name, ISvcLocator* pSvcLocator)
28  : AthAlgorithm(name, pSvcLocator)
29  {}
30 
31  ConversionFinder::~ConversionFinder()= default;
32 
34  {
35  ATH_CHECK( m_VertexFinderTool.retrieve() );
36 
37  m_doExtrapolation.value() &= !m_EMExtrapolationTool.name().empty();
38  ATH_CHECK( m_EMExtrapolationTool.retrieve( EnableTool {m_doExtrapolation} ) );
39 
40  ATH_CHECK( m_tracksName.initialize() );
41  ATH_CHECK( m_InDetConversionOutputName.initialize() );
42  resetStatistics();
43 
44  return StatusCode::SUCCESS;
45  }
46 
48  {
49  if ( msg().level() == MSG::INFO ){
50  msg(MSG::INFO) <<"Summary: "<<endmsg;
51  std::cout<< "------------------------------------------------------------"<<std::endl;
52  std::cout<< "Processed: " << m_events_processed<< " events " <<std::endl;
53  std::cout<< "Stored : " << m_Gamma_stored<<" Conversions " <<std::endl;
54  std::cout<< "------------------------------------------------------------"<<std::endl;
55  std::cout<< "| Double Conversions Si-Si Si-TRT TRT-TRT |"<<std::endl;
56  std::cout<<"| "<<
57  std::setw(10)<<m_Double_Conversions<<
58  std::setw(18)<<m_SiSi_Conversions<<
59  std::setw(11)<<m_SiTrt_Conversions<<
60  std::setw(13)<<m_TrtTrt_Conversions<<" |"<<
61  std::endl;
62  std::cout<< "------------------------------------------------------------" <<std::endl;
63  std::cout<< "| Single Conversions Si TRT |"<<std::endl;
64  std::cout<<"| "<<
65  std::setw(10)<<m_Single_Conversions<<
66  std::setw(25)<<m_Si_Conversions<<
67  std::setw(19)<<m_Trt_Conversions<<" |"<<
68  std::endl;
69  std::cout<< "------------------------------------------------------------" <<std::endl;
70  }
71  return StatusCode::SUCCESS;
72  }
73 
74  void ConversionFinder::resetStatistics() {
75  m_events_processed = 0;
76  m_Gamma_stored = 0;
77  m_Double_Conversions = 0;
78  m_Single_Conversions = 0;
79  m_SiSi_Conversions = 0;
80  m_SiTrt_Conversions = 0;
81  m_TrtTrt_Conversions = 0;
82  m_Si_Conversions = 0;
83  m_Trt_Conversions = 0;
84  }
85 
86  namespace {
87  class cleanup_pair : public std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
88  {
89  public:
90  explicit cleanup_pair(const std::pair<xAOD::VertexContainer*,
91  xAOD::VertexAuxContainer*>& a_pair)
92  : std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>(a_pair)
93  {}
94  ~cleanup_pair() {
95  delete this->first;
96  delete this->second;
97  }
98  xAOD::VertexContainer* releaseFirst() {
100  this->first=nullptr;
101  return tmp;
102  }
103  xAOD::VertexAuxContainer* releaseSecond() {
105  this->second=nullptr;
106  return tmp;
107  }
108  };
109  }
110 
112  {
113 
114  const EventContext& ctx =Algorithm::getContext();
115  m_events_processed++;
116 
117  SG::ReadHandle<xAOD::TrackParticleContainer> trackParticleCollection(m_tracksName,ctx);
118  if ( !trackParticleCollection.isValid())
119  {
120  ATH_MSG_WARNING( "Could not find xAOD::TrackParticleContainer " << m_tracksName << " in StoreGate.");
121  // @TODO change to failure
122  return StatusCode::SUCCESS;
123  }
124 
125  cleanup_pair conversions( m_VertexFinderTool->findVertex ( trackParticleCollection.cptr() ) );
126 
127  if (!conversions.first || !conversions.second)
128  {
129  ATH_MSG_WARNING("Null pointer to conversion container");
130  return StatusCode::SUCCESS;
131  }
132  ATH_MSG_DEBUG("New conversion container size: " << conversions.first->size());
133 
134  m_Gamma_stored += conversions.first->size();
135 
136 
137  // Decorate the vertices with the momentum at the conversion point and
138  // etaAtCalo, phiAtCalo (extrapolate each vertex)
139  if(m_doExtrapolation){
140  float etaAtCalo = -9999., phiAtCalo = -9999.;
141  for (xAOD::Vertex *vertex : *(conversions.first))
142  {
143 
144  Amg::Vector3D momentum(0., 0., 0.);
145  for (unsigned int i = 0; i < vertex->nTrackParticles(); ++i){
146  momentum += m_EMExtrapolationTool->getMomentumAtVertex(ctx,*vertex, i);
147  }
148  static const SG::AuxElement::Accessor<float> accx("px");
149  static const SG::AuxElement::Accessor<float> accy("py");
150  static const SG::AuxElement::Accessor<float> accz("pz");
151  accx(*vertex) = momentum.x();
152  accy(*vertex) = momentum.y();
153  accz(*vertex) = momentum.z();
154  if (!m_EMExtrapolationTool->getEtaPhiAtCalo(ctx, vertex, &etaAtCalo, &phiAtCalo)) {
155  ATH_MSG_DEBUG("getEtaPhiAtCalo failed!");
156  }
157 
158  // Decorate vertex with etaAtCalo, phiAtCalo
159  static const SG::AuxElement::Accessor<float> acceta("etaAtCalo");
160  static const SG::AuxElement::Accessor<float> accphi("phiAtCalo");
161  acceta(*vertex) = etaAtCalo;
162  accphi(*vertex) = phiAtCalo;
163  }
164  }
165 
166  analyzeResults(conversions.first);
167 
168  SG::WriteHandle<xAOD::VertexContainer> output(m_InDetConversionOutputName,ctx);
169  if (output.record( std::unique_ptr<xAOD::VertexContainer>(conversions.releaseFirst()) ,
170  std::unique_ptr<xAOD::VertexAuxContainer>(conversions.releaseSecond())).isFailure()) {
171  ATH_MSG_ERROR("Failed to record conversion vertices " << m_InDetConversionOutputName.key());
172  return StatusCode::FAILURE;
173  }
174 
175  return StatusCode::SUCCESS;
176  }
177 
178  void ConversionFinder::analyzeResults(xAOD::VertexContainer* convContainer) {
179 
180  for ( auto fz : *convContainer){
181 
182  int numTracksPerVertex = fz->nTrackParticles();
183  if (numTracksPerVertex == 2) m_Double_Conversions++;
184  else m_Single_Conversions++;
185 
186  bool isTrt1 = false; bool isSi1 = false; bool isTrt2 = false; bool isSi2 = false;
187  for (unsigned int i = 0; i < fz->nTrackParticles() ; ++i) {
188  const auto *trackParticle = fz->trackParticle( i );
189  if(!trackParticle) continue;
190  uint8_t temp(0);
191  uint8_t ncl(0);
192  uint8_t ntrt(0);
193 
194  if( trackParticle->summaryValue( temp , xAOD::numberOfPixelHits) ) ncl += temp;
195  if( trackParticle->summaryValue( temp , xAOD::numberOfSCTHits) ) ncl += temp;
196  if( trackParticle->summaryValue( temp , xAOD::numberOfTRTHits) ) ntrt += temp;
197  if(i==0) {
198  if(ncl>0) isSi1 = true;
199  if(ncl==0 && ntrt>0) isTrt1 = true;
200  }
201  if(i==1) {
202  if(ncl>0) isSi2 = true;
203  if(ncl==0 && ntrt>0) isTrt2 = true;
204  }
205 
206  //Decide on the type of track combination in vertex
207  if(numTracksPerVertex==2){
208  if (isSi1 && isSi2) m_SiSi_Conversions++;
209  else if(isTrt1 && isTrt2) m_TrtTrt_Conversions++;
210  else m_SiTrt_Conversions++;
211  }
212  if(numTracksPerVertex==1){
213  if(isSi1) m_Si_Conversions++;
214  if(isTrt1) m_Trt_Conversions++;
215  }
216  }
217  }
218  }
219 }
220 
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:50
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:557
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
InDet
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
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:85
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:221
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:536
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:34
VertexAuxContainer.h