Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-26 03:52:08

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "FWCore/ServiceRegistry/interface/Service.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "DataFormats/Common/interface/Handle.h"
0006 #include "FWCore/Framework/interface/ConsumesCollector.h"
0007 #include "FWCore/Framework/interface/ProducesCollector.h"
0008 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0009 #include "SimGeneral/MixingModule/interface/PileUpEventPrincipal.h"
0010 
0011 #include "DataFormats/Common/interface/DetSetVector.h"
0012 #include "DataFormats/Common/interface/DetSet.h"
0013 
0014 #include "SimGeneral/PreMixingModule/interface/PreMixingWorker.h"
0015 #include "SimGeneral/PreMixingModule/interface/PreMixingWorkerFactory.h"
0016 
0017 #include "Phase2TrackerDigitizer.h"
0018 #include "Phase2TrackerDigitizerAlgorithm.h"
0019 
0020 class PreMixingPhase2TrackerWorker : public PreMixingWorker {
0021 public:
0022   PreMixingPhase2TrackerWorker(const edm::ParameterSet& ps, edm::ProducesCollector, edm::ConsumesCollector&& iC);
0023   ~PreMixingPhase2TrackerWorker() override = default;
0024 
0025   void beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& es) override;
0026 
0027   void initializeEvent(edm::Event const& e, edm::EventSetup const& es) override;
0028   void addSignals(edm::Event const& e, edm::EventSetup const& es) override;
0029   void addPileups(PileUpEventPrincipal const& pep, edm::EventSetup const& es) override;
0030   void put(edm::Event& e, edm::EventSetup const& iSetup, std::vector<PileupSummaryInfo> const& ps, int bs) override;
0031 
0032 private:
0033   void accumulate(const edm::DetSetVector<PixelDigi>& digis, const float electronsPerADC);
0034 
0035   cms::Phase2TrackerDigitizer digitizer_;
0036 
0037   edm::EDGetTokenT<edm::DetSetVector<PixelDigi>> pixelSignalToken_;
0038   edm::EDGetTokenT<edm::DetSetVector<PixelDigi>> trackerSignalToken_;
0039   edm::InputTag pixelPileupLabel_;
0040   edm::InputTag trackerPileupLabel_;
0041   float pixelElectronPerAdc_;
0042   float trackerElectronPerAdc_;
0043 
0044   // Maybe map of maps is not that bad for this add once, update once,
0045   // read once workflow?
0046   using SignalMap = std::map<uint32_t, std::map<int, float>>;  // (channel, charge)
0047   SignalMap accumulator_;
0048 };
0049 
0050 PreMixingPhase2TrackerWorker::PreMixingPhase2TrackerWorker(const edm::ParameterSet& ps,
0051                                                            edm::ProducesCollector producesCollector,
0052                                                            edm::ConsumesCollector&& iC)
0053     : digitizer_(ps, producesCollector, iC),
0054       pixelSignalToken_(iC.consumes<edm::DetSetVector<PixelDigi>>(ps.getParameter<edm::InputTag>("pixelLabelSig"))),
0055       trackerSignalToken_(iC.consumes<edm::DetSetVector<PixelDigi>>(ps.getParameter<edm::InputTag>("trackerLabelSig"))),
0056       pixelPileupLabel_(ps.getParameter<edm::InputTag>("pixelPileInputTag")),
0057       trackerPileupLabel_(ps.getParameter<edm::InputTag>("trackerPileInputTag")),
0058       pixelElectronPerAdc_(ps.getParameter<double>("pixelPmxStage1ElectronPerAdc")),
0059       trackerElectronPerAdc_(ps.getParameter<double>("trackerPmxStage1ElectronPerAdc")) {}
0060 
0061 void PreMixingPhase2TrackerWorker::beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& es) {
0062   digitizer_.beginLuminosityBlock(lumi, es);
0063 }
0064 
0065 void PreMixingPhase2TrackerWorker::initializeEvent(edm::Event const& e, edm::EventSetup const& es) {
0066   digitizer_.initializeEvent(e, es);
0067 }
0068 
0069 void PreMixingPhase2TrackerWorker::addSignals(edm::Event const& e, edm::EventSetup const& es) {
0070   edm::Handle<edm::DetSetVector<PixelDigi>> hdigis;
0071   e.getByToken(pixelSignalToken_, hdigis);
0072   accumulate(*hdigis, pixelElectronPerAdc_);
0073 
0074   e.getByToken(trackerSignalToken_, hdigis);
0075   accumulate(*hdigis, trackerElectronPerAdc_);
0076 }
0077 
0078 void PreMixingPhase2TrackerWorker::addPileups(PileUpEventPrincipal const& pep, edm::EventSetup const& es) {
0079   edm::Handle<edm::DetSetVector<PixelDigi>> hdigis;
0080   pep.getByLabel(pixelPileupLabel_, hdigis);
0081   accumulate(*hdigis, pixelElectronPerAdc_);
0082 
0083   pep.getByLabel(trackerPileupLabel_, hdigis);
0084   accumulate(*hdigis, trackerElectronPerAdc_);
0085 }
0086 
0087 void PreMixingPhase2TrackerWorker::accumulate(const edm::DetSetVector<PixelDigi>& digis, const float electronPerADC) {
0088   for (const auto& detset : digis) {
0089     auto& accDet = accumulator_[detset.detId()];
0090     for (const auto& digi : detset) {
0091       // note: according to C++ standard operator[] does
0092       // value-initializiation, which for float means initial value of 0
0093       auto& acc = accDet[digi.channel()];
0094       acc += digi.adc() * electronPerADC;
0095     }
0096   }
0097 }
0098 
0099 void PreMixingPhase2TrackerWorker::put(edm::Event& e,
0100                                        edm::EventSetup const& iSetup,
0101                                        std::vector<PileupSummaryInfo> const& ps,
0102                                        int bs) {
0103   digitizer_.loadAccumulator(accumulator_);
0104   digitizer_.finalizeEvent(e, iSetup);
0105   decltype(accumulator_){}.swap(accumulator_);  // release memory
0106 }
0107 
0108 DEFINE_PREMIXING_WORKER(PreMixingPhase2TrackerWorker);