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")),
48 noise(conf.getParameter<
bool>(
"Noise")),
54 theFedAlgo(conf.getParameter<
int>(
"FedAlgorithm")),
55 zeroSuppression(conf.getParameter<
bool>(
"ZeroSuppression")),
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]) {
330 float detSet_z = fabs(globalPos.
z());
331 float detSet_r = globalPos.
perp();
334 outStripAmplitudes.
reserve(numStrips);
341 if (detAmpl[
strip] > 0) {
346 double baselineV = 0;
363 double outputChargeInADC = 0;
366 double baselineQ = -1.0 * rate *
log(2 * maxResponse / (baselineV + maxResponse) - 1);
369 double newStripCharge = baselineQ + stripCharge;
372 double signalV = 2 * maxResponse / (1 +
exp(-1.0 * newStripCharge / rate)) - maxResponse;
373 double gain = signalV - baselineV;
381 detAmpl[
strip] = outputChargeInADC;
386 outStripAmplitudesPostAPV.
reserve(numStrips);
403 for (
int Napv = 0; Napv < 6; Napv++) {
404 float cursor = CLHEP::RandFlat::shoot(engine);
413 bool HasAtleastOneAffectedAPV =
false;
414 while (!HasAtleastOneAffectedAPV) {
415 for (
int bx = floor(300.0 / 25.0); bx > 0; bx--) {
416 float temp = CLHEP::RandFlat::shoot(engine) < 0.5 ? 1 : 0;
419 HasAtleastOneAffectedAPV =
true;
431 theAffectedAPVvector.push_back(std::make_pair(detID, bs));
438 float randomX = CLHEP::RandFlat::shoot(engine);
439 float scalingValue = (randomX - Shift) * 10.0 / 7.0 - 3.0 / 7.0;
442 if (!badChannels[
strip] && bs[
strip / 128] == 1) {
443 detAmpl[
strip] *= scalingValue > 0 ? scalingValue : 0.0;
458 auto iAssociationInfoByChannel =
467 std::vector<float> noiseRMSv;
469 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
471 if (!badChannels[
strip]) {
472 float gainValue = gainHandle->
getStripGain(strip, detGainRange);
479 int RefStrip =
int(numStrips / 2.);
480 while (RefStrip < numStrips &&
481 badChannels[RefStrip]) {
484 if (RefStrip < numStrips) {
485 float RefgainValue = gainHandle->
getStripGain(RefStrip, detGainRange);
489 detAmpl, firstChannelWithSignal, lastChannelWithSignal, numStrips, RefnoiseRMS, engine);
497 theSiDigitalConverter->convert(detAmpl, gainHandle, detID), digis, detID, noiseHandle, thresholdHandle);
500 if (iAssociationInfoByChannel !=
502 for (
const auto& iDigi : digis) {
503 auto& associationInfoByChannel = iAssociationInfoByChannel->second;
504 const std::vector<AssociationInfo>& associationInfo = associationInfoByChannel[iDigi.channel()];
508 float totalSimADC = 0;
509 for (
const auto& iAssociationInfo : associationInfo)
510 totalSimADC += iAssociationInfo.contributionToADC;
512 for (
const auto& iAssociationInfo : associationInfo) {
516 iAssociationInfo.trackID,
517 iAssociationInfo.simHitGlobalIndex,
518 iAssociationInfo.tofBin,
519 iAssociationInfo.eventID,
520 iAssociationInfo.contributionToADC / totalSimADC));
524 outdigi.
data = digis;
552 std::vector<float> noiseRMSv;
554 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
558 if (!badChannels[
strip])
564 while (RefStrip < numStrips &&
565 badChannels[RefStrip]) {
568 if (RefStrip < numStrips) {
571 if (!badChannels[
strip])
572 noiseRMSv[
strip] = noiseRMS;
606 std::vector<float> vPeds;
608 vPeds.insert(vPeds.begin(), numStrips, 0.);
612 if (!badChannels[
strip])
617 if (!badChannels[
strip])
633 if (iAssociationInfoByChannel !=
638 for (
size_t channel = 0; channel < rawdigis.size(); ++channel) {
639 auto& associationInfoByChannel = iAssociationInfoByChannel->second;
640 const auto iAssociationInfo = associationInfoByChannel.find(channel);
641 if (iAssociationInfo == associationInfoByChannel.end())
643 const std::vector<AssociationInfo>& associationInfo = iAssociationInfo->second;
647 float totalSimADC = 0;
648 for (
const auto& iAssociationInfo : associationInfo)
649 totalSimADC += iAssociationInfo.contributionToADC;
651 for (
const auto& iAssociationInfo : associationInfo) {
655 iAssociationInfo.trackID,
656 iAssociationInfo.simHitGlobalIndex,
657 iAssociationInfo.tofBin,
658 iAssociationInfo.eventID,
659 iAssociationInfo.contributionToADC / totalSimADC));
664 outrawdigi.
data = rawdigis;
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
Point3DBase< float, LocalTag > Local3DPoint
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_