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 
9 
10 // FPGATrackSimMultiTruth
11 // ================================================================
12 // code to match clusters and tracks to GEANT charge deposition
13 // information
14 // ================================================================
15 // 20-04-2009 Antonio Boveia (boveia@hep.uchicago.edu)
16 
17 unsigned long FPGATrackSimMultiTruth::best_barcode() const {
18  Barcode code;
19  Weight weight;
20  return !best(code, weight) ? -999 : code.second;
21 }
22 
24  assert(weight >= 0.);
25  m_truth[code] += weight;
26 }
27 
29  for (auto& rval_truth : rval.m_truth) {
30  m_truth[rval_truth.first] += rval_truth.second;
31  }
32 }
33 
34 // if this doesn't have any truth info, assign maxweight_barcode to be the truth.
35 // otherwise, this should only have the barcode of the largest weight seen so far;
36 // compare with the input barcode and keep the best.
38 {
39  if (m_truth.empty()) m_truth[code] = weight;
40  else
41  {
42  assert(m_truth.size() == 1);
43  if (m_truth.begin()->second < weight)
44  {
45  m_truth.clear();
46  m_truth[code] = weight;
47  }
48  }
49 }
50 
52 {
53  if (rval.m_truth.empty()) return; // if rval has no truth info, do nothing.
54 
55  // find input barcode with maximum weight;
56  Weight maxweight = 0.;
57  Barcode maxweight_barcode(-1l, -1l);
58  for (const auto & rval_truth : rval.m_truth)
59  {
60  if (rval_truth.second > maxweight)
61  {
62  maxweight = rval_truth.second;
63  maxweight_barcode = rval_truth.first;
64  }
65  }
66 
67  maximize(maxweight_barcode, maxweight);
68 }
69 
71 {
72  for ( auto& truth : m_truth) truth.second = 1. / m_truth.size();
73 }
74 
75 std::ostream& operator<<(std::ostream& o, const FPGATrackSimMultiTruth& mt)
76 {
77  size_t count = std::count_if(mt.begin(), mt.end(), [](auto){return true;});
78  o << "FPGATrackSimMultiTruth (event index,barcode) <=> weight, entries: " << count << "\n";
79 
80  if (count == 0) return o;
81 
82  for ( auto& truth : mt)
83  o << " " << (truth.first).first << "," << (truth.first).second << " <=> " << truth.second << "\n";
84 
85  o << " best: \n";
86 
89 
90  if (!mt.best(code, weight)) o << "N/A\n";
91  else o << code.first << "," << code.second << " " << weight << "\n";
92  return o;
93 
94 }
95 
97 {
99  result.add(rval);
100  return result;
101 }
102 
104 {
106  result.maximize(rval);
107  return result;
108 }
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:75
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
ClassImp
ClassImp(FPGATrackSimMultiTruth) unsigned long FPGATrackSimMultiTruth
Definition: FPGATrackSimMultiTruth.cxx:8
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:200
FPGATrackSimMultiTruth::add
void add(const FPGATrackSimMultiTruth::Barcode &code, const FPGATrackSimMultiTruth::Weight &weight)
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
pmontree.code
code
Definition: pmontree.py:443
FPGATrackSimMultiTruth::maximize
void maximize(const FPGATrackSimMultiTruth::Barcode &code, const FPGATrackSimMultiTruth::Weight &weight)
Definition: FPGATrackSimMultiTruth.cxx:37
FPGATrackSimMultiTruth
Definition: FPGATrackSimMultiTruth.h:46
DeMoScan.first
bool first
Definition: DeMoScan.py:534
FPGATrackSimMultiTruth::end
auto end()
Definition: FPGATrackSimMultiTruth.h:66
FPGATrackSimMultiTruth::assign_equal_normalization
void assign_equal_normalization()
Definition: FPGATrackSimMultiTruth.cxx:70