OffHelper

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
#ifndef DQMOFFLINE_TRIGGER_EGHLTOFFHELPER
#define DQMOFFLINE_TRIGGER_EGHLTOFFHELPER

//class: EgHLTOffHelper (Egamma HLT offline helper)
//
//author: Sam Harper (July 2008)
//
//
//aim: to hide temporary place holder code away from the rest of the system
//
//implimentation: currently no isolation producers or electron selection cut meets my needs
//                while I would like to use a central tool, for now I'm cludging my own as
//                placeholders

#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/Common/interface/TriggerResults.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
#include "DataFormats/EgammaCandidates/interface/Photon.h"
#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"

#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
#include "DataFormats/JetReco/interface/CaloJet.h"
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
#include "DataFormats/CaloTowers/interface/CaloTower.h"
#include "DataFormats/CaloTowers/interface/CaloTowerDefs.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"

#include "DQMOffline/Trigger/interface/EgHLTOffEvt.h"
#include "DQMOffline/Trigger/interface/EgHLTOffEle.h"
#include "DQMOffline/Trigger/interface/EgHLTOffPho.h"
#include "DQMOffline/Trigger/interface/EgHLTOffEgSel.h"
#include "DQMOffline/Trigger/interface/EgHLTTrigCodes.h"

#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "Geometry/Records/interface/CaloTopologyRecord.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "Geometry/CaloTopology/interface/CaloTopology.h"

#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
#include "MagneticField/Engine/interface/MagneticField.h"

#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"

#include "CondFormats/EcalObjects/interface/EcalPFRecHitThresholds.h"
#include "CondFormats/DataRecord/interface/EcalPFRecHitThresholdsRcd.h"

class EgammaHLTTrackIsolation;
class HLTConfigProvider;
class EcalSeverityLevelAlgo;
class EcalSeverityLevelAlgoRcd;

namespace egHLT {

  class OffHelper {
  private:
    OffEgSel eleLooseCuts_;  //loose selection cuts (loose has no relation to other 'loose' cuts)
    OffEgSel eleCuts_;       //normal selection cuts
    OffEgSel phoLooseCuts_;  //loose selection cuts (loose has no relation to other 'loose' cuts)
    OffEgSel phoCuts_;       //normal selection cuts

    std::vector<std::pair<TrigCodes::TrigBitSet, OffEgSel> > trigCuts_;  //non sorted vector (for now)

    edm::EDGetTokenT<EcalRecHitCollection> ecalRecHitsEBToken;
    edm::EDGetTokenT<EcalRecHitCollection> ecalRecHitsEEToken;
    edm::EDGetTokenT<reco::CaloJetCollection> caloJetsToken;
    edm::EDGetTokenT<reco::TrackCollection> isolTrkToken;
    edm::EDGetTokenT<HBHERecHitCollection> hbheHitsToken;
    edm::EDGetTokenT<HFRecHitCollection> hfHitsToken;
    edm::EDGetTokenT<trigger::TriggerEvent> triggerSummaryToken;
    edm::EDGetTokenT<reco::GsfElectronCollection> electronsToken;
    edm::EDGetTokenT<reco::PhotonCollection> photonsToken;
    edm::EDGetTokenT<reco::BeamSpot> beamSpotToken;
    edm::EDGetTokenT<CaloTowerCollection> caloTowersToken;
    edm::EDGetTokenT<edm::TriggerResults> trigResultsToken;
    edm::EDGetTokenT<reco::VertexCollection> vertexToken;

    edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeomToken_;
    edm::ESGetToken<CaloTopology, CaloTopologyRecord> caloTopoToken_;
    edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magFieldToken_;
    edm::ESGetToken<EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd> ecalSeverityToken_;

    edm::ESHandle<CaloGeometry> caloGeom_;
    edm::ESHandle<CaloTopology> caloTopology_;
    edm::ESHandle<MagneticField> magField_;
    edm::ESHandle<EcalSeverityLevelAlgo> ecalSeverityLevel_;

    edm::Handle<EcalRecHitCollection> ebRecHits_;
    edm::Handle<EcalRecHitCollection> eeRecHits_;
    edm::Handle<HFRecHitCollection> hfHits_;
    edm::Handle<HBHERecHitCollection> hbheHits_;
    edm::Handle<reco::TrackCollection> isolTrks_;

    edm::Handle<trigger::TriggerEvent> trigEvt_;
    edm::Handle<reco::PhotonCollection> recoPhos_;
    edm::Handle<reco::GsfElectronCollection> recoEles_;
    edm::Handle<std::vector<reco::CaloJet> > recoJets_;

    edm::Handle<reco::BeamSpot> beamSpot_;
    edm::Handle<CaloTowerCollection> caloTowers_;

    edm::Handle<edm::TriggerResults> trigResults_;

    edm::Handle<reco::VertexCollection> recoVertices_;

