CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CandidateGroup.cc
Go to the documentation of this file.
2 
3 #include <iostream>
4 #include <memory>
5 
6 using namespace dtbayesam;
7 
8 //------------------------------------------------------------------
9 //--- Constructores y destructores
10 //------------------------------------------------------------------
12  nhits_ = 0;
13  nLayerhits_ = 0;
14  nisGood_ = 0;
15  nLayerDown_ = 0;
16  nLayerUp_ = 0;
17  pattern_ = p;
18 }
19 
21 
23 
24 void CandidateGroup::addHit(DTPrimitive dthit, int lay, bool isGood) {
25  //Add a hit, check if the hits layer was fired and if it wasn't add it to the fired layers
26  candHits_.push_back(std::make_shared<DTPrimitive>(dthit));
27  if (quality_ != (quality_ | qualitybits(std::pow(2, lay))))
28  nLayerhits_++;
29  if (isGood)
30  nisGood_++;
32  nhits_++;
33  if (lay <= 3)
34  nLayerDown_++;
35  if (lay >= 4)
36  nLayerUp_++;
37 }
38 
40  //Add a hit, check if the hits layer was fired and if it wasn't add it to the fired layers
41  DTPrimitivePtrs tempHits;
42  nhits_ = 0;
43  nLayerDown_ = 0;
44  nLayerUp_ = 0;
45  nLayerhits_ = 0;
46  nisGood_ = 0;
47  quality_ = qualitybits("00000000");
48  for (auto dt_it = candHits_.begin(); dt_it != candHits_.end(); dt_it++) {
49  if (dthit.layerId() == (*dt_it)->layerId() && dthit.channelId() == (*dt_it)->channelId()) {
50  } else {
51  if (pattern_->latHitIn((*dt_it)->layerId(), (*dt_it)->channelId(), 0) > -5)
52  nisGood_++;
53  if (quality_ != (quality_ | qualitybits(std::pow(2, (*dt_it)->layerId()))))
54  nLayerhits_++;
55  quality_ = quality_ | qualitybits(std::pow(2, (*dt_it)->layerId()));
56  nhits_++;
57  if ((*dt_it)->layerId() <= 3)
58  nLayerDown_++;
59  else if ((*dt_it)->layerId() >= 4)
60  nLayerUp_++;
61  tempHits.push_back(*dt_it);
62  }
63  }
64  candHits_ = tempHits;
65 }
66 
67 bool CandidateGroup::operator>(const CandidateGroup& cOther) const {
68  //First number of good (in pattern) matched hits
69  if (nisGood_ > cOther.nisGood())
70  return true;
71  else if (nisGood_ < cOther.nisGood())
72  return false;
73  //Tehn quality_ is number of layers fired
74  else if (nLayerhits_ > cOther.nLayerhits())
75  return true;
76  else if (nLayerhits_ < cOther.nLayerhits())
77  return false;
78  //Then number of matched hits (if multiple hits in a layer is better)
79  else if (nhits_ > cOther.nhits())
80  return true;
81  else if (nhits_ < cOther.nhits())
82  return false;
83  //Balanced quality_, prefer 3+2 over 4+1 for example
84  else if ((nLayerUp_ - nLayerDown_) > (cOther.nLayerUp() - cOther.nLayerDown()))
85  return true;
86  else if ((nLayerUp_ - nLayerDown_) < (cOther.nLayerUp() - cOther.nLayerDown()))
87  return false;
88  //Last, patterns with less gen hits are better matched
89  else if (pattern_->genHits().size() < (cOther.pattern()->genHits().size()))
90  return true;
91  else if (pattern_->genHits().size() > (cOther.pattern()->genHits().size()))
92  return false;
93  //For a total order relation we need this additional dummy
94  else if (candId_ < cOther.candId())
95  return true;
96  else if (candId_ > cOther.candId())
97  return false;
98 
99  //If we are here, they are basically equal so it doesn't matter who goes first
100  return true;
101 }
102 
103 bool CandidateGroup::operator==(const CandidateGroup& cOther) const {
104  //First number of good hits
105  if (nisGood_ != cOther.nisGood())
106  return false;
107  //First quality_ is number of layers fired
108  else if (nLayerhits_ != cOther.nLayerhits())
109  return false;
110  //Then number of matched hits (if multiple hits in a layer is better)
111  else if (nhits_ != cOther.nhits())
112  return false;
113  //Balanced quality_, prefer 3+2 over 4+1 for example
114  else if ((nLayerUp_ - nLayerDown_) != (cOther.nLayerUp() - cOther.nLayerDown()))
115  return false;
116  //Last, patterns with less gen hits are better matched
117  return true;
118 }
std::vector< DTPrimitivePtr > DTPrimitivePtrs
Definition: DTprimitive.h:55
void removeHit(DTPrimitive dthit)
const int channelId() const
Definition: DTprimitive.h:34
std::bitset< 8 > qualitybits
DTPrimitivePtrs candHits_
const DTPatternPtr pattern() const
std::shared_ptr< DTPattern > DTPatternPtr
void addHit(DTPrimitive dthit, int lay, bool isGood)
bool operator==(const CandidateGroup &cOther) const
const int layerId() const
Definition: DTprimitive.h:35
bool operator>(const CandidateGroup &cOther) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29