CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | 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"

Public Member Functions

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

Private Attributes

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

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 148 of file TopDQMHelpers.h.

Constructor & Destructor Documentation

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

default constructor

Definition at line 195 of file TopDQMHelpers.h.

References SelectionStep< Object >::btagLabel_, SelectionStep< Object >::btagWorkingPoint_, SelectionStep< Object >::eidPattern_, 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_.

195  :
196  src_( cfg.getParameter<edm::InputTag>( "src" )),
197  select_( cfg.getParameter<std::string>("select")),
198  jetIDSelect_(0)
199 {
200  // construct min/max if the corresponding params
201  // exist otherwise they are initialized with -1
202  cfg.exists("min") ? min_= cfg.getParameter<int>("min") : min_= -1;
203  cfg.exists("max") ? max_= cfg.getParameter<int>("max") : max_= -1;
204  // read electron extras if they exist
205  if(cfg.existsAs<edm::ParameterSet>("electronId")){
206  edm::ParameterSet elecId=cfg.getParameter<edm::ParameterSet>("electronId");
207  electronId_= elecId.getParameter<edm::InputTag>("src");
208  eidPattern_= elecId.getParameter<int>("pattern");
209  }
210  // read jet corrector label if it exists
211  if(cfg.exists("jetCorrector")){ jetCorrector_= cfg.getParameter<std::string>("jetCorrector"); }
212  // read btag information if it exists
213  if(cfg.existsAs<edm::ParameterSet>("jetBTagger")){
214  edm::ParameterSet jetBTagger=cfg.getParameter<edm::ParameterSet>("jetBTagger");
215  btagLabel_=jetBTagger.getParameter<edm::InputTag>("label");
216  btagWorkingPoint_=jetBTagger.getParameter<double>("workingPoint");
217  }
218  // read jetID information if it exists
219  if(cfg.existsAs<edm::ParameterSet>("jetID")){
221  jetIDLabel_ =jetID.getParameter<edm::InputTag>("label");
222  jetIDSelect_= new StringCutObjectSelector<reco::JetID>(jetID.getParameter<std::string>("select"));
223  }
224 }
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:181
edm::InputTag src_
input collection
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::InputTag jetIDLabel_
jetID as an extra selection type
int min_
min/max for object multiplicity
edm::InputTag electronId_
electronId label as extra selection type
double btagWorkingPoint_
choice of b-tag working point as extra selection type
StringCutObjectSelector< reco::JetID > * jetIDSelect_
selection string on the jetID
std::string jetCorrector_
jet corrector as extra selection type
edm::InputTag btagLabel_
choice for b-tag as extra selection type
StringCutObjectSelector< Object > select_
string cut selector
template<typename Object>
SelectionStep< Object >::~SelectionStep ( )
inline

default destructor

Definition at line 153 of file TopDQMHelpers.h.

153 {};

Member Function Documentation

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

apply selection

Definition at line 228 of file TopDQMHelpers.h.

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

Referenced by TopSingleLeptonDQM::analyze(), TopDiLeptonOfflineDQM::analyze(), python.Vispa.Views.LineDecayView.LineDecayContainer::createObject(), python.Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::find(), python.Vispa.Views.LineDecayView.LineDecayContainer::mousePressEvent(), python.Vispa.Gui.PortConnection.PointToPointConnection::mousePressEvent(), python.Vispa.Gui.VispaWidget.VispaWidget::mousePressEvent(), and python.Vispa.Views.AbstractView.AbstractView::restoreSelection().

229 {
230  // fetch input collection
232  if( !event.getByLabel(src_, src) ) return false;
233 
234  // load electronId value map if configured such
236  if(!electronId_.label().empty()) {
237  if( !event.getByLabel(electronId_, electronId) ) return false;
238  }
239 
240  // determine multiplicity of selected objects
241  int n=0;
242  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
243  // special treatment for electrons
244  if(dynamic_cast<const reco::GsfElectron*>(&*obj)){
245  unsigned int idx = obj-src->begin();
246  if( electronId_.label().empty() ? true : ((int)(*electronId)[src->refAt(idx)] & eidPattern_) ){
247  if(select_(*obj))++n;
248  }
249  }
250  // normal treatment
251  else{
252  if(select_(*obj))++n;
253  }
254  }
255  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
256  return (min_<0 && max_<0) ? (n>0):accept;
257 }
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::InputTag src_
input collection
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:21
int min_
min/max for object multiplicity
tuple obj
Example code starts here #.
Definition: VarParsing.py:655
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
edm::InputTag electronId_
electronId label as extra selection type
std::string const & label() const
Definition: InputTag.h:25
StringCutObjectSelector< Object > select_
string cut selector
tuple src
Definition: align_tpl.py:87
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 261 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.

