File indexing completed on 2024-11-07 06:12:43
0001 #ifndef DPGAnalysis_SiStripTools_MultiplicityAlgorithms_H
0002 #define DPGAnalysis_SiStripTools_MultiplicityAlgorithms_H
0003
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Framework/interface/ConsumesCollector.h"
0007 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
0008
0009 #include "DataFormats/Common/interface/DetSetVector.h"
0010 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0011 #include "DataFormats/Common/interface/DetSet.h"
0012
0013 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0014 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0015 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0016 #include "DataFormats/TrackerCommon/interface/ClusterSummary.h"
0017
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019
0020 #include "DataFormats/Common/interface/Handle.h"
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
0023
0024 #include "DPGAnalysis/SiStripTools/interface/Multiplicities.h"
0025
0026 namespace edm {
0027 class EventSetup;
0028 };
0029
0030 #include <string>
0031
0032 namespace sistriptools::algorithm {
0033 class ClusterSummarySingleMultiplicity {
0034 public:
0035 using value_t = values::Multiplicity;
0036 ClusterSummarySingleMultiplicity(const edm::ParameterSet& iConfig, edm::ConsumesCollector&& iC);
0037 ClusterSummarySingleMultiplicity(const edm::ParameterSet& iConfig, edm::ConsumesCollector& iC);
0038
0039 value_t getEvent(const edm::Event& iEvent, const edm::EventSetup& iSetup) const;
0040
0041 private:
0042 ClusterSummary::CMSTracker m_subdetenum;
0043 ClusterSummary::VariablePlacement m_varenum;
0044 edm::EDGetTokenT<ClusterSummary> m_collection;
0045 bool m_warn;
0046 };
0047
0048 template <class T>
0049 class SingleMultiplicity {
0050 public:
0051 using value_t = values::Multiplicity;
0052 SingleMultiplicity(const edm::ParameterSet& iConfig, edm::ConsumesCollector&& iC);
0053 SingleMultiplicity(const edm::ParameterSet& iConfig, edm::ConsumesCollector& iC);
0054
0055 value_t getEvent(const edm::Event& iEvent, const edm::EventSetup& iSetup) const;
0056
0057 private:
0058 int m_modthr;
0059 bool m_useQuality;
0060 edm::ESGetToken<SiStripQuality, SiStripQualityRcd> m_qualityToken;
0061 edm::EDGetTokenT<T> m_collection;
0062 };
0063
0064 template <class T>
0065 SingleMultiplicity<T>::SingleMultiplicity(const edm::ParameterSet& iConfig, edm::ConsumesCollector&& iC)
0066 : m_modthr(iConfig.getUntrackedParameter<int>("moduleThreshold")),
0067 m_useQuality(iConfig.getUntrackedParameter<bool>("useQuality", false)),
0068 m_qualityToken(m_useQuality
0069 ? decltype(m_qualityToken){iC.esConsumes<SiStripQuality, SiStripQualityRcd>(
0070 edm::ESInputTag{"", iConfig.getUntrackedParameter<std::string>("qualityLabel", "")})}
0071 : decltype(m_qualityToken){}),
0072 m_collection(iC.consumes<T>(iConfig.getParameter<edm::InputTag>("collectionName"))) {}
0073 template <class T>
0074 SingleMultiplicity<T>::SingleMultiplicity(const edm::ParameterSet& iConfig, edm::ConsumesCollector& iC)
0075 : m_modthr(iConfig.getUntrackedParameter<int>("moduleThreshold")),
0076 m_useQuality(iConfig.getUntrackedParameter<bool>("useQuality", false)),
0077 m_qualityToken(m_useQuality
0078 ? decltype(m_qualityToken){iC.esConsumes<SiStripQuality, SiStripQualityRcd>(
0079 edm::ESInputTag(iConfig.getUntrackedParameter<std::string>("qualityLabel", "")))}
0080 : decltype(m_qualityToken){}),
0081 m_collection(iC.consumes<T>(iConfig.getParameter<edm::InputTag>("collectionName"))) {}
0082
0083 template <class T>
0084 typename SingleMultiplicity<T>::value_t SingleMultiplicity<T>::getEvent(const edm::Event& iEvent,
0085 const edm::EventSetup& iSetup) const {
0086 int mult = 0;
0087
0088 const SiStripQuality* quality = nullptr;
0089 if (m_useQuality) {
0090 quality = &iSetup.getData(m_qualityToken);
0091 }
0092
0093 edm::Handle<T> digis;
0094 iEvent.getByToken(m_collection, digis);
0095
0096 for (typename T::const_iterator it = digis->begin(); it != digis->end(); it++) {
0097 if (!m_useQuality || !quality->IsModuleBad(it->detId())) {
0098 if (m_modthr < 0 || int(it->size()) < m_modthr) {
0099 mult += it->size();
0100
0101 }
0102 }
0103 }
0104 return value_t(mult);
0105 }
0106
0107 template <class T1, class T2>
0108 class MultiplicityPair {
0109 public:
0110 using value_t = values::MultiplicityPair<typename T1::value_t, typename T2::value_t>;
0111 MultiplicityPair();
0112 MultiplicityPair(const edm::ParameterSet& iConfig, edm::ConsumesCollector&& iC);
0113 MultiplicityPair(const edm::ParameterSet& iConfig, edm::ConsumesCollector& iC);
0114
0115 value_t getEvent(const edm::Event& iEvent, const edm::EventSetup& iSetup) const;
0116
0117 private:
0118 T1 m_multiplicity1;
0119 T2 m_multiplicity2;
0120 };
0121
0122 template <class T1, class T2>
0123 MultiplicityPair<T1, T2>::MultiplicityPair() : m_multiplicity1(), m_multiplicity2() {}
0124
0125 template <class T1, class T2>
0126 MultiplicityPair<T1, T2>::MultiplicityPair(const edm::ParameterSet& iConfig, edm::ConsumesCollector&& iC)
0127 : m_multiplicity1(iConfig.getParameter<edm::ParameterSet>("firstMultiplicityConfig"), iC),
0128 m_multiplicity2(iConfig.getParameter<edm::ParameterSet>("secondMultiplicityConfig"), iC) {}
0129 template <class T1, class T2>
0130 MultiplicityPair<T1, T2>::MultiplicityPair(const edm::ParameterSet& iConfig, edm::ConsumesCollector& iC)
0131 : m_multiplicity1(iConfig.getParameter<edm::ParameterSet>("firstMultiplicityConfig"), iC),
0132 m_multiplicity2(iConfig.getParameter<edm::ParameterSet>("secondMultiplicityConfig"), iC) {}
0133
0134 template <class T1, class T2>
0135 typename MultiplicityPair<T1, T2>::value_t MultiplicityPair<T1, T2>::getEvent(const edm::Event& iEvent,
0136 const edm::EventSetup& iSetup) const {
0137 auto m1 = m_multiplicity1.getEvent(iEvent, iSetup);
0138 auto m2 = m_multiplicity2.getEvent(iEvent, iSetup);
0139 return value_t(m1, m2);
0140 }
0141
0142 typedef SingleMultiplicity<edm::DetSetVector<SiStripDigi> > SingleSiStripDigiMultiplicity;
0143 typedef SingleMultiplicity<edmNew::DetSetVector<SiStripCluster> > SingleSiStripClusterMultiplicity;
0144 typedef SingleMultiplicity<edmNew::DetSetVector<SiPixelCluster> > SingleSiPixelClusterMultiplicity;
0145 typedef MultiplicityPair<SingleMultiplicity<edmNew::DetSetVector<SiPixelCluster> >,
0146 SingleMultiplicity<edmNew::DetSetVector<SiStripCluster> > >
0147 SiPixelClusterSiStripClusterMultiplicityPair;
0148 typedef MultiplicityPair<ClusterSummarySingleMultiplicity, ClusterSummarySingleMultiplicity>
0149 ClusterSummaryMultiplicityPair;
0150 }
0151
0152 #endif