Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:11:13

0001 #include "L1Trigger/DTTriggerPhase2/interface/CandidateGroup.h"
0002 
0003 #include <iostream>
0004 #include <memory>
0005 
0006 using namespace dtbayesam;
0007 
0008 //------------------------------------------------------------------
0009 //--- Constructors and destructor
0010 //------------------------------------------------------------------
0011 CandidateGroup::CandidateGroup(DTPatternPtr p) {
0012   nhits_ = 0;
0013   nLayerhits_ = 0;
0014   nisGood_ = 0;
0015   nLayerDown_ = 0;
0016   nLayerUp_ = 0;
0017   pattern_ = p;
0018 }
0019 
0020 CandidateGroup::CandidateGroup() {}
0021 
0022 CandidateGroup::~CandidateGroup() {}
0023 
0024 void CandidateGroup::addHit(DTPrimitive dthit, int lay, bool isGood) {
0025   //Add a hit, check if the hits layer was fired and if it wasn't add it to the fired layers
0026   candHits_.push_back(std::make_shared<DTPrimitive>(dthit));
0027   if (quality_ != (quality_ | qualitybits(std::pow(2, lay))))
0028     nLayerhits_++;
0029   if (isGood)
0030     nisGood_++;
0031   quality_ = quality_ | qualitybits(std::pow(2, lay));
0032   nhits_++;
0033   if (lay <= 3)
0034     nLayerDown_++;
0035   if (lay >= 4)
0036     nLayerUp_++;
0037 }
0038 
0039 void CandidateGroup::removeHit(DTPrimitive dthit) {
0040   //Add a hit, check if the hits layer was fired and if it wasn't add it to the fired layers
0041   DTPrimitivePtrs tempHits;
0042   nhits_ = 0;
0043   nLayerDown_ = 0;
0044   nLayerUp_ = 0;
0045   nLayerhits_ = 0;
0046   nisGood_ = 0;
0047   quality_ = qualitybits("00000000");
0048   for (auto dt_it = candHits_.begin(); dt_it != candHits_.end(); dt_it++) {
0049     if (dthit.layerId() == (*dt_it)->layerId() && dthit.channelId() == (*dt_it)->channelId()) {
0050     } else {
0051       if (pattern_->latHitIn((*dt_it)->layerId(), (*dt_it)->channelId(), 0) > -5)
0052         nisGood_++;
0053       if (quality_ != (quality_ | qualitybits(std::pow(2, (*dt_it)->layerId()))))
0054         nLayerhits_++;
0055       quality_ = quality_ | qualitybits(std::pow(2, (*dt_it)->layerId()));
0056       nhits_++;
0057       if ((*dt_it)->layerId() <= 3)
0058         nLayerDown_++;
0059       else if ((*dt_it)->layerId() >= 4)
0060         nLayerUp_++;
0061       tempHits.push_back(*dt_it);
0062     }
0063   }
0064   candHits_ = tempHits;
0065 }
0066 
0067 bool CandidateGroup::operator>(const CandidateGroup& cOther) const {
0068   //First number of good (in pattern) matched hits
0069   if (nisGood_ > cOther.nisGood())
0070     return true;
0071   else if (nisGood_ < cOther.nisGood())
0072     return false;
0073   //Tehn quality_ is number of layers fired
0074   else if (nLayerhits_ > cOther.nLayerhits())
0075     return true;
0076   else if (nLayerhits_ < cOther.nLayerhits())
0077     return false;
0078   //Then number of matched hits (if multiple hits in a layer is better)
0079   else if (nhits_ > cOther.nhits())
0080     return true;
0081   else if (nhits_ < cOther.nhits())
0082     return false;
0083   //Balanced quality_, prefer 3+2 over 4+1 for example
0084   else if ((nLayerUp_ - nLayerDown_) > (cOther.nLayerUp() - cOther.nLayerDown()))
0085     return true;
0086   else if ((nLayerUp_ - nLayerDown_) < (cOther.nLayerUp() - cOther.nLayerDown()))
0087     return false;
0088   //Last, patterns with less gen hits are better matched
0089   else if (pattern_->genHits().size() < (cOther.pattern()->genHits().size()))
0090     return true;
0091   else if (pattern_->genHits().size() > (cOther.pattern()->genHits().size()))
0092     return false;
0093   //For a total order relation we need this additional dummy
0094   else if (candId_ < cOther.candId())
0095     return true;
0096   else if (candId_ > cOther.candId())
0097     return false;
0098 
0099   //If we are here, they are basically equal so it doesn't matter who goes first
0100   return true;
0101 }
0102 
0103 bool CandidateGroup::operator==(const CandidateGroup& cOther) const {
0104   //First number of good hits
0105   if (nisGood_ != cOther.nisGood())
0106     return false;
0107   //First quality_ is number of layers fired
0108   else if (nLayerhits_ != cOther.nLayerhits())
0109     return false;
0110   //Then number of matched hits (if multiple hits in a layer is better)
0111   else if (nhits_ != cOther.nhits())
0112     return false;
0113   //Balanced quality_, prefer 3+2 over 4+1 for example
0114   else if ((nLayerUp_ - nLayerDown_) != (cOther.nLayerUp() - cOther.nLayerDown()))
0115     return false;
0116   //Last, patterns with less gen hits are better matched
0117   return true;
0118 }