forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Electron superclustering in DNN using TICL
- Loading branch information
Showing
28 changed files
with
1,998 additions
and
1,547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** Produce inputs for the superclustering DNN */ | ||
// Author: Theo Cuisset - [email protected] | ||
// Date: 11/2023 | ||
|
||
#ifndef __RecoHGCal_TICL_SuperclusteringDNNInputs_H__ | ||
#define __RecoHGCal_TICL_SuperclusteringDNNInputs_H__ | ||
|
||
#include <vector> | ||
#include <string> | ||
#include <memory> | ||
|
||
namespace ticl { | ||
class Trackster; | ||
|
||
// Abstract base class for DNN input preparation. | ||
class AbstractDNNInput { | ||
public: | ||
virtual ~AbstractDNNInput() = default; | ||
|
||
virtual unsigned int featureCount() const { return featureNames().size(); }; | ||
|
||
/** Get name of features. Used for SuperclusteringSampleDumper branch names (inference does not use the names, only the indices) | ||
* The default implementation is meant to be overriden by inheriting classes | ||
*/ | ||
virtual std::vector<std::string> featureNames() const { | ||
std::vector<std::string> defaultNames; | ||
defaultNames.reserve(featureCount()); | ||
for (unsigned int i = 1; i <= featureCount(); i++) { | ||
defaultNames.push_back(std::string("nb_") + std::to_string(i)); | ||
} | ||
return defaultNames; | ||
} | ||
|
||
/** Compute feature for seed and candidate pair */ | ||
virtual std::vector<float> computeVector(ticl::Trackster const& ts_base, ticl::Trackster const& ts_toCluster) = 0; | ||
}; | ||
|
||
/* First version of DNN by Alessandro Tarabini. Meant as a DNN equivalent of Moustache algorithm (superclustering algo in ECAL) | ||
Uses features : ['DeltaEta', 'DeltaPhi', 'multi_en', 'multi_eta', 'multi_pt', 'seedEta','seedPhi','seedEn', 'seedPt'] | ||
*/ | ||
class DNNInputAlessandroV1 : public AbstractDNNInput { | ||
public: | ||
unsigned int featureCount() const override { return 9; } | ||
|
||
std::vector<float> computeVector(ticl::Trackster const& ts_base, ticl::Trackster const& ts_toCluster) override; | ||
|
||
std::vector<std::string> featureNames() const override { | ||
return {"DeltaEtaBaryc", | ||
"DeltaPhiBaryc", | ||
"multi_en", | ||
"multi_eta", | ||
"multi_pt", | ||
"seedEta", | ||
"seedPhi", | ||
"seedEn", | ||
"seedPt"}; | ||
} | ||
}; | ||
|
||
/* Second version of DNN by Alessandro Tarabini. | ||
Uses features : ['DeltaEta', 'DeltaPhi', 'multi_en', 'multi_eta', 'multi_pt', 'seedEta','seedPhi','seedEn', 'seedPt', 'theta', 'theta_xz_seedFrame', 'theta_yz_seedFrame', 'theta_xy_cmsFrame', 'theta_yz_cmsFrame', 'theta_xz_cmsFrame', 'explVar', 'explVarRatio'] | ||
*/ | ||
class DNNInputAlessandroV2 : public AbstractDNNInput { | ||
public: | ||
unsigned int featureCount() const override { return 17; } | ||
|
||
std::vector<float> computeVector(ticl::Trackster const& ts_base, ticl::Trackster const& ts_toCluster) override; | ||
|
||
std::vector<std::string> featureNames() const override { | ||
return {"DeltaEtaBaryc", | ||
"DeltaPhiBaryc", | ||
"multi_en", | ||
"multi_eta", | ||
"multi_pt", | ||
"seedEta", | ||
"seedPhi", | ||
"seedEn", | ||
"seedPt", | ||
"theta", | ||
"theta_xz_seedFrame", | ||
"theta_yz_seedFrame", | ||
"theta_xy_cmsFrame", | ||
"theta_yz_cmsFrame", | ||
"theta_xz_cmsFrame", | ||
"explVar", | ||
"explVarRatio"}; | ||
} | ||
}; | ||
|
||
std::unique_ptr<AbstractDNNInput> makeDNNInputFromString(std::string dnnVersion); | ||
} // namespace ticl | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Authors : Theo Cuisset <[email protected]>, Shamik Ghosh <[email protected]> | ||
// Date : 01/2024 | ||
/* Translates TICL superclusters to ECAL supercluster dataformats (reco::SuperCluster and reco::CaloCluster). Performs similar task as RecoEcal/EgammaCLusterProducers/PFECALSuperClusterProducer */ | ||
|
||
#include "FWCore/Framework/interface/stream/EDProducer.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/EventSetup.h" | ||
#include "FWCore/Framework/interface/ConsumesCollector.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
#include "FWCore/Utilities/interface/EDGetToken.h" | ||
|
||
#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" | ||
#include "DataFormats/EgammaReco/interface/SuperCluster.h" | ||
#include "DataFormats/EgammaReco/interface/ElectronSeed.h" | ||
#include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h" | ||
#include "DataFormats/HGCalReco/interface/Trackster.h" | ||
|
||
class EGammaSuperclusterProducer : public edm::stream::EDProducer<> { | ||
public: | ||
EGammaSuperclusterProducer(const edm::ParameterSet&); | ||
|
||
void produce(edm::Event&, const edm::EventSetup&) override; | ||
|
||
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); | ||
|
||
private: | ||
edm::EDGetTokenT<ticl::TracksterCollection> ticlSuperClustersToken_; | ||
edm::EDGetTokenT<std::vector<std::vector<unsigned int>>> superClusterLinksToken_; | ||
edm::EDGetTokenT<ticl::TracksterCollection> ticlTrackstersEMToken_; | ||
edm::EDGetTokenT<reco::CaloClusterCollection> layerClustersToken_; | ||
}; | ||
|
||
EGammaSuperclusterProducer::EGammaSuperclusterProducer(const edm::ParameterSet& ps) | ||
: ticlSuperClustersToken_(consumes<ticl::TracksterCollection>(ps.getParameter<edm::InputTag>("ticlSuperClusters"))), | ||
superClusterLinksToken_(consumes<std::vector<std::vector<unsigned int>>>( | ||
edm::InputTag(ps.getParameter<edm::InputTag>("ticlSuperClusters").label(), | ||
"linkedTracksterIdToInputTracksterId", | ||
ps.getParameter<edm::InputTag>("ticlSuperClusters").process()))), | ||
ticlTrackstersEMToken_(consumes<ticl::TracksterCollection>(ps.getParameter<edm::InputTag>("ticlTrackstersEM"))), | ||
layerClustersToken_(consumes<reco::CaloClusterCollection>(ps.getParameter<edm::InputTag>("layerClusters"))) { | ||
produces<reco::SuperClusterCollection>(); | ||
produces<reco::CaloClusterCollection>(); // The CaloCluster corresponding to each EM trackster | ||
} | ||
|
||
void EGammaSuperclusterProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { | ||
auto const& ticlSuperclusters = iEvent.get(ticlSuperClustersToken_); | ||
auto const& ticlSuperclusterLinks = iEvent.get(superClusterLinksToken_); | ||
auto emTracksters_h = iEvent.getHandle(ticlTrackstersEMToken_); | ||
auto const& emTracksters = *emTracksters_h; | ||
auto const& layerClusters = iEvent.get(layerClustersToken_); | ||
// Output collections : | ||
auto egammaSuperclusters = std::make_unique<reco::SuperClusterCollection>(); | ||
auto caloClustersEM = std::make_unique<reco::CaloClusterCollection>(); | ||
|
||
// Fill reco::CaloCluster collection (1-1 mapping to TICL EM tracksters) | ||
for (ticl::Trackster const& emTrackster : emTracksters) { | ||
std::vector<std::pair<DetId, float>> hitsAndFractions; | ||
int iLC = 0; | ||
std::for_each(std::begin(emTrackster.vertices()), std::end(emTrackster.vertices()), [&](unsigned int lcId) { | ||
const auto fraction = 1.f / emTrackster.vertex_multiplicity(iLC++); | ||
for (const auto& cell : layerClusters[lcId].hitsAndFractions()) { | ||
hitsAndFractions.emplace_back(cell.first, cell.second * fraction); | ||
} | ||
}); | ||
|
||
reco::CaloCluster& caloCluster = caloClustersEM->emplace_back( | ||
emTrackster.regressed_energy(), // energy | ||
math::XYZPoint(emTrackster.barycenter()), // position | ||
reco::CaloID(reco::CaloID::DET_HGCAL_ENDCAP), | ||
hitsAndFractions, | ||
reco::CaloCluster::particleFlow, // algoID (copying from output of PFECALCSuperClusterProducer) | ||
hitsAndFractions.at(0).first // seedId : TODO figure out if needed or if we need to put the highest energy hit | ||
); | ||
caloCluster.setCorrectedEnergy(emTrackster.regressed_energy()); | ||
} | ||
|
||
edm::OrphanHandle<reco::CaloClusterCollection> caloClustersEM_h = iEvent.put(std::move(caloClustersEM)); | ||
|
||
// Fill reco::SuperCluster collection | ||
assert(ticlSuperclusters.size() == ticlSuperclusterLinks.size()); | ||
for (std::size_t sc_i = 0; sc_i < ticlSuperclusters.size(); sc_i++) { | ||
ticl::Trackster const& ticlSupercluster = ticlSuperclusters[sc_i]; | ||
std::vector<unsigned int> const& superclusterLink = ticlSuperclusterLinks[sc_i]; | ||
|
||
reco::CaloClusterPtrVector trackstersEMInSupercluster; | ||
/* TODO : for now, set as SuperCluster regressed energy the sum of regressed energies of CLUE3D EM tracksters | ||
A regression will most likely be included here */ | ||
double regressedEnergySum = 0.; | ||
for (unsigned int tsInSc_id : superclusterLink) { | ||
trackstersEMInSupercluster.push_back(reco::CaloClusterPtr(caloClustersEM_h, tsInSc_id)); | ||
regressedEnergySum += emTracksters[tsInSc_id].regressed_energy(); | ||
} | ||
reco::SuperCluster& egammaSc = egammaSuperclusters->emplace_back( | ||
ticlSupercluster.raw_energy(), | ||
reco::SuperCluster::Point(ticlSupercluster.barycenter()), | ||
reco::CaloClusterPtr(caloClustersEM_h, | ||
superclusterLink[0]), // seed (first trackster in superclusterLink is the seed) | ||
trackstersEMInSupercluster, // clusters | ||
0., // Epreshower | ||
0.046, // phiwidth (TODO placeholder value for now) | ||
0.017 // etawidth (TODO placeholder value for now) | ||
); | ||
egammaSc.setCorrectedEnergy(regressedEnergySum); | ||
// correctedEnergyUncertainty is left at its default value for now | ||
} | ||
|
||
iEvent.put(std::move(egammaSuperclusters)); | ||
} | ||
|
||
void EGammaSuperclusterProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.add<edm::InputTag>("ticlSuperClusters", edm::InputTag("ticlTracksterLinksSuperclustering")); | ||
desc.add<edm::InputTag>("ticlTrackstersEM", edm::InputTag("ticlTrackstersCLUE3DHigh")) | ||
->setComment("The trackster collection used before superclustering, ie CLUE3D EM tracksters"); | ||
desc.add<edm::InputTag>("layerClusters", edm::InputTag("hgcalMergeLayerClusters")) | ||
->setComment("The layer cluster collection that goes with ticlTrackstersEM"); | ||
|
||
descriptions.add("ticlEGammaSuperClusterProducer", desc); | ||
} | ||
|
||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
DEFINE_FWK_MODULE(EGammaSuperclusterProducer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.