Belle II Software  release-06-02-00
HelixErrorScalerModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <analysis/modules/HelixErrorScaler/HelixErrorScalerModule.h>
10 
11 #include <analysis/DecayDescriptor/ParticleListName.h>
12 #include <mdst/dataobjects/HitPatternCDC.h>
13 #include <mdst/dataobjects/HitPatternVXD.h>
14 #include <framework/datastore/RelationArray.h>
15 #include <framework/gearbox/Const.h>
16 
17 #include <vector>
18 
19 using namespace Belle2;
20 
21 //-----------------------------------------------------------------
22 // Register the Module
23 //-----------------------------------------------------------------
24 REG_MODULE(HelixErrorScaler)
25 
26 //-----------------------------------------------------------------
27 // Implementation
28 //-----------------------------------------------------------------
29 
31 {
32  // Set module properties
33  setDescription(R"DOC("scale the error of helix parameters
34 
35  Creates a new charged particle list whose helix errors are scaled by constant factors.
36  Parameters (a, b) can be set to define impact parameter resolution,
37  which limits d0 and z0 errors so that they do not shrink below the resolution.
38  )DOC");
39 
40  // Parameter definitions
41  addParam("inputListName", m_inputListName, "The name of input charged particle list", std::string(""));
42  addParam("outputListName", m_outputListName, "The name of output charged particle list", std::string(""));
43  addParam("scaleFactors", m_scaleFactors, "vector of five scale factors for helix parameter errors", {1.0, 1.0, 1.0, 1.0, 1.0});
44  addParam("d0ResolutionParameters", m_d0ResolPars, "d0 resolution parameters", {0.0, 0.0});
45  addParam("z0ResolutionParameters", m_z0ResolPars, "z0 resolution parameters", {0.0, 0.0});
46 
47 }
48 
50 {
51  // check the validity of output ParticleList name
53  if (!valid)
54  B2ERROR("Invalid output ParticleList name: " << m_outputListName);
55 
56  // output particle
58  m_pdgCode = mother->getPDGCode();
60  B2ERROR("Invalid input ParticleList PDG code (must be ChargedStable): " << m_pdgCode);
62 
63  // get existing particle lists
65  B2ERROR("Input and output particle list names are the same: " << m_inputListName);
66  } else if (!m_decaydescriptor.init(m_inputListName)) {
67  B2ERROR("Invalid input particle list name: " << m_inputListName);
68  } else {
70  }
71 
72  // make output list
73  m_outputparticleList.registerInDataStore(m_outputListName);
75 
76  m_particles.registerRelationTo(m_pidlikelihoods);
77  m_particles.registerRelationTo(m_trackfitresults);
78 }
79 
81 {
82  RelationArray particlesToMCParticles(m_particles, m_mcparticles);
83 
84  // new output particle list
85  m_outputparticleList.create();
87  m_outputAntiparticleList.create();
89  m_outputAntiparticleList->bindAntiParticleList(*(m_outputparticleList));
90 
91  // loop over charged particles
92  const unsigned int nPar = m_inputparticleList->getListSize();
93  for (unsigned i = 0; i < nPar; i++) {
94  const Particle* charged = m_inputparticleList->getParticle(i);
95  TrackFitResult* new_trkfit = getTrackFitResultWithScaledError(charged);
96 
97  Const::ChargedStable chargedtype(abs(charged->getPDGCode()));
98 
99  Particle new_charged(charged->getMdstArrayIndex(), new_trkfit, chargedtype);
100  Particle* newCharged = m_particles.appendNew(new_charged);
101  const PIDLikelihood* pid = charged->getPIDLikelihood();
102  const MCParticle* mcCharged = charged->getRelated<MCParticle>();
103  newCharged->addRelationTo(new_trkfit);
104  if (pid) newCharged->addRelationTo(pid);
105  if (mcCharged != nullptr) newCharged->addRelationTo(mcCharged);
106 
107  m_outputparticleList->addParticle(newCharged);
108 
109  } // loop over the charged particles
110 }
111 
113 {
114  const TrackFitResult* trkfit = particle->getTrackFitResult();
115  const std::vector<float> helix = trkfit->getTau();
116  const std::vector<float> cov5 = trkfit->getCov();
117  const Const::ParticleType ptype = trkfit->getParticleType();
118  const double pvalue = trkfit->getPValue();
119  const ULong64_t hitCDC = trkfit->getHitPatternCDC().getInteger();
120  const ULong64_t hitVXD = trkfit->getHitPatternVXD().getInteger();
121  const int ndf = trkfit->getNDF();
122 
123  // d0, z0 resolution = a (+) b / pseudo-momentum
124  TVector3 p = particle->getMomentum();
125  double sinTheta = TMath::Sin(p.Theta());
126  double pD0 = p.Mag2() / (particle->getEnergy()) * TMath::Power(sinTheta, 1.5); // p*beta*sinTheta**1.5
127  double pZ0 = pD0 * sinTheta; // p*beta*sinTheta**2.5
128  double d0Resol = TMath::Sqrt(TMath::Power(m_d0ResolPars[0], 2) + TMath::Power(m_d0ResolPars[1] / pD0, 2));
129  double z0Resol = TMath::Sqrt(TMath::Power(m_z0ResolPars[0], 2) + TMath::Power(m_z0ResolPars[1] / pZ0, 2));
130  double d0Err = TMath::Sqrt(trkfit->getCovariance5()[0][0]);
131  double z0Err = TMath::Sqrt(trkfit->getCovariance5()[3][3]);
132 
133  double scaleFactors[5] = { TMath::Max(d0Resol / d0Err, m_scaleFactors[0]),
134  m_scaleFactors[1],
135  m_scaleFactors[2],
136  TMath::Max(z0Resol / z0Err, m_scaleFactors[3]),
137  m_scaleFactors[4]
138  };
139 
140  std::vector<float> cov5_scaled;
141  unsigned int counter = 0;
142  for (unsigned int j = 0; j < 5; j++) {
143  for (unsigned int k = j; k < 5; k++) {
144  cov5_scaled.push_back(cov5[counter++] * scaleFactors[j] * scaleFactors[k]);
145  }
146  }
147  TrackFitResult* new_trkfit = m_trackfitresults.appendNew(helix, cov5_scaled, ptype, pvalue, hitCDC, hitVXD, ndf);
148  return new_trkfit;
149 }
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:470
The ParticleType class for identifying different particle types.
Definition: Const.h:289
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:499
static const ParticleType invalidParticle
Invalid particle, used internally.
Definition: Const.h:561
Represents a particle in the DecayDescriptor.
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
const DecayDescriptorParticle * getMother() const
return mother.
scale the error of helix parameters
StoreArray< TrackFitResult > m_trackfitresults
StoreArray of TrackFitResult objects.
std::vector< double > m_d0ResolPars
parameters (a,b) to define d0 resolution = a (+) b / (p*beta*sinTheta**1.5)
StoreObjPtr< ParticleList > m_outputparticleList
StoreObjptr for output particlelist.
StoreArray< MCParticle > m_mcparticles
StoreArray of MCParticle objects.
StoreArray< Particle > m_particles
StoreArray of Particle objects.
virtual void event() override
loop over the input charged particles
StoreArray< PIDLikelihood > m_pidlikelihoods
StoreArray of PIDLikelihood objects.
virtual void initialize() override
Register input and output data.
TrackFitResult * getTrackFitResultWithScaledError(const Particle *particle)
create a TrackFitResult with scaled errors
std::vector< double > m_z0ResolPars
parameters (a,b) to define z0 resolution = a (+) b / (p*beta*sinTheta**2.5)
StoreObjPtr< ParticleList > m_inputparticleList
StoreObjptr for input charged particlelist.
StoreObjPtr< ParticleList > m_outputAntiparticleList
StoreObjptr for output antiparticlelist.
DecayDescriptor m_decaydescriptor
Decay descriptor of the charged particle.
int m_pdgCode
PDG code of the charged particle to be scaled.
std::vector< double > m_scaleFactors
vector of five scale factors for helix parameter errors
std::string m_outputAntiListName
output anti-particle list name
std::string m_inputListName
The name of input charged particle list.
std::string m_outputListName
The name of output charged particle list.
ULong64_t getInteger() const
Getter for underlying integer type.
unsigned int getInteger() const
Getter for the underlying integer.
Definition: HitPatternVXD.h:58
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
Base class for Modules.
Definition: Module.h:72
Class to collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes...
Definition: PIDLikelihood.h:26
Class to store reconstructed particles.
Definition: Particle.h:74
unsigned getMdstArrayIndex(void) const
Returns 0-based index of MDST store array object (0 for composite particles)
Definition: Particle.h:425
const PIDLikelihood * getPIDLikelihood() const
Returns the pointer to the PIDLikelihood object that is related to the Track, which was used to creat...
Definition: Particle.cc:840
int getPDGCode(void) const
Returns PDG code.
Definition: Particle.h:392
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:62
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
Values of the result of a track fit with a given particle hypothesis.
std::vector< float > getTau() const
Getter for all perigee parameters.
TMatrixDSym getCovariance5() const
Getter for covariance matrix of perigee parameters in matrix form.
double getPValue() const
Getter for Chi2 Probability of the track fit.
int getNDF() const
Getter for number of degrees of freedom of the track fit.
std::vector< float > getCov() const
Getter for all covariance matrix elements of perigee parameters.
Const::ParticleType getParticleType() const
Getter for ParticleType of the mass hypothesis of the track fit.
HitPatternCDC getHitPatternCDC() const
Getter for the hit pattern in the CDC;.
HitPatternVXD getHitPatternVXD() const
Getter for the hit pattern in the VXD;.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
std::string antiParticleListName(const std::string &listName)
Returns name of anti-particle-list corresponding to listName.
Abstract base class for different kinds of events.