CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

RPCPhiEff Class Reference

#include <MyLib/RPCPhiEff/src/RPCPhiEff.cc>

Inheritance diagram for RPCPhiEff:
edm::EDAnalyzer

List of all members.

Public Member Functions

 RPCPhiEff (const edm::ParameterSet &)
 ~RPCPhiEff ()

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
virtual void beginJob (const edm::EventSetup &)
virtual void endJob ()
std::string fromCones (const edm::Event &iEvent)
std::string fromRaw (const edm::Event &iEvent)

Private Attributes

RPCConst m_const
edm::InputTag m_g4
std::ofstream m_outfileC
std::ofstream m_outfileR
edm::InputTag m_rpcb
edm::InputTag m_rpcdigi
edm::InputTag m_rpcf
RPCConst rpcconst

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 39 of file RPCPhiEff.h.


Constructor & Destructor Documentation

RPCPhiEff::RPCPhiEff ( const edm::ParameterSet ps) [explicit]

Definition at line 65 of file RPCPhiEff.cc.

References m_outfileR.

                                               :
      m_rpcb( ps.getParameter< edm::InputTag >("rpcb") ),
      m_rpcf( ps.getParameter< edm::InputTag >("rpcf") ),
      m_g4( ps.getParameter< edm::InputTag >("g4") ),
      m_rpcdigi( ps.getParameter< edm::InputTag >("rpcdigi") )
{


    //m_outfileC.open("phieffC.txt");
    m_outfileR.open("muons.txt");

}
RPCPhiEff::~RPCPhiEff ( )

Definition at line 79 of file RPCPhiEff.cc.

References m_outfileR.

{

    //m_outfileC.close();
    m_outfileR.close();

}

Member Function Documentation

void RPCPhiEff::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDAnalyzer.

Definition at line 94 of file RPCPhiEff.cc.

References abs, deltaR(), edm::EventID::event(), edm::Event::getByLabel(), edm::EventBase::id(), m_const, m_g4, m_outfileR, m_rpcb, m_rpcf, pi, and RPCConst::towerNumFromEta().

{


    edm::Handle<std::vector<L1MuRegionalCand> > rpcBarrel;
    edm::Handle<std::vector<L1MuRegionalCand> > rpcForward;
  //iEvent.getByLabel("rpctrig","RPCb",rpcBarrel);
  //iEvent.getByLabel("rpctrig","RPCf",rpcForward);

    iEvent.getByLabel(m_rpcb,rpcBarrel);
    iEvent.getByLabel(m_rpcf,rpcForward);


    std::vector< edm::Handle<std::vector<L1MuRegionalCand> >  > handleVec;
    handleVec.push_back( rpcBarrel );  
    handleVec.push_back( rpcForward );  
  
  // Fetch MCdata
    edm::Handle<edm::SimTrackContainer> simTracks;
    iEvent.getByLabel(m_g4,simTracks);

    float etaGen = 0, phiGen = 0, ptGen = 0;
 
    int noOfMuons = 0;
    int noOfRecMuons = 0;
    int noOfMatchedRecMuons = 0; 

    bool firstRunForMuonMatchingCnt = true;

    // ask MC muons to be separated
    double deltarMin = -1;
    edm::SimTrackContainer::const_iterator simTrk = simTracks->begin();
    for (; simTrk != simTracks->end(); ++simTrk) { 

      if (simTrk->type() != -13 && simTrk->type()!=13) continue;

      edm::SimTrackContainer::const_iterator simTrk2 = simTrk;
      ++simTrk2;
      for (; simTrk2 != simTracks->end(); ++simTrk2) { 
        if (simTrk2->type() != -13 && simTrk2->type()!=13) continue;
        double drCand = reco::deltaR(simTrk2->momentum(), simTrk->momentum());
        if (drCand < deltarMin || deltarMin < 0) deltarMin = drCand;
      }


    }

    //std::cout << deltarMin << std::endl;
    if (deltarMin < 0.7 &&  deltarMin > 0) return;

    simTrk = simTracks->begin();
    for (; simTrk != simTracks->end(); simTrk++) {
        int type = simTrk->type();
        if (type == 13 || type == -13) {
            // Get the data
            const math::XYZTLorentzVectorD momentum = simTrk->momentum();
            etaGen = momentum.eta();
            ptGen = momentum.Pt();
            phiGen = momentum.phi();
            noOfMuons++;

            bool matched = false;
            int ptCodeRec = 0;
            int towerRec = 0;
            int phiRec = 0;
            //int muonsFound=0;
            int qual = 0;
            int ghost = 0; // number of ghost for montecarlo muon

            // Iter rpc muon cands, perform delta R matching
            // todo perform matching also using eta...
            for (  std::vector< edm::Handle<std::vector<L1MuRegionalCand> >  >::iterator it = handleVec.begin();
                   it != handleVec.end();
                   ++it  ) 
            {  
               std::vector<L1MuRegionalCand>::const_iterator itRPC;
               for (itRPC=(*it)->begin(); itRPC!=(*it)->end(); itRPC++){
                  int ptCode =  itRPC->pt_packed();
                  if (ptCode != 0) {

                     if (firstRunForMuonMatchingCnt) ++noOfRecMuons;
                     ptCodeRec=ptCode;
                     phiRec=itRPC->phi_packed();
                     qual = itRPC->quality();
                     towerRec = itRPC->eta_packed();
                     if (towerRec > 16) {
                      towerRec = - ( (~towerRec & 63) + 1);
                     }
                     // match
                     float pi = 3.14159265;
                     //float phiPhys = 2*pi*float(phiRec)/144-pi;
                     float phiScaled = phiGen;
                     if (phiScaled<0)  phiScaled += 2*pi;
                     int phiHwGen = (phiScaled)/2/pi*144;

                     //std::cout << "phi " << phiGen << " " << phiHwGen << " " << phiRec
                     //          << " eta " << etaGen << " " << m_const.towerNumFromEta(etaGen) << " "<< towerRec << std::endl;
                     if (  ( std::abs(phiHwGen-phiRec) < 10) && (std::abs(m_const.towerNumFromEta(etaGen)-towerRec)<1) )
                     {
                         if (matched) { // we have matched m.c. earlier, this is ghost
                            ++ghost;
                         }
                         matched = true;
                         ++noOfMatchedRecMuons;
                         m_outfileR << etaGen << " " << phiGen << " " << ptGen 
                                    << " "    << towerRec << " " << phiRec << " " << ptCodeRec << " " << qual
                                    << " "    << ghost
                                    << std::endl;
                     }
                  } // (ptCode != 0)
               } // muon cands iter ends
            } // barrell/fwd iter ends
            firstRunForMuonMatchingCnt=false;
            if (!matched) {
                         m_outfileR << etaGen << " " << phiGen << " " << ptGen 
                                    << " "    << 0 << " " << 0 << " " << 0 << " " << 0
                                    << " "    << 0
                                    << std::endl;

            }


        }
    }

    edm::EventID id = iEvent.id();
    edm::EventNumber_t evNum = id.event();
    edm::RunNumber_t rnNum = id.run();

    if (noOfMatchedRecMuons!=noOfRecMuons)  {
      edm::LogInfo("RPCEffWarn") << " MuonCands " << noOfRecMuons
                            << " matched " << noOfMatchedRecMuons
                            << " in run " << rnNum
                            << " event " << evNum;
    }



      /*
    m_outfileC << etaGen << " " << phiGen << " " << ptGen << " "
               << phiRec << " " << towerRec << " " << muonsFound  << " " 
               <<  fromCones(iEvent) <<std::endl;*/
    /*m_outfileR << etaGen << " " << phiGen << " " << ptGen << " " 
               << phiRec << " " << towerRec << " " << muonsFound  << " " 
               <<  fromRaw(iEvent) <<std::endl;*/


    /* 
    m_outfileR << etaGen << " " << phiGen << " " << ptGen << " " 
               << phiRec << " " << towerRec << " " << muonsFound  << " " 
               << std::endl;
    
    */


}
void RPCPhiEff::beginJob ( const edm::EventSetup ) [private, virtual]

