CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RecoTauPiZeroStripPlugin.cc
Go to the documentation of this file.
1 /*
2  * RecoTauPiZeroStripPlugin
3  *
4  * Merges PFGammas in a PFJet into Candidate piZeros defined as
5  * strips in eta-phi.
6  *
7  * Author: Michail Bachtis (University of Wisconsin)
8  *
9  * Code modifications: Evan Friis (UC Davis)
10  *
11  */
12 #include <algorithm>
13 #include <memory>
14 
16 
25 
30 
31 namespace reco { namespace tau {
32 
33 namespace {
34 // Apply a hypothesis on the mass of the strips.
35 math::XYZTLorentzVector applyMassConstraint(
36  const math::XYZTLorentzVector& vec,double mass) {
37  double factor = sqrt(vec.energy()*vec.energy()-mass*mass)/vec.P();
39  vec.px()*factor,vec.py()*factor,vec.pz()*factor,vec.energy());
40 }
41 }
42 
43 
45  public:
48  // Return type is auto_ptr<PiZeroVector>
49  return_type operator()(const reco::PFJet& jet) const override;
50  // Hook to update PV information
51  virtual void beginEvent() override;
52 
53  private:
56 
57  std::vector<int> inputPdgIds_; //type of candidates to clusterize
58  double etaAssociationDistance_;//eta Clustering Association Distance
59  double phiAssociationDistance_;//phi Clustering Association Distance
60 
61  // Parameters for build strip combinations
65 
67 };
68 
70  const edm::ParameterSet& pset, edm::ConsumesCollector && iC):
71  RecoTauPiZeroBuilderPlugin(pset,std::move(iC)),
72  qcuts_(pset.getParameterSet(
73  "qualityCuts").getParameterSet("signalQualityCuts")),
74  vertexAssociator_(pset.getParameter<edm::ParameterSet>("qualityCuts"),std::move(iC)) {
75  inputPdgIds_ = pset.getParameter<std::vector<int> >(
76  "stripCandidatesParticleIds");
78  "stripEtaAssociationDistance");
80  "stripPhiAssociationDistance");
81  combineStrips_ = pset.getParameter<bool>("makeCombinatoricStrips");
82  if (combineStrips_) {
83  maxStrips_ = pset.getParameter<int>("maxInputStrips");
85  pset.getParameter<double>("stripMassWhenCombining");
86  }
87 }
88 
89 // Update the primary vertex
92 }
93 
95  const reco::PFJet& jet) const {
96  // Get list of gamma candidates
97  typedef std::vector<reco::PFCandidatePtr> PFCandPtrs;
98  typedef PFCandPtrs::iterator PFCandIter;
100 
101  // Get the candidates passing our quality cuts
103  PFCandPtrs candsVector = qcuts_.filterCandRefs(pfCandidates(jet, inputPdgIds_));
104  //PFCandPtrs candsVector = qcuts_.filterCandRefs(pfGammas(jet));
105 
106  // Convert to stl::list to allow fast deletions
107  typedef std::list<reco::PFCandidatePtr> PFCandPtrList;
108  typedef std::list<reco::PFCandidatePtr>::iterator PFCandPtrListIter;
109  PFCandPtrList cands;
110  cands.insert(cands.end(), candsVector.begin(), candsVector.end());
111 
112  while (cands.size() > 0) {
113  // Seed this new strip, and delete it from future strips
114  PFCandidatePtr seed = cands.front();
115  cands.pop_front();
116 
117  // Add a new candidate to our collection using this seed
118  std::auto_ptr<RecoTauPiZero> strip(new RecoTauPiZero(
119  *seed, RecoTauPiZero::kStrips));
120  strip->addDaughter(seed);
121 
122  // Find all other objects in the strip
123  PFCandPtrListIter stripCand = cands.begin();
124  while(stripCand != cands.end()) {
125  if( fabs(strip->eta() - (*stripCand)->eta()) < etaAssociationDistance_
126  && fabs(deltaPhi(*strip, **stripCand)) < phiAssociationDistance_ ) {
127  // Add candidate to strip
128  strip->addDaughter(*stripCand);
129  // Update the strips four momenta
130  p4Builder_.set(*strip);
131  // Delete this candidate from future strips and move on to
132  // the next potential candidate
133  stripCand = cands.erase(stripCand);
134  } else {
135  // This candidate isn't compatabile - just move to the next candidate
136  ++stripCand;
137  }
138  }
139  // Update the vertex
140  if (strip->daughterPtr(0).isNonnull())
141  strip->setVertex(strip->daughterPtr(0)->vertex());
142  output.push_back(strip);
143  }
144 
145  // Check if we want to combine our strips
146  if (combineStrips_ && output.size() > 1) {
147  PiZeroVector stripCombinations;
148  // Sort the output by descending pt
149  output.sort(output.begin(), output.end(),
150  boost::bind(&RecoTauPiZero::pt, _1) >
151  boost::bind(&RecoTauPiZero::pt, _2));
152  // Get the end of interesting set of strips to try and combine
153  PiZeroVector::const_iterator end_iter = takeNElements(
154  output.begin(), output.end(), maxStrips_);
155 
156  // Look at all the combinations
157  for (PiZeroVector::const_iterator first = output.begin();
158  first != end_iter-1; ++first) {
159  for (PiZeroVector::const_iterator second = first+1;
160  second != end_iter; ++second) {
161  Candidate::LorentzVector firstP4 = first->p4();
162  Candidate::LorentzVector secondP4 = second->p4();
163  // If we assume a certain mass for each strip apply it here.
164  firstP4 = applyMassConstraint(firstP4, combinatoricStripMassHypo_);
165  secondP4 = applyMassConstraint(secondP4, combinatoricStripMassHypo_);
166  Candidate::LorentzVector totalP4 = firstP4 + secondP4;
167  // Make our new combined strip
168  std::auto_ptr<RecoTauPiZero> combinedStrips(
169  new RecoTauPiZero(0, totalP4,
170  Candidate::Point(0, 0, 0),
171  //111, 10001, true, RecoTauPiZero::kCombinatoricStrips));
172  111, 10001, true, RecoTauPiZero::kUndefined));
173 
174  // Now loop over the strip members
175  BOOST_FOREACH(const RecoTauPiZero::daughters::value_type& gamma,
176  first->daughterPtrVector()) {
177  combinedStrips->addDaughter(gamma);
178  }
179  BOOST_FOREACH(const RecoTauPiZero::daughters::value_type& gamma,
180  second->daughterPtrVector()) {
181  combinedStrips->addDaughter(gamma);
182  }
183  // Update the vertex
184  if (combinedStrips->daughterPtr(0).isNonnull())
185  combinedStrips->setVertex(combinedStrips->daughterPtr(0)->vertex());
186  // Add to our collection of combined strips
187  stripCombinations.push_back(combinedStrips);
188  }
189  }
190  // When done doing all the combinations, add the combined strips to the
191  // output.
192  output.transfer(output.end(), stripCombinations);
193  }
194 
195  return output.release();
196 }
197 }} // end namespace reco::tau
198 
201  reco::tau::RecoTauPiZeroStripPlugin, "RecoTauPiZeroStripPlugin");
T getParameter(std::string const &) const
InputIterator takeNElements(const InputIterator &begin, const InputIterator &end, size_t N)
virtual float pt() const
transverse momentum
Coll filterCandRefs(const Coll &refcoll, bool invert=false) const
Filter a ref vector of PFCandidates.
ParameterSet const & getParameterSet(ParameterSetID const &id)
std::vector< reco::PFCandidatePtr > PFCandPtrs
reco::VertexRef associatedVertex(const PFJet &jet) const
void setEvent(const edm::Event &evt)
Load the vertices from the event.
RecoTauPiZeroStripPlugin(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
Jets made from PFObjects.
Definition: PFJet.h:21
virtual void beginEvent() override
Hook called at the beginning of the event.
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
void setPV(const reco::VertexRef &vtx) const
Update the primary vertex.
T sqrt(T t)
Definition: SSEVec.h:48
return_type operator()(const reco::PFJet &jet) const override
Build a collection of piZeros from objects in the input jet.
bool first
Definition: L1TdeRCT.cc:75
Container::value_type value_type
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:12
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:41
std::auto_ptr< PiZeroVector > return_type
boost::ptr_vector< RecoTauPiZero > PiZeroVector
PFCandPtrs::iterator PFCandIter
math::XYZPoint Point
point in the space
Definition: Candidate.h:45
#define DEFINE_EDM_PLUGIN(factory, type, name)
void set(reco::Candidate &c) const
set up a candidate