31 #include "CLHEP/Random/RandFlat.h"
36 #include <boost/algorithm/string.hpp>
39 : lorentzAngleName(conf.getParameter<
std::
string>(
"LorentzAngle")),
40 theThreshold(conf.getParameter<double>(
"NoiseSigmaThreshold")),
41 cmnRMStib(conf.getParameter<double>(
"cmnRMStib")),
42 cmnRMStob(conf.getParameter<double>(
"cmnRMStob")),
43 cmnRMStid(conf.getParameter<double>(
"cmnRMStid")),
44 cmnRMStec(conf.getParameter<double>(
"cmnRMStec")),
45 APVSaturationProbScaling_(conf.getParameter<double>(
"APVSaturationProbScaling")),
46 makeDigiSimLinks_(conf.getUntrackedParameter<
bool>(
"makeDigiSimLinks",
false)),
47 peakMode(conf.getParameter<
bool>(
"APVpeakmode")),
54 theFedAlgo(conf.getParameter<
int>(
"FedAlgorithm")),
56 theElectronPerADC(conf.getParameter<double>(peakMode ?
"electronPerAdcPeak" :
"electronPerAdcDec")),
57 theTOFCutForPeak(conf.getParameter<double>(
"TOFCutForPeak")),
58 theTOFCutForDeconvolution(conf.getParameter<double>(
"TOFCutForDeconvolution")),
59 tofCut(peakMode ? theTOFCutForPeak : theTOFCutForDeconvolution),
60 cosmicShift(conf.getUntrackedParameter<double>(
"CosmicDelayShift")),
61 inefficiency(conf.getParameter<double>(
"Inefficiency")),
62 pedOffset((unsigned
int)conf.getParameter<double>(
"PedestalsOffset")),
63 PreMixing_(conf.getParameter<
bool>(
"PreMixingMode")),
70 includeAPVSimulation_(conf.getParameter<
bool>(
"includeAPVSimulation")),
71 apv_maxResponse_(conf.getParameter<double>(
"apv_maxResponse")),
72 apv_rate_(conf.getParameter<double>(
"apv_rate")),
73 apv_mVPerQ_(conf.getParameter<double>(
"apv_mVPerQ")),
74 apv_fCPerElectron_(conf.getParameter<double>(
"apvfCPerElectron")) {
76 LogDebug(
"StripDigiInfo") <<
"APVs running in peak mode (poor time resolution)";
78 LogDebug(
"StripDigiInfo") <<
"APVs running in deconvolution mode (good time resolution)";
81 LogDebug(
"SiStripDigitizerAlgorithm") <<
" SingleStripNoise: ON";
83 LogDebug(
"SiStripDigitizerAlgorithm") <<
" SingleStripNoise: OFF";
85 LogDebug(
"SiStripDigitizerAlgorithm") <<
" CommonModeNoise: ON";
87 LogDebug(
"SiStripDigitizerAlgorithm") <<
" CommonModeNoise: OFF";
89 throw cms::Exception(
"PreMixing does not work with HIP loss simulation yet");
95 std::vector<std::string> strs;
97 if (strs.size() == 2) {
103 throw cms::Exception(
"MissingInput") <<
"It seems that the APV probability list is missing\n";
120 badChannels.insert(badChannels.begin(), numStrips,
false);
124 badChannels[
strip] =
true;
159 std::vector<PSimHit>::const_iterator inputEnd,
160 size_t inputBeginGlobalIndex,
165 CLHEP::HepRandomEngine* engine) {
170 size_t thisFirstChannelWithSignal = numStrips;
171 size_t thisLastChannelWithSignal = 0;
175 std::vector<float> locAmpl(numStrips, 0.);
186 previousLocalAmplitude;
188 size_t simHitGlobalIndex = inputBeginGlobalIndex;
189 for (std::vector<PSimHit>::const_iterator simHitIter = inputBegin; simHitIter != inputEnd;
190 ++simHitIter, ++simHitGlobalIndex) {
192 if ((*simHitIter).detUnitId() != detId) {
198 simHitIter->energyLoss() > 0) {
200 previousLocalAmplitude = locAmpl;
201 size_t localFirstChannel = numStrips;
202 size_t localLastChannel = 0;
205 &*simHitIter, *det, bfield, langle, locAmpl, localFirstChannel, localLastChannel, tTopo, engine);
207 if (thisFirstChannelWithSignal > localFirstChannel)
208 thisFirstChannelWithSignal = localFirstChannel;
209 if (thisLastChannelWithSignal < localLastChannel)
210 thisLastChannelWithSignal = localLastChannel;
213 for (
size_t stripIndex = 0; stripIndex < locAmpl.size(); ++stripIndex) {
215 float signalFromThisSimHit = locAmpl[stripIndex] - previousLocalAmplitude[stripIndex];
216 if (signalFromThisSimHit != 0) {
217 auto& associationVector = (*pDetIDAssociationInfo)[stripIndex];
218 bool addNewEntry =
true;
221 for (
auto& associationInfo : associationVector) {
222 if (associationInfo.trackID == simHitIter->trackId() &&
223 associationInfo.eventID == simHitIter->eventId()) {
225 associationInfo.contributionToADC += signalFromThisSimHit;
233 simHitIter->trackId(), simHitIter->eventId(), signalFromThisSimHit, simHitGlobalIndex, tofBin});
240 theSiPileUpSignals->add(detID, locAmpl, thisFirstChannelWithSignal, thisLastChannelWithSignal);
257 double RevFreq = 11245.;
258 double minBXsec = 70.0E-27;
259 double Bunch = 2100.;
264 std::vector<int>::const_iterator
pu;
265 std::vector<int>::const_iterator pu0 = bunchCrossing.end();
267 for (
pu = bunchCrossing.begin();
pu != bunchCrossing.end(); ++
pu) {
274 if (pu0 != bunchCrossing.end()) {
296 bool simulateAPVInThisEvent,
298 std::vector<std::pair<
int, std::bitset<6>>>& theAffectedAPVvector,
299 CLHEP::HepRandomEngine* engine,
309 std::vector<float> detAmpl(numStrips, 0.);
311 for (
const auto& amp : *theSignal) {
312 detAmpl[amp.first] = amp.second;
319 if (badChannels[
strip]) {
329 float detSet_z = fabs(globalPos.
z());
330 float detSet_r = globalPos.
perp();
333 outStripAmplitudes.
reserve(numStrips);
340 if (detAmpl[
strip] > 0) {
345 double baselineV = 0;
362 double outputChargeInADC = 0;
365 double baselineQ = -1.0 *
rate *
log(2 * maxResponse / (baselineV + maxResponse) - 1);
368 double newStripCharge = baselineQ + stripCharge;
371 double signalV = 2 * maxResponse / (1 +
exp(-1.0 * newStripCharge /
rate)) - maxResponse;
372 double gain = signalV - baselineV;
380 detAmpl[
strip] = outputChargeInADC;
385 outStripAmplitudesPostAPV.
reserve(numStrips);
401 for (
int Napv = 0; Napv < 6; Napv++) {
402 float cursor = CLHEP::RandFlat::shoot(engine);
411 bool HasAtleastOneAffectedAPV =
false;
412 while (!HasAtleastOneAffectedAPV) {
413 for (
int bx = floor(300.0 / 25.0);
bx > 0;
bx--) {
414 float temp = CLHEP::RandFlat::shoot(engine) < 0.5 ? 1 : 0;
417 HasAtleastOneAffectedAPV =
true;
429 theAffectedAPVvector.push_back(std::make_pair(detID,
bs));
436 float randomX = CLHEP::RandFlat::shoot(engine);
437 float scalingValue = (randomX - Shift) * 10.0 / 7.0 - 3.0 / 7.0;
441 detAmpl[
strip] *= scalingValue > 0 ? scalingValue : 0.0;
456 auto iAssociationInfoByChannel =
465 std::vector<float> noiseRMSv;
467 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
469 if (!badChannels[
strip]) {
477 int RefStrip =
int(numStrips / 2.);
478 while (RefStrip < numStrips &&
479 badChannels[RefStrip]) {
482 if (RefStrip < numStrips) {
483 float RefgainValue = gainHandle->
getStripGain(RefStrip, detGainRange);
487 detAmpl, firstChannelWithSignal, lastChannelWithSignal, numStrips, RefnoiseRMS, engine);
495 theSiDigitalConverter->convert(detAmpl, gainHandle, detID), digis, detID, noiseHandle, thresholdHandle);
498 if (iAssociationInfoByChannel !=
500 for (
const auto& iDigi : digis) {
501 auto& associationInfoByChannel = iAssociationInfoByChannel->second;
502 const std::vector<AssociationInfo>& associationInfo = associationInfoByChannel[iDigi.channel()];
506 float totalSimADC = 0;
507 for (
const auto& iAssociationInfo : associationInfo)
508 totalSimADC += iAssociationInfo.contributionToADC;
510 for (
const auto& iAssociationInfo : associationInfo) {
514 iAssociationInfo.trackID,
515 iAssociationInfo.simHitGlobalIndex,
516 iAssociationInfo.tofBin,
517 iAssociationInfo.eventID,
518 iAssociationInfo.contributionToADC / totalSimADC));
522 outdigi.
data = digis;
550 std::vector<float> noiseRMSv;
552 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
556 if (!badChannels[
strip])
562 while (RefStrip < numStrips &&
563 badChannels[RefStrip]) {
566 if (RefStrip < numStrips) {
569 if (!badChannels[
strip])
570 noiseRMSv[
strip] = noiseRMS;
604 std::vector<float> vPeds;
606 vPeds.insert(vPeds.begin(), numStrips, 0.);
610 if (!badChannels[
strip])
615 if (!badChannels[
strip])
631 if (iAssociationInfoByChannel !=
636 for (
size_t channel = 0; channel < rawdigis.size(); ++channel) {
637 auto& associationInfoByChannel = iAssociationInfoByChannel->second;
638 const auto iAssociationInfo = associationInfoByChannel.find(channel);
639 if (iAssociationInfo == associationInfoByChannel.end())
641 const std::vector<AssociationInfo>& associationInfo = iAssociationInfo->second;
645 float totalSimADC = 0;
646 for (
const auto& iAssociationInfo : associationInfo)
647 totalSimADC += iAssociationInfo.contributionToADC;
649 for (
const auto& iAssociationInfo : associationInfo) {
653 iAssociationInfo.trackID,
654 iAssociationInfo.simHitGlobalIndex,
655 iAssociationInfo.tofBin,
656 iAssociationInfo.eventID,
657 iAssociationInfo.contributionToADC / totalSimADC));
662 outrawdigi.
data = rawdigis;