Skip to content

Commit

Permalink
Merge pull request #32412 from ebrondol/hgcalCaloPartValidationUpdate
Browse files Browse the repository at this point in the history
Update of HGCal validation of CaloParticle
  • Loading branch information
cmsbuild authored Dec 10, 2020
2 parents 69d8a54 + 12f5bc0 commit 56ff0af
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 173 deletions.
4 changes: 3 additions & 1 deletion Validation/HGCalValidation/interface/HGCalValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class HGCalValidator : public DQMGlobalEDAnalyzer<HGCalValidatorHistograms> {
void cpParametersAndSelection(const Histograms& histograms,
std::vector<CaloParticle> const& cPeff,
std::vector<SimVertex> const& simVertices,
std::vector<size_t>& selected_cPeff) const;
std::vector<size_t>& selected_cPeff,
unsigned int layers,
std::unordered_map<DetId, const HGCRecHit*> const&) const;

protected:
edm::InputTag label_lcl;
Expand Down
35 changes: 26 additions & 9 deletions Validation/HGCalValidation/interface/HGVHistoProducerAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,23 @@ struct HGVHistoProducerAlgoHistograms {
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_eta;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_eta_Zorigin;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_energy;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_selfenergy;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_energyDifference;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_pt;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_phi;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_nSimClusters;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_nHitsInSimClusters;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_firstlayer;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_lastlayer;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_layersnum;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_nHitsInSimClusters_matchedtoRecHit;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_nHits_matched_energy;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_nHits_matched_energy_layer;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_nHits_matched_energy_layer_1SimCl;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_sum_energy_layer;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_firstlayer_matchedtoRecHit;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_lastlayer_matchedtoRecHit;
std::unordered_map<int, dqm::reco::MonitorElement*> h_caloparticle_layersnum_matchedtoRecHit;

//For multiclusters
std::vector<dqm::reco::MonitorElement*> h_score_multicl2caloparticle;
Expand Down Expand Up @@ -155,14 +170,14 @@ class HGVHistoProducerAlgo {
using Histograms = HGVHistoProducerAlgoHistograms;

void bookInfo(DQMStore::IBooker& ibook, Histograms& histograms);
void bookCaloParticleHistos(DQMStore::IBooker& ibook, Histograms& histograms, int pdgid);
void bookCaloParticleHistos(DQMStore::IBooker& ibook, Histograms& histograms, int pdgid, unsigned int layers);

void bookClusterHistos(DQMStore::IBooker& ibook,
Histograms& histograms,
unsigned layers,
unsigned int layers,
std::vector<int> thicknesses,
std::string pathtomatbudfile);
void bookMultiClusterHistos(DQMStore::IBooker& ibook, Histograms& histograms, unsigned layers);
void bookMultiClusterHistos(DQMStore::IBooker& ibook, Histograms& histograms, unsigned int layers);
void layerClusters_to_CaloParticles(
const Histograms& histograms,
edm::Handle<reco::CaloClusterCollection> clusterHandle,
Expand All @@ -172,7 +187,7 @@ class HGVHistoProducerAlgo {
std::vector<size_t> const& cPIndices,
std::vector<size_t> const& cPSelectedIndices,
std::unordered_map<DetId, const HGCRecHit*> const&,
unsigned layers,
unsigned int layers,
const edm::Handle<hgcal::LayerClusterToCaloParticleAssociator>& LCAssocByEnergyScoreHandle) const;
void multiClusters_to_CaloParticles(const Histograms& histograms,
int count,
Expand All @@ -181,12 +196,14 @@ class HGVHistoProducerAlgo {
std::vector<size_t> const& cPIndices,
std::vector<size_t> const& cPSelectedIndices,
std::unordered_map<DetId, const HGCRecHit*> const&,
unsigned layers) const;
void fill_info_histos(const Histograms& histograms, unsigned layers) const;
unsigned int layers) const;
void fill_info_histos(const Histograms& histograms, unsigned int layers) const;
void fill_caloparticle_histos(const Histograms& histograms,
int pdgid,
const CaloParticle& caloparticle,
std::vector<SimVertex> const& simVertices) const;
std::vector<SimVertex> const& simVertices,
unsigned int layers,
std::unordered_map<DetId, const HGCRecHit*> const&) const;
void fill_cluster_histos(const Histograms& histograms, int count, const reco::CaloCluster& cluster) const;
void fill_generic_cluster_histos(
const Histograms& histograms,
Expand All @@ -200,7 +217,7 @@ class HGVHistoProducerAlgo {
std::vector<size_t> const& cPSelectedIndices,
std::unordered_map<DetId, const HGCRecHit*> const&,
std::map<double, double> cummatbudg,
unsigned layers,
unsigned int layers,
std::vector<int> thicknesses,
edm::Handle<hgcal::LayerClusterToCaloParticleAssociator>& LCAssocByEnergyScoreHandle) const;
void fill_multi_cluster_histos(const Histograms& histograms,
Expand All @@ -210,7 +227,7 @@ class HGVHistoProducerAlgo {
std::vector<size_t> const& cPIndices,
std::vector<size_t> const& cPSelectedIndices,
std::unordered_map<DetId, const HGCRecHit*> const&,
unsigned layers) const;
unsigned int layers) const;
double distance2(const double x1, const double y1, const double x2, const double y2) const;
double distance(const double x1, const double y1, const double x2, const double y2) const;

Expand Down
82 changes: 1 addition & 81 deletions Validation/HGCalValidation/plugins/CaloParticleValidation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@
//

struct Histogram_CaloParticleSingle {
dqm::reco::MonitorElement* eta_;
dqm::reco::MonitorElement* pt_;
dqm::reco::MonitorElement* energy_;
dqm::reco::MonitorElement* nSimClusters_;
dqm::reco::MonitorElement* nHitInSimClusters_;
dqm::reco::MonitorElement*
selfEnergy_; // this is the sum of the energy associated to all recHits linked to all SimClusters
dqm::reco::MonitorElement* energyDifference_; // This contains (energy-selfEnergy)/energy
dqm::reco::MonitorElement* eta_Zorigin_map_;
dqm::reco::MonitorElement* simPFSuperClusterSize_;
dqm::reco::MonitorElement* simPFSuperClusterEnergy_;
dqm::reco::MonitorElement* pfcandidateType_;
Expand Down Expand Up @@ -70,13 +61,8 @@ class CaloParticleValidation : public DQMGlobalEDAnalyzer<Histograms_CaloParticl

// ----------member data ---------------------------
std::string folder_;
std::vector<int> particles_to_monitor_;

edm::EDGetTokenT<std::vector<SimVertex>> simVertices_;
edm::EDGetTokenT<std::vector<CaloParticle>> caloParticles_;
edm::EDGetTokenT<std::vector<reco::SuperCluster>> simPFClusters_;
edm::EDGetTokenT<reco::PFCandidateCollection> simPFCandidates_;
const edm::EDGetTokenT<std::unordered_map<DetId, const HGCRecHit*>> hitMap_;
};

//
Expand All @@ -92,12 +78,8 @@ class CaloParticleValidation : public DQMGlobalEDAnalyzer<Histograms_CaloParticl
//
CaloParticleValidation::CaloParticleValidation(const edm::ParameterSet& iConfig)
: folder_(iConfig.getParameter<std::string>("folder")),
particles_to_monitor_(iConfig.getParameter<std::vector<int>>("particles_to_monitor")),
simVertices_(consumes<std::vector<SimVertex>>(iConfig.getParameter<edm::InputTag>("simVertices"))),
caloParticles_(consumes<std::vector<CaloParticle>>(iConfig.getParameter<edm::InputTag>("caloParticles"))),
simPFClusters_(consumes<std::vector<reco::SuperCluster>>(iConfig.getParameter<edm::InputTag>("simPFClusters"))),
simPFCandidates_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("simPFCandidates"))),
hitMap_(consumes<std::unordered_map<DetId, const HGCRecHit*>>(iConfig.getParameter<edm::InputTag>("hitMapTag"))) {
simPFCandidates_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("simPFCandidates"))) {
//now do what ever initialization is needed
}

