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