-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduced radom number calls in the runSimple Method of HGCDigitizerBase for Potential Speedup. #27980
Reduced radom number calls in the runSimple Method of HGCDigitizerBase for Potential Speedup. #27980
Changes from 4 commits
333b0b2
632427d
835b9f1
a999665
1d73f98
befd79c
f4638e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ | |
accumulatorType = cms.string("HGCDigiProducer"), | ||
hitCollection = cms.string("HGCHitsEE"), | ||
digiCollection = cms.string("HGCDigisEE"), | ||
seedOffset = cms.uint32(9182), | ||
maxSimHitsAccTime = cms.uint32(100), | ||
bxTime = cms.double(25), | ||
eVPerEleHolePair = cms.double(eV_per_eh_pair), | ||
|
@@ -135,6 +136,7 @@ | |
accumulatorType = cms.string("HGCDigiProducer"), | ||
hitCollection = cms.string("HGCHitsHEfront"), | ||
digiCollection = cms.string("HGCDigisHEfront"), | ||
seedOffset = cms.uint32(8273), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since these parameters are no longer used, they can be deleted |
||
maxSimHitsAccTime = cms.uint32(100), | ||
bxTime = cms.double(25), | ||
tofDelay = cms.double(5), | ||
|
@@ -203,6 +205,7 @@ | |
accumulatorType = cms.string("HGCDigiProducer"), | ||
hitCollection = cms.string("HcalHits"), | ||
digiCollection = cms.string("HGCDigisHEback"), | ||
seedOffset = cms.uint32(7364), | ||
maxSimHitsAccTime = cms.uint32(100), | ||
bxTime = cms.double(25), | ||
tofDelay = cms.double(1), | ||
|
@@ -246,6 +249,7 @@ | |
accumulatorType = cms.string("HGCDigiProducer"), | ||
hitCollection = cms.string("HFNoseHits"), | ||
digiCollection = cms.string("HFNoseDigis"), | ||
seedOffset = cms.uint32(5647), | ||
maxSimHitsAccTime = cms.uint32(100), | ||
bxTime = cms.double(25), | ||
eVPerEleHolePair = cms.double(eV_per_eh_pair), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,12 @@ using namespace hgc_digi; | |
using namespace hgc_digi_utils; | ||
|
||
template <class DFr> | ||
HGCDigitizerBase<DFr>::HGCDigitizerBase(const edm::ParameterSet& ps) : scaleByDose_(false) { | ||
HGCDigitizerBase<DFr>::HGCDigitizerBase(const edm::ParameterSet& ps) | ||
: scaleByDose_(false), NoiseMean_(0.0), NoiseStd_(1.0) { | ||
bxTime_ = ps.getParameter<double>("bxTime"); | ||
myCfg_ = ps.getParameter<edm::ParameterSet>("digiCfg"); | ||
doTimeSamples_ = myCfg_.getParameter<bool>("doTimeSamples"); | ||
thresholdFollowsMIP_ = myCfg_.getParameter<bool>("thresholdFollowsMIP"); | ||
|
||
if (myCfg_.exists("keV2fC")) | ||
keV2fC_ = myCfg_.getParameter<double>("keV2fC"); | ||
else | ||
|
@@ -51,6 +51,18 @@ HGCDigitizerBase<DFr>::HGCDigitizerBase(const edm::ParameterSet& ps) : scaleByDo | |
edm::ParameterSet feCfg = myCfg_.getParameter<edm::ParameterSet>("feCfg"); | ||
myFEelectronics_ = std::unique_ptr<HGCFEElectronics<DFr>>(new HGCFEElectronics<DFr>(feCfg)); | ||
myFEelectronics_->SetNoiseValues(noise_fC_); | ||
RandNoiseGenerationFlag_ = 0; | ||
} | ||
|
||
template <class DFr> | ||
void HGCDigitizerBase<DFr>::GenerateGaussianNoise(CLHEP::HepRandomEngine* engine, | ||
const double NoiseMean, | ||
const double NoiseStd) { | ||
for (size_t i = 0; i < NoiseArrayLength_; i++) { | ||
for (size_t j = 0; j < samplesize_; j++) { | ||
GaussianNoiseArray_[i][j] = CLHEP::RandGaussQ::shoot(NoiseMean, NoiseStd); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here you need to use |
||
} | ||
} | ||
} | ||
|
||
template <class DFr> | ||
|
@@ -62,6 +74,10 @@ void HGCDigitizerBase<DFr>::run(std::unique_ptr<HGCDigitizerBase::DColl>& digiCo | |
CLHEP::HepRandomEngine* engine) { | ||
if (scaleByDose_) | ||
scal_.setGeometry(theGeom); | ||
if (RandNoiseGenerationFlag_ == 0) { | ||
GenerateGaussianNoise(engine, NoiseMean_, NoiseStd_); | ||
RandNoiseGenerationFlag_ = 1; | ||
} | ||
if (digitizationType == 0) | ||
runSimple(digiColl, simData, theGeom, validIds, engine); | ||
else | ||
|
@@ -80,13 +96,17 @@ void HGCDigitizerBase<DFr>::runSimple(std::unique_ptr<HGCDigitizerBase::DColl>& | |
HGCCellInfo zeroData; | ||
zeroData.hit_info[0].fill(0.f); //accumulated energy | ||
zeroData.hit_info[1].fill(0.f); //time-of-flight | ||
//GenerateGaussianNoise(engine, NoiseMean_, NoiseStd_); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adas1994 at this point this should disappear There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete commented-out code |
||
|
||
for (const auto& id : validIds) { | ||
chargeColl.fill(0.f); | ||
toa.fill(0.f); | ||
HGCSimHitDataAccumulator::iterator it = simData.find(id); | ||
HGCCellInfo& cell = (simData.end() == it ? zeroData : it->second); | ||
addCellMetadata(cell, theGeom, id); | ||
size_t hash_index = (CLHEP::RandFlat::shootInt(engine, (NoiseArrayLength_ - 1)) + id) % NoiseArrayLength_; | ||
|
||
auto cellNoiseArray = GaussianNoiseArray_[hash_index]; | ||
|
||
//set the noise,cce, LSB and threshold to be used | ||
float cce(1.f), noiseWidth(0.f), lsbADC(-1.f), maxADC(-1.f); | ||
|
@@ -122,7 +142,7 @@ void HGCDigitizerBase<DFr>::runSimple(std::unique_ptr<HGCDigitizerBase::DColl>& | |
toa[i] = cell.hit_info[1][i] / rawCharge; | ||
|
||
//final charge estimation | ||
float noise = CLHEP::RandGaussQ::shoot(engine, 0.0, noiseWidth); | ||
float noise = (float)cellNoiseArray[i] * noiseWidth; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it might be worth putting a switch here to go back to the old behavior, in case someone wants to run a test in the future. |
||
float totalCharge(rawCharge * cce + noise); | ||
if (totalCharge < 0.f) | ||
totalCharge = 0.f; | ||
|
@@ -131,7 +151,8 @@ void HGCDigitizerBase<DFr>::runSimple(std::unique_ptr<HGCDigitizerBase::DColl>& | |
|
||
//run the shaper to create a new data frame | ||
DFr rawDataFrame(id); | ||
myFEelectronics_->runShaper(rawDataFrame, chargeColl, toa, engine, thrADC, lsbADC, maxADC, cell.thickness); | ||
int thickness = cell.thickness > 0 ? cell.thickness : 1; | ||
myFEelectronics_->runShaper(rawDataFrame, chargeColl, toa, engine, thrADC, lsbADC, maxADC, thickness); | ||
|
||
//update the output according to the final shape | ||
updateOutput(coll, rawDataFrame); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adas1994 @mdhildreth in practice this could just be a bool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intended to be defined once for all possible threads? In that case should not it be
static
and managed through a thread safe mechanism a bit like in https://cmssdt.cern.ch/lxr/source/FastSimulation/MaterialEffects/src/NuclearInteractionFTFSimulator.cc for instance?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fabiocos digi production happens in a stream producer (https://github.com/cms-sw/cmssw/blob/master/Mixing/Base/interface/BMixingModule.h), so class member variables can be modified safely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kpedro88 right, so in this case this should be ok, the array is per stream. The comment about the possible use of
bool
is independent