Skip to content

Commit

Permalink
Merge pull request #7941 from diguida/autoCond_733
Browse files Browse the repository at this point in the history
Backport of ecal pfcluster corrections to 73x on top of new GT
  • Loading branch information
cmsbuild committed Mar 2, 2015
2 parents 740bd8e + 1cd5431 commit d54f7f6
Show file tree
Hide file tree
Showing 13 changed files with 406 additions and 125 deletions.
18 changes: 9 additions & 9 deletions Configuration/AlCa/python/autoCond.py
Expand Up @@ -2,23 +2,23 @@

### NEW KEYS ###
# GlobalTag for MC production with perfectly aligned and calibrated detector for Run1
'run1_design' : 'DESRUN1_73_V2::All',
'run1_design' : 'DESRUN1_73_V5::All',
# GlobalTag for MC production (pp collisions) with realistic alignment and calibrations for Run1
'run1_mc' : 'MCRUN1_73_V2::All',
'run1_mc' : 'MCRUN1_73_V5::All',
# GlobalTag for MC production (Heavy Ions collisions) with realistic alignment and calibrations for Run1
'run1_mc_hi' : 'MCHI1_73_V2::All',
'run1_mc_hi' : 'MCHI1_73_V5::All',
# GlobalTag for MC production (p-Pb collisions) with realistic alignment and calibrations for Run1
'run1_mc_pa' : 'MCPA1_73_V2::All',
'run1_mc_pa' : 'MCPA1_73_V5::All',
# GlobalTag for MC production with perfectly aligned and calibrated detector for Run2
'run2_design' : 'DESRUN2_73_V3::All',
'run2_design' : 'DESRUN2_73_V6::All',
# GlobalTag for MC production with pessimistic alignment and calibrations for Run2
'run2_mc_50ns' : 'MCRUN2_73_V6::All',
'run2_mc_50ns' : 'MCRUN2_73_V12::All',
#GlobalTag for MC production with optimistic alignment and calibrations for Run2
'run2_mc' : 'MCRUN2_73_V7::All',
'run2_mc' : 'MCRUN2_73_V13::All',
# GlobalTag for Run1 data reprocessing
'run1_data' : 'GR_R_73_V0A::All',
'run1_data' : 'GR_R_73_V2A::All',
# GlobalTag for Run2 data reprocessing
'run2_data' : 'GR_R_73_V1A::All',
'run2_data' : 'GR_R_73_V3A::All',
# GlobalTag for Run1 HLT: it points to the online GT and overrides the connection string and pfnPrefix for use offline
'run1_hlt' : 'GR_H_V43A::All,frontier://FrontierProd/CMS_COND_31X_GLOBALTAG,frontier://FrontierProd/',
# GlobalTag for Run2 HLT: it points to the online GT and overrides the connection string and pfnPrefix for use offline
Expand Down
18 changes: 9 additions & 9 deletions Configuration/AlCa/python/autoCond_condDBv2.py
Expand Up @@ -2,23 +2,23 @@

