CMS 3D CMS Logo

RecoTauConstructor.h
Go to the documentation of this file.
1 #ifndef RecoTauTag_RecoTau_RecoTauConstructor_h
2 #define RecoTauTag_RecoTau_RecoTauConstructor_h
3 
4 /*
5  * RecoTauConstructor
6  *
7  * A generalized builder of reco::PFTau objects. Takes a variety of
8  * different collections and converts them to the proper Ref format
9  * needed for PFTau storage. Automatically sets the p4, charge, and
10  * other properties correctly. Optionally, it can determine the
11  * lead track information, and copy the gamma candidates owned by the
12  * reconstructed pi zeros into the appropriate PiZero collection.
13  *
14  * If the gammas are copied from the PiZeros, the four vector will be
15  * built using the PiZeros + Charged Hadrons. This can be different than
16  * the Gammas + Charged Hadrons, as the PiZero may have a mass hypothesis set by
17  * the RecoTauPiZeroProducer
18  *
19  * Note that the p4 of the tau is *always* set as the sum of objects in
20  * signal cone.
21  *
22  * Author: Evan K. Friis, UC Davis
23  *
24  */
25 
34 
35 #include "boost/shared_ptr.hpp"
36 #include <vector>
37 
38 namespace reco { namespace tau {
39 
41  public:
42  enum Region {
45  };
46 
47  enum ParticleType {
52  };
53 
55  RecoTauConstructor(const JetBaseRef& jetRef,
56  const edm::Handle<edm::View<reco::Candidate> >& pfCands,
57  bool copyGammasFromPiZeros = false,
61 
62  /*
63  * Code to set leading candidates. These are just wrappers about
64  * the embedded taus methods, but with the ability to convert Ptrs
65  * to Refs.
66  */
67 
69  template<typename T> void setleadChargedHadrCand(const T& cand) {
70  tau_->setleadChargedHadrCand(convertToPtr(cand));
71  }
72 
74  template<typename T> void setleadNeutralCand(const T& cand) {
75  tau_->setleadNeutralCand(convertToPtr(cand));
76  }
77 
79  template<typename T> void setleadCand(const T& cand) {
80  tau_->setleadCand(convertToPtr(cand));
81  }
82 
84  void addPFCand(Region region, ParticleType type, const CandidatePtr& ptr, bool skipAddToP4 = false);
85 
87  void reserve(Region region, ParticleType type, size_t size);
88 
89  // Add a collection of objects to a given collection
90  template<typename InputIterator>
91  void addPFCands(Region region, ParticleType type, const InputIterator& begin, const InputIterator& end)
92  {
93  for(InputIterator iter = begin; iter != end; ++iter) {
94  addPFCand(region, type, convertToPtr(*iter));
95  }
96  }
97 
99  void reserveTauChargedHadron(Region region, size_t size);
100 
103 
105  template<typename InputIterator> void addTauChargedHadrons(Region region, const InputIterator& begin, const InputIterator& end)
106  {
107  for ( InputIterator iter = begin; iter != end; ++iter ) {
108  addTauChargedHadron(region, *iter);
109  }
110  }
111 
113  void reservePiZero(Region region, size_t size);
114 
116  void addPiZero(Region region, const RecoTauPiZero& piZero);
117 
119  template<typename InputIterator> void addPiZeros(Region region, const InputIterator& begin, const InputIterator& end)
120  {
121  for ( InputIterator iter = begin; iter != end; ++iter ) {
122  addPiZero(region, *iter);
123  }
124  }
125 
126  // Build and return the associated tau
127  std::auto_ptr<reco::PFTau> get(bool setupLeadingCandidates=true);
128 
129  // Get the four vector of the signal objects added so far
130  const reco::Candidate::LorentzVector& p4() const { return p4_; }
131 
132  private:
133  typedef std::pair<Region, ParticleType> CollectionKey;
134  typedef std::map<CollectionKey, std::vector<CandidatePtr>*> CollectionMap;
135  typedef boost::shared_ptr<std::vector<CandidatePtr> > SortedListPtr;
136  typedef std::map<CollectionKey, SortedListPtr> SortedCollectionMap;
137 
139 
145 
146  // Retrieve collection associated to signal/iso and type
147  std::vector<CandidatePtr>* getCollection(Region region, ParticleType type);
148  SortedListPtr getSortedCollection(Region region, ParticleType type);
149 
150  // Sort all our collections by PT and copy them into the tau
151  void sortAndCopyIntoTau();
152 
153  // Helper functions for dealing with refs
154  CandidatePtr convertToPtr(const PFCandidatePtr& pfPtr) const;
155  CandidatePtr convertToPtr(const CandidatePtr& candPtr) const;
156 
158  std::auto_ptr<reco::PFTau> tau_;
159  CollectionMap collections_;
160 
161  // Keep sorted (by descending pt) collections
162  SortedCollectionMap sortedCollections_;
163 
164  // Keep track of the signal cone four vector in case we want it
166 };
167 } } // end reco::tau namespace
168 #endif
void addPFCand(Region region, ParticleType type, const CandidatePtr &ptr, bool skipAddToP4=false)
Append a PFCandidateRef/Ptr to a given collection.
size
Write out results.
type
Definition: HCALResponse.h:21
void addTauChargedHadron(Region region, const PFRecoTauChargedHadron &chargedHadron)
Add a ChargedHadron to the given collection.
reco::Candidate::LorentzVector p4_
void reserve(Region region, ParticleType type, size_t size)
Reserve a set amount of space for a given RefVector.
void addTauChargedHadrons(Region region, const InputIterator &begin, const InputIterator &end)
Add a list of charged hadrons to the input collection.
void setleadChargedHadrCand(const T &cand)
Set leading PFChargedHadron candidate.
std::map< CollectionKey, SortedListPtr > SortedCollectionMap
std::vector< CandidatePtr > * getCollection(Region region, ParticleType type)
void setleadNeutralCand(const T &cand)
Set leading PFGamma candidate.
void addPiZeros(Region region, const InputIterator &begin, const InputIterator &end)
Add a list of pizeros to the input collection.
const edm::Handle< edm::View< reco::Candidate > > & pfCands_
SortedCollectionMap sortedCollections_
SortedListPtr getSortedCollection(Region region, ParticleType type)
const reco::Candidate::LorentzVector & p4() const
#define end
Definition: vmac.h:39
std::pair< Region, ParticleType > CollectionKey
void addPFCands(Region region, ParticleType type, const InputIterator &begin, const InputIterator &end)
boost::shared_ptr< std::vector< CandidatePtr > > SortedListPtr
std::auto_ptr< reco::PFTau > tau_
void reserveTauChargedHadron(Region region, size_t size)
Reserve a set amount of space for the ChargedHadrons.
void reservePiZero(Region region, size_t size)
Reserve a set amount of space for the PiZeros.
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
fixed size matrix
#define begin
Definition: vmac.h:32
void setleadCand(const T &cand)
Set leading PF candidate.
void addPiZero(Region region, const RecoTauPiZero &piZero)
Add a PiZero to the given collection.
const StringObjectFunction< reco::PFTau > * signalConeSize_
std::map< CollectionKey, std::vector< CandidatePtr > * > CollectionMap
CandidatePtr convertToPtr(const PFCandidatePtr &pfPtr) const
long double T
RecoTauConstructor(const JetBaseRef &jetRef, const edm::Handle< edm::View< reco::Candidate > > &pfCands, bool copyGammasFromPiZeros=false, const StringObjectFunction< reco::PFTau > *signalConeSize=0, double minAbsPhotonSumPt_insideSignalCone=2.5, double minRelPhotonSumPt_insideSignalCone=0., double minAbsPhotonSumPt_outsideSignalCone=1.e+9, double minRelPhotonSumPt_outsideSignalCone=1.e+9)
Constructor with PFCandidate Handle.