Skip to content

Commit

Permalink
Merge pull request #7 from Sam-Harper/GSIssueNoThrow
Browse files Browse the repository at this point in the history
stopping throws on duplicate superclusters in the event & other debugging info
  • Loading branch information
rafaellopesdesa authored Jan 30, 2017
2 parents cf9eee1 + fca2430 commit 8f90b0b
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 302 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import FWCore.ParameterSet.Config as cms

gsFixedRefinedSuperClusters = cms.EDProducer("EGRefinedSCFixer",
particleFlowEGammaGSFixed = cms.EDProducer("EGRefinedSCFixer",
orgRefinedSC = cms.InputTag("particleFlowEGamma", '', cms.InputTag.skipCurrentProcess()),
orgSC = cms.InputTag("particleFlowSuperClusterECAL", '', cms.InputTag.skipCurrentProcess()),
fixedSC = cms.InputTag("particleFlowSuperClusterECALGSFixed"),
fixedPFClusters = cms.InputTag("particleFlowClusterECALGSFixed"),
throwOnDupECALClustersInEvent = cms.bool(False),
throwOnDupESClustersInEvent = cms.bool(True)

)
112 changes: 52 additions & 60 deletions RecoEcal/EgammaClusterProducers/src/EGRefinedSCFixer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
#include <unordered_set>
#include <iostream>

//work in progress (emergancy fix!)
//issue: we need to re-make the refined superclusters
//we only really need to do this for barrel super with a gain switch
//but usual to remake without gain switch for debugging
//however it is barrel only
//everything else is copied or relinked to produce the same set of outputs
//as particleFlowEGamma

//issue: we need to re-make the refined superclusters in the AOD
//problem: to do this properly, we need the outer position of the track, not stored in AOD
// so we cant re-run PFEGammaProducer which would normally do this
//solution: we fudge it in the following way

//how it works:
// a refined supercluster will have subclusters added or removed w.r.t to its parent SC
Expand All @@ -35,14 +33,18 @@
// we id clusters via seed crystal, this shouldnt change for any cluster without a gain switch,
// its still a local maximum
//
// it is important to know that for the digis to be saved in miniAOD, it must be within the 3x3
// of a hybrid (or multi 5x5 in endcap) supercluster seed crystal. The hybrid supercluster seed
// crystals should map well to the PF supercluster seed crystal, particularly for isolated high
// energy e/gamma objects
//
// for matching the new fixed superclusters vs old superclusters, the seed crystal may gain
// as the gain switched crystal will now have a larger energy
// but it really should be in the 3x3 of the orginal SC (the gain switch crysal has to be here to be redone)
// so we do a dIR = dIEta^2 + dIPhi^2 match of <=2 (ie be in the 3x3)
// but take the smallest dIR

// issues: sub cluster ordering may not be correct (its sorted by decreasing energy)
// issues: when it assigns a sub cluster to a refined SC, it doesnt remove it from others

class EGRefinedSCFixer : public edm::stream::EDProducer<> {
public:
Expand Down Expand Up @@ -104,14 +106,23 @@ class EGRefinedSCFixer : public edm::stream::EDProducer<> {
edm::EDGetTokenT<reco::PFClusterCollection> fixedPFClustersToken_;

// output instance name of EB/EE BC collection
std::string ebeeClustersCollection_;
const std::string ebeeClustersCollection_;
// output instance name of ES BC collection
std::string esClustersCollection_;
const std::string esClustersCollection_;

//if this is true, throw on duplicate clusters entering the event
//if false, we flags the event and move on
const bool throwOnDupECALClustersInEvent_;
const bool throwOnDupESClustersInEvent_;

};

EGRefinedSCFixer::EGRefinedSCFixer(const edm::ParameterSet& iConfig) :
ebeeClustersCollection_("EBEEClusters"),
esClustersCollection_("ESClusters")
esClustersCollection_("ESClusters"),
throwOnDupECALClustersInEvent_(iConfig.getParameter<bool>("throwOnDupECALClustersInEvent")),
throwOnDupESClustersInEvent_(iConfig.getParameter<bool>("throwOnDupESClustersInEvent"))

{
getToken(orgRefinedSCToken_, iConfig, "orgRefinedSC");
getToken(orgBCToken_, iConfig, "orgRefinedSC", "EBEEClusters");
Expand All @@ -132,6 +143,9 @@ EGRefinedSCFixer::EGRefinedSCFixer(const edm::ParameterSet& iConfig) :
produces<SCRefMap>();
produces<SCRefMap>("parentSCsEB");
produces<SCRefMap>("parentSCsEE");
//flags to tell us if we have duplicate clusters
produces<bool>("dupECALClusters");
produces<bool>("dupESClusters");
}

namespace {
Expand All @@ -145,38 +159,6 @@ namespace {
}
}

namespace{
class SCPrinter {
const reco::SuperCluster& sc_;
public:
SCPrinter(const reco::SuperCluster& sc):sc_(sc){}
std::ostream& operator()(std::ostream& out)const{
out <<"E "<<sc_.energy()<<" raw E "<<sc_.rawEnergy()<<" eta "<<sc_.eta()<<" phi "<<sc_.phi()<<" seedId "<<sc_.seed()->seed().rawId()<<" nrclus "<<sc_.clustersSize();
return out;
}

};
// std::ostream& operator<<(std::ostream& out,const SCPrinter& obj){return obj(out);}

}

namespace{
class SCDeepPrinter {
const reco::SuperCluster& sc_;
public:
SCDeepPrinter(const reco::SuperCluster& sc):sc_(sc){}
std::ostream& operator()(std::ostream& out)const{
out <<"E "<<sc_.energy()<<" raw E "<<sc_.rawEnergy()<<" eta "<<sc_.eta()<<" phi "<<sc_.phi()<<" seedId "<<sc_.seed()->seed().rawId()<<" nrclus "<<sc_.clustersSize() <<std::endl;
for(auto& clus : sc_.clusters()){
out <<" clus E "<<clus->energy()<<" Ecorr "<<clus->correctedEnergy()<<" seed "<<clus->seed().rawId()<<" nrHits "<<clus->hitsAndFractions().size()<<std::endl;
}
return out;
}
};
// std::ostream& operator<<(std::ostream& out,const SCDeepPrinter& obj){return obj(out);}

}

void EGRefinedSCFixer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup)
{
auto const& orgRefinedSCs = getHandle(iEvent, orgRefinedSCToken_);
Expand All @@ -193,6 +175,9 @@ void EGRefinedSCFixer::produce(edm::Event & iEvent, const edm::EventSetup & iSet
// EB clusters are fixed, EE are direct translation from the original
auto fixedBCs = std::make_unique<reco::CaloClusterCollection>();
// direct translation of the original ES collection - there is nothing "fixed" about this
// however they may be slightly different as we are reclustering from reduced rec-hit collections
// this will mainly effect non-photon or non-electron superclusters as those superclusters
// save less rec-hits surrounding them
auto fixedESs = std::make_unique<reco::CaloClusterCollection>();
auto fixedConvs = std::make_unique<reco::ConversionCollection>();

Expand Down Expand Up @@ -224,31 +209,26 @@ void EGRefinedSCFixer::produce(edm::Event & iEvent, const edm::EventSetup & iSet
// particleFlowEGamma can create superclusters directly out of PFClusters too
// -> there is not always a matching EB SC
if (orgEBSC.isNonnull()) {
//changing the matching to be in 3x3 now (had issues with suprious matches)
auto fixedEBSC(GainSwitchTools::matchSCBySeedCrys(*orgEBSC, fixedEBSCs, 1, 1));

// here we may genuinely miss a mapping, if the seed position moves too much by re-reconstruction
// Sam: its very unlikely, if not impossible. To be replaced the gain switched crystal must be within +/-1 crystal a hybrid supercluster
// seed crystal because of ecalSelectedDigis.
// You could only get a shift larger than 1 if you had two supercluster seed crystals very close together and even then I'm not sure its possible.
if (fixedEBSC.isNonnull()) {
mappedSCsEB[fixedEBSC.key()] = orgEBSC;

auto fixedRefinedSC(makeFixedRefinedBarrelSC(orgRefinedSC, *orgEBSC, *fixedEBSC, fixedPFClusters,clusterAddedToAnyEBSC));
fixedRefinedSCs->push_back(fixedRefinedSC);


continue;
}
}
}
else {
auto orgEESC(GainSwitchTools::matchSCBySeedCrys(orgRefinedSC, orgEESCs));
if (orgEESC.isNonnull()) {
// there is nothing "fixed" here - two clusters are identical
//there is nothing "fixed" here - two clusters are in theory identical but
//there could be mild differences given we are clustering from the
//reduced rec-hit collecitons
//for example this can lead to small energy changes leading a cluster to be
//now below the 4 GeV Et threshold to make a supercluster and therefore disappear
auto fixedEESC(GainSwitchTools::matchSCBySeedCrys(*orgEESC, fixedEESCs));

// fixedEESC has to be nonnull
if(fixedEESC.isNonnull()) mappedSCsEE[fixedEESC.key()] = orgEESC;
}
}
Expand All @@ -275,6 +255,8 @@ void EGRefinedSCFixer::produce(edm::Event & iEvent, const edm::EventSetup & iSet
std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapEBEE; //maps of pfclusters to caloclusters
std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapES;

bool duplicateECALClusters=false;
bool duplicateESClusters=false;
for (auto& sc : *fixedRefinedSCs) {
// The cluster ref in fixed EB and the other superclusters point to different collections (former to gs-fixed, latter to original)
// but we are copying the basic clusters by value and remaking yet another collection here -> no need to distinguish
Expand All @@ -284,9 +266,13 @@ void EGRefinedSCFixer::produce(edm::Event & iEvent, const edm::EventSetup & iSet
pfClusterMapEBEE[ptr] = fixedBCs->size();
fixedBCs->emplace_back(*ptr);
}
else
throw cms::Exception("EGRefinedSCFixer::produce")
<< "Found an EB/EE pfcluster matched to more than one supercluster!";
else{
duplicateECALClusters=true;
if(throwOnDupECALClustersInEvent_){
throw cms::Exception("EGRefinedSCFixer::produce")
<< "Found an EB/EE pfcluster matched to more than one supercluster!";
}
}
}

for (auto&& cItr = sc.preshowerClustersBegin(); cItr!=sc.preshowerClustersEnd(); ++cItr) {
Expand All @@ -295,12 +281,18 @@ void EGRefinedSCFixer::produce(edm::Event & iEvent, const edm::EventSetup & iSet
pfClusterMapES[ptr] = fixedESs->size();
fixedESs->emplace_back(*ptr);
}
else
throw cms::Exception("PFEgammaProducer::produce")
<< "Found an ES pfcluster matched to more than one supercluster!";
else{
duplicateESClusters=true;
if(throwOnDupESClustersInEvent_){
throw cms::Exception("PFEgammaProducer::produce")
<< "Found an ES pfcluster matched to more than one supercluster!";
}
}
}
}

iEvent.put(std::make_unique<bool>(duplicateECALClusters),"dupECALClusters");
iEvent.put(std::make_unique<bool>(duplicateESClusters),"dupESClusters");

//put calocluster output collections in event and get orphan handles to create ptrs
auto caloClusHandleEBEE(iEvent.put(std::move(fixedBCs), ebeeClustersCollection_));
auto caloClusHandleES(iEvent.put(std::move(fixedESs), esClustersCollection_));
Expand Down
96 changes: 0 additions & 96 deletions RecoEcal/EgammaClusterProducers/src/MapNewToOldSCs.cc

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import FWCore.ParameterSet.Config as cms

gsFixedGsfElectronCores = cms.EDProducer("GsfElectronCoreGSCrysFixer",
gedGsfElectronCoresGSFixed = cms.EDProducer("GsfElectronCoreGSCrysFixer",
orgCores=cms.InputTag("gedGsfElectronCores", '', cms.InputTag.skipCurrentProcess()),
refinedSCs = cms.InputTag('gsFixedRefinedSuperClusters'),
refinedSCs = cms.InputTag('particleFlowEGammaGSFixed'),
scs = cms.InputTag('particleFlowSuperClusterECALGSFixed'),
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import FWCore.ParameterSet.Config as cms
from RecoEgamma.EgammaTools.regressionModifier_cfi import regressionModifier

gsFixedGsfElectrons = cms.EDProducer("GsfElectronGSCrysFixer",
newCores=cms.InputTag("gsFixedGsfElectronCores"),
gedGsfElectronsGSFixed = cms.EDProducer("GsfElectronGSCrysFixer",
newCores=cms.InputTag("gedGsfElectronCoresGSFixed"),
oldEles=cms.InputTag("gedGsfElectrons", '', cms.InputTag.skipCurrentProcess()),
ebRecHits=cms.InputTag("ecalMultiAndGSGlobalRecHitEB"),
regressionConfig = regressionModifier.clone(rhoCollection=cms.InputTag("fixedGridRhoFastjetAllTmp")),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import FWCore.ParameterSet.Config as cms

gedPhotonCoreGSFixed = cms.EDProducer("GEDPhotonCoreGSCrysFixer",
photonCores = cms.InputTag("gedPhotonCore", '', cms.InputTag.skipCurrentProcess()),
refinedSCs = cms.InputTag('particleFlowEGammaGSFixed'),
scs = cms.InputTag('particleFlowSuperClusterECALGSFixed'),
conversions = cms.InputTag('allConversions'),
singleconversions = cms.InputTag('particleFlowEGamma')
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from RecoEgamma.EgammaTools.regressionModifier_cfi import *

gsFixedGEDPhotons = cms.EDProducer('GEDPhotonGSCrysFixer',
gedPhotonsGSFixed = cms.EDProducer('GEDPhotonGSCrysFixer',
photons = cms.InputTag('gedPhotons', '', cms.InputTag.skipCurrentProcess()),
newCores = cms.InputTag('gsFixedGEDPhotonCores'),
newCores = cms.InputTag('gedPhotonCoreGSFixed'),
barrelEcalHits=cms.InputTag("ecalMultiAndGSGlobalRecHitEB"),
primaryVertexProducer = cms.InputTag('offlinePrimaryVerticesWithBS'),
# rest for regression
Expand Down

This file was deleted.

Loading

0 comments on commit 8f90b0b

Please sign in to comment.