9 #include <analysis/modules/TrackIsoCalculator/TrackIsoCalculatorModule.h>
23 setDescription(R
"DOC(Calculate track isolation variables on the input ParticleList.)DOC");
26 addParam(
"particleList",
28 "The name of the input ParticleList. Must be a charged stable particle as defined in Const::chargedStableSet.");
29 addParam(
"detectorInnerSurface",
31 "The name of the detector at whose innermost layer we extrapolate each helix's polar and azimuthal angle. Allowed values: {CDC, PID(=TOP/ARICH), ECL, KLM}.");
32 addParam(
"use2DRhoPhiDist",
34 "If true, will calculate the pair-wise track distance as the cord length on the (rho, phi) projection.",
48 B2INFO(
"TrackIsoCalculator module will calculate isolation variables for the ParticleList: " <<
m_pListName <<
".");
58 B2FATAL(
"PDG: " <<
m_pList->getPDGCode() <<
" of ParticleList: " <<
m_pList->getParticleListName() <<
59 " is not that of a valid particle in Const::chargedStableSet! Aborting...");
62 const auto nParticles =
m_pList->getListSize();
64 B2DEBUG(11,
"EVENT: " <<
m_event_metadata->getEvent() <<
"\n" <<
"nParticles: " << nParticles);
68 std::vector<double> defaultDistances(nParticles, 1e9);
69 std::vector<std::vector<double>> pairwiseDistances(nParticles, defaultDistances);
71 B2DEBUG(11,
"Array of pair-wise distances between tracks in particle list. Initial values:");
74 for (
unsigned int iPart(0); iPart < nParticles; ++iPart) {
78 for (
unsigned int jPart(iPart + 1); jPart < nParticles; ++jPart) {
86 pairwiseDistances[iPart][jPart] = ijDist;
87 pairwiseDistances[jPart][iPart] = ijDist;
93 B2DEBUG(11,
"Array of pair-wise distances between tracks in particle list. Final values:");
97 for (
unsigned int iPart(0); iPart < nParticles; ++iPart) {
99 auto minDist = std::min_element(std::begin(pairwiseDistances[iPart]), std::end(pairwiseDistances[iPart]));
100 auto jPart = std::distance(std::begin(pairwiseDistances[iPart]), minDist);
104 B2DEBUG(10,
m_extraInfoName <<
" = " << *minDist <<
" [cm] - Particle[" << iPart <<
"]'s closest partner at innermost " <<
108 B2DEBUG(10,
"\tStoring extraInfo for Particle[" << iPart <<
"]...");
127 std::string nameExtTheta =
"helixExtTheta(" + std::to_string(rho) +
"," + std::to_string(zfwd) +
"," + std::to_string(zbwd) +
")";
131 std::string nameExtPhi =
"helixExtPhi(" + std::to_string(rho) +
"," + std::to_string(zfwd) +
"," + std::to_string(zbwd) +
")";
149 const auto iExtR = (iExtTheta >= th_fwd_brl && iExtTheta < th_bwd_brl) ? rho / sin(iExtTheta) : ((iExtTheta >= th_fwd
150 && iExtTheta < th_fwd_brl) ? zfwd / cos(iExtTheta) : zbwd / cos(iExtTheta));
151 const auto jExtR = (jExtTheta >= th_fwd_brl && jExtTheta < th_bwd_brl) ? rho / sin(jExtTheta) : ((jExtTheta >= th_fwd
152 && jExtTheta < th_fwd_brl) ? zfwd / cos(jExtTheta) : zbwd / cos(jExtTheta));
159 const auto iExtX = iExtR * sin(iExtTheta) * cos(iExtPhi);
160 const auto iExtY = iExtR * sin(iExtTheta) * sin(iExtPhi);
161 const auto iExtZ = iExtR * cos(iExtTheta);
163 const auto jExtX = jExtR * sin(jExtTheta) * cos(jExtPhi);
164 const auto jExtY = jExtR * sin(jExtTheta) * sin(jExtPhi);
165 const auto jExtZ = jExtR * cos(jExtTheta);
168 return sqrt((iExtX - jExtX) * (iExtX - jExtX) + (iExtY - jExtY) * (iExtY - jExtY) + (iExtZ - jExtZ) * (iExtZ - jExtZ));
180 std::string nameExtPhi =
"helixExtPhi(" + std::to_string(rho) +
"," + std::to_string(zfwd) +
"," + std::to_string(zbwd) +
")";
184 auto diffPhi = jExtPhi - iExtPhi;
185 if (std::abs(diffPhi) > M_PI) {
186 diffPhi = (diffPhi > M_PI) ? diffPhi - 2 * M_PI : 2 * M_PI + diffPhi;
189 return 2 * rho * sin(std::abs(diffPhi) / 2.0);
197 if (logConfig.getLogLevel() ==
LogConfig::c_Debug && logConfig.getDebugLevel() >= 11) {
198 std::cout <<
"" << std::endl;
199 for (
int i(0); i < size; ++i) {
200 for (
int j(0); j < size; ++j) {
201 std::cout << std::setw(7) << arr[i][j] <<
" ";
205 std::cout <<
"" << std::endl;
@ c_Debug
Debug: for code development.
LogConfig & getLogConfig()
Returns the log system configuration.
Class to store reconstructed particles.
void writeExtraInfo(const std::string &name, const float value)
Sets the user defined extraInfo.
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
Calculate track isolation variables on the input ParticleList.
std::unordered_map< std::string, DetSurfCylBoundaries > m_detSurfBoundaries
Map that associates to each detector its innermost layer's boundaries.
StoreObjPtr< EventMetaData > m_event_metadata
The event information.
~TrackIsoCalculatorModule() override
Destructor, use this to clean up anything you created in the constructor.
bool m_use2DRhoPhiDist
If true, will calculate the pair-wise track distance as the cord length on the (rho,...
void initialize() override
Use this to initialize resources or memory your module needs.
double get2DRhoPhiDistAsChordLength(Particle *iParticle, Particle *jParticle)
Calculate the 2D distance between the points where the two input extraplolated track helices cross th...
void event() override
Called once for each event.
std::string m_detInnerSurface
The name of the detector at whose innermost layer we extrapolate each track's polar and azimuthal ang...
void terminate() override
Module terminate().
double get3DDistAtDetSurface(Particle *iParticle, Particle *jParticle)
Calculate the 3D distance between the points where the two input extraplolated track helices cross th...
std::string m_pListName
The name of the input ParticleList.
void printDistancesArr(const std::vector< std::vector< double >> &arr, int size)
Print 2D array of pair-wise distances.
std::string m_extraInfoName
The name of the distance variable to be added to each particle as extraInfo.
bool isStdChargedList()
Check whether input particle list is of a valid charged stable particle.
StoreObjPtr< ParticleList > m_pList
The input ParticleList object.
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
static Manager & Instance()
get singleton instance.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.
FunctionPtr function
Pointer to function.