Belle II Software  release-05-02-19
TestParticleFactory.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Sviatoslav Bilokin *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 #include <framework/gearbox/Const.h>
13 #include <framework/datastore/StoreArray.h>
14 #include <mdst/dataobjects/Track.h>
15 #include <mdst/dataobjects/ECLCluster.h>
16 #include <analysis/dataobjects/Particle.h>
17 #include <analysis/DecayDescriptor/DecayDescriptor.h>
18 #include <analysis/DecayDescriptor/DecayDescriptorParticle.h>
19 #include <TMatrixFSym.h>
20 #include <TLorentzVector.h>
21 
22 
23 #include <string>
24 namespace TestUtilities {
31  class TestParticleFactory {
32  public:
33  TestParticleFactory(): m_photonIndex(0) {};
34  ~TestParticleFactory() {};
45  const Belle2::Particle* produceParticle(const std::string& decayString, const TLorentzVector& momentum, const TVector3& vertex)
46  {
48  Belle2::DecayDescriptor* decaydescriptor = new Belle2::DecayDescriptor();
49  bool isString = decaydescriptor->init(decayString);
50  if (!isString) {
51  B2INFO("Decay string is not defined: " << decayString);
52  delete decaydescriptor;
53  return nullptr;
54  }
55  std::vector<std::string> strNames = decaydescriptor->getSelectionNames();
56  for (auto& name : strNames) {
57  B2INFO("Creation of particle: " << name);
58  }
59  // Recursive function
60  auto* result = createParticle(decaydescriptor, momentum, vertex);
61  delete decaydescriptor;
62  return result;
63  };
64 
69  {
70  int pdg = abs(particleDescription->getPDGCode());
71  if (pdg == Belle2::Const::pion.getPDGCode() || pdg == Belle2::Const::electron.getPDGCode()
72  || pdg == Belle2::Const::kaon.getPDGCode() || pdg == Belle2::Const::muon.getPDGCode()
73  || pdg == Belle2::Const::proton.getPDGCode()) {
74  return Belle2::Particle::EParticleSourceObject::c_Track;
75  }
76  if (pdg == Belle2::Const::photon.getPDGCode()) {
77  return Belle2::Particle::EParticleSourceObject::c_ECLCluster;
78  }
79  return Belle2::Particle::EParticleSourceObject::c_Composite;
80  }
81 
85  const Belle2::Particle* createParticle(const Belle2::DecayDescriptor* particleDescriptor, const TLorentzVector& momentum,
86  const TVector3& vertex)
87  {
88  Belle2::Particle::EParticleSourceObject type = getType(particleDescriptor->getMother());
89  if (type == Belle2::Particle::EParticleSourceObject::c_Track) {
90  return createCharged(particleDescriptor, momentum, vertex);
91  }
92  if (type == Belle2::Particle::EParticleSourceObject::c_ECLCluster) {
93  return createPhoton(momentum);
94  }
96  //Create composite particle:
97  auto* motherDescriptor = particleDescriptor->getMother();
98  B2INFO("Mother PDG: " << motherDescriptor->getPDGCode() << " selected: " << motherDescriptor->isSelected() << " name: " <<
99  motherDescriptor->getNameSimple());
100  unsigned int nDaughters = particleDescriptor->getNDaughters();
101  Belle2::Particle mother(momentum, motherDescriptor->getPDGCode());
102  for (unsigned int i = 0; i < nDaughters; i++) {
103  auto* daughter = particleDescriptor->getDaughter(i)->getMother();
104  B2INFO("\tDaughter PDG: " << daughter->getPDGCode() << " selected: " << daughter->isSelected() << " name: " <<
105  daughter->getNameSimple());
106  auto* daughterParticle = createParticle(particleDescriptor->getDaughter(i), momentum, vertex);
107  mother.appendDaughter(daughterParticle);
108  }
109  auto* result = myParticles.appendNew(mother);
110  return result;
111  };
112 
116  const Belle2::Particle* createPhoton(const TLorentzVector& momentum)
117  {
120  Belle2::ECLCluster myECL;
121  myECL.setIsTrack(false);
122  //TRandom3 generator;
123  float eclREC = momentum[3];
125  myECL.setEnergy(eclREC);
127  //This is necessary to avoid isCopyOf == true for Belle2::ECLClusters:
128  myECL.setClusterId(m_photonIndex++);
129  Belle2::ECLCluster* savedECL = myECLClusters.appendNew(myECL);
130 
131  Belle2::Particle p(savedECL);
132  Belle2::Particle* part = myParticles.appendNew(p);
133  B2INFO("\tParticle PDG: " << part->getPDGCode() << " charge: " << part->getCharge() << " momentum: " <<
134  part->getMomentumMagnitude() << " index: " << part->getArrayIndex() << " eclindex: " << part->getECLCluster()->getArrayIndex()
135  << " theta: " << part->getECLCluster()->getTheta());
136  return part;
137  }
138 
139 
143  const Belle2::Particle* createCharged(const Belle2::DecayDescriptor* particleDescriptor, const TLorentzVector& momentum,
144  const TVector3& vertex)
145  {
146  auto* particleDescription = particleDescriptor->getMother();
147  TVector3 tmomentum(momentum[0], momentum[1], momentum[2]);
148  const float pValue = 0.5;
149  const float bField = 1.5;
150  TMatrixDSym cov6(6);
151  int chargefactor = (abs(particleDescription->getPDGCode()) == Belle2::Const::electron.getPDGCode()
152  || abs(particleDescription->getPDGCode()) == Belle2::Const::muon.getPDGCode()) ? -1 : 1;
153  const int charge = (particleDescription->getPDGCode()) / abs(particleDescription->getPDGCode()) * chargefactor;
154  unsigned long long int CDCValue = static_cast<unsigned long long int>(0x300000000000000);
157  myTrackFits.appendNew(vertex, tmomentum, cov6, charge, Belle2::Const::ChargedStable(abs(particleDescription->getPDGCode())), pValue,
158  bField,
159  CDCValue, 16777215, 0);
160  Belle2::Track mytrack;
162  mytrack.setTrackFitResultIndex(Belle2::Const::ChargedStable(abs(particleDescription->getPDGCode())), myTrackFits.getEntries() - 1);
163  Belle2::Track* savedTrack = myTracks.appendNew(mytrack);
164  Belle2::Particle* part = myParticles.appendNew(savedTrack, Belle2::Const::ChargedStable(abs(particleDescription->getPDGCode())));
165  B2INFO("\tParticle PDG: " << part->getPDGCode() << " charge: " << part->getCharge() << " charge: " << charge << " momentum: " <<
166  part->getMomentumMagnitude() << " index: " << part->getArrayIndex());
167  return part;
168  }
169 
170  private:
171  int m_photonIndex;
172  };
173 };
174 
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
Belle2::Const::photon
static const ParticleType photon
photon particle
Definition: Const.h:547
Belle2::ECLCluster::setIsTrack
void setIsTrack(bool istrack)
Set m_isTrack true if the cluster matches with a track.
Definition: ECLCluster.h:115
Belle2::ECLCluster
ECL cluster data.
Definition: ECLCluster.h:39
Belle2::Const::electron
static const ChargedStable electron
electron particle
Definition: Const.h:533
TestUtilities::TestParticleFactory::createPhoton
const Belle2::Particle * createPhoton(const TLorentzVector &momentum)
Creates different photons for tests.
Definition: TestParticleFactory.h:132
TestUtilities::TestParticleFactory::getType
Belle2::Particle::EParticleSourceObject getType(const Belle2::DecayDescriptorParticle *particleDescription)
Helper method to get EParticleSourceObject from PDG code.
Definition: TestParticleFactory.h:84
Belle2::DecayDescriptorParticle::getPDGCode
int getPDGCode() const
Return PDG code.
Definition: DecayDescriptorParticle.h:89
Belle2::DecayDescriptorParticle
Represents a particle in the DecayDescriptor.
Definition: DecayDescriptorParticle.h:37
Belle2::ECLCluster::EHypothesisBit::c_nPhotons
@ c_nPhotons
CR is split into n photons (N1)
Belle2::Const::ParticleType::getPDGCode
int getPDGCode() const
PDG code.
Definition: Const.h:349
Belle2::ECLCluster::setHypothesis
void setHypothesis(EHypothesisBit hypothesis)
Set hypotheses.
Definition: ECLCluster.h:134
Belle2::DecayDescriptor::getSelectionNames
std::vector< std::string > getSelectionNames()
Return list of human readable names of selected particles.
Definition: DecayDescriptor.cc:343
Belle2::DecayDescriptor::init
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
Definition: DecayDescriptor.cc:47
Belle2::ECLCluster::setEnergy
void setEnergy(double energy)
Set Corrected Energy (GeV).
Definition: ECLCluster.h:238
Belle2::ECLCluster::setConnectedRegionId
void setConnectedRegionId(int crid)
Set connected region id.
Definition: ECLCluster.h:153
Belle2::Const::kaon
static const ChargedStable kaon
charged kaon particle
Definition: Const.h:536
Belle2::Const::pion
static const ChargedStable pion
charged pion particle
Definition: Const.h:535
TestUtilities::TestParticleFactory::m_photonIndex
int m_photonIndex
Used to differentiate photons from one another.
Definition: TestParticleFactory.h:187
Belle2::Track::setTrackFitResultIndex
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:104
TestUtilities::TestParticleFactory::createParticle
const Belle2::Particle * createParticle(const Belle2::DecayDescriptor *particleDescriptor, const TLorentzVector &momentum, const TVector3 &vertex)
This method is used for recursion.
Definition: TestParticleFactory.h:101
Belle2::DecayDescriptor::getDaughter
const DecayDescriptor * getDaughter(int i) const
return i-th daughter (0 based index).
Definition: DecayDescriptor.h:146
Belle2::ECLCluster::setClusterId
void setClusterId(int clusterid)
Set cluster id.
Definition: ECLCluster.h:156
Belle2::DecayDescriptor::getNDaughters
int getNDaughters() const
return number of direct daughters.
Definition: DecayDescriptor.h:141
Belle2::Particle::EParticleSourceObject
EParticleSourceObject
particle source enumerators
Definition: Particle.h:84
TestUtilities::TestParticleFactory::createCharged
const Belle2::Particle * createCharged(const Belle2::DecayDescriptor *particleDescriptor, const TLorentzVector &momentum, const TVector3 &vertex)
Creates different charged particles for tests.
Definition: TestParticleFactory.h:159
TestUtilities::TestParticleFactory::produceParticle
const Belle2::Particle * produceParticle(const std::string &decayString, const TLorentzVector &momentum, const TVector3 &vertex)
Main method to produce particles.
Definition: TestParticleFactory.h:61
Belle2::Particle
Class to store reconstructed particles.
Definition: Particle.h:77
Belle2::Const::proton
static const ChargedStable proton
proton particle
Definition: Const.h:537
Belle2::Const::ChargedStable
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:465
Belle2::DecayDescriptor
The DecayDescriptor stores information about a decay tree or parts of a decay tree.
Definition: DecayDescriptor.h:43
Belle2::Const::muon
static const ChargedStable muon
muon particle
Definition: Const.h:534
Belle2::Track
Class that bundles various TrackFitResults.
Definition: Track.h:35
Belle2::StoreArray< Belle2::Particle >
Belle2::DecayDescriptor::getMother
const DecayDescriptorParticle * getMother() const
return mother.
Definition: DecayDescriptor.h:136
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226