CbmRoot
CbmMatch.cxx
Go to the documentation of this file.
1 
6 #include "CbmMatch.h"
7 
8 #include <sstream> // for operator<<, basic_ostream, stringstream
9 #include <string> // for char_traits
10 #include <utility> // for make_pair
11 
12 using std::make_pair;
13 using std::string;
14 using std::stringstream;
15 using std::vector;
16 
17 CbmMatch::CbmMatch() : fLinks(), fTotalWeight(0.), fMatchedIndex(-1) {}
18 
20 
21 string CbmMatch::ToString() const {
22  stringstream ss;
23  ss << "CbmMatch: ";
24  Int_t nofLinks = GetNofLinks();
25  ss << "nofLinks=" << nofLinks << "\n";
26  for (Int_t i = 0; i < nofLinks; i++) {
27  const CbmLink& link = fLinks[i];
28  ss << link.ToString();
29  }
30  ss << " totalWeight=" << fTotalWeight << ", matchedIndex=" << fMatchedIndex
31  << std::endl;
32  return ss.str();
33 }
34 
35 void CbmMatch::AddLinks(const CbmMatch& match) {
36  Int_t nofLinks = match.GetNofLinks();
37  for (Int_t i = 0; i < nofLinks; i++) {
38  AddLink(match.GetLink(i));
39  }
40 }
41 
42 void CbmMatch::AddLink(const CbmLink& newLink) {
43  Int_t addedIndex = -1;
44  Int_t nofLinks = GetNofLinks();
45  for (Int_t i = 0; i < nofLinks; i++) {
46  CbmLink& link = fLinks[i];
47  if (link == newLink) {
48  link.AddWeight(newLink.GetWeight());
49  addedIndex = i;
50  break;
51  }
52  }
53  if (addedIndex < 0) {
54  fLinks.push_back(newLink);
55  addedIndex = fLinks.size() - 1;
56  }
57 
58  fTotalWeight += newLink.GetWeight();
59  if (fMatchedIndex < 0) {
60  fMatchedIndex = addedIndex;
61  } else {
62  if (fLinks[addedIndex].GetWeight() > fLinks[fMatchedIndex].GetWeight()) {
63  fMatchedIndex = addedIndex;
64  }
65  }
66 }
67 
68 void CbmMatch::AddLink(Double_t weight, Int_t index, Int_t entry, Int_t file) {
69  CbmLink link(weight, index, entry, file);
70  AddLink(link);
71 }
72 
73 
75  fLinks.clear();
76  fTotalWeight = 0.;
77  fMatchedIndex = -1;
78 }
79 
CbmMatch
Definition: CbmMatch.h:22
CbmMatch::~CbmMatch
virtual ~CbmMatch()
Destructor.
Definition: CbmMatch.cxx:19
CbmMatch::GetLink
const CbmLink & GetLink(Int_t i) const
Definition: CbmMatch.h:35
CbmMatch::GetNofLinks
Int_t GetNofLinks() const
Definition: CbmMatch.h:38
CbmMatch::fTotalWeight
Double_t fTotalWeight
Definition: CbmMatch.h:55
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmMatch.h
CbmMatch::fMatchedIndex
Int_t fMatchedIndex
Definition: CbmMatch.h:56
CbmMatch::AddLink
void AddLink(const CbmLink &newLink)
Definition: CbmMatch.cxx:42
ClassImp
ClassImp(CbmMatch)
CbmMatch::AddLinks
void AddLinks(const CbmMatch &match)
Definition: CbmMatch.cxx:35
CbmMatch::CbmMatch
CbmMatch()
Default constructor.
Definition: CbmMatch.cxx:17
CbmMatch::ClearLinks
void ClearLinks()
Definition: CbmMatch.cxx:74
CbmMatch::fLinks
std::vector< CbmLink > fLinks
Definition: CbmMatch.h:54
CbmMatch::ToString
virtual std::string ToString() const
Return string representation of the object.
Definition: CbmMatch.cxx:21