Skip to content

Commit

Permalink
Merge pull request #37 from jbsauvan/optimize-frontend
Browse files Browse the repository at this point in the history
Optimize front-end processing time
  • Loading branch information
jbsauvan committed Aug 24, 2016
2 parents 4089647 + b30b142 commit 872dfa2
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

struct HGCalBestChoiceDataPayload
{
static const size_t size = 114;
static const size_t size = 130; // FIXME: check why 114 is not working
typedef std::array<uint32_t, size> trigger_cell_list; // list of trigger cell values
trigger_cell_list payload;

Expand Down
40 changes: 34 additions & 6 deletions L1Trigger/L1THGCal/plugins/HGCalTriggerDigiProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,48 @@ void HGCalTriggerDigiProducer::produce(edm::Event& e, const edm::EventSetup& es)
const HGCHEDigiCollection& fh_digis = *fh_digis_h;
const HGCHEDigiCollection& bh_digis = *bh_digis_h;

//we produce one output trigger digi per module in the FE
//so we use the geometry to tell us what to loop over
for( const auto& module : triggerGeometry_->modules() ) {
// First find modules containing hits and prepare list of hits for each module
std::unordered_map<uint32_t, HGCEEDigiCollection> hit_modules_ee;
for(const auto& eedata : ee_digis) {
const auto& module = triggerGeometry_->getModuleFromCell(eedata.id());
auto itr_insert = hit_modules_ee.emplace(module->moduleId(),HGCEEDigiCollection());
itr_insert.first->second.push_back(eedata);
}
std::unordered_map<uint32_t,HGCHEDigiCollection> hit_modules_fh;
for(const auto& fhdata : fh_digis) {
const auto& module = triggerGeometry_->getModuleFromCell(fhdata.id());
auto itr_insert = hit_modules_fh.emplace(module->moduleId(), HGCHEDigiCollection());
itr_insert.first->second.push_back(fhdata);
}
// loop on modules containing hits and call front-end processing
// we produce one output trigger digi per module in the FE
for( const auto& module_hits : hit_modules_ee ) {
const auto& module = triggerGeometry_->modules().at(module_hits.first);
fe_output->push_back(l1t::HGCFETriggerDigi());
l1t::HGCFETriggerDigi& digi = fe_output->back();
codec_->setDataPayload(*(module.second),ee_digis,fh_digis,bh_digis);
codec_->setDataPayload(*module,module_hits.second,HGCHEDigiCollection(),HGCHEDigiCollection());
codec_->encode(digi);
digi.setDetId( HGCalDetId(module.first) );
digi.setDetId( HGCalDetId(module_hits.first) );
std::stringstream output;
codec_->print(digi,output);
edm::LogInfo("HGCalTriggerDigiProducer")
<< output.str();
codec_->unSetDataPayload();
} //end loop on EE modules
for( const auto& module_hits : hit_modules_fh ) {
const auto& module = triggerGeometry_->modules().at(module_hits.first);
fe_output->push_back(l1t::HGCFETriggerDigi());
l1t::HGCFETriggerDigi& digi = fe_output->back();
codec_->setDataPayload(*module,HGCEEDigiCollection(),module_hits.second,HGCHEDigiCollection());
codec_->encode(digi);
digi.setDetId( HGCalDetId(module_hits.first) );
std::stringstream output;
codec_->print(digi,output);
edm::LogInfo("HGCalTriggerDigiProducer")
<< output.str();
codec_->unSetDataPayload();
}
} //end loop on FH modules


// get the orphan handle and fe digi collection
auto fe_digis_handle = e.put(std::move(fe_output));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ void HGCalTriggerGeometryHexImp1::fillMaps(const es_info& esInfo)
{
//
// read module mapping file
std::map<short, short> wafer_to_module_ee;
std::map<short, short> wafer_to_module_fh;
std::map<short, std::map<short,short>> module_to_wafers_ee;
std::map<short, std::map<short,short>> module_to_wafers_fh;
std::unordered_map<short, short> wafer_to_module_ee;
std::unordered_map<short, short> wafer_to_module_fh;
std::unordered_map<short, std::map<short,short>> module_to_wafers_ee;
std::unordered_map<short, std::map<short,short>> module_to_wafers_fh;
std::ifstream l1tModulesMappingStream(l1tModulesMapping_.fullPath());
if(!l1tModulesMappingStream.is_open()) edm::LogError("HGCalTriggerGeometry") << "Cannot open L1TModulesMapping file\n";
short subdet = 0;
Expand All @@ -83,7 +83,7 @@ void HGCalTriggerGeometryHexImp1::fillMaps(const es_info& esInfo)
l1tModulesMappingStream.close();
// read trigger cell mapping file
std::map<std::pair<short,short>, short> cells_to_trigger_cells;
std::map<short, short> number_trigger_cells_in_wafers; // the map key is the wafer type
std::unordered_map<short, short> number_trigger_cells_in_wafers; // the map key is the wafer type
std::ifstream l1tCellsMappingStream(l1tCellsMapping_.fullPath());
if(!l1tCellsMappingStream.is_open()) edm::LogError("HGCalTriggerGeometry") << "Cannot open L1TCellsMapping file\n";
short waferType = 0;
Expand Down Expand Up @@ -181,7 +181,7 @@ void HGCalTriggerGeometryHexImp1::buildTriggerCellsAndModules(const es_info& esI
// Build trigger cells and fill map
typedef HGCalTriggerGeometry::TriggerCell::list_type list_cells;
// make list of cells in trigger cells
std::map<unsigned, list_cells> trigger_cells_to_cells;
std::unordered_map<unsigned, list_cells> trigger_cells_to_cells;
for(const auto& cell_triggerCell : cells_to_trigger_cells_)
{
unsigned cell = cell_triggerCell.first;
Expand Down Expand Up @@ -213,7 +213,7 @@ void HGCalTriggerGeometryHexImp1::buildTriggerCellsAndModules(const es_info& esI
typedef HGCalTriggerGeometry::Module::list_type list_triggerCells;
typedef HGCalTriggerGeometry::Module::tc_map_type tc_map_to_cells;
// make list of trigger cells in modules
std::map<unsigned, list_triggerCells> modules_to_trigger_cells;
std::unordered_map<unsigned, list_triggerCells> modules_to_trigger_cells;
for(const auto& triggerCell_module : trigger_cells_to_modules_)
{
unsigned triggerCell = triggerCell_module.first;
Expand Down
160 changes: 106 additions & 54 deletions L1Trigger/L1THGCal/test/HGCalTriggerBestChoiceTester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class HGCalTriggerBestChoiceTester : public edm::EDAnalyzer
private:
void checkSelectedCells(const edm::Event&, const edm::EventSetup&);
void rerunBestChoiceFragments(const edm::Event&, const edm::EventSetup&);
void fillModule(const std::vector<HGCDataFrame<HGCalDetId,HGCSample>>&, const std::vector<std::pair<HGCalDetId, uint32_t > >&, const HGCalBestChoiceDataPayload&, const HGCalBestChoiceDataPayload&,const HGCalBestChoiceDataPayload&, const std::map <HGCalDetId,double>&, const std::map<uint32_t, double>& );
void fillModule(const std::vector<HGCDataFrame<HGCalDetId,HGCSample>>&, const std::vector<std::pair<HGCalDetId, uint32_t > >&, const HGCalBestChoiceDataPayload&, const HGCalBestChoiceDataPayload&,const HGCalBestChoiceDataPayload&, const std::map <HGCalDetId,double>&, const std::unordered_map<uint32_t, double>& );

// inputs
edm::EDGetToken inputee_, inputfh_, inputbh_, inputbeall_, inputbeselect_;
Expand Down Expand Up @@ -342,65 +342,117 @@ void HGCalTriggerBestChoiceTester::rerunBestChoiceFragments(const edm::Event& e,
simhit_energies[digiid_fh] = hit_energy;
}
}

//loop on modules
for( const auto& module : triggerGeometry_->modules() ) {
HGCalDetId moduleId(module.first);
// prepare input data
std::vector<HGCDataFrame<HGCalDetId,HGCSample>> dataframes;
std::vector<std::pair<HGCalDetId, uint32_t > > linearized_dataframes;

// loop over EE or FH digis and fill digis belonging to that module
if(moduleId.subdetId()==ForwardSubdetector::HGCEE) {
for(const auto& eedata : ee_digis) {
if(module.second->containsCell(eedata.id())) {
dataframes.emplace_back(eedata.id());
for(int i=0; i<eedata.size(); i++) {
dataframes.back().setSample(i, eedata.sample(i));
}
}
}
}
else if(moduleId.subdetId()==ForwardSubdetector::HGCHEF) {
for(const auto& fhdata : fh_digis) {
if(module.second->containsCell(fhdata.id())) {
dataframes.emplace_back(fhdata.id());
for(int i=0; i<fhdata.size(); i++) {
dataframes.back().setSample(i, fhdata.sample(i));
// Find modules containing hits and prepare list of hits for each module
std::unordered_map<uint32_t, std::vector<HGCEEDataFrame>> hit_modules_ee;
for(const auto& eedata : ee_digis)
{
const auto& module = triggerGeometry_->getModuleFromCell(eedata.id());
auto itr_insert = hit_modules_ee.emplace(module->moduleId(),std::vector<HGCEEDataFrame>());
itr_insert.first->second.push_back(eedata);
}
std::unordered_map<uint32_t,std::vector<HGCHEDataFrame>> hit_modules_fh;
for(const auto& fhdata : fh_digis)
{
const auto& module = triggerGeometry_->getModuleFromCell(fhdata.id());
auto itr_insert = hit_modules_fh.emplace(module->moduleId(), std::vector<HGCHEDataFrame>());
itr_insert.first->second.push_back(fhdata);
}
// loop on modules containing hits and call front-end processing
for( const auto& module_hits : hit_modules_ee )
{
HGCalDetId moduleId(module_hits.first);
// prepare input data
std::vector<HGCDataFrame<HGCalDetId,HGCSample>> dataframes;
std::vector<std::pair<HGCalDetId, uint32_t > > linearized_dataframes;
// loop over EE and fill digis belonging to that module
if(moduleId.subdetId()==ForwardSubdetector::HGCEE)
{
for(const auto& eedata : module_hits.second)
{
dataframes.emplace_back(eedata.id());
for(int i=0; i<eedata.size(); i++)
{
dataframes.back().setSample(i, eedata.sample(i));
}
}
}
const auto& module_ptr = triggerGeometry_->modules().at(module_hits.first);
// Association simhit energies with trigger cells
std::unordered_map<uint32_t, double> TC_simhit_energies;
if (is_Simhit_comp_)
{
for(const auto& tc_c : module_ptr->triggerCellComponents())
{
HGCalDetId triggercellid( tc_c.first );
uint32_t cellid = triggercellid.cell();
TC_simhit_energies.insert( std::make_pair(cellid, 0) );
double simenergy = simhit_energies[tc_c.second];
TC_simhit_energies[cellid]+=simenergy;
}
}
}
}
// Association simhit energies with trigger cells
std:: map<uint32_t, double> TC_simhit_energies;
if (is_Simhit_comp_) {
for(const auto& tc_c : module.second->triggerCellComponents()){
HGCalDetId triggercellid( tc_c.first );
uint32_t cellid = triggercellid.cell();
TC_simhit_energies.insert( std::make_pair(cellid, 0) );
double simenergy = simhit_energies[tc_c.second];
TC_simhit_energies[cellid]+=simenergy;
}
}

// Best choice encoding
data.reset();
codec_->linearize(*(module.second), dataframes, linearized_dataframes);
codec_->triggerCellSums(*(module.second), linearized_dataframes, data);
HGCalBestChoiceDataPayload data_TCsums_woBestChoice = data;
codec_->bestChoiceSelect(data);
HGCalBestChoiceDataPayload data_TCsums_BestChoice = data;
std::vector<bool> dataword = codec_->encode(data);
HGCalBestChoiceDataPayload datadecoded = codec_->decode(dataword);
fillModule(dataframes, linearized_dataframes, data_TCsums_woBestChoice,data_TCsums_BestChoice, datadecoded, simhit_energies, TC_simhit_energies);

} //end loop on modules

// Best choice encoding
data.reset();
codec_->linearize(*module_ptr, dataframes, linearized_dataframes);
codec_->triggerCellSums(*module_ptr, linearized_dataframes, data);
HGCalBestChoiceDataPayload data_TCsums_woBestChoice = data;
codec_->bestChoiceSelect(data);
HGCalBestChoiceDataPayload data_TCsums_BestChoice = data;
std::vector<bool> dataword = codec_->encode(data);
HGCalBestChoiceDataPayload datadecoded = codec_->decode(dataword);
fillModule(dataframes, linearized_dataframes, data_TCsums_woBestChoice,data_TCsums_BestChoice, datadecoded, simhit_energies, TC_simhit_energies);

} //end loop on EE modules
for( const auto& module_hits : hit_modules_fh )
{
HGCalDetId moduleId(module_hits.first);
// prepare input data
std::vector<HGCDataFrame<HGCalDetId,HGCSample>> dataframes;
std::vector<std::pair<HGCalDetId, uint32_t > > linearized_dataframes;
// loop over FH digis and fill digis belonging to that module
if(moduleId.subdetId()==ForwardSubdetector::HGCHEF)
{
for(const auto& fhdata : module_hits.second)
{
dataframes.emplace_back(fhdata.id());
for(int i=0; i<fhdata.size(); i++)
{
dataframes.back().setSample(i, fhdata.sample(i));
}
}
}
const auto& module_ptr = triggerGeometry_->modules().at(module_hits.first);
// Association simhit energies with trigger cells
std::unordered_map<uint32_t, double> TC_simhit_energies;
if (is_Simhit_comp_)
{
for(const auto& tc_c : module_ptr->triggerCellComponents())
{
HGCalDetId triggercellid( tc_c.first );
uint32_t cellid = triggercellid.cell();
TC_simhit_energies.insert( std::make_pair(cellid, 0) );
double simenergy = simhit_energies[tc_c.second];
TC_simhit_energies[cellid]+=simenergy;
}
}
// Best choice encoding
data.reset();
codec_->linearize(*module_ptr, dataframes, linearized_dataframes);
codec_->triggerCellSums(*module_ptr, linearized_dataframes, data);
HGCalBestChoiceDataPayload data_TCsums_woBestChoice = data;
codec_->bestChoiceSelect(data);
HGCalBestChoiceDataPayload data_TCsums_BestChoice = data;
std::vector<bool> dataword = codec_->encode(data);
HGCalBestChoiceDataPayload datadecoded = codec_->decode(dataword);
fillModule(dataframes, linearized_dataframes, data_TCsums_woBestChoice,data_TCsums_BestChoice, datadecoded, simhit_energies, TC_simhit_energies);
} //end loop on FH modules



}


/*****************************************************************/
void HGCalTriggerBestChoiceTester::fillModule( const std::vector<HGCDataFrame<HGCalDetId,HGCSample>>& dataframes, const std::vector<std::pair<HGCalDetId, uint32_t > >& linearized_dataframes, const HGCalBestChoiceDataPayload& fe_payload_TCsums_woBestChoice, const HGCalBestChoiceDataPayload& fe_payload_TCsums_BestChoice, const HGCalBestChoiceDataPayload& fe_payload, const std::map <HGCalDetId,double>& simhit_energies, const std::map<uint32_t, double>& TC_simhit_energies)
void HGCalTriggerBestChoiceTester::fillModule( const std::vector<HGCDataFrame<HGCalDetId,HGCSample>>& dataframes, const std::vector<std::pair<HGCalDetId, uint32_t > >& linearized_dataframes, const HGCalBestChoiceDataPayload& fe_payload_TCsums_woBestChoice, const HGCalBestChoiceDataPayload& fe_payload_TCsums_BestChoice, const HGCalBestChoiceDataPayload& fe_payload, const std::map <HGCalDetId,double>& simhit_energies, const std::unordered_map<uint32_t, double>& TC_simhit_energies)

/*****************************************************************/
{
Expand Down

0 comments on commit 872dfa2

Please sign in to comment.