Belle II Software  release-06-01-15
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 <TLorentzVector.h>
19 
20 
21 #include <string>
22 namespace TestUtilities {
30  public:
32  ~TestParticleFactory() {};
43  const Belle2::Particle* produceParticle(const std::string& decayString, const TLorentzVector& momentum, const TVector3& 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 TLorentzVector& momentum,
83  const TVector3& 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 TLorentzVector& momentum)
114  {
117  Belle2::ECLCluster myECL;
118  myECL.setIsTrack(false);
119  //TRandom3 generator;
120  float eclREC = momentum[3];
122  myECL.setEnergy(eclREC);
124  //This is necessary to avoid isCopyOf == true for Belle2::ECLClusters:
125  myECL.setClusterId(m_photonIndex++);
126  Belle2::ECLCluster* savedECL = myECLClusters.appendNew(myECL);
127 
128  Belle2::Particle p(savedECL);
129  Belle2::Particle* part = myParticles.appendNew(p);
130  B2INFO("\tParticle PDG: " << part->getPDGCode() << " charge: " << part->getCharge() << " momentum: " <<
131  part->getMomentumMagnitude() << " index: " << part->getArrayIndex() << " eclindex: " << part->getECLCluster()->getArrayIndex()
132  << " theta: " << part->getECLCluster()->getTheta());
133  return part;
134  }
135 
136 
140  const Belle2::Particle* createCharged(const Belle2::DecayDescriptor* particleDescriptor, const TLorentzVector& momentum,
141  const TVector3& vertex)
142  {
143  auto* particleDescription = particleDescriptor->getMother();
144  TVector3 tmomentum(momentum[0], momentum[1], momentum[2]);
145  const float pValue = 0.5;
146  const float bField = 1.5;
147  TMatrixDSym cov6(6);
148  int chargefactor = (abs(particleDescription->getPDGCode()) == Belle2::Const::electron.getPDGCode()
149  || abs(particleDescription->getPDGCode()) == Belle2::Const::muon.getPDGCode()) ? -1 : 1;
150  const int charge = (particleDescription->getPDGCode()) / abs(particleDescription->getPDGCode()) * chargefactor;
151  unsigned long long int CDCValue = static_cast<unsigned long long int>(0x300000000000000);
154  myTrackFits.appendNew(vertex, tmomentum, cov6, charge, Belle2::Const::ChargedStable(abs(particleDescription->getPDGCode())), pValue,
155  bField,
156  CDCValue, 16777215, 0);
157  Belle2::Track mytrack;
159  mytrack.setTrackFitResultIndex(Belle2::Const::ChargedStable(abs(particleDescription->getPDGCode())), myTrackFits.getEntries() - 1);
160  Belle2::Track* savedTrack = myTracks.appendNew(mytrack);
161  Belle2::Particle* part = myParticles.appendNew(savedTrack, Belle2::Const::ChargedStable(abs(particleDescription->getPDGCode())));
162  B2INFO("\tParticle PDG: " << part->getPDGCode() << " charge: " << part->getCharge() << " charge: " << charge << " momentum: " <<
163  part->getMomentumMagnitude() << " index: " << part->getArrayIndex());
164  return part;
165  }
166 
167  private:
169  };
170 };
171 
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
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
EParticleSourceObject
particle source enumerators
Definition: Particle.h:81
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....
int m_photonIndex
Used to differentiate photons from one another.
const Belle2::Particle * createCharged(const Belle2::DecayDescriptor *particleDescriptor, const TLorentzVector &momentum, const TVector3 &vertex)
Creates different charged particles for tests.
const Belle2::Particle * produceParticle(const std::string &decayString, const TLorentzVector &momentum, const TVector3 &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 * createPhoton(const TLorentzVector &momentum)
Creates different photons for tests.
const Belle2::Particle * createParticle(const Belle2::DecayDescriptor *particleDescriptor, const TLorentzVector &momentum, const TVector3 &vertex)
This method is used for recursion.