CMS 3D CMS Logo

PFTopProjector Class Reference

Author:
Colin Bernet
More...

#include <PhysicsTools/PFCandProducer/interface/PFTopProjector.h>

Inheritance diagram for PFTopProjector:

edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

virtual void beginJob (const edm::EventSetup &c)
 PFTopProjector (const edm::ParameterSet &)
virtual void produce (edm::Event &, const edm::EventSetup &)
 ~PFTopProjector ()

Private Member Functions

void maskAncestors (const reco::CandidatePtrVector &ancestors, std::vector< bool > &masked) const
 ancestors is a RefToBase vector.
template<class T>
void printAncestors (const reco::CandidatePtrVector &ancestors, const edm::Handle< std::vector< T > > &allPFCandidates) const
template<class T, class U>
void processCollection (const edm::Handle< std::vector< T > > &handle, const edm::Handle< std::vector< U > > &allPFCandidates, std::vector< bool > &masked, const char *objectName) const
void ptrToAncestor (reco::CandidatePtr candRef, reco::CandidatePtrVector &ancestors, const edm::ProductID &ancestorsID) const
 fills ancestors with ptrs to the PFCandidates that in one way or another contribute to the candidate pointed to by candPtr

Private Attributes

edm::InputTag inputTagIsolatedElectrons_
 optional collection of electrons
edm::InputTag inputTagIsolatedMuons_
 optional collection of muons
edm::InputTag inputTagPFCandidates_
 ancestor PFCandidates
edm::InputTag inputTagPFJets_
 optional collection of jets
edm::InputTag inputTagPFTaus_
 optional collection of taus
edm::InputTag inputTagPileUpPFCandidates_
 optional collection of PileUpPFCandidates
bool verbose_
 verbose ?

Static Private Attributes

static const char * pfCandidatesOutLabel_ = "PFCandidates"
 label for output PFCandidates collection
static const char * pfJetsOutLabel_ = "PFJets"
 label for output PFJet collection


Detailed Description

Author:
Colin Bernet

Date:
february 2008

Definition at line 37 of file PFTopProjector.h.


Constructor & Destructor Documentation

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

Definition at line 31 of file PFTopProjector.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), inputTagIsolatedElectrons_, inputTagIsolatedMuons_, inputTagPFCandidates_, inputTagPFJets_, inputTagPFTaus_, inputTagPileUpPFCandidates_, alivecheck_mergeAndRegister::msg, pfCandidatesOutLabel_, pfJetsOutLabel_, and verbose_.

00031                                                              {
00032   
00033   inputTagPFCandidates_ 
00034     = iConfig.getParameter<InputTag>("PFCandidates");
00035 
00036   inputTagPileUpPFCandidates_ 
00037     = iConfig.getParameter<InputTag>("PileUpPFCandidates");
00038 
00039   inputTagIsolatedElectrons_ 
00040     = iConfig.getParameter<InputTag>("IsolatedElectrons");
00041 
00042   inputTagIsolatedMuons_ 
00043     = iConfig.getParameter<InputTag>("IsolatedMuons");
00044 
00045   inputTagPFJets_ 
00046     = iConfig.getParameter<InputTag>("PFJets");
00047 
00048   inputTagPFTaus_ 
00049     = iConfig.getParameter<InputTag>("PFTaus");
00050 
00051   verbose_ = 
00052     iConfig.getUntrackedParameter<bool>("verbose",false);
00053 
00054 
00055   // produces<reco::PFCandidateCollection>("PFCandidates");
00056   //  produces<reco::PFJetCollection>("PFJets");
00057 
00058   produces<reco::PFCandidateCollection>(pfCandidatesOutLabel_); 
00059   produces<reco::PFJetCollection>(pfJetsOutLabel_);
00060   
00061   if(verbose_) {    
00062     ostringstream  msg;
00063     msg<<"input PFCandidateCollection         : "
00064        <<inputTagPFCandidates_<<endl
00065        <<"input PileUpPFCandidateCollection   : "
00066        <<inputTagPileUpPFCandidates_<<endl 
00067        <<"input IsolatedPFCandidates of type muon : "
00068        <<inputTagIsolatedMuons_<<endl  
00069        <<"input IsolatedPFCandidates of type electron : "
00070        <<inputTagIsolatedElectrons_<<endl  
00071        <<"input PFJetCollection : "
00072        <<inputTagPFJets_<<endl
00073        <<"input PFTauCollection : "
00074        <<inputTagPFTaus_<<endl;  
00075     cout<<msg.str()<<endl;
00076     //     LogInfo("PFTopProjector")<<msg.str();
00077   }
00078 }

