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...
 
bool selectVertex (const edm::Event &event)
 
 ~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...
 
edm::InputTag pvs_
 
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 149 of file TopDQMHelpers.h.

Constructor & Destructor Documentation

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

default constructor

Definition at line 198 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_.

198  :
199  src_( cfg.getParameter<edm::InputTag>( "src" )),
200  select_( cfg.getParameter<std::string>("select")),
201  jetIDSelect_(0)
202 {
203  // construct min/max if the corresponding params
204  // exist otherwise they are initialized with -1
205  cfg.exists("min") ? min_= cfg.getParameter<int>("min") : min_= -1;
206  cfg.exists("max") ? max_= cfg.getParameter<int>("max") : max_= -1;
207  // read electron extras if they exist
208  if(cfg.existsAs<edm::ParameterSet>("electronId")){
209  edm::ParameterSet elecId=cfg.getParameter<edm::ParameterSet>("electronId");
210  electronId_= elecId.getParameter<edm::InputTag>("src");
211  eidPattern_= elecId.getParameter<int>("pattern");
212  }
213  // read jet corrector label if it exists
214  if(cfg.exists("jetCorrector")){ jetCorrector_= cfg.getParameter<std::string>("jetCorrector"); }
215  // read btag information if it exists
216  if(cfg.existsAs<edm::ParameterSet>("jetBTagger")){
217  edm::ParameterSet jetBTagger=cfg.getParameter<edm::ParameterSet>("jetBTagger");
218  btagLabel_=jetBTagger.getParameter<edm::InputTag>("label");
219  btagWorkingPoint_=jetBTagger.getParameter<double>("workingPoint");
220  }
221  // read jetID information if it exists
222  if(cfg.existsAs<edm::ParameterSet>("jetID")){
224  jetIDLabel_ =jetID.getParameter<edm::InputTag>("label");
225  jetIDSelect_= new StringCutObjectSelector<reco::JetID>(jetID.getParameter<std::string>("select"));
226  }
227 }
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:187
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 154 of file TopDQMHelpers.h.

154 {};

Member Function Documentation

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

apply selection

Definition at line 231 of file TopDQMHelpers.h.

References accept(), edm::Event::getByLabel(), n, getGTfromDQMFile::obj, and alcazmumu_cfi::src.

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

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

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

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

287 {
288  // fetch input collection
290  if( !event.getByLabel(src_, src) ) return false;
291 
292  // load btag collection if configured such
293  // NOTE that the JetTagCollection needs an
294  // edm::View to reco::Jets; we have to add
295  // another Handle bjets for this purpose
299  if(!btagLabel_.label().empty()){
300  if( !event.getByLabel(src_, bjets) ) return false;
301  if( !event.getByLabel(btagLabel_, btagger) ) return false;
302  if( !event.getByLabel(pvs_, pvertex) ) return false;
303  }
304 
305  // load jetID value map if configured such
307  if(jetIDSelect_){
308  if( !event.getByLabel(jetIDLabel_, jetID) ) return false;
309 
310  }
311 
312  // load jet corrector if configured such
313  const JetCorrector* corrector=0;
314  if(!jetCorrector_.empty()){
315  // check whether a jet correcto is in the event setup or not
316  if(setup.find( edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>() )){
317  corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
318  }
319  else{
320  edm::LogVerbatim( "TopDQMHelpers" )
321  << "\n"
322  << "------------------------------------------------------------------------------------- \n"
323  << " No JetCorrectionsRecord available from EventSetup: \n"
324  << " - Jets will not be corrected. \n"
325  << " - If you want to change this add the following lines to your cfg file \n"
326  << " \n"
327  << " ## load jet corrections \n"
328  << " process.load(\"JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff\") \n"
329  << " process.prefer(\"ak5CaloL2L3\") \n"
330  << " \n"
331  << "------------------------------------------------------------------------------------- \n";
332  }
333  }
334  // determine multiplicity of selected objects
335  int n=0;
336  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
337  // check for chosen btag discriminator to be above the
338  // corresponding working point if configured such
339  unsigned int idx = obj-src->begin();
340  if( btagLabel_.label().empty() ? true : (*btagger)[bjets->refAt(idx)]>btagWorkingPoint_ ){
341  bool passedJetID=true;
342  // check jetID for calo jets
343  if( jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())){
344  passedJetID=(*jetIDSelect_)((*jetID)[src->refAt(idx)]);
345  }
346  if(passedJetID){
347  // scale jet energy if configured such
348  Object jet=*obj; jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
349  if(select_(jet))++n;
350  }
351  }
352  }
353  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
354  return (min_<0 && max_<0) ? (n>0):accept;
355 }
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
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:22
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:90
edm::InputTag pvs_
edm::InputTag jetIDLabel_
jetID as an extra selection type
int min_
min/max for object multiplicity
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
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:51
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
template<typename Object >
bool SelectionStep< Object >::selectVertex ( const edm::Event event)

Definition at line 262 of file TopDQMHelpers.h.

References accept(), edm::Event::getByLabel(), n, getGTfromDQMFile::obj, and alcazmumu_cfi::src.

Referenced by TopSingleLeptonDQM::analyze().

263 {
264  // fetch input collection
266  if( !event.getByLabel(src_, src) ) return false;
267 
268  // load electronId value map if configured such
270  if(!electronId_.label().empty()) {
271  if( !event.getByLabel(electronId_, electronId) ) return false;
272  }
273 
274  // determine multiplicity of selected objects
275  int n=0;
276  for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
277 
278  if(select_(*obj))++n;
279  }
280  bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
281  return (min_<0 && max_<0) ? (n>0):accept;
282 }
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
edm::InputTag src_
input collection
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:22
int min_
min/max for object multiplicity
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
edm::InputTag electronId_
electronId label as extra selection type
std::string const & label() const
Definition: InputTag.h:25
StringCutObjectSelector< Object > select_
string cut selector

Member Data Documentation

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

choice for b-tag as extra selection type

Definition at line 182 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 184 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 178 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 167 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 180 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 186 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 193 of file TopDQMHelpers.h.

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

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

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

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

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

Definition at line 188 of file TopDQMHelpers.h.

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

string cut selector

Definition at line 191 of file TopDQMHelpers.h.

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

input collection

Definition at line 163 of file TopDQMHelpers.h.