Referenced by python.Vispa.Views.LineDecayView.LineDecayContainer::createObject(), python.Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::find(), python.Vispa.Views.LineDecayView.LineDecayContainer::mousePressEvent(), python.Vispa.Gui.PortConnection.PointToPointConnection::mousePressEvent(), python.Vispa.Gui.VispaWidget.VispaWidget::mousePressEvent(), and python.Vispa.Views.AbstractView.AbstractView::restoreSelection().

262 {
263  // fetch input collection
265  if( !event.getByLabel(src_, src) ) return false;
266 
267  // load btag collection if configured such
268  // NOTE that the JetTagCollection needs an
269  // edm::View to reco::Jets; we have to add
270  // another Handle bjets for this purpose
273  if(!btagLabel_.label().empty()){
274  if( !event.getByLabel(src_, bjets) ) return false;
275  if( !event.getByLabel(btagLabel_, btagger) ) return false;
276  }
277 
278  // load jetID value map if configured such
280  if(jetIDSelect_){
281  if( !event.getByLabel(jetIDLabel_, jetID) ) return false;
282  }
283 
284  // load jet corrector if configured such
285  const JetCorrector* corrector=0;
286  if(!jetCorrector_.empty()){
287  // check whether a jet correcto is in the event setup or not
288  if(setup.find( edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>() )){
289  corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
290  }
291  else{
292  edm::LogVerbatim( "TopDQMHelpers" )
293  << "\n"
294  << "------------------------------------------------------------------------------------- \n"
295  << " No JetCorrectionsRecord available from EventSetup: \n"
296  << " - Jets will not be corrected. \n"
297  << " - If you want to change this add the following lines to your cfg file \n"
298  << " \n"
299  << " ## load jet corrections \n"
300  << " process.load(\"JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff\") \n"
301  << " process.prefer(\"ak5CaloL2L3\") \n"
302  << " \n"
303  << "------------------------------------------------------------------------------------- \n";
304  }
305  }
306  // determine multiplicity of selected objects
307  int n=0;
308  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
309  // check for chosen btag discriminator to be above the
310  // corresponding working point if configured such
311  unsigned int idx = obj-src->begin();
312  if( btagLabel_.label().empty() ? true : (*btagger)[bjets->refAt(idx)]>btagWorkingPoint_ ){
313  bool passedJetID=true;
314  // check jetID for calo jets
315  if( jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())){
316  passedJetID=(*jetIDSelect_)((*jetID)[src->refAt(idx)]);
317  }
318  if(passedJetID){
319  // scale jet energy if configured such
320  Object jet=*obj; jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
321  if(select_(jet))++n;
322  }
323  }
324  }
325  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
326  return (min_<0 && max_<0) ? (n>0):accept;
327 }
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::InputTag src_
input collection
virtual double correction(const LorentzVector &fJet) const =0
get correction using Jet information only
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:21
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:90
edm::InputTag jetIDLabel_
jetID as an extra selection type
int min_
min/max for object multiplicity
tuple obj
Example code starts here #.
Definition: VarParsing.py:655
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
static const JetCorrector * getJetCorrector(const std::string &fName, const edm::EventSetup &fSetup)
retrieve corrector from the event setup. troughs exception if something is missing ...
Definition: JetCorrector.cc:40
double btagWorkingPoint_
choice of b-tag working point as extra selection type
std::string const & label() const
Definition: InputTag.h:25
StringCutObjectSelector< reco::JetID > * jetIDSelect_
selection string on the jetID
std::string jetCorrector_
jet corrector as extra selection type
edm::InputTag btagLabel_
choice for b-tag as extra selection type
StringCutObjectSelector< Object > select_
string cut selector
tuple src
Definition: align_tpl.py:87

Member Data Documentation

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

choice for b-tag as extra selection type

Definition at line 181 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 183 of file TopDQMHelpers.h.

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

template<typename Object>
int SelectionStep< Object >::eidPattern_
private

electronId pattern we expect the following pattern: 0: fails 1: passes electron ID only 2: passes electron Isolation only 3: passes electron ID and Isolation only 4: passes conversion rejection 5: passes conversion rejection and ID 6: passes conversion rejection and Isolation 7: passes the whole selection As described on https://twiki.cern.ch/twiki/bin/view/CMS/SimpleCutBasedEleID

Definition at line 177 of file TopDQMHelpers.h.

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

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

electronId label as extra selection type

Definition at line 166 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 179 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 185 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 190 of file TopDQMHelpers.h.

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

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

Definition at line 164 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 164 of file TopDQMHelpers.h.

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

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

string cut selector

Definition at line 188 of file TopDQMHelpers.h.

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

input collection

Definition at line 162 of file TopDQMHelpers.h.