CMS 3D CMS Logo

Public Types | Public Member Functions | Protected Attributes

Selector< T > Class Template Reference

Functor that operates on <T> More...

#include <CommonTools/Utils/interface/Selector.h>

Inheritance diagram for Selector< T >:
binary_function

List of all members.

Public Types

typedef std::binary_function
< T, pat::strbitset, bool > 
base_type
typedef std::pair< index_type,
size_t > 
cut_flow_item
typedef std::vector
< cut_flow_item
cut_flow_map
typedef T data_type
typedef std::map< index_type,
double > 
double_map
typedef pat::strbitset::index_type index_type
typedef std::map< index_type, int > int_map

Public Member Functions

void clear (std::string const &s)
 Turn off a given selection cut.
void clear (index_type const &i)
bool considerCut (std::string const &s) const
 consider the cut at index "s"
bool considerCut (index_type const &i) const
int cut (index_type const &i, int val) const
 Access the int cut values at index "s".
double cut (index_type const &i, double val) const
 Access the double cut values at index "s".
int cut (std::string s, int val) const
 Access the int cut values at index "s".
double cut (std::string s, double val) const
 Access the double cut values at index "s".
pat::strbitset getBitTemplate () const
 Get an empty bitset with the proper names.
double getPasses (std::string const &s) const
 Return the number of passing cases.
double getPasses (index_type const &i) const
bool ignoreCut (std::string const &s) const
 ignore the cut at index "s"
bool ignoreCut (index_type const &i) const
virtual bool operator() (T const &t, pat::strbitset &ret)=0
 This provides the interface for base classes to select objects.
virtual bool operator() (T const &t, edm::EventBase const &e, pat::strbitset &ret)
 This provides an alternative signature that includes extra information.
virtual bool operator() (T const &t, edm::EventBase const &e)
 This provides an alternative signature that includes extra information.
virtual bool operator() (T const &t)
 This provides an alternative signature without the second ret.
bool operator[] (std::string const &s) const
bool operator[] (index_type const &i) const
void passCut (pat::strbitset &ret, std::string const &s)
 Passing cuts.
void passCut (pat::strbitset &ret, index_type const &i)
void print (std::ostream &out) const
 Print the cut flow.
void printActiveCuts (std::ostream &out) const
 Print the cuts being considered.
virtual void push_back (std::string const &s, int cut)
 This is the registration of an individual cut string, with an int cut value.
virtual void push_back (std::string const &s, double cut)
 This is the registration of an individual cut string, with a double cut value.
virtual void push_back (std::string const &s)
 This is the registration of an individual cut string.
 Selector ()
 Constructor clears the bits.
void set (std::string const &s, int cut, bool val=true)
 Set a given selection cut, on or off, and reset int cut value.
void set (std::string const &s, bool val=true)
 Set a given selection cut, on or off.
void set (index_type const &i, bool val=true)
void set (std::string const &s, double cut, bool val=true)
 Set a given selection cut, on or off, and reset int cut value.
void set (index_type const &i, double cut, bool val=true)
void set (index_type const &i, int cut, bool val=true)
void setIgnored (pat::strbitset &ret)
 set ignored bits
void setIgnoredCuts (std::vector< std::string > const &bitsToIgnore)
 set the bits to ignore from a vector
virtual ~Selector ()

Protected Attributes

pat::strbitset bits_
 the bitset indexed by strings
cut_flow_map cutFlow_
 map of cut flows in "human" order
double_map doubleCuts_
 the double-value cut map
int_map intCuts_
 the int-value cut map
pat::strbitset retInternal_
 internal ret if users don't care about return bits

Detailed Description

template<class T>
class Selector< T >

Functor that operates on <T>

Implements a string-indexed bit_vector.

class template that implements an interface to Selector utilities. This allows the user to access individual cuts based on a string index. The user can then turn individual cuts on and off at will.

Author:
Salvatore Rappoccio
Version:
Id:
Selector.h,v 1.13 2010/08/09 13:50:05 srappocc Exp

Definition at line 25 of file Selector.h.


Member Typedef Documentation

template<class T>
typedef std::binary_function<T,pat::strbitset,bool> Selector< T >::base_type

Definition at line 29 of file Selector.h.

template<class T>
typedef std::pair<index_type, size_t> Selector< T >::cut_flow_item

Definition at line 31 of file Selector.h.

template<class T>
typedef std::vector<cut_flow_item> Selector< T >::cut_flow_map