PFTopProjector::~PFTopProjector (  ) 

Definition at line 82 of file PFTopProjector.cc.

00082 { }


Member Function Documentation

void PFTopProjector::beginJob ( const edm::EventSetup c  )  [virtual]

Reimplemented from edm::EDProducer.

Definition at line 86 of file PFTopProjector.cc.

00086 { }

void PFTopProjector::maskAncestors ( const reco::CandidatePtrVector ancestors,
std::vector< bool > &  masked 
) const [private]

ancestors is a RefToBase vector.

For each object in this vector get the index and set the corresponding slot to true in the masked vector

Definition at line 280 of file PFTopProjector.cc.

References i, index, and edm::PtrVectorBase::size().

Referenced by processCollection().

00281                                                                     {
00282   
00283   for(unsigned i=0; i<ancestors.size(); i++) {
00284     unsigned index = ancestors[i].key();
00285     assert( index<masked.size() );
00286     
00287     //     if(verbose_) {
00288     //       ProductID id = ancestors[i].id();
00289     //       cout<<"\tmasking "<<index<<", ancestor "<<id<<"/"<<index<<endl;
00290     //     }
00291     masked[index] = true;
00292   }
00293 }

template<class T>
void PFTopProjector::printAncestors ( const reco::CandidatePtrVector ancestors,
const edm::Handle< std::vector< T > > &  allPFCandidates 
) const [inline, private]

Definition at line 150 of file PFTopProjector.h.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), i, edm::PtrVectorBase::id(), index, and edm::PtrVectorBase::size().

Referenced by processCollection().

00151                                                                                                {
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 }

template<class T, class U>
void PFTopProjector::processCollection ( const edm::Handle< std::vector< T > > &  handle,
const edm::Handle< std::vector< U > > &  allPFCandidates,
std::vector< bool > &  masked,
const char *  objectName 
) const [inline, private]

Definition at line 107 of file PFTopProjector.h.

References collection, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), i, edm::PtrVectorBase::id(), maskAncestors(), printAncestors(), ptr, ptrToAncestor(), and verbose_.

Referenced by produce().

00110                                                                       {
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 }

void PFTopProjector::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 89 of file PFTopProjector.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), err, edm::EventID::event(), Exception, pfpat::fetchCollection(), i, edm::Event::id(), edm::Handle< T >::id(), inputTagIsolatedElectrons_, inputTagIsolatedMuons_, inputTagPFCandidates_, inputTagPFJets_, inputTagPFTaus_, inputTagPileUpPFCandidates_, edm::Handle< T >::isValid(), pfCandidatesOutLabel_, pfJetBenchmark_cfi::pfJets, pfJetsOutLabel_, processCollection(), edm::Event::put(), and verbose_.

