37 #include "CLHEP/Random/RandFlat.h"
80 typedef std::pair<uint16_t, Amplitude>
RawDigi;
100 return &where->second;
106 typedef std::multimap<uint32_t, std::bitset<6>>
APVMap;
162 peakMode(ps.getParameter<
bool>(
"APVpeakmode")),
163 theThreshold(ps.getParameter<double>(
"NoiseSigmaThreshold")),
164 theElectronPerADC(ps.getParameter<double>(peakMode ?
"electronPerAdcPeak" :
"electronPerAdcDec")),
165 APVSaturationFromHIP_(ps.getParameter<
bool>(
"APVSaturationFromHIP")),
166 theFedAlgo(ps.getParameter<
int>(
"FedAlgorithm_PM")),
169 includeAPVSimulation_(ps.getParameter<
bool>(
"includeAPVSimulation")),
170 fracOfEventsToSimAPV_(ps.getParameter<double>(
"fracOfEventsToSimAPV")),
171 apv_maxResponse_(ps.getParameter<double>(
"apv_maxResponse")),
172 apv_rate_(ps.getParameter<double>(
"apv_rate")),
173 apv_mVPerQ_(ps.getParameter<double>(
"apv_mVPerQ")),
174 apv_fCPerElectron_(ps.getParameter<double>(
"apvfCPerElectron"))
204 throw cms::Exception(
"Psiguration") <<
"SiStripDigitizer requires the RandomNumberGeneratorService\n"
205 "which is not present in the psiguration file. You must add the service\n"
206 "in the configuration file or remove the modules that require it.";
218 unsigned int detId = (*iu)->geographicalId().rawId();
220 unsigned int isub = idet.
subdetId();
223 auto stripdet = dynamic_cast<StripGeomDetUnit const*>((*iu));
224 assert(stripdet !=
nullptr);
241 badChannels.insert(badChannels.begin(), numStrips,
false);
243 hipChannels.insert(hipChannels.begin(), numStrips,
false);
248 badChannels[
strip] =
true;
264 for (; DSViter !=
input->end(); DSViter++) {
266 LogDebug(
"PreMixingSiStripWorker") <<
"Processing DetID " << DSViter->id;
270 LocalMap.
reserve((DSViter->data).size());
271 LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).
end());
293 LogDebug(
"PreMixingSiStripWorker") <<
"\n===============> adding pileups from event " << pep.
principal().
id()
302 const auto&
input = *inputHandle;
308 for (; DSViter !=
input.end(); DSViter++) {
310 LogDebug(
"PreMixingSiStripWorker") <<
"Pileups: Processing DetID " << DSViter->id;
315 SiGlobalIndex::const_iterator itest;
321 LocalMap = itest->second;
324 LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).
end());
331 LocalMap.reserve((DSViter->data).size());
332 LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).
end());
342 if (inputAPVHandle.
isValid()) {
343 const auto& APVinput = inputAPVHandle;
345 std::vector<std::pair<int, std::bitset<6>>>::const_iterator
entry = APVinput->begin();
356 std::vector<PileupSummaryInfo>
const& ps,
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();