10#include <analysis/modules/TrackingSystematics/TrackingMomentumScaleFactors.h>
12#include <framework/datastore/StoreObjPtr.h>
13#include <framework/database/DBObjPtr.h>
14#include <framework/dataobjects/EventMetaData.h>
15#include <framework/core/ModuleParam.templateDetails.h>
16#include <framework/logging/Logger.h>
18#include <analysis/VariableManager/Manager.h>
19#include <analysis/dataobjects/Particle.h>
20#include <analysis/dataobjects/ParticleList.h>
21#include <analysis/dbobjects/ParticleWeightingLookUpTable.h>
24#include <Math/Vector4D.h>
36 R
"DOC(Module to modify momentum of tracks from the lists. Include in your code as
40 mypath.add_module("TrackingMomentumScaleFactors", particleLists=['pi+:cut'], scale=0.999)
42The module modifies the input particleLists by scaling track momenta as given by the parameter scale
48 addParam(
"scale",
m_scale,
"scale factor to be applied to 3-momentum", nan(
""));
57 B2FATAL(
"It's not allowed to provide both a valid value for the scale parameter and a non-empty table name. Please decide for one of the two options!");
59 B2FATAL(
"Neither a valid value for the scale parameter nor a non-empty table name was provided. Please set (exactly) one of the two options!");
61 B2FATAL(
"It's not allowed to provide both a valid value for the scalingFactorName and smearingFactorName. Please set (exactly) one of the two options!");
71 StoreObjPtr<EventMetaData> evt;
72 B2FATAL(
"There is no valid payload for this run!"
74 << LogVar(
"experiment", evt->getExperiment())
75 << LogVar(
"run", evt->getRun())
81 for (
const auto& i_variable : variables) {
84 B2FATAL(
"Variable '" << i_variable <<
"' is not available in Variable::Manager!");
93 StoreObjPtr<ParticleList> particleList(iList);
97 B2ERROR(
"ParticleList " << iList <<
" not found");
101 size_t nPart = particleList->getListSize();
102 for (
size_t iPart = 0; iPart < nPart; iPart++) {
103 auto particle = particleList->getParticle(iPart);
116 std::map<std::string, double> values;
117 for (
const auto& i_variable : variables) {
119 double value = std::get<double>(var->function(particle));
120 values.insert(std::make_pair(i_variable, value));
124 for (
const auto& entry : info) {
138 std::map<std::string, double> values;
139 for (
const auto& i_variable : variables) {
141 double value = std::get<double>(var->function(particle));
142 values.insert(std::make_pair(i_variable, value));
146 for (
const auto& entry : info) {
147 particle->writeExtraInfo(
m_payloadName +
"_" + entry.first, gRandom->Gaus(1, entry.second));
156 if (particle->getParticleSource() == Particle::EParticleSourceObject::c_Composite or
157 particle->getParticleSource() == Particle::EParticleSourceObject::c_V0) {
158 for (
auto daughter : particle->getDaughters()) {
165 for (
auto daughter : particle->getDaughters()) {
166 px += daughter->getPx();
167 py += daughter->getPy();
168 pz += daughter->getPz();
169 E += daughter->getEnergy();
171 const ROOT::Math::PxPyPzEVector vec(px, py, pz,
E);
172 particle->set4Vector(vec);
173 }
else if (particle->getParticleSource() == Particle::EParticleSourceObject::c_Track) {
175 particle->setMomentumScalingFactor(
m_scale);
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Class to store reconstructed particles.
std::vector< std::string > m_ParticleLists
input particle lists
void initialize() override
Initializes the modules and checks the validity of the input parameters.
void event() override
Function to be executed at each event.
std::string m_scalingFactorName
Name of the scale factor from table.
std::string m_payloadName
Name of the table.
std::unique_ptr< DBObjPtr< ParticleWeightingLookUpTable > > m_ParticleWeightingLookUpTable
Pointer to the table in DB.
void setMomentumScalingFactor(Particle *particle)
function to set momentum scaling factor
void beginRun() override
Function to be executed at each beginning of a run.
TrackingMomentumScaleFactorsModule()
Constructor: Sets the description, the properties and the parameters of the module.
double m_scale
input momentum scale modifier
double getSmearingFactor(Particle *particle)
Returns the needed smearing factor for particle based on payloadName and smearingFactorName.
std::string m_smearingFactorName
Name of the smear factor from table.
double getScalingFactor(Particle *particle)
Returns the needed scale factor for particle based on payloadName and scalingFactorName.
std::vector< std::string > resolveCollections(const std::vector< std::string > &variables)
Resolve Collection Returns variable names corresponding to the given collection or if it is not a col...
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
static Manager & Instance()
get singleton instance.
std::map< std::string, double > WeightInfo
Weight information: a line from the weight lookup table.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.
A variable returning a floating-point value for a given Particle.