ATLAS Offline Software
FPGATrackSimMultiTruth.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 #include <iostream>
5 #include <algorithm>
7 
8 
9 // FPGATrackSimMultiTruth
10 // ================================================================
11 // code to match clusters and tracks to GEANT charge deposition
12 // information
13 // ================================================================
14 // 20-04-2009 Antonio Boveia (boveia@hep.uchicago.edu)
15 
16 unsigned long FPGATrackSimMultiTruth::best_barcode() const {
17  Barcode code;
18  Weight weight;
19  return !best(code, weight) ? -999 : code.second;
20 }
21 
23  assert(weight >= 0.);
24  m_truth[code] += weight;
25 }
26 
28  for (auto& rval_truth : rval.m_truth) {
29  m_truth[rval_truth.first] += rval_truth.second;
30  }
31 }
32 
33 // if this doesn't have any truth info, assign maxweight_barcode to be the truth.
34 // otherwise, this should only have the barcode of the largest weight seen so far;
35 // compare with the input barcode and keep the best.
37 {
38  if (m_truth.empty()) m_truth[code] = weight;
39  else
40  {
41  assert(m_truth.size() == 1);
42  if (m_truth.begin()->second < weight)
43  {
44  m_truth.clear();
45  m_truth[code] = weight;
46  }
47  }
48 }
49 
51 {
52  if (rval.m_truth.empty()) return; // if rval has no truth info, do nothing.
53 
54  // find input barcode with maximum weight;
55  Weight maxweight = 0.;
56  Barcode maxweight_barcode(-1l, -1l);
57  for (const auto & rval_truth : rval.m_truth)
58  {
59  if (rval_truth.second > maxweight)
60  {
61  maxweight = rval_truth.second;
62  maxweight_barcode = rval_truth.first;
63  }
64  }
65 
66  maximize(maxweight_barcode, maxweight);
67 }
68 
70 {
71  for ( auto& truth : m_truth) truth.second = 1. / m_truth.size();
72 }
73 
74 std::ostream& operator<<(std::ostream& o, const FPGATrackSimMultiTruth& mt)
75 {
76  size_t count = std::count_if(mt.begin(), mt.end(), [](auto){return true;});
77  o << "FPGATrackSimMultiTruth (event index,barcode) <=> weight, entries: " << count << "\n";
78 
79  if (count == 0) return o;
80 
81  for ( auto& truth : mt)
82  o << " " << (truth.first).first << "," << (truth.first).second << " <=> " << truth.second << "\n";
83 
84  o << " best: \n";
85 
88 
89  if (!mt.best(code, weight)) o << "N/A\n";
90  else o << code.first << "," << code.second << " " << weight << "\n";
91  return o;
92 
93 }
94 
96 {
98  result.add(rval);
99  return result;
100 }
101 
103 {
105  result.maximize(rval);
106  return result;
107 }
Barcode
Definition: IBarcodeSvc.h:17
get_generator_info.result
result
Definition: get_generator_info.py:21
FPGATrackSimMultiTruth::m_truth
TruthMap m_truth
Definition: FPGATrackSimMultiTruth.h:122
operator<<
std::ostream & operator<<(std::ostream &o, const FPGATrackSimMultiTruth &mt)
Definition: FPGATrackSimMultiTruth.cxx:74
FPGATrackSimMultiTruth::Weight
float Weight
Definition: FPGATrackSimMultiTruth.h:50
FPGATrackSimMultiTruth::begin
auto begin()
Definition: FPGATrackSimMultiTruth.h:65
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
FPGATrackSimMultiTruth.h
FPGATrackSimMultiTruth::best_barcode
unsigned long best_barcode() const
Definition: FPGATrackSimMultiTruth.cxx:16
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
FPGATrackSimMultiTruth::best
bool best(FPGATrackSimMultiTruth::Barcode &code, FPGATrackSimMultiTruth::Weight &weight) const
Definition: FPGATrackSimMultiTruth.h:86
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
histSizes.code
code
Definition: histSizes.py:129
FPGATrackSimMultiTruth::add
void add(const FPGATrackSimMultiTruth::Barcode &code, const FPGATrackSimMultiTruth::Weight &weight)
Definition: FPGATrackSimMultiTruth.cxx:22
FPGATrackSimMultiTruth::Barcode
std::pair< unsigned long, unsigned long > Barcode
Definition: FPGATrackSimMultiTruth.h:49
FPGATrackSimMultiTruth::weight
FPGATrackSimMultiTruth::Weight weight(const FPGATrackSimMultiTruth::Barcode &code) const
Definition: FPGATrackSimMultiTruth.h:118
FPGATrackSimMultiTruth::maximize
void maximize(const FPGATrackSimMultiTruth::Barcode &code, const FPGATrackSimMultiTruth::Weight &weight)
Definition: FPGATrackSimMultiTruth.cxx:36
FPGATrackSimMultiTruth
Definition: FPGATrackSimMultiTruth.h:46
DeMoScan.first
bool first
Definition: DeMoScan.py:536
FPGATrackSimMultiTruth::end
auto end()
Definition: FPGATrackSimMultiTruth.h:66
FPGATrackSimMultiTruth::assign_equal_normalization
void assign_equal_normalization()
Definition: FPGATrackSimMultiTruth.cxx:69