Skip to content

Commit

Permalink
Merge pull request cms-sw#2 from valsdav/master
Browse files Browse the repository at this point in the history
Fixed SimHit energy fraction
  • Loading branch information
bmarzocc authored Jun 18, 2019
2 parents 9d93908 + ad1aacb commit 421b778
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 51 deletions.
19 changes: 8 additions & 11 deletions Dumpers/interface/RecoSimDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ class RecoSimDumper : public edm::EDAnalyzer
float caloParticle_phi;
std::vector<float> caloHit_energy;
std::vector<float> caloHit_time;
std::vector<int> caloHit_ieta;
std::vector<int> caloHit_iphi;
std::vector<int> caloHit_iz;
std::vector<float> simHit_energy;
std::vector<float> simHit_eta;
std::vector<float> simHit_phi;
Expand Down Expand Up @@ -201,14 +198,14 @@ class RecoSimDumper : public edm::EDAnalyzer
std::vector<float> superCluster_energy;
std::vector<float> superCluster_eta;
std::vector<float> superCluster_phi;
std::map<int,int> map_simHit_pfCLuster;
std::map<int,int> map_recHit_pfCLuster;
std::map<int,int> map_pfRecHit_pfCLuster;
std::map<int,int> map_pfClusterHit_pfCLuster;
std::map<int,int> map_simHit_superCLuster;
std::map<int,int> map_recHit_superCLuster;
std::map<int,int> map_pfRecHit_superCLuster;
std::map<int,int> map_superClusterHit_superCLuster;
std::map<int,int> map_simHit_pfCluster;
std::map<int,int> map_recHit_pfCluster;
std::map<int,int> map_pfRecHit_pfCluster;
std::map<int,int> map_pfClusterHit_pfCluster;
std::map<int,int> map_simHit_superCluster;
std::map<int,int> map_recHit_superCluster;
std::map<int,int> map_pfRecHit_superCluster;
std::map<int,int> map_superClusterHit_superCluster;
};

#endif
Expand Down
11 changes: 5 additions & 6 deletions Dumpers/python/RecoSimDumper_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

genParticleCollection = cms.InputTag("genParticles","","HLT"),
caloParticleCollection = cms.InputTag("mix","MergedCaloTruth","HLT"),
PCaloHitEBCollection = cms.InputTag("g4SimHits","EcalHitsEB","SIM"),
PCaloHitEECollection = cms.InputTag("g4SimHits","EcalHitsEE","SIM"),
ebRechitCollection = cms.InputTag("ecalRecHit","EcalRecHitsEB","RECO"),
eeRechitCollection = cms.InputTag("ecalRecHit","EcalRecHitsEE","RECO"),
pfRechitCollection = cms.InputTag("particleFlowRecHitECAL","","RECO"),
Expand All @@ -13,18 +15,15 @@

doCompression = cms.bool(True), #do the compression of floats
nBits = cms.int32(12), #nbits for float compression (<=23)
saveCalohits = cms.bool(False),
saveSimhits = cms.bool(True), #save simHits information
saveRechits = cms.bool(True), #save recHits information
savePFRechits = cms.bool(True), #save pfRecHits information
savePFCluster = cms.bool(True), #save pfClusters information
saveSuperCluster = cms.bool(False), #save superClusters information
useEnergyRegression = cms.bool(False), #save corrected energy
motherID = cms.int32(22), #save only caloParticles with this pdgId
motherID = cms.int32(22) #save only caloParticles with this pdgId
#motherID = cms.int32(0), #save only caloParticles with this pdgId

