Go to the documentation of this file.00001
00002
00003
00004
00005 #include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
00006
00007 #include <boost/algorithm/string.hpp>
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009
00010
00011 using namespace pat;
00012
00013
00014
00015
00016
00017 const char TriggerObjectStandAlone::wildcard_;
00018
00019
00020
00021
00022
00023
00024 TriggerObjectStandAlone::TriggerObjectStandAlone() :
00025 TriggerObject()
00026 {
00027 filterLabels_.clear();
00028 pathNames_.clear();
00029 pathLastFilterAccepted_.clear();
00030 pathL3FilterAccepted_.clear();
00031 }
00032
00033
00034
00035 TriggerObjectStandAlone::TriggerObjectStandAlone( const TriggerObject & trigObj ) :
00036 TriggerObject( trigObj )
00037 {
00038 filterLabels_.clear();
00039 pathNames_.clear();
00040 pathLastFilterAccepted_.clear();
00041 pathL3FilterAccepted_.clear();
00042 }
00043
00044
00045
00046 TriggerObjectStandAlone::TriggerObjectStandAlone( const trigger::TriggerObject & trigObj ) :
00047 TriggerObject( trigObj )
00048 {
00049 filterLabels_.clear();
00050 pathNames_.clear();
00051 pathLastFilterAccepted_.clear();
00052 pathL3FilterAccepted_.clear();
00053 }
00054
00055
00056
00057 TriggerObjectStandAlone::TriggerObjectStandAlone( const reco::LeafCandidate & leafCand ) :
00058 TriggerObject( leafCand )
00059 {
00060 filterLabels_.clear();
00061 pathNames_.clear();
00062 pathLastFilterAccepted_.clear();
00063 pathL3FilterAccepted_.clear();
00064 }
00065
00066
00067
00068 TriggerObjectStandAlone::TriggerObjectStandAlone( const reco::Particle::LorentzVector & vec, int id ) :
00069 TriggerObject( vec, id )
00070 {
00071 filterLabels_.clear();
00072 pathNames_.clear();
00073 pathLastFilterAccepted_.clear();
00074 pathL3FilterAccepted_.clear();
00075 }
00076 TriggerObjectStandAlone::TriggerObjectStandAlone( const reco::Particle::PolarLorentzVector & vec, int id ) :
00077 TriggerObject( vec, id )
00078 {
00079 filterLabels_.clear();
00080 pathNames_.clear();
00081 pathLastFilterAccepted_.clear();
00082 pathL3FilterAccepted_.clear();
00083 }
00084
00085
00086
00087
00088
00089
00090 bool TriggerObjectStandAlone::hasAnyName( const std::string & name, const std::vector< std::string > & nameVec ) const
00091 {
00092
00093
00094 if ( nameVec.empty() ) return false;
00095
00096 if ( name.find_first_not_of( wildcard_ ) == std::string::npos ) return true;
00097
00098 std::vector< std::string > namePartsVec;
00099 boost::split( namePartsVec, name, boost::is_any_of( std::string( 1, wildcard_ ) ), boost::token_compress_on );
00100
00101 for ( std::vector< std::string >::const_iterator iVec = nameVec.begin(); iVec != nameVec.end(); ++iVec ) {
00102
00103 bool failed( false );
00104
00105 size_type index( 0 );
00106
00107 for ( std::vector< std::string >::const_iterator iName = namePartsVec.begin(); iName != namePartsVec.end(); ++iName ) {
00108
00109
00110
00111 if ( iName->length() == 0 ) continue;
00112
00113
00114 index = iVec->find( *iName, index );
00115
00116
00117
00118 if ( index == std::string::npos || ( iName == namePartsVec.begin() && index > 0 ) ) {
00119 failed = true;
00120 break;
00121 }
00122
00123 index += iName->length();
00124 }
00125
00126 if ( index < iVec->length() && namePartsVec.back().length() != 0 ) failed = true;
00127
00128 if ( ! failed ) return true;
00129 }
00130
00131 return false;
00132 }
00133
00134
00135
00136 void TriggerObjectStandAlone::addPathOrAlgorithm( const std::string & name, bool pathLastFilterAccepted, bool pathL3FilterAccepted )
00137 {
00138
00139 if ( ! hasPathOrAlgorithm( name, false, false ) ) {
00140
00141 pathNames_.push_back( name );
00142
00143 pathLastFilterAccepted_.push_back( pathLastFilterAccepted );
00144 pathL3FilterAccepted_.push_back( pathL3FilterAccepted );
00145 } else if ( pathLastFilterAccepted || pathL3FilterAccepted ) {
00146 unsigned index( 0 );
00147 while ( index < pathNames_.size() ) {
00148 if ( pathNames_.at( index ) == name ) break;
00149 ++index;
00150 }
00151 if ( index < pathNames_.size() ) {
00152 pathLastFilterAccepted_.at( index ) = pathLastFilterAccepted;
00153 pathL3FilterAccepted_.at( index ) = pathL3FilterAccepted;
00154 }
00155 }
00156 }
00157
00158
00159
00160 std::vector< std::string > TriggerObjectStandAlone::pathsOrAlgorithms( bool pathLastFilterAccepted, bool pathL3FilterAccepted ) const
00161 {
00162
00163 if ( ! hasLastFilter() ) pathLastFilterAccepted = false;
00164 if ( ! hasL3Filter() ) pathL3FilterAccepted = false;
00165
00166 if ( ! pathLastFilterAccepted && ! pathL3FilterAccepted ) return pathNames_;
00167
00168 std::vector< std::string > paths;
00169
00170 for ( unsigned iPath = 0; iPath < pathNames_.size(); ++iPath ) {
00171 if ( ( ! pathLastFilterAccepted || pathLastFilterAccepted_.at( iPath ) ) && ( ! pathL3FilterAccepted || pathL3FilterAccepted_.at( iPath ) ) ) paths.push_back( pathNames_.at( iPath ) );
00172 }
00173
00174 return paths;
00175 }
00176
00177
00178
00179 bool TriggerObjectStandAlone::hasFilterOrCondition( const std::string & name ) const
00180 {
00181
00182 if ( name.find( wildcard_ ) != std::string::npos ) return hasAnyName( name, filterLabels_ );
00183
00184 return ( std::find( filterLabels_.begin(), filterLabels_.end(), name ) != filterLabels_.end() );
00185 }
00186
00187
00188
00189 bool TriggerObjectStandAlone::hasPathOrAlgorithm( const std::string & name, bool pathLastFilterAccepted, bool pathL3FilterAccepted ) const
00190 {
00191
00192 if ( name.find( wildcard_ ) != std::string::npos ) return hasAnyName( name, pathsOrAlgorithms( pathLastFilterAccepted, pathL3FilterAccepted ) );
00193
00194 if ( ! hasLastFilter() ) pathLastFilterAccepted = false;
00195 if ( ! hasL3Filter() ) pathL3FilterAccepted = false;
00196
00197 std::vector< std::string >::const_iterator match( std::find( pathNames_.begin(), pathNames_.end(), name ) );
00198
00199 if ( match == pathNames_.end() ) return false;
00200 if ( ! pathLastFilterAccepted && ! pathL3FilterAccepted ) return true;
00201 bool foundLastFilter( pathLastFilterAccepted ? pathLastFilterAccepted_.at( match - pathNames_.begin() ) : true );
00202 bool foundL3Filter( pathL3FilterAccepted ? pathL3FilterAccepted_.at( match - pathNames_.begin() ) : true );
00203
00204 return ( foundLastFilter && foundL3Filter );
00205 }
00206
00207
00208
00209
00210
00211
00212 TriggerObject TriggerObjectStandAlone::triggerObject()
00213 {
00214
00215 TriggerObject theObj( p4(), pdgId() );
00216
00217 theObj.setCollection( collection() );
00218 for ( size_t i = 0; i < triggerObjectTypes().size(); ++i ) theObj.addTriggerObjectType( triggerObjectTypes().at( i ) );
00219
00220 return theObj;
00221 }
00222
00223
00224
00225 bool TriggerObjectStandAlone::hasCollection( const std::string & collName ) const
00226 {
00227
00228 if ( collName.find( wildcard_ ) != std::string::npos ) {
00229
00230 if ( hasAnyName( collName, std::vector< std::string >( 1, collection() ) ) ) return true;
00231
00232 const edm::InputTag collectionTag( collection() );
00233 const edm::InputTag collTag( collName );
00234
00235 if ( collTag.process().empty() ) {
00236
00237 if ( ( collTag.instance().empty() && collectionTag.instance().empty() ) || hasAnyName( collTag.instance(), std::vector< std::string >( 1, collectionTag.instance() ) ) ) {
00238
00239 return hasAnyName( collTag.label(), std::vector< std::string >( 1, collectionTag.label() ) );
00240 }
00241 }
00242 return false;
00243 }
00244
00245 return TriggerObject::hasCollection( collName );
00246 }