CMS 3D CMS Logo

Public Member Functions | Private Attributes

SelectionStep< Object > Class Template Reference

Templated helper class to allow a selection on a certain object collection. More...

#include <DQM/Physics/interface/TopDQMHelpers.h>

List of all members.

Public Member Functions

bool select (const edm::Event &event)
 apply selection
bool select (const edm::Event &event, const edm::EventSetup &setup)
 apply selection override for jets
 SelectionStep (const edm::ParameterSet &cfg)
 default constructor
 ~SelectionStep ()
 default destructor

Private Attributes

edm::InputTag btagLabel_
 choice for b-tag as extra selection type
double btagWorkingPoint_
 choice of b-tag working point as extra selection type
edm::InputTag electronId_
 electronId as extra selection type
std::string jetCorrector_
 jet corrector as extra selection type
edm::InputTag jetIDLabel_
 jetID as an extra selection type
StringCutObjectSelector
< reco::JetID > * 
jetIDSelect_
 selection string on the jetID
int max_
int min_
 min/max for object multiplicity
StringCutObjectSelector< Object > select_
 string cut selector
edm::InputTag src_
 input collection

Detailed Description

template<typename Object>
class SelectionStep< Object >

Templated helper class to allow a selection on a certain object collection.

Templated helper class to allow a selection on a certain object collection, which may be monitored by a separate class afterwards. The class wraps and slightly extends the features of the StringCutParser to allow also to apply event based selections, according to a minimal or maximal number of elements in the collection after the object selection has been applied. It takes an edm::ParameterSet in the constructor, which should contain the following elements:

The parameters _src_ and _select_ are mandatory. The parameters _min_ and _max_ are optional. The parameters _electronId_ and _jetCorrector_ are optional. They are added to keep the possibility to apply selections on id'ed electrons or on corrected jets. They may be omitted in the PSet for simplification reasons if not needed at any time. They are not effiective for other object collections but electrons or jets. If none of the two parameters _min_ or _max_ is found in the event the select function returns true if at least one object fullfilled the requirements.

The class has one template value, which is the object collection to apply the selection on. This has to be parsed to the StringCutParser class. The function select is overrided for jets to circumvent problems with the template specialisation. Note that for MET not type1 or muon corrections are supported on reco candidates.

Definition at line 147 of file TopDQMHelpers.h.


Constructor & Destructor Documentation

template<typename Object >
SelectionStep< Object >::SelectionStep ( const edm::ParameterSet cfg)

default constructor

Definition at line 183 of file TopDQMHelpers.h.

References SelectionStep< Object >::btagLabel_, SelectionStep< Object >::btagWorkingPoint_, SelectionStep< Object >::electronId_, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), SelectionStep< Object >::jetCorrector_, SelectionStep< Object >::jetIDLabel_, SelectionStep< Object >::jetIDSelect_, SelectionStep< Object >::max_, and SelectionStep< Object >::min_.

                                                               :
  src_( cfg.getParameter<edm::InputTag>( "src"   )),
  select_( cfg.getParameter<std::string>("select")),
  jetIDSelect_(0)
{
  // construct min/max if the corresponding params
  // exist otherwise they are initialized with -1
  cfg.exists("min") ? min_= cfg.getParameter<int>("min") : min_= -1;
  cfg.exists("max") ? max_= cfg.getParameter<int>("max") : max_= -1;
  // read electron extras if they exist
  if(cfg.exists("electronId"  )){ electronId_= cfg.getParameter<edm::InputTag>("electronId"  ); }
  // read jet corrector label if it exists
  if(cfg.exists("jetCorrector")){ jetCorrector_= cfg.getParameter<std::string>("jetCorrector"); }
  // read btag information if it exists
  if(cfg.existsAs<edm::ParameterSet>("jetBTagger")){
    edm::ParameterSet jetBTagger=cfg.getParameter<edm::ParameterSet>("jetBTagger");
    btagLabel_=jetBTagger.getParameter<edm::InputTag>("label");
    btagWorkingPoint_=jetBTagger.getParameter<double>("workingPoint");
  }
  // read jetID information if it exists
  if(cfg.existsAs<edm::ParameterSet>("jetID")){
    edm::ParameterSet jetID=cfg.getParameter<edm::ParameterSet>("jetID");
    jetIDLabel_ =jetID.getParameter<edm::InputTag>("label");
    jetIDSelect_= new StringCutObjectSelector<reco::JetID>(jetID.getParameter<std::string>("select"));
  }
}
template<typename Object>
SelectionStep< Object >::~SelectionStep ( ) [inline]

default destructor

Definition at line 152 of file TopDQMHelpers.h.

{};

Member Function Documentation

template<typename Object >
bool SelectionStep< Object >::select ( const edm::Event event)

apply selection

Definition at line 212 of file TopDQMHelpers.h.

References accept(), edm::Event::getByLabel(), n, VarParsing::obj, and align_tpl::src.

Referenced by TopDiLeptonOfflineDQM::analyze(), and TopSingleLeptonDQM::analyze().

