Skip to content

Commit

Permalink
Merge pull request cms-sw#40 from jbsauvan/change-bit-truncation
Browse files Browse the repository at this point in the history
Change bit truncation
  • Loading branch information
jbsauvan committed Sep 8, 2016
2 parents 1a9f31c + 447cf8c commit 8649100
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 77 deletions.
4 changes: 4 additions & 0 deletions L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h
Expand Up @@ -28,6 +28,7 @@ class HGCalTriggerGeometryBase

typedef std::unordered_map<unsigned,unsigned> geom_map;
typedef std::unordered_set<unsigned> geom_set;
typedef std::set<unsigned> geom_ordered_set;

HGCalTriggerGeometryBase(const edm::ParameterSet& conf);
virtual ~HGCalTriggerGeometryBase() {}
Expand All @@ -51,6 +52,9 @@ class HGCalTriggerGeometryBase
virtual geom_set getCellsFromModule( const unsigned cell_det_id ) const = 0;
virtual geom_set getTriggerCellsFromModule( const unsigned trigger_cell_det_id ) const = 0;

virtual geom_ordered_set getOrderedCellsFromModule( const unsigned cell_det_id ) const = 0;
virtual geom_ordered_set getOrderedTriggerCellsFromModule( const unsigned trigger_cell_det_id ) const = 0;

virtual GlobalPoint getTriggerCellPosition(const unsigned trigger_cell_det_id) const = 0;
virtual GlobalPoint getModulePosition(const unsigned module_det_id) const = 0;

Expand Down
3 changes: 3 additions & 0 deletions L1Trigger/L1THGCal/interface/HGCalTriggerGeometryOld.h
Expand Up @@ -155,6 +155,9 @@ class HGCalTriggerGeometryOld : public HGCalTriggerGeometryBase {
virtual geom_set getCellsFromModule( const unsigned cell_det_id ) const override final;
virtual geom_set getTriggerCellsFromModule( const unsigned trigger_cell_det_id ) const override final;

virtual geom_ordered_set getOrderedCellsFromModule( const unsigned cell_det_id ) const override final;
virtual geom_ordered_set getOrderedTriggerCellsFromModule( const unsigned trigger_cell_det_id ) const override final;

virtual GlobalPoint getTriggerCellPosition(const unsigned trigger_cell_det_id) const override final;
virtual GlobalPoint getModulePosition(const unsigned module_det_id) const override final;

Expand Down
Expand Up @@ -13,7 +13,7 @@

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

Expand Down
Expand Up @@ -24,6 +24,9 @@ class HGCalTriggerGeometryHexImp2 : public HGCalTriggerGeometryBase
virtual geom_set getCellsFromModule( const unsigned cell_det_id ) const override final;
virtual geom_set getTriggerCellsFromModule( const unsigned trigger_cell_det_id ) const override final;

virtual geom_ordered_set getOrderedCellsFromModule( const unsigned cell_det_id ) const override final;
virtual geom_ordered_set getOrderedTriggerCellsFromModule( const unsigned trigger_cell_det_id ) const override final;

virtual GlobalPoint getTriggerCellPosition(const unsigned trigger_cell_det_id) const override final;
virtual GlobalPoint getModulePosition(const unsigned module_det_id) const override final;

Expand Down Expand Up @@ -186,6 +189,42 @@ getCellsFromModule( const unsigned module_det_id ) const
return cell_det_ids;
}

HGCalTriggerGeometryBase::geom_ordered_set
HGCalTriggerGeometryHexImp2::
getOrderedCellsFromModule( const unsigned module_det_id ) const
{
unsigned module = HGCTriggerHexDetId::waferOf(module_det_id);
int wafer_type = HGCTriggerHexDetId::waferTypeOf(module_det_id);
unsigned subdet = HGCTriggerHexDetId::subdetIdOf(module_det_id);
std::pair<std::unordered_multimap<short, short>::const_iterator,
std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
switch(subdet)
{
case ForwardSubdetector::HGCEE:
wafer_itrs = module_to_wafers_ee_.equal_range(module);
break;
case ForwardSubdetector::HGCHEF:
wafer_itrs = module_to_wafers_fh_.equal_range(module);
break;
default:
edm::LogError("HGCalTriggerGeometry") << "Unknown module->wafers mapping for subdet "<<subdet<<"\n";
return geom_ordered_set();
};
geom_ordered_set cell_det_ids;
for(auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
{
// loop on the cells in each wafer
for(int cell=0; cell<number_cells_in_wafers_.at(wafer_type); cell++)
{
unsigned cell_det_id = module_det_id;
HGCTriggerHexDetId::setWaferOf(cell_det_id, wafer_itr->second);
HGCTriggerHexDetId::setCellOf(cell_det_id, cell);
cell_det_ids.emplace(cell_det_id);
}
}
return cell_det_ids;
}

HGCalTriggerGeometryBase::geom_set
HGCalTriggerGeometryHexImp2::
getTriggerCellsFromModule( const unsigned module_det_id ) const
Expand Down Expand Up @@ -223,6 +262,44 @@ getTriggerCellsFromModule( const unsigned module_det_id ) const
return trigger_cell_det_ids;
}

