CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 <functional>
14 #include <memory>
15 
17 
26 
31 
32 namespace reco {
33  namespace tau {
34 
35  namespace {
36  // Apply a hypothesis on the mass of the strips.
37  math::XYZTLorentzVector applyMassConstraint(const math::XYZTLorentzVector& vec, double mass) {
38  double factor = sqrt(vec.energy() * vec.energy() - mass * mass) / vec.P();
39  return math::XYZTLorentzVector(vec.px() * factor, vec.py() * factor, vec.pz() * factor, vec.energy());
40  }
41  } // namespace
42 
44  public:
47  // Return type is unique_ptr<PiZeroVector>
48  return_type operator()(const reco::Jet& jet) const override;
49  // Hook to update PV information
50  void beginEvent() override;
51 
52  private:
53  std::unique_ptr<RecoTauQualityCuts> qcuts_;
55 
56  std::vector<int> inputParticleIds_; //type of candidates to clusterize
57  double etaAssociationDistance_; //eta Clustering Association Distance
58  double phiAssociationDistance_; //phi Clustering Association Distance
59 
60  // Parameters for build strip combinations
64 
66  };
67 
69  : RecoTauPiZeroBuilderPlugin(pset, std::move(iC)),
70  qcuts_(new RecoTauQualityCuts(pset.getParameterSet("qualityCuts").getParameterSet("signalQualityCuts"))),
71  vertexAssociator_(pset.getParameter<edm::ParameterSet>("qualityCuts"), std::move(iC)) {
72  inputParticleIds_ = pset.getParameter<std::vector<int> >("stripCandidatesParticleIds");
73  etaAssociationDistance_ = pset.getParameter<double>("stripEtaAssociationDistance");
74  phiAssociationDistance_ = pset.getParameter<double>("stripPhiAssociationDistance");
75  combineStrips_ = pset.getParameter<bool>("makeCombinatoricStrips");
76  if (combineStrips_) {
77  maxStrips_ = pset.getParameter<int>("maxInputStrips");
78  combinatoricStripMassHypo_ = pset.getParameter<double>("stripMassWhenCombining");
79  }
80  }
81 
82  // Update the primary vertex
84 
86  // Get list of gamma candidates
87  typedef std::vector<reco::CandidatePtr> CandPtrs;
88  typedef CandPtrs::iterator CandIter;
90 
91  // Get the candidates passing our quality cuts
93  CandPtrs candsVector = qcuts_->filterCandRefs(pfCandidates(jet, inputParticleIds_));
94  //PFCandPtrs candsVector = qcuts_->filterCandRefs(pfGammas(jet));
95 
96  // Convert to stl::list to allow fast deletions
97  std::list<reco::CandidatePtr> cands;
98  cands.insert(cands.end(), candsVector.begin(), candsVector.end());
99 
100  while (!cands.empty()) {
101  // Seed this new strip, and delete it from future strips
102  CandidatePtr seed = cands.front();
103  cands.pop_front();
104 
105  // Add a new candidate to our collection using this seed
106  auto strip = std::make_unique<RecoTauPiZero>(*seed, RecoTauPiZero::kStrips);
107  strip->addDaughter(seed);
108 
109  // Find all other objects in the strip
110  auto stripCand = cands.begin();
111  while (stripCand != cands.end()) {
112  if (fabs(strip->eta() - (*stripCand)->eta()) < etaAssociationDistance_ &&
113  fabs(deltaPhi(*strip, **stripCand)) < phiAssociationDistance_) {
114  // Add candidate to strip
115  strip->addDaughter(*stripCand);
116  // Update the strips four momenta
117  p4Builder_.set(*strip);
118  // Delete this candidate from future strips and move on to
119  // the next potential candidate
120  stripCand = cands.erase(stripCand);
121  } else {
122  // This candidate isn't compatabile - just move to the next candidate
123  ++stripCand;
124  }
125  }
126  // Update the vertex
127  if (strip->daughterPtr(0).isNonnull())
128  strip->setVertex(strip->daughterPtr(0)->vertex());
129  output.emplace_back(strip.release());
130  }
131 
132  // Check if we want to combine our strips
133  if (combineStrips_ && output.size() > 1) {
134  PiZeroVector stripCombinations;
135  // Sort the output by descending pt
136  std::sort(output.begin(), output.end(), [&](auto& arg1, auto& arg2) { return arg1->pt() > arg2->pt(); });
137  // Get the end of interesting set of strips to try and combine
138  PiZeroVector::const_iterator end_iter = takeNElements(output.begin(), output.end(), maxStrips_);
139 
140  // Look at all the combinations
141  for (PiZeroVector::const_iterator firstIter = output.begin(); firstIter != end_iter - 1; ++firstIter) {
142  for (PiZeroVector::const_iterator secondIter = firstIter + 1; secondIter != end_iter; ++secondIter) {
143  auto const& first = *firstIter;
144  auto const& second = *secondIter;
145  Candidate::LorentzVector firstP4 = first->p4();
146  Candidate::LorentzVector secondP4 = second->p4();
147  // If we assume a certain mass for each strip apply it here.
148  firstP4 = applyMassConstraint(firstP4, combinatoricStripMassHypo_);
149  secondP4 = applyMassConstraint(secondP4, combinatoricStripMassHypo_);
150  Candidate::LorentzVector totalP4 = firstP4 + secondP4;
151  // Make our new combined strip
152  auto combinedStrips =
153  std::make_unique<RecoTauPiZero>(0,
154  totalP4,
155  Candidate::Point(0, 0, 0),
156  //111, 10001, true, RecoTauPiZero::kCombinatoricStrips));
157  111,
158  10001,
159  true,
161 
162  // Now loop over the strip members
163  for (auto const& gamma : first->daughterPtrVector()) {
164  combinedStrips->addDaughter(gamma);
165  }
166  for (auto const& gamma : second->daughterPtrVector()) {
167  combinedStrips->addDaughter(gamma);
168  }
169  // Update the vertex
170  if (combinedStrips->daughterPtr(0).isNonnull())
171  combinedStrips->setVertex(combinedStrips->daughterPtr(0)->vertex());
172  // Add to our collection of combined strips
173  stripCombinations.emplace_back(combinedStrips.release());
174  }
175  }
176  // When done doing all the combinations, add the combined strips to the output.
177  std::move(stripCombinations.begin(), stripCombinations.end(), std::back_inserter(output));
178  }
179 
180  return output;
181  }
182  } // namespace tau
183 } // namespace reco
184 
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
std::vector< CandidatePtr > pfCandidates(const Jet &jet, int particleId, bool sort=true)
InputIterator takeNElements(const InputIterator &begin, const InputIterator &end, size_t N)
Base class for all types of Jets.
Definition: Jet.h:20
ParameterSet const & getParameterSet(ParameterSetID const &id)
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
T sqrt(T t)
Definition: SSEVec.h:19
def move
Definition: eostools.py:511
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< std::unique_ptr< RecoTauPiZero > > PiZeroVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
reco::VertexRef associatedVertex(const Jet &jet) const
math::XYZPoint Point
point in the space
Definition: Candidate.h:40
#define DEFINE_EDM_PLUGIN(factory, type, name)
void set(reco::Candidate &c) const
set up a candidate
std::unique_ptr< RecoTauQualityCuts > qcuts_
return_type operator()(const reco::Jet &jet) const override
Build a collection of piZeros from objects in the input jet.
CandPtrs::iterator CandIter