CMS 3D CMS Logo

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