### NEW KEYS ###
# GlobalTag for MC production with perfectly aligned and calibrated detector for Run1
'run1_design' : 'DESRUN1_73_V2',
'run1_design' : 'DESRUN1_73_V5',
# GlobalTag for MC production (pp collisions) with realistic alignment and calibrations for Run1
'run1_mc' : 'MCRUN1_73_V2',
'run1_mc' : 'MCRUN1_73_V5',
# GlobalTag for MC production (Heavy Ions collisions) with realistic alignment and calibrations for Run1
'run1_mc_hi' : 'MCHI1_73_V2',
'run1_mc_hi' : 'MCHI1_73_V5',
# GlobalTag for MC production (p-Pb collisions) with realistic alignment and calibrations for Run1
'run1_mc_pa' : 'MCPA1_73_V2',
'run1_mc_pa' : 'MCPA1_73_V5',
# GlobalTag for MC production with perfectly aligned and calibrated detector for Run2
'run2_design' : 'DESRUN2_73_V3',
'run2_design' : 'DESRUN2_73_V6',
# GlobalTag for MC production with pessimistic alignment and calibrations for Run2
'run2_mc_50ns' : 'MCRUN2_73_V6',
'run2_mc_50ns' : 'MCRUN2_73_V12',
#GlobalTag for MC production with optimistic alignment and calibrations for Run2
'run2_mc' : 'MCRUN2_73_V7',
'run2_mc' : 'MCRUN2_73_V13',
# GlobalTag for Run1 data reprocessing
'run1_data' : 'GR_R_73_V0A',
'run1_data' : 'GR_R_73_V2A',
# GlobalTag for Run2 data reprocessing
'run2_data' : 'GR_R_73_V1A',
'run2_data' : 'GR_R_73_V3A',
# GlobalTag for Run1 HLT: it points to the online GT and overrides the connection string and pfnPrefix for use offline
'run1_hlt' : 'GR_H_V43A,frontier://FrontierProd/CMS_CONDITIONS,frontier://FrontierProd/',
# GlobalTag for Run2 HLT: it points to the online GT and overrides the connection string and pfnPrefix for use offline
Expand Down
9 changes: 6 additions & 3 deletions DataFormats/CaloRecHit/interface/CaloCluster.h
Expand Up @@ -40,18 +40,18 @@ namespace reco {

/// default constructor. Sets energy and position to zero
CaloCluster() :
energy_(0), correctedEnergy_(-1.0),
energy_(0), correctedEnergy_(-1.0), correctedEnergyUncertainty_(-1.0),
algoID_( undefined ), flags_(0) {}

/// constructor with algoId, to be used in all child classes
CaloCluster(AlgoID algoID) :
energy_(0), correctedEnergy_(-1.0),
energy_(0), correctedEnergy_(-1.0), correctedEnergyUncertainty_(-1.0),
algoID_( algoID ), flags_(0) {}

CaloCluster( double energy,
const math::XYZPoint& position,
const CaloID& caloID) :
energy_ (energy), correctedEnergy_(-1.0), position_ (position), caloID_(caloID),algoID_( undefined ), flags_(0) {}
energy_ (energy), correctedEnergy_(-1.0), correctedEnergyUncertainty_(-1.0), position_ (position), caloID_(caloID),algoID_( undefined ), flags_(0) {}


/// resets the CaloCluster (position, energy, hitsAndFractions)
Expand Down Expand Up @@ -107,6 +107,7 @@ namespace reco {

void setEnergy(double energy){energy_ = energy;}
void setCorrectedEnergy(double cenergy){correctedEnergy_ = cenergy;}
void setCorrectedEnergyUncertainty(float energyerr) { correctedEnergyUncertainty_ = energyerr; }

void setPosition(const math::XYZPoint& p){position_ = p;}

Expand All @@ -119,6 +120,7 @@ namespace reco {
/// cluster energy
double energy() const { return energy_; }
double correctedEnergy() const { return correctedEnergy_; }
float correctedEnergyUncertainty() const { return correctedEnergyUncertainty_; }

/// cluster centroid position
const math::XYZPoint & position() const { return position_; }
Expand Down Expand Up @@ -204,6 +206,7 @@ namespace reco {
/// cluster energy
double energy_;
double correctedEnergy_;
float correctedEnergyUncertainty_;

/// cluster centroid position
math::XYZPoint position_;
Expand Down
3 changes: 2 additions & 1 deletion DataFormats/CaloRecHit/src/classes_def.xml
Expand Up @@ -2,9 +2,10 @@
<class name="CaloRecHit" ClassVersion="10">
<version ClassVersion="10" checksum="582597904"/>
</class>
<class name="reco::CaloCluster" ClassVersion="11">
<class name="reco::CaloCluster" ClassVersion="12">
<version ClassVersion="10" checksum="3936140"/>
<version ClassVersion="11" checksum="2938838489"/>
<version ClassVersion="12" checksum="4229965835"/>
</class>
<class name="edm::Wrapper<std::vector<std::pair<unsigned long,edm::Ptr<reco::CaloCluster> > > >"/>
<class name="std::vector<std::pair<unsigned long,edm::Ptr<reco::CaloCluster> > >"/>
Expand Down
7 changes: 7 additions & 0 deletions RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h
Expand Up @@ -128,6 +128,7 @@ class EcalClusterLazyToolsT : public EcalClusterLazyToolsBase {
float e4x4( const reco::BasicCluster &cluster );

float e5x5( const reco::BasicCluster &cluster );
int n5x5( const reco::BasicCluster &cluster );
// energy in the 2x5 strip right of the max crystal (does not contain max crystal)
// 2 crystals wide in eta, 5 wide in phi.
float e2x5Right( const reco::BasicCluster &cluster );
Expand Down Expand Up @@ -247,6 +248,12 @@ float EcalClusterLazyToolsT<EcalClusterToolsImpl>::e5x5( const reco::BasicCluste
return EcalClusterToolsImpl::e5x5( cluster, getEcalRecHitCollection(cluster), topology_ );
}

template<class EcalClusterToolsImpl>
int EcalClusterLazyToolsT<EcalClusterToolsImpl>::n5x5( const reco::BasicCluster &cluster )
{
return EcalClusterToolsImpl::n5x5( cluster, getEcalRecHitCollection(cluster), topology_ );
}

template<class EcalClusterToolsImpl>
float EcalClusterLazyToolsT<EcalClusterToolsImpl>::e2x5Right( const reco::BasicCluster &cluster )
{
Expand Down
28 changes: 28 additions & 0 deletions RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h
Expand Up @@ -101,6 +101,7 @@ class EcalClusterToolsT {
static float e4x4( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology);

static float e5x5( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );
static int n5x5( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology );

// energy in the 2x5 strip right of the max crystal (does not contain max crystal)
// 2 crystals wide in eta, 5 wide in phi.
Expand Down Expand Up @@ -177,6 +178,7 @@ class EcalClusterToolsT {
// get the energy deposited in a matrix centered in the maximum energy crystal = (0,0)
// the size is specified by ixMin, ixMax, iyMin, iyMax in unit of crystals
static float matrixEnergy( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology, DetId id, int ixMin, int ixMax, int iyMin, int iyMax );
static int matrixSize( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology, DetId id, int ixMin, int ixMax, int iyMin, int iyMax );

static float getFraction( const std::vector< std::pair<DetId, float> > &v_id, DetId id);
// get the DetId and the energy of the maximum energy crystal in a vector of DetId
Expand Down Expand Up @@ -350,6 +352,25 @@ float EcalClusterToolsT<noZS>::matrixEnergy( const reco::BasicCluster &cluster,
return energy;
}

template<bool noZS>
int EcalClusterToolsT<noZS>::matrixSize( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology, DetId id, int ixMin, int ixMax, int iyMin, int iyMax )
{
// fast version
CaloNavigator<DetId> cursor = CaloNavigator<DetId>( id, topology->getSubdetectorTopology( id ) );
int result = 0;
const std::vector< std::pair<DetId, float> >& v_id = cluster.hitsAndFractions();
for ( int i = ixMin; i <= ixMax; ++i ) {
for ( int j = iyMin; j <= iyMax; ++j ) {
cursor.home();
cursor.offsetBy( i, j );
float frac=getFraction(v_id,*cursor);
float energy = recHitEnergy( *cursor, recHits )*frac;
if (energy > 0) result++;
}
}
return result;
}


template<bool noZS>
std::vector<DetId> EcalClusterToolsT<noZS>::matrixDetId( const CaloTopology* topology, DetId id, int ixMin, int ixMax, int iyMin, int iyMax )
Expand Down Expand Up @@ -415,6 +436,13 @@ float EcalClusterToolsT<noZS>::e5x5( const reco::BasicCluster &cluster, const Ec
return matrixEnergy( cluster, recHits, topology, id, -2, 2, -2, 2 );
}

template<bool noZS>
int EcalClusterToolsT<noZS>::n5x5( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology* topology )
{
DetId id = getMaximum( cluster.hitsAndFractions(), recHits ).first;
return matrixSize( cluster, recHits, topology, id, -2, 2, -2, 2 );
}

template<bool noZS>
float EcalClusterToolsT<noZS>::eMax( const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits )
{
Expand Down
2 changes: 2 additions & 0 deletions RecoHI/Configuration/python/Reconstruction_hiPF_cff.py
Expand Up @@ -22,6 +22,8 @@

from RecoParticleFlow.Configuration.RecoParticleFlow_cff import *

particleFlowClusterECAL.energyCorrector.verticesLabel = cms.InputTag('hiPixelAdaptiveVertex')

mvaElectrons.vertexTag = cms.InputTag("hiSelectedVertex")

particleFlowBlock.elementImporters = cms.VPSet(
Expand Down
1 change: 1 addition & 0 deletions RecoParticleFlow/PFClusterProducer/BuildFile.xml
@@ -1,5 +1,6 @@
<use name="CondFormats/HcalObjects"/>
<use name="CondFormats/EcalObjects"/>
<use name="CondFormats/EgammaObjects"/>
<use name="CondFormats/DataRecord"/>
<use name="DataFormats/Common"/>
<use name="DataFormats/ParticleFlowReco"/>
Expand Down
@@ -1,44 +1,47 @@
#ifndef __PFClusterEMEnergyCorrector_H__
#define __PFClusterEMEnergyCorrector_H__

#include "RecoParticleFlow/PFClusterProducer/interface/PFClusterEnergyCorrectorBase.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"

#include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/ParticleFlowReco/interface/PFRecHitFwd.h"
#include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
#include "RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h"
#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"

class PFClusterEMEnergyCorrector : public PFClusterEnergyCorrectorBase {
class PFClusterEMEnergyCorrector {
public:
PFClusterEMEnergyCorrector(const edm::ParameterSet& conf) :
PFClusterEnergyCorrectorBase(conf),
_applyCrackCorrections(conf.getParameter<bool>("applyCrackCorrections")),
_assoc(NULL),
_idx(0),
_calibrator(new PFEnergyCalibration) { }
PFClusterEMEnergyCorrector(const edm::ParameterSet& conf, edm::ConsumesCollector &&cc);
PFClusterEMEnergyCorrector(const PFClusterEMEnergyCorrector&) = delete;
PFClusterEMEnergyCorrector& operator=(const PFClusterEMEnergyCorrector&) = delete;

void setEEtoPSAssociation(const reco::PFCluster::EEtoPSAssociation& assoc) {
_assoc = &assoc;
}
void setClusterIndex(const unsigned i) { _idx = i; }

void correctEnergy(reco::PFCluster& c) { correctEnergyActual(c,_idx); }
void correctEnergies(reco::PFClusterCollection& cs) {
for( unsigned i = 0; i < cs.size(); ++i ) correctEnergyActual(cs[i],i);
}
void correctEnergies(const edm::Event &evt, const edm::EventSetup &es, const reco::PFCluster::EEtoPSAssociation &assoc, reco::PFClusterCollection& cs);

private:
const bool _applyCrackCorrections;
const reco::PFCluster::EEtoPSAssociation* _assoc;
unsigned _idx;
std::unique_ptr<PFEnergyCalibration> _calibrator;
private:
bool _applyCrackCorrections;
bool _applyMVACorrections;

bool autoDetectBunchSpacing_;
int bunchSpacingManual_;

edm::EDGetTokenT<int> bunchSpacing_;

void correctEnergyActual(reco::PFCluster&, const unsigned) const;
edm::EDGetTokenT<EcalRecHitCollection> _recHitsEB;
edm::EDGetTokenT<EcalRecHitCollection> _recHitsEE;
edm::EDGetTokenT<reco::VertexCollection> _vertices;

std::vector<std::string> _condnames_mean_50ns;
std::vector<std::string> _condnames_sigma_50ns;
std::vector<std::string> _condnames_mean_25ns;
std::vector<std::string> _condnames_sigma_25ns;

std::unique_ptr<PFEnergyCalibration> _calibrator;

};

DEFINE_EDM_PLUGIN(PFClusterEnergyCorrectorFactory,
PFClusterEMEnergyCorrector,
"PFClusterEMEnergyCorrector");

#endif
Expand Up @@ -7,8 +7,9 @@

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

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h"
Expand Down Expand Up @@ -62,14 +63,15 @@ class CorrectedECALPFClusterProducer : public edm::stream::EDProducer<> {
_inputPS = consumes<reco::PFClusterCollection>( inputPS );

const edm::ParameterSet corConf = conf.getParameterSet("energyCorrector");
_corrector.reset(new PFClusterEMEnergyCorrector(corConf));
_corrector.reset(new PFClusterEMEnergyCorrector(corConf,consumesCollector()));

produces<reco::PFCluster::EEtoPSAssociation>();
produces<reco::PFClusterCollection>();
}

virtual void produce(edm::Event& e, const edm::EventSetup& es);

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
const double _minimumPSEnergy;
std::unique_ptr<PFClusterEMEnergyCorrector> _corrector;
Expand Down Expand Up @@ -124,14 +126,33 @@ produce(edm::Event& e, const edm::EventSetup& es) {
}
}
std::sort(association_out->begin(),association_out->end(),sortByKey);

_corrector->setEEtoPSAssociation(*association_out);
_corrector->correctEnergies(*clusters_out);

_corrector->correctEnergies(e,es,*association_out,*clusters_out);

association_out->shrink_to_fit();

e.put(association_out);
e.put(clusters_out);
}

void CorrectedECALPFClusterProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<double>("minimumPSEnergy",0.0);
desc.add<edm::InputTag>("inputPS",edm::InputTag("particleFlowClusterPS"));
{
edm::ParameterSetDescription psd0;
psd0.add<bool>("applyCrackCorrections",false);
psd0.add<bool>("applyMVACorrections",false);
psd0.add<std::string>("algoName","PFClusterEMEnergyCorrector");
psd0.add<edm::InputTag>("recHitsEBLabel",edm::InputTag("ecalRecHit","EcalRecHitsEB"));
psd0.add<edm::InputTag>("recHitsEELabel",edm::InputTag("ecalRecHit","EcalRecHitsEE"));
psd0.add<edm::InputTag>("verticesLabel",edm::InputTag("offlinePrimaryVertices"));
psd0.add<bool>("autoDetectBunchSpacing",true);
psd0.add<int>("bunchSpacing",25);
desc.add<edm::ParameterSetDescription>("energyCorrector",psd0);
}
desc.add<edm::InputTag>("inputECAL",edm::InputTag("particleFlowClusterECALUncorrected"));
descriptions.add("particleFlowClusterECAL",desc);
}

#endif
Expand Up @@ -5,7 +5,12 @@
#energy corrector for corrected cluster producer
_emEnergyCorrector = cms.PSet(
algoName = cms.string("PFClusterEMEnergyCorrector"),
applyCrackCorrections = cms.bool(False)
applyCrackCorrections = cms.bool(False),
applyMVACorrections = cms.bool(True),
recHitsEBLabel = cms.InputTag('ecalRecHit', 'EcalRecHitsEB'),
recHitsEELabel = cms.InputTag('ecalRecHit', 'EcalRecHitsEE'),
verticesLabel = cms.InputTag('offlinePrimaryVertices'),
autoDetectBunchSpacing = cms.bool(True),
)

particleFlowClusterECAL = cms.EDProducer(
Expand Down

0 comments on commit d54f7f6

Please sign in to comment.