Belle II Software  release-08-01-10
BelleMdstToGenHepevt.cc
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 // ****************************************************************
10 // Belle MDST objects -> MC Particle relations
11 //
12 // Original file: ${BELLE_TOP_DIR}/src/anal/mdst/src/mdst.cc
13 //
14 // ****************************************************************
15 
16 #include <b2bii/utility/BelleMdstToGenHepevt.h>
17 
18 // trace back to isthep>=0 or isthep=-10(decay-in-flight)
19 static const Belle::Gen_hepevt& gen_level_step1(const Belle::Gen_hepevt& gen)
20 {
21  return (gen && gen.mother() && gen.isthep() < 0 && gen.isthep() != -10)
22  ? gen_level_step1(gen.mother()) : gen;
23 }
24 
25 // trace back to isthep>0 level
26 static const Belle::Gen_hepevt& gen_level_step2(const Belle::Gen_hepevt& gen)
27 {
28  return (gen && gen.mother() && gen.isthep() < 0)
29  ? gen_level_step2(gen.mother()) : gen;
30 }
31 
32 const Belle::Gen_hepevt& gen_level(const Belle::Gen_hepevt& gen)
33 {
34  const Belle::Gen_hepevt& level1(gen_level_step1(gen));
35  if (!level1 || level1.isthep() >= 0) {
36  return level1;
37  } else if (level1.isthep() == -10) {
38  const Belle::Gen_hepevt& level2(gen_level_step2(gen));
39  // If "gen" is made by Ks(which is made by generator) daughter, returns daughter
40  if (level2.idhep() == 310 || abs(level2.idhep()) == 3122) return level1;
41  // Otherwize, trace back to generator level
42  else return level2;
43  }
44  return level1;
45 }
46 
47 const Belle::Gen_hepevt& get_hepevt(const Belle::Mdst_trk& trk, int i)
48 {
49  Belle::Mdst_sim_trk_Manager& xrefmgr = Belle::Mdst_sim_trk_Manager::get_manager();
50  Belle::Mdst_sim_trk_Index index(xrefmgr.index("trk"));
51  index.update();
52  Belle::Panther_ID trackID(trk.get_ID());
53  std::vector<Belle::Mdst_sim_trk> point = point_from(trackID, index);
54  if (i >= 0 && i < (int)point.size()) return point[i].hepevt();
55  else return Belle::Gen_hepevt_Manager::get_manager().get_NULL();
56 }
57 
58 const Belle::Gen_hepevt& get_hepevt(const Belle::Mdst_charged& ch, int i)
59 {
60  if (!Belle::Mdst_sim_trk_Manager::get_manager().count()) {
61  // for backward compatibility
62  Belle::Mdst_sim_xref_Manager& xrefmgr = Belle::Mdst_sim_xref_Manager::get_manager();
63  Belle::Mdst_sim_xref_Index index(xrefmgr.index("charged"));
64  index.update();
65  Belle::Panther_ID trackID(ch.get_ID());
66  std::vector<Belle::Mdst_sim_xref> point = point_from(trackID, index);
67  if (i >= 0 && i < (int)point.size()) return point[i].hepevt();
68  else return Belle::Gen_hepevt_Manager::get_manager().get_NULL();
69  }
70  return get_hepevt(ch.trk(), i);
71 }
72 
73 const Belle::Gen_hepevt& get_hepevt(const Belle::Mdst_ecl& ecl, int i)
74 {
75  Belle::Mdst_sim_ecl_Manager& xrefmgr = Belle::Mdst_sim_ecl_Manager::get_manager();
76  Belle::Mdst_sim_ecl_Index index(xrefmgr.index("ecl"));
77  index.update();
78  Belle::Panther_ID eclID(ecl.get_ID());
79  std::vector<Belle::Mdst_sim_ecl> point = point_from(eclID, index);
80  if (i >= 0 && i < (int)point.size()) return point[i].hepevt();
81  else return Belle::Gen_hepevt_Manager::get_manager().get_NULL();
82 }
83 
84 const Belle::Gen_hepevt& get_hepevt(const Belle::Mdst_gamma& gamma, int i)
85 {
86  if (!Belle::Mdst_sim_ecl_Manager::get_manager().count()) {
87  // do NOT support backward compatibility
88  // because the returned "Belle::Gen_hepevt & " may not be correct
89  return Belle::Gen_hepevt_Manager::get_manager().get_NULL();
90  }
91  return get_hepevt(gamma.ecl(), i);
92 }
93