    std::string hltTag_;
    std::vector<std::string> hltFiltersUsed_;
    std::vector<std::pair<std::string, int> >
        hltFiltersUsedWithNrCandsCut_;  //stores the filter name + number of candidates required to pass that filter for it to accept
    std::vector<std::pair<std::string, std::string> >
        l1PreAndSeedFilters_;                      //filter names of a l1 prescaler and the corresponding l1 seed filter
    std::vector<std::string> l1PreScaledPaths_;    //l1 pre-scaled path names
    std::vector<std::string> l1PreScaledFilters_;  //l1 pre scale filters

    //allow us to recompute e/gamma HLT isolations (note we also have em and hcal but they have to be declared for every event)
    //which is awkward and I havent thought of a good way around it yet
    EgammaHLTTrackIsolation* hltEleTrkIsolAlgo_;
    EgammaHLTTrackIsolation* hltPhoTrkIsolAlgo_;

    //our hlt isolation parameters...
    //ecal
    double hltEMIsolOuterCone_;
    double hltEMIsolInnerConeEB_;
    double hltEMIsolEtaSliceEB_;
    double hltEMIsolEtMinEB_;
    double hltEMIsolEMinEB_;
    double hltEMIsolInnerConeEE_;
    double hltEMIsolEtaSliceEE_;
    double hltEMIsolEtMinEE_;
    double hltEMIsolEMinEE_;
    //tracker
    double hltPhoTrkIsolPtMin_;
    double hltPhoTrkIsolOuterCone_;
    double hltPhoTrkIsolInnerCone_;
    double hltPhoTrkIsolZSpan_;
    double hltPhoTrkIsolRSpan_;
    bool hltPhoTrkIsolCountTrks_;
    double hltEleTrkIsolPtMin_;
    double hltEleTrkIsolOuterCone_;
    double hltEleTrkIsolInnerCone_;
    double hltEleTrkIsolZSpan_;
    double hltEleTrkIsolRSpan_;
    //hcal
    double hltHadIsolOuterCone_;
    double hltHadIsolInnerCone_;
    double hltHadIsolEtMin_;
    int hltHadIsolDepth_;
    //flags to disable calculations if same as reco (saves time)
    bool calHLTHcalIsol_;
    bool calHLTEmIsol_;
    bool calHLTEleTrkIsol_;
    bool calHLTPhoTrkIsol_;

    std::vector<edm::ParameterSet> trigCutParams_;  //probably the least bad option

  public:
    OffHelper()
        : eleLooseCuts_(),
          eleCuts_(),
          phoLooseCuts_(),
          phoCuts_(),
          hltEleTrkIsolAlgo_(nullptr),
          hltPhoTrkIsolAlgo_(nullptr) {}
    OffHelper& operator=(const OffHelper&) = delete;
    OffHelper(const OffHelper&) = delete;
    ~OffHelper();

    void setup(const edm::ParameterSet& conf, edm::ConsumesCollector&& iC);
    void setupTriggers(const HLTConfigProvider& config,
                       const std::vector<std::string>& hltFiltersUsed,
                       const TrigCodes& trigCodes);

    //int is the error code, 0 = no error
    //it should never throw, print to screen or crash, this is the only error reporting it does
    int makeOffEvt(const edm::Event& edmEvent,
                   const edm::EventSetup& setup,
                   egHLT::OffEvt& offEvent,
                   const TrigCodes& trigCodes);

    int getHandles(const edm::Event& event, const edm::EventSetup& setup);
    int fillOffEleVec(std::vector<OffEle>& offEles);
    int fillOffPhoVec(std::vector<OffPho>& offPhos);
    int setTrigInfo(const edm::Event& edmEvent, egHLT::OffEvt& offEvent, const TrigCodes& trigCodes);

    void fillIsolData(const reco::GsfElectron& ele, OffEle::IsolData& isolData);
    void fillClusShapeData(const reco::GsfElectron& ele, OffEle::ClusShapeData& clusShapeData);
    void fillHLTData(const reco::GsfElectron& ele, OffEle::HLTData& hltData);

    void fillIsolData(const reco::Photon& pho, OffPho::IsolData& isolData);
    void fillClusShapeData(const reco::Photon& pho, OffPho::ClusShapeData& clusShapeData);
    void fillHLTDataPho(const reco::Photon& pho, OffPho::HLTData& hltData);

    //tempory debugging functions
    const trigger::TriggerEvent* trigEvt() const { return trigEvt_.product(); }
    const std::vector<std::pair<TrigCodes::TrigBitSet, OffEgSel> >& trigCuts() const { return trigCuts_; }

    template <class T>
    static bool getHandle(const edm::Event& event, const edm::EDGetTokenT<T>& token, edm::Handle<T>& handle);

    const EcalPFRecHitThresholds* thresholds = nullptr;
  };

  template <class T>
  bool OffHelper::getHandle(const edm::Event& event, const edm::EDGetTokenT<T>& token, edm::Handle<T>& handle) {
    bool success = event.getByToken(token, handle);
    return success && handle.product();
  }
}  // namespace egHLT

#endif