00090                                                        {
00091   
00092   
00093   if( verbose_)
00094     cout<<"Event -------------------- "<<iEvent.id().event()<<endl;
00095   
00096   // get the various collections
00097 
00098   // this collection is the collection of PFCandidates to 
00099   // be masked by the other ones
00100   Handle<PFCandidateCollection> pfCandidates;
00101   pfpat::fetchCollection(pfCandidates, 
00102                          inputTagPFCandidates_, 
00103                          iEvent );
00104 
00105   if( !pfCandidates.isValid() ) {
00106     std::ostringstream  err;
00107     err<<"The collection of input PFCandidates must be supplied."<<endl
00108        <<"It is now set to : "<<inputTagPFCandidates_<<endl;
00109     edm::LogError("PFPAT")<<err.str();
00110     throw cms::Exception( "MissingProduct", err.str());
00111   }
00112 
00113   edm::ProductID pfCandidatesID = pfCandidates.id();
00114 
00115   // for each object in the following collections, the 
00116   // PFTopProjector will find and mask all PFCandidates in pfCandidates
00117   // involved in the construction of this object
00118   
00119   // empty input tags can be specified, and will be recognized 
00120   // by the fetchCollection function
00121   
00122   Handle<PileUpPFCandidateCollection> pfPileUpCandidates;
00123   pfpat::fetchCollection(pfPileUpCandidates, 
00124                          inputTagPileUpPFCandidates_, 
00125                          iEvent );
00126 
00127   Handle<PFCandidateCollection> pfIsolatedElectrons;
00128   pfpat::fetchCollection(pfIsolatedElectrons, 
00129                          inputTagIsolatedElectrons_, 
00130                          iEvent );
00131 
00132   Handle<PFCandidateCollection> pfIsolatedMuons;
00133   pfpat::fetchCollection(pfIsolatedMuons, 
00134                          inputTagIsolatedMuons_, 
00135                          iEvent );
00136 
00137   Handle<PFJetCollection> pfJets;
00138   pfpat::fetchCollection(pfJets, 
00139                          inputTagPFJets_, 
00140                          iEvent );
00141 
00142   Handle<PFTauCollection> pfTaus;
00143   pfpat::fetchCollection(pfTaus, 
00144                          inputTagPFTaus_, 
00145                          iEvent );
00146 
00147   if(verbose_) {
00148     cout<<"Top projector: event "<<iEvent.id().event()<<endl;
00149     cout<<"product Ids --------------------"<<endl;
00150     cout<<"PF       :  "<<pfCandidates.id()<<endl
00151         <<"PFPU     :  "<<pfPileUpCandidates.id()<<endl
00152         <<"PFIso e  :  "<<pfIsolatedElectrons.id()<<endl
00153         <<"PFIso mu :  "<<pfIsolatedMuons.id()<<endl
00154         <<"PFJets   :  "<<pfJets.id()<<endl
00155         <<"PFTaus   :  "<<pfTaus.id()<<endl;
00156   }
00157 
00158   // output PFCandidate collection
00159   // will contain a copy of each PFCandidate in pfCandidates
00160   // that remains unmasked. 
00161   auto_ptr< reco::PFCandidateCollection > 
00162     pPFCandidateOutput( new reco::PFCandidateCollection ); 
00163   
00164   auto_ptr< reco::PFJetCollection > 
00165     pPFJetOutput( new reco::PFJetCollection ); 
00166   
00167   // mask for each PFCandidate.
00168   // at the beginning, all PFCandidates are unmasked.
00169   vector<bool> masked( pfCandidates->size(), false);
00170     
00171   assert( pfCandidates.isValid() );
00172 
00173 
00174   processCollection( pfTaus, pfCandidates, masked, 
00175                      "PFTau");
00176   processCollection( pfJets, pfCandidates, masked, 
00177                      "PFJet");
00178   processCollection( pfPileUpCandidates, pfCandidates, masked, 
00179                      "PileUpParticle");
00180   processCollection( pfIsolatedElectrons, pfCandidates, masked, 
00181                      "IsoElectron");
00182   processCollection( pfIsolatedMuons, pfCandidates, masked, 
00183                      "IsoMuon");
00184 
00185 
00186   const PFCandidateCollection& inCands = *pfCandidates;
00187 
00188   if(verbose_) 
00189     cout<<" Remaining PFCandidates ------ "<<endl;
00190   
00191   for(unsigned i=0; i<inCands.size(); i++) {
00192     
00193     if(masked[i]) {
00194       if(verbose_)
00195         cout<<"X "<<i<<" "<<inCands[i]<<endl;
00196       continue;
00197     }
00198     else {
00199       if(verbose_)
00200         cout<<"O "<<i<<" "<<inCands[i]<<endl;
00201       PFCandidatePtr motherPtr( pfCandidates, i );
00202       pPFCandidateOutput->push_back( inCands[i] );
00203       pPFCandidateOutput->back().setSourcePtr(motherPtr);
00204     }
00205   }
00206 
00207   iEvent.put( pPFCandidateOutput, pfCandidatesOutLabel_ );
00208 
00209 
00210   // now mask the jets with the taus (if the jet collection has been provided)
00211   
00212   if( pfJets.isValid() ) {
00213     vector<bool> maskedJets( pfJets->size(), false);
00214 
00215     
00216     processCollection( pfTaus, pfJets, maskedJets, 
00217                        "PFTau masking PFJets");
00218 
00219 
00220     const PFJetCollection& inJets = *pfJets;
00221     
00222     if(verbose_) 
00223       cout<<" Remaining PFJets ------ "<<endl;
00224     
00225     for(unsigned i=0; i<inJets.size(); i++) {
00226       
00227       if(maskedJets[i]) {
00228         if(verbose_)
00229           cout<<"X "<<i<<" "<<inJets[i]<<endl;
00230         continue;
00231       }
00232       else {
00233         if(verbose_)
00234           cout<<"O "<<i<<" "<<inJets[i]<<endl;
00235         pPFJetOutput->push_back( inJets[i] );
00236       }
00237     }
00238   }
00239 
00240 
00241 
00242   iEvent.put( pPFJetOutput, pfJetsOutLabel_);
00243   
00244   //   LogDebug("PFTopProjector")<<"STOP event: "<<iEvent.id().event()
00245   //                     <<" in run "<<iEvent.id().run()<<endl;
00246 }

