37 #include "CLHEP/Random/RandFlat.h"
71 typedef std::pair<uint16_t, Amplitude>
RawDigi;
91 return &where->second;
97 typedef std::multimap<uint32_t, std::bitset<6>>
APVMap;
149 : gainLabel(ps.getParameter<
std::
string>(
"Gain")),
151 peakMode(ps.getParameter<
bool>(
"APVpeakmode")),
152 theThreshold(ps.getParameter<double>(
"NoiseSigmaThreshold")),
153 theElectronPerADC(ps.getParameter<double>(peakMode ?
"electronPerAdcPeak" :
"electronPerAdcDec")),
154 APVSaturationFromHIP_(ps.getParameter<
bool>(
"APVSaturationFromHIP")),
155 theFedAlgo(ps.getParameter<
int>(
"FedAlgorithm_PM")),
159 includeAPVSimulation_(ps.getParameter<
bool>(
"includeAPVSimulation")),
160 fracOfEventsToSimAPV_(ps.getParameter<double>(
"fracOfEventsToSimAPV")),
161 apv_maxResponse_(ps.getParameter<double>(
"apv_maxResponse")),
162 apv_rate_(ps.getParameter<double>(
"apv_rate")),
163 apv_mVPerQ_(ps.getParameter<double>(
"apv_mVPerQ")),
164 apv_fCPerElectron_(ps.getParameter<double>(
"apvfCPerElectron"))
189 throw cms::Exception(
"Psiguration") <<
"SiStripDigitizer requires the RandomNumberGeneratorService\n"
190 "which is not present in the psiguration file. You must add the service\n"
191 "in the configuration file or remove the modules that require it.";
203 unsigned int detId = (*iu)->geographicalId().rawId();
205 unsigned int isub = idet.
subdetId();
208 auto stripdet = dynamic_cast<StripGeomDetUnit const*>((*iu));
209 assert(stripdet !=
nullptr);
227 badChannels.insert(badChannels.begin(), numStrips,
false);
229 hipChannels.insert(hipChannels.begin(), numStrips,
false);
234 badChannels[
strip] =
true;
250 for (; DSViter !=
input->end(); DSViter++) {
252 LogDebug(
"PreMixingSiStripWorker") <<
"Processing DetID " << DSViter->id;
256 LocalMap.
reserve((DSViter->data).size());
257 LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).
end());
279 LogDebug(
"PreMixingSiStripWorker") <<
"\n===============> adding pileups from event " << pep.
principal().
id()
288 const auto&
input = *inputHandle;
294 for (; DSViter !=
input.end(); DSViter++) {
296 LogDebug(
"PreMixingSiStripWorker") <<
"Pileups: Processing DetID " << DSViter->id;
301 SiGlobalIndex::const_iterator itest;
307 LocalMap = itest->second;
310 LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).
end());
317 LocalMap.reserve((DSViter->data).size());
318 LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).
end());
328 if (inputAPVHandle.
isValid()) {
329 const auto& APVinput = inputAPVHandle;
331 std::vector<std::pair<int, std::bitset<6>>>::const_iterator
entry = APVinput->begin();
342 std::vector<PileupSummaryInfo>
const& ps,
358 CLHEP::HepRandomEngine* engine = &rng->
getEngine(
e.streamID());
362 if (simulateAPVInThisEvent) {
365 const auto it = std::find_if(
367 if (it != std::begin(ps)) {
368 nTruePU = it->getTrueNumInteractions();
370 edm::LogWarning(
"PreMixingSiStripWorker") <<
"Could not find PileupSummaryInfo for current bunch crossing";
371 nTruePU = std::begin(ps)->getTrueNumInteractions();
375 std::map<int, std::bitset<6>> DeadAPVList;
399 uint32_t detID = IDet->first;
407 OneDetectorMap::const_iterator iLocal = LocalMap.begin();
408 for (; iLocal != LocalMap.end(); ++iLocal) {
409 uint16_t currentStrip = iLocal->strip();
410 float signal =
float(iLocal->adc());
411 if (iLocal->adc() == 1022)
413 if (iLocal->adc() == 1023)
418 float ReSignal = signal * signal / 9.0;
420 RawDigi NewRawDigi = std::make_pair(currentStrip, ReSignal);
422 LocalRawMap.push_back(NewRawDigi);
431 int NumberOfBxBetweenHIPandEvent = 1
e3;
436 bool HasAtleastOneAffectedAPV =
false;
437 while (!HasAtleastOneAffectedAPV) {
438 for (
int bx = floor(300.0 / 25.0);
bx > 0;
bx--) {
439 float temp = CLHEP::RandFlat::shoot(engine) < 0.5 ? 1 : 0;
440 if (
temp == 1 &&
bx < NumberOfBxBetweenHIPandEvent) {
441 NumberOfBxBetweenHIPandEvent =
bx;
442 HasAtleastOneAffectedAPV =
true;
447 APVMap::const_iterator iAPVchk;
448 uint32_t formerID = 0;
450 std::bitset<6> NewAPVBits;
453 currentID = iAPV->first;
455 if (currentID == formerID) {
456 for (
int ibit = 0; ibit < 6; ++ibit) {
457 NewAPVBits[ibit] = NewAPVBits[ibit] || (iAPV->second)[ibit];
460 DeadAPVList[currentID] = NewAPVBits;
462 formerID = currentID;
463 NewAPVBits = iAPV->second;
468 DeadAPVList[currentID] = NewAPVBits;
477 std::vector<edm::DetSet<SiStripDigi>> vSiStripDigi;
487 uint32_t detID = IDet->first;
495 int formerStrip = -1;
501 OneDetectorRawMap::const_iterator iLocalchk;
502 OneDetectorRawMap::const_iterator iLocal = LocalMap.begin();
503 for (; iLocal != LocalMap.end(); ++iLocal) {
504 currentStrip = iLocal->first;
506 if (currentStrip == formerStrip) {
508 ADCSum += iLocal->second;
510 if (formerStrip != -1) {
511 Signals.insert(std::make_pair(formerStrip, ADCSum));
514 formerStrip = currentStrip;
515 ADCSum = iLocal->second;
519 if ((++iLocalchk) == LocalMap.end()) {
520 Signals.insert(std::make_pair(formerStrip, ADCSum));
524 signals_.insert(std::make_pair(detID, Signals));
532 if (sgd !=
nullptr) {
543 std::vector<float> detAmpl(numStrips, 0.);
545 for (
const auto& amp : *theSignal) {
546 detAmpl[amp.first] = amp.second;
554 if (badChannels[
strip])
558 if (simulateAPVInThisEvent) {
563 float detSet_z = fabs(globalPos.
z());
564 float detSet_r = globalPos.
perp();
569 if (detAmpl[
strip] > 0) {
574 double baselineV = 0;
576 baselineV = apvSimulationParametersHandle->
sampleTIB(tTopo->
tibLayer(detID), detSet_z, nTruePU, engine);
578 baselineV = apvSimulationParametersHandle->
sampleTOB(tTopo->
tobLayer(detID), detSet_z, nTruePU, engine);
580 baselineV = apvSimulationParametersHandle->
sampleTID(tTopo->
tidWheel(detID), detSet_r, nTruePU, engine);
582 baselineV = apvSimulationParametersHandle->
sampleTEC(tTopo->
tecWheel(detID), detSet_r, nTruePU, engine);
588 double outputChargeInADC = 0;
591 double baselineQ = -1.0 *
rate *
log(2 * maxResponse / (baselineV + maxResponse) - 1);
594 double newStripCharge = baselineQ + stripCharge;
597 double signalV = 2 * maxResponse / (1 +
exp(-1.0 * newStripCharge /
rate)) - maxResponse;
598 double gain = signalV - baselineV;
606 detAmpl[
strip] = outputChargeInADC;
612 std::bitset<6>&
bs = DeadAPVList[detID];
618 1 - NumberOfBxBetweenHIPandEvent / floor(300.0 / 25.0);
619 float randomX = CLHEP::RandFlat::shoot(engine);
620 float scalingValue = (randomX - Shift) * 10.0 / 7.0 - 3.0 / 7.0;
624 detAmpl[
strip] *= scalingValue > 0 ? scalingValue : 0.0;
653 size_t firstChannelWithSignal = 0;
654 size_t lastChannelWithSignal = numStrips;
657 std::vector<float> noiseRMSv;
659 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
661 if (!badChannels[
strip]) {
668 int RefStrip =
int(numStrips / 2.);
669 while (RefStrip < numStrips &&
670 badChannels[RefStrip]) {
673 if (RefStrip < numStrips) {
674 float RefgainValue = gainHandle->
getStripGain(RefStrip, detGainRange);
678 detAmpl, firstChannelWithSignal, lastChannelWithSignal, numStrips, RefnoiseRMS, engine);
684 theSiDigitalConverter->convert(detAmpl, gainHandle, detID), digis, detID, noiseHandle, thresholdHandle);
689 vSiStripDigi.push_back(SSD);
696 edm::LogInfo(
"PreMixingSiStripWorker") <<
"total # Merged strips: " << vSiStripDigi.size();