CMS 3D CMS Logo

PFTopProjector.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_PFCandProducer_PFTopProjector_
00002 #define PhysicsTools_PFCandProducer_PFTopProjector_
00003 
00004 // system include files
00005 #include <iostream>
00006 #include <memory>
00007 #include <string>
00008 
00009 // user include files
00010 #include "FWCore/Framework/interface/Frameworkfwd.h"
00011 #include "FWCore/Framework/interface/EDProducer.h"
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 
00014 #include "FWCore/Framework/interface/Event.h"
00015 #include "FWCore/Framework/interface/MakerMacros.h"
00016 
00017 #include "DataFormats/Provenance/interface/ProductID.h"
00018 
00019 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00020 #include "DataFormats/TauReco/interface/PFTau.h"
00021 
00022 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00023 
00024 
00032 #include <iostream>
00033 
00034 
00035 using namespace std;
00036 
00037 class PFTopProjector : public edm::EDProducer {
00038  public:
00039 
00040   explicit PFTopProjector(const edm::ParameterSet&);
00041 
00042   ~PFTopProjector();
00043   
00044   virtual void produce(edm::Event&, const edm::EventSetup&);
00045 
00046   virtual void beginJob(const edm::EventSetup & c);
00047 
00048 
00049  private:
00050  
00054   void
00055     ptrToAncestor( reco::CandidatePtr candRef,
00056                    reco::CandidatePtrVector& ancestors,
00057                    const edm::ProductID& ancestorsID ) const;
00058 
00062   void maskAncestors( const reco::CandidatePtrVector& ancestors,
00063                       std::vector<bool>& masked ) const;
00064     
00065 
00066   template< class T, class U> 
00067     void processCollection( const edm::Handle< std::vector<T> >& handle,
00068                             const edm::Handle< std::vector<U> >& allPFCandidates ,
00069                             std::vector<bool>& masked,
00070                             const char* objectName  ) const; 
00071 
00072   template< class T >
00073     void  printAncestors( const reco::CandidatePtrVector& ancestors,
00074                           const edm::Handle< std::vector<T> >& allPFCandidates ) const;
00075 
00077   edm::InputTag   inputTagPFCandidates_;
00078  
00080   edm::InputTag   inputTagPileUpPFCandidates_;
00081 
00083   edm::InputTag   inputTagIsolatedElectrons_;
00084   
00086   edm::InputTag   inputTagIsolatedMuons_;
00087   
00089   edm::InputTag   inputTagPFJets_;
00090 
00092   edm::InputTag   inputTagPFTaus_;
00093   
00095   bool   verbose_;
00096 
00098   static const char* pfJetsOutLabel_;
00099 
00101   static const char* pfCandidatesOutLabel_;
00102   
00103 
00104 };
00105 
00106 template< class T, class U > 
00107 void PFTopProjector::processCollection( const edm::Handle< std::vector<T> >& handle,
00108                                         const edm::Handle< std::vector<U> >& allPFCandidates ,
00109                                         std::vector<bool>& masked,
00110                                         const char* objectName) const {
00111 
00112   if( handle.isValid() && allPFCandidates.isValid() ) {
00113     const std::vector<T>& collection = *handle;
00114     
00115     if(verbose_) 
00116       std::cout<<" Collection: "<<objectName
00117                <<" size = "<<collection.size()<<std::endl;
00118     
00119     for(unsigned i=0; i<collection.size(); i++) {
00120       
00121       
00122       edm::Ptr<T>   ptr( handle, i);
00123       reco::CandidatePtr basePtr( ptr );
00124  
00125       
00126       reco::CandidatePtrVector ancestors;
00127       ptrToAncestor( basePtr,
00128                      ancestors,
00129                      allPFCandidates.id() );
00130       
00131       if(verbose_) {
00132 /*      std::cout<<"\t"<<objectName<<" "<<i */
00133 /*               <<" pt,eta,phi = " */
00134 /*               <<basePtr->pt()<<"," */
00135 /*               <<basePtr->eta()<<"," */
00136 /*               <<basePtr->phi()<<std::endl; */
00137         
00138         std::cout<<"\t"<<collection[i]<<std::endl;
00139         printAncestors( ancestors, allPFCandidates );
00140       }
00141   
00142       maskAncestors( ancestors, masked );
00143     }
00144   }
00145 
00146 }
00147 
00148 
00149 template< class T >
00150 void  PFTopProjector::printAncestors( const reco::CandidatePtrVector& ancestors,
00151                                       const edm::Handle< std::vector<T> >& allPFCandidates ) const {
00152   
00153   std::vector<T> pfs = *allPFCandidates;
00154 
00155   for(unsigned i=0; i<ancestors.size(); i++) {
00156 
00157     edm::ProductID id = ancestors[i].id();
00158     assert( id == allPFCandidates.id() );
00159  
00160     unsigned index = ancestors[i].key();
00161     assert( index < pfs.size() );
00162     
00163     std::cout<<"\t\t"<<pfs[index]<<std::endl;
00164   }
00165 }
00166 
00167 
00168 
00169 
00170 #endif

Generated on Tue Jun 9 17:41:49 2009 for CMSSW by  doxygen 1.5.4