CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TriggerObjectStandAlone.cc
Go to the documentation of this file.
1 //
2 // $Id: TriggerObjectStandAlone.cc,v 1.15 2012/04/13 21:04:55 gpetrucc Exp $
3 //
4 
6 
7 #include <boost/algorithm/string.hpp>
9 
10 
11 using namespace pat;
12 
13 
14 // Const data members' definitions
15 
16 
18 
19 
20 // Constructors and Destructor
21 
22 
23 // Default constructor
26 {
27  filterLabels_.clear();
28  pathNames_.clear();
30  pathL3FilterAccepted_.clear();
31 }
32 
33 
34 // Constructor from pat::TriggerObject
36  TriggerObject( trigObj )
37 {
38  filterLabels_.clear();
39  pathNames_.clear();
41  pathL3FilterAccepted_.clear();
42 }
43 
44 
45 // Constructor from trigger::TriggerObject
47  TriggerObject( trigObj )
48 {
49  filterLabels_.clear();
50  pathNames_.clear();
52  pathL3FilterAccepted_.clear();
53 }
54 
55 
56 // Constructor from reco::Candidate
58  TriggerObject( leafCand )
59 {
60  filterLabels_.clear();
61  pathNames_.clear();
63  pathL3FilterAccepted_.clear();
64 }
65 
66 
67 // Constructors from Lorentz-vectors and (optional) PDG ID
69  TriggerObject( vec, id )
70 {
71  filterLabels_.clear();
72  pathNames_.clear();
74  pathL3FilterAccepted_.clear();
75 }
77  TriggerObject( vec, id )
78 {
79  filterLabels_.clear();
80  pathNames_.clear();
82  pathL3FilterAccepted_.clear();
83 }
84 
85 
86 // Private methods
87 
88 
89 // Checks a string vector for occurence of a certain string, incl. wild-card mechanism
90 bool TriggerObjectStandAlone::hasAnyName( const std::string & name, const std::vector< std::string > & nameVec ) const
91 {
92  // Special cases first
93  // Always false for empty vector to check
94  if ( nameVec.empty() ) return false;
95  // Always true for general wild-card(s)
96  if ( name.find_first_not_of( wildcard_ ) == std::string::npos ) return true;
97  // Split name to evaluate in parts, seperated by wild-cards
98  std::vector< std::string > namePartsVec;
99  boost::split( namePartsVec, name, boost::is_any_of( std::string( 1, wildcard_ ) ), boost::token_compress_on );
100  // Iterate over vector of names to search
101  for ( std::vector< std::string >::const_iterator iVec = nameVec.begin(); iVec != nameVec.end(); ++iVec ) {
102  // Not failed yet
103  bool failed( false );
104  // Start searching at the first character
105  size_type index( 0 );
106  // Iterate over evaluation name parts
107  for ( std::vector< std::string >::const_iterator iName = namePartsVec.begin(); iName != namePartsVec.end(); ++iName ) {
108  // Empty parts due to
109  // - wild-card at beginning/end or
110  // - multiple wild-cards (should be supressed by 'boost::token_compress_on')
111  if ( iName->length() == 0 ) continue;
112  // Search from current index and
113  // set index to found occurence
114  index = iVec->find( *iName, index );
115  // Failed and exit loop, if
116  // - part not found
117  // - part at beginning not found there
118  if ( index == std::string::npos || ( iName == namePartsVec.begin() && index > 0 ) ) {
119  failed = true;
120  break;
121  }
122  // Increase index by length of found part
123  index += iName->length();
124  }
125  // Failed, if end of name not reached
126  if ( index < iVec->length() && namePartsVec.back().length() != 0 ) failed = true;
127  // Match found!
128  if ( ! failed ) return true;
129  }
130  // No match found!
131  return false;
132 }
133 
134 
135 // Adds a new HLT path or L1 algorithm name
136 void TriggerObjectStandAlone::addPathOrAlgorithm( const std::string & name, bool pathLastFilterAccepted, bool pathL3FilterAccepted )
137 {
138  // Check, if path is already assigned
139  if ( ! hasPathOrAlgorithm( name, false, false ) ) {
140  // The path itself
141  pathNames_.push_back( name );
142  // The corresponding usage of the trigger objects
143  pathLastFilterAccepted_.push_back( pathLastFilterAccepted );
144  pathL3FilterAccepted_.push_back( pathL3FilterAccepted );
145  // Enable status updates
146  } else if ( pathLastFilterAccepted || pathL3FilterAccepted ) {
147  // Search for path
148  unsigned index( 0 );
149  while ( index < pathNames_.size() ) {
150  if ( pathNames_.at( index ) == name ) break;
151  ++index;
152  }
153  // Status update
154  if ( index < pathNames_.size() ) {
155  pathLastFilterAccepted_.at( index ) = pathLastFilterAccepted_.at( index ) || pathLastFilterAccepted;
156  pathL3FilterAccepted_.at( index ) = pathL3FilterAccepted_.at( index ) || pathL3FilterAccepted;
157  }
158  }
159 }
160 
161 
162 // Gets all HLT path or L1 algorithm names
163 std::vector< std::string > TriggerObjectStandAlone::pathsOrAlgorithms( bool pathLastFilterAccepted, bool pathL3FilterAccepted ) const
164 {
165  // Deal with older PAT-tuples, where trigger object usage is not available
166  if ( ! hasLastFilter() ) pathLastFilterAccepted = false;
167  if ( ! hasL3Filter() ) pathL3FilterAccepted = false;
168  // All path names, if usage not restricted (not required or not available)
169  if ( ! pathLastFilterAccepted && ! pathL3FilterAccepted ) return pathNames_;
170  // Temp vector of path names
171  std::vector< std::string > paths;
172  // Loop over usage vector and fill corresponding paths into temp vector
173  for ( unsigned iPath = 0; iPath < pathNames_.size(); ++iPath ) {
174  if ( ( ! pathLastFilterAccepted || pathLastFilterAccepted_.at( iPath ) ) && ( ! pathL3FilterAccepted || pathL3FilterAccepted_.at( iPath ) ) ) paths.push_back( pathNames_.at( iPath ) ); // order matters in order to protect from empty vectors in old data
175  }
176  // Return temp vector
177  return paths;
178 }
179 
180 
181 // Checks, if a certain HLT filter label or L1 condition name is assigned
182 bool TriggerObjectStandAlone::hasFilterOrCondition( const std::string & name ) const
183 {
184  // Move to wild-card parser, if needed
185  if ( name.find( wildcard_ ) != std::string::npos ) return hasAnyName( name, filterLabels_ );
186  // Return, if filter label is assigned
187  return ( std::find( filterLabels_.begin(), filterLabels_.end(), name ) != filterLabels_.end() );
188 }
189 
190 
191 // Checks, if a certain path name is assigned
192 bool TriggerObjectStandAlone::hasPathOrAlgorithm( const std::string & name, bool pathLastFilterAccepted, bool pathL3FilterAccepted ) const
193 {
194  // Move to wild-card parser, if needed
195  if ( name.find( wildcard_ ) != std::string::npos ) return hasAnyName( name, pathsOrAlgorithms( pathLastFilterAccepted, pathL3FilterAccepted ) );
196  // Deal with older PAT-tuples, where trigger object usage is not available
197  if ( ! hasLastFilter() ) pathLastFilterAccepted = false;
198  if ( ! hasL3Filter() ) pathL3FilterAccepted = false;
199  // Check, if path name is assigned at all
200  std::vector< std::string >::const_iterator match( std::find( pathNames_.begin(), pathNames_.end(), name ) );
201  // False, if path name not assigned
202  if ( match == pathNames_.end() ) return false;
203  if ( ! pathLastFilterAccepted && ! pathL3FilterAccepted ) return true;
204  bool foundLastFilter( pathLastFilterAccepted ? pathLastFilterAccepted_.at( match - pathNames_.begin() ) : true );
205  bool foundL3Filter( pathL3FilterAccepted ? pathL3FilterAccepted_.at( match - pathNames_.begin() ) : true );
206  // Return for assigned path name, if trigger object usage meets requirement
207  return ( foundLastFilter && foundL3Filter );
208 }
209 
210 
211 // Methods
212 
213 
214 // Gets the pat::TriggerObject (parent class)
216 {
217  // Create a TriggerObjects
218  TriggerObject theObj( p4(), pdgId() );
219  // Set its collection and trigger objects types (no c'tor for that)
220  theObj.setCollection( collection() );
221  for ( size_t i = 0; i < triggerObjectTypes().size(); ++i ) theObj.addTriggerObjectType( triggerObjectTypes().at( i ) );
222  // Return TriggerObject
223  return theObj;
224 }
225 
226 
227 // Checks, if a certain label of original collection is assigned (method overrides)
228 bool TriggerObjectStandAlone::hasCollection( const std::string & collName ) const
229 {
230  // Move to wild-card parser, if needed only
231  if ( collName.find( wildcard_ ) != std::string::npos ) {
232  // True, if collection name is simply fine
233  if ( hasAnyName( collName, std::vector< std::string >( 1, collection() ) ) ) return true;
234  // Check, if collection name possibly fits in an edm::InputTag approach
235  const edm::InputTag collectionTag( collection() );
236  const edm::InputTag collTag( collName );
237  // If evaluated collection tag contains a process name, it must have been found already by identity check
238  if ( collTag.process().empty() ) {
239  // Check instance ...
240  if ( ( collTag.instance().empty() && collectionTag.instance().empty() ) || hasAnyName( collTag.instance(), std::vector< std::string >( 1, collectionTag.instance() ) ) ) {
241  // ... and label
242  return hasAnyName( collTag.label(), std::vector< std::string >( 1, collectionTag.label() ) );
243  }
244  }
245  return false;
246  }
247  // Use parent class's method otherwise
248  return TriggerObject::hasCollection( collName );
249 }
int i
Definition: DBlmapReader.cc:9
virtual int pdgId() const
PDG identifier.
std::vector< std::string > pathsOrAlgorithms(bool pathLastFilterAccepted, bool pathL3FilterAccepted) const
Gets all HLT path or L1 algorithm names.
size_t size_type
Definition: Candidate.h:31
virtual bool hasCollection(const std::string &collName) const
Checks, if a certain label of original collection is assigned (method overrides)
static const char wildcard_
Constants.
std::vector< std::string > pathNames_
Vector of names of all HLT paths or L1 algorithms the trigger objects has been used in...
std::vector< std::string > filterLabels_
Vector of labels of all HLT filters or names od L1 conditions the trigger objects has been used in...
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
Analysis-level trigger object class.
Definition: TriggerObject.h:49
bool hasAnyName(const std::string &name, const std::vector< std::string > &nameVec) const
Private methods.
void addPathOrAlgorithm(const std::string &name, bool pathLastFilterAccepted, bool pathL3FilterAccepted)
Adds a new HLT path or L1 algorithm name.
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:24
TriggerObject triggerObject()
Gets the pat::TriggerObject (parent class)
void setCollection(const std::string &collName)
Methods.
Definition: TriggerObject.h:86
const std::string & collection() const
Get the label of the collection the trigger object originates from.
Definition: TriggerObject.h:94
TriggerObjectStandAlone()
Constructors and Destructor.
virtual bool hasCollection(const std::string &collName) const
Checks, if a certain label of original collection is assigned.
unsigned int index
Definition: LeafCandidate.h:33
bool hasLastFilter() const
Check, if the usage indicator vectors have been filled.
unsigned int index
index type
Definition: Candidate.h:52
bool hasPathOrAlgorithm(const std::string &name, bool pathLastFilterAccepted, bool pathL3FilterAccepted) const
Checks, if a certain HLT path or L1 algorithm name is assigned.
std::vector< bool > pathL3FilterAccepted_
std::string const & label() const
Definition: InputTag.h:25
std::string const & process() const
Definition: InputTag.h:29
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:27
std::vector< int > triggerObjectTypes() const
Get all trigger object type identifiers.
bool hasFilterOrCondition(const std::string &name) const
Checks, if a certain HLT filter label or L1 condition name is assigned.
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
void addTriggerObjectType(trigger::TriggerObjectType triggerObjectType)
Add a new trigger object type identifier.
Definition: TriggerObject.h:89
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
std::string const & instance() const
Definition: InputTag.h:26
std::vector< bool > pathLastFilterAccepted_
double split
Definition: MVATrainer.cc:139
list at
Definition: asciidump.py:428