CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/DataFormats/PatCandidates/src/TriggerObject.cc

Go to the documentation of this file.
00001 //
00002 // $Id: TriggerObject.cc,v 1.12 2010/12/20 20:05:52 vadler Exp $
00003 //
00004 
00005 #include "DataFormats/PatCandidates/interface/TriggerObject.h"
00006 
00007 #include "FWCore/Utilities/interface/EDMException.h"
00008 
00009 
00010 using namespace pat;
00011 
00012 
00013 // Constructors and Destructor
00014 
00015 
00016 // Default constructor
00017 TriggerObject::TriggerObject() :
00018   reco::LeafCandidate()
00019 {
00020   triggerObjectTypes_.clear();
00021 }
00022 
00023 
00024 // Constructor from trigger::TriggerObject
00025 TriggerObject::TriggerObject( const trigger::TriggerObject & trigObj ) :
00026   reco::LeafCandidate( 0, trigObj.particle().p4(), reco::Particle::Point( 0., 0., 0. ), trigObj.id() ),
00027   refToOrig_()
00028 {
00029   triggerObjectTypes_.clear();
00030 }
00031 
00032 
00033 // Constructors from base class object
00034 TriggerObject::TriggerObject( const reco::LeafCandidate & leafCand ) :
00035   reco::LeafCandidate( leafCand ),
00036   refToOrig_()
00037 {
00038   triggerObjectTypes_.clear();
00039 }
00040 
00041 
00042 // Constructors from base candidate reference (for 'l1extra' particles)
00043 TriggerObject::TriggerObject( const reco::CandidateBaseRef & candRef ) :
00044   reco::LeafCandidate( *candRef ),
00045   refToOrig_( candRef )
00046 {
00047   triggerObjectTypes_.clear();
00048 }
00049 
00050 
00051 // Constructors from Lorentz-vectors and (optional) PDG ID
00052 TriggerObject::TriggerObject( const reco::Particle::LorentzVector & vec, int id ) :
00053   reco::LeafCandidate( 0, vec, reco::Particle::Point( 0., 0., 0. ), id ),
00054   refToOrig_()
00055 {
00056   triggerObjectTypes_.clear();
00057 }
00058 TriggerObject::TriggerObject( const reco::Particle::PolarLorentzVector & vec, int id ) :
00059   reco::LeafCandidate( 0, vec, reco::Particle::Point( 0., 0., 0. ), id ),
00060   refToOrig_()
00061 {
00062   triggerObjectTypes_.clear();
00063 }
00064 
00065 
00066 // Methods
00067 
00068 
00069 // Get all trigger object type identifiers
00070 std::vector< int > TriggerObject::triggerObjectTypes() const
00071 {
00072   std::vector< int > triggerObjectTypes;
00073   for ( size_t iTo = 0; iTo < triggerObjectTypes_.size(); ++iTo ) {
00074     triggerObjectTypes.push_back( triggerObjectTypes_.at( iTo ) );
00075   }
00076   return triggerObjectTypes;
00077 }
00078 
00079 
00080 // Checks, if a certain label of original collection is assigned
00081 bool TriggerObject::hasCollection( const std::string & collName ) const
00082 {
00083   // True, if collection name is simply fine
00084   if ( collName == collection_ ) return true;
00085   // Check, if collection name possibly fits in an edm::InputTag approach
00086   const edm::InputTag collectionTag( collection_ );
00087   const edm::InputTag collTag( collName );
00088   // If evaluated collection tag contains a process name, it must have been found already by identity check
00089   if ( collTag.process().empty() ) {
00090     // Check instance ...
00091     if ( ( collTag.instance().empty() && collectionTag.instance().empty() ) || collTag.instance() == collectionTag.instance() ) {
00092       // ... and label
00093       return ( collTag.label() == collectionTag.label() );
00094     }
00095   }
00096   return false;
00097 }
00098 
00099 
00100 // Checks, if a certain trigger object type identifier is assigned
00101 bool TriggerObject::hasTriggerObjectType( trigger::TriggerObjectType triggerObjectType ) const
00102 {
00103   for ( size_t iF = 0; iF < triggerObjectTypes_.size(); ++iF ) {
00104     if ( triggerObjectType == triggerObjectTypes_.at( iF ) ) return true;
00105   }
00106   return false;
00107 }
00108 
00109 
00110 // Special methods for 'l1extra' particles
00111 
00112 
00113 // Getters specific to the 'l1extra' particle types
00114 // Exceptions of type 'edm::errors::InvalidReference' are thrown,
00115 // if wrong particle type is requested
00116 
00117 // EM
00118 const l1extra::L1EmParticleRef TriggerObject::origL1EmRef() const
00119 {
00120   l1extra::L1EmParticleRef l1Ref;
00121   try {
00122     l1Ref = origObjRef().castTo< l1extra::L1EmParticleRef >();
00123   } catch ( edm::Exception X ) {
00124     if ( X.categoryCode() != edm::errors::InvalidReference ) throw X;
00125   }
00126   return l1Ref;
00127 }
00128 
00129 // EtMiss
00130 const l1extra::L1EtMissParticleRef TriggerObject::origL1EtMissRef() const
00131 {
00132   l1extra::L1EtMissParticleRef l1Ref;
00133   try {
00134     l1Ref = origObjRef().castTo< l1extra::L1EtMissParticleRef >();
00135   } catch ( edm::Exception X ) {
00136     if ( X.categoryCode() != edm::errors::InvalidReference ) throw X;
00137   }
00138   return l1Ref;
00139 }
00140 
00141 // Jet
00142 const l1extra::L1JetParticleRef TriggerObject::origL1JetRef() const
00143 {
00144   l1extra::L1JetParticleRef l1Ref;
00145   try {
00146     l1Ref = origObjRef().castTo< l1extra::L1JetParticleRef >();
00147   } catch ( edm::Exception X ) {
00148     if ( X.categoryCode() != edm::errors::InvalidReference ) throw X;
00149   }
00150   return l1Ref;
00151 }
00152 
00153 // Muon
00154 const l1extra::L1MuonParticleRef TriggerObject::origL1MuonRef() const
00155 {
00156   l1extra::L1MuonParticleRef l1Ref;
00157   try {
00158     l1Ref = origObjRef().castTo< l1extra::L1MuonParticleRef >();
00159   } catch ( edm::Exception X ) {
00160     if ( X.categoryCode() != edm::errors::InvalidReference ) throw X;
00161   }
00162   return l1Ref;
00163 }