void PFTopProjector::ptrToAncestor ( reco::CandidatePtr  candRef,
reco::CandidatePtrVector ancestors,
const edm::ProductID ancestorsID 
) const [private]

fills ancestors with ptrs to the PFCandidates that in one way or another contribute to the candidate pointed to by candPtr

Definition at line 250 of file PFTopProjector.cc.

References i, edm::Ptr< T >::id(), and edm::PtrVector< T >::push_back().

Referenced by processCollection().

00252                                                                          {
00253 
00254   
00255  
00256   unsigned nSources = candPtr->numberOfSourceCandidatePtrs();
00257 
00258 //   cout<<"going down from "<<candPtr.id()
00259 //       <<"/"<<candPtr.key()<<" #mothers "<<nSources
00260 //       <<" ancestor id "<<ancestorsID<<endl;
00261   
00262   for(unsigned i=0; i<nSources; i++) {
00263     
00264     CandidatePtr mother = candPtr->sourceCandidatePtr(i);
00265 //     cout<<"  mother id "<<mother.id()<<endl;
00266     
00267     if(  mother.id() != ancestorsID ) {
00268       // the mother is not yet at lowest level
00269       ptrToAncestor( mother, ancestors, ancestorsID);
00270     }
00271     else {
00272       // adding mother to the list of ancestors
00273       ancestors.push_back( mother ); 
00274     }
00275   }
00276 }


Member Data Documentation

edm::InputTag PFTopProjector::inputTagIsolatedElectrons_ [private]

optional collection of electrons

Definition at line 83 of file PFTopProjector.h.

Referenced by PFTopProjector(), and produce().

edm::InputTag PFTopProjector::inputTagIsolatedMuons_ [private]

optional collection of muons

Definition at line 86 of file PFTopProjector.h.

Referenced by PFTopProjector(), and produce().

edm::InputTag PFTopProjector::inputTagPFCandidates_ [private]

ancestor PFCandidates

Definition at line 77 of file PFTopProjector.h.

Referenced by PFTopProjector(), and produce().

edm::InputTag PFTopProjector::inputTagPFJets_ [private]

optional collection of jets

Definition at line 89 of file PFTopProjector.h.

Referenced by PFTopProjector(), and produce().

edm::InputTag PFTopProjector::inputTagPFTaus_ [private]

optional collection of taus

Definition at line 92 of file PFTopProjector.h.

Referenced by PFTopProjector(), and produce().

edm::InputTag PFTopProjector::inputTagPileUpPFCandidates_ [private]

optional collection of PileUpPFCandidates

Definition at line 80 of file PFTopProjector.h.

Referenced by PFTopProjector(), and produce().

const char * PFTopProjector::pfCandidatesOutLabel_ = "PFCandidates" [static, private]

label for output PFCandidates collection

Definition at line 101 of file PFTopProjector.h.

Referenced by PFTopProjector(), and produce().

const char * PFTopProjector::pfJetsOutLabel_ = "PFJets" [static, private]

label for output PFJet collection

Definition at line 98 of file PFTopProjector.h.

Referenced by PFTopProjector(), and produce().

bool PFTopProjector::verbose_ [private]

verbose ?

Definition at line 95 of file PFTopProjector.h.

Referenced by PFTopProjector(), processCollection(), and produce().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:29:50 2009 for CMSSW by  doxygen 1.5.4