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;
408 uint32_t detID = IDet->first;
416 OneDetectorMap::const_iterator iLocal = LocalMap.begin();
417 for (; iLocal != LocalMap.end(); ++iLocal) {
418 uint16_t currentStrip = iLocal->strip();
419 float signal =
float(iLocal->adc());
420 if (iLocal->adc() == 1022)
422 if (iLocal->adc() == 1023)
427 float ReSignal = signal * signal / 9.0;
429 RawDigi NewRawDigi = std::make_pair(currentStrip, ReSignal);
431 LocalRawMap.push_back(NewRawDigi);
440 int NumberOfBxBetweenHIPandEvent = 1
e3;
445 bool HasAtleastOneAffectedAPV =
false;
446 while (!HasAtleastOneAffectedAPV) {
447 for (
int bx = floor(300.0 / 25.0);
bx > 0;
bx--) {
448 float temp = CLHEP::RandFlat::shoot(engine) < 0.5 ? 1 : 0;
449 if (
temp == 1 &&
bx < NumberOfBxBetweenHIPandEvent) {
450 NumberOfBxBetweenHIPandEvent =
bx;
451 HasAtleastOneAffectedAPV =
true;
456 APVMap::const_iterator iAPVchk;
457 uint32_t formerID = 0;
459 std::bitset<6> NewAPVBits;
462 currentID = iAPV->first;
464 if (currentID == formerID) {
465 for (
int ibit = 0; ibit < 6; ++ibit) {
466 NewAPVBits[ibit] = NewAPVBits[ibit] || (iAPV->second)[ibit];
469 DeadAPVList[currentID] = NewAPVBits;
471 formerID = currentID;
472 NewAPVBits = iAPV->second;
477 DeadAPVList[currentID] = NewAPVBits;
486 std::vector<edm::DetSet<SiStripDigi>> vSiStripDigi;
496 uint32_t detID = IDet->first;
504 int formerStrip = -1;
510 OneDetectorRawMap::const_iterator iLocalchk;
511 OneDetectorRawMap::const_iterator iLocal = LocalMap.begin();
512 for (; iLocal != LocalMap.end(); ++iLocal) {
513 currentStrip = iLocal->first;
515 if (currentStrip == formerStrip) {
517 ADCSum += iLocal->second;
519 if (formerStrip != -1) {
520 Signals.insert(std::make_pair(formerStrip, ADCSum));
523 formerStrip = currentStrip;
524 ADCSum = iLocal->second;
528 if ((++iLocalchk) == LocalMap.end()) {
529 Signals.insert(std::make_pair(formerStrip, ADCSum));
533 signals_.insert(std::make_pair(detID, Signals));
541 if (sgd !=
nullptr) {
552 std::vector<float> detAmpl(numStrips, 0.);
554 for (
const auto& amp : *theSignal) {
555 detAmpl[amp.first] = amp.second;
563 if (badChannels[
strip])
567 if (simulateAPVInThisEvent) {
572 float detSet_z = fabs(globalPos.
z());
573 float detSet_r = globalPos.
perp();
578 if (detAmpl[
strip] > 0) {
583 double baselineV = 0;
585 baselineV = apvSimulationParameters->
sampleTIB(tTopo->
tibLayer(detID), detSet_z, nTruePU, engine);
587 baselineV = apvSimulationParameters->
sampleTOB(tTopo->
tobLayer(detID), detSet_z, nTruePU, engine);
589 baselineV = apvSimulationParameters->
sampleTID(tTopo->
tidWheel(detID), detSet_r, nTruePU, engine);
591 baselineV = apvSimulationParameters->
sampleTEC(tTopo->
tecWheel(detID), detSet_r, nTruePU, engine);
597 double outputChargeInADC = 0;
600 double baselineQ = -1.0 *
rate *
log(2 * maxResponse / (baselineV + maxResponse) - 1);
603 double newStripCharge = baselineQ + stripCharge;
606 double signalV = 2 * maxResponse / (1 +
exp(-1.0 * newStripCharge /
rate)) - maxResponse;
607 double gain = signalV - baselineV;
615 detAmpl[
strip] = outputChargeInADC;
621 std::bitset<6>&
bs = DeadAPVList[detID];
627 1 - NumberOfBxBetweenHIPandEvent / floor(300.0 / 25.0);
628 float randomX = CLHEP::RandFlat::shoot(engine);
629 float scalingValue = (randomX - Shift) * 10.0 / 7.0 - 3.0 / 7.0;
633 detAmpl[
strip] *= scalingValue > 0 ? scalingValue : 0.0;
662 size_t firstChannelWithSignal = 0;
663 size_t lastChannelWithSignal = numStrips;
666 std::vector<float> noiseRMSv;
668 noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
670 if (!badChannels[
strip]) {
671 float gainValue =
gain.getStripGain(
strip, detGainRange);
677 int RefStrip =
int(numStrips / 2.);
678 while (RefStrip < numStrips &&
679 badChannels[RefStrip]) {
682 if (RefStrip < numStrips) {
683 float RefgainValue =
gain.getStripGain(RefStrip, detGainRange);
687 detAmpl, firstChannelWithSignal, lastChannelWithSignal, numStrips, RefnoiseRMS, engine);
698 vSiStripDigi.push_back(SSD);
705 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
std::map< uint32_t, OneDetectorRawMap > SiGlobalRawIndex
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_
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_
const SignalMapType * getSignal(uint32_t detID) const
constexpr uint32_t rawId() const
get the raw id
const int getBunchCrossing() const
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
APVMap theAffectedAPVmap_
std::pair< uint16_t, Amplitude > RawDigi
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_
std::map< int, Amplitude > SignalMapType
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
edm::ESGetToken< SiStripApvSimulationParameters, SiStripApvSimulationParametersRcd > apvSimulationParametersToken_
SiDigitalConverter::DigitalVecType DigitalVecType
Point3DBase< float, LocalTag > Local3DPoint