Skip to content

Commit

Permalink
Merge pull request #32910 from Sam-Harper/EgTrigSum_1117
Browse files Browse the repository at this point in the history
New HLT DEBUG object: EgTrigSumObj : CMSSW_11_1_X
  • Loading branch information
cmsbuild committed Feb 17, 2021
2 parents cdab7e4 + bae0977 commit d373ee4
Show file tree
Hide file tree
Showing 8 changed files with 673 additions and 0 deletions.
1 change: 1 addition & 0 deletions DataFormats/HLTReco/BuildFile.xml
Expand Up @@ -5,6 +5,7 @@
<use name="DataFormats/L1Trigger"/>
<use name="DataFormats/RecoCandidate"/>
<use name="DataFormats/EgammaCandidates"/>
<use name="DataFormats/EgammaReco"/>
<use name="DataFormats/JetReco"/>
<use name="DataFormats/METReco"/>
<use name="DataFormats/HcalIsolatedTrack"/>
Expand Down
64 changes: 64 additions & 0 deletions DataFormats/HLTReco/interface/EgammaObject.h
@@ -0,0 +1,64 @@
#ifndef DataFormats_HLTReco_EgammaObject_h
#define DataFormats_HLTReco_EgammaObject_h

#include "DataFormats/HLTReco/interface/TriggerObject.h"
#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
#include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"

#include <vector>
#include <string>

namespace reco {
class RecoEcalCandidate;
}

namespace trigger {
class EgammaObject : public TriggerObject {
public:
EgammaObject() : hasPixelMatch_(false) {}

EgammaObject(int id, float pt, float eta, float phi, float mass)
: TriggerObject(id, pt, eta, phi, mass), hasPixelMatch_(false) {}
EgammaObject(const reco::RecoEcalCandidate& ecalCand);

const reco::SuperClusterRef& superCluster() const { return superCluster_; }
const reco::GsfTrackRefVector& gsfTracks() const { return gsfTracks_; }
const reco::ElectronSeedRefVector& seeds() const { return seeds_; }

void setSuperCluster(const reco::SuperClusterRef& sc) { superCluster_ = sc; }
void setGsfTracks(reco::GsfTrackRefVector trks) { gsfTracks_ = std::move(trks); }
void setSeeds(reco::ElectronSeedRefVector seeds);

bool hasVar(const std::string& varName) const;
float var(const std::string& varName, bool raiseExcept = true) const;
const std::vector<std::pair<std::string, float>>& vars() const { return vars_; }
//varNames and varNamesStr are reasonably expensive functions and are more
//intended for debugging than normal use
std::vector<std::string> varNames() const;
std::string varNamesStr() const;
void setVars(std::vector<std::pair<std::string, float>> vars);
void clearVars() { vars_.clear(); }

private:
struct VarComparer {
bool operator()(const std::string& lhs, const std::pair<std::string, float>& rhs) const {
return lhs < rhs.first;
}
bool operator()(const std::pair<std::string, float>& lhs, const std::string& rhs) const {
return lhs.first < rhs;
}
};

bool hasPixelMatch_;
std::vector<std::pair<std::string, float>> vars_;

reco::SuperClusterRef superCluster_;
reco::GsfTrackRefVector gsfTracks_;
//currently these are pixel seeds but could be tracker seeds...
reco::ElectronSeedRefVector seeds_;
};

} // namespace trigger

#endif
19 changes: 19 additions & 0 deletions DataFormats/HLTReco/interface/EgammaObjectFwd.h
@@ -0,0 +1,19 @@
#ifndef DataFormats_HLTReco_EgammaObjectFwd_h
#define DataFormats_HLTReco_EgammaObjectFwd_h

#include <vector>
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/Common/interface/RefVector.h"
#include "DataFormats/Common/interface/RefProd.h"

namespace trigger {
class EgammaObject;

typedef std::vector<EgammaObject> EgammaObjectCollection;
typedef edm::Ref<EgammaObjectCollection> EgammaObjectRef;
typedef edm::RefProd<EgammaObjectCollection> EgammaObjectRefProd;
typedef edm::RefVector<EgammaObjectCollection> EgammaObjectRefVector;
typedef EgammaObjectRefVector::iterator EgammaObjectIterator;
} // namespace trigger

#endif
62 changes: 62 additions & 0 deletions DataFormats/HLTReco/src/EgammaObject.cc
@@ -0,0 +1,62 @@
#include "DataFormats/HLTReco/interface/EgammaObject.h"

