367 CLHEP::HepRandomEngine* engine = &rng->
getEngine(
e.streamID());
371 if (simulateAPVInThisEvent) {
374 const auto it = std::find_if(
376 if (it != std::begin(ps)) {
377 nTruePU = it->getTrueNumInteractions();
379 edm::LogWarning(
"PreMixingSiStripWorker") <<
"Could not find PileupSummaryInfo for current bunch crossing";
380 nTruePU = std::begin(ps)->getTrueNumInteractions();
384 std::map<int, std::bitset<6>> DeadAPVList;
405 uint32_t detID = IDet->first;
407 auto const& LocalMap = IDet->second;
412 localRawMap.reserve(LocalMap.size());
413 for (
auto const& iLocal : LocalMap) {
414 uint16_t currentStrip = iLocal.strip();
415 float signal =
float(iLocal.adc());
416 if (iLocal.adc() == 1022)
418 if (iLocal.adc() == 1023)
422 constexpr
float inv9 = 1.f / 9.0f;
423 float ReSignal = signal * signal * inv9;
427 localRawMap.emplace_back(currentStrip, ReSignal);
433 int NumberOfBxBetweenHIPandEvent = 1
e3;
438 bool HasAtleastOneAffectedAPV =
false;
439 while (!HasAtleastOneAffectedAPV) {
440 for (
int bx = floor(300.0 / 25.0);
bx > 0;
bx--) {
441 float temp = CLHEP::RandFlat::shoot(engine) < 0.5 ? 1 : 0;
442 if (
temp == 1 &&
bx < NumberOfBxBetweenHIPandEvent) {
443 NumberOfBxBetweenHIPandEvent =
bx;
444 HasAtleastOneAffectedAPV =
true;
449 APVMap::const_iterator iAPVchk;
450 uint32_t formerID = 0;
452 std::bitset<6> NewAPVBits;
455 currentID = iAPV->first;
457 if (currentID == formerID) {
458 for (
int ibit = 0; ibit < 6; ++ibit) {
459 NewAPVBits[ibit] = NewAPVBits[ibit] || (iAPV->second)[ibit];
462 DeadAPVList[currentID] = NewAPVBits;
464 formerID = currentID;
465 NewAPVBits = iAPV->second;
470 DeadAPVList[currentID] = NewAPVBits;
479 std::vector<edm::DetSet<SiStripDigi>> vSiStripDigi;
489 uint32_t detID = IDet.first;
494 auto const& LocalMap = IDet.second;
497 lSignals.reserve(
std::min(LocalMap.size(), 512ul));
500 int formerStrip = -1;
506 OneDetectorRawMap::const_iterator iLocalchk;
507 OneDetectorRawMap::const_iterator iLocal = LocalMap.begin();
508 for (; iLocal != LocalMap.end(); ++iLocal) {
509 currentStrip = iLocal->first;
511 if (currentStrip == formerStrip) {
513 ADCSum += iLocal->second;
515 if (formerStrip != -1) {
516 lSignals.emplace_back(formerStrip, ADCSum);
519 formerStrip = currentStrip;
520 ADCSum = iLocal->second;
524 if ((++iLocalchk) == LocalMap.end()) {
525 lSignals.emplace_back(formerStrip, ADCSum);
535 if (sgd !=
nullptr) {
546 std::vector<float> detAmpl(numStrips, 0.);
548 for (
const auto& amp : *lSignal) {
549 detAmpl[amp.first] = amp.second;
557 if (badChannels[
strip])
561 if (simulateAPVInThisEvent) {
566 float detSet_z = fabs(globalPos.
z());
567 float detSet_r = globalPos.
perp();
572 if (detAmpl[
strip] > 0) {
577 double baselineV = 0;
579 baselineV = apvSimulationParameters->
sampleTIB(tTopo->
tibLayer(detID), detSet_z, nTruePU, engine);
581 baselineV = apvSimulationParameters->
sampleTOB(tTopo->
tobLayer(detID), detSet_z, nTruePU, engine);
583 baselineV = apvSimulationParameters->
sampleTID(tTopo->
tidWheel(detID), detSet_r, nTruePU, engine);
585 baselineV = apvSimulationParameters->
sampleTEC(tTopo->
tecWheel(detID), detSet_r, nTruePU, engine);
591 double outputChargeInADC = 0;
594 double baselineQ = -1.0 *
rate *
log(2 * maxResponse / (baselineV + maxResponse) - 1);
597 double newStripCharge = baselineQ + stripCharge;
600 double signalV = 2 * maxResponse / (1 +
exp(-1.0 * newStripCharge /
rate)) - maxResponse;
601 double gain = signalV - baselineV;
609 detAmpl[
strip] = outputChargeInADC;
615 std::bitset<6>&
bs = DeadAPVList[detID];
621 1 - NumberOfBxBetweenHIPandEvent / floor(300.0 / 25.0);
622 float randomX = CLHEP::RandFlat::shoot(engine);
623 float scalingValue = (randomX - Shift) * 10.0 / 7.0 - 3.0 / 7.0;
627 detAmpl[
strip] *= scalingValue > 0 ? scalingValue : 0.0;
656 size_t firstChannelWithSignal = 0;
657 size_t lastChannelWithSignal = numStrips;
660 std::vector<float> noiseRMSv;
662 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
664 if (!badChannels[
strip]) {
665 float gainValue =
gain.getStripGain(
strip, detGainRange);
671 int RefStrip =
int(numStrips / 2.);
672 while (RefStrip < numStrips &&
673 badChannels[RefStrip]) {
676 if (RefStrip < numStrips) {
677 float RefgainValue =
gain.getStripGain(RefStrip, detGainRange);
681 detAmpl, firstChannelWithSignal, lastChannelWithSignal, numStrips, RefnoiseRMS, engine);
692 LogDebug(
"PreMixingSiStripWorker") << detID <<
" " <<
data.size() <<
' ' << SSD.data.size();
695 vSiStripDigi.push_back(SSD);
702 edm::LogInfo(
"PreMixingSiStripWorker") <<
"total # Merged strips: " << vSiStripDigi.size();
std::map< unsigned int, std::vector< bool > > allBadChannels
unsigned int tobLayer(const DetId &id) const
float sampleTOB(layerid layer, float z, float pu, CLHEP::HepRandomEngine *engine) const
std::unique_ptr< SiTrivialDigitalConverter > theSiDigitalConverter
unsigned int tidWheel(const DetId &id) const
unsigned int tecWheel(const DetId &id) const
float sampleTIB(layerid layer, float z, float pu, CLHEP::HepRandomEngine *engine) const
edm::ESGetToken< SiStripNoises, SiStripNoisesRcd > const noiseToken_
SiGlobalIndex SiHitStorage_
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
const double fracOfEventsToSimAPV_
std::string SiStripDigiCollectionDM_
bool includeAPVSimulation_
std::unique_ptr< SiGaussianTailNoiseAdder > theSiNoiseAdder
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
std::pair< ContainerIterator, ContainerIterator > Range
bool APVSaturationFromHIP_
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
DetId geographicalId() const
The label of this GeomDet.
std::unique_ptr< SiStripFedZeroSuppression > theSiZeroSuppress
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
const double apv_fCPerElectron_
Log< level::Info, false > LogInfo
const TrackerGeometry * pDD
float sampleTID(layerid wheel, float r, float pu, CLHEP::HepRandomEngine *engine) const
const Plane & surface() const
The nominal surface of the GeomDet.
SiGlobalRawIndex SiRawDigis_
constexpr uint32_t rawId() const
get the raw id
const int getBunchCrossing() const
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
APVMap theAffectedAPVmap_
SignalMapType const * getSignal(uint32_t detID) const
char data[epos_bytes_allocation]
const double apv_maxResponse_
virtual LocalPoint localPosition(float strip) const =0
unsigned int tibLayer(const DetId &id) const
std::vector< RawDigi > OneDetectorRawMap
Log< level::Warning, false > LogWarning
std::pair< ContainerIterator, ContainerIterator > Range
float sampleTEC(layerid wheel, float r, float pu, CLHEP::HepRandomEngine *engine) const
edm::ESGetToken< SiStripGain, SiStripGainSimRcd > const gainToken_
edm::ESGetToken< SiStripThreshold, SiStripThresholdRcd > const thresholdToken_
edm::ESGetToken< SiStripApvSimulationParameters, SiStripApvSimulationParametersRcd > apvSimulationParametersToken_
Point3DBase< float, LocalTag > Local3DPoint