Definition at line 32 of file Selector.h.

template<class T>
typedef T Selector< T >::data_type

Definition at line 28 of file Selector.h.

template<class T>
typedef std::map<index_type, double> Selector< T >::double_map

Definition at line 34 of file Selector.h.

template<class T>
typedef pat::strbitset::index_type Selector< T >::index_type

Definition at line 30 of file Selector.h.

template<class T>
typedef std::map<index_type, int> Selector< T >::int_map

Definition at line 33 of file Selector.h.


Constructor & Destructor Documentation

template<class T>
Selector< T >::Selector ( ) [inline]

Constructor clears the bits.

Definition at line 37 of file Selector.h.

              { 
    bits_.clear(); 
    intCuts_.clear(); 
    doubleCuts_.clear();
    cutFlow_.clear();
    retInternal_ = getBitTemplate();
  }
template<class T>
virtual Selector< T >::~Selector ( ) [inline, virtual]

Definition at line 44 of file Selector.h.

{}

Member Function Documentation

template<class T>
void Selector< T >::clear ( std::string const &  s) [inline]

Turn off a given selection cut.

Definition at line 132 of file Selector.h.

Referenced by Selector< pat::Electron >::clear().

template<class T>
void Selector< T >::clear ( index_type const &  i) [inline]

Definition at line 136 of file Selector.h.

                                   {
    bits_[i] = false;
  }
template<class T>
bool Selector< T >::considerCut ( std::string const &  s) const [inline]

consider the cut at index "s"

Definition at line 152 of file Selector.h.

Referenced by Selector< pat::Electron >::print(), and Selector< pat::Electron >::printActiveCuts().

                                                {
    return bits_[s] == true;
  }
template<class T>
bool Selector< T >::considerCut ( index_type const &  i) const [inline]

Definition at line 155 of file Selector.h.

                                                  {
    return bits_[i] == true;
  }
template<class T>
int Selector< T >::cut ( index_type const &  i,
int  val 
) const [inline]

Access the int cut values at index "s".

Definition at line 195 of file Selector.h.

Referenced by Selector< pat::Electron >::cut(), Selector< pat::Electron >::push_back(), and Selector< pat::Electron >::set().

                                                 {
    return intCuts_.find( i )->second;
  };
template<class T>
double Selector< T >::cut ( index_type const &  i,
double  val 
) const [inline]

Access the double cut values at index "s".

Definition at line 199 of file Selector.h.

                                                       {
    return doubleCuts_.find( i )->second;
  };
template<class T>
int Selector< T >::cut ( std::string  s,
int  val 
) const [inline]

Access the int cut values at index "s".

Definition at line 204 of file Selector.h.

                                        {
    return cut( index_type(&bits_,s), val);
  };
template<class T>
double Selector< T >::cut ( std::string  s,
double  val 
) const [inline]

Access the double cut values at index "s".

Definition at line 208 of file Selector.h.

                                              {
    return cut( index_type(&bits_,s), val);
  };
template<class T>
pat::strbitset Selector< T >::getBitTemplate ( ) const [inline]

Get an empty bitset with the proper names.

Definition at line 213 of file Selector.h.

Referenced by SimpleJetFilter::filter(), WPlusJetsEventSelector::operator()(), and Selector< pat::Electron >::Selector().

                                      { 
    pat::strbitset ret = bits_; 
    ret.set(false);
    for ( cut_flow_map::const_iterator cutsBegin = cutFlow_.begin(),
            cutsEnd = cutFlow_.end(), icut = cutsBegin;
          icut != cutsEnd; ++icut ) {
      if ( ignoreCut(icut->first) ) ret[icut->first] = true;
    }     
    return ret;
  }
template<class T>
double Selector< T >::getPasses ( std::string const &  s) const [inline]

Return the number of passing cases.

Definition at line 270 of file Selector.h.

Referenced by Selector< pat::Electron >::getPasses().

                                                {
    return getPasses( index_type(&bits_,s) );
  }
template<class T>
double Selector< T >::getPasses ( index_type const &  i) const [inline]

Definition at line 273 of file Selector.h.

                                                {
    cut_flow_map::iterator found = cutFlow_.end();
    for ( cut_flow_map::iterator cutsBegin = cutFlow_.begin(),
            cutsEnd = cutFlow_.end(), icut = cutsBegin;
          icut != cutsEnd && found == cutsEnd; ++icut ) {
      if ( icut->first == i ) {
        found = icut;
      }
    }
    return found->second;
  }
