Skip to content

Commit

Permalink
Merge branch 'moh-modSplit' of github.com:mhassans/cmssw into moh-mod…
Browse files Browse the repository at this point in the history
…Split
  • Loading branch information
Mohammadhassan Hassanshahi committed Jun 10, 2021
2 parents 78ab68e + b72659d commit 54c1049
Show file tree
Hide file tree
Showing 8 changed files with 3,744 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DataFormats/L1THGCal/interface/HGCalTowerMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace l1t {

const HGCalTowerMap& operator+=(const HGCalTowerMap& map);

bool addEt(short bin_id, float etEm, float etHad);
bool addEt(std::unordered_map<unsigned short, float> binIDandShares, float etEm, float etHad);

unsigned nTowers() const { return towerMap_.size(); }
const std::unordered_map<unsigned short, l1t::HGCalTower>& towers() const { return towerMap_; }
Expand Down
15 changes: 8 additions & 7 deletions DataFormats/L1THGCal/src/HGCalTowerMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ const HGCalTowerMap& HGCalTowerMap::operator+=(const HGCalTowerMap& map) {
return *this;
}

bool HGCalTowerMap::addEt(short bin_id, float etEm, float etHad) {
auto this_tower = towerMap_.find(bin_id);
if (this_tower == towerMap_.end())
return false;
this_tower->second.addEtEm(etEm);
this_tower->second.addEtHad(etHad);

bool HGCalTowerMap::addEt(std::unordered_map<unsigned short, float> binIDandShares, float etEm, float etHad) {
for (auto binIDandShare: binIDandShares){
auto this_tower = towerMap_.find(binIDandShare.first);
if (this_tower == towerMap_.end())
return false;
this_tower->second.addEtEm(etEm*binIDandShare.second);
this_tower->second.addEtHad(etHad*binIDandShare.second);
}
return true;
}
3,627 changes: 3,627 additions & 0 deletions L1Trigger/L1THGCal/data/tower_per_module.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "L1Trigger/L1THGCal/interface/HGCalTriggerTools.h"
#include "DataFormats/L1THGCal/interface/HGCalTriggerCell.h"
#include "DataFormats/L1THGCal/interface/HGCalTriggerSums.h"
#include "L1Trigger/L1THGCal/interface/HGCalModuleDetId.h"

#include <vector>
#include <unordered_map>
Expand All @@ -35,8 +36,8 @@ class HGCalTriggerTowerGeometryHelper {
const std::vector<l1t::HGCalTowerCoord>& getTowerCoordinates() const;

unsigned short getTriggerTowerFromEtaPhi(const float& eta, const float& phi) const;
unsigned short getTriggerTower(const l1t::HGCalTriggerCell&) const;
unsigned short getTriggerTower(const l1t::HGCalTriggerSums&) const;
std::unordered_map<unsigned short, float> getTriggerTower(const l1t::HGCalTriggerCell&) const;
std::unordered_map<unsigned short, float> getTriggerTower(const l1t::HGCalTriggerSums&) const;

const bool isNose() { return doNose_; }

Expand Down
5 changes: 5 additions & 0 deletions L1Trigger/L1THGCal/python/customTowers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FWCore.ParameterSet.Config as cms
from L1Trigger.L1THGCal.hgcalTowerMapProducer_cfi import L1TTriggerTowerConfig_energySplit
import math

def custom_towers_unclustered_tc(process):
Expand Down Expand Up @@ -35,6 +36,10 @@ def custom_towers_etaphi(process,
parameters_towers_2d.L1TTriggerTowerConfig.binsPhi = cms.vdouble(binsPhi)
return process

def custom_towers_energySplit(process):
parameters_towers_2d = L1TTriggerTowerConfig_energySplit.clone()
process.hgcalTowerMapProducer.ProcessorParameters.towermap_parameters.L1TTriggerTowerConfig = parameters_towers_2d
return process

def custom_towers_map(process,
towermapping='L1Trigger/L1THGCal/data/tower_mapping_hgcroc_eta-phi_v3.txt',
Expand Down
11 changes: 11 additions & 0 deletions L1Trigger/L1THGCal/python/hgcalTowerMapProducer_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
binsEta=cms.vdouble(),
binsPhi=cms.vdouble())

L1TTriggerTowerConfig_energySplit = cms.PSet(readMappingFile=cms.bool(False),
doNose=cms.bool(False),
minEta=cms.double(1.305),
maxEta=cms.double(3.045),
minPhi=cms.double(-1*math.pi),
maxPhi=cms.double(math.pi),
nBinsEta=cms.int32(20),
nBinsPhi=cms.int32(72),
binsEta=cms.vdouble(),
binsPhi=cms.vdouble())

towerMap2D_parValues = cms.PSet( useLayerWeights = cms.bool(False),
layerWeights = cms.vdouble(),
AlgoName = cms.string('HGCalTowerMapsWrapper'),
Expand Down
75 changes: 68 additions & 7 deletions L1Trigger/L1THGCal/src/HGCalTriggerTowerGeometryHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,82 @@ unsigned short HGCalTriggerTowerGeometryHelper::getTriggerTowerFromEtaPhi(const
bin_phi = bin_phi_l - binsPhi_.begin() - 1;
}
int zside = eta < 0 ? -1 : 1;

return l1t::HGCalTowerID(doNose_, zside, bin_eta, bin_phi).rawId();
}

unsigned short HGCalTriggerTowerGeometryHelper::getTriggerTower(const l1t::HGCalTriggerCell& thecell) const {
std::unordered_map<unsigned short, float> HGCalTriggerTowerGeometryHelper::getTriggerTower(const l1t::HGCalTriggerCell& thecell) const {
std::unordered_map<unsigned short, float> binIDandShares = {};
unsigned int trigger_cell_id = thecell.detId();
// NOTE: if the TC is not found in the map than it is mapped via eta-phi coords.
// this can be considered dangerous (silent failure of the map) but it actually allows to save
// memory mapping explicitly only what is actually needed
auto tower_id_itr = cells_to_trigger_towers_.find(trigger_cell_id);
if (tower_id_itr != cells_to_trigger_towers_.end())
return tower_id_itr->second;

return getTriggerTowerFromEtaPhi(thecell.position().eta(), thecell.position().phi());
if (tower_id_itr != cells_to_trigger_towers_.end()){
binIDandShares.insert({tower_id_itr->second, 1});
return binIDandShares;
}
binIDandShares.insert({getTriggerTowerFromEtaPhi(thecell.position().eta(), thecell.position().phi()), 1});
return binIDandShares;
}

unsigned short HGCalTriggerTowerGeometryHelper::getTriggerTower(const l1t::HGCalTriggerSums& thesum) const {
return getTriggerTowerFromEtaPhi(thesum.position().eta(), thesum.position().phi());
std::unordered_map<unsigned short, float> HGCalTriggerTowerGeometryHelper::getTriggerTower(const l1t::HGCalTriggerSums& thesum) const {
HGCalModuleDetId detid(thesum.detId());
int moduleU = detid.moduleU();
int moduleV = detid.moduleV();
int layer = detid.layer();
int sector = detid.sector();
int zside = detid.zside();

int subdet = -1;
int splitDevisor = -1;
if(detid.isHScintillator()){ //FIXME HFNose not handled
subdet = 2;
layer += 28;
splitDevisor = 16; //FIXME should be added from the config
} else if(detid.isEE()){
subdet = 0;
splitDevisor = 8;
} else if(detid.isHSilicon()) {
subdet = 1;
layer += 28;
splitDevisor = 8;
}
std::ifstream input("../L1Trigger/L1THGCal/data/tower_per_module.txt");

std::vector<std::string> result;
std::string line;
getline(input, line); //To skip column names row

for( std::string line; getline( input, line ); ){
std::stringstream ss(line);
while(ss.good()){
std::string substr;
std::getline(ss, substr, ' ');
result.push_back(substr);
}

if (std::stoi(result[0])==subdet && std::stoi(result[1])==layer && std::stoi(result[2])==moduleU && std::stoi(result[3])==moduleV){
break;
}
else{
result.clear();
}
}

std::unordered_map<unsigned short, float> binIDandShares = {};

int towerEta;
int towerPhi;

for (int i=1; i<=std::stoi(result[4]); i++){
towerEta = 2 + std::stoi(result[3*i+2]); // shift by two to avoid negative eta
towerPhi = (std::stoi(result[3*i+3]) + sector*int(nBinsPhi_)/3) % int(nBinsPhi_); // move to the correct sector
towerPhi = (towerPhi + int(nBinsPhi_)) % int(nBinsPhi_); //correct for negative phi
binIDandShares.insert( {l1t::HGCalTowerID(doNose_, zside, towerEta, towerPhi).rawId(), std::stod(result[3*i+4])/splitDevisor } );
}

return binIDandShares; //FIXME add option (boolean) to the config to choose to return in the new and old ways
// return getTriggerTowerFromEtaPhi(thesum.position().eta(), thesum.position().phi());

}
23 changes: 21 additions & 2 deletions L1Trigger/L1THGCalUtilities/test/testHGCalL1T_RelValV11_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,22 @@


process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(50)
input = cms.untracked.int32(2000)
)

# Input source
filePfx = '/store/mc/Phase2HLTTDRWinter20DIGI/SingleElectron_PT2to200/GEN-SIM-DIGI-RAW/PU200_110X_mcRun4_realistic_v3_ext2-v2/40000/'
process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring('/store/mc/Phase2HLTTDRWinter20DIGI/SingleElectron_PT2to200/GEN-SIM-DIGI-RAW/PU200_110X_mcRun4_realistic_v3_ext2-v2/40000/00582F93-5A2A-5847-8162-D81EE503500F.root'),
fileNames = cms.untracked.vstring(filePfx + '/00582F93-5A2A-5847-8162-D81EE503500F.root',
filePfx + '/01C92E48-6B8E-6D4B-8B57-57540AFBC9D5.root',
filePfx + '/01F69B83-AC48-1242-9C6D-339335FABC1E.root',
filePfx + '/022471A5-F18F-3D45-AAF0-88BAAA4B159C.root',
filePfx + '/025E005F-AF77-9F45-AC99-4A78ADBAFF40.root',
filePfx + '/0287BD18-6928-8844-9919-E2183E3C5BF4.root',
filePfx + '/02C1307B-78C5-BC4F-B854-6988CD65D4C8.root',
filePfx + '/03B69335-90DB-EA48-9D5C-F88786E854F0.root',
filePfx + '/0457C237-9151-ED46-8FD5-F1B152AA824F.root',
filePfx + '/0457CFA7-3B54-324F-B61F-CA1F9384266B.root'),
inputCommands=cms.untracked.vstring(
'keep *',
'drop l1tEMTFHit2016Extras_simEmtfDigis_CSC_HLT',
Expand Down Expand Up @@ -69,6 +79,15 @@
# load HGCAL TPG simulation
process.load('L1Trigger.L1THGCal.hgcalTriggerPrimitives_cff')

from L1Trigger.L1THGCal.customTriggerSums import custom_full_trigger_sums
process = custom_full_trigger_sums(process)

from L1Trigger.L1THGCal.customTriggerGeometry import custom_geometry_decentralized_V11
process = custom_geometry_decentralized_V11(process, implementation=2)

from L1Trigger.L1THGCal.customTowers import custom_towers_energySplit
process = custom_towers_energySplit(process)

process.hgcl1tpg_step = cms.Path(process.hgcalTriggerPrimitives)


Expand Down

0 comments on commit 54c1049

Please sign in to comment.