Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-09 09:25:44

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/TrackFitting/KalmanFitterError.hpp"
0010 #include "Acts/Utilities/Result.hpp"
0011 
0012 #include <iostream>
0013 #include <system_error>
0014 
0015 // Example struct representing a track for demonstration purposes
0016 struct Track {
0017   int id;
0018 };
0019 
0020 // Example struct representing track parameters
0021 struct TrackParameters {
0022   double momentum;
0023 };
0024 
0025 //! [Error Enum Pattern]
0026 enum class MyComponentError {
0027   ErrorValue1 = 1,  // All error values must be non-zero
0028   ErrorValue2,
0029   // ...
0030 };
0031 
0032 // Factory function to create std::error_code
0033 std::error_code make_error_code(MyComponentError e);
0034 //! [Error Enum Pattern]
0035 
0036 //! [Usage with Result Type]
0037 Acts::Result<Track> fitTrack(const TrackParameters& params) {
0038   if (params.momentum < 0) {
0039     return Acts::KalmanFitterError::UpdateFailed;
0040   }
0041   Track track{42};
0042   return track;  // Success
0043 }
0044 
0045 void processTrack() {
0046   TrackParameters params{100.0};
0047 
0048   // Usage
0049   auto result = fitTrack(params);
0050   if (!result.ok()) {
0051     std::error_code error = result.error();
0052     // Handle error
0053     std::cerr << "Error: " << error.message() << std::endl;
0054   } else {
0055     Track track = std::move(result).value();
0056     std::cout << "Track fitted successfully: " << track.id << std::endl;
0057   }
0058 }
0059 //! [Usage with Result Type]