Belle II Software  release-08-01-10
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 
19 #include <string>
20 namespace TestUtilities {
28  public:
30  ~TestParticleFactory() {};
41  const Belle2::Particle* produceParticle(const std::string& decayString, const ROOT::Math::PxPyPzEVector& momentum,
42  const ROOT::Math::XYZVector& vertex)
43  {
44  Belle2::DecayDescriptor* decaydescriptor = new Belle2::DecayDescriptor();
45  bool isString = decaydescriptor->init(decayString);
46  if (!isString) {
47  B2INFO("Decay string is not defined: " << decayString);
48  delete decaydescriptor;
49  return nullptr;
50  }
51  std::vector<std::string> strNames = decaydescriptor->getSelectionNames();
52  for (auto& name : strNames) {
53  B2INFO("Creation of particle: " << name);
54  }
55  // Recursive function
56  auto* result = createParticle(decaydescriptor, momentum, vertex);
57  delete decaydescriptor;
58  return result;
59  };
60 
65  {
66  int pdg = abs(particleDescription->getPDGCode());
67  if (pdg == Belle2::Const::pion.getPDGCode() || pdg == Belle2::Const::electron.getPDGCode()
68  || pdg == Belle2::Const::kaon.getPDGCode() || pdg == Belle2::Const::muon.getPDGCode()
69  || pdg == Belle2::Const::proton.getPDGCode()) {
70  return Belle2::Particle::EParticleSourceObject::c_Track;
71  }
72  if (pdg == Belle2::Const::photon.getPDGCode()) {
73  return Belle2::Particle::EParticleSourceObject::c_ECLCluster;
74  }
75  return Belle2::Particle::EParticleSourceObject::c_Composite;
76  }
77 
81  const Belle2::Particle* createParticle(const Belle2::DecayDescriptor* particleDescriptor, const ROOT::Math::PxPyPzEVector& momentum,
82  const ROOT::Math::XYZVector& vertex)
83  {
84  Belle2::Particle::EParticleSourceObject type = getType(particleDescriptor->getMother());
85  if (type == Belle2::Particle::EParticleSourceObject::c_Track) {
86  return createCharged(particleDescriptor, momentum, vertex);
87  }
88  if (type == Belle2::Particle::EParticleSourceObject::c_ECLCluster) {
89  return createPhoton(momentum);
90  }
92  //Create composite particle:
93  auto* motherDescriptor = particleDescriptor->getMother();
94  B2INFO("Mother PDG: " << motherDescriptor->getPDGCode() << " selected: " << motherDescriptor->isSelected() << " name: " <<
95  motherDescriptor->getNameSimple());
96  unsigned int nDaughters = particleDescriptor->getNDaughters();
97  Belle2::Particle mother(momentum, motherDescriptor->getPDGCode());
98  for (unsigned int i = 0; i < nDaughters; i++) {
99  auto* daughter = particleDescriptor->getDaughter(i)->getMother();
100  B2INFO("\tDaughter PDG: " << daughter->getPDGCode() << " selected: " << daughter->isSelected() << " name: " <<
101  daughter->getNameSimple());
102  auto* daughterParticle = createParticle(particleDescriptor->getDaughter(i), momentum, vertex);
103  mother.appendDaughter(daughterParticle);
104  }
105  auto* result = myParticles.appendNew(mother);
106  return result;
107  };
108 
112  const Belle2::Particle* createPhoton(const ROOT::Math::PxPyPzEVector& momentum)
113  {
116  Belle2::ECLCluster myECL;
117  myECL.setIsTrack(false);
118  //TRandom3 generator;
120  myECL.setEnergy(momentum.E());
122  //This is necessary to avoid isCopyOf == true for Belle2::ECLClusters:
123  myECL.setClusterId(m_photonIndex++);
124  Belle2::ECLCluster* savedECL = myECLClusters.appendNew(myECL);
125 
126  Belle2::Particle p(savedECL);
127  Belle2::Particle* part = myParticles.appendNew(p);
128  B2INFO("\tParticle PDG: " << part->getPDGCode() << " charge: " << part->getCharge() << " momentum: " <<
129  part->getMomentumMagnitude() << " index: " << part->getArrayIndex() << " eclindex: " << part->getECLCluster()->getArrayIndex()
130  << " theta: " << part->getECLCluster()->getTheta());
131  return part;
132  }
133 
134 
138  const Belle2::Particle* createCharged(const Belle2::DecayDescriptor* particleDescriptor, const ROOT::Math::PxPyPzEVector& momentum,
139  const ROOT::Math::XYZVector& vertex)
140  {
141  auto* particleDescription = particleDescriptor->getMother();
142  ROOT::Math::XYZVector tmomentum(momentum.X(), momentum.Y(), momentum.Z());
143  const float pValue = 0.5;
144  const float bField = 1.5;
145  TMatrixDSym cov6(6);
146  int chargefactor = (abs(particleDescription->getPDGCode()) == Belle2::Const::electron.getPDGCode()
147  || abs(particleDescription->getPDGCode()) == Belle2::Const::muon.getPDGCode()) ? -1 : 1;
148  const int charge = (particleDescription->getPDGCode()) / abs(particleDescription->getPDGCode()) * chargefactor;
149  unsigned long long int CDCValue = static_cast<unsigned long long int>(0x300000000000000);
152  myTrackFits.appendNew(vertex, tmomentum, cov6, charge, Belle2::Const::ChargedStable(abs(particleDescription->getPDGCode())), pValue,
153  bField,
154  CDCValue, 16777215, 0);
155  Belle2::Track mytrack;
157  mytrack.setTrackFitResultIndex(Belle2::Const::ChargedStable(abs(particleDescription->getPDGCode())), myTrackFits.getEntries() - 1);
158  Belle2::Track* savedTrack = myTracks.appendNew(mytrack);
159  Belle2::Particle* part = myParticles.appendNew(savedTrack, Belle2::Const::ChargedStable(abs(particleDescription->getPDGCode())));
160  B2INFO("\tParticle PDG: " << part->getPDGCode() << " charge: " << part->getCharge() << " charge: " << charge << " momentum: " <<
161  part->getMomentumMagnitude() << " index: " << part->getArrayIndex());
162  return part;
163  }
164 
165  private:
167  };
168 };
169 
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:580
int getPDGCode() const
PDG code.
Definition: Const.h:464
static const ChargedStable muon
muon particle
Definition: Const.h:651
static const ChargedStable pion
charged pion particle
Definition: Const.h:652
static const ChargedStable proton
proton particle
Definition: Const.h:654
static const ChargedStable kaon
charged kaon particle
Definition: Const.h:653
static const ParticleType photon
photon particle
Definition: Const.h:664
static const ChargedStable electron
electron particle
Definition: Const.h:650
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
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:75
EParticleSourceObject
particle source enumerators
Definition: Particle.h:82
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 (index = -1) for a specific mass hypothesis...
Definition: Track.h:174
This is a class, which generates DataStore particles, according to the provided decay string e....
int m_photonIndex
Used to differentiate photons from one another.
const Belle2::Particle * produceParticle(const std::string &decayString, const ROOT::Math::PxPyPzEVector &momentum, const ROOT::Math::XYZVector &vertex)
Main method to produce particles.
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 ROOT::Math::XYZVector &vertex)
This method is used for recursion.
const Belle2::Particle * createPhoton(const ROOT::Math::PxPyPzEVector &momentum)
Creates different photons for tests.
const Belle2::Particle * createCharged(const Belle2::DecayDescriptor *particleDescriptor, const ROOT::Math::PxPyPzEVector &momentum, const ROOT::Math::XYZVector &vertex)
Creates different charged particles for tests.