#include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
#include "DataFormats/EgammaReco/interface/SuperCluster.h"
#include "DataFormats/EgammaReco/interface/ElectronSeed.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrack.h"

trigger::EgammaObject::EgammaObject(const reco::RecoEcalCandidate& ecalCand)
: TriggerObject(ecalCand), hasPixelMatch_(false), superCluster_(ecalCand.superCluster()) {}

void trigger::EgammaObject::setSeeds(reco::ElectronSeedRefVector seeds) {
seeds_ = std::move(seeds);
hasPixelMatch_ = false;
for (const auto& seed : seeds_) {
if (!seed->hitInfo().empty()) {
hasPixelMatch_ = true;
break;
}
}
}

bool trigger::EgammaObject::hasVar(const std::string& varName) const {
return std::binary_search(vars_.begin(), vars_.end(), varName, VarComparer());
}

float trigger::EgammaObject::var(const std::string& varName, const bool raiseExcept) const {
//here we have a guaranteed sorted vector with unique entries
auto varIt = std::equal_range(vars_.begin(), vars_.end(), varName, VarComparer());
if (varIt.first != varIt.second)
return varIt.first->second;
else if (raiseExcept) {
cms::Exception ex("AttributeError");
ex << " error variable " << varName << " is not present, variables present are " << varNamesStr();
throw ex;
} else {
return std::numeric_limits<float>::max();
}
}

std::vector<std::string> trigger::EgammaObject::varNames() const {
std::vector<std::string> names;
for (const auto& var : vars_) {
names.push_back(var.first);
}
return names;
}

std::string trigger::EgammaObject::varNamesStr() const {
std::string retVal;
auto names = varNames();
for (const auto& name : names) {
if (!retVal.empty())
retVal += " ";
retVal += name;
}
return retVal;
}

void trigger::EgammaObject::setVars(std::vector<std::pair<std::string, float>> vars) {
vars_ = std::move(vars);
std::sort(vars_.begin(), vars_.end(), [](auto& lhs, auto& rhs) { return lhs.first < rhs.first; });
}
1 change: 1 addition & 0 deletions DataFormats/HLTReco/src/classes.h
Expand Up @@ -6,6 +6,7 @@
#include "DataFormats/HLTReco/interface/TriggerEvent.h"
#include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h"
#include "DataFormats/HLTReco/interface/HLTPrescaleTable.h"
#include "DataFormats/HLTReco/interface/EgammaObject.h"
#include "DataFormats/Common/interface/Wrapper.h"

#include "DataFormats/Candidate/interface/CompositeCandidate.h"
Expand Down
12 changes: 12 additions & 0 deletions DataFormats/HLTReco/src/classes_def.xml
Expand Up @@ -89,5 +89,17 @@
<version ClassVersion="10" checksum="2181075001"/>
</class>
<class name="edm::Wrapper<trigger::HLTPrescaleTable>"/>

<class name="trigger::EgammaObject" ClassVersion="3">
<version ClassVersion="3" checksum="2024664439"/>
</class>
<class name="std::vector<trigger::EgammaObject>"/>
<class name="edm::Wrapper<std::vector<trigger::EgammaObject> >"/>
<class name="edm::Ref<std::vector<trigger::EgammaObject>,trigger::EgammaObject,edm::refhelper::FindUsingAdvance<std::vector<trigger::EgammaObject>,trigger::EgammaObject> >"/>
<class name="edm::RefProd<std::vector<trigger::EgammaObject> >"/>
<class name="edm::RefVector<std::vector<trigger::EgammaObject>,trigger::EgammaObject,edm::refhelper::FindUsingAdvance<std::vector<trigger::EgammaObject>,trigger::EgammaObject> >"/>
<class name="edm::Wrapper<edm::RefVector<std::vector<trigger::EgammaObject>,trigger::EgammaObject,edm::refhelper::FindUsingAdvance<std::vector<trigger::EgammaObject>,trigger::EgammaObject> > >"/>
<class name="std::vector<edm::Ref<std::vector<trigger::EgammaObject>,trigger::EgammaObject,edm::refhelper::FindUsingAdvance<std::vector<trigger::EgammaObject>,trigger::EgammaObject> > >"/>
<class name="edm::Wrapper<std::vector<edm::Ref<std::vector<trigger::EgammaObject>,trigger::EgammaObject,edm::refhelper::FindUsingAdvance<std::vector<trigger::EgammaObject>,trigger::EgammaObject> > > >"/>

</lcgdict>

0 comments on commit d373ee4

Please sign in to comment.