DigiCollectionProfiler

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
#ifndef DPGAnalysis_SiStripTools_DigiCollectionProfile_H
#define DPGAnalysis_SiStripTools_DigiCollectionProfile_H

#include <vector>
#include "CommonTools/UtilAlgos/interface/DetIdSelector.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
#include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
#include "DataFormats/Common/interface/DetSetVector.h"
#include "DataFormats/Common/interface/DetSetVectorNew.h"
#include "DataFormats/Common/interface/DetSet.h"
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"

#include "TH1.h"
#include "TH2.h"
#include "TProfile.h"

template <class T>
class DigiCollectionProfiler {
public:
  DigiCollectionProfiler();
  DigiCollectionProfiler(const edm::ParameterSet& iConfig);
  ~DigiCollectionProfiler() {}

  void fill(edm::Handle<T> digis,
            const std::vector<TH1F*>&,
            const std::vector<TProfile*>&,
            const std::vector<TH2F*>&) const;

private:
  bool m_folded;
  bool m_want1dHisto;
  bool m_wantProfile;
  bool m_want2dHisto;

  std::vector<DetIdSelector> m_selections;
};

template <class T>
DigiCollectionProfiler<T>::DigiCollectionProfiler()
    : m_folded(false), m_want1dHisto(false), m_wantProfile(false), m_want2dHisto(false), m_selections() {}

template <class T>
DigiCollectionProfiler<T>::DigiCollectionProfiler(const edm::ParameterSet& iConfig)
    : m_folded(iConfig.getUntrackedParameter<bool>("foldedStrips", false)),
      m_want1dHisto(iConfig.getUntrackedParameter<bool>("want1dHisto", true)),
      m_wantProfile(iConfig.getUntrackedParameter<bool>("wantProfile", true)),
      m_want2dHisto(iConfig.getUntrackedParameter<bool>("want2dHisto", false))

{
  std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");

  for (std::vector<edm::ParameterSet>::const_iterator selconfig = selconfigs.begin(); selconfig != selconfigs.end();
       ++selconfig) {
    DetIdSelector selection(*selconfig);
    m_selections.push_back(selection);
  }
}

template <class T>
void DigiCollectionProfiler<T>::fill(edm::Handle<T> digis,
                                     const std::vector<TH1F*>& hist,
                                     const std::vector<TProfile*>& hprof,
                                     const std::vector<TH2F*>& hist2d) const {}

template <>
inline void DigiCollectionProfiler<edm::DetSetVector<SiStripDigi> >::fill(
    edm::Handle<edm::DetSetVector<SiStripDigi> > digis,
    const std::vector<TH1F*>& hist,
    const std::vector<TProfile*>& hprof,
    const std::vector<TH2F*>& hist2d) const {
  for (edm::DetSetVector<SiStripDigi>::const_iterator mod = digis->begin(); mod != digis->end(); mod++) {
    for (unsigned int isel = 0; isel < m_selections.size(); ++isel) {
      if (m_selections[isel].isSelected(mod->detId())) {
        TH1F* tobefilled1d = nullptr;
        TProfile* tobefilledprof = nullptr;
        TH2F* tobefilled2d = nullptr;

        if (m_want1dHisto)
          tobefilled1d = hist[isel];
        if (m_wantProfile)
          tobefilledprof = hprof[isel];
        if (m_want2dHisto)
          tobefilled2d = hist2d[isel];

        for (edm::DetSet<SiStripDigi>::const_iterator digi = mod->begin(); digi != mod->end(); digi++) {
          if (digi->adc() > 0) {
            unsigned int strip = digi->strip();
            if (m_folded)
              strip = strip % 256;
            if (tobefilled1d)
              tobefilled1d->Fill(strip);
            if (tobefilledprof)
              tobefilledprof->Fill(strip, digi->adc());
            if (tobefilled2d)
              tobefilled2d->Fill(strip, digi->adc());
          }
        }
      }
    }
  }
}

template <>
inline void DigiCollectionProfiler<edm::DetSetVector<SiStripRawDigi> >::fill(
    edm::Handle<edm::DetSetVector<SiStripRawDigi> > digis,
    const std::vector<TH1F*>& hist,
    const std::vector<TProfile*>& hprof,
    const std::vector<TH2F*>& hist2d) const {
  for (edm::DetSetVector<SiStripRawDigi>::const_iterator mod = digis->begin(); mod != digis->end(); mod++) {
    for (unsigned int isel = 0; isel < m_selections.size(); ++isel) {
      if (m_selections[isel].isSelected(mod->detId())) {
        TH1F* tobefilled1d = nullptr;
        TProfile* tobefilledprof = nullptr;
        TH2F* tobefilled2d = nullptr;

        if (m_want1dHisto)
          tobefilled1d = hist[isel];
        if (m_wantProfile)
          tobefilledprof = hprof[isel];
        if (m_want2dHisto)
          tobefilled2d = hist2d[isel];

        unsigned int istrip = 0;
        for (edm::DetSet<SiStripRawDigi>::const_iterator digi = mod->begin(); digi != mod->end(); digi++, ++istrip) {
          if (digi->adc() > 0) {
            unsigned int strip = istrip;
            if (m_folded)
              strip = strip % 256;
            if (tobefilled1d)
              tobefilled1d->Fill(strip);
            if (tobefilledprof)
              tobefilledprof->Fill(strip, digi->adc());
            if (tobefilled2d)
              tobefilled2d->Fill(strip, digi->adc());
          }
        }
      }
    }
  }
}

template <>
inline void DigiCollectionProfiler<edmNew::DetSetVector<SiStripCluster> >::fill(
    edm::Handle<edmNew::DetSetVector<SiStripCluster> > digis,
    const std::vector<TH1F*>& hist,
    const std::vector<TProfile*>& hprof,
    const std::vector<TH2F*>& hist2d) const {
  for (edmNew::DetSetVector<SiStripCluster>::const_iterator mod = digis->begin(); mod != digis->end(); mod++) {
    for (unsigned int isel = 0; isel < m_selections.size(); ++isel) {
      if (m_selections[isel].isSelected(mod->detId())) {
        TH1F* tobefilled1d = nullptr;
        TProfile* tobefilledprof = nullptr;
        TH2F* tobefilled2d = nullptr;

        if (m_want1dHisto)
          tobefilled1d = hist[isel];
        if (m_wantProfile)
          tobefilledprof = hprof[isel];
        if (m_want2dHisto)
          tobefilled2d = hist2d[isel];

        for (edmNew::DetSet<SiStripCluster>::const_iterator clus = mod->begin(); clus != mod->end(); clus++) {
          for (unsigned int digi = 0; digi < clus->amplitudes().size(); ++digi) {
            if (clus->amplitudes()[digi] > 0) {
              unsigned int strip = clus->firstStrip() + digi;
              if (m_folded)
                strip = strip % 256;
              if (tobefilled1d)
                tobefilled1d->Fill(strip);
              if (tobefilledprof)
                tobefilledprof->Fill(strip, clus->amplitudes()[digi]);
              if (tobefilled2d)
                tobefilled2d->Fill(strip, clus->amplitudes()[digi]);
            }
          }
        }
      }
    }
  }
}

#endif  // DPGAnalysis_SiStripTools_DigiCollectionProfile_H