######################
# PCaloHits analysis
saveCalohits = cms.bool(False),
PCaloHitEBCollection = cms.InputTag("g4SimHits","EcalHitsEB","SIM"),
PCaloHitEECollection = cms.InputTag("g4SimHits","EcalHitsEE","SIM")

)
62 changes: 34 additions & 28 deletions Dumpers/src/RecoSimDumper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ RecoSimDumper::RecoSimDumper(const edm::ParameterSet& iConfig)
if(saveCalohits_){
tree->Branch("caloHit_energy","std::vector<float>",&caloHit_energy);
tree->Branch("caloHit_time","std::vector<float>",&caloHit_time);
tree->Branch("caloHit_ieta","std::vector<int>",&caloHit_ieta);
tree->Branch("caloHit_iphi","std::vector<int>",&caloHit_iphi);
tree->Branch("caloHit_iz","std::vector<int>",&caloHit_iz);
}
if(saveSimhits_){
tree->Branch("simHit_energy","std::vector<float>",&simHit_energy);
Expand Down Expand Up @@ -195,10 +192,10 @@ RecoSimDumper::RecoSimDumper(const edm::ParameterSet& iConfig)
tree->Branch("pfCluster_energy","std::vector<float>",&pfCluster_energy);
tree->Branch("pfCluster_eta","std::vector<float>",&pfCluster_eta);
tree->Branch("pfCluster_phi","std::vector<float>",&pfCluster_phi);
if(saveSimhits_)tree->Branch("map_simHit_pfCLuster","std::map<int,int>",&map_simHit_pfCLuster);
if(!saveSimhits_ && saveRechits_)tree->Branch("map_recHit_pfCLuster","std::map<int,int>",&map_recHit_pfCLuster);
if(!saveSimhits_ && !saveRechits_ && savePFRechits_)tree->Branch("map_pfRecHit_pfCLuster","std::map<int,int>",&map_pfRecHit_pfCLuster);
if(!saveSimhits_ && !saveRechits_ && !savePFRechits_)tree->Branch("map_pfClusterHit_pfCLuster","std::map<int,int>",&map_pfClusterHit_pfCLuster);
if(saveSimhits_)tree->Branch("map_simHit_pfCluster","std::map<int,int>",&map_simHit_pfCluster);
if(!saveSimhits_ && saveRechits_)tree->Branch("map_recHit_pfCluster","std::map<int,int>",&map_recHit_pfCluster);
if(!saveSimhits_ && !saveRechits_ && savePFRechits_)tree->Branch("map_pfRecHit_pfCluster","std::map<int,int>",&map_pfRecHit_pfCluster);
if(!saveSimhits_ && !saveRechits_ && !savePFRechits_)tree->Branch("map_pfClusterHit_pfCluster","std::map<int,int>",&map_pfClusterHit_pfCluster);
}
if(saveSuperCluster_){
tree->Branch("superClusterHit_energy","std::vector<float>",&superClusterHit_energy);
Expand All @@ -212,10 +209,10 @@ RecoSimDumper::RecoSimDumper(const edm::ParameterSet& iConfig)
tree->Branch("superCluster_energy","std::vector<float>",&superCluster_energy);
tree->Branch("superCluster_eta","std::vector<float>",&superCluster_eta);
tree->Branch("superCluster_phi","std::vector<float>",&superCluster_phi);
if(saveSimhits_)tree->Branch("map_simHit_superCLuster","std::map<int,int>",&map_simHit_superCLuster);
if(!saveSimhits_ && saveRechits_)tree->Branch("map_recHit_superCLuster","std::map<int,int>",&map_recHit_superCLuster);
if(!saveSimhits_ && !saveRechits_ && savePFRechits_)tree->Branch("map_pfRecHit_superCLuster","std::map<int,int>",&map_pfRecHit_pfCLuster);
if(!saveSimhits_ && !saveRechits_ && !savePFRechits_)tree->Branch("map_superClusterHit_superCLuster","std::map<int,int>",&map_superClusterHit_superCLuster);
if(saveSimhits_)tree->Branch("map_simHit_superCluster","std::map<int,int>",&map_simHit_superCluster);
if(!saveSimhits_ && saveRechits_)tree->Branch("map_recHit_superCluster","std::map<int,int>",&map_recHit_superCluster);
if(!saveSimhits_ && !saveRechits_ && savePFRechits_)tree->Branch("map_pfRecHit_superCluster","std::map<int,int>",&map_pfRecHit_pfCluster);
if(!saveSimhits_ && !saveRechits_ && !savePFRechits_)tree->Branch("map_superClusterHit_superCluster","std::map<int,int>",&map_superClusterHit_superCluster);
}
}

Expand Down Expand Up @@ -330,6 +327,8 @@ void RecoSimDumper::analyze(const edm::Event& ev, const edm::EventSetup& iSetup)

//SetBranch values to default
setDefaultValues();
caloHit_energy.clear();
caloHit_time.clear();
simHit_energy.clear();
simHit_eta.clear();
simHit_phi.clear();
Expand Down Expand Up @@ -404,6 +403,18 @@ void RecoSimDumper::analyze(const edm::Event& ev, const edm::EventSetup& iSetup)
caloParticle_eta = iCalo.eta();
caloParticle_phi = iCalo.phi();

// Accumulate PCaloHit energies to be able to calculate
// the energy fraction of the hits in SimCluster.
// In CaloParticle the simCluster fractions are calculated with
// respect of total energy in the event for given detid
map<int, float> detIDtoTotEn;
for (auto & pch : *(PCaloHitsEB.product())){
detIDtoTotEn[pch.id()] += pch.energy();
}
for (auto & pch : *(PCaloHitsEE.product())){
detIDtoTotEn[pch.id()] += pch.energy();
}

//Get hits from simClusters, and associated recHits, pfRechits, PFClusterhit and superClusterhit
int simHit_index=-1;
const auto& simClusters = iCalo.simClusters();
Expand Down Expand Up @@ -439,7 +450,8 @@ void RecoSimDumper::analyze(const edm::Event& ev, const edm::EventSetup& iSetup)
}

