CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

ZmumuPFEmbedder Class Reference

#include <MyAna/ZmumuPFEmbedder/src/ZmumuPFEmbedder.cc>

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

List of all members.

Public Member Functions

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

Private Member Functions

virtual void beginJob ()
virtual void endJob ()
virtual void produce (edm::Event &, const edm::EventSetup &)
void producePFCandColl (edm::Event &, const std::vector< reco::Particle::LorentzVector > *toBeAdded)
void produceTrackColl (edm::Event &, const std::vector< reco::Particle::LorentzVector > *toBeAdded)

Private Attributes

edm::InputTag _selectedMuons
edm::InputTag _tracks
bool _useCombinedCandidate

Detailed Description

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

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

Definition at line 50 of file ZmumuPFEmbedder.cc.


Constructor & Destructor Documentation

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

Definition at line 81 of file ZmumuPFEmbedder.cc.

  : _tracks(iConfig.getParameter<edm::InputTag>("tracks")),
    _selectedMuons(iConfig.getParameter<edm::InputTag>("selectedMuons")),
    _useCombinedCandidate(iConfig.getUntrackedParameter<bool>("useCombinedCandidate", false))
{

   //register your products
   // produces< std::vector< reco::Muon >  >("zMusExtracted"); // 
   produces<reco::TrackCollection>("tracks");
   produces< std::vector< reco::PFCandidate >  >("pfCands");

   
}
ZmumuPFEmbedder::~ZmumuPFEmbedder ( )

Definition at line 95 of file ZmumuPFEmbedder.cc.

{
 
   // do anything here that needs to be done at desctruction time
   // (e.g. close files, deallocate resources etc.)

}

Member Function Documentation

void ZmumuPFEmbedder::beginJob ( void  ) [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 213 of file ZmumuPFEmbedder.cc.

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

Reimplemented from edm::EDProducer.

Definition at line 219 of file ZmumuPFEmbedder.cc.

                        {
}
void ZmumuPFEmbedder::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDProducer.

Definition at line 110 of file ZmumuPFEmbedder.cc.

References _selectedMuons, _useCombinedCandidate, edm::Event::getByLabel(), UserOptions_cff::idx, producePFCandColl(), and produceTrackColl().

{
   std::vector< reco::Particle::LorentzVector > toBeAdded;
   
   if (_useCombinedCandidate)
   {
      edm::Handle< std::vector< reco::CompositeCandidate > > combCandidatesHandle;
      if (iEvent.getByLabel(_selectedMuons, combCandidatesHandle) && combCandidatesHandle->size()>0)
         for (size_t idx = 0; idx < combCandidatesHandle->at(0).numberOfDaughters(); ++idx)                     // use only the first combined candidate
            toBeAdded.push_back(combCandidatesHandle->at(0).daughter(idx)->p4());
   }
   else
   {
      edm::Handle< edm::View< reco::Muon > > selectedZMuonsHandle;
      if (iEvent.getByLabel(_selectedMuons, selectedZMuonsHandle))
        for (size_t idx = 0; idx < selectedZMuonsHandle->size(); ++idx)
          toBeAdded.push_back(selectedZMuonsHandle->at(idx).p4());
   }

   if (toBeAdded.size() == 0)
      return;

   producePFCandColl(iEvent, &toBeAdded);
   produceTrackColl(iEvent, &toBeAdded);
}
void ZmumuPFEmbedder::producePFCandColl ( edm::Event iEvent,
const std::vector< reco::Particle::LorentzVector > *  toBeAdded 
) [private]

Definition at line 137 of file ZmumuPFEmbedder.cc.

References abs, deltaR(), edm::Event::getByLabel(), and edm::Event::put().

Referenced by produce().

{
   edm::Handle<reco::PFCandidateCollection> pfIn;
   iEvent.getByLabel("particleFlow",pfIn);

   //std::vector< reco::Muon > toBeAdded;
   // TODO - check col size
   //reco::Muon l1 = *(toBeAdded->begin());
   //reco::Muon l2 = *(toBeAdded->rbegin());
   
   std::auto_ptr<std::vector< reco::PFCandidate > > newCol(new std::vector< reco::PFCandidate  > );   
   
   //get selected muons
   // iterate over pfcandidates, make copy if its not a selected muon
   reco::PFCandidateConstIterator it = pfIn->begin();
   reco::PFCandidateConstIterator itE = pfIn->end();

   for (;it!=itE;++it) {
     int pdg = std::abs( it->pdgId() );
     double minDR = 10;
     /* 
     double dr1 = reco::deltaR( *it, l1); 
     double dr2 = reco::deltaR( *it, l2); 
     */
     std::vector< reco::Particle::LorentzVector >::const_iterator itSelectedMu = toBeAdded->begin();
     std::vector< reco::Particle::LorentzVector >::const_iterator itSelectedMuE = toBeAdded->end();
     for (; itSelectedMu != itSelectedMuE; ++itSelectedMu ){
       double dr = reco::deltaR( *it, *itSelectedMu);
       if (dr < minDR)  minDR = dr;
     }

     //if ( pdg == 13 && (dr1 < 0.001 || dr2 < 0.002 ) ) { // it is a selected muon, do not copy
     if ( pdg == 13 && (minDR < 0.001 ) ) { // it is a selected muon, do not copy
       
       
     } else {
       newCol->push_back(*it);
     }
   }

   iEvent.put(newCol, "pfCands");
}
void ZmumuPFEmbedder::produceTrackColl ( edm::Event iEvent,
const std::vector< reco::Particle::LorentzVector > *  toBeAdded 
) [private]

Definition at line 181 of file ZmumuPFEmbedder.cc.

References _tracks, gather_cfg::cout, deltaR(), epsilon, edm::Event::getByLabel(), convertSQLiteXML::ok, and edm::Event::put().

Referenced by produce().

{
   edm::Handle<reco::TrackCollection> tks;
   iEvent.getByLabel( _tracks, tks);

   std::auto_ptr< reco::TrackCollection  > newCol(new reco::TrackCollection );

   double epsilon = 0.00001;
   unsigned int nMatched = 0;
   
   for ( reco::TrackCollection::const_iterator it = tks->begin() ; it != tks->end(); ++it) 
   {
     bool ok = true;
     for ( std::vector< reco::Particle::LorentzVector >::const_iterator itTBA = toBeAdded->begin();
                                                            itTBA != toBeAdded->end();
                                                            ++itTBA)
     {
       double dr = reco::deltaR( *it, *itTBA);
       //std::cout << "TTTT " << dr << std::endl;
       if (dr < epsilon) {
         ++ nMatched;
         ok = false;
       }
     }
     if (ok)  newCol->push_back(*it);  
   }
   if (nMatched!=toBeAdded->size() ) std::cout << "TTT ARGGGHGH " << nMatched << std::endl;

   iEvent.put(newCol, "tracks");
}

Member Data Documentation

Definition at line 63 of file ZmumuPFEmbedder.cc.

Referenced by produce().

Definition at line 62 of file ZmumuPFEmbedder.cc.

Referenced by produceTrackColl().

Definition at line 64 of file ZmumuPFEmbedder.cc.

Referenced by produce().