CMS 3D CMS Logo

TopProjector.cc
Go to the documentation of this file.
1 
31 
32 #include <iostream>
33 #include <memory>
34 #include <string>
35 
37 template <class Top, class Bottom>
39 public:
42 
43  explicit TopProjectorFwdPtrOverlap() { bottom_ = 0; }
44 
46  : bottom_(nullptr), matchByPtrDirect_(iConfig.getParameter<bool>("matchByPtrDirect")) {}
47 
48  inline void setBottom(BottomFwdPtr const& bottom) { bottom_ = &bottom; }
49 
50  bool operator()(TopFwdPtr const& top) const {
52  return top.ptr().refCore() == bottom_->ptr().refCore() && top.ptr().key() == bottom_->ptr().key();
53  bool topFwdGood = top.ptr().isNonnull() && top.ptr().isAvailable();
54  bool topBckGood = top.backPtr().isNonnull() && top.backPtr().isAvailable();
55  bool bottomFwdGood = bottom_->ptr().isNonnull() && bottom_->ptr().isAvailable();
56  bool bottomBckGood = bottom_->backPtr().isNonnull() && bottom_->backPtr().isAvailable();
57 
58  bool matched = (topFwdGood && bottomFwdGood && top.ptr().refCore() == bottom_->ptr().refCore() &&
59  top.ptr().key() == bottom_->ptr().key()) ||
60  (topFwdGood && bottomBckGood && top.ptr().refCore() == bottom_->backPtr().refCore() &&
61  top.ptr().key() == bottom_->backPtr().key()) ||
62  (topBckGood && bottomFwdGood && top.backPtr().refCore() == bottom_->ptr().refCore() &&
63  top.backPtr().key() == bottom_->ptr().key()) ||
64  (topBckGood && bottomBckGood && top.backPtr().refCore() == bottom_->backPtr().refCore() &&
65  top.backPtr().key() == bottom_->backPtr().key());
66  if (!matched) {
67  for (unsigned isource = 0; isource < top->numberOfSourceCandidatePtrs(); ++isource) {
68  reco::CandidatePtr const& topSrcPtr = top->sourceCandidatePtr(isource);
69  bool topSrcGood = topSrcPtr.isNonnull() && topSrcPtr.isAvailable();
70  if ((topSrcGood && bottomFwdGood && topSrcPtr.refCore() == bottom_->ptr().refCore() &&
71  topSrcPtr.key() == bottom_->ptr().key()) ||
72  (topSrcGood && bottomBckGood && topSrcPtr.refCore() == bottom_->backPtr().refCore() &&
73  topSrcPtr.key() == bottom_->backPtr().key())) {
74  matched = true;
75  break;
76  }
77  }
78  }
79  if (!matched) {
80  for (unsigned isource = 0; isource < (*bottom_)->numberOfSourceCandidatePtrs(); ++isource) {
81  reco::CandidatePtr const& bottomSrcPtr = (*bottom_)->sourceCandidatePtr(isource);
82  bool bottomSrcGood = bottomSrcPtr.isNonnull() && bottomSrcPtr.isAvailable();
83  if ((topFwdGood && bottomSrcGood && bottomSrcPtr.refCore() == top.ptr().refCore() &&
84  bottomSrcPtr.key() == top.ptr().key()) ||
85  (topBckGood && bottomSrcGood && bottomSrcPtr.refCore() == top.backPtr().refCore() &&
86  bottomSrcPtr.key() == top.backPtr().key())) {
87  matched = true;
88  break;
89  }
90  }
91  }
92 
93  return matched;
94  }
95 
96 protected:
98  const bool matchByPtrDirect_ = false;
99 };
100 
102 template <class Top, class Bottom>
104 public:
107 
108  explicit TopProjectorDeltaROverlap() { bottom_ = 0; }
110  : deltaR2_(config.getParameter<double>("deltaR")),
111  bottom_(nullptr),
112  bottomCPtr_(nullptr),
113  botEta_(-999.f),
114  botPhi_(0.f) {
115  deltaR2_ *= deltaR2_;
116  }
117 
118  inline void setBottom(BottomFwdPtr const& bottom) {
119  bottom_ = &bottom;
120  bottomCPtr_ = &**bottom_;
121  botEta_ = bottomCPtr_->eta();
122  botPhi_ = bottomCPtr_->phi();
123  }
124 
125  bool operator()(TopFwdPtr const& top) const {
126  const Top& oTop = *top;
127  float topEta = oTop.eta();
128  float topPhi = oTop.phi();
129  bool matched = reco::deltaR2(topEta, topPhi, botEta_, botPhi_) < deltaR2_;
130  return matched;
131  }
132 
133 protected:
134  double deltaR2_;
136  const Bottom* bottomCPtr_;
137  float botEta_, botPhi_;
138 };
139 
140 template <class Top, class Bottom, class Matcher = TopProjectorFwdPtrOverlap<Top, Bottom>>
142 public:
143  typedef std::vector<Top> TopCollection;
145  typedef std::vector<TopFwdPtr> TopFwdPtrCollection;
146 
147  typedef std::vector<Bottom> BottomCollection;
149  typedef std::vector<BottomFwdPtr> BottomFwdPtrCollection;
150 
152 
153  ~TopProjector() override = default;
154 
155  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
156 
157  void produce(edm::Event&, const edm::EventSetup&) override;
158 
159 private:
162 
164  const bool enable_;
165 
168 
171 
174 };
175 
176 template <class Top, class Bottom, class Matcher>
178  : match_(iConfig),
179  enable_(iConfig.getParameter<bool>("enable")),
180  name_(iConfig.getUntrackedParameter<std::string>("name", "No Name")),
181  tokenTop_(consumes<TopFwdPtrCollection>(iConfig.getParameter<edm::InputTag>("topCollection"))),
182  tokenBottom_(consumes<BottomFwdPtrCollection>(iConfig.getParameter<edm::InputTag>("bottomCollection"))) {
183  // will produce a collection of the unmasked candidates in the
184  // bottom collection
185  produces<BottomFwdPtrCollection>();
186 }
187 
188 template <class Top, class Bottom, class Matcher>
191  psD.add<bool>("enable");
193  psD.add<double>("deltaR");
194  psD.addUntracked<std::string>("name", "No Name");
195  psD.add<edm::InputTag>("topCollection");
196  psD.add<edm::InputTag>("bottomCollection");
198  psD.add<bool>("matchByPtrDirect", false)->setComment("fast check by ptr() only");
199  desc.addWithDefaultLabel(psD);
200 }
201 
202 template <class Top, class Bottom, class Matcher>
204  // get the various collections
205 
206  // Access the masking collection
207  auto const& tops = iEvent.get(tokenTop_);
208  std::list<TopFwdPtr> topsList;
209 
210  for (auto const& top : tops) {
211  topsList.push_back(top);
212  }
213 
214  // Access the collection to
215  // be masked by the other ones
216  auto const& bottoms = iEvent.get(tokenBottom_);
217 
218  // output collection of FwdPtrs to objects,
219  // selected from the Bottom collection
220  std::unique_ptr<BottomFwdPtrCollection> pBottomFwdPtrOutput(new BottomFwdPtrCollection);
221 
222  LogDebug("TopProjection") << " Remaining candidates in the bottom collection ------ ";
223 
224  int iB = -1;
225  for (auto const& bottom : bottoms) {
226  iB++;
227  match_.setBottom(bottom);
228  auto found = topsList.end();
229  if (enable_) {
230  found = std::find_if(topsList.begin(), topsList.end(), match_);
231  }
232 
233  // If this is masked in the top projection, we remove it.
234  if (found != topsList.end()) {
235  LogDebug("TopProjection") << "X " << iB << *bottom;
236  topsList.erase(found);
237  continue;
238  }
239  // otherwise, we keep it.
240  else {
241  LogDebug("TopProjection") << "O " << iB << *bottom;
242  pBottomFwdPtrOutput->push_back(bottom);
243  }
244  }
245 
246  iEvent.put(std::move(pBottomFwdPtrOutput));
247 }
248 
249 using namespace std;
250 using namespace edm;
251 using namespace reco;
252 
257 
261 
TopProjector< PFCandidate, PileUpPFCandidate > TPPFCandidatesOnPileUpPFCandidates
bool operator()(TopFwdPtr const &top) const
Definition: TopProjector.cc:50
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
const bool enable_
enable? if not, all candidates in the bottom collection are copied to the output collection ...
edm::FwdPtr< Bottom > BottomFwdPtr
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< TopFwdPtr > TopFwdPtrCollection
const Bottom * bottomCPtr_
BottomFwdPtr const * bottom_
Definition: TopProjector.cc:97
TopProjector< IsolatedPFCandidate, PFCandidate > TPIsolatedPFCandidatesOnPFCandidates
std::vector< Bottom > BottomCollection
Definition: config.py:1
void setBottom(BottomFwdPtr const &bottom)
Definition: TopProjector.cc:48
~TopProjector() override=default
TopProjector< PFCandidate, PFCandidate > TPPFCandidatesOnPFCandidates
bool isAvailable() const
Definition: Ptr.h:230
edm::FwdPtr< Top > TopFwdPtr
const std::string name_
name of the top projection
TopProjector(const edm::ParameterSet &)
static const std::string Top
std::vector< Top > TopCollection
void produce(edm::Event &, const edm::EventSetup &) override
edm::FwdPtr< Top > TopFwdPtr
edm::FwdPtr< Bottom > BottomFwdPtr
Definition: TopProjector.cc:41
int iEvent
Definition: GenABIO.cc:224
TopProjector< PFTau, PFJet, TopProjectorDeltaROverlap< PFTau, PFJet > > TPPFTausOnPFJetsDeltaR
edm::FwdPtr< Bottom > BottomFwdPtr
const edm::EDGetTokenT< TopFwdPtrCollection > tokenTop_
input tag for the top (masking) collection
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< BottomFwdPtrCollection > tokenBottom_
input tag for the masked collection.
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
Matcher match_
Matching method.
void setBottom(BottomFwdPtr const &bottom)
TopProjector< PFJet, PFCandidate > TPPFJetsOnPFCandidates
double f[11][100]
This checks a slew of possible overlaps for FwdPtr<Candidate> and derivatives.
Definition: TopProjector.cc:38
Ptr< value_type > const & backPtr() const
Definition: FwdPtr.h:117
Definition: value.py:1
ParameterDescriptionBase * add(U const &iLabel, T const &value)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
TopProjectorFwdPtrOverlap(edm::ParameterSet const &iConfig)
Definition: TopProjector.cc:45
This checks matching based on delta R.
RefCore const & refCore() const
Definition: Ptr.h:167
fixed size matrix
HLT enums.
key_type key() const
Definition: Ptr.h:163
edm::FwdPtr< Top > TopFwdPtr
Definition: TopProjector.cc:40
bool operator()(TopFwdPtr const &top) const
TopProjector< PFTau, PFJet > TPPFTausOnPFJets
Ptr< value_type > const & ptr() const
Definition: FwdPtr.h:116
virtual CandidatePtr sourceCandidatePtr(size_type i) const
Definition: Candidate.h:169
BottomFwdPtr const * bottom_
TopProjector< PileUpPFCandidate, PFCandidate > TPPileUpPFCandidatesOnPFCandidates
std::vector< BottomFwdPtr > BottomFwdPtrCollection
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)
TopProjectorDeltaROverlap(edm::ParameterSet const &config)