Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:06:33

0001 #ifndef DPGAnalysis_SiStripTools_DigiCollectionProfile_H
0002 #define DPGAnalysis_SiStripTools_DigiCollectionProfile_H
0003 
0004 #include <vector>
0005 #include "CommonTools/UtilAlgos/interface/DetIdSelector.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0008 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
0009 #include "DataFormats/Common/interface/DetSetVector.h"
0010 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0011 #include "DataFormats/Common/interface/DetSet.h"
0012 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0013 
0014 #include "TH1.h"
0015 #include "TH2.h"
0016 #include "TProfile.h"
0017 
0018 template <class T>
0019 class DigiCollectionProfiler {
0020 public:
0021   DigiCollectionProfiler();
0022   DigiCollectionProfiler(const edm::ParameterSet& iConfig);
0023   ~DigiCollectionProfiler(){};
0024 
0025   void fill(edm::Handle<T> digis,
0026             const std::vector<TH1F*>&,
0027             const std::vector<TProfile*>&,
0028             const std::vector<TH2F*>&) const;
0029 
0030 private:
0031   bool m_folded;
0032   bool m_want1dHisto;
0033   bool m_wantProfile;
0034   bool m_want2dHisto;
0035 
0036   std::vector<DetIdSelector> m_selections;
0037 };
0038 
0039 template <class T>
0040 DigiCollectionProfiler<T>::DigiCollectionProfiler()
0041     : m_folded(false), m_want1dHisto(false), m_wantProfile(false), m_want2dHisto(false), m_selections() {}
0042 
0043 template <class T>
0044 DigiCollectionProfiler<T>::DigiCollectionProfiler(const edm::ParameterSet& iConfig)
0045     : m_folded(iConfig.getUntrackedParameter<bool>("foldedStrips", false)),
0046       m_want1dHisto(iConfig.getUntrackedParameter<bool>("want1dHisto", true)),
0047       m_wantProfile(iConfig.getUntrackedParameter<bool>("wantProfile", true)),
0048       m_want2dHisto(iConfig.getUntrackedParameter<bool>("want2dHisto", false))
0049 
0050 {
0051   std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");
0052 
0053   for (std::vector<edm::ParameterSet>::const_iterator selconfig = selconfigs.begin(); selconfig != selconfigs.end();
0054        ++selconfig) {
0055     DetIdSelector selection(*selconfig);
0056     m_selections.push_back(selection);
0057   }
0058 }
0059 
0060 template <class T>
0061 void DigiCollectionProfiler<T>::fill(edm::Handle<T> digis,
0062                                      const std::vector<TH1F*>& hist,
0063                                      const std::vector<TProfile*>& hprof,
0064                                      const std::vector<TH2F*>& hist2d) const {}
0065 
0066 template <>
0067 inline void DigiCollectionProfiler<edm::DetSetVector<SiStripDigi> >::fill(
0068     edm::Handle<edm::DetSetVector<SiStripDigi> > digis,
0069     const std::vector<TH1F*>& hist,
0070     const std::vector<TProfile*>& hprof,
0071     const std::vector<TH2F*>& hist2d) const {
0072   for (edm::DetSetVector<SiStripDigi>::const_iterator mod = digis->begin(); mod != digis->end(); mod++) {
0073     for (unsigned int isel = 0; isel < m_selections.size(); ++isel) {
0074       if (m_selections[isel].isSelected(mod->detId())) {
0075         TH1F* tobefilled1d = nullptr;
0076         TProfile* tobefilledprof = nullptr;
0077         TH2F* tobefilled2d = nullptr;
0078 
0079         if (m_want1dHisto)
0080           tobefilled1d = hist[isel];
0081         if (m_wantProfile)
0082           tobefilledprof = hprof[isel];
0083         if (m_want2dHisto)
0084           tobefilled2d = hist2d[isel];
0085 
0086         for (edm::DetSet<SiStripDigi>::const_iterator digi = mod->begin(); digi != mod->end(); digi++) {
0087           if (digi->adc() > 0) {
0088             unsigned int strip = digi->strip();
0089             if (m_folded)
0090               strip = strip % 256;
0091             if (tobefilled1d)
0092               tobefilled1d->Fill(strip);
0093             if (tobefilledprof)
0094               tobefilledprof->Fill(strip, digi->adc());
0095             if (tobefilled2d)
0096               tobefilled2d->Fill(strip, digi->adc());
0097           }
0098         }
0099       }
0100     }
0101   }
0102 }
0103 
0104 template <>
0105 inline void DigiCollectionProfiler<edm::DetSetVector<SiStripRawDigi> >::fill(
0106     edm::Handle<edm::DetSetVector<SiStripRawDigi> > digis,
0107     const std::vector<TH1F*>& hist,
0108     const std::vector<TProfile*>& hprof,
0109     const std::vector<TH2F*>& hist2d) const {
0110   for (edm::DetSetVector<SiStripRawDigi>::const_iterator mod = digis->begin(); mod != digis->end(); mod++) {
0111     for (unsigned int isel = 0; isel < m_selections.size(); ++isel) {
0112       if (m_selections[isel].isSelected(mod->detId())) {
0113         TH1F* tobefilled1d = nullptr;
0114         TProfile* tobefilledprof = nullptr;
0115         TH2F* tobefilled2d = nullptr;
0116 
0117         if (m_want1dHisto)
0118           tobefilled1d = hist[isel];
0119         if (m_wantProfile)
0120           tobefilledprof = hprof[isel];
0121         if (m_want2dHisto)
0122           tobefilled2d = hist2d[isel];
0123 
0124         unsigned int istrip = 0;
0125         for (edm::DetSet<SiStripRawDigi>::const_iterator digi = mod->begin(); digi != mod->end(); digi++, ++istrip) {
0126           if (digi->adc() > 0) {
0127             unsigned int strip = istrip;
0128             if (m_folded)
0129               strip = strip % 256;
0130             if (tobefilled1d)
0131               tobefilled1d->Fill(strip);
0132             if (tobefilledprof)
0133               tobefilledprof->Fill(strip, digi->adc());
0134             if (tobefilled2d)
0135               tobefilled2d->Fill(strip, digi->adc());
0136           }
0137         }
0138       }
0139     }
0140   }
0141 }
0142 
0143 template <>
0144 inline void DigiCollectionProfiler<edmNew::DetSetVector<SiStripCluster> >::fill(
0145     edm::Handle<edmNew::DetSetVector<SiStripCluster> > digis,
0146     const std::vector<TH1F*>& hist,
0147     const std::vector<TProfile*>& hprof,
0148     const std::vector<TH2F*>& hist2d) const {
0149   for (edmNew::DetSetVector<SiStripCluster>::const_iterator mod = digis->begin(); mod != digis->end(); mod++) {
0150     for (unsigned int isel = 0; isel < m_selections.size(); ++isel) {
0151       if (m_selections[isel].isSelected(mod->detId())) {
0152         TH1F* tobefilled1d = nullptr;
0153         TProfile* tobefilledprof = nullptr;
0154         TH2F* tobefilled2d = nullptr;
0155 
0156         if (m_want1dHisto)
0157           tobefilled1d = hist[isel];
0158         if (m_wantProfile)
0159           tobefilledprof = hprof[isel];
0160         if (m_want2dHisto)
0161           tobefilled2d = hist2d[isel];
0162 
0163         for (edmNew::DetSet<SiStripCluster>::const_iterator clus = mod->begin(); clus != mod->end(); clus++) {
0164           for (unsigned int digi = 0; digi < clus->amplitudes().size(); ++digi) {
0165             if (clus->amplitudes()[digi] > 0) {
0166               unsigned int strip = clus->firstStrip() + digi;
0167               if (m_folded)
0168                 strip = strip % 256;
0169               if (tobefilled1d)
0170                 tobefilled1d->Fill(strip);
0171               if (tobefilledprof)
0172                 tobefilledprof->Fill(strip, clus->amplitudes()[digi]);
0173               if (tobefilled2d)
0174                 tobefilled2d->Fill(strip, clus->amplitudes()[digi]);
0175             }
0176           }
0177         }
0178       }
0179     }
0180   }
0181 }
0182 
0183 #endif  // DPGAnalysis_SiStripTools_DigiCollectionProfile_H