ATLAS Offline Software
Loading...
Searching...
No Matches
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
17 Barcode code;
19 return !best(code, weight) ? -999 : code.second;
20}
21
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
74std::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}
std::ostream & operator<<(std::ostream &o, const FPGATrackSimMultiTruth &mt)
void add(const FPGATrackSimMultiTruth::Barcode &code, const FPGATrackSimMultiTruth::Weight &weight)
FPGATrackSimMultiTruth()=default
void maximize(const FPGATrackSimMultiTruth::Barcode &code, const FPGATrackSimMultiTruth::Weight &weight)
bool best(FPGATrackSimMultiTruth::Barcode &code, FPGATrackSimMultiTruth::Weight &weight) const
std::pair< unsigned long, unsigned long > Barcode
unsigned long best_barcode() const
FPGATrackSimMultiTruth::Weight weight(const FPGATrackSimMultiTruth::Barcode &code) const
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146