Expand All @@ -117,18 +99,6 @@ void CaloParticleValidation::dqmAnalyze(edm::Event const& iEvent,
Histograms_CaloParticleValidation const& histos) const {
using namespace edm;

Handle<std::unordered_map<DetId, const HGCRecHit*>> hitMapHandle;
iEvent.getByToken(hitMap_, hitMapHandle);
const auto hitmap = *hitMapHandle;

Handle<std::vector<SimVertex>> simVerticesHandle;
iEvent.getByToken(simVertices_, simVerticesHandle);
std::vector<SimVertex> const& simVertices = *simVerticesHandle;

Handle<std::vector<CaloParticle>> caloParticleHandle;
iEvent.getByToken(caloParticles_, caloParticleHandle);
std::vector<CaloParticle> const& caloParticles = *caloParticleHandle;

Handle<std::vector<reco::SuperCluster>> simPFClustersHandle;
iEvent.getByToken(simPFClusters_, simPFClustersHandle);
std::vector<reco::SuperCluster> const& simPFClusters = *simPFClustersHandle;
Expand All @@ -137,40 +107,6 @@ void CaloParticleValidation::dqmAnalyze(edm::Event const& iEvent,
iEvent.getByToken(simPFCandidates_, simPFCandidatesHandle);
reco::PFCandidateCollection const& simPFCandidates = *simPFCandidatesHandle;

for (auto const& caloParticle : caloParticles) {
if (caloParticle.g4Tracks()[0].eventId().event() != 0 or
caloParticle.g4Tracks()[0].eventId().bunchCrossing() != 0) {
LogDebug("CaloParticleValidation") << "Excluding CaloParticles from event: "
<< caloParticle.g4Tracks()[0].eventId().event()
<< " with BX: " << caloParticle.g4Tracks()[0].eventId().bunchCrossing()
<< std::endl;
continue;
}
int id = caloParticle.pdgId();
if (histos.count(id)) {
auto& histo = histos.at(id);
histo.eta_->Fill(caloParticle.eta());
histo.pt_->Fill(caloParticle.pt());
histo.energy_->Fill(caloParticle.energy());
histo.nSimClusters_->Fill(caloParticle.simClusters().size());
// Find the corresponding vertex.
histo.eta_Zorigin_map_->Fill(simVertices.at(caloParticle.g4Tracks()[0].vertIndex()).position().z(),
caloParticle.eta());
int simHits = 0;
float energy = 0.;
for (auto const& sc : caloParticle.simClusters()) {
simHits += sc->hits_and_fractions().size();
for (auto const& h_and_f : sc->hits_and_fractions()) {
if (hitmap.count(h_and_f.first))
energy += hitmap.at(h_and_f.first)->energy() * h_and_f.second;
}
}
histo.nHitInSimClusters_->Fill((float)simHits);
histo.selfEnergy_->Fill(energy);
histo.energyDifference_->Fill(1. - energy / caloParticle.energy());
}
}

// simPFSuperClusters
for (auto const& sc : simPFClusters) {
histos.at(0).simPFSuperClusterSize_->Fill((float)sc.clustersSize());
Expand Down Expand Up @@ -201,18 +137,6 @@ void CaloParticleValidation::bookHistograms(DQMStore::IBooker& ibook,
edm::Run const& run,
edm::EventSetup const& iSetup,
Histograms_CaloParticleValidation& histos) const {
for (auto const particle : particles_to_monitor_) {
ibook.setCurrentFolder(folder_ + "CaloParticles/" + std::to_string(particle));
auto& histo = histos[particle];
histo.eta_ = ibook.book1D("Eta", "Eta", 80, -4., 4.);
histo.energy_ = ibook.book1D("Energy", "Energy", 250, 0., 500.);
histo.pt_ = ibook.book1D("Pt", "Pt", 100, 0., 100.);
histo.nSimClusters_ = ibook.book1D("NSimClusters", "NSimClusters", 100, 0., 100.);
histo.nHitInSimClusters_ = ibook.book1D("NHitInSimClusters", "NHitInSimClusters", 100, 0., 100.);
histo.selfEnergy_ = ibook.book1D("SelfEnergy", "SelfEnergy", 250, 0., 500.);
histo.energyDifference_ = ibook.book1D("EnergyDifference", "(Energy-SelfEnergy)/Energy", 300, -5., 1.);
histo.eta_Zorigin_map_ = ibook.book2D("Eta vs Zorigin", "Eta vs Zorigin", 80, -4., 4., 1100, -550., 550.);
}
int offset = 100000;
ibook.setCurrentFolder(folder_ + "PFCandidates");
histos[offset].pfcandidateType_ = ibook.book1D("PFCandidateType", "PFCandidateType", 10, 0, 10);
Expand All @@ -239,12 +163,8 @@ void CaloParticleValidation::fillDescriptions(edm::ConfigurationDescriptions& de
// Please change this to state exactly what you do use, even if it is no parameters
edm::ParameterSetDescription desc;
desc.add<std::string>("folder", "HGCAL/"); // Please keep the trailing '/'
desc.add<std::vector<int>>("particles_to_monitor", {11, -11, 13, -13, 22, 111, 211, -211, 321, -321});
desc.add<edm::InputTag>("simVertices", edm::InputTag("g4SimHits"));
desc.add<edm::InputTag>("caloParticles", edm::InputTag("mix", "MergedCaloTruth"));
desc.add<edm::InputTag>("simPFClusters", edm::InputTag("simPFProducer", "perfect"));
desc.add<edm::InputTag>("simPFCandidates", edm::InputTag("simPFProducer"));
desc.add<edm::InputTag>("hitMapTag", edm::InputTag("hgcalRecHitMapProducer"));
descriptions.add("caloparticlevalidationDefault", desc);
}

Expand Down
18 changes: 12 additions & 6 deletions Validation/HGCalValidation/plugins/HGCalValidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ void HGCalValidator::bookHistograms(DQMStore::IBooker& ibook,

for (auto const particle : particles_to_monitor_) {
ibook.setCurrentFolder(dirName_ + "SelectedCaloParticles/" + std::to_string(particle));
histoProducerAlgo_->bookCaloParticleHistos(ibook, histograms.histoProducerAlgo, particle);
histoProducerAlgo_->bookCaloParticleHistos(
ibook, histograms.histoProducerAlgo, particle, totallayers_to_monitor_);
}
ibook.cd();
ibook.setCurrentFolder(dirName_);
Expand Down Expand Up @@ -141,7 +142,9 @@ void HGCalValidator::bookHistograms(DQMStore::IBooker& ibook,
void HGCalValidator::cpParametersAndSelection(const Histograms& histograms,
std::vector<CaloParticle> const& cPeff,
std::vector<SimVertex> const& simVertices,
std::vector<size_t>& selected_cPeff) const {
std::vector<size_t>& selected_cPeff,
unsigned int layers,
std::unordered_map<DetId, const HGCRecHit*> const& hitMap) const {
selected_cPeff.reserve(cPeff.size());

size_t j = 0;
Expand All @@ -151,7 +154,8 @@ void HGCalValidator::cpParametersAndSelection(const Histograms& histograms,
if (!doCaloParticleSelection_ || (doCaloParticleSelection_ && cpSelector(caloParticle, simVertices))) {
selected_cPeff.push_back(j);
if (doCaloParticlePlots_) {
histoProducerAlgo_->fill_caloparticle_histos(histograms.histoProducerAlgo, id, caloParticle, simVertices);
histoProducerAlgo_->fill_caloparticle_histos(
histograms.histoProducerAlgo, id, caloParticle, simVertices, layers, hitMap);
}
}
++j;
Expand Down Expand Up @@ -214,9 +218,10 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event,
// ##############################################
// fill caloparticles histograms
// ##############################################
LogTrace("HGCalValidator") << "\n# of CaloParticles: " << caloParticles.size() << "\n";
// HGCRecHit are given to select the SimHits which are also reconstructed
LogTrace("HGCalValidator") << "\n# of CaloParticles: " << caloParticles.size() << "\n" << std::endl;
std::vector<size_t> selected_cPeff;
cpParametersAndSelection(histograms, caloParticles, simVertices, selected_cPeff);
cpParametersAndSelection(histograms, caloParticles, simVertices, selected_cPeff, totallayers_to_monitor_, *hitMap);

//get collections from the event
//Layer clusters
Expand Down Expand Up @@ -279,7 +284,8 @@ void HGCalValidator::dqmAnalyze(const edm::Event& event,
//General Info on multiclusters
LogTrace("HGCalValidator") << "\n# of multi clusters with " << label_mcl[wml].process() << ":"
<< label_mcl[wml].label() << ":" << label_mcl[wml].instance() << ": "
<< multiClusters.size() << "\n";
<< multiClusters.size() << "\n"
<< std::endl;
}
} //end of loop over multicluster input labels
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
tipCP = cms.double(60),
chargedOnlyCP = cms.bool(False),
stableOnlyCP = cms.bool(False),
pdgIdCP = cms.vint32(11, -11, 13, -13, 22, 111, 211, -211, 321, -321),
pdgIdCP = cms.vint32(11, -11, 13, -13, 22, 111, 211, -211, 321, -321, 311),
#--signal only means no PU particles
signalOnlyCP = cms.bool(True),
#--intime only means no OOT PU particles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,3 @@

from Validation.HGCalValidation.caloparticlevalidationDefault_cfi import caloparticlevalidationDefault as _caloparticlevalidationDefault
caloparticlevalidation = _caloparticlevalidationDefault.clone()

# TODO: The following would be needed to use the signal+pileup
# CaloParticles for premixing. However, the code uses SimVertices, and
# - we don't propagate pileup SimVertices (actually we don't do that even in classical mixing?)
# - the code will either produce garbage or throw an exception
from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2
premix_stage2.toModify(caloparticlevalidation,
caloParticles = "mixData:MergedCaloTruth"
)
Loading

0 comments on commit 56ff0af

Please sign in to comment.