File indexing completed on 2024-04-06 12:06:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include <memory>
0020 #include <string>
0021 #include <map>
0022 #include <vector>
0023
0024
0025 #include "FWCore/Framework/interface/Frameworkfwd.h"
0026 #include "FWCore/Framework/interface/global/EDProducer.h"
0027
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030
0031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "FWCore/Utilities/interface/InputTag.h"
0034
0035 #include "DataFormats/DetId/interface/DetId.h"
0036 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0037 #include "DataFormats/Common/interface/DetSetVector.h"
0038
0039 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0040 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0041 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0042
0043 #include "CommonTools/UtilAlgos/interface/DetIdSelector.h"
0044
0045
0046
0047 template <class T>
0048 class MultiplicityProducer : public edm::global::EDProducer<> {
0049 public:
0050 explicit MultiplicityProducer(const edm::ParameterSet&);
0051 ~MultiplicityProducer() override;
0052
0053 private:
0054 void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0055 int multiplicity(typename T::const_iterator det) const;
0056 int detSetMultiplicity(typename T::const_iterator det) const;
0057
0058
0059
0060 edm::EDGetTokenT<T> m_collectionToken;
0061 const bool m_clustersize;
0062 std::map<unsigned int, std::string> m_subdets;
0063 std::map<unsigned int, DetIdSelector> m_subdetsels;
0064 };
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 template <class T>
0078 MultiplicityProducer<T>::MultiplicityProducer(const edm::ParameterSet& iConfig)
0079 : m_collectionToken(consumes<T>(iConfig.getParameter<edm::InputTag>("clusterdigiCollection"))),
0080 m_clustersize(iConfig.getUntrackedParameter<bool>("withClusterSize", false)),
0081 m_subdets(),
0082 m_subdetsels() {
0083 produces<std::map<unsigned int, int> >();
0084
0085
0086
0087 std::vector<edm::ParameterSet> wantedsubds(iConfig.getParameter<std::vector<edm::ParameterSet> >("wantedSubDets"));
0088
0089 for (std::vector<edm::ParameterSet>::iterator ps = wantedsubds.begin(); ps != wantedsubds.end(); ++ps) {
0090 m_subdets[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("detLabel");
0091 m_subdetsels[ps->getParameter<unsigned int>("detSelection")] =
0092 DetIdSelector(ps->getUntrackedParameter<std::vector<std::string> >("selection", std::vector<std::string>()));
0093 }
0094 }
0095
0096 template <class T>
0097 MultiplicityProducer<T>::~MultiplicityProducer() {
0098
0099
0100 }
0101
0102
0103
0104
0105
0106
0107 template <class T>
0108 void MultiplicityProducer<T>::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0109 LogDebug("Multiplicity") << " Ready to loop";
0110
0111 using namespace edm;
0112
0113 std::unique_ptr<std::map<unsigned int, int> > mults(new std::map<unsigned int, int>);
0114
0115 Handle<T> digis;
0116 iEvent.getByToken(m_collectionToken, digis);
0117
0118 for (std::map<unsigned int, std::string>::const_iterator sdet = m_subdets.begin(); sdet != m_subdets.end(); ++sdet) {
0119 (*mults)[sdet->first] = 0;
0120 }
0121
0122 for (typename T::const_iterator det = digis->begin(); det != digis->end(); ++det) {
0123
0124 if (m_subdets.find(0) != m_subdets.end())
0125 (*mults)[0] += multiplicity(det);
0126
0127 DetId detid(det->detId());
0128 unsigned int subdet = detid.subdetId();
0129
0130
0131 if (m_subdets.find(subdet) != m_subdets.end()) {
0132 auto detsel = m_subdetsels.find(subdet);
0133 if (detsel == m_subdetsels.end() or !detsel->second.isValid())
0134 (*mults)[subdet] += multiplicity(det);
0135 }
0136 for (std::map<unsigned int, DetIdSelector>::const_iterator detsel = m_subdetsels.begin();
0137 detsel != m_subdetsels.end();
0138 ++detsel) {
0139
0140 if (detsel->second.isValid() && detsel->second.isSelected(detid))
0141 (*mults)[detsel->first] += multiplicity(det);
0142 }
0143 }
0144
0145 for (std::map<unsigned int, int>::const_iterator it = mults->begin(); it != mults->end(); ++it) {
0146 LogDebug("Multiplicity") << " Found " << it->second << " digis/clusters in " << it->first << " "
0147 << m_subdets.find(it->first)->second;
0148 }
0149
0150 iEvent.put(std::move(mults));
0151 }
0152
0153 template <class T>
0154 int MultiplicityProducer<T>::multiplicity(typename T::const_iterator det) const {
0155 int mult = 0;
0156 if (m_clustersize) {
0157
0158 mult = detSetMultiplicity(det);
0159
0160 } else {
0161 mult = det->size();
0162
0163 }
0164 return mult;
0165 }
0166
0167 template <class T>
0168 int MultiplicityProducer<T>::detSetMultiplicity(typename T::const_iterator det) const {
0169 return det->size();
0170 }
0171
0172 template <>
0173 int MultiplicityProducer<edmNew::DetSetVector<SiStripCluster> >::detSetMultiplicity(
0174 edmNew::DetSetVector<SiStripCluster>::const_iterator det) const {
0175 int mult = 0;
0176
0177 for (edmNew::DetSet<SiStripCluster>::const_iterator clus = det->begin(); clus != det->end(); ++clus) {
0178
0179 mult += clus->amplitudes().size();
0180 }
0181
0182 return mult;
0183 }
0184
0185 template <>
0186 int MultiplicityProducer<edmNew::DetSetVector<SiPixelCluster> >::detSetMultiplicity(
0187 edmNew::DetSetVector<SiPixelCluster>::const_iterator det) const {
0188 int mult = 0;
0189
0190 for (edmNew::DetSet<SiPixelCluster>::const_iterator clus = det->begin(); clus != det->end(); ++clus) {
0191 mult += clus->size();
0192 }
0193
0194 return mult;
0195 }
0196
0197
0198 typedef MultiplicityProducer<edmNew::DetSetVector<SiStripCluster> > SiStripClusterMultiplicityProducer;
0199 typedef MultiplicityProducer<edmNew::DetSetVector<SiPixelCluster> > SiPixelClusterMultiplicityProducer;
0200 typedef MultiplicityProducer<edm::DetSetVector<SiStripDigi> > SiStripDigiMultiplicityProducer;
0201
0202 DEFINE_FWK_MODULE(SiStripClusterMultiplicityProducer);
0203 DEFINE_FWK_MODULE(SiPixelClusterMultiplicityProducer);
0204 DEFINE_FWK_MODULE(SiStripDigiMultiplicityProducer);