LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MCShowerRecoPart.cxx
Go to the documentation of this file.
1 //
3 // MCShowerRecoPart source
4 //
6 
8 
9 #include "MCShowerRecoPart.h"
11 
12 #include "TString.h"
13 
14 #include <iostream>
15 #include <limits>
16 
17 namespace sim {
18 
19  const unsigned int MCShowerRecoPart::kINVALID_UINT = std::numeric_limits<unsigned int>::max();
20  const int MCShowerRecoPart::kINVALID_INT = std::numeric_limits<int>::max();
21 
22  //##################################################################
24  //##################################################################
25  {
26  _debug_mode = pset.get<bool>("DebugMode");
27  }
28 
29  //-----------------------------------------------------------------------------------------------
31  //-----------------------------------------------------------------------------------------------
32  {
33  _shower_id.clear();
34  _shower_id.resize(part_v.size(), -1);
35  _shower_index.clear();
36  _shower_daughters.clear();
37 
38  if (!part_v.size()) return;
39 
40  // Construct MCShower
41  std::vector<std::multimap<double, unsigned int>> daughter_map;
42  for (size_t i = 0; i < part_v.size(); ++i) {
43 
44  auto const& mcp = part_v[i];
45 
46  int candidate_mom_index = -1;
47  if (mcp._pdgcode == 22 || mcp._pdgcode == 11 || mcp._pdgcode == -11) candidate_mom_index = i;
48 
49  unsigned int mom_track = mcp._mother;
50  auto mom_iter = part_v._track_index.find(mom_track);
51  while (mom_iter != part_v._track_index.end()) {
52 
53  unsigned int mom_index = (*mom_iter).second;
54 
55  if (part_v.at(mom_index)._pdgcode == 22 || part_v.at(mom_index)._pdgcode == 11 ||
56  part_v.at(mom_index)._pdgcode == -11)
57 
58  candidate_mom_index = mom_index;
59 
60  mom_iter = part_v._track_index.find(part_v.at(mom_index)._mother);
61  }
62 
63  if (candidate_mom_index >= 0) {
64 
65  auto candidate_mom_iter = _shower_index.find(candidate_mom_index);
66  if (candidate_mom_iter == _shower_index.end()) {
67  _shower_index.insert(
68  std::make_pair((unsigned int)candidate_mom_index, (unsigned int)_shower_index.size()));
69  daughter_map.push_back(std::multimap<double, unsigned int>());
70  }
71  unsigned int shower_index = (*_shower_index.find(candidate_mom_index)).second;
72  daughter_map.at(shower_index)
73  .insert(std::make_pair((double)(mcp._start_vtx[3]), (unsigned int)i));
74  _shower_id.at(i) = shower_index;
75  }
76  else if (_debug_mode) {
77 
78  std::cout << "Found a particle that does not belong to a shower!" << std::endl
79  << Form(" PDGID: %d ... Track %d @ (%g,%g,%g,%g) with (%g,%g,%g,%g)",
80  mcp._pdgcode,
81  mcp._track_id,
82  mcp._start_vtx[0],
83  mcp._start_vtx[1],
84  mcp._start_vtx[2],
85  mcp._start_vtx[3],
86  mcp._start_mom[0],
87  mcp._start_mom[1],
88  mcp._start_mom[2],
89  mcp._start_mom[3])
90  << std::endl
91  << std::endl;
92  }
93  }
94 
95  if (_debug_mode)
96  std::cout << Form("Found %zu MCShowers....", _shower_index.size()) << std::endl;
97 
98  _shower_daughters.resize(_shower_index.size(), std::vector<unsigned int>());
99  for (auto const& mom : _shower_index) {
100 
101  _shower_daughters.at(mom.second).reserve(daughter_map.at(mom.second).size());
102  for (auto const& part_index : daughter_map.at(mom.second))
103 
104  _shower_daughters.at(mom.second).push_back(part_index.second);
105 
106  auto const& mcp = part_v.at(mom.first);
107  if (_debug_mode)
108  std::cout
109  << Form("PDGID: %d ... Track %d @ (%g,%g,%g,%g) with (%g,%g,%g,%g) ... %zu daughters!",
110  mcp._pdgcode,
111  mcp._track_id,
112  mcp._start_vtx[0],
113  mcp._start_vtx[1],
114  mcp._start_vtx[2],
115  mcp._start_vtx[3],
116  mcp._start_mom[0],
117  mcp._start_mom[1],
118  mcp._start_mom[2],
119  mcp._start_mom[3],
120  _shower_daughters.at(mom.second).size())
121  << std::endl;
122  }
123 
124  if (_debug_mode) std::cout << std::endl;
125  }
126 
127 }
std::vector< int > _shower_id
Track index to shower index map.
std::map< unsigned int, unsigned int > _track_index
Track ID => Index Map.
Definition: MCRecoPart.h:123
std::vector< std::vector< unsigned int > > _shower_daughters
Shower time-ordered daughters.
MCShowerRecoPart(fhicl::ParameterSet const &pset)
Default constructor with fhicl parameters.
T get(std::string const &key) const
Definition: ParameterSet.h:314
static const int kINVALID_INT
bool _debug_mode
lots of stdout stream
Monte Carlo Simulation.
std::map< unsigned int, unsigned int > _shower_index
Shower Primary Index ID => Shower Index Map.
static const unsigned int kINVALID_UINT
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
void ConstructShower(const MCRecoPart &part_v)
Main function to read-in data and fill variables in this algorithm to reconstruct MC shower...