Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-03 02:53:35

0001 #ifndef DataFormats_Luminosity_PixelClusterCounts_h
0002 #define DataFormats_Luminosity_PixelClusterCounts_h
0003 /** \class reco::PixelClusterCounts
0004  *  
0005  * Reconstructed PixelClusterCounts object that will contain the moduleID, BX, and counts.
0006  *
0007  * \authors: Sam Higginbotham shigginb@cern.ch and Chris Palmer capalmer@cern.ch
0008  * 
0009  *
0010  */
0011 #include <algorithm>
0012 #include <string>
0013 #include <sstream>
0014 #include <iostream>
0015 #include <vector>
0016 
0017 #include "DataFormats/Luminosity/interface/LumiConstants.h"
0018 #include "DataFormats/Luminosity/interface/PixelClusterCountsInEvent.h"
0019 
0020 namespace reco {
0021   class PixelClusterCounts {
0022   public:
0023     PixelClusterCounts() : m_events(LumiConstants::numBX) {}
0024 
0025     void increment(int mD, unsigned int bxID, int count) {
0026       size_t modIndex = std::distance(m_ModID.begin(), std::find(m_ModID.begin(), m_ModID.end(), mD));
0027       if (modIndex == m_ModID.size()) {
0028         m_ModID.push_back(mD);
0029         m_counts.resize(m_counts.size() + LumiConstants::numBX, 0);
0030       }
0031       m_counts.at(LumiConstants::numBX * modIndex + bxID - 1) += count;
0032     }
0033 
0034     void eventCounter(unsigned int bxID) { m_events.at(bxID - 1)++; }
0035 
0036     void add(reco::PixelClusterCountsInEvent const& pccInEvent) {
0037       std::vector<int> const& countsInEvent = pccInEvent.counts();
0038       std::vector<int> const& modIDInEvent = pccInEvent.modID();
0039       int bxIDInEvent = pccInEvent.bxID();
0040       for (unsigned int i = 0; i < modIDInEvent.size(); i++) {
0041         increment(modIDInEvent[i], bxIDInEvent, countsInEvent.at(i));
0042       }
0043     }
0044 
0045     void merge(reco::PixelClusterCounts const& pcc) {
0046       std::vector<int> const& counts = pcc.readCounts();
0047       std::vector<int> const& modIDs = pcc.readModID();
0048       std::vector<int> const& events = pcc.readEvents();
0049       for (unsigned int i = 0; i < modIDs.size(); i++) {
0050         for (unsigned int bxID = 0; bxID < LumiConstants::numBX; ++bxID) {
0051           increment(modIDs[i], bxID + 1, counts.at(i * LumiConstants::numBX + bxID));
0052         }
0053       }
0054       for (unsigned int i = 0; i < LumiConstants::numBX; ++i) {
0055         m_events[i] += events[i];
0056       }
0057     }
0058 
0059     void reset() {
0060       m_counts.clear();
0061       m_ModID.clear();
0062       m_events.clear();
0063       m_events.resize(LumiConstants::numBX, 0);
0064     }
0065 
0066     std::vector<int> const& readCounts() const { return (m_counts); }
0067     std::vector<int> const& readEvents() const { return (m_events); }
0068     std::vector<int> const& readModID() const { return (m_ModID); }
0069 
0070   private:
0071     std::vector<int> m_counts;
0072     std::vector<int> m_events;
0073     std::vector<int> m_ModID;
0074   };
0075 
0076 }  // namespace reco
0077 #endif