CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

RPCTrigger Class Reference

Implements RPC trigger emulation. More...

#include <RPCTrigger.h>

Inheritance diagram for RPCTrigger:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

virtual void produce (edm::Event &, const edm::EventSetup &)
 RPCTrigger (const edm::ParameterSet &)
 ~RPCTrigger ()

Private Member Functions

std::vector< L1MuRegionalCandgiveFinallCandindates (L1RpcTBMuonsVec finalMuons, int type, int bx, edm::Handle< RPCDigiCollection > rpcDigis, std::vector< RPCDigiL1Link > &retRPCDigiLink)
 Returns vector of L1MuRegionalCand (input of L1GMT)

Private Attributes

unsigned long long m_cacheID
bool m_firstRun
std::string m_label
RPCPacManager< RPCPacDatam_pacManager
RPCPacTriggerm_pacTrigger
RPCConeBuilderFromES m_theLinksystemFromES
RPCBasicTrigConfigm_trigConfig
int m_triggerDebug

Detailed Description

Implements RPC trigger emulation.

Author:
Tomasz Fruboes

Definition at line 48 of file RPCTrigger.h.


Constructor & Destructor Documentation

RPCTrigger::RPCTrigger ( const edm::ParameterSet iConfig) [explicit]

Definition at line 25 of file RPCTrigger.cc.

References edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), m_cacheID, m_firstRun, m_label, and m_triggerDebug.

                                                    :
   m_trigConfig(0),m_pacTrigger(0)
{
  produces<std::vector<L1MuRegionalCand> >("RPCb");
  produces<std::vector<L1MuRegionalCand> >("RPCf");

  produces<std::vector<RPCDigiL1Link> >("RPCb");
  produces<std::vector<RPCDigiL1Link> >("RPCf");

  m_firstRun = true;
  m_cacheID = 0;


  m_triggerDebug = iConfig.getUntrackedParameter<int>("RPCTriggerDebug",0);
  
  // 0 - no debug
  // 1 - dump to xml
  if ( m_triggerDebug != 1){
     m_triggerDebug = 0;
  }
     
   
  m_label = iConfig.getParameter<std::string>("label");
}
RPCTrigger::~RPCTrigger ( )

Definition at line 53 of file RPCTrigger.cc.

References m_pacTrigger, and m_trigConfig.

                       { 
   if (m_pacTrigger != 0) delete m_pacTrigger;
   if (m_trigConfig != 0) delete m_trigConfig;
}

Member Function Documentation

std::vector< L1MuRegionalCand > RPCTrigger::giveFinallCandindates ( L1RpcTBMuonsVec  finalMuons,
int  type,
int  bx,
edm::Handle< RPCDigiCollection rpcDigis,
std::vector< RPCDigiL1Link > &  retRPCDigiLink 
) [private]

Returns vector of L1MuRegionalCand (input of L1GMT)

Note:
- type is defined in L1MuRegionalCand 1 - barell, 3 - forward

Definition at line 214 of file RPCTrigger.cc.

References L1MuRegionalCand::bx(), DeDxDiscriminatorTools::charge(), L1MuRegionalCand::charge_packed(), L1MuRegionalCand::eta_packed(), LogDebug, L1MuRegionalCand::phi_packed(), L1MuRegionalCand::quality(), DetId::rawId(), L1MuRegionalCand::setBx(), L1MuRegionalCand::setChargePacked(), L1MuRegionalCand::setChargeValid(), L1MuRegionalCand::setEtaPacked(), RPCDigiL1Link::setLink(), L1MuRegionalCand::setPhiPacked(), L1MuRegionalCand::setPtPacked(), L1MuRegionalCand::setQualityPacked(), L1MuRegionalCand::setType(), and L1MuRegionalCand::type_idx().

Referenced by produce().