{
  // fetch input collection
  edm::Handle<edm::View<Object> > src; 
  if( !event.getByLabel(src_, src) ) return false;

  // load electronId value map if configured such
  edm::Handle<edm::ValueMap<float> > electronId;
  if(!electronId_.label().empty()) {
    if( !event.getByLabel(electronId_, electronId) ) return false;
  }

  // determine multiplicity of selected objects
  int n=0;
  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
    // special treatment for electrons
    if(dynamic_cast<const reco::GsfElectron*>(&*obj)){
      unsigned int idx = obj-src->begin();
      if( electronId_.label().empty() ? true : (*electronId)[src->refAt(idx)]>0.99 ){   
        if(select_(*obj))++n;
      }
    }
    // normal treatment
    else{
      if(select_(*obj))++n;
    }
  }
  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
  return (min_<0 && max_<0) ? (n>0):accept;
}
template<typename Object >
bool SelectionStep< Object >::select ( const edm::Event event,
const edm::EventSetup setup 
)

apply selection override for jets

apply selection (w/o using the template class Object), override for jets

Definition at line 245 of file TopDQMHelpers.h.

References accept(), JetCorrector::correction(), edm::EventSetup::find(), edm::Event::getByLabel(), JetCorrector::getJetCorrector(), metsig::jet, n, VarParsing::obj, and align_tpl::src.

{
  // fetch input collection
  edm::Handle<edm::View<Object> > src; 
  if( !event.getByLabel(src_, src) ) return false;

  // load btag collection if configured such
  // NOTE that the JetTagCollection needs an
  // edm::View to reco::Jets; we have to add
  // another Handle bjets for this purpose
  edm::Handle<edm::View<reco::Jet> > bjets; 
  edm::Handle<reco::JetTagCollection> btagger;
  if(!btagLabel_.label().empty()){ 
    if( !event.getByLabel(src_, bjets) ) return false;
    if( !event.getByLabel(btagLabel_, btagger) ) return false;
  }
  
  // load jetID value map if configured such 
  edm::Handle<reco::JetIDValueMap> jetID;
  if(jetIDSelect_){
    if( !event.getByLabel(jetIDLabel_, jetID) ) return false;
  }

  // load jet corrector if configured such
  const JetCorrector* corrector=0;
  if(!jetCorrector_.empty()){
    // check whether a jet correcto is in the event setup or not
    if(setup.find( edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>() )){
      corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
    }
    else{
      edm::LogVerbatim( "TopDQMHelpers" ) 
        << "\n"
        << "------------------------------------------------------------------------------------- \n"
        << " No JetCorrectionsRecord available from EventSetup:                                   \n" 
        << "  - Jets will not be corrected.                                                       \n"
        << "  - If you want to change this add the following lines to your cfg file               \n"
        << "                                                                                      \n"
        << "  ## load jet corrections                                                             \n"
        << "  process.load(\"JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff\") \n"
        << "  process.prefer(\"ak5CaloL2L3\")                                                     \n"
        << "                                                                                      \n"
        << "------------------------------------------------------------------------------------- \n";
    }
  }
  // determine multiplicity of selected objects
  int n=0;
  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
    // check for chosen btag discriminator to be above the 
    // corresponding working point if configured such 
    unsigned int idx = obj-src->begin();
    if( btagLabel_.label().empty() ? true : (*btagger)[bjets->refAt(idx)]>btagWorkingPoint_ ){   
      bool passedJetID=true;
      // check jetID for calo jets
      if( jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())){
        passedJetID=(*jetIDSelect_)((*jetID)[src->refAt(idx)]);
      }
      if(passedJetID){
        // scale jet energy if configured such
        Object jet=*obj; jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
        if(select_(jet))++n;
      }
    }
  }
  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
  return (min_<0 && max_<0) ? (n>0):accept;
}

Member Data Documentation

template<typename Object>
edm::InputTag SelectionStep< Object >::btagLabel_ [private]

choice for b-tag as extra selection type

Definition at line 169 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
double SelectionStep< Object >::btagWorkingPoint_ [private]

choice of b-tag working point as extra selection type

Definition at line 171 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
edm::InputTag SelectionStep< Object >::electronId_ [private]

electronId as extra selection type

Definition at line 165 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
std::string SelectionStep< Object >::jetCorrector_ [private]

jet corrector as extra selection type

Definition at line 167 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
edm::InputTag SelectionStep< Object >::jetIDLabel_ [private]

jetID as an extra selection type

Definition at line 173 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
StringCutObjectSelector<reco::JetID>* SelectionStep< Object >::jetIDSelect_ [private]

selection string on the jetID

Definition at line 178 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
int SelectionStep< Object >::max_ [private]

Definition at line 163 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
int SelectionStep< Object >::min_ [private]

min/max for object multiplicity

Definition at line 163 of file TopDQMHelpers.h.

Referenced by SelectionStep< Object >::SelectionStep().

template<typename Object>
StringCutObjectSelector<Object> SelectionStep< Object >::select_ [private]

string cut selector

Definition at line 176 of file TopDQMHelpers.h.

template<typename Object>
edm::InputTag SelectionStep< Object >::src_ [private]

input collection

Definition at line 161 of file TopDQMHelpers.h.