Skip to content

Commit

Permalink
Merge pull request cms-sw#105 from CMS-HGCAL/hackathon_base_CMSSW_14_…
Browse files Browse the repository at this point in the history
…1_0_pre0

Update with DIGIs SOA
  • Loading branch information
pfs authored Mar 6, 2024
2 parents 9cb1c13 + b4c3d58 commit bf51c3a
Show file tree
Hide file tree
Showing 16 changed files with 299 additions and 18 deletions.
5 changes: 5 additions & 0 deletions DataFormats/HGCalDigi/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<use name="rootcore"/>
<use name="eigen"/>
<use name="DataFormats/Portable"/>
<use name="DataFormats/Common"/>
<use name="DataFormats/ForwardDetId"/>
<use name="DataFormats/DetId"/>
<use name="HeterogeneousCore/AlpakaInterface"/>
<flags ALPAKA_BACKENDS="!serial"/>
<export>
<lib name="1"/>
</export>
1 change: 0 additions & 1 deletion DataFormats/HGCalDigi/interface/HGCROCChannelDataFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class HGCROCChannelDataFrame {
HGCROCChannelDataFrame(uint32_t value) : id_(0), value_(value) {}
HGCROCChannelDataFrame(const D& id, uint32_t value) : id_(id), value_(value) {}
HGCROCChannelDataFrame(const HGCROCChannelDataFrame& o) : id_(o.id_), value_(o.value_) {}
HGCROCChannelDataFrame& operator=(const HGCROCChannelDataFrame&) = default;

/**
@short det id
Expand Down
4 changes: 2 additions & 2 deletions DataFormats/HGCalDigi/interface/HGCalDigiCollections.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include "DataFormats/HGCalDigi/interface/HGCalElectronicsId.h"

typedef HGCROCChannelDataFrame<HGCalDetId> HGCROCChannelDataFrameSpec;
typedef edm::SortedCollection<HGCROCChannelDataFrameSpec> HGCalDigiCollection;
typedef edm::SortedCollection<HGCROCChannelDataFrameSpec> HGCalROCChannelDigiCollection;

typedef HGCROCChannelDataFrame<HGCalElectronicsId> HGCROCChannelDataFrameElecSpec;
typedef edm::SortedCollection<HGCROCChannelDataFrameElecSpec> HGCalElecDigiCollection;
typedef edm::SortedCollection<HGCROCChannelDataFrameElecSpec> HGCalElecROCChannelDigiCollection;

#endif
14 changes: 14 additions & 0 deletions DataFormats/HGCalDigi/interface/HGCalDigiHostCollection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef DataFormats_HGCalDigi_interface_HGCalDigiHostCollection_h
#define DataFormats_HGCalDigi_interface_HGCalDigiHostCollection_h

#include "DataFormats/Portable/interface/PortableHostCollection.h"
#include "DataFormats/HGCalDigi/interface/HGCalDigiSoA.h"

namespace hgcaldigi {

// SoA with x, y, z, id fields in host memory
using HGCalDigiHostCollection = PortableHostCollection<HGCalDigiSoA>;

} // namespace hgcaldigi

#endif // DataFormats_HGCalDigi_interface_HGCalDigiHostCollection_h
29 changes: 29 additions & 0 deletions DataFormats/HGCalDigi/interface/HGCalDigiSoA.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef DataFormats_HGCalDigi_interface_HGCalDigiSoA_h
#define DataFormats_HGCalDigi_interface_HGCalDigiSoA_h

#include <Eigen/Core>
#include <Eigen/Dense>

#include "DataFormats/SoATemplate/interface/SoACommon.h"
#include "DataFormats/SoATemplate/interface/SoALayout.h"
#include "DataFormats/SoATemplate/interface/SoAView.h"

namespace hgcaldigi {

// Generate structure of arrays (SoA) layout with Digi dataformat
GENERATE_SOA_LAYOUT(HGCalDigiSoALayout,
// columns: one value per element
SOA_COLUMN(uint32_t, electronicsId),
SOA_COLUMN(uint8_t, tctp),
SOA_COLUMN(uint16_t, adcm1),
SOA_COLUMN(uint16_t, adc),
SOA_COLUMN(uint16_t, tot),
SOA_COLUMN(uint16_t, toa),
SOA_COLUMN(uint16_t, cm),
SOA_COLUMN(uint16_t, flags)
)
using HGCalDigiSoA = HGCalDigiSoALayout<>;

} // namespace hgcaldigi

#endif // DataFormats_HGCalDigi_interface_HGCalDigiSoA_h
23 changes: 23 additions & 0 deletions DataFormats/HGCalDigi/interface/alpaka/HGCalDigiDeviceCollection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef DataFormats_HGCalDigi_interface_alpaka_HGCalDigiDeviceCollection_h
#define DataFormats_HGCalDigi_interface_alpaka_HGCalDigiDeviceCollection_h

#include "DataFormats/Portable/interface/alpaka/PortableCollection.h"
#include "DataFormats/HGCalDigi/interface/HGCalDigiSoA.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {

namespace hgcaldigi {

// make the names from the top-level hgcaldigi namespace visible for unqualified lookup
// inside the ALPAKA_ACCELERATOR_NAMESPACE::hgcaldigi namespace
using namespace ::hgcaldigi;

// SoA in device global memory
using HGCalDigiDeviceCollection = PortableCollection<HGCalDigiSoA>;

} // namespace hgcaldigi

} // namespace ALPAKA_ACCELERATOR_NAMESPACE

#endif // DataFormats_HGCalDigi_interface_alpaka_HGCalDigiDeviceCollection_h
4 changes: 4 additions & 0 deletions DataFormats/HGCalDigi/src/alpaka/classes_cuda.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "DataFormats/Common/interface/DeviceProduct.h"
#include "DataFormats/Common/interface/Wrapper.h"
#include "DataFormats/HGCalDigi/interface/HGCalDigiSoA.h"
#include "DataFormats/HGCalDigi/interface/alpaka/HGCalDigiDeviceCollection.h"
5 changes: 5 additions & 0 deletions DataFormats/HGCalDigi/src/alpaka/classes_cuda_def.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<lcgdict>
<class name="alpaka_cuda_async::hgcaldigi::HGCalDigiDeviceCollection" persistent="false"/>
<class name="edm::DeviceProduct<alpaka_cuda_async::hgcaldigi::HGCalDigiDeviceCollection>" persistent="false"/>
<class name="edm::Wrapper<edm::DeviceProduct<alpaka_cuda_async::hgcaldigi::HGCalDigiDeviceCollection>>" persistent="false"/>
</lcgdict>
4 changes: 4 additions & 0 deletions DataFormats/HGCalDigi/src/alpaka/classes_rocm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "DataFormats/Common/interface/DeviceProduct.h"
#include "DataFormats/Common/interface/Wrapper.h"
#include "DataFormats/HGCalDigi/interface/HGCalDigiSoA.h"
#include "DataFormats/HGCalDigi/interface/alpaka/HGCalDigiDeviceCollection.h"
5 changes: 5 additions & 0 deletions DataFormats/HGCalDigi/src/alpaka/classes_rocm_def.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<lcgdict>
<class name="alpaka_rocm_async::hgcaldigi::HGCalDigiDeviceCollection" persistent="false"/>
<class name="edm::DeviceProduct<alpaka_rocm_async::hgcaldigi::HGCalDigiDeviceCollection>" persistent="false"/>
<class name="edm::Wrapper<edm::DeviceProduct<alpaka_rocm_async::hgcaldigi::HGCalDigiDeviceCollection>>" persistent="false"/>
</lcgdict>
4 changes: 4 additions & 0 deletions DataFormats/HGCalDigi/src/classes.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "DataFormats/Portable/interface/PortableHostCollectionReadRules.h"
#include "DataFormats/HGCalDigi/interface/HGCalDigiHostCollection.h"

SET_PORTABLEHOSTCOLLECTION_READ_RULES(hgcaldigi::HGCalDigiHostCollection);
3 changes: 2 additions & 1 deletion DataFormats/HGCalDigi/src/classes.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <vector>
#include <bitset>

#include "DataFormats/Common/interface/Wrapper.h"
#include "DataFormats/HGCalDigi/interface/HGCalElectronicsId.h"
#include "DataFormats/HGCalDigi/interface/HGCalDigiCollections.h"
#include "DataFormats/HGCalDigi/interface/PHGCSimAccumulator.h"
#include "DataFormats/HGCalDigi/interface/HGCalRawDataEmulatorInfo.h"
#include "DataFormats/HGCalDigi/interface/HGCalDigiHostCollection.h"
#include "DataFormats/HGCalDigi/interface/HGCalDigiSoA.h"
20 changes: 15 additions & 5 deletions DataFormats/HGCalDigi/src/classes_def.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<lcgdict>

<class name="HGCalElectronicsId" ClassVersion="3">
<version ClassVersion="3" checksum="2587023721"/>
</class>

<class name="HGCROCChannelDataFrame<HGCalDetId>" ClassVersion="3">
<version ClassVersion="3" checksum="2026905296"/>
</class>


<class name="HGCROCChannelDataFrame<HGCalElectronicsId>" ClassVersion="3">
<version ClassVersion="3" checksum="2054618736"/>
</class>
Expand Down Expand Up @@ -40,4 +37,17 @@
<version ClassVersion="3" checksum="2245547372"/>
</class>
<class name="edm::Wrapper<HGCalSlinkEmulatorInfo>"/>

<class name="hgcaldigi::HGCalDigiSoA"/>
<class name="hgcaldigi::HGCalDigiSoA::View"/>
<class name="hgcaldigi::HGCalDigiHostCollection"/>
<!-- <class name="edm::Wrapper<hgcaldigi::HGCalDigiHostCollection" splitLevel="0"/> -->

<class name="hgcaldigi::HGCalDigiSoALayout<128,false>"/>
<class name="edm::Wrapper<PortableHostCollection<hgcaldigi::HGCalDigiSoALayout<128,false> > >" splitLevel="0"/>

<!-- Recursive templates implementing the association of indices and layouts, and containing the data -->
<class name="portablecollection::CollectionLeaf<0, hgcaldigi::HGCalDigiSoALayout<128, false>>"/>


</lcgdict>
23 changes: 14 additions & 9 deletions SimCalorimetry/HGCalSimProducers/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<use name="FWCore/Framework"/>
<use name="FWCore/Utilities"/>
<use name="Geometry/Records"/>
<use name="SimCalorimetry/HGCalSimProducers"/>
<use name="SimDataFormats/CaloTest"/>
<use name="SimGeneral/MixingModule"/>
<use name="SimGeneral/PreMixingModule"/>
<use name="root"/>
<flags EDM_PLUGIN="1"/>
<!-- host-only plugins -->
<library file="*.cc" name="SimCalorimetryHGCalSimProducersPlugins">
<use name="FWCore/Framework"/>
<use name="FWCore/Utilities"/>
<use name="Geometry/Records"/>
<use name="CondFormats/HGCalObjects"/>
<use name="SimCalorimetry/HGCalSimProducers"/>
<use name="SimDataFormats/CaloTest"/>
<use name="SimGeneral/MixingModule"/>
<use name="SimGeneral/PreMixingModule"/>
<use name="DataFormats/HGCalDigi"/>
<use name="root"/>
<flags EDM_PLUGIN="1"/>
</library>
104 changes: 104 additions & 0 deletions SimCalorimetry/HGCalSimProducers/plugins/HGCalDigiSoaFiller.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Utilities/interface/StreamID.h"

#include "DataFormats/HGCalDigi/interface/HGCalElectronicsId.h"
#include "DataFormats/HGCDigi/interface/HGCDigiCollections.h"
#include "DataFormats/HGCalDigi/interface/HGCalDigiHostCollection.h"

/**
* @short consumes channel digis and packs then in a realistic FEDRawData stream
*/
class HGCalDigiSoaFiller : public edm::stream::EDProducer<> {

public:

/**
@short constructor
*/
explicit HGCalDigiSoaFiller(edm::ParameterSet const& config)
: digisCEET_( consumes<edm::SortedCollection<HGCalDataFrame> >(config.getParameter<edm::InputTag>("eeChannelDigis") ) ),
digisCEHSiT_( consumes<edm::SortedCollection<HGCalDataFrame> >(config.getParameter<edm::InputTag>("cehsiChannelDigis") ) ),
digisCEHSiPMT_( consumes<edm::SortedCollection<HGCalDataFrame> >(config.getParameter<edm::InputTag>("cehsipmChannelDigis") ) ) {

digiProdT_ = produces(config.getParameter<std::string>("digisProdName"));

}

/**
@short parameters to be used with this plugin
*/
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("eeChannelDigis", edm::InputTag("simHGCalUnsuppressedDigis","EE"));
desc.add<edm::InputTag>("cehsiChannelDigis", edm::InputTag("simHGCalUnsuppressedDigis","HEfront"));
desc.add<edm::InputTag>("cehsipmChannelDigis", edm::InputTag("simHGCalUnsuppressedDigis","HEback"));
desc.add<std::string>("digisProdName", "HGC");
descriptions.addWithDefaultLabel(desc);

}


private:

/**
@short steers the conversion to SOA
*/
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override {

//FIXME
int itSample = 2;

//read "classic" channel digis
auto const &digisCEE = iEvent.get(digisCEET_);
//auto const &digisCEHSi = iEvent.get(digisCEHSiT_);
//auto const &digisCEHSiPM = iEvent.get(digisCEHSiPMT_);

//fill the SoA collection
int finaldigi_size = 100; //FIXME : to be retrieved from Elec Mapping
hgcaldigi::HGCalDigiHostCollection digiProd(finaldigi_size,cms::alpakatools::host());
for(auto d : digisCEE) {

int i=0;
uint32_t detid( d.id().rawId() );
uint32_t eleid( detid ); //FIXME : from mapping

//read digi (in-time sample only)
uint32_t toa = d.sample(itSample).toa();
uint32_t tctp = d.sample(itSample).mode() ? 3 : 0;
uint32_t adcm1( d.sample(itSample-1).data() );
uint32_t adc( tctp<3 ? d.sample(itSample).data() : 0 );
uint32_t tot( tctp==3 ? d.sample(itSample).data() : 0 );

std::cout << "Filling with " << eleid << " " << toa << " " << tctp << " " << adcm1 << " " << adc << " " << tot << std::endl;

auto idigi = digiProd.view()[i];
idigi.electronicsId() = eleid;
idigi.tctp() = tctp;
idigi.adcm1() = adcm1;
idigi.adc() = adc;
idigi.tot() = tot;
idigi.toa() = toa;
idigi.cm() = 0;
idigi.flags() = 0;

break;
}


iEvent.emplace(digiProdT_, std::move(digiProd));
}


edm::EDGetTokenT<edm::SortedCollection<HGCalDataFrame> > digisCEET_,digisCEHSiT_,digisCEHSiPMT_;
edm::EDPutTokenT<hgcaldigi::HGCalDigiHostCollection> digiProdT_;
};