Definition at line 381 of file RPCPhiEff.cc.

{
}
void RPCPhiEff::endJob ( void  ) [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 386 of file RPCPhiEff.cc.

{
}
std::string RPCPhiEff::fromCones ( const edm::Event iEvent) [private]

Definition at line 252 of file RPCPhiEff.cc.

                                                     {

 return "";
}
std::string RPCPhiEff::fromRaw ( const edm::Event iEvent) [private]

Definition at line 305 of file RPCPhiEff.cc.

References gather_cfg::cout, edm::Event::getByLabel(), m_rpcdigi, and relativeConstraints::station.

                                                   {

   std::stringstream ss;

   // Digi data.
    edm::Handle<RPCDigiCollection> rpcDigis;
    iEvent.getByLabel(m_rpcdigi,rpcDigis);

    std::set<int> hwPlanes;

    RPCDigiCollection::DigiRangeIterator detUnitIt;
    for (detUnitIt=rpcDigis->begin();
         detUnitIt!=rpcDigis->end();
                 ++detUnitIt)
    {

        const RPCDigiCollection::Range& range = (*detUnitIt).second;
        bool hasBX0 = false;
        for (RPCDigiCollection::const_iterator digiIt = range.first;
            digiIt!=range.second;
            ++digiIt)
        {
          if (digiIt->bx() == 0) {
             hasBX0 = true;
             break;
          }
        } 

        if (!hasBX0) continue;
 
        const RPCDetId& id = (*detUnitIt).first;
        int station = id.station();
        int layer = id.layer();
        //int region = id.region();

          if (station == 3)
            hwPlanes.insert(5);

          else if (station == 4)
            hwPlanes.insert(6);

          else if (station  == 1 && layer == 1)
            hwPlanes.insert(1);

          else if (station  == 1 && layer == 2)
            hwPlanes.insert(2);

          else if (station  == 2 && layer == 1)
            hwPlanes.insert(3);

          else if (station  == 2 && layer == 2)
            hwPlanes.insert(4);

          else
            std::cout << "??????????????" << std::endl;

    }


    for (std::set<int>::iterator it= hwPlanes.begin();
                                 it!= hwPlanes.end();
                                 ++it)
    {
        ss << " " << *it;
    }




  return ss.str();



}

Member Data Documentation

Definition at line 64 of file RPCPhiEff.h.

Referenced by analyze().

Definition at line 61 of file RPCPhiEff.h.

Referenced by analyze().

std::ofstream RPCPhiEff::m_outfileC [private]

Definition at line 51 of file RPCPhiEff.h.

std::ofstream RPCPhiEff::m_outfileR [private]

Definition at line 52 of file RPCPhiEff.h.

Referenced by analyze(), RPCPhiEff(), and ~RPCPhiEff().

Definition at line 59 of file RPCPhiEff.h.

Referenced by analyze().

Definition at line 62 of file RPCPhiEff.h.

Referenced by fromRaw().

Definition at line 60 of file RPCPhiEff.h.

Referenced by analyze().

Definition at line 57 of file RPCPhiEff.h.