CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoTauTag/RecoTau/interface/RecoTauConstructor.h

Go to the documentation of this file.
00001 #ifndef RecoTauTag_RecoTau_RecoTauConstructor_h
00002 #define RecoTauTag_RecoTau_RecoTauConstructor_h
00003 
00004 /*
00005  * RecoTauConstructor
00006  *
00007  * A generalized builder of reco::PFTau objects.  Takes a variety of
00008  * different collections and converts them to the proper Ref format
00009  * needed for PFTau storage.  Automatically sets the p4, charge, and
00010  * other properties correctly.  Optionally, it can determine the
00011  * lead track information, and copy the gamma candidates owned by the
00012  * reconstructed pi zeros into the appropriate PiZero collection.
00013  *
00014  * If the gammas are copied from the PiZeros, the four vector will be
00015  * built using the PiZeros + Charged Hadrons.  This can be different than
00016  * the Gammas + Charged Hadrons, as the PiZero may have a mass hypothesis set by
00017  * the RecoTauPiZeroProducer
00018  *
00019  * Note that the p4 of the tau is *always* set as the sum of objects in
00020  * signal cone.
00021  *
00022  * Author: Evan K. Friis, UC Davis
00023  *
00024  * $Id $
00025  */
00026 
00027 #include "DataFormats/Common/interface/Handle.h"
00028 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00029 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00030 #include "DataFormats/TauReco/interface/PFTau.h"
00031 #include "DataFormats/JetReco/interface/PFJetCollection.h"
00032 #include "DataFormats/TauReco/interface/RecoTauPiZero.h"
00033 
00034 namespace reco { namespace tau {
00035 
00036 class RecoTauConstructor {
00037   public:
00038     enum Region {
00039       kSignal,
00040       kIsolation
00041     };
00042 
00043     enum ParticleType {
00044       kChargedHadron,
00045       kGamma,
00046       kNeutralHadron,
00047       kAll
00048     };
00049 
00051     RecoTauConstructor(const PFJetRef& jetRef,
00052         const edm::Handle<PFCandidateCollection>& pfCands,
00053         bool copyGammasFromPiZeros=false);
00054 
00055     /*
00056      * Code to set leading candidates.  These are just wrappers about
00057      * the embedded taus methods, but with the ability to convert Ptrs
00058      * to Refs.
00059      */
00060 
00062     template<typename T> void setleadPFChargedHadrCand(const T& cand) {
00063       tau_->setleadPFChargedHadrCand(convertToRef(cand));
00064     }
00065 
00067     template<typename T> void setleadPFNeutralCand(const T& cand) {
00068       tau_->setleadPFNeutralCand(convertToRef(cand));
00069     }
00070 
00072     template<typename T> void setleadPFCand(const T& cand) {
00073       tau_->setleadPFCand(convertToRef(cand));
00074     }
00075 
00077     void addPFCand(Region region, ParticleType type, const PFCandidateRef& ref);
00078 
00080     void reserve(Region region, ParticleType type, size_t size);
00081 
00082     // Add a collection of objects to the charged hadrons collection
00083     template<typename InputIterator>
00084       void addPFCands(Region region, ParticleType type,
00085           const InputIterator& begin, const InputIterator& end) {
00086         for(InputIterator iter = begin; iter != end; ++iter) {
00087           addPFCand(region, type, convertToRef(*iter));
00088         }
00089       }
00090 
00092     void reservePiZero(Region region, size_t size);
00093 
00095     void addPiZero(Region region, const RecoTauPiZero& piZero);
00096 
00098     template<typename InputIterator>
00099       void addPiZeros(Region region,
00100           const InputIterator& begin, const InputIterator& end)
00101       {
00102         for(InputIterator iter = begin; iter != end; ++iter)
00103         {
00104           addPiZero(region, *iter);
00105         }
00106       }
00107 
00108     // Build and return the associated tau
00109     std::auto_ptr<reco::PFTau> get(bool setupLeadingCandidates=true);
00110 
00111     // Get the four vector of the signal objects added so far
00112     const reco::Candidate::LorentzVector& p4() const { return p4_; }
00113 
00114 
00115   private:
00116     typedef std::pair<Region, ParticleType> CollectionKey;
00117     typedef std::map<CollectionKey, PFCandidateRefVector*> CollectionMap;
00118     typedef boost::shared_ptr<std::vector<PFCandidateRef> > SortedListPtr;
00119     typedef std::map<CollectionKey, SortedListPtr> SortedCollectionMap;
00120 
00121     bool copyGammas_;
00122     // Retrieve collection associated to signal/iso and type
00123     PFCandidateRefVector * getCollection(Region region, ParticleType type);
00124     SortedListPtr getSortedCollection(Region region, ParticleType type);
00125 
00126     // Sort all our collections by PT and copy them into the tau
00127     void sortAndCopyIntoTau();
00128 
00129     // Helper functions for dealing with refs
00130     PFCandidateRef convertToRef(const PFCandidatePtr& pfPtr) const;
00131     PFCandidateRef convertToRef(const CandidatePtr& candPtr) const;
00132     PFCandidateRef convertToRef(const PFCandidateRef& pfRef) const;
00133 
00134     const edm::Handle<PFCandidateCollection>& pfCands_;
00135     std::auto_ptr<reco::PFTau> tau_;
00136     CollectionMap collections_;
00137 
00138     // Keep sorted (by descending pt) collections
00139     SortedCollectionMap sortedCollections_;
00140 
00141     // Keep track of the signal cone four vector in case we want it
00142     reco::Candidate::LorentzVector p4_;
00143 };
00144 } } // end reco::tau namespace
00145 #endif