Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VertexPerformanceWriter.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VertexPerformanceWriter.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019-2023 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
22 
23 #include <mutex>
24 #include <string>
25 #include <vector>
26 
27 class TFile;
28 class TTree;
29 namespace ActsFatras {
30 class Barcode;
31 } // namespace ActsFatras
32 
33 namespace ActsExamples {
34 struct AlgorithmContext;
35 
44  : public WriterT<std::vector<Acts::Vertex<Acts::BoundTrackParameters>>> {
45  public:
47 
48  struct Config {
65  std::shared_ptr<Acts::MagneticFieldProvider> bField;
67  std::string filePath = "vertexingperformance.root";
69  std::string treeName = "vertextree";
71  std::string fileMode = "RECREATE";
77  double truthMatchProbMin = 0.5;
79  bool useTracks = true;
80  };
81 
87 
88  ~VertexPerformanceWriter() override;
89 
91  ProcessCode finalize() override;
92 
94  const Config& config() const { return m_cfg; }
95 
96  protected:
100  const AlgorithmContext& ctx,
102  override;
103 
104  private:
106  std::mutex m_writeMutex;
107  TFile* m_outputFile{nullptr};
108  TTree* m_outputTree{nullptr};
109 
110  // True 4D vertex position
111  std::vector<double> m_truthX;
112  std::vector<double> m_truthY;
113  std::vector<double> m_truthZ;
114  std::vector<double> m_truthT;
115 
116  // Reconstructed 4D vertex position
117  std::vector<double> m_recoX;
118  std::vector<double> m_recoY;
119  std::vector<double> m_recoZ;
120  std::vector<double> m_recoT;
121 
123  std::vector<double> m_resX;
124  std::vector<double> m_resY;
125  std::vector<double> m_resZ;
126  std::vector<double> m_resT;
127 
128  // pull(X) = (X_reco - X_true)/Var(X_reco)^(1/2)
129  std::vector<double> m_pullX;
130  std::vector<double> m_pullY;
131  std::vector<double> m_pullZ;
132  std::vector<double> m_pullT;
133 
134  // Vertex covariance
135  std::vector<double> m_covXX;
136  std::vector<double> m_covYY;
137  std::vector<double> m_covZZ;
138  std::vector<double> m_covTT;
139  std::vector<double> m_covXY;
140  std::vector<double> m_covXZ;
141  std::vector<double> m_covXT;
142  std::vector<double> m_covYZ;
143  std::vector<double> m_covYT;
144  std::vector<double> m_covZT;
145 
146  //--------------------------------------------------------------
147  // Track-related variables are contained in a vector of vectors: The inner
148  // vectors contain the values of all tracks corresponding to one vertex. The
149  // outer vector can then have the same length as the flat vectors of
150  // vertex-related variables (see above). E.g.,
151  // m_truthPhi = ((truthPhi of 1st trk belonging to vtx 1,
152  // truthPhi of 2nd trk belonging to vtx 1, ...),
153  // (truthPhi of 1st trk belonging to vtx 2,
154  // truthPhi of 2nd trk belonging to vtx 2, ...),
155  // ...)
156  //
157  // True track momenta at the vertex
158  std::vector<std::vector<double>> m_truthPhi;
159  std::vector<std::vector<double>> m_truthTheta;
160  std::vector<std::vector<double>> m_truthQOverP;
161 
162  // Reconstructed track momenta at the vertex before and after the vertex fit
163  std::vector<std::vector<double>> m_recoPhi;
164  std::vector<std::vector<double>> m_recoPhiFitted;
165  std::vector<std::vector<double>> m_recoTheta;
166  std::vector<std::vector<double>> m_recoThetaFitted;
167  std::vector<std::vector<double>> m_recoQOverP;
168  std::vector<std::vector<double>> m_recoQOverPFitted;
169 
170  // Difference between reconstructed momenta and true momenta
171  std::vector<std::vector<double>> m_resPhi;
172  std::vector<std::vector<double>> m_resPhiFitted;
173  std::vector<std::vector<double>> m_resTheta;
174  std::vector<std::vector<double>> m_resThetaFitted;
175  std::vector<std::vector<double>> m_resQOverP;
176  std::vector<std::vector<double>> m_resQOverPFitted;
177  std::vector<std::vector<double>> m_momOverlap;
178  std::vector<std::vector<double>> m_momOverlapFitted;
179 
180  // Pulls
181  std::vector<std::vector<double>> m_pullPhi;
182  std::vector<std::vector<double>> m_pullPhiFitted;
183  std::vector<std::vector<double>> m_pullTheta;
184  std::vector<std::vector<double>> m_pullThetaFitted;
185  std::vector<std::vector<double>> m_pullQOverP;
186  std::vector<std::vector<double>> m_pullQOverPFitted;
187 
188  // Number of tracks associated with truth/reconstructed vertex
189  std::vector<int> m_nTracksOnTruthVertex;
190  std::vector<int> m_nTracksOnRecoVertex;
191 
192  std::vector<double> m_trackVtxMatchFraction;
193 
195  int m_nRecoVtx = -1;
197  int m_nTrueVtx = -1;
203 
205  const SimParticleContainer& collection) const;
206 
207  int getNumberOfTruePriVertices(const SimParticleContainer& collection) const;
208 
210  this, "InputAllTruthParticles"};
211 
213  this, "InputSelectedTruthParticles"};
214 
216  m_inputTrackParameters{this, "InputTrackParameters"};
217 
219  this, "InputTrajectories"};
220 
222  this, "InputAssociatedTruthParticles"};
223 
225  this, "InputMeasurementParticlesMap"};
226 };
227 
228 } // namespace ActsExamples