// define this as a plug-in
DEFINE_FWK_MODULE(HGCalDigiSoaFiller);
69 changes: 69 additions & 0 deletions SimCalorimetry/HGCalSimProducers/test/hgcalRealistiDigis_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import FWCore.ParameterSet.Config as cms

from Configuration.Eras.Era_Phase2C17I13M9_cff import Phase2C17I13M9 as Era_Phase2
process = cms.Process("REALDIGI", Era_Phase2)


from FWCore.ParameterSet.VarParsing import VarParsing
options = VarParsing ('standard')
options.register('geometry', 'Extended2026D94', VarParsing.multiplicity.singleton, VarParsing.varType.string, 'geometry to use')
options.register('modules','Geometry/HGCalMapping/data/ModuleMaps/modulelocator_test.txt',mytype=VarParsing.varType.string,
info="Path to module mapper. Absolute, or relative to CMSSW src directory")
options.register('sicells','Geometry/HGCalMapping/data/CellMaps/WaferCellMapTraces.txt',mytype=VarParsing.varType.string,
info="Path to Si cell mapper. Absolute, or relative to CMSSW src directory")
options.register('sipmcells','Geometry/HGCalMapping/data/CellMaps/channels_sipmontile.hgcal.txt',mytype=VarParsing.varType.string,
info="Path to SiPM-on-tile cell mapper. Absolute, or relative to CMSSW src directory")
options.parseArguments()

