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.;
260 if (bunchSpacing == 50)
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;
440 if (!badChannels[
strip] && bs[
strip / 128] == 1) {
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]) {
470 float gainValue = gainHandle->
getStripGain(strip, detGainRange);
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;
std::vector< std::string_view > split(std::string_view, const char *)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
const std::unique_ptr< SiPileUpSignals > theSiPileUpSignals
edm::ESHandle< SiStripLorentzAngle > lorentzAngleHandle
float sampleTIB(layerid layer, float z, float pu, CLHEP::HepRandomEngine *engine) const
void push_back(const T &t)
unsigned int tibLayer(const DetId &id) const
std::map< int, float > mapOfAPVprobabilities
AssociationInfoForDetId associationInfoForDetId_
Structure that holds the information on the SimTrack contributions. Only filled if makeDigiSimLinks_ ...
const std::vector< float > & getMix_TrueInteractions() const
SiDigitalConverter::DigitalRawVecType DigitalRawVecType
SiDigitalConverter::DigitalVecType DigitalVecType
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
const std::vector< int > & getMix_bunchCrossing() const
std::vector< unsigned int >::const_iterator ContainerIterator
float sampleTID(layerid wheel, float r, float pu, CLHEP::HepRandomEngine *engine) const
void digitize(edm::DetSet< SiStripDigi > &outDigis, edm::DetSet< SiStripRawDigi > &outRawDigis, edm::DetSet< SiStripRawDigi > &outStripAmplitudes, edm::DetSet< SiStripRawDigi > &outStripAmplitudesPostAPV, edm::DetSet< SiStripRawDigi > &outStripAPVBaselines, edm::DetSet< StripDigiSimLink > &outLink, const StripGeomDetUnit *stripdet, edm::ESHandle< SiStripGain > &, edm::ESHandle< SiStripThreshold > &, edm::ESHandle< SiStripNoises > &, edm::ESHandle< SiStripPedestals > &, bool simulateAPVInThisEvent, edm::ESHandle< SiStripApvSimulationParameters > &, std::vector< std::pair< int, std::bitset< 6 >>> &theAffectedAPVvector, CLHEP::HepRandomEngine *, const TrackerTopology *tTopo)
constexpr uint32_t rawId() const
get the raw id
void initializeEvent(const edm::EventSetup &iSetup)
const double theElectronPerADC
unsigned int tidWheel(const DetId &id) const
const bool makeDigiSimLinks_
std::pair< ContainerIterator, ContainerIterator > Range
void initializeDetUnit(StripGeomDetUnit const *det, const edm::EventSetup &iSetup)
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
const Plane & surface() const
The nominal surface of the GeomDet.
const std::unique_ptr< const SiGaussianTailNoiseAdder > theSiNoiseAdder
const std::unique_ptr< SiHitDigitizer > theSiHitDigitizer
float sampleTOB(layerid layer, float z, float pu, CLHEP::HepRandomEngine *engine) const
bool includeAPVSimulation_
std::map< unsigned int, size_t > firstChannelsWithSignal
float getPed(const uint16_t &strip, const Range &range) const
std::map< int, Amplitude > SignalMapType
bool getData(T &iHolder) const
static float getNoise(uint16_t strip, const Range &range)
float getLorentzAngle(const uint32_t &) const
const std::unique_ptr< SiTrivialDigitalConverter > theSiDigitalConverter
const bool zeroSuppression
decltype(auto) emplace_back(Args &&...args)
const std::unique_ptr< SiStripFedZeroSuppression > theSiZeroSuppress
virtual LocalPoint localPosition(float strip) const =0
static float getStripGain(const uint16_t &strip, const SiStripApvGain::Range &range)
edm::FileInPath APVProbabilityFile
const double apv_fCPerElectron_
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::pair< ContainerIterator, ContainerIterator > Range
DetId geographicalId() const
The label of this GeomDet.
const std::string lorentzAngleName
const double apv_maxResponse_
void calculateInstlumiScale(PileupMixingContent *puInfo)
std::map< unsigned int, std::vector< bool > > allBadChannels
void setParticleDataTable(const ParticleDataTable *pardt)
const double APVSaturationProbScaling_
unsigned short firstStrip
std::map< int, std::vector< AssociationInfo > > AssociationInfoForChannel
const double inefficiency
RealPedestals
NOTE : turning Noise ON/OFF will make a big change Parameters valid only if Noise = True and ZeroSupp...
SiStripDigitizerAlgorithm(const edm::ParameterSet &conf)
const Range getRange(const uint32_t detID) const
const Range getRange(const uint32_t detID) const
std::pair< ContainerIterator, ContainerIterator > Range
std::map< unsigned int, size_t > lastChannelsWithSignal
std::ifstream APVProbaFile
void accumulateSimHits(const std::vector< PSimHit >::const_iterator inputBegin, const std::vector< PSimHit >::const_iterator inputEnd, size_t inputBeginGlobalIndex, unsigned int tofBin, const StripGeomDetUnit *stripdet, const GlobalVector &bfield, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)
const int & getMix_bunchSpacing() const
std::string fullPath() const
int NumberOfBxBetweenHIPandEvent
const Range getRange(const uint32_t &detID) const
std::map< int, std::bitset< 6 > > SiStripTrackerAffectedAPVMap
std::pair< ContainerIterator, ContainerIterator > Range
const bool SingleStripNoise
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
unsigned int tecWheel(const DetId &id) const
const bool APVSaturationFromHIP
float sampleTEC(layerid wheel, float r, float pu, CLHEP::HepRandomEngine *engine) const
const ParticleDataTable * pdt
data decode(const unsigned int &value) const
const bool CommonModeNoise
unsigned int tobLayer(const DetId &id) const
~SiStripDigitizerAlgorithm()
const SiStripApvGain::Range getRange(uint32_t detID) const
double APVSaturationProb_
Point3DBase< float, LocalTag > Local3DPoint