CMS 3D CMS Logo

Public Member Functions | Private Types | Private Attributes

pat::PATCleaner< PATObjType > Class Template Reference

PAT Cleaner module for PAT Objects. More...

#include <PhysicsTools/PatAlgos/interface/PATCleaner.h>

Inheritance diagram for pat::PATCleaner< PATObjType >:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 PATCleaner (const edm::ParameterSet &iConfig)
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
virtual ~PATCleaner ()

Private Types

typedef pat::helper::OverlapTest OverlapTest
typedef
StringCutObjectSelector
< PATObjType > 
Selector

Private Attributes

bool doFinalCut_
bool doPreselection_
Selector finalCut_
boost::ptr_vector< OverlapTestoverlapTests_
Selector preselectionCut_
edm::InputTag src_

Detailed Description

template<class PATObjType>
class pat::PATCleaner< PATObjType >

PAT Cleaner module for PAT Objects.

The same module is used for all collections.

Author:
Giovanni Petrucciani
Version:
Id:
PATCleaner.h,v 1.3 2010/10/20 23:08:30 wmtan Exp

Definition at line 41 of file PATCleaner.h.


Member Typedef Documentation

template<class PATObjType >
typedef pat::helper::OverlapTest pat::PATCleaner< PATObjType >::OverlapTest [private]

Definition at line 56 of file PATCleaner.h.

template<class PATObjType >
typedef StringCutObjectSelector<PATObjType> pat::PATCleaner< PATObjType >::Selector [private]

Definition at line 49 of file PATCleaner.h.


Constructor & Destructor Documentation

template<class PATObjType >
pat::PATCleaner< PATObjType >::PATCleaner ( const edm::ParameterSet iConfig) [explicit]

Definition at line 64 of file PATCleaner.h.

References algorithm(), edm::ParameterSet::empty(), Exception, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNamesForType(), pat::PATCleaner< PATObjType >::overlapTests_, and pat::PATCleaner< PATObjType >::src_.

                                                                     :
    src_(iConfig.getParameter<edm::InputTag>("src")),
    preselectionCut_(iConfig.getParameter<std::string>("preselection")),
    finalCut_(iConfig.getParameter<std::string>("finalCut"))
{
    // pick parameter set for overlaps
    edm::ParameterSet overlapPSet = iConfig.getParameter<edm::ParameterSet>("checkOverlaps");
    // get all the names of the tests (all nested PSets in this PSet)
    std::vector<std::string> overlapNames = overlapPSet.getParameterNamesForType<edm::ParameterSet>();
    // loop on them
    for (std::vector<std::string>::const_iterator itn = overlapNames.begin(); itn != overlapNames.end(); ++itn) {
        // retrieve configuration
        edm::ParameterSet cfg = overlapPSet.getParameter<edm::ParameterSet>(*itn);
        // skip empty parameter sets
        if (cfg.empty()) continue; 
        // get the name of the algorithm to use
        std::string algorithm = cfg.getParameter<std::string>("algorithm");
        // create the appropriate OverlapTest
        if (algorithm == "byDeltaR") {
            overlapTests_.push_back(new pat::helper::BasicOverlapTest(*itn, cfg));
        } else if (algorithm == "bySuperClusterSeed") {
            overlapTests_.push_back(new pat::helper::OverlapBySuperClusterSeed(*itn, cfg));
        } else {
            throw cms::Exception("Configuration") << "PATCleaner for " << src_ << ": unsupported algorithm '" << algorithm << "'\n";
        }
    }
        

    produces<std::vector<PATObjType> >();
}
template<class PATObjType >
virtual pat::PATCleaner< PATObjType >::~PATCleaner ( ) [inline, virtual]

Definition at line 44 of file PATCleaner.h.

{}

Member Function Documentation

template<class PATObjType >
void pat::PATCleaner< PATObjType >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 97 of file PATCleaner.h.

References edm::Event::getByLabel(), VarParsing::obj, convertSQLitetoXML_cfg::output, analyzePatCleaning_cfg::overlaps, and edm::Event::put().

                                                                                  {

  // Read the input. We use edm::View<> in case the input happes to be something different than a std::vector<>
  edm::Handle<edm::View<PATObjType> > candidates;
  iEvent.getByLabel(src_, candidates);

  // Prepare a collection for the output
  std::auto_ptr< std::vector<PATObjType> > output(new std::vector<PATObjType>());

  // initialize the overlap tests
  for (boost::ptr_vector<OverlapTest>::iterator itov = overlapTests_.begin(), edov = overlapTests_.end(); itov != edov; ++itov) {
    itov->readInput(iEvent,iSetup);
  }

  for (typename edm::View<PATObjType>::const_iterator it = candidates->begin(), ed = candidates->end(); it != ed; ++it) {
      // Apply a preselection to the inputs and copy them in the output
      if (!preselectionCut_(*it)) continue; 

      // Add it to the list and take a reference to it, so it can be modified (e.g. to set the overlaps)
      // If at some point I'll decide to drop this item, I'll use pop_back to remove it
      output->push_back(*it);
      PATObjType &obj = output->back();

      // Look for overlaps
      bool badForOverlap = false;
      for (boost::ptr_vector<OverlapTest>::iterator itov = overlapTests_.begin(), edov = overlapTests_.end(); itov != edov; ++itov) {
        reco::CandidatePtrVector overlaps;
        bool hasOverlap = itov->fillOverlapsForItem(obj, overlaps);
        if (hasOverlap && itov->requireNoOverlaps()) { 
            badForOverlap = true; // mark for discarding
            break; // no point in checking the others, as this item will be discarded
        }
        obj.setOverlaps(itov->name(), overlaps);
      }
      if (badForOverlap) { output->pop_back(); continue; }

      // Apply one final selection cut
      if (!finalCut_(obj)) output->pop_back();
  }

  iEvent.put(output);
}

Member Data Documentation

template<class PATObjType >
bool pat::PATCleaner< PATObjType >::doFinalCut_ [private]

Definition at line 52 of file PATCleaner.h.

template<class PATObjType >
bool pat::PATCleaner< PATObjType >::doPreselection_ [private]

Definition at line 52 of file PATCleaner.h.

template<class PATObjType >
Selector pat::PATCleaner< PATObjType >::finalCut_ [private]

Definition at line 54 of file PATCleaner.h.

template<class PATObjType >
boost::ptr_vector<OverlapTest> pat::PATCleaner< PATObjType >::overlapTests_ [private]

Definition at line 58 of file PATCleaner.h.

Referenced by pat::PATCleaner< PATObjType >::PATCleaner().

template<class PATObjType >
Selector pat::PATCleaner< PATObjType >::preselectionCut_ [private]

Definition at line 53 of file PATCleaner.h.

template<class PATObjType >
edm::InputTag pat::PATCleaner< PATObjType >::src_ [private]

Definition at line 51 of file PATCleaner.h.

Referenced by pat::PATCleaner< PATObjType >::PATCleaner().