From b3e3dd74cb95b89cb3a4f880107542c88a13ae06 Mon Sep 17 00:00:00 2001 From: mmusich Date: Thu, 29 Aug 2019 18:49:22 +0200 Subject: [PATCH 1/4] first push --- .../plugins/PreMixingSiPixelWorker.cc | 4 ++ .../plugins/SiPixelDigitizer.cc | 9 ++++ .../plugins/SiPixelDigitizerAlgorithm.cc | 52 +++++++++++++++++++ .../plugins/SiPixelDigitizerAlgorithm.h | 9 +++- 4 files changed, 73 insertions(+), 1 deletion(-) diff --git a/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc b/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc index 4ad950a92df0a..fa238ada042a7 100644 --- a/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc +++ b/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc @@ -280,6 +280,10 @@ void PreMixingSiPixelWorker::put(edm::Event& e, iSetup.get().get(tTopoHand); const TrackerTopology* tTopo = tTopoHand.product(); + digitizer_.chooseScenario(ps,engine); + + std::cout << "5: " << (digitizer_.GetPixelFEDChannelCollection_ptr() != nullptr) << std::endl; + for (const auto& iu : pDD->detUnits()) { if (iu->type().isTrackerPixel()) { edm::DetSet collector(iu->geographicalId().rawId()); diff --git a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.cc b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.cc index 8b83acecfa577..5f272cf08783d 100644 --- a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.cc +++ b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.cc @@ -268,6 +268,9 @@ namespace cms { if (_pixeldigialgo->killBadFEDChannels()) { std::unique_ptr PixelFEDChannelCollection_ = _pixeldigialgo->chooseScenario(PileupInfo_.get(), randomEngine_); + + std::cout << __FILE__ << " " << __LINE__ << ": PixelFEDChannelCollection_: " << PixelFEDChannelCollection_.get() << std::endl; + if (PixelFEDChannelCollection_ == nullptr) { throw cms::Exception("NullPointerError") << "PixelFEDChannelCollection not set in chooseScenario function.\n"; } @@ -281,8 +284,14 @@ namespace cms { edm::DetSet collector(iu->geographicalId().rawId()); edm::DetSet linkcollector(iu->geographicalId().rawId()); + std::cout << "3: " << (_pixeldigialgo->GetPixelFEDChannelCollection_ptr() != nullptr) << std::endl; + _pixeldigialgo->digitize( dynamic_cast(iu), collector.data, linkcollector.data, tTopo, randomEngine_); + + std::cout << "4: " << (_pixeldigialgo->GetPixelFEDChannelCollection_ptr() != nullptr) << std::endl; + + if (!collector.data.empty()) { theDigiVector.push_back(std::move(collector)); } diff --git a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc index ebdfa7fc2e6b7..d3b1142d1c3fd 100644 --- a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc +++ b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc @@ -895,6 +895,55 @@ 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 @@ -1730,6 +1779,9 @@ void SiPixelDigitizerAlgorithm::pixel_inefficiency(const PixelEfficiencies& eff, auto pIndexConverter = PixelIndices(numColumns, numRows); std::vector badRocsFromFEDChannels(16, 0); + + std::cout<< __FILE__ << " " << __LINE__ <<": " << eff.PixelFEDChannelCollection_.get() << std::endl; + if (eff.PixelFEDChannelCollection_ != nullptr) { PixelFEDChannelCollection::const_iterator it = eff.PixelFEDChannelCollection_->find(detID); diff --git a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h index 609afb64bf9f9..75ab884367759 100644 --- a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h +++ b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h @@ -77,17 +77,24 @@ 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; + PixelFEDChannelCollection* GetPixelFEDChannelCollection_ptr(){ + return pixelEfficiencies_.PixelFEDChannelCollection_.get(); + } + + private: //Accessing Lorentz angle from DB: edm::ESHandle SiPixelLorentzAngle_; From 0ec9b05a61a8ceb8da14e386196c757acd640dd8 Mon Sep 17 00:00:00 2001 From: mmusich Date: Thu, 29 Aug 2019 20:27:35 +0200 Subject: [PATCH 2/4] produce output PixelFEDChannelCollection --- .../SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc b/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc index fa238ada042a7..e1e8f8690c92f 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(); // clear local storage for this event SiHitStorage_.clear(); @@ -280,7 +281,13 @@ void PreMixingSiPixelWorker::put(edm::Event& e, iSetup.get().get(tTopoHand); const TrackerTopology* tTopo = tTopoHand.product(); - digitizer_.chooseScenario(ps,engine); + 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_)); + } std::cout << "5: " << (digitizer_.GetPixelFEDChannelCollection_ptr() != nullptr) << std::endl; From 1812da21cbc1961f76b3e5be19ae259f62239c2e Mon Sep 17 00:00:00 2001 From: mmusich Date: Thu, 29 Aug 2019 23:18:36 +0200 Subject: [PATCH 3/4] clean-up --- .../SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc | 6 ++---- SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.cc | 9 --------- .../plugins/SiPixelDigitizerAlgorithm.cc | 3 --- .../SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h | 6 ------ 4 files changed, 2 insertions(+), 22 deletions(-) diff --git a/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc b/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc index e1e8f8690c92f..74ffda9991291 100644 --- a/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc +++ b/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc @@ -94,7 +94,7 @@ PreMixingSiPixelWorker::PreMixingSiPixelWorker(const edm::ParameterSet& ps, PixelDigiPToken_ = iC.consumes>(pixeldigi_collectionPile_); producer.produces>(PixelDigiCollectionDM_); - producer.produces(); + producer.produces(PixelDigiCollectionDM_); // clear local storage for this event SiHitStorage_.clear(); @@ -286,11 +286,9 @@ void PreMixingSiPixelWorker::put(edm::Event& e, if (PixelFEDChannelCollection_ == nullptr) { throw cms::Exception("NullPointerError") << "PixelFEDChannelCollection not set in chooseScenario function.\n"; } - e.put(std::move(PixelFEDChannelCollection_)); + e.put(std::move(PixelFEDChannelCollection_), PixelDigiCollectionDM_); } - std::cout << "5: " << (digitizer_.GetPixelFEDChannelCollection_ptr() != nullptr) << std::endl; - for (const auto& iu : pDD->detUnits()) { if (iu->type().isTrackerPixel()) { edm::DetSet collector(iu->geographicalId().rawId()); diff --git a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.cc b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.cc index 5f272cf08783d..8b83acecfa577 100644 --- a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.cc +++ b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.cc @@ -268,9 +268,6 @@ namespace cms { if (_pixeldigialgo->killBadFEDChannels()) { std::unique_ptr PixelFEDChannelCollection_ = _pixeldigialgo->chooseScenario(PileupInfo_.get(), randomEngine_); - - std::cout << __FILE__ << " " << __LINE__ << ": PixelFEDChannelCollection_: " << PixelFEDChannelCollection_.get() << std::endl; - if (PixelFEDChannelCollection_ == nullptr) { throw cms::Exception("NullPointerError") << "PixelFEDChannelCollection not set in chooseScenario function.\n"; } @@ -284,14 +281,8 @@ namespace cms { edm::DetSet collector(iu->geographicalId().rawId()); edm::DetSet linkcollector(iu->geographicalId().rawId()); - std::cout << "3: " << (_pixeldigialgo->GetPixelFEDChannelCollection_ptr() != nullptr) << std::endl; - _pixeldigialgo->digitize( dynamic_cast(iu), collector.data, linkcollector.data, tTopo, randomEngine_); - - std::cout << "4: " << (_pixeldigialgo->GetPixelFEDChannelCollection_ptr() != nullptr) << std::endl; - - if (!collector.data.empty()) { theDigiVector.push_back(std::move(collector)); } diff --git a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc index d3b1142d1c3fd..a6e49d40f521a 100644 --- a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc +++ b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc @@ -1779,9 +1779,6 @@ void SiPixelDigitizerAlgorithm::pixel_inefficiency(const PixelEfficiencies& eff, auto pIndexConverter = PixelIndices(numColumns, numRows); std::vector badRocsFromFEDChannels(16, 0); - - std::cout<< __FILE__ << " " << __LINE__ <<": " << eff.PixelFEDChannelCollection_.get() << std::endl; - if (eff.PixelFEDChannelCollection_ != nullptr) { PixelFEDChannelCollection::const_iterator it = eff.PixelFEDChannelCollection_->find(detID); diff --git a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h index 75ab884367759..81d3a92a36ea1 100644 --- a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h +++ b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h @@ -79,7 +79,6 @@ class SiPixelDigitizerAlgorithm { 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... @@ -90,11 +89,6 @@ class SiPixelDigitizerAlgorithm { typedef std::unordered_map PixelFEDChannelCollectionMap; const PixelFEDChannelCollectionMap* quality_map; - PixelFEDChannelCollection* GetPixelFEDChannelCollection_ptr(){ - return pixelEfficiencies_.PixelFEDChannelCollection_.get(); - } - - private: //Accessing Lorentz angle from DB: edm::ESHandle SiPixelLorentzAngle_; From d1a7e7713fb89659948d7f37519319d1e09cb28b Mon Sep 17 00:00:00 2001 From: mmusich Date: Mon, 2 Sep 2019 07:33:18 +0200 Subject: [PATCH 4/4] implement code-format suggestions --- .../plugins/PreMixingSiPixelWorker.cc | 4 ++-- .../plugins/SiPixelDigitizerAlgorithm.cc | 12 +++++------- .../plugins/SiPixelDigitizerAlgorithm.h | 5 +++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc b/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc index 74ffda9991291..98732d6d04003 100644 --- a/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc +++ b/SimTracker/SiPixelDigitizer/plugins/PreMixingSiPixelWorker.cc @@ -281,8 +281,8 @@ 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 (digitizer_.killBadFEDChannels()) { + std::unique_ptr PixelFEDChannelCollection_ = digitizer_.chooseScenario(ps, engine); if (PixelFEDChannelCollection_ == nullptr) { throw cms::Exception("NullPointerError") << "PixelFEDChannelCollection not set in chooseScenario function.\n"; } diff --git a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc index a6e49d40f521a..1aebd88f8dba6 100644 --- a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc +++ b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc @@ -895,16 +895,15 @@ void SiPixelDigitizerAlgorithm::calculateInstlumiFactor(const std::vector SiPixelDigitizerAlgorithm::chooseScenario(const std::vector& ps ,CLHEP::HepRandomEngine* engine) -{ +std::unique_ptr 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++){ + for (unsigned int i = 0; i < ps.size(); i++) { bunchCrossing.push_back(ps[i].getBunchCrossing()); TrueInteractionList.push_back(ps[i].getTrueNumInteractions()); } @@ -920,7 +919,7 @@ std::unique_ptr SiPixelDigitizerAlgorithm::chooseScen } pui++; } - + if (pu0 != bunchCrossing.end()) { unsigned int PUBin = TrueInteractionList.at(p); // case delta PU=1, fix me const auto& theProbabilitiesPerScenario = scenarioProbabilityHandle->getProbabilities(PUBin); @@ -937,13 +936,12 @@ std::unique_ptr SiPixelDigitizerAlgorithm::chooseScen PixelFEDChannelCollection_ = std::make_unique(quality_map->at(scenario)); pixelEfficiencies_.PixelFEDChannelCollection_ = - std::make_unique(quality_map->at(scenario)); + 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 81d3a92a36ea1..f7b83e526cf49 100644 --- a/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h +++ b/SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.h @@ -78,12 +78,13 @@ class SiPixelDigitizerAlgorithm { 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(const std::vector& ps, + CLHEP::HepRandomEngine* engine); bool killBadFEDChannels() const; typedef std::unordered_map PixelFEDChannelCollectionMap;