All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
VertexMCOperator.cc
Go to the documentation of this file.
1 #include "VertexMCOperator.hh"
2 using EVENT::Vertex;
3 using std::vector;
4 using std::string;
5 using EVENT::MCParticle;
6 using EVENT::ReconstructedParticle;
7 using IMPL::VertexImpl;
8 using IMPL::ReconstructedParticleImpl;
9 using EVENT::LCCollection;
10 using UTIL::LCRelationNavigator;
11 namespace TTbarAnalysis
12 {
13  VertexMCOperator:: VertexMCOperator(LCCollection * rel)
14  {
15  myRelCollection = rel;
16  }
17  vector< Vertex * > * VertexMCOperator::Construct(DecayChain * chain)
18  {
19  if (!chain || chain->GetSize() == 0)
20  {
21  return NULL;
22  }
23 
24  vector< Vertex * > * result = new vector< Vertex * >();
25  const double * ip = chain->Get(0)->getVertex();
26  for (int i = 1; i < chain->GetSize(); i++) // <<==============================
27  {
28  result->push_back(construct(chain->Get(i), ip, chain->GetParentPDG(), i+1));
29  }
30  for (unsigned int i = 0; i < result->size(); i++)
31  {
32  addParticle(result->at(i), chain->Get(i));
33  }
34  return result;
35  }
36 
37  Vertex * VertexMCOperator::construct(EVENT::MCParticle * particle, const double * ip, int pdg, int number)
38  {
39  //VertexImpl * result = new VertexImpl();
40  MyVertex * result = new MyVertex();
41 
42  const double * initial;
43  initial = particle->getVertex();
44  float distance = MathOperator::getDistance(ip, initial);
45  result->setPrimary(false);
46  result->setAlgorithmType("VertexMCOperator");
47 
48  result->setPosition(initial[0], initial[1], initial[2]);
49  result->addParameter (distance);
50  result->addParameter (pdg);
51  result->addParameter (number);
52 
53  return result;
54  }
55  void VertexMCOperator::AddProngs(Vertex * vertex, vector< MCParticle * > & particles, bool usingRelation)
56  {
57  if (!vertex || particles.size() == 0)
58  {
59  streamlog_out(DEBUG) << "ERRORMC: argument is null!\n";
60  return;
61  }
62  ReconstructedParticle * reco = vertex->getAssociatedParticle();
63  for (unsigned int i = 0; i < particles.size(); i++)
64  {
65  ReconstructedParticle * prong =(usingRelation)? getReco(particles[i]) : translate(particles[i]);
66  if (prong)
67  {
68  reco->addParticle(prong);
69  }
70  else
71  {
72  streamlog_out(DEBUG) << "ERROR: Corrupted vertex!\n";
73 
74  }
75  }
76  MyVertex * myvertex = static_cast< MyVertex * >(vertex);
77  myvertex->__SetMCParticles(particles);
78  //streamlog_out(DEBUG) << "Added " << myvertex->__GetMCParticles().size() << " particles!\n";
79 
80  }
81  void VertexMCOperator::addParticle(Vertex * vertex, MCParticle * particle)
82  {
83  if (!vertex || !particle)
84  {
85  streamlog_out(DEBUG) << "ERRORMC: argument is null!\n";
86  return;
87  }
88  ReconstructedParticle * reco = translate(particle);
89  VertexImpl * ivertex = static_cast<VertexImpl*>(vertex);
90  ivertex->setAssociatedParticle(reco);
91  }
92  ReconstructedParticle * VertexMCOperator::getReco(EVENT::MCParticle * particle)
93  {
94  LCRelationNavigator navigator(myRelCollection);
95  int nvtx = navigator.getRelatedFromObjects(particle).size();
96  streamlog_out(DEBUG) << "Particles: " << nvtx <<'\n';
97  ReconstructedParticle * reco = NULL; // check!!!
98  int winner = -1;
99  float weight = 0.0;
100  const vector< float > weights = navigator.getRelatedFromWeights(particle);
101  if (nvtx > 0)
102  {
103  for (int i = 0; i < nvtx; i++)
104  {
105  if (weights[i] > weight)
106  {
107  winner = i;
108  weight = weights[i];
109  }
110  }
111  reco = dynamic_cast<ReconstructedParticle*>(navigator.getRelatedFromObjects(particle)[winner]);
112  }
113 
114  return reco;
115  }
116  ReconstructedParticle * VertexMCOperator::translate(EVENT::MCParticle * particle)
117  {
118  ReconstructedParticleImpl * reco = new ReconstructedParticleImpl();
119  reco->setType(particle->getPDG());
120  reco->setMass(particle->getMass());
121  reco->setCharge(particle->getCharge());
122  reco->setMomentum(particle->getMomentum());
123  reco->setEnergy(particle->getEnergy());
124  return reco;
125  }
126 } /* TTbarAnalysis */
VertexMCOperator(EVENT::LCCollection *rel)
EVENT::ReconstructedParticle * translate(EVENT::MCParticle *particle)
int GetParentPDG() const
Definition: DecayChain.cc:50
void addParticle(EVENT::Vertex *vertex, EVENT::MCParticle *particle)
EVENT::LCCollection * myRelCollection
void __SetMCParticles(const std::vector< EVENT::MCParticle * > particles)
Definition: MyVertex.cc:11
EVENT::Vertex * construct(EVENT::MCParticle *particle, const double *ip, int pdg, int number)
std::vector< EVENT::Vertex * > * Construct(DecayChain *chain)
static float getDistance(const double *start, const double *end)
Definition: MathOperator.cc:22
EVENT::ReconstructedParticle * getReco(EVENT::MCParticle *particle)
EVENT::MCParticle * Get(int i)
Definition: DecayChain.cc:23
void AddProngs(EVENT::Vertex *vertex, std::vector< EVENT::MCParticle * > &particles, bool usingRelation=false)