{

  std::vector<L1MuRegionalCand> RPCCand;

  for(unsigned int iMu = 0; iMu < finalMuons.size(); iMu++)
  {

    if (finalMuons[iMu].getPtCode()==0){
      continue; 
    } 

    RPCDigiL1Link newDigiLink;

    //std::cout << "######################################## " << std::endl;
    //std::cout << finalMuons[iMu].getPhiAddr() << " " << finalMuons[iMu].getEtaAddr() << std::endl;
    RPCMuon::TDigiLinkVec digiIVec = finalMuons[iMu].getDigiIdxVec();
    // Here the iteration has to be the same as in 
    short int digiIndex = 0;
    RPCDigiCollection::DigiRangeIterator detUnitIt;
    for (detUnitIt=rpcDigis->begin();
         detUnitIt!=rpcDigis->end();
         ++detUnitIt)
    {

      const RPCDetId& id = (*detUnitIt).first;
      uint32_t rawId = id.rawId();
      const RPCDigiCollection::Range& range = (*detUnitIt).second;


      for (RPCDigiCollection::const_iterator digiIt = range.first;
           digiIt!=range.second;
           ++digiIt)
      {
        ++digiIndex;

        RPCMuon::TDigiLinkVec::iterator it = digiIVec.begin();
        for(;it!=digiIVec.end();++it) {
           if (digiIndex==it->m_digiIdx) {
             newDigiLink.setLink(it->m_layer+1, rawId, digiIt->strip(), digiIt->bx() );
             //std::cout << type << " " << iMu << " layer: " << it->m_layer <<  " index " << it->m_digiIdx << std::endl;
             //std::cout << "         " << id << " " << " |bx " << digiIt->bx() << " strip " << digiIt->strip() << std::endl;  
           }
        }
      }
    }
    retRPCDigiLink.push_back(newDigiLink);


    L1MuRegionalCand l1Cand;
    
    l1Cand.setBx(bx);
    
    
    l1Cand.setQualityPacked(finalMuons[iMu].getQuality());
    l1Cand.setPtPacked(finalMuons[iMu].getPtCode());
    
    l1Cand.setType(type); 
    
    int charge=finalMuons[iMu].getSign();
    
    if (charge == 0)  // negative
      l1Cand.setChargePacked(1);
    else  
      l1Cand.setChargePacked(0);
    
    //RPCConst::l1RpcConeCrdnts cone = finalMuons[iMu].getConeCrdnts();    
    
    /*
    int pac = cone.m_LogSector*12+cone.m_LogSegment;
    const float pi = 3.14159265;
    const float offset = 5*(2*pi/360); // redefinition! Defined also in RPCRingFromRolls::phiMapCompare
    float phi = 2*pi*pac/144-offset;
    if (phi<0)
      phi+=2*pi;
    
    l1Cand.setPhiValue(phi);
    */

    //Note: pac numbering begins at 5 deg and goes from 1 to 144.
    // we want phi values from 0 to 2.5 deg to be phiPacked=0 
    // max phiPacked value is 143 (see CMS IN 2004-022)
    //int phiPacked = (finalMuons[iMu].getPhiAddr()+2)%144;
    int phiPacked = finalMuons[iMu].getPhiAddr();
    l1Cand.setPhiPacked(phiPacked);
/*
    float eta = RPCConst::etaFromTowerNum(cone.m_Tower);
    l1Cand.setEtaValue(eta);
*/
    //Note: etaAddr is packed in special way: see CMS IN 2004-022
    signed short etaAddr = finalMuons[iMu].getEtaAddr(); // 
//    signed short etaAddr = finalMuons[iMu].getEtaAddr()-16; // -16..16
//    bool etaNegative = false;
//    if (etaAddr < 0){
//      etaNegative = true;
//      etaAddr = ~(-etaAddr)+1; // convert to negative :)
//    }

//    etaAddr &= 63; // 6 bits only
         
    l1Cand.setEtaPacked(etaAddr);
    l1Cand.setChargeValid(true);

    /*    
    std::cout<< std::endl << "RBMuon::" << finalMuons[iMu].getEtaAddr() << " " 
             << finalMuons[iMu].getPhiAddr() << std::endl ;
    std::cout<< "cand " <<  l1Cand.eta_packed() << " " 
             << l1Cand.phi_packed() << std::endl ;
    */

    RPCCand.push_back(l1Cand);
        
    LogDebug("RPCTrigger") << "Found muonf of pt " 
        << finalMuons[iMu].getPtCode()
        << " bx " << l1Cand.bx()
        << " L1Charge " << l1Cand.charge_packed()
        << " ql " << l1Cand.quality()
        << " fp " << finalMuons[iMu].getFiredPlanes()
        << " b/f " << l1Cand.type_idx()
        << " phi " <<  l1Cand.phi_packed()
        << " eta " << l1Cand.eta_packed()
        //<< " eta l1 " << l1Cand.etaValue() // will drop out soon 
        << " killed " << finalMuons[iMu].wasKilled();
        
    
  }

  return RPCCand;
}
void RPCTrigger::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 61 of file RPCTrigger.cc.