HGCalTriggerGeometryBase::geom_ordered_set
HGCalTriggerGeometryHexImp2::
getOrderedTriggerCellsFromModule( const unsigned module_det_id ) const
{
unsigned module = HGCTriggerHexDetId::waferOf(module_det_id);
unsigned wafer_type = HGCTriggerHexDetId::waferTypeOf(module_det_id);
unsigned subdet = HGCTriggerHexDetId::subdetIdOf(module_det_id);
std::pair<std::unordered_multimap<short, short>::const_iterator,
std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
switch(subdet)
{
case ForwardSubdetector::HGCEE:
wafer_itrs = module_to_wafers_ee_.equal_range(module);
break;
case ForwardSubdetector::HGCHEF:
wafer_itrs = module_to_wafers_fh_.equal_range(module);
break;
default:
edm::LogError("HGCalTriggerGeometry") << "Unknown module->wafers mapping for subdet "<<subdet<<"\n";
return geom_ordered_set();
};
geom_ordered_set trigger_cell_det_ids;
// loop on the wafers included in the module
for(auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
{
// loop on the trigger cells in each wafer
for(int trigger_cell=0; trigger_cell<number_trigger_cells_in_wafers_.at(wafer_type); trigger_cell++)
{
unsigned trigger_cell_det_id = module_det_id;
HGCTriggerHexDetId::setWaferOf(trigger_cell_det_id, wafer_itr->second);
HGCTriggerHexDetId::setCellOf(trigger_cell_det_id, trigger_cell);
trigger_cell_det_ids.emplace(trigger_cell_det_id);
}
}
return trigger_cell_det_ids;
}


GlobalPoint
HGCalTriggerGeometryHexImp2::
getTriggerCellPosition(const unsigned trigger_cell_det_id) const
Expand Down
Expand Up @@ -7,7 +7,7 @@
NData = cms.uint32(12),
DataLength = cms.uint32(8),
linLSB = cms.double(100./1024.),
triggerCellTruncationBits = cms.uint32(2),
triggerCellTruncationBits = cms.uint32(7),
#take the following parameters from the digitization config file
adcsaturation = digiparam.hgceeDigitizer.digiCfg.feCfg.adcSaturation_fC,
adcnBits = digiparam.hgceeDigitizer.digiCfg.feCfg.adcNbits,
Expand Down
22 changes: 22 additions & 0 deletions L1Trigger/L1THGCal/src/HGCalTriggerGeometryOld.cc
Expand Up @@ -70,12 +70,34 @@ getCellsFromModule( const unsigned module_det_id ) const {
return cells;
}

HGCalTriggerGeometryBase::geom_ordered_set
HGCalTriggerGeometryOld::
getOrderedCellsFromModule( const unsigned module_det_id ) const {
const auto& triggercell_cells = modules_.find(module_det_id)->second->triggerCellComponents();
HGCalTriggerGeometryBase::geom_ordered_set cells;
for(const auto& tc_c : triggercell_cells) {
cells.emplace(tc_c.second);
}
return cells;
}

HGCalTriggerGeometryBase::geom_set
HGCalTriggerGeometryOld::
getTriggerCellsFromModule( const unsigned module_det_id ) const {
return modules_.find(module_det_id)->second->components();
}

HGCalTriggerGeometryBase::geom_ordered_set
HGCalTriggerGeometryOld::
getOrderedTriggerCellsFromModule( const unsigned module_det_id ) const {
// Build set from unordered_set. Maybe a more efficient to do it
HGCalTriggerGeometryBase::geom_ordered_set trigger_cells;
for(const auto& tc : modules_.find(module_det_id)->second->components()) {
trigger_cells.emplace(tc);
}
return trigger_cells;
}

GlobalPoint
HGCalTriggerGeometryOld::
getTriggerCellPosition(const unsigned trigger_cell_det_id) const {
Expand Down
11 changes: 9 additions & 2 deletions L1Trigger/L1THGCal/src/fe_codecs/HGCalBestChoiceCodecImpl.cc
Expand Up @@ -120,11 +120,11 @@ void HGCalBestChoiceCodecImpl::linearize(const std::vector<HGCDataFrame<HGCalDet
void HGCalBestChoiceCodecImpl::triggerCellSums(const HGCalTriggerGeometryBase& geometry, const std::vector<std::pair<HGCalDetId, uint32_t > >& linearized_dataframes, data_type& data)
/*****************************************************************/
{
if(linearized_dataframes.size()==0) return;
std::map<HGCTriggerHexDetId, uint32_t> payload;
// sum energies in trigger cells
for(const auto& frame : linearized_dataframes)
{
// FIXME: only EE
HGCalDetId cellid(frame.first);
// find trigger cell associated to cell
uint32_t tcid = geometry.getTriggerCellFromCell(cellid);
Expand All @@ -135,10 +135,17 @@ void HGCalBestChoiceCodecImpl::triggerCellSums(const HGCalTriggerGeometryBase& g
payload[triggercellid] += value; // 32 bits integer should be largely enough (maximum 7 12-bits sums are done)

}
uint32_t module = geometry.getModuleFromTriggerCell(payload.begin()->first);
HGCalTriggerGeometryBase::geom_ordered_set trigger_cells_in_module = geometry.getOrderedTriggerCellsFromModule(module);
// fill data payload
for(const auto& id_value : payload)
{
uint32_t id = id_value.first.cell();
// find the index of the trigger cell in the module (not necessarily equal to .cell())
// FIXME: std::distance is linear with size for sets (no random access). In order to have constant
// access would require to convert the set into a vector.
uint32_t id = std::distance(trigger_cells_in_module.begin(),trigger_cells_in_module.find(id_value.first));
//uint32_t id = id_value.first.cell();
//std::cerr<<"cell id in trigger cell sum: "<<id<<"("<<id_value.first.wafer()<<","<<id_value.first.cell()<<")\n";
if(id>=nCellsInModule_)
{
throw cms::Exception("BadGeometry")
Expand Down

0 comments on commit 8649100

Please sign in to comment.