Belle II Software  light-2205-abys
TestParticleFactory.h
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 #pragma once
10 #include <framework/gearbox/Const.h>
11 #include <framework/datastore/StoreArray.h>
12 #include <mdst/dataobjects/Track.h>
13 #include <mdst/dataobjects/ECLCluster.h>
14 #include <analysis/dataobjects/Particle.h>
15 #include <analysis/DecayDescriptor/DecayDescriptor.h>
16 #include <analysis/DecayDescriptor/DecayDescriptorParticle.h>
17 #include <TMatrixFSym.h>
18 #include <framework/geometry/B2Vector3.h>
19 
20 #include <string>
21 namespace TestUtilities {
29  public:
31  ~TestParticleFactory() {};
42  const Belle2::Particle* produceParticle(const std::string& decayString, const ROOT::Math::PxPyPzEVector& momentum,
43  const Belle2::B2Vector3D& vertex)
44  {
45  Belle2::DecayDescriptor* decaydescriptor = new Belle2::DecayDescriptor();
46  bool isString = decaydescriptor->init(decayString);
47  if (!isString) {
48  B2INFO("Decay string is not defined: " << decayString);
49  delete decaydescriptor;
50  return nullptr;
51  }
52  std::vector<std::string> strNames = decaydescriptor->getSelectionNames();
53  for (auto& name : strNames) {
54  B2INFO("Creation of particle: " << name);
55  }
56  // Recursive function
57  auto* result = createParticle(decaydescriptor, momentum, vertex);
58  delete decaydescriptor;
59  return result;
60  };
61 
66  {
67  int pdg = abs(particleDescription->getPDGCode());
68  if (pdg == Belle2::Const::pion.getPDGCode() || pdg == Belle2::Const::electron.getPDGCode()
69  || pdg == Belle2::Const::kaon.getPDGCode() || pdg == Belle2::Const::muon.getPDGCode()
70  || pdg == Belle2::Const::proton.getPDGCode()) {
71  return Belle2::Particle::EParticleSourceObject::c_Track;
72  }
73  if (pdg == Belle2::Const::photon.getPDGCode()) {
74  return Belle2::Particle::EParticleSourceObject::c_ECLCluster;
75  }
76  return Belle2::Particle::EParticleSourceObject::c_Composite;
77  }
78 
82  const Belle2::Particle* createParticle(const Belle2::DecayDescriptor* particleDescriptor, const ROOT::Math::PxPyPzEVector& momentum,
83  const Belle2::B2Vector3D& vertex)
84  {
85  Belle2::Particle::EParticleSourceObject type = getType(particleDescriptor->getMother());
86  if (type == Belle2::Particle::EParticleSourceObject::c_Track) {
87  return createCharged(particleDescriptor, momentum, vertex);
88  }
89  if (type == Belle2::Particle::EParticleSourceObject::c_ECLCluster) {
90  return createPhoton(momentum);
91  }
93  //Create composite particle:
94  auto* motherDescriptor = particleDescriptor->getMother();
95  B2INFO("Mother PDG: " << motherDescriptor->getPDGCode() << " selected: " << motherDescriptor->isSelected() << " name: " <<
96  motherDescriptor->getNameSimple());
97  unsigned int nDaughters = particleDescriptor->getNDaughters();
98  Belle2::Particle mother(momentum, motherDescriptor->getPDGCode());
99  for (unsigned int i = 0; i < nDaughters; i++) {
100  auto* daughter = particleDescriptor->getDaughter(i)->getMother();
101  B2INFO("\tDaughter PDG: " << daughter->getPDGCode() << " selected: " << daughter->isSelected() << " name: " <<
102  daughter->getNameSimple());
103  auto* daughterParticle = createParticle(particleDescriptor->getDaughter(i), momentum, vertex);
104  mother.appendDaughter(daughterParticle);
105  }
106  auto* result = myParticles.appendNew(mother);
107  return result;
108  };
109 
113  const Belle2::Particle* createPhoton(const ROOT::Math::PxPyPzEVector& momentum)
114  {
117  Belle2::ECLCluster myECL;
118  myECL.setIsTrack(false);
119  //TRandom3 generator;
121  myECL.setEnergy(momentum.E());
123  //This is necessary to avoid isCopyOf == true for Belle2::ECLClusters:
124  myECL.setClusterId(m_photonIndex++);
125  Belle2::ECLCluster* savedECL = myECLClusters.appendNew(myECL);
126 
127  Belle2::Particle p(savedECL);
128  Belle2::Particle* part = myParticles.appendNew(p);
129  B2INFO("\tParticle PDG: " << part->getPDGCode() << " charge: " << part->getCharge() << " momentum: " <<
130  part->getMomentumMagnitude() << " index: " << part->getArrayIndex() << " eclindex: " << part->getECLCluster()->getArrayIndex()
131  << " theta: " << part->getECLCluster()->getTheta());
132  return part;
133  }
134 
135 
139  const Belle2::Particle* createCharged(const Belle2::DecayDescriptor* particleDescriptor, const ROOT::Math::PxPyPzEVector& momentum,
140  const Belle2::B2Vector3D& vertex)
141  {
142  auto* particleDescription = particleDescriptor->getMother();
143  Belle2::B2Vector3D tmomentum(momentum.x(), momentum.y(), momentum.z());
144  const float pValue = 0.5;
145  const float bField = 1.5;
146  TMatrixDSym cov6(6);
147  int chargefactor = (abs(particleDescription->getPDGCode()) == Belle2::Const::electron.getPDGCode()
148  || abs(particleDescription->getPDGCode()) == Belle2::Const::muon.getPDGCode()) ? -1 : 1;
149  const int charge = (particleDescription->getPDGCode()) / abs(particleDescription->getPDGCode()) * chargefactor;
150  unsigned long long int CDCValue = static_cast<unsigned long long int>(0x300000000000000);
153  myTrackFits.appendNew(vertex, tmomentum, cov6, charge, Belle2::Const::ChargedStable(abs(particleDescription->getPDGCode())), pValue,
154  bField,
155  CDCValue, 16777215, 0);
156  Belle2::Track mytrack;
158  mytrack.setTrackFitResultIndex(Belle2::Const::ChargedStable(abs(particleDescription->getPDGCode())), myTrackFits.getEntries() - 1);
159  Belle2::Track* savedTrack = myTracks.appendNew(mytrack);
160  Belle2::Particle* part = myParticles.appendNew(savedTrack, Belle2::Const::ChargedStable(abs(particleDescription->getPDGCode())));
161  B2INFO("\tParticle PDG: " << part->getPDGCode() << " charge: " << part->getCharge() << " charge: " << charge << " momentum: " <<
162  part->getMomentumMagnitude() << " index: " << part->getArrayIndex());
163  return part;
164  }
165 
166  private:
168  };
169 };
170 
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:470
int getPDGCode() const
PDG code.
Definition: Const.h:354
static const ChargedStable muon
muon particle
Definition: Const.h:541
static const ChargedStable pion
charged pion particle
Definition: Const.h:542
static const ChargedStable proton
proton particle
Definition: Const.h:544
static const ChargedStable kaon
charged kaon particle
Definition: Const.h:543
static const ParticleType photon
photon particle
Definition: Const.h:554
static const ChargedStable electron
electron particle
Definition: Const.h:540
Represents a particle in the DecayDescriptor.
int getPDGCode() const
Return PDG code.
The DecayDescriptor stores information about a decay tree or parts of a decay tree.
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
const DecayDescriptorParticle * getMother() const
return mother.
int getNDaughters() const
return number of direct daughters.
const DecayDescriptor * getDaughter(int i) const
return i-th daughter (0 based index).
std::vector< std::string > getSelectionNames()
Return list of human readable names of selected particles.
ECL cluster data.
Definition: ECLCluster.h:27
void setConnectedRegionId(int crid)
Set connected region id.
Definition: ECLCluster.h:142
void setClusterId(int clusterid)
Set cluster id.
Definition: ECLCluster.h:145
void setHypothesis(EHypothesisBit hypothesis)
Set hypotheses.
Definition: ECLCluster.h:123
void setEnergy(double energy)
Set Corrected Energy (GeV).
Definition: ECLCluster.h:226
double getTheta() const
Return Corrected Theta of Shower (radian).
Definition: ECLCluster.h:304
void setIsTrack(bool istrack)
Set m_isTrack true if the cluster matches with a track.
Definition: ECLCluster.h:104
@ c_nPhotons
CR is split into n photons (N1)
Class to store reconstructed particles.
Definition: Particle.h:74
const ECLCluster * getECLCluster() const
Returns the pointer to the ECLCluster object that was used to create this Particle (if ParticleType =...
Definition: Particle.cc:883
EParticleSourceObject
particle source enumerators
Definition: Particle.h:81
int getPDGCode(void) const
Returns PDG code.
Definition: Particle.h:403
double getCharge(void) const
Returns particle charge.
Definition: Particle.cc:645
double getMomentumMagnitude() const
Returns momentum magnitude.
Definition: Particle.h:506
void appendDaughter(const Particle *daughter, const bool updateType=true)
Appends index of daughter to daughters index array.
Definition: Particle.cc:700
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Class that bundles various TrackFitResults.
Definition: Track.h:25
void setTrackFitResultIndex(const Const::ChargedStable &chargedStable, short index)
Set an index (for positive values) or unavailability-code (with negative values) for a specific mass ...
Definition: Track.h:94
This is a class, which generates DataStore particles, according to the provided decay string e....
const Belle2::Particle * createCharged(const Belle2::DecayDescriptor *particleDescriptor, const ROOT::Math::PxPyPzEVector &momentum, const Belle2::B2Vector3D &vertex)
Creates different charged particles for tests.
int m_photonIndex
Used to differentiate photons from one another.
Belle2::Particle::EParticleSourceObject getType(const Belle2::DecayDescriptorParticle *particleDescription)
Helper method to get EParticleSourceObject from PDG code.
const Belle2::Particle * createParticle(const Belle2::DecayDescriptor *particleDescriptor, const ROOT::Math::PxPyPzEVector &momentum, const Belle2::B2Vector3D &vertex)
This method is used for recursion.
const Belle2::Particle * createPhoton(const ROOT::Math::PxPyPzEVector &momentum)
Creates different photons for tests.
const Belle2::Particle * produceParticle(const std::string &decayString, const ROOT::Math::PxPyPzEVector &momentum, const Belle2::B2Vector3D &vertex)
Main method to produce particles.