EICrecon
JANA based reconstruction for the EPIC detector
Loading...
Searching...
No Matches
Beam.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// Copyright (C) 2022 Wouter Deconinck
3
4#pragma once
5
6#include <Math/Vector4D.h>
7#include <edm4hep/MCParticleCollection.h>
8#include <edm4eic/ReconstructedParticleCollection.h>
9#include <algorithm>
10#include <fmt/format.h>
11#include <set>
12#include <stdexcept>
13#include <vector>
14#include <cmath>
15
16using ROOT::Math::PxPyPzEVector;
17
18namespace eicrecon {
19
20template <class T> auto find_first_with_pdg(const T* parts, const std::set<int32_t>& pdg) {
21 T c;
22 c.setSubsetCollection();
23 const auto it = std::find_if(parts->begin(), parts->end(),
24 [&pdg](const auto& p) { return pdg.count(p.getPDG()) > 0; });
25 if (it != parts->end()) {
26 c.push_back(*it);
27 }
28 return c;
29}
30
31template <class T>
32auto find_first_with_status_pdg(const T* parts, const std::set<int32_t>& status,
33 const std::set<int32_t>& pdg) {
34 T c;
35 c.setSubsetCollection();
36 const auto it = std::find_if(parts->begin(), parts->end(), [&status, &pdg](const auto& p) {
37 return status.count(p.getGeneratorStatus()) > 0 && pdg.count(p.getPDG()) > 0;
38 });
39 if (it != parts->end()) {
40 c.push_back(*it);
41 }
42 return c;
43}
44
45inline auto find_first_beam_electron(const edm4hep::MCParticleCollection* mcparts) {
46 return find_first_with_status_pdg(mcparts, {4}, {11});
47}
48
49inline auto find_first_beam_hadron(const edm4hep::MCParticleCollection* mcparts) {
50 return find_first_with_status_pdg(mcparts, {4}, {2212, 2112});
51}
52
53inline auto find_first_scattered_electron(const edm4hep::MCParticleCollection* mcparts) {
54 return find_first_with_status_pdg(mcparts, {1}, {11});
55}
56
57inline auto find_first_scattered_electron(const edm4eic::ReconstructedParticleCollection* rcparts) {
58 return find_first_with_pdg(rcparts, {11});
59}
60
61// Canonical beam momentum allowlists used by all kinematics algorithms.
62// Electron beam: negative pz (beam goes in -z direction).
63inline const std::vector<float> electron_beam_pz_set{-5.0, -9.0, -10.0, -18.0};
64// Hadron beam: positive pz (beam goes in +z direction).
65inline const std::vector<float> hadron_beam_pz_set{41.0, 100.0, 130.0, 250.0, 275.0};
66
67template <typename Vector3>
68PxPyPzEVector round_beam_four_momentum(const Vector3& p_in, const float mass,
69 const std::vector<float>& pz_set,
70 const float crossing_angle = 0.0) {
71 // Find the closest pz within 10% relative tolerance
72 float best_pz = 0.0F;
73 float best_err = 0.1F; // 10% tolerance — entries above this are not accepted
74 bool found_match = false;
75 for (const auto& pz : pz_set) {
76 const float err = std::abs(p_in.z / pz - 1);
77 if (err < best_err) {
78 best_err = err;
79 best_pz = pz;
80 found_match = true;
81 }
82 }
83 if (!found_match) {
84 throw std::runtime_error(
85 fmt::format("round_beam_four_momentum: no match for beam momentum {:.3f} GeV within 10% "
86 "of any of the allowed values",
87 p_in.z));
88 }
89 PxPyPzEVector p_out;
90 p_out.SetPz(best_pz);
91 p_out.SetPx(p_out.Pz() * sin(crossing_angle));
92 p_out.SetPz(p_out.Pz() * cos(crossing_angle));
93 p_out.SetE(std::hypot(p_out.Px(), p_out.Pz(), mass));
94 return p_out;
95}
96
97} // namespace eicrecon
-client
Definition CalorimeterClusterRecoCoG.cc:37
const std::vector< float > hadron_beam_pz_set
Definition Beam.h:65
PxPyPzEVector round_beam_four_momentum(const Vector3 &p_in, const float mass, const std::vector< float > &pz_set, const float crossing_angle=0.0)
Definition Beam.h:68
auto find_first_with_status_pdg(const T *parts, const std::set< int32_t > &status, const std::set< int32_t > &pdg)
Definition Beam.h:32
auto find_first_scattered_electron(const edm4hep::MCParticleCollection *mcparts)
Definition Beam.h:53
auto find_first_beam_electron(const edm4hep::MCParticleCollection *mcparts)
Definition Beam.h:45
auto find_first_with_pdg(const T *parts, const std::set< int32_t > &pdg)
Definition Beam.h:20
auto find_first_beam_hadron(const edm4hep::MCParticleCollection *mcparts)
Definition Beam.h:49
const std::vector< float > electron_beam_pz_set
Definition Beam.h:63