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;
408 uint32_t detID = IDet->first;
416 OneDetectorMap::const_iterator iLocal = LocalMap.begin();
417 for (; iLocal != LocalMap.end(); ++iLocal) {
418 uint16_t currentStrip = iLocal->strip();
419 float signal =
float(iLocal->adc());
420 if (iLocal->adc() == 1022)
422 if (iLocal->adc() == 1023)
427 float ReSignal = signal * signal / 9.0;
429 RawDigi NewRawDigi = std::make_pair(currentStrip, ReSignal);
431 LocalRawMap.push_back(NewRawDigi);
440 int NumberOfBxBetweenHIPandEvent = 1
e3;
445 bool HasAtleastOneAffectedAPV =
false;
446 while (!HasAtleastOneAffectedAPV) {
447 for (
int bx = floor(300.0 / 25.0);
bx > 0;
bx--) {
448 float temp = CLHEP::RandFlat::shoot(engine) < 0.5 ? 1 : 0;
449 if (
temp == 1 &&
bx < NumberOfBxBetweenHIPandEvent) {
450 NumberOfBxBetweenHIPandEvent =
bx;
451 HasAtleastOneAffectedAPV =
true;
456 APVMap::const_iterator iAPVchk;
457 uint32_t formerID = 0;
459 std::bitset<6> NewAPVBits;
462 currentID = iAPV->first;
464 if (currentID == formerID) {
465 for (
int ibit = 0; ibit < 6; ++ibit) {
466 NewAPVBits[ibit] = NewAPVBits[ibit] || (iAPV->second)[ibit];
469 DeadAPVList[currentID] = NewAPVBits;
471 formerID = currentID;
472 NewAPVBits = iAPV->second;
477 DeadAPVList[currentID] = NewAPVBits;
486 std::vector<edm::DetSet<SiStripDigi>> vSiStripDigi;
496 uint32_t detID = IDet->first;
504 int formerStrip = -1;
510 OneDetectorRawMap::const_iterator iLocalchk;
511 OneDetectorRawMap::const_iterator iLocal = LocalMap.begin();
512 for (; iLocal != LocalMap.end(); ++iLocal) {
513 currentStrip = iLocal->first;
515 if (currentStrip == formerStrip) {
517 ADCSum += iLocal->second;
519 if (formerStrip != -1) {
520 Signals.insert(std::make_pair(formerStrip, ADCSum));
523 formerStrip = currentStrip;
524 ADCSum = iLocal->second;
528 if ((++iLocalchk) == LocalMap.end()) {
529 Signals.insert(std::make_pair(formerStrip, ADCSum));
533 signals_.insert(std::make_pair(detID, Signals));
541 if (sgd !=
nullptr) {
552 std::vector<float> detAmpl(numStrips, 0.);
554 for (
const auto& amp : *theSignal) {
555 detAmpl[amp.first] = amp.second;
563 if (badChannels[
strip])
567 if (simulateAPVInThisEvent) {
572 float detSet_z = fabs(globalPos.
z());
573 float detSet_r = globalPos.
perp();
578 if (detAmpl[
strip] > 0) {
583 double baselineV = 0;
585 baselineV = apvSimulationParameters->
sampleTIB(tTopo->
tibLayer(detID), detSet_z, nTruePU, engine);
587 baselineV = apvSimulationParameters->
sampleTOB(tTopo->
tobLayer(detID), detSet_z, nTruePU, engine);
589 baselineV = apvSimulationParameters->
sampleTID(tTopo->
tidWheel(detID), detSet_r, nTruePU, engine);
591 baselineV = apvSimulationParameters->
sampleTEC(tTopo->
tecWheel(detID), detSet_r, nTruePU, engine);
597 double outputChargeInADC = 0;
600 double baselineQ = -1.0 *
rate *
log(2 * maxResponse / (baselineV + maxResponse) - 1);
603 double newStripCharge = baselineQ + stripCharge;
606 double signalV = 2 * maxResponse / (1 +
exp(-1.0 * newStripCharge /
rate)) - maxResponse;
607 double gain = signalV - baselineV;
615 detAmpl[
strip] = outputChargeInADC;
621 std::bitset<6>&
bs = DeadAPVList[detID];
627 1 - NumberOfBxBetweenHIPandEvent / floor(300.0 / 25.0);
628 float randomX = CLHEP::RandFlat::shoot(engine);
629 float scalingValue = (randomX - Shift) * 10.0 / 7.0 - 3.0 / 7.0;
633 detAmpl[
strip] *= scalingValue > 0 ? scalingValue : 0.0;
662 size_t firstChannelWithSignal = 0;
663 size_t lastChannelWithSignal = numStrips;
666 std::vector<float> noiseRMSv;
668 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
670 if (!badChannels[
strip]) {
671 float gainValue =
gain.getStripGain(
strip, detGainRange);
677 int RefStrip =
int(numStrips / 2.);
678 while (RefStrip < numStrips &&
679 badChannels[RefStrip]) {
682 if (RefStrip < numStrips) {
683 float RefgainValue =
gain.getStripGain(RefStrip, detGainRange);
687 detAmpl, firstChannelWithSignal, lastChannelWithSignal, numStrips, RefnoiseRMS, engine);
698 vSiStripDigi.push_back(SSD);
705 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_
Container::value_type value_type
std::vector< SiStripDigi > OneDetectorMap
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_
const SignalMapType * getSignal(uint32_t detID) const
constexpr uint32_t rawId() const
get the raw id
const int getBunchCrossing() const
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
APVMap theAffectedAPVmap_
std::pair< uint16_t, Amplitude > RawDigi
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_
std::map< int, Amplitude > SignalMapType
edm::ESGetToken< SiStripApvSimulationParameters, SiStripApvSimulationParametersRcd > apvSimulationParametersToken_
SiDigitalConverter::DigitalVecType DigitalVecType
Point3DBase< float, LocalTag > Local3DPoint