if len(options.files)==0:
options.files=['file:/eos/cms/store/group/dpg_hgcal/comm_hgcal/psilva/hackhathon/23234.103_TTbar_14TeV+2026D94Aging3000/step2.root']
print(f'Using hackathon test files: {options.files}')

#set geometry/global tag
process.load('Configuration.StandardSequences.Services_cff')
process.load('Configuration.StandardSequences.MagneticField_cff')
process.load('Configuration.EventContent.EventContent_cff')
process.load("FWCore.MessageService.MessageLogger_cfi")
process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
process.load('Configuration.Geometry.Geometry%sReco_cff'%options.geometry)
process.load('Configuration.Geometry.Geometry%s_cff'%options.geometry)
from Configuration.AlCa.GlobalTag import GlobalTag
process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic', '')

process.MessageLogger.cerr.threshold = ''
process.MessageLogger.cerr.FwkReport.reportEvery = 500

process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring(options.files),
duplicateCheckMode = cms.untracked.string("noDuplicateCheck")
)
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.maxEvents) )


#ESSources/Producers for the logical mapping
#indexers
process.load('Geometry.HGCalMapping.hgCalMappingIndexESSource_cfi')
process.hgCalMappingIndexESSource.modules = cms.FileInPath(options.modules)
process.hgCalMappingIndexESSource.si = cms.FileInPath(options.sicells)
process.hgCalMappingIndexESSource.sipm = cms.FileInPath(options.sipmcells)

process.load('Configuration.StandardSequences.Accelerators_cff')
process.hgCalMappingModuleESProducer = cms.ESProducer('hgcal::HGCalMappingModuleESProducer@alpaka',
filename=cms.FileInPath(options.modules),
moduleindexer=cms.ESInputTag('') )
process.hgCalMappingCellESProducer = cms.ESProducer('hgcal::HGCalMappingCellESProducer@alpaka',
filelist=cms.vstring(options.sicells,options.sipmcells),
cellindexer=cms.ESInputTag('') )

#realistic digis producer
process.load('SimCalorimetry.HGCalSimProducers.hgCalDigiSoaFiller_cfi')
process.t = cms.Task(process.hgCalDigiSoaFiller)
process.p = cms.Path(process.t)

#output
process.output = cms.OutputModule('PoolOutputModule',
fileName = cms.untracked.string(options.output),
outputCommands = cms.untracked.vstring('drop *',
'keep *_*_*_REALDIGI'))

process.output_path = cms.EndPath(process.output)

0 comments on commit bf51c3a

Please sign in to comment.