Skip to content

Commit

Permalink
Merge pull request #32968 from Sam-Harper/HGCALRegDevBranch_111X
Browse files Browse the repository at this point in the history
Adding HGCAL SuperCluster Regressions : 111X
  • Loading branch information
cmsbuild committed Feb 26, 2021
2 parents d373ee4 + 4182450 commit 9ceba50
Show file tree
Hide file tree
Showing 13 changed files with 848 additions and 509 deletions.
2 changes: 1 addition & 1 deletion Configuration/AlCa/python/autoCond.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
# GlobalTag for MC production with realistic conditions for Phase1 2024
'phase1_2024_realistic' : '111X_mcRun3_2024_realistic_v7', # GT containing realistic conditions for Phase1 2024
# GlobalTag for MC production with realistic conditions for Phase2
'phase2_realistic' : '111X_mcRun4_realistic_T15_v4'
'phase2_realistic' : '111X_mcRun4_realistic_T15_v5'
}

aliases = {
Expand Down
2 changes: 2 additions & 0 deletions DataFormats/Common/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,14 @@
<class name="edm::ValueMap<float>" />
<class name="edm::ValueMap<double>" />
<class name="edm::ValueMap<std::pair<float, float>>" />
<class name="edm::ValueMap<std::vector<float>>" />
<class name="edm::Wrapper<edm::ValueMap<int> >" splitLevel="0"/>
<class name="edm::Wrapper<edm::ValueMap<bool> >" splitLevel="0"/>
<class name="edm::Wrapper<edm::ValueMap<unsigned int> >" splitLevel="0"/>
<class name="edm::Wrapper<edm::ValueMap<float> >" splitLevel="0"/>
<class name="edm::Wrapper<edm::ValueMap<double> >" splitLevel="0"/>
<class name="edm::Wrapper<edm::ValueMap<std::pair<float, float>> >" splitLevel="0"/>
<class name="edm::Wrapper<edm::ValueMap<std::vector<float>> >" splitLevel="0"/>
<class name="std::vector<edm::EventAuxiliary>"/>
<class name="edm::Wrapper<std::vector<edm::EventAuxiliary> >"/>
<class name="edm::Wrapper<std::vector<edm::ErrorSummaryEntry> >"/>
Expand Down
3 changes: 3 additions & 0 deletions RecoEcal/EgammaClusterAlgos/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
<use name="DataFormats/EcalRecHit"/>
<use name="DataFormats/EgammaReco"/>
<use name="DataFormats/Math"/>
<use name="DataFormats/ParticleFlowReco"/>
<use name="DataFormats/VertexReco"/>
<use name="CondFormats/ESObjects"/>
<use name="CondFormats/EgammaObjects"/>
<use name="CondFormats/DataRecord"/>
<use name="RecoEcal/EgammaCoreTools"/>
<use name="Geometry/CaloGeometry"/>
<use name="Geometry/CaloTopology"/>
<use name="RecoEgamma/EgammaTools"/>
<use name="RecoParticleFlow/PFClusterTools"/>
<use name="clhep"/>
<export>
Expand Down
179 changes: 142 additions & 37 deletions RecoEcal/EgammaClusterAlgos/interface/SCEnergyCorrectorSemiParm.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,176 @@
//
// Helper Class for applying regression-based energy corrections with optimized BDT implementation
//
// Authors: J.Bendavid
// Original Author: J.Bendavid
//
// Refactored, modernised and extended to HGCAL by S. Harper (RAL/CERN)
// with input from S. Bhattacharya (DESY)
//--------------------------------------------------------------------------------------------------

#ifndef RecoEcal_EgammaClusterAlgos_SCEnergyCorrectorSemiParm_h
#define RecoEcal_EgammaClusterAlgos_SCEnergyCorrectorSemiParm_h

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"

#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "CondFormats/EgammaObjects/interface/GBRForestD.h"
#include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
#include "Geometry/CaloTopology/interface/CaloTopology.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "DataFormats/EgammaReco/interface/SuperCluster.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
#include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
#include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "CondFormats/EgammaObjects/interface/GBRForestD.h"
#include "CondFormats/DataRecord/interface/GBRDWrapperRcd.h"
#include "RecoEgamma/EgammaTools/interface/EgammaBDTOutputTransformer.h"
#include "RecoEgamma/EgammaTools/interface/HGCalShowerShapeHelper.h"

class SCEnergyCorrectorSemiParm {
public:
SCEnergyCorrectorSemiParm();
~SCEnergyCorrectorSemiParm();
//if you want override the default on where conditions are consumed, you need to use
//the other constructor and then call setTokens approprately
SCEnergyCorrectorSemiParm(const edm::ParameterSet& iConfig, edm::ConsumesCollector cc);

static void fillPSetDescription(edm::ParameterSetDescription& desc);
static edm::ParameterSetDescription makePSetDescription();

template <edm::Transition tr = edm::Transition::BeginLuminosityBlock>
void setTokens(const edm::ParameterSet& iConfig, edm::ConsumesCollector cc);

void setEventSetup(const edm::EventSetup& es);
void setEvent(const edm::Event& e);

std::pair<double, double> getCorrections(const reco::SuperCluster& sc) const;
void modifyObject(reco::SuperCluster& sc) const;

std::vector<float> getRegData(const reco::SuperCluster& sc) const;

private:
class RegParam {
public:
RegParam(std::string meanKey = "",
float meanLow = 0,
float meanHigh = 0,
std::string sigmaKey = "",
float sigmaLow = 0,
float sigmaHigh = 0)
: meanKey_(std::move(meanKey)),
sigmaKey_(std::move(sigmaKey)),
meanOutTrans_(meanLow, meanHigh),
sigmaOutTrans_(sigmaLow, sigmaHigh) {}
RegParam(edm::ConsumesCollector cc,
std::string meanKey = "",
float meanLow = 0,
float meanHigh = 0,
std::string sigmaKey = "",
float sigmaLow = 0,
float sigmaHigh = 0)
: RegParam(meanKey, meanLow, meanHigh, sigmaKey, sigmaLow, sigmaHigh) {
setTokens(cc);
}
template <edm::Transition esTransition = edm::Transition::BeginLuminosityBlock>
void setTokens(edm::ConsumesCollector cc);
void setForests(const edm::EventSetup& setup);

double mean(const std::vector<float>& data) const;
double sigma(const std::vector<float>& data) const;

void setTokens(const edm::ParameterSet &iConfig, edm::ConsumesCollector &cc);
private:
std::string meanKey_;
std::string sigmaKey_;
EgammaBDTOutputTransformer meanOutTrans_;
EgammaBDTOutputTransformer sigmaOutTrans_;
const GBRForestD* meanForest_;
const GBRForestD* sigmaForest_;
edm::ESGetToken<GBRForestD, GBRDWrapperRcd> meanForestToken_;
edm::ESGetToken<GBRForestD, GBRDWrapperRcd> sigmaForestToken_;
};

std::pair<double, double> getCorrections(const reco::SuperCluster &sc) const;
void modifyObject(reco::SuperCluster &sc);
//returns barrel for ecal barrel, otherwise returns endcap
const RegParam& getRegParam(const DetId& detId) const {
return detId.det() == DetId::Ecal && detId.subdetId() == EcalBarrel ? regParamBarrel_ : regParamEndcap_;
}

void setEventSetup(const edm::EventSetup &es);
void setEvent(const edm::Event &e);
std::vector<float> getRegDataECALV1(const reco::SuperCluster& sc) const;
std::vector<float> getRegDataECALHLTV1(const reco::SuperCluster& sc) const;
std::vector<float> getRegDataHGCALV1(const reco::SuperCluster& sc) const;
std::vector<float> getRegDataHGCALHLTV1(const reco::SuperCluster& sc) const;

protected:
const GBRForestD *foresteb_;
const GBRForestD *forestee_;
const GBRForestD *forestsigmaeb_;
const GBRForestD *forestsigmaee_;
//barrel = always ecal barrel, endcap may be ECAL or HGCAL
RegParam regParamBarrel_;
RegParam regParamEndcap_;

edm::ESHandle<CaloTopology> calotopo_;
edm::ESHandle<CaloGeometry> calogeom_;
const CaloTopology* caloTopo_;
const CaloGeometry* caloGeom_;
edm::ESGetToken<CaloTopology, CaloTopologyRecord> caloTopoToken_;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeomToken_;

edm::EDGetTokenT<EcalRecHitCollection> tokenEBRecHits_;
edm::EDGetTokenT<EcalRecHitCollection> tokenEERecHits_;
edm::EDGetTokenT<reco::PFRecHitCollection> tokenHgcalRecHits_;
edm::EDGetTokenT<reco::VertexCollection> tokenVertices_;

edm::Handle<EcalRecHitCollection> recHitsEB_;
edm::Handle<EcalRecHitCollection> recHitsEE_;
edm::Handle<reco::PFRecHitCollection> recHitsHgcal_;
edm::Handle<reco::VertexCollection> vertices_;
edm::Handle<EcalRecHitCollection> rechitsEB_;
edm::Handle<EcalRecHitCollection> rechitsEE_;

edm::InputTag ecalHitsEBInputTag_;
edm::InputTag ecalHitsEEInputTag_;
edm::InputTag vertexInputTag_;

std::string regressionKeyEB_;
std::string uncertaintyKeyEB_;
std::string regressionKeyEE_;
std::string uncertaintyKeyEE_;

private:
bool isHLT_;
bool isPhaseII_;
bool applySigmaIetaIphiBug_; //there was a bug in sigmaIetaIphi for the 74X application
int nHitsAboveThreshold_;
float eThreshold_;
int nHitsAboveThresholdEB_;
int nHitsAboveThresholdEE_;
int nHitsAboveThresholdHG_;
float hitsEnergyThreshold_;
float hgcalCylinderR_;
HGCalShowerShapeHelper hgcalShowerShapes_;
};

template <edm::Transition esTransition>
void SCEnergyCorrectorSemiParm::RegParam::setTokens(edm::ConsumesCollector cc) {
meanForestToken_ = cc.esConsumes<GBRForestD, GBRDWrapperRcd, esTransition>(edm::ESInputTag("", meanKey_));
sigmaForestToken_ = cc.esConsumes<GBRForestD, GBRDWrapperRcd, esTransition>(edm::ESInputTag("", sigmaKey_));
}

template <edm::Transition esTransition>
void SCEnergyCorrectorSemiParm::setTokens(const edm::ParameterSet& iConfig, edm::ConsumesCollector cc) {
isHLT_ = iConfig.getParameter<bool>("isHLT");
isPhaseII_ = iConfig.getParameter<bool>("isPhaseII");
applySigmaIetaIphiBug_ = iConfig.getParameter<bool>("applySigmaIetaIphiBug");
tokenEBRecHits_ = cc.consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("ecalRecHitsEB"));
if (not isPhaseII_) {
tokenEERecHits_ = cc.consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("ecalRecHitsEE"));
} else {
tokenHgcalRecHits_ = cc.consumes<reco::PFRecHitCollection>(iConfig.getParameter<edm::InputTag>("hgcalRecHits"));
hgcalCylinderR_ = iConfig.getParameter<double>("hgcalCylinderR");
hgcalShowerShapes_.setTokens<esTransition>(cc);
}
caloGeomToken_ = cc.esConsumes<CaloGeometry, CaloGeometryRecord, esTransition>();
caloTopoToken_ = cc.esConsumes<CaloTopology, CaloTopologyRecord, esTransition>();

regParamBarrel_ = RegParam(iConfig.getParameter<std::string>("regressionKeyEB"),
iConfig.getParameter<double>("regressionMinEB"),
iConfig.getParameter<double>("regressionMaxEB"),
iConfig.getParameter<std::string>("uncertaintyKeyEB"),
iConfig.getParameter<double>("uncertaintyMinEB"),
iConfig.getParameter<double>("uncertaintyMaxEB"));
regParamBarrel_.setTokens<esTransition>(cc);
regParamEndcap_ = RegParam(iConfig.getParameter<std::string>("regressionKeyEE"),
iConfig.getParameter<double>("regressionMinEE"),
iConfig.getParameter<double>("regressionMaxEE"),
iConfig.getParameter<std::string>("uncertaintyKeyEE"),
iConfig.getParameter<double>("uncertaintyMinEE"),
iConfig.getParameter<double>("uncertaintyMaxEE"));
regParamEndcap_.setTokens<esTransition>(cc);
hitsEnergyThreshold_ = iConfig.getParameter<double>("eRecHitThreshold");
if (not isHLT_) {
tokenVertices_ = cc.consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexCollection"));
}
}
#endif

0 comments on commit 9ceba50

Please sign in to comment.