Belle II Software  release-08-01-10
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 #include <framework/geometry/B2Vector3.h>
17 
18 #include <Math/Vector3D.h>
19 #include <vector>
20 
21 using namespace Belle2;
22 
23 //-----------------------------------------------------------------
24 // Register the Module
25 //-----------------------------------------------------------------
26 REG_MODULE(HelixErrorScaler);
27 
28 //-----------------------------------------------------------------
29 // Implementation
30 //-----------------------------------------------------------------
31 
32 HelixErrorScalerModule::HelixErrorScalerModule() : Module(), m_pdgCode(0), m_scaleKshort(false)
33 {
34  // Set module properties
35  setDescription(R"DOC(scale the error of helix parameters
36 
37  Creates a new charged particle list whose helix errors are scaled by constant factors.
38  Different sets of scale factors are defined for tracks with/without a PXD hit.
39  For tracks with a PXD hit, in order to avoid severe underestimation of d0 and z0 errors,
40  lower limits (best resolution) can be set in a momentum-dependent form.
41  The module also accepts a V0 Kshort particle list as input and applies the error correction to its daughters.
42  Note the difference in impact parameter resolution between V0 daughters and tracks from IP,
43  as V0 daughters are free from multiple scattering through the beam pipe.
44  )DOC");
45 
46  // Parameter definitions
47  addParam("inputListName", m_inputListName, "The name of input particle list (charged stable or V0 Kshort)", std::string(""));
48  addParam("outputListName", m_outputListName, "The name of output charged particle list", std::string(""));
49  addParam("scaleFactors_PXD", m_scaleFactors_PXD,
50  "vector of five scale factors for helix parameter errors (for tracks with a PXD hit)", {1.0, 1.0, 1.0, 1.0, 1.0});
51  addParam("scaleFactors_noPXD", m_scaleFactors_noPXD,
52  "vector of five scale factors for helix parameter errors (for tracks without a PXD hit)", {1.0, 1.0, 1.0, 1.0, 1.0});
53  addParam("d0ResolutionParameters", m_d0ResolPars, "d0 best resolution parameters", {0.0, 0.0});
54  addParam("z0ResolutionParameters", m_z0ResolPars, "z0 best resolution parameters", {0.0, 0.0});
55  addParam("d0MomentumThreshold", m_d0MomThr, "d0 best resolution is kept constant below this momentum.", 0.0);
56  addParam("z0MomentumThreshold", m_z0MomThr, "z0 best resolution is kept constant below this momentum.", 0.0);
57 
58 }
59 
61 {
62  // check the validity of output ParticleList name
64  if (!valid)
65  B2ERROR("Invalid output ParticleList name: " << m_outputListName);
66 
67  // output particle
69  m_pdgCode = mother->getPDGCode();
70  if (m_pdgCode == Const::Kshort.getPDGCode()) {
71  m_scaleKshort = true;
72  } else if (Const::chargedStableSet.find(abs(m_pdgCode)) == Const::invalidParticle) {
73  B2ERROR("Invalid input ParticleList PDG code (must be ChargedStable): " << m_pdgCode);
74  }
75 
76  // get existing particle lists
78  B2ERROR("Input and output particle list names are the same: " << m_inputListName);
79  } else if (!m_decaydescriptor.init(m_inputListName)) {
80  B2ERROR("Invalid input particle list name: " << m_inputListName);
81  } else {
83  }
84 
85  // make output list
86  m_outputparticleList.registerInDataStore(m_outputListName);
87  if (! m_scaleKshort) {
90  }
91 
92  m_particles.registerRelationTo(m_pidlikelihoods);
93  m_particles.registerRelationTo(m_trackfitresults);
94 }
95 
97 {
98  RelationArray particlesToMCParticles(m_particles, m_mcparticles);
99 
100  // new output particle list
101  if (! m_outputparticleList.isValid()) {
102  m_outputparticleList.create();
104  }
105 
106  if (! m_scaleKshort) {
107  m_outputAntiparticleList.create();
109  m_outputAntiparticleList->bindAntiParticleList(*(m_outputparticleList));
110  }
111 
112  if (m_scaleKshort) { // scale V0 Kshort
113 
114  // loop over Kshort
115  const unsigned int nPar = m_inputparticleList->getListSize();
116  for (unsigned i = 0; i < nPar; i++) {
117  const Particle* particle = m_inputparticleList->getParticle(i);
118  if (particle->getParticleSource() != Particle::EParticleSourceObject::c_V0) {
119  B2WARNING(" Input ParticleList " << m_inputListName <<
120  " contains a particle which is not from V0. It will not be copied to output list.");
121  continue;
122  }
123 
124  if (particle->getNDaughters() != 2)
125  B2ERROR("V0 particle should have exactly two daughters");
126 
127  const Particle* dauP = particle->getDaughter(0);
128  const Particle* dauM = particle->getDaughter(1);
129 
130  Particle* newDauP = getChargedWithScaledError(dauP);
131  Particle* newDauM = getChargedWithScaledError(dauM);
132 
133  ROOT::Math::PxPyPzEVector v0Momentum = newDauP->get4Vector() + newDauM->get4Vector();
134  Particle new_v0(v0Momentum, m_pdgCode, particle->getFlavorType(),
135  Particle::EParticleSourceObject::c_V0, particle->getMdstArrayIndex());
136  new_v0.appendDaughter(newDauP, false);
137  new_v0.appendDaughter(newDauM, false);
138 
139  Particle* newV0 = m_particles.appendNew(new_v0);
140  m_outputparticleList->addParticle(newV0);
141 
142  } // loop over Kshort
143 
144  } else { // scale charged particles
145 
146  // loop over charged particles
147  const unsigned int nPar = m_inputparticleList->getListSize();
148  for (unsigned i = 0; i < nPar; i++) {
149  const Particle* charged = m_inputparticleList->getParticle(i);
150  Particle* newCharged = getChargedWithScaledError(charged);
151  m_outputparticleList->addParticle(newCharged);
152  }
153  }
154 
155 }
156 
158 {
159  const TrackFitResult* new_trkfit = getTrackFitResultWithScaledError(particle);
160 
161  Const::ChargedStable chargedtype(abs(particle->getPDGCode()));
162  Particle new_charged(particle->getMdstArrayIndex(), new_trkfit, chargedtype);
163  Particle* newCharged = m_particles.appendNew(new_charged);
164 
165  // add relation to PID, MCParticle (if any) and TrackFitResult
166  const PIDLikelihood* pid = particle->getPIDLikelihood();
167  const MCParticle* mcCharged = particle->getRelated<MCParticle>();
168  newCharged->addRelationTo(new_trkfit);
169  if (pid) newCharged->addRelationTo(pid);
170  if (mcCharged != nullptr) newCharged->addRelationTo(mcCharged);
171 
172  return newCharged;
173 }
174 
176 {
177  const TrackFitResult* trkfit = particle->getTrackFitResult();
178 
179  const std::vector<float> helix = trkfit->getTau();
180  const std::vector<float> cov5 = trkfit->getCov();
181  const Const::ParticleType ptype = trkfit->getParticleType();
182  const double pvalue = trkfit->getPValue();
183  const ULong64_t hitCDC = trkfit->getHitPatternCDC().getInteger();
184  const ULong64_t hitVXD = trkfit->getHitPatternVXD().getInteger();
185  const int ndf = trkfit->getNDF();
186 
187  std::vector<double> scaleFactors = getScaleFactors(particle, trkfit);
188  std::vector<float> cov5_scaled;
189  unsigned int counter = 0;
190  for (unsigned int j = 0; j < 5; j++) {
191  for (unsigned int k = j; k < 5; k++) {
192  cov5_scaled.push_back(cov5[counter++] * scaleFactors[j] * scaleFactors[k]);
193  }
194  }
195  TrackFitResult* new_trkfit = m_trackfitresults.appendNew(helix, cov5_scaled, ptype, pvalue, hitCDC, hitVXD, ndf);
196  return new_trkfit;
197 }
198 
199 std::vector<double> HelixErrorScalerModule::getScaleFactors(const Particle* particle, const TrackFitResult* trkfit)
200 {
201  if (trkfit->getHitPatternVXD().getNPXDHits() > 0) {
202 
203  // d0, z0 resolution = a (+) b / pseudo-momentum
204  B2Vector3D p = particle->getMomentum();
205  double sinTheta = TMath::Sin(p.Theta());
206  double pD0 = p.Mag2() / (particle->getEnergy()) * TMath::Power(sinTheta, 1.5); // p*beta*sinTheta**1.5
207  double pZ0 = pD0 * sinTheta; // p*beta*sinTheta**2.5
208 
209  pD0 = TMath::Max(pD0, m_d0MomThr); // if pD0 is smaller than the threshold, *overwrite* it with the threshold.
210  pZ0 = TMath::Max(pZ0, m_z0MomThr); // if pZ0 is smaller than the threshold, *overwrite* it with the threshold.
211  double d0Resol = TMath::Sqrt(TMath::Power(m_d0ResolPars[0], 2) + TMath::Power(m_d0ResolPars[1] / pD0, 2));
212  double z0Resol = TMath::Sqrt(TMath::Power(m_z0ResolPars[0], 2) + TMath::Power(m_z0ResolPars[1] / pZ0, 2));
213  double d0Err = TMath::Sqrt(trkfit->getCovariance5()[0][0]);
214  double z0Err = TMath::Sqrt(trkfit->getCovariance5()[3][3]);
215 
216  std::vector<double> scaleFactors = { TMath::Max(d0Resol / d0Err, m_scaleFactors_PXD[0]),
219  TMath::Max(z0Resol / z0Err, m_scaleFactors_PXD[3]),
221  };
222  return scaleFactors;
223  } else {
224  return m_scaleFactors_noPXD;
225  }
226 }
227 
228 
229 
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:580
The ParticleType class for identifying different particle types.
Definition: Const.h:399
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:609
static const ParticleType invalidParticle
Invalid particle, used internally.
Definition: Const.h:672
static const ParticleType Kshort
K^0_S particle.
Definition: Const.h:668
Represents a particle in the DecayDescriptor.
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
const DecayDescriptorParticle * getMother() const
return mother.
bool m_scaleKshort
Whether the input particle list is Kshort or not.
StoreArray< TrackFitResult > m_trackfitresults
StoreArray of TrackFitResult objects.
std::vector< double > m_d0ResolPars
parameters (a,b) to define d0 best resolution = a (+) b / (p*beta*sinTheta**1.5)
StoreObjPtr< ParticleList > m_outputparticleList
StoreObjptr for output particlelist.
virtual void initialize() override
Register input and output data.
virtual void event() override
loop over the input charged particles
StoreArray< MCParticle > m_mcparticles
StoreArray of MCParticle objects.
double m_d0MomThr
d0 best resolution is kept constant below this momentum.
std::vector< double > m_scaleFactors_PXD
vector of five scale factors for helix parameter errors (for tracks with a PXD hit)
StoreArray< Particle > m_particles
StoreArray of Particle objects.
std::vector< double > getScaleFactors(const Particle *particle, const TrackFitResult *trkfit)
get scale factors
StoreArray< PIDLikelihood > m_pidlikelihoods
StoreArray of PIDLikelihood objects.
HelixErrorScalerModule()
Constructor: Sets the description, the properties and the parameters of the module.
const TrackFitResult * getTrackFitResultWithScaledError(const Particle *particle)
create a TrackFitResult with scaled errors
std::vector< double > m_z0ResolPars
parameters (a,b) to define z0 best resolution = a (+) b / (p*beta*sinTheta**2.5)
StoreObjPtr< ParticleList > m_inputparticleList
StoreObjptr for input charged particlelist.
Particle * getChargedWithScaledError(const Particle *particle)
create a Particle with scaled errors
StoreObjPtr< ParticleList > m_outputAntiparticleList
StoreObjptr for output antiparticlelist.
DecayDescriptor m_decaydescriptor
Decay descriptor of the charged particle.
double m_z0MomThr
z0 best resolution is kept constant below this momentum.
int m_pdgCode
PDG code of the charged particle to be scaled.
std::string m_outputAntiListName
output anti-particle list name
std::vector< double > m_scaleFactors_noPXD
vector of five scale factors for helix parameter errors (for tracks without a PXD hit)
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
unsigned short getNPXDHits() const
Get total number of hits in the PXD.
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
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:75
void appendDaughter(const Particle *daughter, const bool updateType=true, const int daughterProperty=c_Ordinary)
Appends index of daughter to daughters index array.
Definition: Particle.cc:680
ROOT::Math::PxPyPzEVector get4Vector() const
Returns Lorentz vector.
Definition: Particle.h:517
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).
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.
float getNDF() const
Getter for number of degrees of freedom of the track fit.
double getPValue() const
Getter for Chi2 Probability 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;.
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
std::string antiParticleListName(const std::string &listName)
Returns name of anti-particle-list corresponding to listName.
Abstract base class for different kinds of events.