CMS 3D CMS Logo

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 
15 #include "boost/bind.hpp"
16 
18 
27 
32 
33 namespace reco { namespace tau {
34 
35 namespace {
36 // Apply a hypothesis on the mass of the strips.
37 math::XYZTLorentzVector applyMassConstraint(
38  const math::XYZTLorentzVector& vec,double mass) {
39  double factor = sqrt(vec.energy()*vec.energy()-mass*mass)/vec.P();
41  vec.px()*factor,vec.py()*factor,vec.pz()*factor,vec.energy());
42 }
43 }
44 
45 
47  public:
50  // Return type is unique_ptr<PiZeroVector>
51  return_type operator()(const reco::Jet& jet) const override;
52  // Hook to update PV information
53  void beginEvent() override;
54 
55  private:
58 
59  std::vector<int> inputParticleIds_; //type of candidates to clusterize
60  double etaAssociationDistance_;//eta Clustering Association Distance
61  double phiAssociationDistance_;//phi Clustering Association Distance
62 
63  // Parameters for build strip combinations
67 
69 };
70 
75  "qualityCuts").getParameterSet("signalQualityCuts")),
76  vertexAssociator_(pset.getParameter<edm::ParameterSet>("qualityCuts"),std::move(iC)) {
77  inputParticleIds_ = pset.getParameter<std::vector<int> >(
78  "stripCandidatesParticleIds");
80  "stripEtaAssociationDistance");
82  "stripPhiAssociationDistance");
83  combineStrips_ = pset.getParameter<bool>("makeCombinatoricStrips");
84  if (combineStrips_) {
85  maxStrips_ = pset.getParameter<int>("maxInputStrips");
87  pset.getParameter<double>("stripMassWhenCombining");
88  }
89 }
90 
91 // Update the primary vertex
94 }
95 
97  const reco::Jet& jet) const {
98  // Get list of gamma candidates
99  typedef std::vector<reco::CandidatePtr> CandPtrs;
100  typedef CandPtrs::iterator CandIter;
102 
103  // Get the candidates passing our quality cuts
105  CandPtrs candsVector = qcuts_.filterCandRefs(pfCandidates(jet, inputParticleIds_));
106  //PFCandPtrs candsVector = qcuts_.filterCandRefs(pfGammas(jet));
107 
108  // Convert to stl::list to allow fast deletions
109  typedef std::list<reco::CandidatePtr> CandPtrList;
110  typedef std::list<reco::CandidatePtr>::iterator CandPtrListIter;
111  CandPtrList cands;
112  cands.insert(cands.end(), candsVector.begin(), candsVector.end());
113 
114  while (!cands.empty()) {
115  // Seed this new strip, and delete it from future strips
116  CandidatePtr seed = cands.front();
117  cands.pop_front();
118 
119  // Add a new candidate to our collection using this seed
120  std::unique_ptr<RecoTauPiZero> strip(new RecoTauPiZero(
121  *seed, RecoTauPiZero::kStrips));
122  strip->addDaughter(seed);
123 
124  // Find all other objects in the strip
125  CandPtrListIter stripCand = cands.begin();
126  while(stripCand != cands.end()) {
127  if( fabs(strip->eta() - (*stripCand)->eta()) < etaAssociationDistance_
128  && fabs(deltaPhi(*strip, **stripCand)) < phiAssociationDistance_ ) {
129  // Add candidate to strip
130  strip->addDaughter(*stripCand);
131  // Update the strips four momenta
132  p4Builder_.set(*strip);
133  // Delete this candidate from future strips and move on to
134  // the next potential candidate
135  stripCand = cands.erase(stripCand);
136  } else {
137  // This candidate isn't compatabile - just move to the next candidate
138  ++stripCand;
139  }
140  }
141  // Update the vertex
142  if (strip->daughterPtr(0).isNonnull())
143  strip->setVertex(strip->daughterPtr(0)->vertex());
144  output.push_back(strip.get());
145  }
146 
147  // Check if we want to combine our strips
148  if (combineStrips_ && output.size() > 1) {
149  PiZeroVector stripCombinations;
150  // Sort the output by descending pt
151  output.sort(output.begin(), output.end(),
152  boost::bind(&RecoTauPiZero::pt, _1) >
153  boost::bind(&RecoTauPiZero::pt, _2));
154  // Get the end of interesting set of strips to try and combine
155  PiZeroVector::const_iterator end_iter = takeNElements(
156  output.begin(), output.end(), maxStrips_);
157 
158  // Look at all the combinations
159  for (PiZeroVector::const_iterator first = output.begin();
160  first != end_iter-1; ++first) {
161  for (PiZeroVector::const_iterator second = first+1;
162  second != end_iter; ++second) {
163  Candidate::LorentzVector firstP4 = first->p4();
164  Candidate::LorentzVector secondP4 = second->p4();
165  // If we assume a certain mass for each strip apply it here.
166  firstP4 = applyMassConstraint(firstP4, combinatoricStripMassHypo_);
167  secondP4 = applyMassConstraint(secondP4, combinatoricStripMassHypo_);
168  Candidate::LorentzVector totalP4 = firstP4 + secondP4;
169  // Make our new combined strip
170  std::unique_ptr<RecoTauPiZero> combinedStrips(
171  new RecoTauPiZero(0, totalP4,
172  Candidate::Point(0, 0, 0),
173  //111, 10001, true, RecoTauPiZero::kCombinatoricStrips));
174  111, 10001, true, RecoTauPiZero::kUndefined));
175 
176  // Now loop over the strip members
177  for(auto const& gamma : first->daughterPtrVector()) {
178  combinedStrips->addDaughter(gamma);
179  }
180  for(auto const& gamma : 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.get());
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");
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
std::vector< CandidatePtr > pfCandidates(const Jet &jet, int particleId, bool sort=true)
T getParameter(std::string const &) const
InputIterator takeNElements(const InputIterator &begin, const InputIterator &end, size_t N)
Coll filterCandRefs(const Coll &refcoll, bool invert=false) const
Filter a ref vector of Candidates.
Base class for all types of Jets.
Definition: Jet.h:20
ParameterSet const & getParameterSet(ParameterSetID const &id)
return_type operator()(const reco::Jet &jet) const override
Build a collection of piZeros from objects in the input jet.
double pt() const final
transverse momentum
void setEvent(const edm::Event &evt)
Load the vertices from the event.
RecoTauPiZeroStripPlugin(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
void beginEvent() override
Hook called at the beginning of the event.
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
std::vector< reco::CandidatePtr > CandPtrs
void setPV(const reco::VertexRef &vtx) const
Update the primary vertex.
T sqrt(T t)
Definition: SSEVec.h:18
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
std::auto_ptr< PiZeroVector > return_type
fixed size matrix
HLT enums.
reco::VertexRef associatedVertex(const Jet &jet) const
boost::ptr_vector< RecoTauPiZero > PiZeroVector
math::XYZPoint Point
point in the space
Definition: Candidate.h:41
#define DEFINE_EDM_PLUGIN(factory, type, name)
void set(reco::Candidate &c) const
set up a candidate
CandPtrs::iterator CandIter
def move(src, dest)
Definition: eostools.py:511