Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-13 01:32:15

0001 // -*- C++ -*-
0002 //
0003 // Package:    RPCConeConnectionsAna
0004 // Class:      RPCConeConnectionsAna
0005 //
0006 /**\class RPCConeConnectionsAna RPCConeConnectionsAna.cc L1TriggerConfig/RPCConeConnectionsAna/src/RPCConeConnectionsAna.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Tomasz Maciej Frueboes
0015 //         Created:  Tue Mar 18 15:15:30 CET 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 
0031 #include "FWCore/Framework/interface/ESHandle.h"
0032 
0033 #include "CondFormats/DataRecord/interface/L1RPCConeBuilderRcd.h"
0034 #include "CondFormats/RPCObjects/interface/L1RPCConeBuilder.h"
0035 
0036 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
0037 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0038 
0039 #include "CondFormats/RPCObjects/interface/RPCReadOutMapping.h"
0040 
0041 #include "CondFormats/RPCObjects/interface/RPCEMap.h"
0042 #include "CondFormats/DataRecord/interface/RPCEMapRcd.h"
0043 
0044 #include "CondFormats/L1TObjects/interface/L1RPCConeDefinition.h"
0045 #include "CondFormats/DataRecord/interface/L1RPCConeDefinitionRcd.h"
0046 
0047 //
0048 // class decleration
0049 //
0050 
0051 class RPCConeConnectionsAna : public edm::one::EDAnalyzer<> {
0052 public:
0053   explicit RPCConeConnectionsAna(const edm::ParameterSet&);
0054 
0055 private:
0056   void analyze(const edm::Event&, const edm::EventSetup&) override;
0057   int getDCCNumber(int iTower, int iSec);
0058   int getDCC(int iSec);
0059   void printSymetric(RPCDetId det, edm::ESHandle<RPCGeometry> rpcGeom);
0060   void printRoll(RPCRoll const* roll);
0061   int m_towerBeg;
0062   int m_towerEnd;
0063   int m_sectorBeg;
0064   int m_sectorEnd;
0065 
0066   // ----------member data ---------------------------
0067   edm::ESGetToken<L1RPCConeBuilder, L1RPCConeBuilderRcd> m_coneBuilderToken;
0068   edm::ESGetToken<RPCGeometry, MuonGeometryRecord> m_rpcGeomToken;
0069   edm::ESGetToken<L1RPCConeDefinition, L1RPCConeDefinitionRcd> m_coneDefToken;
0070   edm::ESGetToken<RPCEMap, RPCEMapRcd> m_nmapToken;
0071 };
0072 
0073 //
0074 // constants, enums and typedefs
0075 //
0076 
0077 //
0078 // static data member definitions
0079 //
0080 
0081 //
0082 // constructors and destructor
0083 //
0084 RPCConeConnectionsAna::RPCConeConnectionsAna(const edm::ParameterSet& iConfig)
0085 
0086 {
0087   //now do what ever initialization is needed
0088   m_towerBeg = iConfig.getParameter<int>("minTower");
0089   m_towerEnd = iConfig.getParameter<int>("maxTower");
0090 
0091   m_sectorBeg = iConfig.getParameter<int>("minSector");
0092   m_sectorEnd = iConfig.getParameter<int>("maxSector");
0093 
0094   m_coneBuilderToken = esConsumes();
0095   m_rpcGeomToken = esConsumes();
0096   m_coneDefToken = esConsumes();
0097   m_nmapToken = esConsumes();
0098 }
0099 
0100 //
0101 // member functions
0102 //
0103 
0104 // ------------ method called once each job just before starting event loop  ------------
0105 void RPCConeConnectionsAna::analyze(const edm::Event& iEvent, const edm::EventSetup& evtSetup) {
0106   std::map<int, int> PACmap;
0107 
0108   edm::ESHandle<L1RPCConeBuilder> coneBuilder = evtSetup.getHandle(m_coneBuilderToken);
0109 
0110   edm::ESHandle<RPCGeometry> rpcGeom = evtSetup.getHandle(m_rpcGeomToken);
0111 
0112   edm::ESHandle<L1RPCConeDefinition> coneDef = evtSetup.getHandle(m_coneDefToken);
0113 
0114   edm::ESHandle<RPCEMap> nmap = evtSetup.getHandle(m_nmapToken);
0115   const RPCEMap* eMap = nmap.product();
0116   edm::ESHandle<RPCReadOutMapping> map = eMap->convert();
0117 
0118   for (TrackingGeometry::DetContainer::const_iterator it = rpcGeom->dets().begin(); it != rpcGeom->dets().end(); ++it) {
0119     if (dynamic_cast<const RPCRoll*>(*it) == 0)
0120       continue;
0121 
0122     RPCRoll const* roll = dynamic_cast<RPCRoll const*>(*it);
0123 
0124     int detId = roll->id().rawId();
0125     //      if ( detId != 637567014) continue;
0126     //     if (roll->id().station() != 2 || roll->id().ring() != 2) continue;
0127 
0128     std::pair<L1RPCConeBuilder::TCompressedConVec::const_iterator, L1RPCConeBuilder::TCompressedConVec::const_iterator>
0129         compressedConnPair = coneBuilder->getCompConVec(detId);
0130     //iterate over strips
0131     for (int strip = 0; strip < roll->nstrips(); ++strip) {
0132       /* old 
0133           std::pair<L1RPCConeBuilder::TStripConVec::const_iterator, 
0134                     L1RPCConeBuilder::TStripConVec::const_iterator> 
0135                     itPair = coneBuilder->getConVec(detId, strip);*/
0136 
0137       //         L1RPCConeBuilder::TStripConVec::const_iterator it = itPair.first;
0138       //         for (; it!=itPair.second;++it){
0139       L1RPCConeBuilder::TCompressedConVec::const_iterator itComp = compressedConnPair.first;
0140       for (; itComp != compressedConnPair.second; ++itComp) {
0141         int logstrip = itComp->getLogStrip(strip, coneDef->getLPSizeVec());
0142         if (logstrip == -1)
0143           continue;
0144 
0145         // iterate over all PACs
0146         for (int tower = m_towerBeg; tower <= m_towerEnd; ++tower) {
0147           if (itComp->m_tower != tower)
0148             continue;
0149 
0150           for (int sector = m_sectorBeg; sector <= m_sectorEnd; ++sector) {
0151             int dccInputChannel = getDCCNumber(tower, sector);
0152             int PAC = sector * 12;
0153             int PACend = PAC + 11;
0154 
0155             for (; PAC <= PACend; ++PAC) {
0156               if (itComp->m_PAC != PAC)
0157                 continue;
0158               ++PACmap[PAC];
0159 
0160               LinkBoardElectronicIndex a;
0161               std::pair<LinkBoardElectronicIndex, LinkBoardPackedStrip> linkStrip =
0162                   std::make_pair(a, LinkBoardPackedStrip(0, 0));
0163 
0164               std::pair<int, int> stripInDetUnit(detId, strip);
0165               std::vector<std::pair<LinkBoardElectronicIndex, LinkBoardPackedStrip> > aVec =
0166                   map->rawDataFrame(stripInDetUnit);
0167               std::vector<std::pair<LinkBoardElectronicIndex, LinkBoardPackedStrip> >::const_iterator CI;
0168 
0169               for (CI = aVec.begin(); CI != aVec.end(); CI++) {
0170                 if (CI->first.dccInputChannelNum == dccInputChannel)
0171                   linkStrip = *CI;
0172               }
0173 
0174               if (linkStrip.second.packedStrip() == -17) {
0175                 std::cout << "BAD: PAC " << PAC << " tower " << tower << " detId " << detId << " strip " << strip
0176                           << " lp " << (int)itComp->m_logplane << " ls " << (int)logstrip << std::endl;
0177 
0178                 std::cout << " Connected to: " << std::endl;
0179                 for (CI = aVec.begin(); CI != aVec.end(); CI++) {
0180                   std::cout << "     DCC: " << CI->first.dccId << " DCCInChannel: " << CI->first.dccInputChannelNum
0181                             << std::endl;
0182                 }
0183                 std::cout << " Me thinks it should be: DCC: " << getDCC(sector) << " DCCInChannel: " << dccInputChannel
0184                           << std::endl;
0185 
0186                 printRoll(roll);
0187                 printSymetric(roll->id(), rpcGeom);
0188 
0189               } else {
0190                 /*
0191                      std::cout<<" OK: PAC "<< PAC  << " tower "  << tower 
0192                               << " detId " << detId << " strip " << strip 
0193                               << " lp " << (int)itComp->m_logplane
0194                               << " ls "  << (int)logstrip
0195                               <<" "<< RPCDetId(detId) 
0196                               << std::endl;*/
0197               }
0198 
0199             }  // PAC iteration
0200 
0201           }  // sector iteration
0202 
0203         }  // tower iteration
0204 
0205       }  // cone connections interation
0206 
0207     }  // strip in roll iteration
0208 
0209   }  // roll iteration
0210 
0211   std::map<int, int>::iterator it = PACmap.begin();
0212   for (; it != PACmap.end(); ++it) {
0213     if (it->second != 8) {
0214       //    std::cout << "PAC " << it->first << " refcon " << it->second << std::endl;
0215     }
0216   }
0217 }
0218 
0219 int RPCConeConnectionsAna::getDCCNumber(int iTower, int iSec) {
0220   int tbNumber = 0;
0221   if (iTower < -12)
0222     tbNumber = 0;
0223   else if (-13 < iTower && iTower < -8)
0224     tbNumber = 1;
0225   else if (-9 < iTower && iTower < -4)
0226     tbNumber = 2;
0227   else if (-5 < iTower && iTower < -1)
0228     tbNumber = 3;
0229   else if (-2 < iTower && iTower < 2)
0230     tbNumber = 4;
0231   else if (1 < iTower && iTower < 5)
0232     tbNumber = 5;
0233   else if (4 < iTower && iTower < 9)
0234     tbNumber = 6;
0235   else if (8 < iTower && iTower < 13)
0236     tbNumber = 7;
0237   else if (12 < iTower)
0238     tbNumber = 8;
0239 
0240   int phiFactor = iSec % 4;
0241   return (tbNumber + phiFactor * 9);  //Count DCC input channel from 1
0242 }
0243 
0244 int RPCConeConnectionsAna::getDCC(int iSec) {
0245   int ret = 0;
0246   if (iSec >= 0 && iSec <= 3)
0247     ret = 792;
0248   else if (iSec >= 4 && iSec <= 7)
0249     ret = 791;
0250   else if (iSec >= 8 && iSec <= 11)
0251     ret = 791;
0252 
0253   else
0254     throw cms::Exception("blablabla") << "Bad ligsector:" << iSec << std::endl;
0255 
0256   return ret;
0257 }
0258 
0259 void RPCConeConnectionsAna::printSymetric(RPCDetId det, edm::ESHandle<RPCGeometry> rpcGeom) {
0260   RPCDetId detSym;
0261 
0262   if (det.region() == 0) {  // bar
0263     detSym = RPCDetId(0, -det.ring(), det.station(), det.sector(), det.layer(), det.subsector(), det.roll());
0264   } else {  // endcap
0265     detSym = RPCDetId(-det.region(), det.ring(), det.station(), det.sector(), det.layer(), det.subsector(), det.roll());
0266   }
0267 
0268   for (TrackingGeometry::DetContainer::const_iterator it = rpcGeom->dets().begin(); it != rpcGeom->dets().end(); ++it) {
0269     if (dynamic_cast<const RPCRoll*>(*it) == 0)
0270       continue;
0271     RPCRoll const* roll = dynamic_cast<RPCRoll const*>(*it);
0272 
0273     if (roll->id() != detSym)
0274       continue;
0275     printRoll(roll);
0276   }
0277 }
0278 
0279 void RPCConeConnectionsAna::printRoll(const RPCRoll* roll) {
0280   LocalPoint lStripCentre1 = roll->centreOfStrip(1);
0281   LocalPoint lStripCentreMax = roll->centreOfStrip(roll->nstrips());
0282 
0283   GlobalPoint gStripCentre1 = roll->toGlobal(lStripCentre1);
0284   GlobalPoint gStripCentreMax = roll->toGlobal(lStripCentreMax);
0285   float phiRaw1 = gStripCentre1.phi();
0286   float phiRawMax = gStripCentreMax.phi();
0287   std::cout << roll->id().rawId() << " " << roll->id() << " - chamber spans in phi between : " << phiRaw1 << " "
0288             << phiRawMax << std::endl;
0289 }
0290 //define this as a plug-in
0291 DEFINE_FWK_MODULE(RPCConeConnectionsAna);