CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/L1Trigger/RPCTrigger/src/RPCLogCone.cc

Go to the documentation of this file.
00001 /*******************************************************************************
00002 *                                                                              *
00003 *  Karol Bunkowski                                                             *
00004 *  Warsaw University 2002                                                      *
00005 *                                                                              *
00006 *******************************************************************************/
00007 #include "L1Trigger/RPCTrigger/interface/RPCLogCone.h"
00008 #include "L1Trigger/RPCTrigger/interface/RPCException.h"
00009 
00010 #include <iostream>
00011 #include <iomanip>
00012 #include <sstream>
00013 
00019 RPCLogCone::RPCLogCone():
00020     m_ConeCrdnts()
00021 {
00022   m_LogPlanesVec.assign(RPCConst::m_LOGPLANES_COUNT, TLogPlane());
00023   m_MuonCode = 0;
00024   m_MuonSign = 0;
00025 }
00032 RPCLogCone::RPCLogCone(int tower, int logSector, int logSegment):
00033     m_ConeCrdnts(tower, logSector, logSegment)
00034 {
00035   m_LogPlanesVec.assign(RPCConst::m_LOGPLANES_COUNT, TLogPlane());
00036   m_MuonCode = 0;
00037   m_MuonSign = 0;
00038 }
00044 RPCLogCone::RPCLogCone(const RPCLogHit &logHit)
00045 {
00046   m_LogPlanesVec.assign(RPCConst::m_LOGPLANES_COUNT, TLogPlane());
00047 
00048   m_ConeCrdnts = logHit.getConeCrdnts();
00049 
00050   m_MuonCode = 0;
00051   m_MuonSign = 0;
00052 
00053   setLogStrip(logHit.getlogPlaneNumber() -1, logHit.getStripNumberInCone(), logHit.getDigiIdx());
00054 }
00055 
00056 RPCLogCone::RPCLogCone(const unsigned long long &pat, int tower, int logSector, int logSegment):
00057       m_ConeCrdnts(tower, logSector, logSegment)
00058 {
00059   m_LogPlanesVec.assign(RPCConst::m_LOGPLANES_COUNT, TLogPlane());
00060   m_MuonCode = 0;
00061   m_MuonSign = 0;
00062 
00063   unsigned long long int mask = 255; // (first 8 bits)
00064   int shift = 0;
00065 
00066   //std::cout << "Decompressing pattern: " << pat << std::endl;
00067   for (int logplane = RPCConst::m_FIRST_PLANE;
00068            logplane != RPCConst::m_USED_PLANES_COUNT[std::abs(getTower())];
00069          ++logplane  )
00070   {
00071       unsigned int strip = (pat & (mask<<shift) ) >> shift;
00072       //std::cout << logplane << " " << strip << std::endl;
00073       shift += 8;
00074       // We should prob. use m_NOT_CONNECTED value
00075       if (strip != RPCConst::m_LOGPLANE_SIZE[std::abs(getTower())][logplane])
00076         setLogStrip(logplane,strip);
00077   }
00078 }
00079 
00080 unsigned long long RPCLogCone::getCompressedCone(){
00081 
00082     unsigned long long int pattern = 0;
00083     int shift = 0;
00084 
00085     for (int logplane = RPCConst::m_FIRST_PLANE;
00086              logplane != RPCConst::m_USED_PLANES_COUNT[std::abs(getTower())];
00087              logplane++  )
00088      {
00089        unsigned long long int strip;
00090        if (getHitsCnt(logplane)==0) {
00091           // We need to mark somehow, that plane is empty (strip 0 is not fired)
00092           strip = RPCConst::m_LOGPLANE_SIZE[std::abs(getTower())][logplane];
00093        }
00094        else if (getHitsCnt(logplane)==1) {
00095           RPCLogCone::TLogPlane lp = getLogPlane(logplane);
00096           strip = lp.begin()->first;
00097        }
00098        else {
00099           throw RPCException("To many hits in logcone");
00100        }
00101           pattern = pattern | (strip << shift);
00102           shift += 8;
00103      }
00104 
00105    //std::cout << " Compressed cone: "   << pattern << std::endl;
00106    return pattern;
00107 }
00108 
00109 
00110 std::string RPCLogCone::toString() const {
00111   std::ostringstream ostr;
00112   ostr << "\n       ======================> TOWER = ";
00113   ostr<<std::setw(2)
00114       <<m_ConeCrdnts.m_Tower
00115       <<", m_LogSector = "
00116       <<m_ConeCrdnts.m_LogSector
00117       <<",  m_LogSegment = "
00118       <<m_ConeCrdnts.m_LogSegment
00119       <<" <======================="<< std::endl;
00120 
00121   std::string spacer;
00122 
00123   for (int logPlane = RPCConst::m_LAST_PLANE; logPlane >= RPCConst::m_FIRST_PLANE; logPlane--) {
00124     ostr<<RPCConst::m_LOGPLANE_STR[logPlane]<<" ";
00125     spacer.assign((72 - RPCConst::m_LOGPLANE_SIZE[abs(m_ConeCrdnts.m_Tower)][logPlane])/2, ' ');
00126     ostr<<spacer;
00127   
00128     for(int i = RPCConst::m_LOGPLANE_SIZE[abs(m_ConeCrdnts.m_Tower)][logPlane]-1; i >=0; i--) {
00129       if(getLogStripState(logPlane, i))
00130          ostr<<"X";
00131       else {
00132         if(i%8 == 0)
00133           ostr<<i%10;
00134         else
00135     ostr<<"."; 
00136       }  
00137     }  
00138 
00139     ostr<<std::endl;
00140   }
00141  
00142   ostr<< std::endl;
00143   return ostr.str();
00144 }
00145 void RPCLogCone::shift(int pos) {
00146   int shiftPos;
00147   for(int logPlane = RPCConst::m_FIRST_PLANE; logPlane <= RPCConst::m_LAST_PLANE; logPlane++) {
00148     TLogPlane shifted;
00149     for(TLogPlane::iterator it = m_LogPlanesVec[logPlane].begin();
00150         it != m_LogPlanesVec[logPlane].end();
00151         it++)
00152     {
00153       shiftPos = it->first + pos;
00154  /*     std::cout << shiftPos << " "
00155                 << RPCConst::m_LOGPLANE_SIZE[abs(m_ConeCrdnts.m_Tower)] 
00156                 << std::endl;*/
00157       if ( shiftPos >= 0 && shiftPos < (int)RPCConst::m_LOGPLANE_SIZE[abs(m_ConeCrdnts.m_Tower)][logPlane])
00158         shifted.insert(TLogPlane::value_type(shiftPos, it->second));
00159     }
00160     m_LogPlanesVec[logPlane] = shifted;
00161   }
00162 }
00163 // 
00164 //#############################################################################################
00165 //
00166 //  Simple getters and setters
00167 //
00168 //#############################################################################################
00169 RPCLogCone::TLogPlane RPCLogCone::getLogPlane(int logPlane) const { 
00170   return m_LogPlanesVec[logPlane]; 
00171 }
00172 
00174 int RPCLogCone::getHitsCnt(int logPlane) const {
00175   return m_LogPlanesVec[logPlane].size();
00176 }
00177 
00179 void RPCLogCone::setMuonCode(int code) { m_MuonCode = code; }
00180 
00182 int RPCLogCone::getMuonCode() const { return m_MuonCode; }
00183 
00184 void RPCLogCone::setMuonSign(int sign) { m_MuonSign = sign; }
00185 
00186 int RPCLogCone::getMuonSign() const { return m_MuonSign; }
00187 
00188 int RPCLogCone::getTower() const { return m_ConeCrdnts.m_Tower; }
00189 
00190 int RPCLogCone::getLogSector() const { return m_ConeCrdnts.m_LogSector; }
00191 
00192 int RPCLogCone::getLogSegment() const { return m_ConeCrdnts.m_LogSegment; }
00193 
00194 RPCConst::l1RpcConeCrdnts RPCLogCone::getConeCrdnts() const { return m_ConeCrdnts; }
00195 
00196 void RPCLogCone::setIdx(int index) { m_Index = index; }
00197 
00198 int RPCLogCone::getIdx() const { return m_Index; }
00199   
00200 void RPCLogCone::setLogStrip(int logPlane, int logStripNum, int m_digiIdx) {
00201 //m_LogPlanesVec[logPlane].insert(logStripNum);
00202 //m_LogPlanesVec[logPlane].insert(TLogPlane::value_type(logStripNum, vector<int>()));
00203   m_LogPlanesVec[logPlane][logStripNum].push_back(m_digiIdx);
00204 }
00205 
00206 void RPCLogCone::setLogStrip(int logPlane, int logStripNum) {
00207   m_LogPlanesVec[logPlane].insert(TLogPlane::value_type(logStripNum, std::vector<int>()));
00208 }
00209 
00210 
00211 bool RPCLogCone::getLogStripState(int logPlane, unsigned int logStripNum)  const {
00212   return m_LogPlanesVec[logPlane].count(logStripNum);
00213 }
00214 
00215   
00221 bool RPCLogCone::addLogHit(const RPCLogHit &logHit) {
00222   
00223   if (m_ConeCrdnts.m_Tower == logHit.getTower() &&
00224       m_ConeCrdnts.m_LogSector == logHit.getLogSector() &&
00225       m_ConeCrdnts.m_LogSegment == logHit.getLogSegment()) 
00226   {
00227     setLogStrip(logHit.getlogPlaneNumber()-1, logHit.getStripNumberInCone(), logHit.getDigiIdx());
00228     return true;
00229   }
00230   else
00231     return false;
00232 }
00233 
00234 
00235 std::vector<int> RPCLogCone::getLogStripDigisIdxs(int logPlane, unsigned int logStripNum) const {
00236   TLogPlane::const_iterator it = m_LogPlanesVec[logPlane].find(logStripNum); 
00237   if(it != m_LogPlanesVec[logPlane].end())
00238     return it->second;
00239   else
00240     return std::vector<int>();
00241 }
00242 
00243 
00244 bool RPCLogCone::isPlaneFired(int logPlane) const {
00245   if(m_LogPlanesVec[logPlane].size() == 0)
00246     return false; 
00247   else
00248     return true;  
00249 }
00250 
00251 int RPCLogCone::getFiredPlanesCnt() const{
00252   int firedPlanes = 0;
00253   for(int logPlane = RPCConst::m_FIRST_PLANE;
00254       logPlane < RPCConst::m_USED_PLANES_COUNT[abs(m_ConeCrdnts.m_Tower)];
00255       logPlane++)
00256   {
00257     firedPlanes = firedPlanes + isPlaneFired(logPlane);
00258   }
00259   return firedPlanes;
00260 }
00261 
00262 
00263 int RPCLogCone::possibleTrigger() const {
00264   int triggerType = 0; //0 - trigger not possible
00265                         //1 - 3/4 (3 inner planes fired)
00266                         //2 - 4/6 (four palnes fired)
00267   int firedPlanes = 0;
00268 
00269   int logPlane = RPCConst::m_FIRST_PLANE;
00270   for( ; logPlane <= RPCConst::m_LOGPLANE4; logPlane++) {
00271     firedPlanes = firedPlanes + isPlaneFired(logPlane);
00272   }
00273   if(firedPlanes >= 3)
00274     triggerType = 1;
00275 
00276   for( ;
00277       logPlane < RPCConst::m_USED_PLANES_COUNT[abs(m_ConeCrdnts.m_Tower)];
00278       logPlane++)
00279   {
00280     firedPlanes = firedPlanes + isPlaneFired(logPlane);
00281   }
00282   if(firedPlanes >= 4)
00283     triggerType = 2;
00284 
00285   return triggerType;
00286 }