BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnMatch.cxx
Go to the documentation of this file.
1/**
2 * \file BmnMatch.cxx
3 * \author Andrey Lebedev <andrey.lebedev@gsi.de> - original author for CBM experiment
4 * \author Sergey Merts <sergey.merts@gmail.com> - modifications for BMN experiment
5 * \date 2013-2014
6 **/
7
8#include "BmnMatch.h"
9
10#include <sstream>
11
12using std::make_pair;
13using std::stringstream;
14
16 : fLinks()
17 , fTotalWeight(0.)
18 , fMatchedIndex(-1)
19{}
20
22{
23 fLinks.clear();
24}
25
26string BmnMatch::ToString() const
27{
28 stringstream ss;
29 ss << "BmnMatch: ";
30 Int_t nofLinks = GetNofLinks();
31 ss << "nofLinks=" << nofLinks << "\n";
32 for (Int_t i = 0; i < nofLinks; i++) {
33 const BmnLink& link = fLinks[i];
34 ss << link.ToString();
35 }
36 ss << " totalWeight=" << fTotalWeight << ", matchedIndex=" << fMatchedIndex << std::endl;
37 return ss.str();
38}
39
41{
42 Int_t nofLinks = match.GetNofLinks();
43 for (Int_t i = 0; i < nofLinks; i++) {
44 AddLink(match.GetLink(i));
45 }
46}
47
48void BmnMatch::AddLink(const BmnLink& newLink)
49{
50 Int_t addedIndex = -1;
51 Int_t nofLinks = GetNofLinks();
52 for (Int_t i = 0; i < nofLinks; i++) {
53 BmnLink& link = fLinks[i];
54 if (link == newLink) {
55 link.AddWeight(newLink.GetWeight());
56 addedIndex = i;
57 break;
58 }
59 }
60 if (addedIndex < 0) {
61 fLinks.push_back(newLink);
62 addedIndex = fLinks.size() - 1;
63 }
64
65 fTotalWeight += newLink.GetWeight();
66 if (fMatchedIndex < 0) {
67 fMatchedIndex = addedIndex;
68 } else {
69 if (fLinks[addedIndex].GetWeight() > fLinks[fMatchedIndex].GetWeight()) {
70 fMatchedIndex = addedIndex;
71 }
72 }
73}
74
75void BmnMatch::AddLink(Double_t weight, Int_t index, Int_t entry, Int_t file)
76{
77 BmnLink link(weight, index, entry, file);
78 AddLink(link);
79}
80
82{
83 fLinks.clear();
84 fTotalWeight = 0.;
85 fMatchedIndex = -1;
86}
int i
Definition P4_F32vec4.h:22
int Int_t
double Double_t
Double_t fTotalWeight
Definition BmnMatch.h:60
vector< BmnLink > fLinks
Definition BmnMatch.h:59
Int_t fMatchedIndex
Definition BmnMatch.h:61
void AddLink(const BmnMatch &match)
Definition BmnMatch.cxx:40
void ClearLinks()
Definition BmnMatch.cxx:81
virtual ~BmnMatch()
Destructor.
Definition BmnMatch.cxx:21
BmnMatch()
Default constructor.
Definition BmnMatch.cxx:15
virtual string ToString() const
Return string representation of the object.
Definition BmnMatch.cxx:26
Int_t GetNofLinks() const
Definition BmnMatch.h:41