CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/L1Trigger/RPCTrigger/src/RPCPacData.cc

Go to the documentation of this file.
00001 /*******************************************************************************
00002 *                                                                              *
00003 *  Karol Bunkowski                                                             *
00004 *  Warsaw University 2002                                                      *
00005 *  Porting to CMSSW - Tomasz Fruboes
00006 *                                                                              *
00007 *******************************************************************************/
00008 #include <cmath>
00009 #include <bitset>
00010 #include "L1Trigger/RPCTrigger/interface/RPCPacData.h"
00011 #include "L1Trigger/RPCTrigger/interface/RPCConst.h"
00012 
00013 #include "L1Trigger/RPCTrigger/interface/RPCException.h"
00014 
00015 #include <iostream>
00016 
00017 //#include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 
00019 
00030 RPCPacData::RPCPacData(std::string patFilesDir, int tower, int logSector, int logSegment){
00031   
00032  //: RPCPacBase(tower, logSector, logSegment) { 
00033   m_MaxQuality=0;
00034   std::string patFileName;
00035   
00036   RPCConst rpcconst;
00037 
00038 
00039   patFileName = patFilesDir 
00040       + "pacPat_t" + rpcconst.intToString(tower) 
00041       + "sc" + rpcconst.intToString(logSector) 
00042       + "sg" + rpcconst.intToString(logSegment) 
00043       + ".xml";
00044 
00045   RPCConst::l1RpcConeCrdnts coneCrds;
00046   coneCrds.m_Tower=tower;
00047   coneCrds.m_LogSector=logSector;
00048   coneCrds.m_LogSegment=logSegment;
00049         
00050   RPCPatternsParser parser;
00051   parser.parse(patFileName);
00052   init(parser, coneCrds);
00053 
00054   m_TrackPatternsGroup.setGroupDescription("Track PatternsGroup");
00055     
00056 }
00062 RPCPacData::RPCPacData(const RPCPattern::RPCPatVec &patVec, 
00063                        const RPCPattern::TQualityVec &qualVec) :
00064   m_MaxQuality(0)
00065 {
00066   for(unsigned int i = 0; i < qualVec.size(); ++i) {    
00067     RPCPattern::TQuality quality = qualVec[i];
00068     std::bitset<RPCConst::m_LOGPLANES_COUNT> qualBits(quality.m_FiredPlanes);
00069     unsigned short firedPlanes = qualBits.to_ulong();
00070 
00071     insertQualityRecord(quality.m_QualityTabNumber, firedPlanes, quality.m_QualityValue);  
00072   }
00073 
00074   
00075   insertPatterns(patVec);
00076 
00077    
00078 }
00079 
00080 
00081 
00082 RPCPacData::RPCPacData(const L1RPCConfig * rpcconf, const int tower, const int sector, const int segment):
00083   m_MaxQuality(0)
00084 {
00085 
00086     for (unsigned int iqual=0; iqual<rpcconf->m_quals.size(); iqual++){
00087 
00088       if (rpcconf->m_quals[iqual].m_tower != tower ||  
00089           rpcconf->m_quals[iqual].m_logsector != sector ||
00090           rpcconf->m_quals[iqual].m_logsegment != segment )  continue;
00091 
00092       RPCPattern::TQuality quality =rpcconf->m_quals[iqual];
00093       std::bitset<RPCConst::m_LOGPLANES_COUNT> qualBits(quality.m_FiredPlanes);
00094       unsigned short firedPlanes = qualBits.to_ulong();
00095       insertQualityRecord(quality.m_QualityTabNumber, firedPlanes, quality.m_QualityValue);
00096 
00097     }
00098 
00099   insertPatterns(rpcconf->m_pats,tower,sector,segment);
00100 
00101 }
00102 
00103 
00104 
00105 
00106 
00112 int RPCPacData::getPatternsGroupCount() {
00113   return(1 + m_EnergeticPatternsGroupList.size()); //1 = track pattrens group
00114 }
00121 RPCPattern RPCPacData::getPattern(int patNum) const {
00122   if(m_PatternsVec.size() == 0) {
00123   
00124     throw RPCException("GetPattren(): Patterns vec is empty, mayby it was not filled!");
00125     //edm::LogError("RPCTrigger") << "GetPattren(): Patterns vec is empty, mayby it was not filled!";
00126     
00127   }
00128   return m_PatternsVec[patNum];
00129   
00130 }
00136 int RPCPacData::getPatternsCount() {
00137   return m_PatternsVec.size();
00138 }
00145 bool RPCPacData::getTPatternsGroupShape(int logPlane, int logStripNum) {
00146   return m_TrackPatternsGroup.m_GroupShape.getLogStripState(logPlane, logStripNum);
00147 }
00154 bool RPCPacData::getEPatternsGroupShape(int groupNum, int logPlane, int bitNum) {
00155   TEPatternsGroupList::const_iterator iEGroup = m_EnergeticPatternsGroupList.begin();
00156   int i = 0;
00157   for(; iEGroup != m_EnergeticPatternsGroupList.end(); iEGroup++, i++) {
00158     if(i == groupNum)
00159       return iEGroup->m_GroupShape.getLogStripState(logPlane, bitNum);
00160   }
00161   throw RPCException("getEPatternsGroupShape(): groupNum to big!");
00162   //edm::LogError("RPCTrigger")<< "getEPatternsGroupShape(): groupNum to big!";
00163   return false; // XXX - TMF
00164 }
00165 
00166 std::string RPCPacData::getPatternsGroupDescription(int patternGroupNum) {
00167   
00168   RPCConst rpcconst;
00169   
00170   std::string ret;
00171   if(patternGroupNum == -1)
00172     ret =  m_TrackPatternsGroup.getGroupDescription();
00173   else  {
00174     TEPatternsGroupList::iterator iEGroup = m_EnergeticPatternsGroupList.begin();
00175     int i = 0;
00176     for(; iEGroup != m_EnergeticPatternsGroupList.end(); iEGroup++, i++) {
00177       if(i == patternGroupNum)
00178         ret = "EGroup #"+ rpcconst.intToString(i)+iEGroup->getGroupDescription();
00179     }
00180     
00181   }
00182   
00183   if(ret.empty()){
00184       throw RPCException("getEPatternsGroupShape(): groupNum to big!");
00185       //edm::LogError("RPCTrigger")<< "getEPatternsGroupShape(): groupNum to big!";
00186   }
00187 
00188   return ret;
00189 }
00190 
00191 void RPCPacData::insertQualityRecord(unsigned int qualityTabNumber,
00192                               unsigned short firedPlanes, short quality) {
00193   
00194   if(quality > m_MaxQuality)
00195     m_MaxQuality = quality;
00196   if(qualityTabNumber < m_QualityTabsVec.size()) {
00197     m_QualityTabsVec[qualityTabNumber][firedPlanes] = quality;                   
00198   }
00199   else if(qualityTabNumber == m_QualityTabsVec.size()) {
00200     // XXX - added cast(int)
00201 
00202     //= new TQualityTab();
00203     RPCConst::TQualityTab qualityTab((int)std::pow(2.0,RPCConst::m_LOGPLANES_COUNT), -1); 
00204     m_QualityTabsVec.push_back(qualityTab);
00205     m_QualityTabsVec[qualityTabNumber][firedPlanes] = quality; 
00206   }
00207   else
00208     throw RPCException("insertQualityRecord(): wrong qualityTabNumber");
00209     //edm::LogError("RPCTrigger") << "insertQualityRecord(): wrong qualityTabNumber";
00210 }
00211 
00212 
00213 void RPCPacData::insertPatterns(const RPCPattern::RPCPatVec& patternsVec, const int tower, const int sector, const int segment) {
00214    
00215   bool ignorePos = false;
00216   if ( tower == 99 || sector == 99 || segment == 99) ignorePos = true; 
00217   
00218   RPCConst rpcconst;
00219   
00220   for(RPCPattern::RPCPatVec::const_iterator patIt = patternsVec.begin();
00221       patIt != patternsVec.end();
00222       patIt++)
00223   {
00224     if (!ignorePos &&
00225          (patIt->getTower() != tower  
00226           || patIt->getLogSector() != sector  
00227           || patIt->getLogSegment() != segment) ) continue;
00228     
00229     if(patIt->getPatternType() == RPCPattern::PAT_TYPE_T)
00230       m_TrackPatternsGroup.addPattern(patIt);
00231     else if(patIt->getPatternType() == RPCPattern::PAT_TYPE_E) {
00232       TEPatternsGroupList::iterator iEGroup;
00233       for(iEGroup = m_EnergeticPatternsGroupList.begin();
00234           iEGroup != m_EnergeticPatternsGroupList.end(); iEGroup++)
00235         if(iEGroup->check(patIt))
00236           break;
00237       if(iEGroup == m_EnergeticPatternsGroupList.end()) {
00238         TEPatternsGroup newEGroup(patIt);
00239         newEGroup.setGroupDescription(
00240         //"EGroup #"+ rpcconst.intToString(m_EnergeticPatternsGroupList.size())+
00241         ", code: " + rpcconst.intToString(patIt->getCode()) +
00242         ", dir: " + rpcconst.intToString(patIt->getSign()) +
00243         ", refGroup: " + rpcconst.intToString(patIt->getRefGroup()) +
00244         ", qualityTabNumber: " + rpcconst.intToString(patIt->getQualityTabNumber()));
00245         m_EnergeticPatternsGroupList.push_back(newEGroup);
00246       }
00247       else
00248        iEGroup->addPattern(patIt);
00249     }
00250     else
00251       throw RPCException("InsertPattern(): unsupported pattern type");
00252       //edm::LogError("RPCTrigger") << "InsertPattern(): unsupported pattern type";
00253   }  
00254 
00255   if(m_EnergeticPatternsGroupList.size() != 0) {
00256      
00257     m_EnergeticPatternsGroupList.sort();  //to jest potrzebne, bo w run() przechodzi
00258                                           //pierwszy paettern, ktory ma Maxymalna quality, wiec
00259                                           //grupy musza byc
00260     m_EnergeticPatternsGroupList.reverse();
00261   } 
00262 }
00263 
00264 void RPCPacData::init(const RPCPatternsParser& parser, const RPCConst::l1RpcConeCrdnts& coneCrdnts) {
00265   for(unsigned int i = 0; i < parser.getQualityVec().size(); i++) {    
00266     RPCPattern::TQuality quality = parser.getQualityVec()[i];
00267     std::bitset<RPCConst::m_LOGPLANES_COUNT> qualBits(quality.m_FiredPlanes);
00268     unsigned short firedPlanes = qualBits.to_ulong();
00269 
00270     insertQualityRecord(quality.m_QualityTabNumber, firedPlanes, quality.m_QualityValue);  
00271   }
00272 
00273   m_PatternsVec = parser.getPatternsVec(coneCrdnts);
00274   insertPatterns(m_PatternsVec);
00275 }