if(saveSimhits_){
simHit_energy.push_back(reduceFloat(hits_and_fractions[iHit].second*simCluster->energy(),nBits_));
simHit_energy.push_back(reduceFloat(hits_and_fractions[iHit].second*detIDtoTotEn[id.rawId()],nBits_));
//cout << "iSimCl: "<< iSC << " | id: " << id.rawId()<< " | Fraction: "<< hits_and_fractions[iHit].second << " | energy tot: " << detIDtoTotEn[id.rawId()] <<endl;
simHit_eta.push_back(reduceFloat(eta,nBits_));
simHit_phi.push_back(reduceFloat(phi,nBits_));
}
Expand All @@ -451,12 +463,9 @@ void RecoSimDumper::analyze(const edm::Event& ev, const edm::EventSetup& iSetup)
if (pch.id() == id.rawId()){
caloHit_energy.push_back(reduceFloat(pch.energy(),nBits_));
caloHit_time.push_back(reduceFloat(pch.time(),nBits_));
caloHit_ieta.push_back(ieta);
caloHit_iphi.push_back(iphi);
caloHit_iz.push_back(iz);
}
}
}
}
}

if(saveSimhits_){
simHit_ieta.push_back(ieta);
Expand Down Expand Up @@ -512,9 +521,6 @@ void RecoSimDumper::analyze(const edm::Event& ev, const edm::EventSetup& iSetup)
if (pch.id() == id.rawId()){
caloHit_energy.push_back(reduceFloat(pch.energy(),nBits_));
caloHit_time.push_back(reduceFloat(pch.time(),nBits_));
caloHit_ieta.push_back(ieta);
caloHit_iphi.push_back(iphi);
caloHit_iz.push_back(iz);
}
}
}
Expand Down Expand Up @@ -617,20 +623,20 @@ void RecoSimDumper::analyze(const edm::Event& ev, const edm::EventSetup& iSetup)
}
//map simHit to PFCluster and to SuperCluster
if(saveSimhits_){
if(savePFCluster_) map_simHit_pfCLuster.insert(pair<int,int>(simHit_index,pfCluster_index));
if(saveSuperCluster_) map_simHit_superCLuster.insert(pair<int,int>(simHit_index,superCluster_index));
if(savePFCluster_) map_simHit_pfCluster.insert(pair<int,int>(simHit_index,pfCluster_index));
if(saveSuperCluster_) map_simHit_superCluster.insert(pair<int,int>(simHit_index,superCluster_index));
}
if(!saveSimhits_ && saveRechits_){
if(savePFCluster_) map_recHit_pfCLuster.insert(pair<int,int>(simHit_index,pfCluster_index));
if(saveSuperCluster_) map_recHit_superCLuster.insert(pair<int,int>(simHit_index,superCluster_index));
if(savePFCluster_) map_recHit_pfCluster.insert(pair<int,int>(simHit_index,pfCluster_index));
if(saveSuperCluster_) map_recHit_superCluster.insert(pair<int,int>(simHit_index,superCluster_index));
}
if(!saveSimhits_ && !saveRechits_ && savePFRechits_){
if(savePFCluster_) map_pfRecHit_pfCLuster.insert(pair<int,int>(simHit_index,pfCluster_index));
if(saveSuperCluster_) map_pfRecHit_superCLuster.insert(pair<int,int>(simHit_index,superCluster_index));
if(savePFCluster_) map_pfRecHit_pfCluster.insert(pair<int,int>(simHit_index,pfCluster_index));
if(saveSuperCluster_) map_pfRecHit_superCluster.insert(pair<int,int>(simHit_index,superCluster_index));
}
if(!saveSimhits_ && !saveRechits_ && !savePFRechits_){
if(savePFCluster_) map_pfClusterHit_pfCLuster.insert(pair<int,int>(simHit_index,pfCluster_index));
if(saveSuperCluster_) map_superClusterHit_superCLuster.insert(pair<int,int>(simHit_index,superCluster_index));
if(savePFCluster_) map_pfClusterHit_pfCluster.insert(pair<int,int>(simHit_index,pfCluster_index));
if(saveSuperCluster_) map_superClusterHit_superCluster.insert(pair<int,int>(simHit_index,superCluster_index));
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions Dumpers/test/step2_DIGI_L1_DIGI2RAW_HLT.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@
outputCommands = process.FEVTDEBUGHLTEventContent.outputCommands,
splitLevel = cms.untracked.int32(0)
)
process.FEVTDEBUGHLTEventContent.outputCommands.extend(['keep *_mix_MergedCaloTruth_*'])
process.FEVTDEBUGHLTEventContent.outputCommands.extend(['keep *_*genParticle*_*_*'])
process.FEVTDEBUGHLTEventContent.outputCommands.extend(
['keep *_mix_MergedCaloTruth_*',
'keep *_*genParticle*_*_*'])

# Additional output definition

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@
splitLevel = cms.untracked.int32(0)
)
process.RECOSIMoutput.outputCommands.extend(['keep *_mix_MergedCaloTruth_*',
'keep *_particleFlowRecHitECAL_*_*'])

#process.RECOSIMoutput.outputCommands.extend(['keep *PCaloHit*_g4SimHits_EcalHitsE*_*'])

'keep *_particleFlowRecHitECAL_*_*',
'keep *PCaloHit*_g4SimHits_EcalHitsE*_*',
'keep *_*genParticle*_*_*'])

process.MINIAODSIMoutput = cms.OutputModule("PoolOutputModule",
compressionAlgorithm = cms.untracked.string('LZMA'),
Expand Down

0 comments on commit 421b778

Please sign in to comment.