Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:36

0001 /*******************************************************************************
0002 *                                                                              *
0003 *  Karol Bunkowski                                                             *
0004 *  Warsaw University 2002                                                      *
0005 *                                                                              *
0006 *******************************************************************************/
0007 #include "L1Trigger/RPCTrigger/interface/RPCLogCone.h"
0008 #include "L1Trigger/RPCTrigger/interface/RPCException.h"
0009 
0010 #include <iostream>
0011 #include <iomanip>
0012 #include <sstream>
0013 
0014 /**
0015  *
0016  * Default constructor. No hits, no muon.
0017  *
0018 */
0019 RPCLogCone::RPCLogCone() : m_ConeCrdnts() {
0020   m_LogPlanesVec.assign(RPCConst::m_LOGPLANES_COUNT, TLogPlane());
0021   m_MuonCode = 0;
0022   m_MuonSign = 0;
0023 }
0024 /**
0025  *
0026  * Constructor. Cone coordinates are set.
0027  *
0028 */
0029 
0030 RPCLogCone::RPCLogCone(int tower, int logSector, int logSegment) : m_ConeCrdnts(tower, logSector, logSegment) {
0031   m_LogPlanesVec.assign(RPCConst::m_LOGPLANES_COUNT, TLogPlane());
0032   m_MuonCode = 0;
0033   m_MuonSign = 0;
0034 }
0035 /**
0036  *
0037  * Copying Constructor
0038  *
0039 */
0040 RPCLogCone::RPCLogCone(const RPCLogHit &logHit) {
0041   m_LogPlanesVec.assign(RPCConst::m_LOGPLANES_COUNT, TLogPlane());
0042 
0043   m_ConeCrdnts = logHit.getConeCrdnts();
0044 
0045   m_MuonCode = 0;
0046   m_MuonSign = 0;
0047 
0048   setLogStrip(logHit.getlogPlaneNumber() - 1, logHit.getStripNumberInCone(), logHit.getDigiIdx());
0049 }
0050 
0051 RPCLogCone::RPCLogCone(const unsigned long long &pat, int tower, int logSector, int logSegment)
0052     : m_ConeCrdnts(tower, logSector, logSegment) {
0053   m_LogPlanesVec.assign(RPCConst::m_LOGPLANES_COUNT, TLogPlane());
0054   m_MuonCode = 0;
0055   m_MuonSign = 0;
0056 
0057   unsigned long long int mask = 255;  // (first 8 bits)
0058   int shift = 0;
0059 
0060   //std::cout << "Decompressing pattern: " << pat << std::endl;
0061   for (int logplane = RPCConst::m_FIRST_PLANE; logplane != RPCConst::m_USED_PLANES_COUNT[std::abs(getTower())];
0062        ++logplane) {
0063     unsigned int strip = (pat & (mask << shift)) >> shift;
0064     //std::cout << logplane << " " << strip << std::endl;
0065     shift += 8;
0066     // We should prob. use m_NOT_CONNECTED value
0067     if (strip != RPCConst::m_LOGPLANE_SIZE[std::abs(getTower())][logplane])
0068       setLogStrip(logplane, strip);
0069   }
0070 }
0071 
0072 unsigned long long RPCLogCone::getCompressedCone() {
0073   unsigned long long int pattern = 0;
0074   int shift = 0;
0075 
0076   for (int logplane = RPCConst::m_FIRST_PLANE; logplane != RPCConst::m_USED_PLANES_COUNT[std::abs(getTower())];
0077        logplane++) {
0078     unsigned long long int strip;
0079     if (getHitsCnt(logplane) == 0) {
0080       // We need to mark somehow, that plane is empty (strip 0 is not fired)
0081       strip = RPCConst::m_LOGPLANE_SIZE[std::abs(getTower())][logplane];
0082     } else if (getHitsCnt(logplane) == 1) {
0083       RPCLogCone::TLogPlane lp = getLogPlane(logplane);
0084       strip = lp.begin()->first;
0085     } else {
0086       throw RPCException("To many hits in logcone");
0087     }
0088     pattern = pattern | (strip << shift);
0089     shift += 8;
0090   }
0091 
0092   //std::cout << " Compressed cone: "   << pattern << std::endl;
0093   return pattern;
0094 }
0095 
0096 std::string RPCLogCone::toString() const {
0097   std::ostringstream ostr;
0098   ostr << "\n       ======================> TOWER = ";
0099   ostr << std::setw(2) << m_ConeCrdnts.m_Tower << ", m_LogSector = " << m_ConeCrdnts.m_LogSector
0100        << ",  m_LogSegment = " << m_ConeCrdnts.m_LogSegment << " <=======================" << std::endl;
0101 
0102   std::string spacer;
0103 
0104   for (int logPlane = RPCConst::m_LAST_PLANE; logPlane >= RPCConst::m_FIRST_PLANE; logPlane--) {
0105     ostr << RPCConst::m_LOGPLANE_STR[logPlane] << " ";
0106     spacer.assign((72 - RPCConst::m_LOGPLANE_SIZE[abs(m_ConeCrdnts.m_Tower)][logPlane]) / 2, ' ');
0107     ostr << spacer;
0108 
0109     for (int i = RPCConst::m_LOGPLANE_SIZE[abs(m_ConeCrdnts.m_Tower)][logPlane] - 1; i >= 0; i--) {
0110       if (getLogStripState(logPlane, i))
0111         ostr << "X";
0112       else {
0113         if (i % 8 == 0)
0114           ostr << i % 10;
0115         else
0116           ostr << ".";
0117       }
0118     }
0119 
0120     ostr << std::endl;
0121   }
0122 
0123   ostr << std::endl;
0124   return ostr.str();
0125 }
0126 void RPCLogCone::shift(int pos) {
0127   int shiftPos;
0128   for (int logPlane = RPCConst::m_FIRST_PLANE; logPlane <= RPCConst::m_LAST_PLANE; logPlane++) {
0129     TLogPlane shifted;
0130     for (TLogPlane::iterator it = m_LogPlanesVec[logPlane].begin(); it != m_LogPlanesVec[logPlane].end(); it++) {
0131       shiftPos = it->first + pos;
0132       /*     std::cout << shiftPos << " "
0133                 << RPCConst::m_LOGPLANE_SIZE[abs(m_ConeCrdnts.m_Tower)] 
0134                 << std::endl;*/
0135       if (shiftPos >= 0 && shiftPos < (int)RPCConst::m_LOGPLANE_SIZE[abs(m_ConeCrdnts.m_Tower)][logPlane])
0136         shifted.insert(TLogPlane::value_type(shiftPos, it->second));
0137     }
0138     m_LogPlanesVec[logPlane] = shifted;
0139   }
0140 }
0141 //
0142 //#############################################################################################
0143 //
0144 //  Simple getters and setters
0145 //
0146 //#############################################################################################
0147 RPCLogCone::TLogPlane RPCLogCone::getLogPlane(int logPlane) const { return m_LogPlanesVec[logPlane]; }
0148 
0149 ///Gets fired strips count in given logPlane.
0150 int RPCLogCone::getHitsCnt(int logPlane) const { return m_LogPlanesVec[logPlane].size(); }
0151 
0152 /// sets pt code of muon that fired the strips */
0153 void RPCLogCone::setMuonCode(int code) { m_MuonCode = code; }
0154 
0155 /** @return pt code of muon that fired the strips */
0156 int RPCLogCone::getMuonCode() const { return m_MuonCode; }
0157 
0158 void RPCLogCone::setMuonSign(int sign) { m_MuonSign = sign; }
0159 
0160 int RPCLogCone::getMuonSign() const { return m_MuonSign; }
0161 
0162 int RPCLogCone::getTower() const { return m_ConeCrdnts.m_Tower; }
0163 
0164 int RPCLogCone::getLogSector() const { return m_ConeCrdnts.m_LogSector; }
0165 
0166 int RPCLogCone::getLogSegment() const { return m_ConeCrdnts.m_LogSegment; }
0167 
0168 RPCConst::l1RpcConeCrdnts RPCLogCone::getConeCrdnts() const { return m_ConeCrdnts; }
0169 
0170 void RPCLogCone::setIdx(int index) { m_Index = index; }
0171 
0172 int RPCLogCone::getIdx() const { return m_Index; }
0173 
0174 void RPCLogCone::setLogStrip(int logPlane, int logStripNum, int m_digiIdx) {
0175   //m_LogPlanesVec[logPlane].insert(logStripNum);
0176   //m_LogPlanesVec[logPlane].insert(TLogPlane::value_type(logStripNum, vector<int>()));
0177   m_LogPlanesVec[logPlane][logStripNum].push_back(m_digiIdx);
0178 }
0179 
0180 void RPCLogCone::setLogStrip(int logPlane, int logStripNum) {
0181   m_LogPlanesVec[logPlane].insert(TLogPlane::value_type(logStripNum, std::vector<int>()));
0182 }
0183 
0184 bool RPCLogCone::getLogStripState(int logPlane, unsigned int logStripNum) const {
0185   return m_LogPlanesVec[logPlane].count(logStripNum);
0186 }
0187 
0188 /**
0189  *
0190  * Adds a loghit to a cone
0191  * 
0192 */
0193 bool RPCLogCone::addLogHit(const RPCLogHit &logHit) {
0194   if (m_ConeCrdnts.m_Tower == logHit.getTower() && m_ConeCrdnts.m_LogSector == logHit.getLogSector() &&
0195       m_ConeCrdnts.m_LogSegment == logHit.getLogSegment()) {
0196     setLogStrip(logHit.getlogPlaneNumber() - 1, logHit.getStripNumberInCone(), logHit.getDigiIdx());
0197     return true;
0198   } else
0199     return false;
0200 }
0201 
0202 std::vector<int> RPCLogCone::getLogStripDigisIdxs(int logPlane, unsigned int logStripNum) const {
0203   TLogPlane::const_iterator it = m_LogPlanesVec[logPlane].find(logStripNum);
0204   if (it != m_LogPlanesVec[logPlane].end())
0205     return it->second;
0206   else
0207     return std::vector<int>();
0208 }
0209 
0210 bool RPCLogCone::isPlaneFired(int logPlane) const {
0211   if (m_LogPlanesVec[logPlane].empty())
0212     return false;
0213   else
0214     return true;
0215 }
0216 
0217 int RPCLogCone::getFiredPlanesCnt() const {
0218   int firedPlanes = 0;
0219   for (int logPlane = RPCConst::m_FIRST_PLANE; logPlane < RPCConst::m_USED_PLANES_COUNT[abs(m_ConeCrdnts.m_Tower)];
0220        logPlane++) {
0221     firedPlanes = firedPlanes + isPlaneFired(logPlane);
0222   }
0223   return firedPlanes;
0224 }
0225 
0226 int RPCLogCone::possibleTrigger() const {
0227   int triggerType = 0;  //0 - trigger not possible
0228                         //1 - 3/4 (3 inner planes fired)
0229                         //2 - 4/6 (four palnes fired)
0230   int firedPlanes = 0;
0231 
0232   int logPlane = RPCConst::m_FIRST_PLANE;
0233   for (; logPlane <= RPCConst::m_LOGPLANE4; logPlane++) {
0234     firedPlanes = firedPlanes + isPlaneFired(logPlane);
0235   }
0236   if (firedPlanes >= 3)
0237     triggerType = 1;
0238 
0239   for (; logPlane < RPCConst::m_USED_PLANES_COUNT[abs(m_ConeCrdnts.m_Tower)]; logPlane++) {
0240     firedPlanes = firedPlanes + isPlaneFired(logPlane);
0241   }
0242   if (firedPlanes >= 4)
0243     triggerType = 2;
0244 
0245   return triggerType;
0246 }