CMS 3D CMS Logo

PATCleaner.cc
Go to the documentation of this file.
1 
26 
27 #include <memory>
28 #include <vector>
29 
30 namespace pat {
31 
32  template <class PATObjType>
34  public:
35  explicit PATCleaner(const edm::ParameterSet& iConfig);
36  ~PATCleaner() override {}
37 
38  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) final;
39 
40  private:
42 
47 
49  std::vector<std::unique_ptr<OverlapTest>> overlapTests_;
50  };
51 
52 } // namespace pat
53 
54 template <class PATObjType>
56  : src_(iConfig.getParameter<edm::InputTag>("src")),
57  srcToken_(consumes<edm::View<PATObjType>>(src_)),
58  preselectionCut_(iConfig.getParameter<std::string>("preselection")),
59  finalCut_(iConfig.getParameter<std::string>("finalCut")) {
60  // pick parameter set for overlaps
61  edm::ParameterSet overlapPSet = iConfig.getParameter<edm::ParameterSet>("checkOverlaps");
62  // get all the names of the tests (all nested PSets in this PSet)
63  std::vector<std::string> overlapNames = overlapPSet.getParameterNamesForType<edm::ParameterSet>();
64  // loop on them
65  for (std::vector<std::string>::const_iterator itn = overlapNames.begin(); itn != overlapNames.end(); ++itn) {
66  // retrieve configuration
68  // skip empty parameter sets
69  if (cfg.empty())
70  continue;
71  // get the name of the algorithm to use
72  std::string algorithm = cfg.getParameter<std::string>("algorithm");
73  // create the appropriate OverlapTest
74  if (algorithm == "byDeltaR") {
75  overlapTests_.emplace_back(new pat::helper::BasicOverlapTest(*itn, cfg, consumesCollector()));
76  } else if (algorithm == "bySuperClusterSeed") {
77  overlapTests_.emplace_back(new pat::helper::OverlapBySuperClusterSeed(*itn, cfg, consumesCollector()));
78  } else {
79  throw cms::Exception("Configuration")
80  << "PATCleaner for " << src_ << ": unsupported algorithm '" << algorithm << "'\n";
81  }
82  }
83 
84  produces<std::vector<PATObjType>>();
85 }
86 
87 template <class PATObjType>
89  // Read the input. We use edm::View<> in case the input happes to be something different than a std::vector<>
91  iEvent.getByToken(srcToken_, candidates);
92 
93  // Prepare a collection for the output
94  auto output = std::make_unique<std::vector<PATObjType>>();
95 
96  // initialize the overlap tests
97  for (auto& itov : overlapTests_) {
98  itov->readInput(iEvent, iSetup);
99  }
100 
101  for (typename edm::View<PATObjType>::const_iterator it = candidates->begin(), ed = candidates->end(); it != ed;
102  ++it) {
103  // Apply a preselection to the inputs and copy them in the output
104  if (!preselectionCut_(*it))
105  continue;
106 
107  // Add it to the list and take a reference to it, so it can be modified (e.g. to set the overlaps)
108  // If at some point I'll decide to drop this item, I'll use pop_back to remove it
109  output->push_back(*it);
110  PATObjType& obj = output->back();
111 
112  // Look for overlaps
113  bool badForOverlap = false;
114  for (auto& itov : overlapTests_) {
116  bool hasOverlap = itov->fillOverlapsForItem(obj, overlaps);
117  if (hasOverlap && itov->requireNoOverlaps()) {
118  badForOverlap = true; // mark for discarding
119  break; // no point in checking the others, as this item will be discarded
120  }
121  obj.setOverlaps(itov->name(), overlaps);
122  }
123  if (badForOverlap) {
124  output->pop_back();
125  continue;
126  }
127 
128  // Apply one final selection cut
129  if (!finalCut_(obj))
130  output->pop_back();
131  }
132 
133  iEvent.put(std::move(output));
134 }
135 
137 namespace pat {
146 } // namespace pat
147 using namespace pat;
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const Selector finalCut_
Definition: PATCleaner.cc:46
pat::PATCleaner< pat::GenericParticle > PATGenericParticleCleaner
Definition: PATCleaner.cc:144
const Selector preselectionCut_
Definition: PATCleaner.cc:45
pat::PATCleaner< pat::MET > PATMETCleaner
Definition: PATCleaner.cc:143
PAT Cleaner module for PAT Objects.
Definition: PATCleaner.cc:33
Definition: HeavyIon.h:7
pat::PATCleaner< pat::Tau > PATTauCleaner
Definition: PATCleaner.cc:140
int iEvent
Definition: GenABIO.cc:224
std::vector< std::unique_ptr< OverlapTest > > overlapTests_
Definition: PATCleaner.cc:49
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) final
Definition: PATCleaner.cc:88
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:179
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::InputTag src_
Definition: PATCleaner.cc:43
pat::PATCleaner< pat::PFParticle > PATPFParticleCleaner
Definition: PATCleaner.cc:145
pat::PATCleaner< pat::Electron > PATElectronCleaner
Definition: PATCleaner.cc:138
pat::PATCleaner< pat::Jet > PATJetCleaner
Definition: PATCleaner.cc:142
pat::PATCleaner< pat::Muon > PATMuonCleaner
Definition: PATCleaner.cc:139
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
pat::helper::OverlapTest OverlapTest
Definition: PATCleaner.cc:48
~PATCleaner() override
Definition: PATCleaner.cc:36
PATCleaner(const edm::ParameterSet &iConfig)
Definition: PATCleaner.cc:55
pat::PATCleaner< pat::Photon > PATPhotonCleaner
Definition: PATCleaner.cc:141
const edm::EDGetTokenT< edm::View< PATObjType > > srcToken_
Definition: PATCleaner.cc:44
def move(src, dest)
Definition: eostools.py:511
StringCutObjectSelector< PATObjType > Selector
Definition: PATCleaner.cc:41