References edm::EventBase::bunchCrossing(), edm::eventsetup::EventSetupRecord::cacheIdentifier(), dbtoconf::conf, edm::EventID::event(), edm::EventSetup::get(), edm::Event::getByLabel(), RPCConeBuilderFromES::getConesFromES(), giveFinallCandindates(), edm::EventBase::id(), RPCPacManager< TPacType >::init(), MuonsGrabber::Instance(), edm::HandleBase::isValid(), LogDebug, m_cacheID, m_firstRun, m_label, m_pacManager, m_pacTrigger, m_theLinksystemFromES, m_trigConfig, m_triggerDebug, edm::ESHandle< T >::product(), edm::Event::put(), L1RPCConfig_cff::rpcconf, RPCPacTrigger::runEvent(), RPCTriggerConfiguration::setDebugLevel(), MuonsGrabber::setRPCBasicTrigConfig(), MuonsGrabber::startNewEvent(), and MuonsGrabber::writeDataForRelativeBX().

{
 
  if ( m_triggerDebug == 1)  MuonsGrabber::Instance().startNewEvent(iEvent.id().event(), iEvent.bunchCrossing());  

  if (m_firstRun){

     m_cacheID = iSetup.get<L1RPCConfigRcd>().cacheIdentifier();
     m_firstRun = false;  
     edm::ESHandle<L1RPCConfig> conf;
     iSetup.get<L1RPCConfigRcd>().get(conf);
     const L1RPCConfig *rpcconf = conf.product();


     m_pacManager.init(rpcconf);
     m_trigConfig = new RPCBasicTrigConfig(&m_pacManager);
     m_trigConfig->setDebugLevel(m_triggerDebug);
     m_pacTrigger = new RPCPacTrigger(m_trigConfig);
     if ( m_triggerDebug == 1)  MuonsGrabber::Instance().setRPCBasicTrigConfig(m_trigConfig);

      
  }

  if (m_cacheID != iSetup.get<L1RPCConfigRcd>().cacheIdentifier()) {

      //std::cout << " New pats: " << iSetup.get<L1RPCConfigRcd>().cacheIdentifier() << std::endl ; 
      m_cacheID = iSetup.get<L1RPCConfigRcd>().cacheIdentifier();

     edm::ESHandle<L1RPCConfig> conf;
     iSetup.get<L1RPCConfigRcd>().get(conf);
     const L1RPCConfig *rpcconf = conf.product();

     m_pacManager.init(rpcconf);
     delete m_trigConfig;
     m_trigConfig = new RPCBasicTrigConfig(&m_pacManager);
     m_trigConfig->setDebugLevel(m_triggerDebug);

     delete m_pacTrigger;
     m_pacTrigger = new RPCPacTrigger(m_trigConfig);

     if ( m_triggerDebug == 1)  MuonsGrabber::Instance().setRPCBasicTrigConfig(m_trigConfig);

       
  }

 
  
  edm::Handle<RPCDigiCollection> rpcDigis;
//  iEvent.getByType(rpcDigis);
  //iEvent.getByLabel("muonRPCDigis",rpcDigis);
  iEvent.getByLabel(m_label, rpcDigis);

  std::auto_ptr<std::vector<L1MuRegionalCand> > candBarell(new std::vector<L1MuRegionalCand>);
  std::auto_ptr<std::vector<L1MuRegionalCand> > candForward(new std::vector<L1MuRegionalCand>);
  if (!rpcDigis.isValid()) 
  {
     LogDebug("RPCTrigger")
          << "\nWarning: RPCDigiCollection with input tag " << m_label
          << "\nrequested in configuration, but not found in the event. Emulator will produce empty collection \n ";

          iEvent.put(candBarell, "RPCb");
          iEvent.put(candForward, "RPCf");
 
          return;
  }

  
  if (rpcDigis->begin() == rpcDigis->end() )
  {
     LogDebug("RPCTrigger")
          << "\nWarning: RPCDigiCollection with input tag " << m_label
          << "\n seems to be empty for this event. Emulator will run on empty collection ";

  }



  std::auto_ptr<std::vector<RPCDigiL1Link> >  brlLinks(new std::vector<RPCDigiL1Link>);
  std::auto_ptr<std::vector<RPCDigiL1Link> >  fwdLinks(new std::vector<RPCDigiL1Link>);
    
  for (int iBx = -1; iBx < 2; ++ iBx) {
    
    L1RpcLogConesVec ActiveCones;

    edm::ESHandle<L1RPCConeBuilder> coneBuilder;
    iSetup.get<L1RPCConeBuilderRcd>().get(coneBuilder);
      
    edm::ESHandle<L1RPCConeDefinition> l1RPCConeDefinition;
    iSetup.get<L1RPCConeDefinitionRcd>().get(l1RPCConeDefinition);

    edm::ESHandle<L1RPCHwConfig> hwConfig;
    iSetup.get<L1RPCHwConfigRcd>().get(hwConfig);

    edm::ESHandle<L1RPCBxOrConfig> bxOrConfig;
    iSetup.get<L1RPCBxOrConfigRcd>().get(bxOrConfig);



    ActiveCones = m_theLinksystemFromES.getConesFromES(rpcDigis, coneBuilder, l1RPCConeDefinition, bxOrConfig, hwConfig, iBx);
    
    edm::ESHandle<L1RPCHsbConfig> hsbConfig;
    iSetup.get<L1RPCHsbConfigRcd>().get(hsbConfig);

    L1RpcTBMuonsVec2 finalMuons = m_pacTrigger->runEvent(ActiveCones, hsbConfig);
  
    //int maxFiredPlanes = 0;
    
    /*
    for (unsigned int i=0;i<ActiveCones.size();i++){
        int fpCnt = ActiveCones[i].getFiredPlanesCnt();
        if (fpCnt > maxFiredPlanes)
          maxFiredPlanes = fpCnt;
    }
  
    // Fill out the products
    // finalMuons[0]=barell, finalMuons[1]=endcap
    LogDebug("RPCTrigger") << "---Filling candindates in new event--- " 
                          << maxFiredPlanes << std::endl;
<<<<<<< RPCTrigger.cc
    */
    
//    std::vector<L1MuRegionalCand> RPCb = giveFinallCandindates(finalMuons[0],1, iBx);
//    std::vector<L1MuRegionalCand> RPCf = giveFinallCandindates(finalMuons[1],3, iBx);
    std::vector<RPCDigiL1Link> dlBrl;  
    std::vector<RPCDigiL1Link> dlFwd;  
    std::vector<L1MuRegionalCand> RPCb = giveFinallCandindates(finalMuons[0],1, iBx, rpcDigis, dlBrl);
    std::vector<L1MuRegionalCand> RPCf = giveFinallCandindates(finalMuons[1],3, iBx, rpcDigis, dlFwd);
      
    
    brlLinks->insert(brlLinks->end(), dlBrl.begin(), dlBrl.end() );
    fwdLinks->insert(fwdLinks->end(), dlFwd.begin(), dlFwd.end() );

    candBarell->insert(candBarell->end(), RPCb.begin(), RPCb.end());
    candForward->insert(candForward->end(), RPCf.begin(), RPCf.end());

    if ( m_triggerDebug == 1)  MuonsGrabber::Instance().writeDataForRelativeBX(iBx);  
  }  

  iEvent.put(fwdLinks, "RPCf");
  iEvent.put(brlLinks, "RPCb");
  iEvent.put(candBarell, "RPCb");
  iEvent.put(candForward, "RPCf");
  
}

Member Data Documentation

unsigned long long RPCTrigger::m_cacheID [private]

Definition at line 69 of file RPCTrigger.h.

Referenced by produce(), and RPCTrigger().

bool RPCTrigger::m_firstRun [private]

Definition at line 67 of file RPCTrigger.h.

Referenced by produce(), and RPCTrigger().

std::string RPCTrigger::m_label [private]

Definition at line 74 of file RPCTrigger.h.

Referenced by produce(), and RPCTrigger().

Definition at line 61 of file RPCTrigger.h.

Referenced by produce().

Definition at line 65 of file RPCTrigger.h.

Referenced by produce(), and ~RPCTrigger().

Definition at line 59 of file RPCTrigger.h.

Referenced by produce().

Definition at line 63 of file RPCTrigger.h.

Referenced by produce(), and ~RPCTrigger().

Definition at line 68 of file RPCTrigger.h.

Referenced by produce(), and RPCTrigger().