template<class T>
bool Selector< T >::ignoreCut ( std::string const &  s) const [inline]

ignore the cut at index "s"

Definition at line 160 of file Selector.h.

Referenced by Selector< pat::Electron >::getBitTemplate(), and Selector< pat::Electron >::setIgnored().

                                              {
    return bits_[s] == false;
  }
template<class T>
bool Selector< T >::ignoreCut ( index_type const &  i) const [inline]

Definition at line 163 of file Selector.h.

                                               {
    return bits_[i] == false;
  }
template<class T>
virtual bool Selector< T >::operator() ( T const &  t) [inline, virtual]

This provides an alternative signature without the second ret.

Definition at line 80 of file Selector.h.

template<class T>
virtual bool Selector< T >::operator() ( T const &  t,
edm::EventBase const &  e 
) [inline, virtual]

This provides an alternative signature that includes extra information.

Definition at line 96 of file Selector.h.

template<class T>
virtual bool Selector< T >::operator() ( T const &  t,
pat::strbitset ret 
) [pure virtual]
template<class T>
virtual bool Selector< T >::operator() ( T const &  t,
edm::EventBase const &  e,
pat::strbitset ret 
) [inline, virtual]

This provides an alternative signature that includes extra information.

Reimplemented in MuonVPlusJetsIDSelectionFunctor.

Definition at line 90 of file Selector.h.

  {
    return operator()(t, ret);
  }
template<class T>
bool Selector< T >::operator[] ( index_type const &  i) const [inline]

Definition at line 147 of file Selector.h.

                                                 {
    return bits_[i];
  }
template<class T>
bool Selector< T >::operator[] ( std::string const &  s) const [inline]

Access the selector cut at index "s". "true" means to consider the cut. "false" means to ignore the cut.

Definition at line 143 of file Selector.h.

                                                {
    return bits_[s];
  }
template<class T>
void Selector< T >::passCut ( pat::strbitset ret,
std::string const &  s 
) [inline]

Passing cuts.

Definition at line 177 of file Selector.h.

Referenced by Selector< pat::Electron >::passCut().

                                                          {
    passCut( ret, index_type(&bits_,s));
  }
template<class T>
void Selector< T >::passCut ( pat::strbitset ret,
index_type const &  i 
) [inline]

Definition at line 181 of file Selector.h.

                                                           {
    ret[i] = true;
    cut_flow_map::iterator found = cutFlow_.end();
    for ( cut_flow_map::iterator cutsBegin = cutFlow_.begin(),
            cutsEnd = cutFlow_.end(), icut = cutsBegin;
          icut != cutsEnd && found == cutsEnd; ++icut ) {
      if ( icut->first == i ) {
        found = icut;
      }
    }
    ++(found->second);
  }
template<class T>
void Selector< T >::print ( std::ostream &  out) const [inline]

Print the cut flow.

Definition at line 234 of file Selector.h.

Referenced by WPlusJetsEventSelector::printSelectors().

                                     { 
    for ( cut_flow_map::const_iterator cutsBegin = cutFlow_.begin(),
            cutsEnd = cutFlow_.end(), icut = cutsBegin;
          icut != cutsEnd; ++icut ) {
      char buff[1000];
      if ( considerCut( icut->first ) ) {
        sprintf(buff, "%6lu : %20s %10lu", 
                static_cast<unsigned long>(icut - cutsBegin),
                icut->first.str().c_str(),
                static_cast<unsigned long>(icut->second) );
      } else {
        sprintf(buff, "%6lu : %20s %10s", 
                static_cast<unsigned long>(icut - cutsBegin),
                icut->first.str().c_str(),
                "off" );
      }
      out << buff << std::endl;
    } 
  }
template<class T>
void Selector< T >::printActiveCuts ( std::ostream &  out) const [inline]

Print the cuts being considered.

Definition at line 255 of file Selector.h.

                                               { 
    bool already_printed_one = false;
    for ( cut_flow_map::const_iterator cutsBegin = cutFlow_.begin(),
            cutsEnd = cutFlow_.end(), icut = cutsBegin;
          icut != cutsEnd; ++icut ) {
      if ( considerCut( icut->first ) ) {
        if( already_printed_one ) out << ", ";
        out << icut->first;
        already_printed_one = true;
      }
    } 
    out << std::endl;
  }
