37 #include "CLHEP/Random/RandFlat.h" 80 typedef std::pair<uint16_t, Amplitude>
RawDigi;
100 return &where->second;
106 typedef std::multimap<uint32_t, std::bitset<6>>
APVMap;
162 peakMode(ps.getParameter<
bool>(
"APVpeakmode")),
163 theThreshold(ps.getParameter<double>(
"NoiseSigmaThreshold")),
164 theElectronPerADC(ps.getParameter<double>(peakMode ?
"electronPerAdcPeak" :
"electronPerAdcDec")),
165 APVSaturationFromHIP_(ps.getParameter<
bool>(
"APVSaturationFromHIP")),
166 theFedAlgo(ps.getParameter<
int>(
"FedAlgorithm_PM")),
169 includeAPVSimulation_(ps.getParameter<
bool>(
"includeAPVSimulation")),
170 fracOfEventsToSimAPV_(ps.getParameter<double>(
"fracOfEventsToSimAPV")),
171 apv_maxResponse_(ps.getParameter<double>(
"apv_maxResponse")),
172 apv_rate_(ps.getParameter<double>(
"apv_rate")),
173 apv_mVPerQ_(ps.getParameter<double>(
"apv_mVPerQ")),
174 apv_fCPerElectron_(ps.getParameter<double>(
"apvfCPerElectron"))
204 throw cms::Exception(
"Psiguration") <<
"SiStripDigitizer requires the RandomNumberGeneratorService\n" 205 "which is not present in the psiguration file. You must add the service\n" 206 "in the configuration file or remove the modules that require it.";
218 unsigned int detId = (*iu)->geographicalId().rawId();
220 unsigned int isub = idet.
subdetId();
224 assert(stripdet !=
nullptr);
241 badChannels.insert(badChannels.begin(), numStrips,
false);
243 hipChannels.insert(hipChannels.begin(), numStrips,
false);
248 badChannels[
strip] =
true;
264 for (; DSViter !=
input->end(); DSViter++) {
266 LogDebug(
"PreMixingSiStripWorker") <<
"Processing DetID " << DSViter->id;
270 LocalMap.
reserve((DSViter->data).size());
271 LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).
end());
293 LogDebug(
"PreMixingSiStripWorker") <<
"\n===============> adding pileups from event " << pep.
principal().
id()
302 const auto&
input = *inputHandle;
308 for (; DSViter !=
input.end(); DSViter++) {
310 LogDebug(
"PreMixingSiStripWorker") <<
"Pileups: Processing DetID " << DSViter->id;
315 SiGlobalIndex::const_iterator itest;
321 LocalMap = itest->second;
324 LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).
end());
331 LocalMap.reserve((DSViter->data).size());
332 LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).
end());
342 if (inputAPVHandle.
isValid()) {
343 const auto& APVinput = inputAPVHandle;
345 std::vector<std::pair<int, std::bitset<6>>>::const_iterator
entry = APVinput->begin();
356 std::vector<PileupSummaryInfo>
const& ps,
367 CLHEP::HepRandomEngine* engine = &rng->
getEngine(
e.streamID());
371 if (simulateAPVInThisEvent) {
374 const auto it = std::find_if(
376 if (it != std::begin(ps)) {
377 nTruePU = it->getTrueNumInteractions();
379 edm::LogWarning(
"PreMixingSiStripWorker") <<
"Could not find PileupSummaryInfo for current bunch crossing";
380 nTruePU = std::begin(ps)->getTrueNumInteractions();
384 std::map<int, std::bitset<6>> DeadAPVList;
405 uint32_t detID = IDet->first;
407 auto const& LocalMap = IDet->second;
412 localRawMap.reserve(LocalMap.size());
413 for (
auto const& iLocal : LocalMap) {
414 uint16_t currentStrip = iLocal.strip();
415 float signal =
float(iLocal.adc());
416 if (iLocal.adc() == 1022)
418 if (iLocal.adc() == 1023)
422 constexpr
float inv9 = 1.f / 9.0f;
423 float ReSignal = signal * signal * inv9;
427 localRawMap.emplace_back(currentStrip, ReSignal);
433 int NumberOfBxBetweenHIPandEvent = 1
e3;
438 bool HasAtleastOneAffectedAPV =
false;
439 while (!HasAtleastOneAffectedAPV) {
440 for (
int bx = floor(300.0 / 25.0);
bx > 0;
bx--) {
441 float temp = CLHEP::RandFlat::shoot(engine) < 0.5 ? 1 : 0;
442 if (
temp == 1 &&
bx < NumberOfBxBetweenHIPandEvent) {
443 NumberOfBxBetweenHIPandEvent =
bx;
444 HasAtleastOneAffectedAPV =
true;
449 APVMap::const_iterator iAPVchk;
450 uint32_t formerID = 0;
452 std::bitset<6> NewAPVBits;
455 currentID = iAPV->first;
457 if (currentID == formerID) {
458 for (
int ibit = 0; ibit < 6; ++ibit) {
459 NewAPVBits[ibit] = NewAPVBits[ibit] || (iAPV->second)[ibit];
462 DeadAPVList[currentID] = NewAPVBits;
464 formerID = currentID;
465 NewAPVBits = iAPV->second;
470 DeadAPVList[currentID] = NewAPVBits;
479 std::vector<edm::DetSet<SiStripDigi>> vSiStripDigi;
489 uint32_t detID = IDet.first;
494 auto const& LocalMap = IDet.second;
497 lSignals.reserve(
std::min(LocalMap.size(), 512ul));
500 int formerStrip = -1;
506 OneDetectorRawMap::const_iterator iLocalchk;
507 OneDetectorRawMap::const_iterator iLocal = LocalMap.begin();
508 for (; iLocal != LocalMap.end(); ++iLocal) {
509 currentStrip = iLocal->first;
511 if (currentStrip == formerStrip) {
513 ADCSum += iLocal->second;
515 if (formerStrip != -1) {
516 lSignals.emplace_back(formerStrip, ADCSum);
519 formerStrip = currentStrip;
520 ADCSum = iLocal->second;
524 if ((++iLocalchk) == LocalMap.end()) {
525 lSignals.emplace_back(formerStrip, ADCSum);
535 if (sgd !=
nullptr) {
546 std::vector<float> detAmpl(numStrips, 0.);
548 for (
const auto& amp : *lSignal) {
549 detAmpl[amp.first] = amp.second;
557 if (badChannels[
strip])
561 if (simulateAPVInThisEvent) {
566 float detSet_z = fabs(globalPos.
z());
567 float detSet_r = globalPos.
perp();
572 if (detAmpl[
strip] > 0) {
577 double baselineV = 0;
579 baselineV = apvSimulationParameters->
sampleTIB(tTopo->
tibLayer(detID), detSet_z, nTruePU, engine);
581 baselineV = apvSimulationParameters->
sampleTOB(tTopo->
tobLayer(detID), detSet_z, nTruePU, engine);
583 baselineV = apvSimulationParameters->
sampleTID(tTopo->
tidWheel(detID), detSet_r, nTruePU, engine);
585 baselineV = apvSimulationParameters->
sampleTEC(tTopo->
tecWheel(detID), detSet_r, nTruePU, engine);
591 double outputChargeInADC = 0;
594 double baselineQ = -1.0 *
rate *
log(2 * maxResponse / (baselineV + maxResponse) - 1);
597 double newStripCharge = baselineQ + stripCharge;
600 double signalV = 2 * maxResponse / (1 +
exp(-1.0 * newStripCharge /
rate)) - maxResponse;
601 double gain = signalV - baselineV;
609 detAmpl[
strip] = outputChargeInADC;
615 std::bitset<6>&
bs = DeadAPVList[detID];
621 1 - NumberOfBxBetweenHIPandEvent / floor(300.0 / 25.0);
622 float randomX = CLHEP::RandFlat::shoot(engine);
623 float scalingValue = (randomX - Shift) * 10.0 / 7.0 - 3.0 / 7.0;
627 detAmpl[
strip] *= scalingValue > 0 ? scalingValue : 0.0;
656 size_t firstChannelWithSignal = 0;
657 size_t lastChannelWithSignal = numStrips;
660 std::vector<float> noiseRMSv;
662 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
664 if (!badChannels[
strip]) {
665 float gainValue =
gain.getStripGain(
strip, detGainRange);
671 int RefStrip =
int(numStrips / 2.);
672 while (RefStrip < numStrips &&
673 badChannels[RefStrip]) {
676 if (RefStrip < numStrips) {
677 float RefgainValue =
gain.getStripGain(RefStrip, detGainRange);
681 detAmpl, firstChannelWithSignal, lastChannelWithSignal, numStrips, RefnoiseRMS, engine);
692 LogDebug(
"PreMixingSiStripWorker") << detID <<
" " <<
data.size() <<
' ' << SSD.
data.size();
695 vSiStripDigi.push_back(SSD);
702 edm::LogInfo(
"PreMixingSiStripWorker") <<
"total # Merged strips: " << vSiStripDigi.size();
bool operator()(SiStripDigi i, SiStripDigi j) const
std::map< unsigned int, std::vector< bool > > allBadChannels
static constexpr auto TEC
void addSignals(edm::Event const &e, edm::EventSetup const &es) override
std::vector< SiStripDigi > DigitalVecType
std::map< unsigned int, std::vector< bool > > allHIPChannels
PreMixingSiStripWorker(const edm::ParameterSet &ps, edm::ProducesCollector, edm::ConsumesCollector &&iC)
T getParameter(std::string const &) const
unsigned int tobLayer(const DetId &id) const
float sampleTOB(layerid layer, float z, float pu, CLHEP::HepRandomEngine *engine) const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
std::unique_ptr< SiTrivialDigitalConverter > theSiDigitalConverter
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
std::map< unsigned int, size_t > lastChannelsWithSignal
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > const pDDToken_
std::vector< unsigned int >::const_iterator ContainerIterator
unsigned int tidWheel(const DetId &id) const
unsigned int tecWheel(const DetId &id) const
std::map< uint32_t, OneDetectorMap > SiGlobalIndex
void DMinitializeDetUnit(StripGeomDetUnit const *det, const edm::EventSetup &iSetup)
float sampleTIB(layerid layer, float z, float pu, CLHEP::HepRandomEngine *engine) const
edm::ESGetToken< SiStripNoises, SiStripNoisesRcd > const noiseToken_
int bunchCrossing() const
SiGlobalIndex SiHitStorage_
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
bool operator()(RawDigi i, RawDigi j) const
const Range getRange(const uint32_t detID) const
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
std::multimap< uint32_t, std::bitset< 6 > > APVMap
static std::string const input
const double fracOfEventsToSimAPV_
edm::InputTag SistripLabelSig_
edm::EventPrincipal const & principal()
Container::value_type value_type
edm::InputTag SiStripPileInputTag_
std::vector< SiStripDigi > OneDetectorMap
std::string SiStripDigiCollectionDM_
bool includeAPVSimulation_
std::unique_ptr< SiGaussianTailNoiseAdder > theSiNoiseAdder
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
std::pair< ContainerIterator, ContainerIterator > Range
bool APVSaturationFromHIP_
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
~PreMixingSiStripWorker() override=default
std::string SistripAPVListDM_
std::vector< std::pair< uint32_t, OneDetectorRawMap > > SiGlobalRawIndex
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
static constexpr auto TOB
edm::InputTag SiStripAPVPileInputTag_
DetId geographicalId() const
The label of this GeomDet.
std::unique_ptr< SiStripFedZeroSuppression > theSiZeroSuppress
void put(edm::Event &e, edm::EventSetup const &iSetup, std::vector< PileupSummaryInfo > const &ps, int bs) override
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
const double apv_fCPerElectron_
Log< level::Info, false > LogInfo
edm::ESGetToken< SiStripBadStrip, SiStripBadChannelRcd > const deadChannelToken_
const TrackerGeometry * pDD
float sampleTID(layerid wheel, float r, float pu, CLHEP::HepRandomEngine *engine) const
static constexpr auto TIB
const Plane & surface() const
The nominal surface of the GeomDet.
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
SiGlobalRawIndex SiRawDigis_
constexpr uint32_t rawId() const
get the raw id
const int getBunchCrossing() const
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
APVMap theAffectedAPVmap_
SignalMapType const * getSignal(uint32_t detID) const
std::pair< uint16_t, Amplitude > RawDigi
char data[epos_bytes_allocation]
std::pair< ContainerIterator, ContainerIterator > Range
std::map< unsigned int, size_t > firstChannelsWithSignal
const double apv_maxResponse_
data decode(const unsigned int &value) const
virtual LocalPoint localPosition(float strip) const =0
void addPileups(PileUpEventPrincipal const &pep, edm::EventSetup const &es) override
unsigned int tibLayer(const DetId &id) const
std::vector< RawDigi > OneDetectorRawMap
Log< level::Warning, false > LogWarning
std::pair< ContainerIterator, ContainerIterator > Range
edm::InputTag SistripAPVLabelSig_
collection_type::const_iterator const_iterator
EventID const & id() const
float sampleTEC(layerid wheel, float r, float pu, CLHEP::HepRandomEngine *engine) const
static constexpr auto TID
#define DEFINE_PREMIXING_WORKER(TYPE)
std::map< uint32_t, SignalMapType > signalMaps
edm::ESGetToken< SiStripGain, SiStripGainSimRcd > const gainToken_
edm::ESGetToken< SiStripThreshold, SiStripThresholdRcd > const thresholdToken_
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
std::vector< std::pair< int, Amplitude > > SignalMapType
edm::ESGetToken< SiStripApvSimulationParameters, SiStripApvSimulationParametersRcd > apvSimulationParametersToken_
SiDigitalConverter::DigitalVecType DigitalVecType
Point3DBase< float, LocalTag > Local3DPoint