Skip to content

Commit

Permalink
Merge pull request #1 from Sam-Harper/GSIssueFixPATcustomize
Browse files Browse the repository at this point in the history
Bug Fixes for electrons, photons and superclusters
  • Loading branch information
rafaellopesdesa authored Jan 25, 2017
2 parents c6cc8eb + 4bdc5e7 commit c77b076
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
53 changes: 45 additions & 8 deletions RecoEcal/EgammaClusterProducers/src/EGRefinedSCFixer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class EGRefinedSCFixer : public edm::stream::EDProducer<> {
static std::unordered_set<unsigned>
getListOfClusterSeedIdsForNewSC(const reco::SuperCluster& orgRefinedSC,
const reco::SuperCluster& orgSC,
const reco::SuperCluster& fixedSC);
const reco::SuperCluster& fixedSC,
const std::vector<edm::Ptr<reco::CaloCluster> >& clustersAddedToAnySC);

static std::vector<edm::Ptr<reco::PFCluster> >
getClustersFromSeedIds(const std::unordered_set<unsigned>& seedIds,const edm::Handle<edm::View<reco::PFCluster> >& inClusters);
Expand All @@ -73,7 +74,8 @@ class EGRefinedSCFixer : public edm::stream::EDProducer<> {
makeFixedRefinedBarrelSC(const reco::SuperCluster& orgRefinedSC,
const reco::SuperCluster& orgSC,
const reco::SuperCluster& fixedSC,
const edm::Handle<edm::View<reco::PFCluster> >& fixedClusters);
const edm::Handle<edm::View<reco::PFCluster> >& fixedClusters,
const std::vector<edm::Ptr<reco::CaloCluster> >& clustersAddedToAnySC);

private:
typedef edm::View<reco::PFCluster> PFClusterView;
Expand Down Expand Up @@ -171,6 +173,8 @@ namespace{
return out;
}
};
// std::ostream& operator<<(std::ostream& out,const SCDeepPrinter& obj){return obj(out);}

}