template<class T>
virtual void Selector< T >::push_back ( std::string const &  s) [inline, virtual]

This is the registration of an individual cut string.

Definition at line 47 of file Selector.h.

                                               {
    bits_.push_back(s);
    index_type i(&bits_,s);    
    // don't need to check to see if the key is already there,
    // bits_ does that.
    cutFlow_.push_back( cut_flow_item(i, 0) );
  }
template<class T>
virtual void Selector< T >::push_back ( std::string const &  s,
double  cut 
) [inline, virtual]

This is the registration of an individual cut string, with a double cut value.

Definition at line 67 of file Selector.h.

                                                           {
    bits_.push_back(s);
    index_type i(&bits_,s);
    doubleCuts_[i] = cut;
    // don't need to check to see if the key is already there,
    // bits_ does that.
    cutFlow_.push_back( cut_flow_item(i,0) );
  }
template<class T>
virtual void Selector< T >::push_back ( std::string const &  s,
int  cut 
) [inline, virtual]

This is the registration of an individual cut string, with an int cut value.

Definition at line 57 of file Selector.h.

                                                        {
    bits_.push_back(s);
    index_type i(&bits_,s);
    intCuts_[i] = cut;
    // don't need to check to see if the key is already there,
    // bits_ does that.
    cutFlow_.push_back( cut_flow_item(i,0) );
  }
template<class T>
void Selector< T >::set ( std::string const &  s,
bool  val = true 
) [inline]

Set a given selection cut, on or off.

Definition at line 106 of file Selector.h.

                                                 {
    set( index_type(&bits_,s), val);
  }
template<class T>
void Selector< T >::set ( index_type const &  i,
bool  val = true 
) [inline]

Definition at line 109 of file Selector.h.

                                                  {
    bits_[i] = val;
  }
template<class T>
void Selector< T >::set ( std::string const &  s,
double  cut,
bool  val = true 
) [inline]

Set a given selection cut, on or off, and reset int cut value.

Definition at line 123 of file Selector.h.

                                                             {
    set( index_type(&bits_,s), cut);
  }
template<class T>
void Selector< T >::set ( std::string const &  s,
int  cut,
bool  val = true 
) [inline]

Set a given selection cut, on or off, and reset int cut value.

Definition at line 114 of file Selector.h.

                                                          {
    set( index_type(&bits_,s), cut);
  }
template<class T>
void Selector< T >::set ( index_type const &  i,
double  cut,
bool  val = true 
) [inline]

Definition at line 126 of file Selector.h.

                                                              {
    bits_[i] = val;
    doubleCuts_[i] = cut;
  }
template<class T>
void Selector< T >::set ( index_type const &  i,
int  cut,
bool  val = true 
) [inline]

Definition at line 117 of file Selector.h.

                                                           {
    bits_[i] = val;
    intCuts_[i] = cut;
  }
template<class T>
void Selector< T >::setIgnored ( pat::strbitset ret) [inline]

set ignored bits

Definition at line 225 of file Selector.h.

Referenced by Selector< pat::Electron >::operator()().

                                        {
    for ( cut_flow_map::const_iterator cutsBegin = cutFlow_.begin(),
            cutsEnd = cutFlow_.end(), icut = cutsBegin;
          icut != cutsEnd; ++icut ) {
      if ( ignoreCut(icut->first) ) ret[icut->first] = true;
    } 
  }
template<class T>
void Selector< T >::setIgnoredCuts ( std::vector< std::string > const &  bitsToIgnore) [inline]

set the bits to ignore from a vector

Definition at line 168 of file Selector.h.

                                                                   {
    for ( std::vector<std::string>::const_iterator ignoreBegin = bitsToIgnore.begin(),
            ignoreEnd = bitsToIgnore.end(), ibit = ignoreBegin;
          ibit != ignoreEnd; ++ibit ) {
      set(*ibit, false );
    }
  }

Member Data Documentation

template<class T>
pat::strbitset Selector< T >::bits_ [protected]
template<class T>
cut_flow_map Selector< T >::cutFlow_ [protected]
template<class T>
double_map Selector< T >::doubleCuts_ [protected]
template<class T>
int_map Selector< T >::intCuts_ [protected]
template<class T>
pat::strbitset Selector< T >::retInternal_ [protected]

internal ret if users don't care about return bits

Definition at line 288 of file Selector.h.

Referenced by Selector< pat::Electron >::operator()(), and Selector< pat::Electron >::Selector().