diff --git a/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc b/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc index 4ad950a92df0a..98732d6d04003 100644 --- a/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc +++ b/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc @@ -94,6 +94,7 @@ PreMixingSiPixelWorker::PreMixingSiPixelWorker(const edm::ParameterSet& ps, PixelDigiPToken_ = iC.consumes>(pixeldigi_collectionPile_); producer.produces>(PixelDigiCollectionDM_); + producer.produces(PixelDigiCollectionDM_); // clear local storage for this event SiHitStorage_.clear(); @@ -280,6 +281,14 @@ void PreMixingSiPixelWorker::put(edm::Event& e, iSetup.get().get(tTopoHand); const TrackerTopology* tTopo = tTopoHand.product(); + if (digitizer_.killBadFEDChannels()) { + std::unique_ptr PixelFEDChannelCollection_ = digitizer_.chooseScenario(ps, engine); + if (PixelFEDChannelCollection_ == nullptr) { + throw cms::Exception("NullPointerError") << "PixelFEDChannelCollection not set in chooseScenario function.\n"; + } + e.put(std::move(PixelFEDChannelCollection_), PixelDigiCollectionDM_); + } + for (const auto& iu : pDD->detUnits()) { if (iu->type().isTrackerPixel()) { edm::DetSet collector(iu->geographicalId().rawId()); diff --git a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc index ebdfa7fc2e6b7..1aebd88f8dba6 100644 --- a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc +++ b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc @@ -895,6 +895,53 @@ void SiPixelDigitizerAlgorithm::calculateInstlumiFactor(const std::vector SiPixelDigitizerAlgorithm::chooseScenario( + const std::vector& ps, CLHEP::HepRandomEngine* engine) { + std::unique_ptr PixelFEDChannelCollection_ = nullptr; + pixelEfficiencies_.PixelFEDChannelCollection_ = nullptr; + + std::vector bunchCrossing; + std::vector TrueInteractionList; + + for (unsigned int i = 0; i < ps.size(); i++) { + bunchCrossing.push_back(ps[i].getBunchCrossing()); + TrueInteractionList.push_back(ps[i].getTrueNumInteractions()); + } + + int pui = 0, p = 0; + std::vector::const_iterator pu; + std::vector::const_iterator pu0 = bunchCrossing.end(); + + for (pu = bunchCrossing.begin(); pu != bunchCrossing.end(); ++pu) { + if (*pu == 0) { + pu0 = pu; + p = pui; + } + pui++; + } + + if (pu0 != bunchCrossing.end()) { + unsigned int PUBin = TrueInteractionList.at(p); // case delta PU=1, fix me + const auto& theProbabilitiesPerScenario = scenarioProbabilityHandle->getProbabilities(PUBin); + std::vector probabilities; + probabilities.reserve(theProbabilitiesPerScenario.size()); + for (auto it = theProbabilitiesPerScenario.begin(); it != theProbabilitiesPerScenario.end(); it++) { + probabilities.push_back(it->second); + } + + CLHEP::RandGeneral randGeneral(*engine, &(probabilities.front()), probabilities.size()); + double x = randGeneral.shoot(); + unsigned int index = x * probabilities.size() - 1; + const std::string& scenario = theProbabilitiesPerScenario.at(index).first; + + PixelFEDChannelCollection_ = std::make_unique(quality_map->at(scenario)); + pixelEfficiencies_.PixelFEDChannelCollection_ = + std::make_unique(quality_map->at(scenario)); + } + + return PixelFEDChannelCollection_; +} + std::unique_ptr SiPixelDigitizerAlgorithm::chooseScenario(PileupMixingContent* puInfo, CLHEP::HepRandomEngine* engine) { //Determine scenario to use for the current event based on pileup information diff --git a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h index 609afb64bf9f9..f7b83e526cf49 100644 --- a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h +++ b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h @@ -77,13 +77,15 @@ class SiPixelDigitizerAlgorithm { CLHEP::HepRandomEngine*); void calculateInstlumiFactor(PileupMixingContent* puInfo); void init_DynIneffDB(const edm::EventSetup&, const unsigned int&); + std::unique_ptr chooseScenario(PileupMixingContent* puInfo, CLHEP::HepRandomEngine*); // for premixing void calculateInstlumiFactor(const std::vector& ps, int bunchSpacing); // TODO: try to remove the duplication of logic... void setSimAccumulator(const std::map >& signalMap); + std::unique_ptr chooseScenario(const std::vector& ps, + CLHEP::HepRandomEngine* engine); - std::unique_ptr chooseScenario(PileupMixingContent* puInfo, CLHEP::HepRandomEngine*); bool killBadFEDChannels() const; typedef std::unordered_map PixelFEDChannelCollectionMap; const PixelFEDChannelCollectionMap* quality_map;