31 #include "CLHEP/Random/RandFlat.h" 36 #include <boost/algorithm/string.hpp> 39 : theThreshold(conf.getParameter<double>(
"NoiseSigmaThreshold")),
40 cmnRMStib(conf.getParameter<double>(
"cmnRMStib")),
41 cmnRMStob(conf.getParameter<double>(
"cmnRMStob")),
42 cmnRMStid(conf.getParameter<double>(
"cmnRMStid")),
43 cmnRMStec(conf.getParameter<double>(
"cmnRMStec")),
44 APVSaturationProbScaling_(conf.getParameter<double>(
"APVSaturationProbScaling")),
45 makeDigiSimLinks_(conf.getUntrackedParameter<
bool>(
"makeDigiSimLinks",
false)),
46 peakMode(conf.getParameter<
bool>(
"APVpeakmode")),
53 theFedAlgo(conf.getParameter<
int>(
"FedAlgorithm")),
55 theElectronPerADC(conf.getParameter<double>(peakMode ?
"electronPerAdcPeak" :
"electronPerAdcDec")),
56 theTOFCutForPeak(conf.getParameter<double>(
"TOFCutForPeak")),
57 theTOFCutForDeconvolution(conf.getParameter<double>(
"TOFCutForDeconvolution")),
58 tofCut(peakMode ? theTOFCutForPeak : theTOFCutForDeconvolution),
59 cosmicShift(conf.getUntrackedParameter<double>(
"CosmicDelayShift")),
60 inefficiency(conf.getParameter<double>(
"Inefficiency")),
61 pedOffset((unsigned
int)conf.getParameter<double>(
"PedestalsOffset")),
62 PreMixing_(conf.getParameter<
bool>(
"PreMixingMode")),
71 includeAPVSimulation_(conf.getParameter<
bool>(
"includeAPVSimulation")),
72 apv_maxResponse_(conf.getParameter<double>(
"apv_maxResponse")),
73 apv_rate_(conf.getParameter<double>(
"apv_rate")),
74 apv_mVPerQ_(conf.getParameter<double>(
"apv_mVPerQ")),
75 apv_fCPerElectron_(conf.getParameter<double>(
"apvfCPerElectron")) {
77 LogDebug(
"StripDigiInfo") <<
"APVs running in peak mode (poor time resolution)";
79 LogDebug(
"StripDigiInfo") <<
"APVs running in deconvolution mode (good time resolution)";
82 LogDebug(
"SiStripDigitizerAlgorithm") <<
" SingleStripNoise: ON";
84 LogDebug(
"SiStripDigitizerAlgorithm") <<
" SingleStripNoise: OFF";
86 LogDebug(
"SiStripDigitizerAlgorithm") <<
" CommonModeNoise: ON";
88 LogDebug(
"SiStripDigitizerAlgorithm") <<
" CommonModeNoise: OFF";
90 throw cms::Exception(
"PreMixing does not work with HIP loss simulation yet");
96 std::vector<std::string> strs;
98 if (strs.size() == 2) {
104 throw cms::Exception(
"MissingInput") <<
"It seems that the APV probability list is missing\n";
118 badChannels.insert(badChannels.begin(), numStrips,
false);
122 badChannels[
strip] =
true;
155 std::vector<PSimHit>::const_iterator inputEnd,
156 size_t inputBeginGlobalIndex,
161 CLHEP::HepRandomEngine* engine) {
166 size_t thisFirstChannelWithSignal = numStrips;
167 size_t thisLastChannelWithSignal = 0;
171 std::vector<float> locAmpl(numStrips, 0.);
182 previousLocalAmplitude;
184 size_t simHitGlobalIndex = inputBeginGlobalIndex;
185 for (std::vector<PSimHit>::const_iterator simHitIter = inputBegin; simHitIter != inputEnd;
186 ++simHitIter, ++simHitGlobalIndex) {
188 if ((*simHitIter).detUnitId() !=
detId) {
194 simHitIter->energyLoss() > 0) {
196 previousLocalAmplitude = locAmpl;
197 size_t localFirstChannel = numStrips;
198 size_t localLastChannel = 0;
201 &*simHitIter, *det, bfield, langle, locAmpl, localFirstChannel, localLastChannel, tTopo, engine);
203 if (thisFirstChannelWithSignal > localFirstChannel)
204 thisFirstChannelWithSignal = localFirstChannel;
205 if (thisLastChannelWithSignal < localLastChannel)
206 thisLastChannelWithSignal = localLastChannel;
212 if (signalFromThisSimHit != 0) {
213 auto& associationVector = (*pDetIDAssociationInfo)[
stripIndex];
214 bool addNewEntry =
true;
217 for (
auto& associationInfo : associationVector) {
218 if (associationInfo.trackID == simHitIter->trackId() &&
219 associationInfo.eventID == simHitIter->eventId()) {
221 associationInfo.contributionToADC += signalFromThisSimHit;
229 simHitIter->trackId(), simHitIter->eventId(), signalFromThisSimHit, simHitGlobalIndex, tofBin});
236 theSiPileUpSignals->add(detID, locAmpl, thisFirstChannelWithSignal, thisLastChannelWithSignal);
253 double RevFreq = 11245.;
254 double minBXsec = 70.0E-27;
255 double Bunch = 2100.;
260 std::vector<int>::const_iterator
pu;
261 std::vector<int>::const_iterator pu0 = bunchCrossing.end();
263 for (
pu = bunchCrossing.begin();
pu != bunchCrossing.end(); ++
pu) {
270 if (pu0 != bunchCrossing.end()) {
292 bool simulateAPVInThisEvent,
294 std::vector<std::pair<
int, std::bitset<6>>>& theAffectedAPVvector,
295 CLHEP::HepRandomEngine* engine,
305 std::vector<float> detAmpl(numStrips, 0.);
307 for (
const auto& amp : *theSignal) {
308 detAmpl[amp.first] = amp.second;
315 if (badChannels[
strip]) {
325 float detSet_z = fabs(globalPos.
z());
326 float detSet_r = globalPos.
perp();
329 outStripAmplitudes.
reserve(numStrips);
336 if (detAmpl[
strip] > 0) {
341 double baselineV = 0;
358 double outputChargeInADC = 0;
361 double baselineQ = -1.0 *
rate *
log(2 * maxResponse / (baselineV + maxResponse) - 1);
364 double newStripCharge = baselineQ + stripCharge;
367 double signalV = 2 * maxResponse / (1 +
exp(-1.0 * newStripCharge /
rate)) - maxResponse;
368 double gain = signalV - baselineV;
376 detAmpl[
strip] = outputChargeInADC;
381 outStripAmplitudesPostAPV.
reserve(numStrips);
397 for (
int Napv = 0; Napv < 6; Napv++) {
398 float cursor = CLHEP::RandFlat::shoot(engine);
407 bool HasAtleastOneAffectedAPV =
false;
408 while (!HasAtleastOneAffectedAPV) {
409 for (
int bx = floor(300.0 / 25.0);
bx > 0;
bx--) {
410 float temp = CLHEP::RandFlat::shoot(engine) < 0.5 ? 1 : 0;
413 HasAtleastOneAffectedAPV =
true;
425 theAffectedAPVvector.push_back(std::make_pair(detID,
bs));
432 float randomX = CLHEP::RandFlat::shoot(engine);
433 float scalingValue = (randomX - Shift) * 10.0 / 7.0 - 3.0 / 7.0;
437 detAmpl[
strip] *= scalingValue > 0 ? scalingValue : 0.0;
452 auto iAssociationInfoByChannel =
461 std::vector<float> noiseRMSv;
463 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
465 if (!badChannels[
strip]) {
466 float gainValue =
gain.getStripGain(
strip, detGainRange);
473 int RefStrip =
int(numStrips / 2.);
474 while (RefStrip < numStrips &&
475 badChannels[RefStrip]) {
478 if (RefStrip < numStrips) {
479 float RefgainValue =
gain.getStripGain(RefStrip, detGainRange);
483 detAmpl, firstChannelWithSignal, lastChannelWithSignal, numStrips, RefnoiseRMS, engine);
494 if (iAssociationInfoByChannel !=
496 for (
const auto& iDigi : digis) {
497 auto& associationInfoByChannel = iAssociationInfoByChannel->second;
498 const std::vector<AssociationInfo>& associationInfo = associationInfoByChannel[iDigi.channel()];
502 float totalSimADC = 0;
503 for (
const auto& iAssociationInfo : associationInfo)
504 totalSimADC += iAssociationInfo.contributionToADC;
506 for (
const auto& iAssociationInfo : associationInfo) {
510 iAssociationInfo.trackID,
511 iAssociationInfo.simHitGlobalIndex,
512 iAssociationInfo.tofBin,
513 iAssociationInfo.eventID,
514 iAssociationInfo.contributionToADC / totalSimADC));
518 outdigi.
data = digis;
546 std::vector<float> noiseRMSv;
548 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
552 if (!badChannels[
strip])
558 while (RefStrip < numStrips &&
559 badChannels[RefStrip]) {
562 if (RefStrip < numStrips) {
565 if (!badChannels[
strip])
566 noiseRMSv[
strip] = noiseRMS;
579 switch (
detId.subdetId()) {
600 std::vector<float> vPeds;
602 vPeds.insert(vPeds.begin(), numStrips, 0.);
606 if (!badChannels[
strip])
611 if (!badChannels[
strip])
627 if (iAssociationInfoByChannel !=
632 for (
size_t channel = 0; channel < rawdigis.size(); ++channel) {
633 auto& associationInfoByChannel = iAssociationInfoByChannel->second;
634 const auto iAssociationInfo = associationInfoByChannel.find(channel);
635 if (iAssociationInfo == associationInfoByChannel.end())
637 const std::vector<AssociationInfo>& associationInfo = iAssociationInfo->second;
641 float totalSimADC = 0;
642 for (
const auto& iAssociationInfo : associationInfo)
643 totalSimADC += iAssociationInfo.contributionToADC;
645 for (
const auto& iAssociationInfo : associationInfo) {
649 iAssociationInfo.trackID,
650 iAssociationInfo.simHitGlobalIndex,
651 iAssociationInfo.tofBin,
652 iAssociationInfo.eventID,
653 iAssociationInfo.contributionToADC / totalSimADC));
658 outrawdigi.
data = rawdigis;
const edm::ESGetToken< HepPDT::ParticleDataTable, PDTRecord > pdtToken_
const std::unique_ptr< SiPileUpSignals > theSiPileUpSignals
unsigned int tobLayer(const DetId &id) const
edm::ESHandle< SiStripLorentzAngle > lorentzAngleHandle
void push_back(const T &t)
float sampleTOB(layerid layer, float z, float pu, CLHEP::HepRandomEngine *engine) const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
std::string fullPath() const
const int & getMix_bunchSpacing() const
std::map< int, float > mapOfAPVprobabilities
AssociationInfoForDetId associationInfoForDetId_
Structure that holds the information on the SimTrack contributions. Only filled if makeDigiSimLinks_ ...
SiDigitalConverter::DigitalRawVecType DigitalRawVecType
SiDigitalConverter::DigitalVecType DigitalVecType
std::vector< unsigned int >::const_iterator ContainerIterator
unsigned int tidWheel(const DetId &id) const
unsigned int tecWheel(const DetId &id) const
void initializeEvent(const edm::EventSetup &iSetup)
const double theElectronPerADC
float sampleTIB(layerid layer, float z, float pu, CLHEP::HepRandomEngine *engine) const
const std::vector< int > & getMix_bunchCrossing() const
const bool makeDigiSimLinks_
std::pair< ContainerIterator, ContainerIterator > Range
const Range getRange(const uint32_t detID) const
const std::unique_ptr< const SiGaussianTailNoiseAdder > theSiNoiseAdder
const std::unique_ptr< SiHitDigitizer > theSiHitDigitizer
bool includeAPVSimulation_
std::map< unsigned int, size_t > firstChannelsWithSignal
std::map< int, Amplitude > SignalMapType
static float getNoise(uint16_t strip, const Range &range)
const std::unique_ptr< SiTrivialDigitalConverter > theSiDigitalConverter
const bool zeroSuppression
void initializeDetUnit(StripGeomDetUnit const *det, SiStripBadStrip const &)
const std::unique_ptr< SiStripFedZeroSuppression > theSiZeroSuppress
__host__ __device__ std::uint32_t stripIndex(fedId_t fed, fedCh_t channel, stripId_t strip)
decltype(auto) emplace_back(Args &&... args)
edm::FileInPath APVProbabilityFile
const double apv_fCPerElectron_
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
std::pair< ContainerIterator, ContainerIterator > Range
const double apv_maxResponse_
DetId geographicalId() const
The label of this GeomDet.
void calculateInstlumiScale(PileupMixingContent *puInfo)
std::map< unsigned int, std::vector< bool > > allBadChannels
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
def split(sequence, size)
void setParticleDataTable(const ParticleDataTable *pardt)
float getLorentzAngle(const uint32_t &) const
float sampleTID(layerid wheel, float r, float pu, CLHEP::HepRandomEngine *engine) const
const double APVSaturationProbScaling_
const Plane & surface() const
The nominal surface of the GeomDet.
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
const std::vector< float > & getMix_TrueInteractions() const
constexpr uint32_t rawId() const
get the raw id
const edm::ESGetToken< SiStripLorentzAngle, SiStripLorentzAngleSimRcd > lorentzAngleToken_
std::map< int, std::vector< AssociationInfo > > AssociationInfoForChannel
SiStripDigitizerAlgorithm(const edm::ParameterSet &conf, edm::ConsumesCollector iC)
const double inefficiency
RealPedestals
NOTE : turning Noise ON/OFF will make a big change Parameters valid only if Noise = True and ZeroSupp...
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 *)
data decode(const unsigned int &value) const
virtual LocalPoint localPosition(float strip) const =0
int NumberOfBxBetweenHIPandEvent
unsigned int tibLayer(const DetId &id) 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 ...
float sampleTEC(layerid wheel, float r, float pu, CLHEP::HepRandomEngine *engine) const
const bool APVSaturationFromHIP
const bool CommonModeNoise
~SiStripDigitizerAlgorithm()
double APVSaturationProb_
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, const SiStripGain &, const SiStripThreshold &, const SiStripNoises &, const SiStripPedestals &, bool simulateAPVInThisEvent, const SiStripApvSimulationParameters *, std::vector< std::pair< int, std::bitset< 6 >>> &theAffectedAPVvector, CLHEP::HepRandomEngine *, const TrackerTopology *tTopo)
Point3DBase< float, LocalTag > Local3DPoint