CMS 3D CMS Logo

TopProjector.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PFCandProducer_TopProjector_
2 #define PhysicsTools_PFCandProducer_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 
48  explicit TopProjectorFwdPtrOverlap(edm::ParameterSet const& iConfig) { bottom_ = nullptr; }
49 
50  inline void setBottom(BottomFwdPtr const& bottom) { bottom_ = &bottom; }
51 
52  bool operator()(TopFwdPtr const& top) const {
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 };
99 
101 template <class Top, class Bottom>
103 public:
106 
107  explicit TopProjectorDeltaROverlap() { bottom_ = 0; }
109  : deltaR2_(config.getParameter<double>("deltaR")),
110  bottom_(nullptr),
111  bottomCPtr_(nullptr),
112  botEta_(-999.f),
113  botPhi_(0.f) {
114  deltaR2_ *= deltaR2_;
115  }
116 
117  inline void setBottom(BottomFwdPtr const& bottom) {
118  bottom_ = &bottom;
119  bottomCPtr_ = &**bottom_;
120  botEta_ = bottomCPtr_->eta();
121  botPhi_ = bottomCPtr_->phi();
122  }
123 
124  bool operator()(TopFwdPtr const& top) const {
125  const Top& oTop = *top;
126  float topEta = oTop.eta();
127  float topPhi = oTop.phi();
128  bool matched = reco::deltaR2(topEta, topPhi, botEta_, botPhi_) < deltaR2_;
129  return matched;
130  }
131 
132 protected:
133  double deltaR2_;
135  const Bottom* bottomCPtr_;
136  float botEta_, botPhi_;
137 };
138 
139 template <class Top, class Bottom, class Matcher = TopProjectorFwdPtrOverlap<Top, Bottom> >
141 public:
142  typedef std::vector<Top> TopCollection;
145  typedef std::vector<TopFwdPtr> TopFwdPtrCollection;
147 
148  typedef std::vector<Bottom> BottomCollection;
153  typedef std::vector<BottomFwdPtr> BottomFwdPtrCollection;
155 
157 
158  ~TopProjector() override{};
159 
160  void produce(edm::Event&, const edm::EventSetup&) override;
161 
162 private:
165 
167  bool enable_;
168 
171 
175 
179 };
180 
181 template <class Top, class Bottom, class Matcher>
183  : match_(iConfig), enable_(iConfig.getParameter<bool>("enable")) {
184  name_ = iConfig.getUntrackedParameter<std::string>("name", "No Name");
185  inputTagTop_ = iConfig.getParameter<edm::InputTag>("topCollection");
186  tokenTop_ = consumes<TopFwdPtrCollection>(inputTagTop_);
187  inputTagBottom_ = iConfig.getParameter<edm::InputTag>("bottomCollection");
188  tokenBottom_ = consumes<BottomFwdPtrCollection>(inputTagBottom_);
189 
190  // will produce a collection of the unmasked candidates in the
191  // bottom collection
192  produces<BottomFwdPtrCollection>();
193 }
194 
195 template <class Top, class Bottom, class Matcher>
197  // get the various collections
198 
199  // Access the masking collection
200  TopFwdPtrHandle tops;
201  iEvent.getByToken(tokenTop_, tops);
202  std::list<TopFwdPtr> topsList;
203 
204  for (typename TopFwdPtrCollection::const_iterator ibegin = tops->begin(), iend = tops->end(), i = ibegin; i != iend;
205  ++i) {
206  topsList.push_back(*i);
207  }
208 
209  /* if( !tops.isValid() ) { */
210  /* std::ostringstream err; */
211  /* err<<"The top collection must be supplied."<<std::endl */
212  /* <<"It is now set to : "<<inputTagTop_<<std::endl; */
213  /* edm::LogError("PFPAT")<<err.str(); */
214  /* throw cms::Exception( "MissingProduct", err.str()); */
215  /* } */
216 
217  // Access the collection to
218  // be masked by the other ones
219  BottomFwdPtrHandle bottoms;
220  iEvent.getByToken(tokenBottom_, bottoms);
221 
222  /* if( !bottoms.isValid() ) { */
223  /* std::ostringstream err; */
224  /* err<<"The bottom collection must be supplied."<<std::endl */
225  /* <<"It is now set to : "<<inputTagBottom_<<std::endl; */
226  /* edm::LogError("PFPAT")<<err.str(); */
227  /* throw cms::Exception( "MissingProduct", err.str()); */
228  /* } */
229 
230  /* if(verbose_) { */
231  /* const edm::Provenance& topProv = iEvent.getProvenance(tops.id()); */
232  /* const edm::Provenance& bottomProv = iEvent.getProvenance(bottoms.id()); */
233 
234  /* edm::LogDebug("TopProjection")<<"Top projector: event "<<iEvent.id().event()<<std::endl; */
235  /* edm::LogDebug("TopProjection")<<"Inputs --------------------"<<std::endl; */
236  /* edm::LogDebug("TopProjection")<<"Top : " */
237  /* <<tops.id()<<"\t"<<tops->size()<<std::endl */
238  /* <<topProv.branchDescription()<<std::endl; */
239 
240  /* for(unsigned i=0; i<tops->size(); i++) { */
241  /* TopFwdPtr top = (*tops)[i]; */
242  /* edm::LogDebug("TopProjection") << "< " << i << " " << top.key() << " : " << *top << std::endl; */
243  /* } */
244 
245  /* edm::LogDebug("TopProjection")<<"Bottom : " */
246  /* <<bottoms.id()<<"\t"<<bottoms->size()<<std::endl */
247  /* <<bottomProv.branchDescription()<<std::endl; */
248 
249  /* for(unsigned i=0; i<bottoms->size(); i++) { */
250  /* BottomFwdPtr bottom = (*bottoms)[i]; */
251  /* edm::LogDebug("TopProjection") << "> " << i << " " << bottom.key() << " : " << *bottom << std::endl; */
252  /* } */
253 
254  /* } */
255 
256  // output collection of FwdPtrs to objects,
257  // selected from the Bottom collection
258  std::unique_ptr<BottomFwdPtrCollection> pBottomFwdPtrOutput(new BottomFwdPtrCollection);
259 
260  LogDebug("TopProjection") << " Remaining candidates in the bottom collection ------ ";
261 
262  for (typename BottomFwdPtrCollection::const_iterator i = bottoms->begin(), iend = bottoms->end(), ibegin = i;
263  i != iend;
264  ++i) {
265  BottomFwdPtr const& bottom = *i;
266  match_.setBottom(bottom);
267  typename std::list<TopFwdPtr>::iterator found = topsList.end();
268  if (enable_) {
269  found = std::find_if(topsList.begin(), topsList.end(), match_);
270  }
271 
272  // If this is masked in the top projection, we remove it.
273  if (found != topsList.end()) {
274  LogDebug("TopProjection") << "X " << i - ibegin << **i;
275  topsList.erase(found);
276  continue;
277  }
278  // otherwise, we keep it.
279  else {
280  LogDebug("TopProjection") << "O " << i - ibegin << **i;
281  pBottomFwdPtrOutput->push_back(bottom);
282  }
283  }
284 
285  iEvent.put(std::move(pBottomFwdPtrOutput));
286 }
287 
288 #endif
TopProjector::TopCollection
std::vector< Top > TopCollection
Definition: TopProjector.h:142
muonTagProbeFilters_cff.matched
matched
Definition: muonTagProbeFilters_cff.py:62
TopProjector::name_
std::string name_
name of the top projection
Definition: TopProjector.h:170
TopProjector::inputTagTop_
edm::InputTag inputTagTop_
input tag for the top (masking) collection
Definition: TopProjector.h:173
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
TopProjector::BottomFwdPtrHandle
edm::Handle< BottomFwdPtrCollection > BottomFwdPtrHandle
Definition: TopProjector.h:154
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:97
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
TopProjectorDeltaROverlap::TopProjectorDeltaROverlap
TopProjectorDeltaROverlap(edm::ParameterSet const &config)
Definition: TopProjector.h:108
TopProjector::enable_
bool enable_
enable? if not, all candidates in the bottom collection are copied to the output collection
Definition: TopProjector.h:167
edm::EDGetTokenT< TopFwdPtrCollection >
edm::Ptr::refCore
RefCore const & refCore() const
Definition: Ptr.h:167
TopProjector::BottomFwdPtrCollection
std::vector< BottomFwdPtr > BottomFwdPtrCollection
Definition: TopProjector.h:153
PFJet.h
TopProjector::BottomHandle
edm::Handle< std::vector< Bottom > > BottomHandle
Definition: TopProjector.h:149
TopProjector::TopHandle
edm::Handle< std::vector< Top > > TopHandle
Definition: TopProjector.h:143
EDProducer.h
TopProjectorFwdPtrOverlap::operator()
bool operator()(TopFwdPtr const &top) const
Definition: TopProjector.h:52
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::Ptr::key
key_type key() const
Definition: Ptr.h:163
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
edm::FwdPtr::ptr
Ptr< value_type > const & ptr() const
Definition: FwdPtr.h:116
TopProjector::~TopProjector
~TopProjector() override
Definition: TopProjector.h:158
TopProjectorDeltaROverlap::BottomFwdPtr
edm::FwdPtr< Bottom > BottomFwdPtr
Definition: TopProjector.h:105
TopProjectorDeltaROverlap::TopProjectorDeltaROverlap
TopProjectorDeltaROverlap()
Definition: TopProjector.h:107
edm::Ref
Definition: AssociativeIterator.h:58
CandidateFwd.h
deltaR.h
TopProjectorDeltaROverlap::bottomCPtr_
const Bottom * bottomCPtr_
Definition: TopProjector.h:135
config
Definition: config.py:1
TopProjectorDeltaROverlap::botEta_
float botEta_
Definition: TopProjector.h:136
TopProjectorFwdPtrOverlap::setBottom
void setBottom(BottomFwdPtr const &bottom)
Definition: TopProjector.h:50
TopProjector::inputTagBottom_
edm::InputTag inputTagBottom_
input tag for the masked collection.
Definition: TopProjector.h:177
MakerMacros.h
TopProjector::BottomCollection
std::vector< Bottom > BottomCollection
Definition: TopProjector.h:148
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
TopProjectorDeltaROverlap::operator()
bool operator()(TopFwdPtr const &top) const
Definition: TopProjector.h:124
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
TopProjector::TopFwdPtrCollection
std::vector< TopFwdPtr > TopFwdPtrCollection
Definition: TopProjector.h:145
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
TopProjector::BottomPtr
edm::Ptr< Bottom > BottomPtr
Definition: TopProjector.h:150
iEvent
int iEvent
Definition: GenABIO.cc:224
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:57
TopProjectorDeltaROverlap::TopFwdPtr
edm::FwdPtr< Top > TopFwdPtr
Definition: TopProjector.h:104
TopProjector
Definition: TopProjector.h:140
edm::Ptr< Candidate >
TopProjectorDeltaROverlap::deltaR2_
double deltaR2_
Definition: TopProjector.h:133
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
TopProjectorDeltaROverlap::bottom_
BottomFwdPtr const * bottom_
Definition: TopProjector.h:134
Frameworkfwd.h
PFTau.h
TopProjector::tokenTop_
edm::EDGetTokenT< TopFwdPtrCollection > tokenTop_
Definition: TopProjector.h:174
TopProjector::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: TopProjector.h:196
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:182
TopProjector::tokenBottom_
edm::EDGetTokenT< BottomFwdPtrCollection > tokenBottom_
Definition: TopProjector.h:178
TopProjector::BottomRef
edm::Ref< BottomCollection > BottomRef
Definition: TopProjector.h:151
TopProjectorFwdPtrOverlap::TopFwdPtr
edm::FwdPtr< Top > TopFwdPtr
Definition: TopProjector.h:43
edm::Ptr::isAvailable
bool isAvailable() const
Definition: Ptr.h:229
OverlapChecker.h
ParameterSet.h
TopProjectorDeltaROverlap::setBottom
void setBottom(BottomFwdPtr const &bottom)
Definition: TopProjector.h:117
edm::Event
Definition: Event.h:73
TopProjector::TopFwdPtr
edm::FwdPtr< Top > TopFwdPtr
Definition: TopProjector.h:144
TopProjectorDeltaROverlap::botPhi_
float botPhi_
Definition: TopProjector.h:136
TopProjector::BottomFwdPtr
edm::FwdPtr< Bottom > BottomFwdPtr
Definition: TopProjector.h:152
TopProjectorDeltaROverlap
This checks matching based on delta R.
Definition: TopProjector.h:102
edm::InputTag
Definition: InputTag.h:15
TopProjectorFwdPtrOverlap::TopProjectorFwdPtrOverlap
TopProjectorFwdPtrOverlap()
Definition: TopProjector.h:46
PFCandidateFwd.h
Matcher
Definition: Matcher.py:1
TopProjector::TopFwdPtrHandle
edm::Handle< TopFwdPtrCollection > TopFwdPtrHandle
Definition: TopProjector.h:146