CMS 3D CMS Logo

MultiplicityProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MultiplicityProducer
4 // Class: MultiplicityProducer
5 //
12 //
13 // Original Author: Andrea Venturi
14 // Created: Fri Dec 04 2009
15 //
16 //
17 
18 // system include files
19 #include <memory>
20 #include <string>
21 #include <map>
22 #include <vector>
23 
24 // user include files
27 
30 
34 
38 
42 
44 //
45 // class decleration
46 //
47 template <class T>
49 public:
50  explicit MultiplicityProducer(const edm::ParameterSet&);
51  ~MultiplicityProducer() override;
52 
53 private:
54  void beginJob() override;
55  void produce(edm::Event&, const edm::EventSetup&) override;
56  void endJob() override;
57  int multiplicity(typename T::const_iterator det) const;
58  int detSetMultiplicity(typename T::const_iterator det) const;
59 
60  // ----------member data ---------------------------
61 
64  std::map<unsigned int, std::string> m_subdets;
65  std::map<unsigned int, DetIdSelector> m_subdetsels;
66 };
67 
68 //
69 // constants, enums and typedefs
70 //
71 
72 //
73 // static data member definitions
74 //
75 
76 //
77 // constructors and destructor
78 //
79 template <class T>
81  : m_collectionToken(consumes<T>(iConfig.getParameter<edm::InputTag>("clusterdigiCollection"))),
82  m_clustersize(iConfig.getUntrackedParameter<bool>("withClusterSize", false)),
83  m_subdets(),
84  m_subdetsels() {
85  produces<std::map<unsigned int, int> >();
86 
87  //now do what ever other initialization is needed
88 
89  std::vector<edm::ParameterSet> wantedsubds(iConfig.getParameter<std::vector<edm::ParameterSet> >("wantedSubDets"));
90 
91  for (std::vector<edm::ParameterSet>::iterator ps = wantedsubds.begin(); ps != wantedsubds.end(); ++ps) {
92  m_subdets[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("detLabel");
93  m_subdetsels[ps->getParameter<unsigned int>("detSelection")] =
94  DetIdSelector(ps->getUntrackedParameter<std::vector<std::string> >("selection", std::vector<std::string>()));
95  }
96 }
97 
98 template <class T>
100  // do anything here that needs to be done at desctruction time
101  // (e.g. close files, deallocate resources etc.)
102 }
103 
104 //
105 // member functions
106 //
107 
108 // ------------ method called to produce the data ------------
109 template <class T>
111  LogDebug("Multiplicity") << " Ready to loop";
112 
113  using namespace edm;
114 
115  std::unique_ptr<std::map<unsigned int, int> > mults(new std::map<unsigned int, int>);
116 
117  Handle<T> digis;
118  iEvent.getByToken(m_collectionToken, digis);
119 
120  for (std::map<unsigned int, std::string>::const_iterator sdet = m_subdets.begin(); sdet != m_subdets.end(); ++sdet) {
121  (*mults)[sdet->first] = 0;
122  }
123 
124  for (typename T::const_iterator det = digis->begin(); det != digis->end(); ++det) {
125  // if(m_subdets.find(0)!=m_subdets.end()) (*mults)[0]+= det->size();
126  if (m_subdets.find(0) != m_subdets.end())
127  (*mults)[0] += multiplicity(det);
128 
129  DetId detid(det->detId());
130  unsigned int subdet = detid.subdetId();
131 
132  // if(m_subdets.find(subdet)!=m_subdets.end() && !m_subdetsels[subdet].isValid() ) (*mults)[subdet] += det->size();
133  if (m_subdets.find(subdet) != m_subdets.end() && !m_subdetsels[subdet].isValid())
134  (*mults)[subdet] += multiplicity(det);
135 
136  for (std::map<unsigned int, DetIdSelector>::const_iterator detsel = m_subdetsels.begin();
137  detsel != m_subdetsels.end();
138  ++detsel) {
139  // if(detsel->second.isValid() && detsel->second.isSelected(detid)) (*mults)[detsel->first] += det->size();
140  if (detsel->second.isValid() && detsel->second.isSelected(detid))
141  (*mults)[detsel->first] += multiplicity(det);
142  }
143  }
144 
145  for (std::map<unsigned int, int>::const_iterator it = mults->begin(); it != mults->end(); ++it) {
146  LogDebug("Multiplicity") << " Found " << it->second << " digis/clusters in " << it->first << " "
147  << m_subdets[it->first];
148  }
149 
150  iEvent.put(std::move(mults));
151 }
152 
153 // ------------ method called once each job just before starting event loop ------------
154 template <class T>
156 
157 // ------------ method called once each job just after ending the event loop ------------
158 template <class T>
160 
161 template <class T>
162 int MultiplicityProducer<T>::multiplicity(typename T::const_iterator det) const {
163  int mult = 0;
164  if (m_clustersize) {
165  // edm::LogInfo("multiplicitywithcustersize") << "sono qua: with size";
166  mult = detSetMultiplicity(det);
167 
168  } else {
169  mult = det->size();
170  // edm::LogInfo("multiplicitywithcustersize") << "sono qua senza size";
171  }
172  return mult;
173 }
174 
175 template <class T>
176 int MultiplicityProducer<T>::detSetMultiplicity(typename T::const_iterator det) const {
177  return det->size();
178 }
179 
180 template <>
183  int mult = 0;
184 
185  for (edmNew::DetSet<SiStripCluster>::const_iterator clus = det->begin(); clus != det->end(); ++clus) {
186  // edm::LogInfo("multiplicitywithcustersize") << "sono qua";
187  mult += clus->amplitudes().size();
188  }
189 
190  return mult;
191 }
192 
193 template <>
196  int mult = 0;
197 
198  for (edmNew::DetSet<SiPixelCluster>::const_iterator clus = det->begin(); clus != det->end(); ++clus) {
199  mult += clus->size();
200  }
201 
202  return mult;
203 }
204 
205 //define this as a plug-in
209 
MultiplicityProducer::multiplicity
int multiplicity(typename T::const_iterator det) const
Definition: MultiplicityProducer.cc:162
electrons_cff.bool
bool
Definition: electrons_cff.py:372
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
EDProducer.h
MultiplicityProducer::m_subdetsels
std::map< unsigned int, DetIdSelector > m_subdetsels
Definition: MultiplicityProducer.cc:65
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
SiPixelCluster.h
edmNew::DetSetVector::const_iterator
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetSetVectorNew.h:231
MultiplicityProducer::m_collectionToken
edm::EDGetTokenT< T > m_collectionToken
Definition: MultiplicityProducer.cc:62
edmNew::DetSetVector::begin
const_iterator begin(bool update=false) const
Definition: DetSetVectorNew.h:572
DetIdSelector.h
MultiplicityProducer::detSetMultiplicity
int detSetMultiplicity(typename T::const_iterator det) const
Definition: MultiplicityProducer.cc:176
edm::Handle
Definition: AssociativeIterator.h:50
DetId
Definition: DetId.h:17
MakerMacros.h
MultiplicityProducer::~MultiplicityProducer
~MultiplicityProducer() override
Definition: MultiplicityProducer.cc:99
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SiStripDigi.h
MultiplicityProducer::m_subdets
std::map< unsigned int, std::string > m_subdets
Definition: MultiplicityProducer.cc:64
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
MultiplicityProducer::beginJob
void beginJob() override
Definition: MultiplicityProducer.cc:155
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
MultiplicityProducer::MultiplicityProducer
MultiplicityProducer(const edm::ParameterSet &)
Definition: MultiplicityProducer.cc:80
SiStripCluster.h
Event.h
SiStripClusterMultiplicityProducer
MultiplicityProducer< edmNew::DetSetVector< SiStripCluster > > SiStripClusterMultiplicityProducer
Definition: MultiplicityProducer.cc:206
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
DetSetVector.h
InputTag.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
SiStripDigiMultiplicityProducer
MultiplicityProducer< edm::DetSetVector< SiStripDigi > > SiStripDigiMultiplicityProducer
Definition: MultiplicityProducer.cc:208
MultiplicityProducer::endJob
void endJob() override
Definition: MultiplicityProducer.cc:159
eostools.move
def move(src, dest)
Definition: eostools.py:511
DetId.h
Frameworkfwd.h
T
long double T
Definition: Basic3DVectorLD.h:48
edmNew::DetSetVector::end
const_iterator end(bool update=false) const
Definition: DetSetVectorNew.h:577
edm::EDProducer
Definition: EDProducer.h:36
VarParsing.mult
mult
Definition: VarParsing.py:659
MultiplicityProducer::m_clustersize
bool m_clustersize
Definition: MultiplicityProducer.cc:63
MultiplicityProducer
Definition: MultiplicityProducer.cc:48
ParameterSet.h
edm::Event
Definition: Event.h:73
SiPixelClusterMultiplicityProducer
MultiplicityProducer< edmNew::DetSetVector< SiPixelCluster > > SiPixelClusterMultiplicityProducer
Definition: MultiplicityProducer.cc:207
DetSetVectorNew.h
DetIdSelector
Definition: DetIdSelector.h:12
MultiplicityProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: MultiplicityProducer.cc:110
edmNew::DetSet::const_iterator
const data_type * const_iterator
Definition: DetSetNew.h:31