LDMX Software
AnalysisUtils.cxx File Reference

Collection of utility functions useful for analysis. More...

#include "Tools/AnalysisUtils.h"
#include <string>
#include <tuple>
#include "Framework/Exception/Exception.h"
#include "SimCore/Event/SimParticle.h"
#include "Math/Vector3D.h"

Go to the source code of this file.

Functions

std::tuple< int, const ldmx::SimParticle * > analysis::getRecoil (const std::map< int, ldmx::SimParticle > &particleMap)
 Find and return the sim particle associated with the recoil electron.
 
bool analysis::doesParticleHavePNDaughters (const ldmx::SimParticle &gamma, const std::map< int, ldmx::SimParticle > &particleMap)
 Helper function to getPNGamma.
 
const ldmx::SimParticleanalysis::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.
 

Detailed Description

Collection of utility functions useful for analysis.

Author
Omar Moreno, SLAC National Accelerator Laboratory

Definition in file AnalysisUtils.cxx.

Function Documentation

◆ doesParticleHavePNDaughters()

bool analysis::doesParticleHavePNDaughters ( const ldmx::SimParticle & gamma,
const std::map< int, ldmx::SimParticle > & particleMap )

Helper function to getPNGamma.

Checks if a particle has daughter particles produced by the photonNuclear process type that are present in the particle map.

Definition at line 57 of file AnalysisUtils.cxx.

59 {
60 for (auto daughter_id : gamma.getDaughters()) {
61 if (particleMap.find(daughter_id) != std::end(particleMap)) {
62 const auto daughter{particleMap.at(daughter_id)};
63 const auto process_type{daughter.getProcessType()};
64 if (process_type == ldmx::SimParticle::ProcessType::photonNuclear) {
65 return true;
66 } // Was it PN?
67 } // Was it in the map?
68 }
69
70 return false;
71}
std::vector< int > getDaughters() const
Get a vector containing the track IDs of all daughter particles.

References analysis::doesParticleHavePNDaughters(), and ldmx::SimParticle::getDaughters().

Referenced by analysis::doesParticleHavePNDaughters(), and analysis::getPNGamma().

◆ getPNGamma()

const ldmx::SimParticle * analysis::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.

Returns the first particle in the map that underwent a PN interaction and has an energy above the threshold. If more than one particle satisfied this condition, this will NOT notice.

Parameters
[in]particleMapMap of sim particles
[in]recoilThe recoil electron
[in]energyThresholdThe energy that the photon energy must be greater than.
Returns
[out] Pointer to sim particle labeled as PN Gamma photon (nullptr if not found)

Definition at line 73 of file AnalysisUtils.cxx.

75 {
76 auto recoil_daughters{recoil->getDaughters()};
77 for (auto recoil_daughter_id : recoil_daughters) {
78 // Have we stored the recoil daughter?
79 if (particleMap.find(recoil_daughter_id) != std::end(particleMap)) {
80 auto recoil_daughter{particleMap.at(recoil_daughter_id)};
81 // Is it a gamma?
82 if (recoil_daughter.getPdgID() == 22) {
83 // Does it have enough energy?
84 if (recoil_daughter.getEnergy() >= energyThreshold) {
85 // Are its daughters PN products?
86 if (doesParticleHavePNDaughters(recoil_daughter, particleMap)) {
87 return &particleMap.at(recoil_daughter_id);
88 }
89 }
90 }
91 }
92 }
93 return nullptr;
94}
bool doesParticleHavePNDaughters(const ldmx::SimParticle &gamma, const std::map< int, ldmx::SimParticle > &particleMap)
Helper function to getPNGamma.

References analysis::doesParticleHavePNDaughters(), ldmx::SimParticle::getDaughters(), and analysis::getPNGamma().

Referenced by analysis::getPNGamma().

◆ getRecoil()

std::tuple< int, const ldmx::SimParticle * > analysis::getRecoil ( const std::map< int, ldmx::SimParticle > & particleMap)

Find and return the sim particle associated with the recoil electron.

Parameters
[in]particleMapmap of sim particles
Returns
[out] Pointer to sim particle labeled as recoil electron (nullptr if not found)

Definition at line 28 of file AnalysisUtils.cxx.

29 {
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, &particle};
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}

References analysis::getRecoil().

Referenced by analysis::getRecoil().