Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:27

0001 //
0002 //
0003 
0004 #include "DataFormats/PatCandidates/interface/TriggerObject.h"
0005 
0006 #include "FWCore/Utilities/interface/EDMException.h"
0007 
0008 using namespace pat;
0009 
0010 // Constructors and Destructor
0011 
0012 // Default constructor
0013 TriggerObject::TriggerObject() : reco::LeafCandidate() { triggerObjectTypes_.clear(); }
0014 
0015 // Constructor from trigger::TriggerObject
0016 TriggerObject::TriggerObject(const trigger::TriggerObject& trigObj)
0017     : reco::LeafCandidate(0, trigObj.particle().p4(), reco::Particle::Point(0., 0., 0.), trigObj.id()), refToOrig_() {
0018   triggerObjectTypes_.clear();
0019 }
0020 
0021 // Constructors from base class object
0022 TriggerObject::TriggerObject(const reco::LeafCandidate& leafCand) : reco::LeafCandidate(leafCand), refToOrig_() {
0023   triggerObjectTypes_.clear();
0024 }
0025 
0026 // Constructors from base candidate reference (for 'l1extra' particles)
0027 TriggerObject::TriggerObject(const reco::CandidateBaseRef& candRef)
0028     : reco::LeafCandidate(*candRef), refToOrig_(candRef) {
0029   triggerObjectTypes_.clear();
0030 }
0031 
0032 // Constructors from Lorentz-vectors and (optional) PDG ID
0033 TriggerObject::TriggerObject(const reco::Particle::LorentzVector& vec, int id)
0034     : reco::LeafCandidate(0, vec, reco::Particle::Point(0., 0., 0.), id), refToOrig_() {
0035   triggerObjectTypes_.clear();
0036 }
0037 TriggerObject::TriggerObject(const reco::Particle::PolarLorentzVector& vec, int id)
0038     : reco::LeafCandidate(0, vec, reco::Particle::Point(0., 0., 0.), id), refToOrig_() {
0039   triggerObjectTypes_.clear();
0040 }
0041 
0042 // Methods
0043 
0044 // Get all trigger object type identifiers
0045 std::vector<int> TriggerObject::triggerObjectTypes() const {
0046   std::vector<int> triggerObjectTypes;
0047   for (size_t iTo = 0; iTo < triggerObjectTypes_.size(); ++iTo) {
0048     triggerObjectTypes.push_back(triggerObjectTypes_.at(iTo));
0049   }
0050   return triggerObjectTypes;
0051 }
0052 
0053 // Checks, if a certain label of original collection is assigned
0054 bool TriggerObject::hasCollection(const std::string& collName) const {
0055   // True, if collection name is simply fine
0056   if (collName == collection_)
0057     return true;
0058   // Check, if collection name possibly fits in an edm::InputTag approach
0059   const edm::InputTag collectionTag(collection_);
0060   const edm::InputTag collTag(collName);
0061   // If evaluated collection tag contains a process name, it must have been found already by identity check
0062   if (collTag.process().empty()) {
0063     // Check instance ...
0064     if ((collTag.instance().empty() && collectionTag.instance().empty()) ||
0065         collTag.instance() == collectionTag.instance()) {
0066       // ... and label
0067       return (collTag.label() == collectionTag.label());
0068     }
0069   }
0070   return false;
0071 }
0072 
0073 // Checks, if a certain trigger object type identifier is assigned
0074 bool TriggerObject::hasTriggerObjectType(trigger::TriggerObjectType triggerObjectType) const {
0075   for (size_t iF = 0; iF < triggerObjectTypes_.size(); ++iF) {
0076     if (triggerObjectType == triggerObjectTypes_.at(iF))
0077       return true;
0078   }
0079   return false;
0080 }
0081 
0082 // Special methods for 'l1extra' particles
0083 
0084 // Getters specific to the 'l1extra' particle types
0085 // Exceptions of type 'edm::errors::InvalidReference' are thrown,
0086 // if wrong particle type is requested
0087 
0088 // EM
0089 const l1extra::L1EmParticleRef TriggerObject::origL1EmRef() const {
0090   l1extra::L1EmParticleRef l1Ref;
0091   try {
0092     l1Ref = origObjRef().castTo<l1extra::L1EmParticleRef>();
0093   } catch (edm::Exception const& X) {
0094     if (X.categoryCode() != edm::errors::InvalidReference)
0095       throw X;
0096   }
0097   return l1Ref;
0098 }
0099 
0100 // EtMiss
0101 const l1extra::L1EtMissParticleRef TriggerObject::origL1EtMissRef() const {
0102   l1extra::L1EtMissParticleRef l1Ref;
0103   try {
0104     l1Ref = origObjRef().castTo<l1extra::L1EtMissParticleRef>();
0105   } catch (edm::Exception const& X) {
0106     if (X.categoryCode() != edm::errors::InvalidReference)
0107       throw X;
0108   }
0109   return l1Ref;
0110 }
0111 
0112 // Jet
0113 const l1extra::L1JetParticleRef TriggerObject::origL1JetRef() const {
0114   l1extra::L1JetParticleRef l1Ref;
0115   try {
0116     l1Ref = origObjRef().castTo<l1extra::L1JetParticleRef>();
0117   } catch (edm::Exception const& X) {
0118     if (X.categoryCode() != edm::errors::InvalidReference)
0119       throw X;
0120   }
0121   return l1Ref;
0122 }
0123 
0124 // Muon
0125 const l1extra::L1MuonParticleRef TriggerObject::origL1MuonRef() const {
0126   l1extra::L1MuonParticleRef l1Ref;
0127   try {
0128     l1Ref = origObjRef().castTo<l1extra::L1MuonParticleRef>();
0129   } catch (edm::Exception const& X) {
0130     if (X.categoryCode() != edm::errors::InvalidReference)
0131       throw X;
0132   }
0133   return l1Ref;
0134 }