ATLAS Offline Software
Loading...
Searching...
No Matches
ClusterSplitProbabilityContainer.h
Go to the documentation of this file.
1/* Dear emacs, this is -*-c++-*- */
2#ifndef _ClusterSplitProbabilityContainer_H_
3#define _ClusterSplitProbabilityContainer_H_
4
5#include "Identifier/Identifier.h"
7#include <unordered_map>
8#include <algorithm>
9#include <stdexcept>
10
11namespace Trk {
13
17 {
19 public:
20 using ClusterIdentifier=unsigned int;
21
22 struct ProbabilityInfo : public std::pair<float,float> {
23 ProbabilityInfo(float prob1, float prob2) : std::pair<float,float>(prob1,prob2) {}
24 float splitProbability1() const { return isTooBigToBeSplit() ? 0.f : this->first; }
25 float splitProbability2() const { return isTooBigToBeSplit() ? 0.f : this->second; }
26 bool isTooBigToBeSplit() const { return first<0; }
27 bool isSplit() const { return m_isSplit;}
29 void updateSplitProbabilities(float prob1, float prob2) { this->first=prob1; this->second=prob2; m_isSplit=false;}
30 private:
31 bool m_isSplit = false;
32 };
34
35 const ProbabilityInfo &splitProbability(const PrepRawData*cluster) const {
36 assert(cluster);
37 std::unordered_map<ClusterIdentifier, ProbabilityInfo>::const_iterator iter = m_splitProbMap.find(cluster->getHashAndIndex().hashAndIndex());
38 return (iter != m_splitProbMap.end()) ? iter->second : s_unset;
39 }
41 assert(cluster);
42 std::unordered_map<ClusterIdentifier, ProbabilityInfo>::iterator iter = m_splitProbMap.find(cluster->getHashAndIndex().hashAndIndex());
43 return (iter != m_splitProbMap.end()) ? &iter->second : nullptr;
44 }
45 ProbabilityInfo &setSplitInformation(const PrepRawData*cluster, float prob1, float prob2) {
46 assert(cluster);
47 // @TODO remove the precision clipping, which is currently implemented here to produce identical results wrt. the current version.
48 constexpr int splitmask = 0x7fff;
49 prob1 = int(prob1 * splitmask)/(1.*splitmask);
50 prob2 = int(prob2 * splitmask)/(1.*splitmask);
51 std::pair<std::unordered_map<ClusterIdentifier, ProbabilityInfo>::iterator,bool>
52 ret = m_splitProbMap.insert( std::make_pair( cluster->getHashAndIndex().hashAndIndex(), ProbabilityInfo(prob1, prob2) ) );
53 if (!ret.second) {
54 std::unordered_map<ClusterIdentifier, ProbabilityInfo>::iterator iter = m_splitProbMap.find(cluster->getHashAndIndex().hashAndIndex());
55 if (iter == m_splitProbMap.end()) {
56 throw std::runtime_error("Failed to set cluster splitting probability.");
57 }
58 iter->second.updateSplitProbabilities(prob1,prob2);
59 return iter->second;
60 }
61 else {
62 return ret.first->second;
63 }
64 }
65 void setTooBigToBeSplit(const PrepRawData*cluster) {
66 assert(cluster);
67 m_splitProbMap.insert( std::make_pair( cluster->getHashAndIndex().hashAndIndex(), ProbabilityInfo(-1.,-1.) ) );
68 }
69
70 const std::unordered_map<ClusterIdentifier, ProbabilityInfo>&
72 {
73 return m_splitProbMap;
74 }
75
76 protected:
77 std::unordered_map<ClusterIdentifier, ProbabilityInfo> m_splitProbMap;
79 };
80}
81#ifndef CLIDSVC_CLASSDEF_H
84#endif
85#endif
macros to associate a CLID to a type
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
unsigned int hashAndIndex() const
combined index
Container to associate Cluster with cluster splitting probabilities.
static const ProbabilityInfo & getNoSplitProbability()
ProbabilityInfo & setSplitInformation(const PrepRawData *cluster, float prob1, float prob2)
const ProbabilityInfo & splitProbability(const PrepRawData *cluster) const
const std::unordered_map< ClusterIdentifier, ProbabilityInfo > & splitProbMap() const
std::unordered_map< ClusterIdentifier, ProbabilityInfo > m_splitProbMap
ProbabilityInfo * getSplitProbability(const PrepRawData *cluster)
const IdentContIndex & getHashAndIndex() const
STL class.
Ensure that the ATLAS eigen extensions are properly loaded.
STL namespace.