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 //
5 
21 
24 
33 
35 #include <boost/ptr_container/ptr_vector.hpp>
36 
37 namespace pat {
38 
39  template<class PATObjType>
40  class PATCleaner : public edm::EDProducer {
41  public:
42  explicit PATCleaner(const edm::ParameterSet & iConfig);
43  virtual ~PATCleaner() {}
44 
45  virtual void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override;
46 
47  private:
49 
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  srcToken_(consumes<edm::View<PATObjType> >(src_)),
67  preselectionCut_(iConfig.getParameter<std::string>("preselection")),
68  finalCut_(iConfig.getParameter<std::string>("finalCut"))
69 {
70  // pick parameter set for overlaps
71  edm::ParameterSet overlapPSet = iConfig.getParameter<edm::ParameterSet>("checkOverlaps");
72  // get all the names of the tests (all nested PSets in this PSet)
73  std::vector<std::string> overlapNames = overlapPSet.getParameterNamesForType<edm::ParameterSet>();
74  // loop on them
75  for (std::vector<std::string>::const_iterator itn = overlapNames.begin(); itn != overlapNames.end(); ++itn) {
76  // retrieve configuration
77  edm::ParameterSet cfg = overlapPSet.getParameter<edm::ParameterSet>(*itn);
78  // skip empty parameter sets
79  if (cfg.empty()) continue;
80  // get the name of the algorithm to use
81  std::string algorithm = cfg.getParameter<std::string>("algorithm");
82  // create the appropriate OverlapTest
83  if (algorithm == "byDeltaR") {
85  } else if (algorithm == "bySuperClusterSeed") {
87  } else {
88  throw cms::Exception("Configuration") << "PATCleaner for " << src_ << ": unsupported algorithm '" << algorithm << "'\n";
89  }
90  }
91 
92 
93  produces<std::vector<PATObjType> >();
94 }
95 
96 template <class PATObjType>
97 void
99 
100  // Read the input. We use edm::View<> in case the input happes to be something different than a std::vector<>
102  iEvent.getByToken(srcToken_, candidates);
103 
104  // Prepare a collection for the output
105  std::auto_ptr< std::vector<PATObjType> > output(new std::vector<PATObjType>());
106 
107  // initialize the overlap tests
108  for (boost::ptr_vector<OverlapTest>::iterator itov = overlapTests_.begin(), edov = overlapTests_.end(); itov != edov; ++itov) {
109  itov->readInput(iEvent,iSetup);
110  }
111 
112  for (typename edm::View<PATObjType>::const_iterator it = candidates->begin(), ed = candidates->end(); it != ed; ++it) {
113  // Apply a preselection to the inputs and copy them in the output
114  if (!preselectionCut_(*it)) continue;
115 
116  // Add it to the list and take a reference to it, so it can be modified (e.g. to set the overlaps)
117  // If at some point I'll decide to drop this item, I'll use pop_back to remove it
118  output->push_back(*it);
119  PATObjType &obj = output->back();
120 
121  // Look for overlaps
122  bool badForOverlap = false;
123  for (boost::ptr_vector<OverlapTest>::iterator itov = overlapTests_.begin(), edov = overlapTests_.end(); itov != edov; ++itov) {
125  bool hasOverlap = itov->fillOverlapsForItem(obj, overlaps);
126  if (hasOverlap && itov->requireNoOverlaps()) {
127  badForOverlap = true; // mark for discarding
128  break; // no point in checking the others, as this item will be discarded
129  }
130  obj.setOverlaps(itov->name(), overlaps);
131  }
132  if (badForOverlap) { output->pop_back(); continue; }
133 
134  // Apply one final selection cut
135  if (!finalCut_(obj)) output->pop_back();
136  }
137 
138  iEvent.put(output);
139 }
140 
141 
142 #endif
T getParameter(std::string const &) const
bool empty() const
Definition: ParameterSet.h:216
boost::ptr_vector< OverlapTest > overlapTests_
Definition: PATCleaner.h:58
virtual ~PATCleaner()
Definition: PATCleaner.h:43
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
Selector finalCut_
Definition: PATCleaner.h:54
PAT Cleaner module for PAT Objects.
Definition: PATCleaner.h:40
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:192
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
edm::EDGetTokenT< edm::View< PATObjType > > srcToken_
Definition: PATCleaner.h:51
bool doPreselection_
Definition: PATCleaner.h:52
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: PATCleaner.h:98
Selector preselectionCut_
Definition: PATCleaner.h:53
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
pat::helper::OverlapTest OverlapTest
Definition: PATCleaner.h:56
PATCleaner(const edm::ParameterSet &iConfig)
Definition: PATCleaner.h:64
StringCutObjectSelector< PATObjType > Selector
Definition: PATCleaner.h:48
edm::InputTag src_
Definition: PATCleaner.h:50