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")),
71 LogDebug(
"StripDigiInfo") <<
"APVs running in peak mode (poor time resolution)";
73 LogDebug(
"StripDigiInfo") <<
"APVs running in deconvolution mode (good time resolution)";
76 LogDebug(
"SiStripDigitizerAlgorithm") <<
" SingleStripNoise: ON";
78 LogDebug(
"SiStripDigitizerAlgorithm") <<
" SingleStripNoise: OFF";
80 LogDebug(
"SiStripDigitizerAlgorithm") <<
" CommonModeNoise: ON";
82 LogDebug(
"SiStripDigitizerAlgorithm") <<
" CommonModeNoise: OFF";
84 throw cms::Exception(
"PreMixing does not work with HIP loss simulation yet");
90 std::vector<std::string> strs;
92 if (strs.size() == 2) {
98 throw cms::Exception(
"MissingInput") <<
"It seems that the APV probability list is missing\n";
115 badChannels.insert(badChannels.begin(), numStrips,
false);
119 badChannels[
strip] =
true;
152 std::vector<PSimHit>::const_iterator inputEnd,
153 size_t inputBeginGlobalIndex,
158 CLHEP::HepRandomEngine* engine) {
163 size_t thisFirstChannelWithSignal = numStrips;
164 size_t thisLastChannelWithSignal = 0;
168 std::vector<float> locAmpl(numStrips, 0.);
179 previousLocalAmplitude;
181 size_t simHitGlobalIndex = inputBeginGlobalIndex;
182 for (std::vector<PSimHit>::const_iterator simHitIter = inputBegin; simHitIter != inputEnd;
183 ++simHitIter, ++simHitGlobalIndex) {
185 if ((*simHitIter).detUnitId() != detId) {
191 simHitIter->energyLoss() > 0) {
193 previousLocalAmplitude = locAmpl;
194 size_t localFirstChannel = numStrips;
195 size_t localLastChannel = 0;
198 &*simHitIter, *det, bfield, langle, locAmpl, localFirstChannel, localLastChannel, tTopo, engine);
200 if (thisFirstChannelWithSignal > localFirstChannel)
201 thisFirstChannelWithSignal = localFirstChannel;
202 if (thisLastChannelWithSignal < localLastChannel)
203 thisLastChannelWithSignal = localLastChannel;
206 for (
size_t stripIndex = 0; stripIndex < locAmpl.size(); ++stripIndex) {
208 float signalFromThisSimHit = locAmpl[stripIndex] - previousLocalAmplitude[stripIndex];
209 if (signalFromThisSimHit != 0) {
210 auto& associationVector = (*pDetIDAssociationInfo)[stripIndex];
211 bool addNewEntry =
true;
214 for (
auto& associationInfo : associationVector) {
215 if (associationInfo.trackID == simHitIter->trackId() &&
216 associationInfo.eventID == simHitIter->eventId()) {
218 associationInfo.contributionToADC += signalFromThisSimHit;
226 simHitIter->trackId(), simHitIter->eventId(), signalFromThisSimHit, simHitGlobalIndex, tofBin});
233 theSiPileUpSignals->add(detID, locAmpl, thisFirstChannelWithSignal, thisLastChannelWithSignal);
250 double RevFreq = 11245.;
251 double minBXsec = 70.0E-27;
252 double Bunch = 2100.;
253 if (bunchSpacing == 50)
257 std::vector<int>::const_iterator
pu;
258 std::vector<int>::const_iterator pu0 = bunchCrossing.end();
260 for (pu = bunchCrossing.begin(); pu != bunchCrossing.end(); ++
pu) {
267 if (pu0 != bunchCrossing.end()) {
268 double Tintr = TrueInteractionList.at(
p);
269 double instLumi = Bunch * Tintr * RevFreq / minBXsec;
286 std::vector<std::pair<
int, std::bitset<6>>>& theAffectedAPVvector,
287 CLHEP::HepRandomEngine* engine) {
293 std::vector<float> detAmpl(numStrips, 0.);
295 for (
const auto& amp : *theSignal) {
296 detAmpl[amp.first] = amp.second;
303 if (badChannels[
strip]) {
319 for (
int Napv = 0; Napv < 6; Napv++) {
320 float cursor = CLHEP::RandFlat::shoot(engine);
329 bool HasAtleastOneAffectedAPV =
false;
330 while (!HasAtleastOneAffectedAPV) {
331 for (
int bx = floor(300.0 / 25.0); bx > 0; bx--) {
332 float temp = CLHEP::RandFlat::shoot(engine) < 0.5 ? 1 : 0;
335 HasAtleastOneAffectedAPV =
true;
347 theAffectedAPVvector.push_back(std::make_pair(detID, bs));
354 float randomX = CLHEP::RandFlat::shoot(engine);
355 float scalingValue = (randomX - Shift) * 10.0 / 7.0 - 3.0 / 7.0;
358 if (!badChannels[
strip] && bs[
strip / 128] == 1) {
359 detAmpl[
strip] *= scalingValue > 0 ? scalingValue : 0.0;
374 auto iAssociationInfoByChannel =
383 std::vector<float> noiseRMSv;
385 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
387 if (!badChannels[
strip]) {
388 float gainValue = gainHandle->
getStripGain(strip, detGainRange);
395 int RefStrip =
int(numStrips / 2.);
396 while (RefStrip < numStrips &&
397 badChannels[RefStrip]) {
400 if (RefStrip < numStrips) {
401 float RefgainValue = gainHandle->
getStripGain(RefStrip, detGainRange);
405 detAmpl, firstChannelWithSignal, lastChannelWithSignal, numStrips, RefnoiseRMS, engine);
413 theSiDigitalConverter->convert(detAmpl, gainHandle, detID), digis, detID, noiseHandle, thresholdHandle);
416 if (iAssociationInfoByChannel !=
418 for (
const auto& iDigi : digis) {
419 auto& associationInfoByChannel = iAssociationInfoByChannel->second;
420 const std::vector<AssociationInfo>& associationInfo = associationInfoByChannel[iDigi.channel()];
424 float totalSimADC = 0;
425 for (
const auto& iAssociationInfo : associationInfo)
426 totalSimADC += iAssociationInfo.contributionToADC;
428 for (
const auto& iAssociationInfo : associationInfo) {
432 iAssociationInfo.trackID,
433 iAssociationInfo.simHitGlobalIndex,
434 iAssociationInfo.tofBin,
435 iAssociationInfo.eventID,
436 iAssociationInfo.contributionToADC / totalSimADC));
440 outdigi.
data = digis;
468 std::vector<float> noiseRMSv;
470 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
474 if (!badChannels[
strip])
480 while (RefStrip < numStrips &&
481 badChannels[RefStrip]) {
484 if (RefStrip < numStrips) {
487 if (!badChannels[
strip])
488 noiseRMSv[
strip] = noiseRMS;
504 }
else if (SubDet == 4) {
506 }
else if (SubDet == 5) {
508 }
else if (SubDet == 6) {
518 std::vector<float> vPeds;
520 vPeds.insert(vPeds.begin(), numStrips, 0.);
524 if (!badChannels[
strip])
529 if (!badChannels[
strip])
544 if (iAssociationInfoByChannel !=
549 for (
size_t channel = 0; channel < rawdigis.size(); ++channel) {
550 auto& associationInfoByChannel = iAssociationInfoByChannel->second;
551 const auto iAssociationInfo = associationInfoByChannel.find(channel);
552 if (iAssociationInfo == associationInfoByChannel.end())
554 const std::vector<AssociationInfo>& associationInfo = iAssociationInfo->second;
558 float totalSimADC = 0;
559 for (
const auto& iAssociationInfo : associationInfo)
560 totalSimADC += iAssociationInfo.contributionToADC;
562 for (
const auto& iAssociationInfo : associationInfo) {
566 iAssociationInfo.trackID,
567 iAssociationInfo.simHitGlobalIndex,
568 iAssociationInfo.tofBin,
569 iAssociationInfo.eventID,
570 iAssociationInfo.contributionToADC / totalSimADC));
575 outrawdigi.
data = rawdigis;
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
const std::unique_ptr< SiPileUpSignals > theSiPileUpSignals
void digitize(edm::DetSet< SiStripDigi > &outDigis, edm::DetSet< SiStripRawDigi > &outRawDigis, edm::DetSet< StripDigiSimLink > &outLink, const StripGeomDetUnit *stripdet, edm::ESHandle< SiStripGain > &, edm::ESHandle< SiStripThreshold > &, edm::ESHandle< SiStripNoises > &, edm::ESHandle< SiStripPedestals > &, std::vector< std::pair< int, std::bitset< 6 >>> &theAffectedAPVvector, CLHEP::HepRandomEngine *)
edm::ESHandle< SiStripLorentzAngle > lorentzAngleHandle
void push_back(const T &t)
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
constexpr uint32_t rawId() const
get the raw id
void initializeEvent(const edm::EventSetup &iSetup)
const double theElectronPerADC
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
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
const std::unique_ptr< SiStripFedZeroSuppression > theSiZeroSuppress
static float getStripGain(const uint16_t &strip, const SiStripApvGain::Range &range)
edm::FileInPath APVProbabilityFile
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
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
const bool APVSaturationFromHIP
const ParticleDataTable * pdt
data decode(const unsigned int &value) const
const bool CommonModeNoise
~SiStripDigitizerAlgorithm()
const SiStripApvGain::Range getRange(uint32_t detID) const
double APVSaturationProb_