Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JetContainerv1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JetContainerv1.cc
1 #include "JetContainerv1.h"
2 #include "Jetv2.h"
3 
4 #include <phool/phool.h> // for PHWHERE
5 
6 #include <string>
7 
9 {
10  m_clones = new TClonesArray("Jetv2", 50);
11 }
12 
13 void JetContainerv1::identify(std::ostream& os) const
14 {
15  os << "JetContainerv1: size = " << m_clones->GetEntriesFast() << std::endl
16  << " Contains jets with the following properties:" << std::endl;
18  return;
19 }
20 
22  : m_njets{rhs.size()}
23  , m_pindex{rhs.property_indices()}
24  , m_psize{rhs.size_properties()}
25  , m_RhoMedian{rhs.get_rho_median()}
26 {
27  m_clones = rhs.clone_data();
28 
29  for (auto src = rhs.begin_src(); src != rhs.end_src(); ++src)
30  {
31  m_src.insert(*src);
32  }
33 
34  m_jetpar_R = rhs.get_jetpar_R();
35 }
36 
38 {
40  delete m_clones;
41 }
42 
44 {
45  m_clones->Clear("C");
46  m_njets = 0;
47  m_RhoMedian = NAN;
48 }
49 
51 {
52  auto jet = (Jet*) m_clones->ConstructedAt(m_njets++, "C");
53  jet->resize_properties(m_psize);
54  return jet;
55 }
56 
57 Jet* JetContainerv1::get_jet(unsigned int ijet)
58 {
59  if (ijet < m_njets)
60  {
61  return (Jet*) m_clones->At(ijet);
62  }
63  else
64  {
65  return nullptr;
66  }
67 }
68 
70 {
71  return (Jet*) m_clones->UncheckedAt(index);
72 }
73 
74 // ----------------------------------------------------------------------------------------
75 // Interface for adding, setting, and getting jet properties
76 // ----------------------------------------------------------------------------------------
77 
78 void JetContainerv1::print_jets(std::ostream& os)
79 {
80  os << " No. of jets: " << m_njets;
81  if (!isnan(m_RhoMedian)) os << " rho median " << m_RhoMedian;
82  os << std::endl;
83 
84  int ijet = 0;
85  for (auto jet : *this)
86  {
87  os << Form(" jet(%2i) : pT(%6.2f) eta(%6.2f) phi(%6.2f)",
88  ijet, jet->get_pt(), jet->get_eta(), jet->get_phi());
89  ++ijet;
90  unsigned int i = 0;
91  for (auto prop : m_pindex)
92  {
93  os << Form(" %8s(%6.2f)", str_Jet_PROPERTY(prop.first).c_str(), jet->get_property(prop.second));
94  i++;
95  }
96  os << std::endl;
97  }
98  os << std::endl;
99 }
100 
101 void JetContainerv1::print_property_types(std::ostream& os) const
102 {
103  os << " Jet properties in Jet vectors: " << std::endl;
104  int i = 0;
105  for (auto p : m_pindex)
106  {
107  os << " (" << i++ << ") -> " << str_Jet_PROPERTY(p.first) << std::endl;
108  }
109  return;
110 }
111 
112 // Add properties to the jets.
114 {
115  auto [iter, is_new] = m_pindex.try_emplace(prop, static_cast<Jet::PROPERTY>(m_psize));
116  if (is_new)
117  {
118  ++m_psize;
120  }
121  return m_psize;
122 }
123 
124 size_t JetContainerv1::add_property(std::set<Jet::PROPERTY> props)
125 {
126  bool added = false;
127  for (auto prop : props) {
128  auto [iter, is_new] = m_pindex.try_emplace(prop, static_cast<Jet::PROPERTY>(m_psize));
129  if (is_new) {
130  ++m_psize;
131  added = true;
132  }
133  }
134  if (added) {
136  }
137  return m_psize;
138 }
139 
140 // get the index for a given property
142 {
143  if (!has_property(prop)) add_property(prop);
144  return m_pindex[prop];
145 }
146 
148 {
149  return Jet::IterJetTCA(m_clones);
150 }
151 
152 Jet::IterJetTCA JetContainerv1::end() // dummy implementation -- don't anticipate that it will ever be checked
153  {
154  auto rval = Jet::IterJetTCA(m_clones);
155  rval.index = rval.size;
156  return rval;
157 }
158 
160 {
161  for (auto jet : *this)
162  {
163  jet->resize_properties(m_psize);
164  }
165  return;
166 }
167 
169 {
170  switch (prop)
171  {
172  case Jet::PROPERTY::prop_JetCharge:
173  return "JetCharge";
174  case Jet::PROPERTY::prop_BFrac:
175  return "BFrac";
176  case Jet::PROPERTY::prop_SeedD:
177  return "SeedD";
178  case Jet::PROPERTY::prop_SeedItr:
179  return "SeedItr";
180  case Jet::PROPERTY::prop_zg:
181  return "zg";
182  case Jet::PROPERTY::prop_Rg:
183  return "Rg";
184  case Jet::PROPERTY::prop_mu:
185  return "mu";
186  case Jet::PROPERTY::prop_gamma:
187  return "gamma";
189  return "JetHadronFlavor";
191  return "JetHadronZT";
192  case Jet::PROPERTY::prop_area:
193  return "area";
194  default:
195  return "no_property";
196  }
197  return "";
198 }