CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATCleaner.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PatAlgos_plugins_PATCleaner_h
2 #define PhysicsTools_PatAlgos_plugins_PATCleaner_h
3 //
4 // $Id: PATCleaner.h,v 1.4 2013/02/27 23:26:56 wmtan Exp $
5 //
6 
22 
25 
34 
36 #include <boost/ptr_container/ptr_vector.hpp>
37 
38 namespace pat {
39 
40  template<class PATObjType>
41  class PATCleaner : public edm::EDProducer {
42  public:
43  explicit PATCleaner(const edm::ParameterSet & iConfig);
44  virtual ~PATCleaner() {}
45 
46  virtual void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override;
47 
48  private:
50 
55 
57  // make a list of overlap tests (ptr_vector instead of std::vector because they're polymorphic)
58  boost::ptr_vector<OverlapTest> overlapTests_;
59  };
60 
61 } // namespace
62 
63 template <class PATObjType>
65  src_(iConfig.getParameter<edm::InputTag>("src")),
66  preselectionCut_(iConfig.getParameter<std::string>("preselection")),
67  finalCut_(iConfig.getParameter<std::string>("finalCut"))
68 {
69  // pick parameter set for overlaps
70  edm::ParameterSet overlapPSet = iConfig.getParameter<edm::ParameterSet>("checkOverlaps");
71  // get all the names of the tests (all nested PSets in this PSet)
72  std::vector<std::string> overlapNames = overlapPSet.getParameterNamesForType<edm::ParameterSet>();
73  // loop on them
74  for (std::vector<std::string>::const_iterator itn = overlapNames.begin(); itn != overlapNames.end(); ++itn) {
75  // retrieve configuration
76  edm::ParameterSet cfg = overlapPSet.getParameter<edm::ParameterSet>(*itn);
77  // skip empty parameter sets
78  if (cfg.empty()) continue;
79  // get the name of the algorithm to use
80  std::string algorithm = cfg.getParameter<std::string>("algorithm");
81  // create the appropriate OverlapTest
82  if (algorithm == "byDeltaR") {
83  overlapTests_.push_back(new pat::helper::BasicOverlapTest(*itn, cfg));
84  } else if (algorithm == "bySuperClusterSeed") {
85  overlapTests_.push_back(new pat::helper::OverlapBySuperClusterSeed(*itn, cfg));
86  } else {
87  throw cms::Exception("Configuration") << "PATCleaner for " << src_ << ": unsupported algorithm '" << algorithm << "'\n";
88  }
89  }
90 
91 
92  produces<std::vector<PATObjType> >();
93 }
94 
95 template <class PATObjType>
96 void
98 
99  // Read the input. We use edm::View<> in case the input happes to be something different than a std::vector<>
101  iEvent.getByLabel(src_, candidates);
102 
103  // Prepare a collection for the output
104  std::auto_ptr< std::vector<PATObjType> > output(new std::vector<PATObjType>());
105 
106  // initialize the overlap tests
107  for (boost::ptr_vector<OverlapTest>::iterator itov = overlapTests_.begin(), edov = overlapTests_.end(); itov != edov; ++itov) {
108  itov->readInput(iEvent,iSetup);
109  }
110 
111  for (typename edm::View<PATObjType>::const_iterator it = candidates->begin(), ed = candidates->end(); it != ed; ++it) {
112  // Apply a preselection to the inputs and copy them in the output
113  if (!preselectionCut_(*it)) continue;
114 
115  // Add it to the list and take a reference to it, so it can be modified (e.g. to set the overlaps)
116  // If at some point I'll decide to drop this item, I'll use pop_back to remove it
117  output->push_back(*it);
118  PATObjType &obj = output->back();
119 
120  // Look for overlaps
121  bool badForOverlap = false;
122  for (boost::ptr_vector<OverlapTest>::iterator itov = overlapTests_.begin(), edov = overlapTests_.end(); itov != edov; ++itov) {
124  bool hasOverlap = itov->fillOverlapsForItem(obj, overlaps);
125  if (hasOverlap && itov->requireNoOverlaps()) {
126  badForOverlap = true; // mark for discarding
127  break; // no point in checking the others, as this item will be discarded
128  }
129  obj.setOverlaps(itov->name(), overlaps);
130  }
131  if (badForOverlap) { output->pop_back(); continue; }
132 
133  // Apply one final selection cut
134  if (!finalCut_(obj)) output->pop_back();
135  }
136 
137  iEvent.put(output);
138 }
139 
140 
141 #endif
T getParameter(std::string const &) const
bool empty() const
Definition: ParameterSet.h:219
< trclass="colgroup">< tdclass="colgroup"colspan=5 > Ecal cluster collections</td ></tr >< tr >< td >< ahref="classreco_1_1BasicCluster.html"> reco::BasicCluster</a ></td >< td >< ahref="DataFormats_EgammaReco.html"> reco::BasicClusterCollection</a ></td >< td >< ahref="#"> hybridSuperClusters</a ></td >< tdclass="description"> Basic clusters reconstructed with hybrid algorithm(barrel only)</td >< td >S.Rahatlou</td ></tr >< tr >< td >< a href
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
boost::ptr_vector< OverlapTest > overlapTests_
Definition: PATCleaner.h:58
virtual ~PATCleaner()
Definition: PATCleaner.h:44
Selector finalCut_
Definition: PATCleaner.h:54
PAT Cleaner module for PAT Objects.
Definition: PATCleaner.h:41
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:195
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
bool doPreselection_
Definition: PATCleaner.h:52
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: PATCleaner.h:97
Selector preselectionCut_
Definition: PATCleaner.h:53
pat::helper::OverlapTest OverlapTest
Definition: PATCleaner.h:56
PATCleaner(const edm::ParameterSet &iConfig)
Definition: PATCleaner.h:64
StringCutObjectSelector< PATObjType > Selector
Definition: PATCleaner.h:49
edm::InputTag src_
Definition: PATCleaner.h:51