CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
33 
34 #include <vector>
35 
36 namespace reco { namespace tau {
37 
39  public:
40  enum Region {
43  };
44 
45  enum ParticleType {
50  };
51 
53  RecoTauConstructor(const PFJetRef& jetRef,
55  bool copyGammasFromPiZeros=false);
56 
57  /*
58  * Code to set leading candidates. These are just wrappers about
59  * the embedded taus methods, but with the ability to convert Ptrs
60  * to Refs.
61  */
62 
64  template<typename T> void setleadPFChargedHadrCand(const T& cand) {
65  tau_->setleadPFChargedHadrCand(convertToPtr(cand));
66  }
67 
69  template<typename T> void setleadPFNeutralCand(const T& cand) {
70  tau_->setleadPFNeutralCand(convertToPtr(cand));
71  }
72 
74  template<typename T> void setleadPFCand(const T& cand) {
75  tau_->setleadPFCand(convertToPtr(cand));
76  }
77 
79  void addPFCand(Region region, ParticleType type, const PFCandidateRef& ref, bool skipAddToP4 = false);
80  void addPFCand(Region region, ParticleType type, const PFCandidatePtr& ptr, bool skipAddToP4 = false);
81 
83  void reserve(Region region, ParticleType type, size_t size);
84 
85  // Add a collection of objects to a given collection
86  template<typename InputIterator>
87  void addPFCands(Region region, ParticleType type, const InputIterator& begin, const InputIterator& end)
88  {
89  for(InputIterator iter = begin; iter != end; ++iter) {
90  addPFCand(region, type, convertToPtr(*iter));
91  }
92  }
93 
95  void reserveTauChargedHadron(Region region, size_t size);
96 
98  void addTauChargedHadron(Region region, const PFRecoTauChargedHadron& chargedHadron);
99 
101  template<typename InputIterator> void addTauChargedHadrons(Region region, const InputIterator& begin, const InputIterator& end)
102  {
103  for ( InputIterator iter = begin; iter != end; ++iter ) {
104  addTauChargedHadron(region, *iter);
105  }
106  }
107 
109  void reservePiZero(Region region, size_t size);
110 
112  void addPiZero(Region region, const RecoTauPiZero& piZero);
113 
115  template<typename InputIterator> void addPiZeros(Region region, const InputIterator& begin, const InputIterator& end)
116  {
117  for ( InputIterator iter = begin; iter != end; ++iter ) {
118  addPiZero(region, *iter);
119  }
120  }
121 
122  // Build and return the associated tau
123  std::auto_ptr<reco::PFTau> get(bool setupLeadingCandidates=true);
124 
125  // Get the four vector of the signal objects added so far
126  const reco::Candidate::LorentzVector& p4() const { return p4_; }
127 
128  private:
129  typedef std::pair<Region, ParticleType> CollectionKey;
130  typedef std::map<CollectionKey, std::vector<PFCandidatePtr>*> CollectionMap;
131  typedef boost::shared_ptr<std::vector<PFCandidatePtr> > SortedListPtr;
132  typedef std::map<CollectionKey, SortedListPtr> SortedCollectionMap;
133 
135  // Retrieve collection associated to signal/iso and type
136  std::vector<PFCandidatePtr>* getCollection(Region region, ParticleType type);
138 
139  // Sort all our collections by PT and copy them into the tau
140  void sortAndCopyIntoTau();
141 
142  // Helper functions for dealing with refs
143  PFCandidatePtr convertToPtr(const PFCandidatePtr& pfPtr) const;
144  PFCandidatePtr convertToPtr(const CandidatePtr& candPtr) const;
145  PFCandidatePtr convertToPtr(const PFCandidateRef& pfRef) const;
146 
148  std::auto_ptr<reco::PFTau> tau_;
150 
151  // Keep sorted (by descending pt) collections
153 
154  // Keep track of the signal cone four vector in case we want it
156 };
157 } } // end reco::tau namespace
158 #endif
type
Definition: HCALResponse.h:21
void addPFCand(Region region, ParticleType type, const PFCandidateRef &ref, bool skipAddToP4=false)
Append a PFCandidateRef/Ptr to a given collection.
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.
boost::shared_ptr< std::vector< PFCandidatePtr > > SortedListPtr
std::vector< PFCandidatePtr > * getCollection(Region region, ParticleType type)
std::map< CollectionKey, SortedListPtr > SortedCollectionMap
void addPiZeros(Region region, const InputIterator &begin, const InputIterator &end)
Add a list of pizeros to the input collection.
SortedCollectionMap sortedCollections_
const edm::Handle< PFCandidateCollection > & pfCands_
SortedListPtr getSortedCollection(Region region, ParticleType type)
const reco::Candidate::LorentzVector & p4() const
#define end
Definition: vmac.h:37
std::pair< Region, ParticleType > CollectionKey
void setleadPFCand(const T &cand)
Set leading PF candidate.
void addPFCands(Region region, ParticleType type, const InputIterator &begin, const InputIterator &end)
PFCandidatePtr convertToPtr(const PFCandidatePtr &pfPtr) const
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:41
void setleadPFChargedHadrCand(const T &cand)
Set leading PFChargedHadron candidate.
#define begin
Definition: vmac.h:30
RecoTauConstructor(const PFJetRef &jetRef, const edm::Handle< PFCandidateCollection > &pfCands, bool copyGammasFromPiZeros=false)
Constructor with PFCandidate Handle.
std::map< CollectionKey, std::vector< PFCandidatePtr > * > CollectionMap
void setleadPFNeutralCand(const T &cand)
Set leading PFGamma candidate.
void addPiZero(Region region, const RecoTauPiZero &piZero)
Add a PiZero to the given collection.
long double T
tuple size
Write out results.