void EGRefinedSCFixer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup)
Expand All @@ -196,6 +200,19 @@ void EGRefinedSCFixer::produce(edm::Event & iEvent, const edm::EventSetup & iSet
std::vector<reco::SuperClusterRef> mappedSCsEB(fixedEBSCs->size());
std::vector<reco::SuperClusterRef> mappedSCsEE(fixedEESCs->size());

std::vector<edm::Ptr<reco::CaloCluster> > clusterAddedToAnyEBSC;
for(auto& refinedSC : *orgRefinedSCs){
if(refinedSC.seed()->seed().subdetId() == EcalBarrel) {
reco::SuperClusterRef parentSC = GainSwitchTools::matchSCBySeedCrys(refinedSC,orgEBSCs);
if(parentSC.isNonnull()) {
auto clusAdded = getSubClustersMissing(refinedSC,*parentSC);
for(auto clusPtr : clusAdded) clusterAddedToAnyEBSC.push_back(clusPtr);
}else{ //no parent supercluster, all superclusters in this supercluster are addded
for(auto clusPtr : refinedSC.clusters()) clusterAddedToAnyEBSC.push_back(clusPtr);
}
}
}

for (unsigned iO(0); iO != orgRefinedSCs->size(); ++iO) {
auto& orgRefinedSC(orgRefinedSCs->at(iO));
mappedRefinedSCs.emplace_back(orgRefinedSCs, iO);
Expand All @@ -210,12 +227,16 @@ void EGRefinedSCFixer::produce(edm::Event & iEvent, const edm::EventSetup & iSet
auto fixedEBSC(GainSwitchTools::matchSCBySeedCrys(*orgEBSC, fixedEBSCs, 2, 2));

// 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));
auto fixedRefinedSC(makeFixedRefinedBarrelSC(orgRefinedSC, *orgEBSC, *fixedEBSC, fixedPFClusters,clusterAddedToAnyEBSC));
fixedRefinedSCs->push_back(fixedRefinedSC);

// std::cout<<" org refined "<<SCDeepPrinter(orgRefinedSC)<<std::endl;
//std::cout<<" new refined "<<SCDeepPrinter(fixedRefinedSC)<<std::endl;

continue;
}
}
Expand All @@ -234,6 +255,7 @@ void EGRefinedSCFixer::produce(edm::Event & iEvent, const edm::EventSetup & iSet
fixedRefinedSCs->push_back(orgRefinedSC);
}


// Put the PF SC maps in Event
std::auto_ptr<SCRefMap> pEBSCRefMap(new SCRefMap);
SCRefMap::Filler ebSCMapFiller(*pEBSCRefMap);
Expand Down Expand Up @@ -341,21 +363,35 @@ EGRefinedSCFixer::getSubClustersMissing(const reco::SuperCluster& lhs,
std::unordered_set<unsigned>
EGRefinedSCFixer::getListOfClusterSeedIdsForNewSC(const reco::SuperCluster& orgRefinedSC,
const reco::SuperCluster& orgSC,
const reco::SuperCluster& fixedSC)
const reco::SuperCluster& fixedSC,
const std::vector<edm::Ptr<reco::CaloCluster> >& clustersAddedToAnySC)

{
auto clusAdded = getSubClustersMissing(orgRefinedSC,orgSC);
auto clusRemoved = getSubClustersMissing(orgSC,orgRefinedSC);


std::unordered_set<unsigned> detIdsOfClustersForNewSC;
for(auto& clus : fixedSC.clusters()){
auto compFunc=[&clus](auto& rhs){return rhs->seed().rawId()==clus->seed().rawId();};
if(std::find_if(clusRemoved.begin(),clusRemoved.end(),compFunc)==clusRemoved.end()){

//first check if the cluster was removed by the refining process
bool notRemoved = std::find_if(clusRemoved.begin(),clusRemoved.end(),compFunc)==clusRemoved.end();

//now check if it was assigned to another supercluster (it wont be picked up by the previous
//check if the parent supercluster picked it up during reclustering)
//if its a cluster which is added to any supercluster it wont add it
//its okay if it was added to this supercluster as we will add it in below
bool notAddedToASuperCluster = std::find_if(clustersAddedToAnySC.begin(),
clustersAddedToAnySC.end(),compFunc)==clustersAddedToAnySC.end();

if(notRemoved && notAddedToASuperCluster){
detIdsOfClustersForNewSC.insert(clus->seed().rawId());
}
}
for(auto clus : clusAdded)
for(auto clus : clusAdded){
detIdsOfClustersForNewSC.insert(clus->seed().rawId());
}

return detIdsOfClustersForNewSC;
}
Expand All @@ -381,9 +417,10 @@ reco::SuperCluster
EGRefinedSCFixer::makeFixedRefinedBarrelSC(const reco::SuperCluster& orgRefinedSC,
const reco::SuperCluster& orgSC,
const reco::SuperCluster& fixedSC,
const edm::Handle<edm::View<reco::PFCluster> >& fixedClusters)
const edm::Handle<edm::View<reco::PFCluster> >& fixedClusters,
const std::vector<edm::Ptr<reco::CaloCluster> >& clustersAddedToAnySC)
{
auto listOfSeedIds = getListOfClusterSeedIdsForNewSC(orgRefinedSC,orgSC,fixedSC);
auto listOfSeedIds = getListOfClusterSeedIdsForNewSC(orgRefinedSC,orgSC,fixedSC,clustersAddedToAnySC);

// make sure the seed cluster is in the listOfSeedIds
unsigned seedSeedId(fixedSC.seed()->seed().rawId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ void GsfElectronGSCrysFixer::produce( edm::Event & iEvent, const edm::EventSetup

reco::GsfElectron::ShowerShape full5x5ShowerShape = GainSwitchTools::redoEcalShowerShape<true>(newEle.full5x5_showerShape(),newEle.superCluster(),&ebRecHits,topology_,geometry_);
reco::GsfElectron::ShowerShape showerShape = GainSwitchTools::redoEcalShowerShape<false>(newEle.showerShape(),newEle.superCluster(),&ebRecHits,topology_,geometry_);
newEle.full5x5_setShowerShape(full5x5ShowerShape);
newEle.setShowerShape(showerShape);


float eNewSCOverEOldSC = newEle.superCluster()->energy()/oldEle.superCluster()->energy();
GainSwitchTools::correctHadem(showerShape,eNewSCOverEOldSC,GainSwitchTools::ShowerShapeType::Fractions);
GainSwitchTools::correctHadem(full5x5ShowerShape,eNewSCOverEOldSC,GainSwitchTools::ShowerShapeType::Full5x5);

newEle.full5x5_setShowerShape(full5x5ShowerShape);
newEle.setShowerShape(showerShape);


if( gedRegression_ )
gedRegression_->modifyObject(newEle);
}
Expand Down
8 changes: 4 additions & 4 deletions RecoEgamma/EgammaPhotonProducers/src/GEDPhotonGSCrysFixer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ GEDPhotonGSCrysFixer::produce(edm::Event& _event, const edm::EventSetup& _setup)
outPhoton.setShowerShapeVariables(newSS);

reco::Photon::ShowerShape new55SS;
newSS.e1x5 = noZS::EcalClusterTools::e1x5(newSeed, &ebHits, topology_);
newSS.e2x5 = noZS::EcalClusterTools::e2x5Max(newSeed, &ebHits, topology_);
newSS.e3x3 = noZS::EcalClusterTools::e3x3(newSeed, &ebHits, topology_);
newSS.e5x5 = noZS::EcalClusterTools::e5x5(newSeed, &ebHits, topology_);
new55SS.e1x5 = noZS::EcalClusterTools::e1x5(newSeed, &ebHits, topology_);
new55SS.e2x5 = noZS::EcalClusterTools::e2x5Max(newSeed, &ebHits, topology_);
new55SS.e3x3 = noZS::EcalClusterTools::e3x3(newSeed, &ebHits, topology_);
new55SS.e5x5 = noZS::EcalClusterTools::e5x5(newSeed, &ebHits, topology_);
new55SS.maxEnergyXtal = noZS::EcalClusterTools::eMax(newSeed, &ebHits);
new55SS.sigmaEtaEta = std::sqrt(cov55[0]);
new55SS.sigmaIetaIeta = std::sqrt(locCov55[0]);
Expand Down

0 comments on commit c77b076

Please sign in to comment.