CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

PFCandidateMixer Class Reference

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

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

List of all members.

Public Member Functions

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

Private Member Functions

virtual void beginJob ()
virtual void endJob ()
virtual void produce (edm::Event &, const edm::EventSetup &)

Private Attributes

edm::InputTag _col1
edm::InputTag _col2
edm::InputTag _trackCol

Detailed Description

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

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

Definition at line 45 of file PFCandidateMixer.cc.


Constructor & Destructor Documentation

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

Definition at line 73 of file PFCandidateMixer.cc.

                                                                :
   _col1(iConfig.getUntrackedParameter<edm::InputTag>("col1") ),
   _col2(iConfig.getUntrackedParameter<edm::InputTag>("col2") ),
  _trackCol(iConfig.getUntrackedParameter<edm::InputTag>("trackCol") )
{

   produces< std::vector< reco::PFCandidate >  >(); 

}
PFCandidateMixer::~PFCandidateMixer ( )

Definition at line 83 of file PFCandidateMixer.cc.

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

}

Member Function Documentation

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

Reimplemented from edm::EDProducer.

Definition at line 190 of file PFCandidateMixer.cc.

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

Reimplemented from edm::EDProducer.

Definition at line 196 of file PFCandidateMixer.cc.

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

Implements edm::EDProducer.

Definition at line 98 of file PFCandidateMixer.cc.

References _col1, _col2, _trackCol, gather_cfg::cout, reco::deltaR(), deltaR(), newFWLiteAna::found, edm::Event::getByLabel(), edm::Event::getProvenance(), i, edm::Provenance::moduleLabel(), edm::Provenance::processName(), edm::Provenance::productInstanceName(), edm::Event::put(), dt_dqm_sourceclient_common_cff::reco, reco::PFCandidate::setTrackRef(), and GlobalPosition_Frontier_DevDB_cff::tag.

{
   using namespace edm;
   using namespace reco;

   Handle< std::vector<reco::Track> > trackCol;
   iEvent.getByLabel( _trackCol, trackCol);

 
   std::vector< Handle<PFCandidateCollection> > colVec; 
   Handle<PFCandidateCollection> pfIn1;
   Handle<PFCandidateCollection> pfIn2;
   iEvent.getByLabel(_col1,pfIn1);
   iEvent.getByLabel(_col2,pfIn2);
   
   colVec.push_back(pfIn1);
   colVec.push_back(pfIn2);

   std::auto_ptr<std::vector< reco::PFCandidate > > pOut(new std::vector< reco::PFCandidate  > );
   
   std::vector< Handle<PFCandidateCollection> >::iterator itCol= colVec.begin();
   std::vector< Handle<PFCandidateCollection> >::iterator itColE= colVec.end();

   int iCol = 0;
   for (;itCol!=itColE; ++itCol){
     if (!itCol->isValid()) {
       std::cout << "Whoops!" << std::endl;
     }
     PFCandidateConstIterator it = (*itCol)->begin();
     PFCandidateConstIterator itE = (*itCol)->end();
     for (;it!=itE;++it) {
       PFCandidate cand(*it);
       size_t i = 0;
       bool found = false;
       double minDR = 9999.;
       int iMinDr = -1;
       if (it->trackRef().isNonnull()) {
         for ( i = 0 ; i < trackCol->size(); ++i){
           if ( reco::deltaR( *(it->trackRef()), trackCol->at(i) )<0.001 ) {
                found = true;
                break; 
           }
           double dr = reco::deltaR( *(it->trackRef()), trackCol->at(i) );
           if ( dr < minDR) {
              iMinDr = i;
              minDR = dr;
           } 
         } 
       } 
       if ( found ){ // ref was found, overwrite in PFCand
         reco::TrackRef trref(trackCol,i);
         cand.setTrackRef(trref);
         //std::cout << " YY track ok"<<std::endl;

       } else { // keep orginall ref
         if (it->trackRef().isNonnull()) {
           std::cout << " XXXXXXXXXXX track not found " 
                 << " col " << iCol
                 << " ch " << it->charge()
                 << " id " << it->pdgId() 
                 << " pt " << it->pt() 
                 << " track: eta " << it->trackRef()->eta()
                 << " pt:  " << it->trackRef()->pt()
                 << " charge:  " << it->trackRef()->charge()
                 <<  std::endl;
           std::cout << " minDR=" << minDR << std::endl; 
           if ( iMinDr >= 0 ) {
                std::cout 
                     << " closest track pt=" << trackCol->at(iMinDr).pt()
                     << " ch=" << trackCol->at(iMinDr).charge()
                     <<  std::endl; 
           } 
           edm::Provenance prov=iEvent.getProvenance(it->trackRef().id());
           edm::InputTag tag(prov.moduleLabel(),  prov.productInstanceName(),   prov.processName());
           std::cout << " trackref in PFCand came from: "   << tag.encode() << std::endl;
 
           
         }
       }
       pOut->push_back(cand);
     }
     ++iCol;
   }
    

   iEvent.put(pOut);

   
}

Member Data Documentation

Definition at line 55 of file PFCandidateMixer.cc.

Referenced by produce().

Definition at line 56 of file PFCandidateMixer.cc.

Referenced by produce().

Definition at line 57 of file PFCandidateMixer.cc.

Referenced by produce().