CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
39 
41 template < class Top, class Bottom>
42  class TopProjectorFwdPtrOverlap : public std::unary_function<edm::FwdPtr<Top>, bool > {
43 
44  public:
47 
48 
50 
51  explicit TopProjectorFwdPtrOverlap(edm::ParameterSet const & iConfig ){ bottom_ = 0;}
52 
53  inline void setBottom(BottomFwdPtr const & bottom ) { bottom_ = &bottom; }
54 
55  bool operator() ( TopFwdPtr const & top ) const{
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 =
62  (topFwdGood && bottomFwdGood && top.ptr().refCore() == bottom_->ptr().refCore() && top.ptr().key() == bottom_->ptr().key()) ||
63  (topFwdGood && bottomBckGood && top.ptr().refCore() == bottom_->backPtr().refCore() && top.ptr().key() == bottom_->backPtr().key()) ||
64  (topBckGood && bottomFwdGood && top.backPtr().refCore() == bottom_->ptr().refCore() && top.backPtr().key() == bottom_->ptr().key()) ||
65  (topBckGood && bottomBckGood && top.backPtr().refCore() == bottom_->backPtr().refCore() && top.backPtr().key() == bottom_->backPtr().key())
66  ;
67  if ( !matched ) {
68  for ( unsigned isource = 0; isource < top->numberOfSourceCandidatePtrs(); ++isource ) {
69  reco::CandidatePtr const & topSrcPtr = top->sourceCandidatePtr(isource);
70  bool topSrcGood = topSrcPtr.isNonnull() && topSrcPtr.isAvailable();
71  if ( (topSrcGood && bottomFwdGood && topSrcPtr.refCore() == bottom_->ptr().refCore() && topSrcPtr.key() == bottom_->ptr().key())||
72  (topSrcGood && bottomBckGood && topSrcPtr.refCore() == bottom_->backPtr().refCore() && topSrcPtr.key() == bottom_->backPtr().key())
73  ) {
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() && bottomSrcPtr.key() == top.ptr().key() )||
84  (topBckGood && bottomSrcGood && bottomSrcPtr.refCore() == top.backPtr().refCore() && bottomSrcPtr.key() == top.backPtr().key() )
85  ) {
86  matched = true;
87  break;
88  }
89  }
90  }
91 
92  return matched;
93 
94  }
95 
96  protected :
98 
99 };
100 
101 
103 template < class Top, class Bottom>
104  class TopProjectorDeltaROverlap : public std::unary_function<edm::FwdPtr<Top>, bool > {
105 
106  public:
109 
112  deltaR2_( config.getParameter<double>("deltaR") ),
113  bottom_(0),bottomCPtr_(0),botEta_(-999.f),botPhi_(0.f)
114  {deltaR2_*=deltaR2_;}
115 
116 
117  inline void setBottom(BottomFwdPtr const & bottom ) {
118  bottom_ = &bottom; bottomCPtr_=&**bottom_;
119  botEta_ = bottomCPtr_->eta();
120  botPhi_ = bottomCPtr_->phi();
121  }
122 
123  bool operator() ( TopFwdPtr const & top ) const{
124  const Top& oTop = *top; float topEta = oTop.eta(); float topPhi = oTop.phi();
125  bool matched = reco::deltaR2( topEta, topPhi, botEta_, botPhi_) < deltaR2_;
126  return matched;
127  }
128 
129  protected :
130  double deltaR2_;
132  const Bottom* bottomCPtr_;
134 };
135 
136 template< class Top, class Bottom, class Matcher = TopProjectorFwdPtrOverlap<Top,Bottom> >
138 
139  public:
140 
141  typedef std::vector<Top> TopCollection;
144  typedef std::vector<TopFwdPtr> TopFwdPtrCollection;
146 
147  typedef std::vector<Bottom> BottomCollection;
152  typedef std::vector<BottomFwdPtr> BottomFwdPtrCollection;
154 
156 
158 
159 
160  void produce(edm::Event&, const edm::EventSetup&);
161 
162 
163  private:
165  Matcher match_;
166 
168  bool enable_;
169 
172 
175 
178 };
179 
180 
181 
182 
183 template< class Top, class Bottom, class Matcher >
185  match_(iConfig),
186  enable_(iConfig.getParameter<bool>("enable")) {
187  name_ = iConfig.getUntrackedParameter<std::string>("name","No Name");
188  inputTagTop_ = iConfig.getParameter<edm::InputTag>("topCollection");
189  inputTagBottom_ = iConfig.getParameter<edm::InputTag>("bottomCollection");
190 
191  // will produce a collection of the unmasked candidates in the
192  // bottom collection
193  produces< BottomFwdPtrCollection > ();
194 }
195 
196 
197 template< class Top, class Bottom, class Matcher >
199  const edm::EventSetup& iSetup) {
200  // get the various collections
201 
202  // Access the masking collection
203  TopFwdPtrHandle tops;
204  iEvent.getByLabel( inputTagTop_, tops );
205  std::list< TopFwdPtr > topsList;
206 
207  for ( typename TopFwdPtrCollection::const_iterator ibegin = tops->begin(),
208  iend = tops->end(), i = ibegin; i != iend; ++i ) {
209  topsList.push_back( *i );
210  }
211 
212 
213 /* if( !tops.isValid() ) { */
214 /* std::ostringstream err; */
215 /* err<<"The top collection must be supplied."<<std::endl */
216 /* <<"It is now set to : "<<inputTagTop_<<std::endl; */
217 /* edm::LogError("PFPAT")<<err.str(); */
218 /* throw cms::Exception( "MissingProduct", err.str()); */
219 /* } */
220 
221 
222 
223 
224  // Access the collection to
225  // be masked by the other ones
226  BottomFwdPtrHandle bottoms;
227  iEvent.getByLabel( inputTagBottom_, bottoms );
228 
229 /* if( !bottoms.isValid() ) { */
230 /* std::ostringstream err; */
231 /* err<<"The bottom collection must be supplied."<<std::endl */
232 /* <<"It is now set to : "<<inputTagBottom_<<std::endl; */
233 /* edm::LogError("PFPAT")<<err.str(); */
234 /* throw cms::Exception( "MissingProduct", err.str()); */
235 /* } */
236 
237 
238  /* if(verbose_) { */
239  /* const edm::Provenance& topProv = iEvent.getProvenance(tops.id()); */
240  /* const edm::Provenance& bottomProv = iEvent.getProvenance(bottoms.id()); */
241 
242  /* edm::LogDebug("TopProjection")<<"Top projector: event "<<iEvent.id().event()<<std::endl; */
243  /* edm::LogDebug("TopProjection")<<"Inputs --------------------"<<std::endl; */
244  /* edm::LogDebug("TopProjection")<<"Top : " */
245  /* <<tops.id()<<"\t"<<tops->size()<<std::endl */
246  /* <<topProv.branchDescription()<<std::endl; */
247 
248  /* for(unsigned i=0; i<tops->size(); i++) { */
249  /* TopFwdPtr top = (*tops)[i]; */
250  /* edm::LogDebug("TopProjection") << "< " << i << " " << top.key() << " : " << *top << std::endl; */
251  /* } */
252 
253 
254  /* edm::LogDebug("TopProjection")<<"Bottom : " */
255  /* <<bottoms.id()<<"\t"<<bottoms->size()<<std::endl */
256  /* <<bottomProv.branchDescription()<<std::endl; */
257 
258  /* for(unsigned i=0; i<bottoms->size(); i++) { */
259  /* BottomFwdPtr bottom = (*bottoms)[i]; */
260  /* edm::LogDebug("TopProjection") << "> " << i << " " << bottom.key() << " : " << *bottom << std::endl; */
261  /* } */
262 
263  /* } */
264 
265 
266  // output collection of FwdPtrs to objects,
267  // selected from the Bottom collection
268  std::auto_ptr< BottomFwdPtrCollection >
269  pBottomFwdPtrOutput( new BottomFwdPtrCollection );
270 
271  LogDebug("TopProjection")<<" Remaining candidates in the bottom collection ------ ";
272 
273  for(typename BottomFwdPtrCollection::const_iterator i=bottoms->begin(),
274  iend = bottoms->end(), ibegin = i; i != iend; ++i) {
275 
276  BottomFwdPtr const & bottom = *i;
277  match_.setBottom(bottom);
278  typename std::list< TopFwdPtr >::iterator found = topsList.end();
279  if ( enable_ ) {
280  found = std::find_if( topsList.begin(), topsList.end(), match_ );
281  }
282 
283  // If this is masked in the top projection, we remove it.
284  if( found != topsList.end() ) {
285  LogDebug("TopProjection")<<"X "<<i-ibegin << **i;
286  topsList.erase(found);
287  continue;
288  }
289  // otherwise, we keep it.
290  else {
291  LogDebug("TopProjection")<<"O "<<i-ibegin << **i;
292  pBottomFwdPtrOutput->push_back( bottom );
293  }
294  }
295 
296  iEvent.put( pBottomFwdPtrOutput );
297 }
298 
299 
300 #endif
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void produce(edm::Event &, const edm::EventSetup &)
Definition: TopProjector.h:198
Ptr< value_type > const & ptr() const
Definition: FwdPtr.h:119
edm::Handle< BottomFwdPtrCollection > BottomFwdPtrHandle
Definition: TopProjector.h:153
edm::FwdPtr< Bottom > BottomFwdPtr
Definition: TopProjector.h:151
std::vector< TopFwdPtr > TopFwdPtrCollection
Definition: TopProjector.h:144
const Bottom * bottomCPtr_
Definition: TopProjector.h:132
edm::Ptr< Bottom > BottomPtr
Definition: TopProjector.h:149
BottomFwdPtr const * bottom_
Definition: TopProjector.h:97
std::vector< Bottom > BottomCollection
Definition: TopProjector.h:147
void setBottom(BottomFwdPtr const &bottom)
Definition: TopProjector.h:53
edm::Handle< TopFwdPtrCollection > TopFwdPtrHandle
Definition: TopProjector.h:145
edm::FwdPtr< Top > TopFwdPtr
Definition: TopProjector.h:107
Ptr< value_type > const & backPtr() const
Definition: FwdPtr.h:120
TopProjector(const edm::ParameterSet &)
Definition: TopProjector.h:184
static const std::string Top
std::vector< Top > TopCollection
Definition: TopProjector.h:141
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:152
edm::FwdPtr< Top > TopFwdPtr
Definition: TopProjector.h:143
edm::FwdPtr< Bottom > BottomFwdPtr
Definition: TopProjector.h:46
int iEvent
Definition: GenABIO.cc:243
edm::FwdPtr< Bottom > BottomFwdPtr
Definition: TopProjector.h:108
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
bool operator()(TopFwdPtr const &top) const
Definition: TopProjector.h:123
Matcher match_
Matching method.
Definition: TopProjector.h:165
void setBottom(BottomFwdPtr const &bottom)
Definition: TopProjector.h:117
double f[11][100]
This checks a slew of possible overlaps for FwdPtr&lt;Candidate&gt; and derivatives.
Definition: TopProjector.h:42
RefCore const & refCore() const
Definition: Ptr.h:173
bool operator()(TopFwdPtr const &top) const
Definition: TopProjector.h:55
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
bool enable_
enable? if not, all candidates in the bottom collection are copied to the output collection ...
Definition: TopProjector.h:168
key_type key() const
Definition: Ptr.h:169
TopProjectorFwdPtrOverlap(edm::ParameterSet const &iConfig)
Definition: TopProjector.h:51
This checks matching based on delta R.
Definition: TopProjector.h:104
edm::InputTag inputTagBottom_
input tag for the masked collection.
Definition: TopProjector.h:177
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:58
edm::Ref< BottomCollection > BottomRef
Definition: TopProjector.h:150
std::string name_
name of the top projection
Definition: TopProjector.h:171
edm::FwdPtr< Top > TopFwdPtr
Definition: TopProjector.h:45
bool isAvailable() const
Definition: Ptr.h:158
edm::InputTag inputTagTop_
input tag for the top (masking) collection
Definition: TopProjector.h:174
BottomFwdPtr const * bottom_
Definition: TopProjector.h:131
edm::Handle< std::vector< Bottom > > BottomHandle
Definition: TopProjector.h:148
edm::Handle< std::vector< Top > > TopHandle
Definition: TopProjector.h:142
std::vector< BottomFwdPtr > BottomFwdPtrCollection
Definition: TopProjector.h:152
TopProjectorDeltaROverlap(edm::ParameterSet const &config)
Definition: TopProjector.h:111