36 #include "CLHEP/Random/RandFlat.h" 70 typedef std::pair<uint16_t, Amplitude>
RawDigi;
85 const SignalMapType*
getSignal(uint32_t detID)
const {
90 return &where->second;
96 typedef std::multimap<uint32_t, std::bitset<6>>
APVMap;
141 bool operator()(RawDigi
i, RawDigi j)
const {
return i.first < j.first; }
151 theThreshold(ps.getParameter<double>(
"NoiseSigmaThreshold")),
161 apv_rate_(ps.getParameter<double>(
"apv_rate")),
162 apv_mVPerQ_(ps.getParameter<double>(
"apv_mVPerQ")),
175 producer.
produces<
bool>(SiStripDigiCollectionDM_ +
"SimulatedAPVDynamicGain");
188 throw cms::Exception(
"Psiguration") <<
"SiStripDigitizer requires the RandomNumberGeneratorService\n" 189 "which is not present in the psiguration file. You must add the service\n" 190 "in the configuration file or remove the modules that require it.";
202 unsigned int detId = (*iu)->geographicalId().rawId();
204 unsigned int isub = idet.
subdetId();
208 assert(stripdet !=
nullptr);
226 badChannels.insert(badChannels.begin(), numStrips,
false);
228 hipChannels.insert(hipChannels.begin(), numStrips,
false);
233 badChannels[
strip] =
true;
249 for (; DSViter != input->end(); DSViter++) {
251 LogDebug(
"PreMixingSiStripWorker") <<
"Processing DetID " << DSViter->id;
255 LocalMap.
reserve((DSViter->data).size());
256 LocalMap.insert(LocalMap.end(), (DSViter->data).
begin(), (DSViter->data).
end());
278 LogDebug(
"PreMixingSiStripWorker") <<
"\n===============> adding pileups from event " << pep.
principal().
id()
287 const auto&
input = *inputHandle;
293 for (; DSViter !=
input.end(); DSViter++) {
295 LogDebug(
"PreMixingSiStripWorker") <<
"Pileups: Processing DetID " << DSViter->id;
300 SiGlobalIndex::const_iterator itest;
306 LocalMap = itest->second;
309 LocalMap.insert(LocalMap.end(), (DSViter->data).
begin(), (DSViter->data).
end());
316 LocalMap.reserve((DSViter->data).size());
317 LocalMap.insert(LocalMap.end(), (DSViter->data).
begin(), (DSViter->data).
end());
327 if (inputAPVHandle.
isValid()) {
328 const auto& APVinput = inputAPVHandle;
330 std::vector<std::pair<int, std::bitset<6>>>::const_iterator
entry = APVinput->begin();
331 for (; entry != APVinput->end(); entry++) {
341 std::vector<PileupSummaryInfo>
const& ps,
361 if (simulateAPVInThisEvent) {
364 const auto it = std::find_if(
367 nTruePU = it->getTrueNumInteractions();
369 edm::LogWarning(
"PreMixingSiStripWorker") <<
"Could not find PileupSummaryInfo for current bunch crossing";
370 nTruePU =
std::begin(ps)->getTrueNumInteractions();
374 std::map<int, std::bitset<6>> DeadAPVList;
398 uint32_t detID = IDet->first;
406 OneDetectorMap::const_iterator iLocal = LocalMap.begin();
407 for (; iLocal != LocalMap.end(); ++iLocal) {
408 uint16_t currentStrip = iLocal->strip();
409 float signal =
float(iLocal->adc());
410 if (iLocal->adc() == 1022)
412 if (iLocal->adc() == 1023)
417 float ReSignal = signal * signal / 9.0;
419 RawDigi NewRawDigi = std::make_pair(currentStrip, ReSignal);
421 LocalRawMap.push_back(NewRawDigi);
430 int NumberOfBxBetweenHIPandEvent = 1
e3;
435 bool HasAtleastOneAffectedAPV =
false;
436 while (!HasAtleastOneAffectedAPV) {
437 for (
int bx = floor(300.0 / 25.0); bx > 0; bx--) {
438 float temp = CLHEP::RandFlat::shoot(engine) < 0.5 ? 1 : 0;
439 if (temp == 1 && bx < NumberOfBxBetweenHIPandEvent) {
440 NumberOfBxBetweenHIPandEvent = bx;
441 HasAtleastOneAffectedAPV =
true;
446 APVMap::const_iterator iAPVchk;
447 uint32_t formerID = 0;
449 std::bitset<6> NewAPVBits;
452 currentID = iAPV->first;
454 if (currentID == formerID) {
455 for (
int ibit = 0; ibit < 6; ++ibit) {
456 NewAPVBits[ibit] = NewAPVBits[ibit] || (iAPV->second)[ibit];
459 DeadAPVList[currentID] = NewAPVBits;
461 formerID = currentID;
462 NewAPVBits = iAPV->second;
467 DeadAPVList[currentID] = NewAPVBits;
476 std::vector<edm::DetSet<SiStripDigi>> vSiStripDigi;
486 uint32_t detID = IDet->first;
494 int formerStrip = -1;
500 OneDetectorRawMap::const_iterator iLocalchk;
501 OneDetectorRawMap::const_iterator iLocal = LocalMap.begin();
502 for (; iLocal != LocalMap.end(); ++iLocal) {
503 currentStrip = iLocal->first;
505 if (currentStrip == formerStrip) {
507 ADCSum += iLocal->second;
509 if (formerStrip != -1) {
510 Signals.insert(std::make_pair(formerStrip, ADCSum));
513 formerStrip = currentStrip;
514 ADCSum = iLocal->second;
518 if ((++iLocalchk) == LocalMap.end()) {
519 Signals.insert(std::make_pair(formerStrip, ADCSum));
523 signals_.insert(std::make_pair(detID, Signals));
531 if (sgd !=
nullptr) {
542 std::vector<float> detAmpl(numStrips, 0.);
544 for (
const auto& amp : *theSignal) {
545 detAmpl[amp.first] = amp.second;
553 if (badChannels[
strip])
557 if (simulateAPVInThisEvent) {
562 float detSet_z = fabs(globalPos.
z());
563 float detSet_r = globalPos.
perp();
568 if (detAmpl[
strip] > 0) {
573 double baselineV = 0;
575 baselineV = apvSimulationParametersHandle->
sampleTIB(tTopo->
tibLayer(detID), detSet_z, nTruePU, engine);
577 baselineV = apvSimulationParametersHandle->
sampleTOB(tTopo->
tobLayer(detID), detSet_z, nTruePU, engine);
579 baselineV = apvSimulationParametersHandle->
sampleTID(tTopo->
tidWheel(detID), detSet_r, nTruePU, engine);
581 baselineV = apvSimulationParametersHandle->
sampleTEC(tTopo->
tecWheel(detID), detSet_r, nTruePU, engine);
587 double outputChargeInADC = 0;
590 double baselineQ = -1.0 * rate *
log(2 * maxResponse / (baselineV + maxResponse) - 1);
593 double newStripCharge = baselineQ + stripCharge;
596 double signalV = 2 * maxResponse / (1 +
exp(-1.0 * newStripCharge / rate)) - maxResponse;
597 double gain = signalV - baselineV;
605 detAmpl[
strip] = outputChargeInADC;
611 std::bitset<6>& bs = DeadAPVList[detID];
617 1 - NumberOfBxBetweenHIPandEvent / floor(300.0 / 25.0);
618 float randomX = CLHEP::RandFlat::shoot(engine);
619 float scalingValue = (randomX - Shift) * 10.0 / 7.0 - 3.0 / 7.0;
622 if (!badChannels[
strip] && bs[
strip / 128] == 1) {
623 detAmpl[
strip] *= scalingValue > 0 ? scalingValue : 0.0;
652 size_t firstChannelWithSignal = 0;
653 size_t lastChannelWithSignal = numStrips;
656 std::vector<float> noiseRMSv;
658 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
660 if (!badChannels[
strip]) {
661 float gainValue = gainHandle->
getStripGain(strip, detGainRange);
667 int RefStrip =
int(numStrips / 2.);
668 while (RefStrip < numStrips &&
669 badChannels[RefStrip]) {
672 if (RefStrip < numStrips) {
673 float RefgainValue = gainHandle->
getStripGain(RefStrip, detGainRange);
677 detAmpl, firstChannelWithSignal, lastChannelWithSignal, numStrips, RefnoiseRMS, engine);
683 theSiDigitalConverter->convert(detAmpl, gainHandle, detID), digis, detID, noiseHandle, thresholdHandle);
688 vSiStripDigi.push_back(SSD);
695 edm::LogInfo(
"PreMixingSiStripWorker") <<
"total # Merged strips: " << vSiStripDigi.size();
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
int bunchCrossing() const
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
std::map< unsigned int, std::vector< bool > > allBadChannels
T getParameter(std::string const &) const
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::ProducerBase &producer, edm::ConsumesCollector &&iC)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
float sampleTIB(layerid layer, float z, float pu, CLHEP::HepRandomEngine *engine) const
unsigned int tibLayer(const DetId &id) const
std::unique_ptr< SiTrivialDigitalConverter > theSiDigitalConverter
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
std::map< unsigned int, size_t > lastChannelsWithSignal
std::map< uint32_t, OneDetectorRawMap > SiGlobalRawIndex
std::vector< unsigned int >::const_iterator ContainerIterator
float sampleTID(layerid wheel, float r, float pu, CLHEP::HepRandomEngine *engine) const
edm::ESHandle< TrackerGeometry > pDD
std::map< uint32_t, OneDetectorMap > SiGlobalIndex
EventID const & id() const
constexpr uint32_t rawId() const
get the raw id
void DMinitializeDetUnit(StripGeomDetUnit const *det, const edm::EventSetup &iSetup)
unsigned int tidWheel(const DetId &id) const
SiGlobalIndex SiHitStorage_
const int getBunchCrossing() const
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
std::multimap< uint32_t, std::bitset< 6 > > APVMap
const Plane & surface() const
The nominal surface of the GeomDet.
float sampleTOB(layerid layer, float z, float pu, CLHEP::HepRandomEngine *engine) const
static std::string const input
const double fracOfEventsToSimAPV_
edm::InputTag SistripLabelSig_
edm::EventPrincipal const & principal()
static float getNoise(uint16_t strip, const Range &range)
Container::value_type value_type
edm::InputTag SiStripPileInputTag_
virtual LocalPoint localPosition(float strip) const =0
static float getStripGain(const uint16_t &strip, const SiStripApvGain::Range &range)
std::vector< SiStripDigi > OneDetectorMap
std::string SiStripDigiCollectionDM_
const uint16_t & strip() const
bool includeAPVSimulation_
const SignalMapType * getSignal(uint32_t detID) const
std::unique_ptr< SiGaussianTailNoiseAdder > theSiNoiseAdder
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.
bool APVSaturationFromHIP_
~PreMixingSiStripWorker() override=default
std::string SistripAPVListDM_
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
edm::InputTag SiStripAPVPileInputTag_
std::unique_ptr< SiStripFedZeroSuppression > theSiZeroSuppress
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
void put(edm::Event &e, edm::EventSetup const &iSetup, std::vector< PileupSummaryInfo > const &ps, int bs) override
bool operator()(RawDigi i, RawDigi j) const
const double apv_fCPerElectron_
Point3DBase< float, LocalTag > Local3DPoint
bool operator()(SiStripDigi i, SiStripDigi j) const
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
SiGlobalRawIndex SiRawDigis_
unsigned short firstStrip
APVMap theAffectedAPVmap_
std::pair< uint16_t, Amplitude > RawDigi
const Range getRange(const uint32_t detID) const
const Range getRange(const uint32_t detID) const
std::pair< ContainerIterator, ContainerIterator > Range
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
std::map< unsigned int, size_t > firstChannelsWithSignal
StreamID streamID() const
const double apv_maxResponse_
void addPileups(PileUpEventPrincipal const &pep, edm::EventSetup const &es) override
std::vector< RawDigi > OneDetectorRawMap
std::pair< ContainerIterator, ContainerIterator > Range
edm::InputTag SistripAPVLabelSig_
collection_type::const_iterator const_iterator
unsigned int tecWheel(const DetId &id) const
#define DEFINE_PREMIXING_WORKER(TYPE)
float sampleTEC(layerid wheel, float r, float pu, CLHEP::HepRandomEngine *engine) const
std::map< uint32_t, SignalMapType > signalMaps
std::map< int, Amplitude > SignalMapType
data decode(const unsigned int &value) const
unsigned int tobLayer(const DetId &id) const
const SiStripApvGain::Range getRange(uint32_t detID) const
SiDigitalConverter::DigitalVecType DigitalVecType