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")),
72 includeAPVSimulation_(conf.getParameter<
bool>(
"includeAPVSimulation")),
73 apv_maxResponse_(conf.getParameter<double>(
"apv_maxResponse")),
74 apv_rate_(conf.getParameter<double>(
"apv_rate")),
75 apv_mVPerQ_(conf.getParameter<double>(
"apv_mVPerQ")),
76 apv_fCPerElectron_(conf.getParameter<double>(
"apvfCPerElectron")) {
78 LogDebug(
"StripDigiInfo") <<
"APVs running in peak mode (poor time resolution)";
80 LogDebug(
"StripDigiInfo") <<
"APVs running in deconvolution mode (good time resolution)";
83 LogDebug(
"SiStripDigitizerAlgorithm") <<
" SingleStripNoise: ON";
85 LogDebug(
"SiStripDigitizerAlgorithm") <<
" SingleStripNoise: OFF";
87 LogDebug(
"SiStripDigitizerAlgorithm") <<
" CommonModeNoise: ON";
89 LogDebug(
"SiStripDigitizerAlgorithm") <<
" CommonModeNoise: OFF";
91 throw cms::Exception(
"PreMixing does not work with HIP loss simulation yet");
97 std::vector<std::string> strs;
99 if (strs.size() == 2) {
105 throw cms::Exception(
"MissingInput") <<
"It seems that the APV probability list is missing\n";
121 badChannels.insert(badChannels.begin(), numStrips,
false);
125 badChannels[
strip] =
true;
158 std::vector<PSimHit>::const_iterator inputEnd,
159 size_t inputBeginGlobalIndex,
164 CLHEP::HepRandomEngine* engine) {
169 size_t thisFirstChannelWithSignal = numStrips;
170 size_t thisLastChannelWithSignal = 0;
174 std::vector<float> locAmpl(numStrips, 0.);
185 previousLocalAmplitude;
187 size_t simHitGlobalIndex = inputBeginGlobalIndex;
188 for (std::vector<PSimHit>::const_iterator simHitIter = inputBegin; simHitIter != inputEnd;
189 ++simHitIter, ++simHitGlobalIndex) {
191 if ((*simHitIter).detUnitId() != detId) {
197 simHitIter->energyLoss() > 0) {
199 previousLocalAmplitude = locAmpl;
200 size_t localFirstChannel = numStrips;
201 size_t localLastChannel = 0;
204 &*simHitIter, *det, bfield, langle, locAmpl, localFirstChannel, localLastChannel, tTopo, engine);
206 if (thisFirstChannelWithSignal > localFirstChannel)
207 thisFirstChannelWithSignal = localFirstChannel;
208 if (thisLastChannelWithSignal < localLastChannel)
209 thisLastChannelWithSignal = localLastChannel;
212 for (
size_t stripIndex = 0; stripIndex < locAmpl.size(); ++stripIndex) {
214 float signalFromThisSimHit = locAmpl[stripIndex] - previousLocalAmplitude[stripIndex];
215 if (signalFromThisSimHit != 0) {
216 auto& associationVector = (*pDetIDAssociationInfo)[stripIndex];
217 bool addNewEntry =
true;
220 for (
auto& associationInfo : associationVector) {
221 if (associationInfo.trackID == simHitIter->trackId() &&
222 associationInfo.eventID == simHitIter->eventId()) {
224 associationInfo.contributionToADC += signalFromThisSimHit;
232 simHitIter->trackId(), simHitIter->eventId(), signalFromThisSimHit, simHitGlobalIndex, tofBin});
239 theSiPileUpSignals->add(detID, locAmpl, thisFirstChannelWithSignal, thisLastChannelWithSignal);
256 double RevFreq = 11245.;
257 double minBXsec = 70.0E-27;
258 double Bunch = 2100.;
263 std::vector<int>::const_iterator
pu;
264 std::vector<int>::const_iterator pu0 = bunchCrossing.end();
266 for (
pu = bunchCrossing.begin();
pu != bunchCrossing.end(); ++
pu) {
273 if (pu0 != bunchCrossing.end()) {
295 bool simulateAPVInThisEvent,
297 std::vector<std::pair<
int, std::bitset<6>>>& theAffectedAPVvector,
298 CLHEP::HepRandomEngine* engine,
308 std::vector<float> detAmpl(numStrips, 0.);
310 for (
const auto& amp : *theSignal) {
311 detAmpl[amp.first] = amp.second;
318 if (badChannels[
strip]) {
328 float detSet_z = fabs(globalPos.
z());
329 float detSet_r = globalPos.
perp();
332 outStripAmplitudes.
reserve(numStrips);
339 if (detAmpl[
strip] > 0) {
344 double baselineV = 0;
361 double outputChargeInADC = 0;
364 double baselineQ = -1.0 *
rate *
log(2 * maxResponse / (baselineV + maxResponse) - 1);
367 double newStripCharge = baselineQ + stripCharge;
370 double signalV = 2 * maxResponse / (1 +
exp(-1.0 * newStripCharge /
rate)) - maxResponse;
371 double gain = signalV - baselineV;
379 detAmpl[
strip] = outputChargeInADC;
384 outStripAmplitudesPostAPV.
reserve(numStrips);
400 for (
int Napv = 0; Napv < 6; Napv++) {
401 float cursor = CLHEP::RandFlat::shoot(engine);
410 bool HasAtleastOneAffectedAPV =
false;
411 while (!HasAtleastOneAffectedAPV) {
412 for (
int bx = floor(300.0 / 25.0);
bx > 0;
bx--) {
413 float temp = CLHEP::RandFlat::shoot(engine) < 0.5 ? 1 : 0;
416 HasAtleastOneAffectedAPV =
true;
428 theAffectedAPVvector.push_back(std::make_pair(detID,
bs));
435 float randomX = CLHEP::RandFlat::shoot(engine);
436 float scalingValue = (randomX - Shift) * 10.0 / 7.0 - 3.0 / 7.0;
440 detAmpl[
strip] *= scalingValue > 0 ? scalingValue : 0.0;
455 auto iAssociationInfoByChannel =
464 std::vector<float> noiseRMSv;
466 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
468 if (!badChannels[
strip]) {
469 float gainValue =
gain.getStripGain(
strip, detGainRange);
476 int RefStrip =
int(numStrips / 2.);
477 while (RefStrip < numStrips &&
478 badChannels[RefStrip]) {
481 if (RefStrip < numStrips) {
482 float RefgainValue =
gain.getStripGain(RefStrip, detGainRange);
486 detAmpl, firstChannelWithSignal, lastChannelWithSignal, numStrips, RefnoiseRMS, engine);
497 if (iAssociationInfoByChannel !=
499 for (
const auto& iDigi : digis) {
500 auto& associationInfoByChannel = iAssociationInfoByChannel->second;
501 const std::vector<AssociationInfo>& associationInfo = associationInfoByChannel[iDigi.channel()];
505 float totalSimADC = 0;
506 for (
const auto& iAssociationInfo : associationInfo)
507 totalSimADC += iAssociationInfo.contributionToADC;
509 for (
const auto& iAssociationInfo : associationInfo) {
513 iAssociationInfo.trackID,
514 iAssociationInfo.simHitGlobalIndex,
515 iAssociationInfo.tofBin,
516 iAssociationInfo.eventID,
517 iAssociationInfo.contributionToADC / totalSimADC));
521 outdigi.
data = digis;
549 std::vector<float> noiseRMSv;
551 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
555 if (!badChannels[
strip])
561 while (RefStrip < numStrips &&
562 badChannels[RefStrip]) {
565 if (RefStrip < numStrips) {
568 if (!badChannels[
strip])
569 noiseRMSv[
strip] = noiseRMS;
603 std::vector<float> vPeds;
605 vPeds.insert(vPeds.begin(), numStrips, 0.);
609 if (!badChannels[
strip])
614 if (!badChannels[
strip])
630 if (iAssociationInfoByChannel !=
635 for (
size_t channel = 0; channel < rawdigis.size(); ++channel) {
636 auto& associationInfoByChannel = iAssociationInfoByChannel->second;
637 const auto iAssociationInfo = associationInfoByChannel.find(channel);
638 if (iAssociationInfo == associationInfoByChannel.end())
640 const std::vector<AssociationInfo>& associationInfo = iAssociationInfo->second;
644 float totalSimADC = 0;
645 for (
const auto& iAssociationInfo : associationInfo)
646 totalSimADC += iAssociationInfo.contributionToADC;
648 for (
const auto& iAssociationInfo : associationInfo) {
652 iAssociationInfo.trackID,
653 iAssociationInfo.simHitGlobalIndex,
654 iAssociationInfo.tofBin,
655 iAssociationInfo.eventID,
656 iAssociationInfo.contributionToADC / totalSimADC));
661 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
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
void initializeDetUnit(StripGeomDetUnit const *det, const edm::EventSetup &iSetup)
const edm::ESGetToken< SiStripBadStrip, SiStripBadChannelRcd > deadChannelToken_
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
const std::unique_ptr< SiStripFedZeroSuppression > theSiZeroSuppress
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
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
bool getData(T &iHolder) const
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 *)
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