Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:10

0001 #include "FWCore/Framework/interface/ProducesCollector.h"
0002 #include "SimGeneral/PreMixingModule/interface/PreMixingMuonWorker.h"
0003 #include "SimGeneral/PreMixingModule/interface/PreMixingWorkerFactory.h"
0004 
0005 #include "DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h"
0006 #include "DataFormats/CSCDigi/interface/CSCStripDigiCollection.h"
0007 #include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h"
0008 
0009 // Specialize put for CSC strip
0010 template <>
0011 void PreMixingMuonWorker<CSCStripDigiCollection>::put(edm::Event &iEvent) {
0012   auto merged = std::make_unique<CSCStripDigiCollection>();
0013   for (const auto &elem : *accumulated_) {
0014     // The layerId
0015     const CSCDetId &layerId = elem.first;
0016 
0017     // Get the iterators over the digis associated with this LayerId
0018     const CSCStripDigiCollection::Range &range = elem.second;
0019 
0020     std::vector<CSCStripDigi> NewDigiList;
0021 
0022     std::vector<int> StripList;
0023     std::vector<CSCStripDigiCollection::const_iterator> StripPointer;
0024 
0025     for (CSCStripDigiCollection::const_iterator dtdigi = range.first; dtdigi != range.second; ++dtdigi) {
0026       StripList.push_back((*dtdigi).getStrip());
0027       StripPointer.push_back(dtdigi);
0028     }
0029 
0030     int PrevStrip = -1;
0031     std::vector<int> DuplicateList;
0032 
0033     std::vector<CSCStripDigiCollection::const_iterator>::const_iterator StripPtr = StripPointer.begin();
0034 
0035     for (std::vector<int>::const_iterator istrip = StripList.begin(); istrip != StripList.end(); ++istrip) {
0036       const int CurrentStrip = *(istrip);
0037 
0038       if (CurrentStrip > PrevStrip) {
0039         PrevStrip = CurrentStrip;
0040 
0041         int dupl_count;
0042         dupl_count = std::count(StripList.begin(), StripList.end(), CurrentStrip);
0043         if (dupl_count > 1) {
0044           std::vector<int>::const_iterator duplicate = istrip;
0045           ++duplicate;
0046           std::vector<CSCStripDigiCollection::const_iterator>::const_iterator DuplPointer = StripPtr;
0047           ++DuplPointer;
0048           for (; duplicate != StripList.end(); ++duplicate) {
0049             if ((*duplicate) == CurrentStrip) {
0050               DuplicateList.push_back(CurrentStrip);
0051 
0052               std::vector<int> pileup_adc = (**DuplPointer).getADCCounts();
0053               std::vector<int> signal_adc = (**StripPtr).getADCCounts();
0054 
0055               std::vector<int>::const_iterator minplace;
0056 
0057               minplace = std::min_element(pileup_adc.begin(), pileup_adc.end());
0058 
0059               int minvalue = (*minplace);
0060 
0061               std::vector<int> new_adc;
0062 
0063               std::vector<int>::const_iterator newsig = signal_adc.begin();
0064 
0065               for (std::vector<int>::const_iterator ibin = pileup_adc.begin(); ibin != pileup_adc.end(); ++ibin) {
0066                 new_adc.push_back((*newsig) + (*ibin) - minvalue);
0067 
0068                 ++newsig;
0069               }
0070 
0071               CSCStripDigi newDigi(CurrentStrip, new_adc);
0072               NewDigiList.push_back(newDigi);
0073             }
0074             ++DuplPointer;
0075           }
0076         } else {
0077           NewDigiList.push_back(**StripPtr);
0078         }
0079       }                    // if strips monotonically increasing...  Haven't hit duplicates yet
0080       else {               // reached end of signal digis, or there was no overlap
0081         PrevStrip = 1000;  // now into pileup signals, stop looking forward for
0082                            // duplicates
0083 
0084         // check if this digi was in the duplicate list
0085         int check;
0086         check = std::count(DuplicateList.begin(), DuplicateList.end(), CurrentStrip);
0087         if (check == 0)
0088           NewDigiList.push_back(**StripPtr);
0089       }
0090       ++StripPtr;
0091     }
0092 
0093     CSCStripDigiCollection::Range stripRange(NewDigiList.begin(), NewDigiList.end());
0094 
0095     merged->put(stripRange, layerId);
0096   }
0097 
0098   iEvent.put(std::move(merged), collectionDM_);
0099   accumulated_.reset();
0100 }
0101 
0102 // CSC has three digi collections
0103 class PreMixingCSCWorker : public PreMixingWorker {
0104 public:
0105   PreMixingCSCWorker(const edm::ParameterSet &ps, edm::ProducesCollector producesCollector, edm::ConsumesCollector &&iC)
0106       : stripWorker_(ps.getParameter<edm::ParameterSet>("strip"), producesCollector, iC),
0107         wireWorker_(ps.getParameter<edm::ParameterSet>("wire"), producesCollector, iC),
0108         comparatorWorker_(ps.getParameter<edm::ParameterSet>("comparator"), producesCollector, iC) {}
0109   ~PreMixingCSCWorker() override = default;
0110 
0111   void initializeEvent(edm::Event const &iEvent, edm::EventSetup const &iSetup) override {}
0112 
0113   void addSignals(edm::Event const &iEvent, edm::EventSetup const &iSetup) override {
0114     stripWorker_.addSignals(iEvent, iSetup);
0115     wireWorker_.addSignals(iEvent, iSetup);
0116     comparatorWorker_.addSignals(iEvent, iSetup);
0117   }
0118 
0119   void addPileups(PileUpEventPrincipal const &pep, edm::EventSetup const &iSetup) override {
0120     stripWorker_.addPileups(pep, iSetup);
0121     wireWorker_.addPileups(pep, iSetup);
0122     comparatorWorker_.addPileups(pep, iSetup);
0123   }
0124 
0125   void put(edm::Event &iEvent,
0126            edm::EventSetup const &iSetup,
0127            std::vector<PileupSummaryInfo> const &ps,
0128            int bunchSpacing) override {
0129     stripWorker_.put(iEvent);
0130     wireWorker_.put(iEvent);
0131     comparatorWorker_.put(iEvent);
0132   }
0133 
0134 private:
0135   PreMixingMuonWorker<CSCStripDigiCollection> stripWorker_;
0136   PreMixingMuonWorker<CSCWireDigiCollection> wireWorker_;
0137   PreMixingMuonWorker<CSCComparatorDigiCollection> comparatorWorker_;
0138 };
0139 
0140 DEFINE_PREMIXING_WORKER(PreMixingCSCWorker);