~ma5/madanalysis5/madanalysis-development

« back to all changes in this revision

Viewing changes to tools/SampleAnalyzer/Commons/DataFormat/MCEventFormat.cpp

  • Committer: Benjamin Fuks
  • Date: 2018-05-04 10:44:49 UTC
  • mfrom: (115.1.81 v1.6beta)
  • Revision ID: fuks@cern.ch-20180504104449-60h8a00loxgr8zg0
Releasing v1.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// SampleAnalyzer headers
 
2
#include "SampleAnalyzer/Commons/DataFormat/MCEventFormat.h"
 
3
#include <set>
 
4
 
 
5
using namespace MA5;
 
6
 
 
7
struct VertexInfo
 
8
{
 
9
  std::vector<const MCParticleFormat*> in;
 
10
  std::vector<const MCParticleFormat*> out;
 
11
};
 
12
 
 
13
MAbool CompareMothers(const std::vector<const MCParticleFormat*>& a, const std::vector<const MCParticleFormat*>& b)
 
14
{
 
15
  std::set<const MCParticleFormat*> aa;
 
16
  std::set<const MCParticleFormat*> bb;
 
17
  for (unsigned int i=0;i<a.size();i++) aa.insert(a[i]);
 
18
  for (unsigned int i=0;i<b.size();i++) bb.insert(b[i]);
 
19
  if (aa==bb) return true; else return false;
 
20
}
 
21
 
 
22
MAbool CompareMothers(const std::vector<const MCParticleFormat*>& a, const std::vector<MCParticleFormat*>& b)
 
23
{
 
24
  std::set<const MCParticleFormat*> aa;
 
25
  std::set<const MCParticleFormat*> bb;
 
26
  for (unsigned int i=0;i<a.size();i++) aa.insert(a[i]);
 
27
  for (unsigned int i=0;i<b.size();i++) bb.insert(b[i]);
 
28
  if (aa==bb) return true; else return false;
 
29
}
 
30
 
 
31
void MCEventFormat::PrintVertices() const
 
32
{
 
33
  std::vector<VertexInfo> vertices;
 
34
  for (MAuint32 i=0;i<particles_.size();i++)
 
35
  {
 
36
    const MCParticleFormat* part = &(particles_[i]);
 
37
    if (part->mothers().empty())   continue;
 
38
 
 
39
    VertexInfo myVertex;
 
40
    for (MAuint32 j=0;j<part->mothers().size();j++)
 
41
    {
 
42
      myVertex.in.push_back(part->mothers()[j]);
 
43
    }
 
44
    for (MAuint32 j=0;j<particles_.size();j++)
 
45
    {
 
46
      if (CompareMothers(myVertex.in,particles_[j].mothers()))
 
47
      {
 
48
        myVertex.out.push_back(&(particles_[j]));
 
49
      }
 
50
    }
 
51
    bool ok=true;
 
52
    for (MAuint32 j=0;j<vertices.size();j++)
 
53
    {
 
54
      if (CompareMothers(myVertex.in,vertices[j].in) && CompareMothers(myVertex.out,vertices[j].out))
 
55
      {
 
56
        ok=false; break;
 
57
      }
 
58
    }
 
59
    if (ok) vertices.push_back(myVertex);
 
60
  }
 
61
  std::cout << "# vertices = " << vertices.size() << std::endl;
 
62
  for (unsigned int i=0;i<vertices.size();i++)
 
63
  {
 
64
    std::cout << " - ( ";
 
65
    for (unsigned int j=0;j<vertices[i].in.size();j++)
 
66
    {
 
67
      if (j!=0) std::cout << " ++ ";
 
68
      std::cout << vertices[i].in[j]->pdgid();
 
69
    }
 
70
    std::cout << " ) --> ( ";
 
71
    for (unsigned int j=0;j<vertices[i].out.size();j++)
 
72
    {
 
73
      if (j!=0) std::cout << " ++ ";
 
74
      std::cout << vertices[i].out[j]->pdgid();
 
75
    }
 
76
    std::cout << " )" << std::endl;
 
77
  }
 
78
}
 
79
 
 
80
/// Displaying mothers
 
81
void MCEventFormat::PrintMothers() const
 
82
{
 
83
  std::cout << "**********************************************" << std::endl;
 
84
  for (MAuint32 i=0;i<particles_.size();i++)
 
85
  {
 
86
    std::cout << "- ";
 
87
    std::cout << std::setw(6) << particles_[i].pdgid() << "]  <-  ";
 
88
    for (MAuint32 j=0;j<particles_[i].mothers().size();j++)
 
89
    {
 
90
      std::cout << std::setw(6) << particles_[i].mothers()[j]->pdgid() << "  ";
 
91
    }
 
92
    std::cout << std::endl;
 
93
  }
 
94
  std::cout << "**********************************************" << std::endl;
 
95
}
 
96
 
 
97
 
 
98
/// Displaying daughters
 
99
void MCEventFormat::PrintDaughters() const
 
100
{
 
101
  std::cout << "**********************************************" << std::endl;
 
102
  for (MAuint32 i=0;i<particles_.size();i++)
 
103
  {
 
104
    std::cout << "- ";
 
105
    std::cout << std::setw(6) << particles_[i].pdgid() << "]  <-  ";
 
106
    for (MAuint32 j=0;j<particles_[i].daughters().size();j++)
 
107
    {
 
108
      std::cout << std::setw(6) << particles_[i].daughters()[j]->pdgid() << "  ";
 
109
    }
 
110
    std::cout << std::endl;
 
111
  }
 
112
  std::cout << "**********************************************" << std::endl;
 
113
}