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 auto_ptr<PiZeroVector>
51  return_type operator()(const reco::PFJet& jet) const override;
52  // Hook to update PV information
53  void beginEvent() override;
54 
55  private:
58 
59  std::vector<int> inputPdgIds_; //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  inputPdgIds_ = 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::PFJet& jet) const {
98  // Get list of gamma candidates
99  typedef std::vector<reco::PFCandidatePtr> PFCandPtrs;
100  typedef PFCandPtrs::iterator PFCandIter;
102 
103  // Get the candidates passing our quality cuts
105  PFCandPtrs candsVector = qcuts_.filterCandRefs(pfCandidates(jet, inputPdgIds_));
106  //PFCandPtrs candsVector = qcuts_.filterCandRefs(pfGammas(jet));
107 
108  // Convert to stl::list to allow fast deletions
109  typedef std::list<reco::PFCandidatePtr> PFCandPtrList;
110  typedef std::list<reco::PFCandidatePtr>::iterator PFCandPtrListIter;
111  PFCandPtrList 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  PFCandidatePtr seed = cands.front();
117  cands.pop_front();
118 
119  // Add a new candidate to our collection using this seed
120  std::auto_ptr<RecoTauPiZero> strip(new RecoTauPiZero(
121  *seed, RecoTauPiZero::kStrips));
122  strip->addDaughter(seed);
123 
124  // Find all other objects in the strip
125  PFCandPtrListIter 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);
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::auto_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  BOOST_FOREACH(const RecoTauPiZero::daughters::value_type& gamma,
178  first->daughterPtrVector()) {
179  combinedStrips->addDaughter(gamma);
180  }
181  BOOST_FOREACH(const RecoTauPiZero::daughters::value_type& gamma,
182  second->daughterPtrVector()) {
183  combinedStrips->addDaughter(gamma);
184  }
185  // Update the vertex
186  if (combinedStrips->daughterPtr(0).isNonnull())
187  combinedStrips->setVertex(combinedStrips->daughterPtr(0)->vertex());
188  // Add to our collection of combined strips
189  stripCombinations.push_back(combinedStrips);
190  }
191  }
192  // When done doing all the combinations, add the combined strips to the
193  // output.
194  output.transfer(output.end(), stripCombinations);
195  }
196 
197  return output.release();
198 }
199 }} // end namespace reco::tau
200 
203  reco::tau::RecoTauPiZeroStripPlugin, "RecoTauPiZeroStripPlugin");
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
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 PFCandidates.
ParameterSet const & getParameterSet(ParameterSetID const &id)
std::vector< reco::PFCandidatePtr > PFCandPtrs
reco::VertexRef associatedVertex(const PFJet &jet) const
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)
Jets made from PFObjects.
Definition: PFJet.h:21
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
return_type operator()(const reco::PFJet &jet) const override
Build a collection of piZeros from objects in the input jet.
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.
boost::ptr_vector< RecoTauPiZero > PiZeroVector
PFCandPtrs::iterator PFCandIter
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
def move(src, dest)
Definition: eostools.py:510