LDMX Software
AnalysisUtils.cxx
Go to the documentation of this file.
1
8
9//-----------------//
10// C++ StdLib //
11//-----------------//
12#include <string>
13#include <tuple>
14
15//----------//
16// ldmx //
17//----------//
18#include "Framework/Exception/Exception.h"
19#include "SimCore/Event/SimParticle.h"
20
21//----------//
22// ROOT //
23//----------//
24#include "Math/Vector3D.h"
25
26namespace analysis {
27
28std::tuple<int, const ldmx::SimParticle*> getRecoil(
29 const std::map<int, ldmx::SimParticle>& particleMap) {
30 // The recoil electron is "produced" in the dark brem geneartion
31 for (const auto& [trackID, particle] : particleMap) {
32 if (particle.getPdgID() == 11 and
33 particle.getProcessType() ==
34 ldmx::SimParticle::ProcessType::eDarkBrem) {
35 return {trackID, &particleMap.at(trackID)};
36 }
37 }
38 // only get here if recoil electron was not "produced" by dark brem
39 // in this case (bkgd), we interpret the primary electron as also the recoil
40 // electron
41 if (particleMap.find(1) != particleMap.end()) {
42 return {1, &(particleMap.at(1))};
43 } else {
44 // need to account for overlay tracks, which replace track ID
45 // 1 with 134217729 in the main sample and with 150994945 in the
46 // pileup
47 // this code right now is decidedly NOT future proof and only handles a
48 // single encoding version
49 return {134217729, &(particleMap.at(134217729))};
50 }
51}
52
53std::tuple<int, const ldmx::SimParticle*> getBremPhoton(
54 const std::map<int, ldmx::SimParticle>& particleMap) {
55 int bremTrackID = -1;
56 double bremEnergy = -9999.0;
57 for (const auto& [trackID, particle] : particleMap) {
58 // find the highest energy photon generated at the target
59 if (particle.getEnergy() > bremEnergy // if the energy is greatest yet
60 && particle.getVertex()[2] > -5.0 &&
61 particle.getVertex()[2] <
62 5.0 // if the particle originates near the target
63 && particle.getPdgID() == 22) { // and the particle is a photon
64 bremTrackID = trackID;
65 bremEnergy = particle.getEnergy();
66 }
67 } //
68 if (bremTrackID != -1 && bremEnergy != -9999.0) {
69 return {bremTrackID, &particleMap.at(bremTrackID)};
70 } else {
71 // if no brem photon is found
72 return {1, nullptr};
73 }
74}
75
76// Search the recoil electrons daughters for a photon
77// Check if the photon has daughters and if so, if they were produced by PN
78//
79
81 const ldmx::SimParticle& gamma,
82 const std::map<int, ldmx::SimParticle>& particleMap) {
83 for (auto daughter_id : gamma.getDaughters()) {
84 if (particleMap.find(daughter_id) != std::end(particleMap)) {
85 const auto daughter{particleMap.at(daughter_id)};
86 const auto process_type{daughter.getProcessType()};
87 if (process_type == ldmx::SimParticle::ProcessType::photonNuclear) {
88 return true;
89 } // Was it PN?
90 } // Was it in the map?
91 }
92
93 return false;
94}
95
97 const std::map<int, ldmx::SimParticle>& particleMap,
98 const ldmx::SimParticle* recoil, const float& energyThreshold) {
99 auto recoil_daughters{recoil->getDaughters()};
100 for (auto recoil_daughter_id : recoil_daughters) {
101 // Have we stored the recoil daughter?
102 if (particleMap.find(recoil_daughter_id) != std::end(particleMap)) {
103 auto recoil_daughter{particleMap.at(recoil_daughter_id)};
104 // Is it a gamma?
105 if (recoil_daughter.getPdgID() == 22) {
106 // Does it have enough energy?
107 if (recoil_daughter.getEnergy() >= energyThreshold) {
108 // Are its daughters PN products?
109 if (doesParticleHavePNDaughters(recoil_daughter, particleMap)) {
110 return &particleMap.at(recoil_daughter_id);
111 }
112 }
113 }
114 }
115 }
116 return nullptr;
117}
118
119} // namespace analysis
Collection of utility functions useful for analysis.
std::tuple< int, const ldmx::SimParticle * > getBremPhoton(const std::map< int, ldmx::SimParticle > &particleMap)
Find and return the sim particle associated with the brem photon, if any.
const ldmx::SimParticle * getPNGamma(const std::map< int, ldmx::SimParticle > &particleMap, const ldmx::SimParticle *recoil, const float &energyThreshold)
Get a pointer to the sim particle associated with the photon that underwent a photo-nuclear reaction.
std::tuple< int, const ldmx::SimParticle * > getRecoil(const std::map< int, ldmx::SimParticle > &particleMap)
Find and return the sim particle associated with the recoil electron.
bool doesParticleHavePNDaughters(const ldmx::SimParticle &gamma, const std::map< int, ldmx::SimParticle > &particleMap)
Helper function to getPNGamma.
Class representing a simulated particle.
Definition SimParticle.h:24
std::vector< int > getDaughters() const
Get a vector containing the track IDs of all daughter particles.