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 
19 // system include files
20 #include <memory>
21 #include <string>
22 #include <map>
23 #include <vector>
24 
25 // user include files
28 
31 
35 
39 
43 
45 //
46 // class decleration
47 //
48 template <class T>
50 
51 public:
52  explicit MultiplicityProducer(const edm::ParameterSet&);
54 
55 private:
56  virtual void beginJob() override ;
57  virtual void produce(edm::Event&, const edm::EventSetup&) override;
58  virtual void endJob() override ;
59  int multiplicity(typename T::const_iterator det) const;
60  int detSetMultiplicity(typename T::const_iterator det) const;
61 
62  // ----------member data ---------------------------
63 
66  std::map<unsigned int, std::string> m_subdets;
67  std::map<unsigned int, DetIdSelector> m_subdetsels;
68 
69 };
70 
71 //
72 // constants, enums and typedefs
73 //
74 
75 
76 //
77 // static data member definitions
78 //
79 
80 //
81 // constructors and destructor
82 //
83 template <class T>
85  m_collectionToken(consumes<T>(iConfig.getParameter<edm::InputTag>("clusterdigiCollection"))),
86  m_clustersize(iConfig.getUntrackedParameter<bool>("withClusterSize",false)),
88 {
89 
90  produces<std::map<unsigned int,int> >();
91 
92  //now do what ever other initialization is needed
93 
94  std::vector<edm::ParameterSet> wantedsubds(iConfig.getParameter<std::vector<edm::ParameterSet> >("wantedSubDets"));
95 
96  for(std::vector<edm::ParameterSet>::iterator ps=wantedsubds.begin();ps!=wantedsubds.end();++ps) {
97  m_subdets[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("detLabel");
98  m_subdetsels[ps->getParameter<unsigned int>("detSelection")] =
99  DetIdSelector(ps->getUntrackedParameter<std::vector<std::string> >("selection",std::vector<std::string>()));
100  }
101 }
102 
103 template <class T>
105 {
106 
107  // do anything here that needs to be done at desctruction time
108  // (e.g. close files, deallocate resources etc.)
109 
110 }
111 
112 
113 //
114 // member functions
115 //
116 
117 // ------------ method called to produce the data ------------
118 template <class T>
119 void
121 {
122 
123  LogDebug("Multiplicity") << " Ready to loop";
124 
125  using namespace edm;
126 
127  std::unique_ptr<std::map<unsigned int,int> > mults(new std::map<unsigned int,int> );
128 
129 
130  Handle<T> digis;
131  iEvent.getByToken(m_collectionToken,digis);
132 
133  for(std::map<unsigned int,std::string>::const_iterator sdet=m_subdets.begin();sdet!=m_subdets.end();++sdet) { (*mults)[sdet->first]=0; }
134 
135 
136  for(typename T::const_iterator det = digis->begin();det!=digis->end();++det) {
137 
138  // if(m_subdets.find(0)!=m_subdets.end()) (*mults)[0]+= det->size();
139  if(m_subdets.find(0)!=m_subdets.end()) (*mults)[0]+= multiplicity(det);
140 
141  DetId detid(det->detId());
142  unsigned int subdet = detid.subdetId();
143 
144  // if(m_subdets.find(subdet)!=m_subdets.end() && !m_subdetsels[subdet].isValid() ) (*mults)[subdet] += det->size();
145  if(m_subdets.find(subdet)!=m_subdets.end() && !m_subdetsels[subdet].isValid() ) (*mults)[subdet] += multiplicity(det);
146 
147  for(std::map<unsigned int,DetIdSelector>::const_iterator detsel=m_subdetsels.begin();detsel!=m_subdetsels.end();++detsel) {
148 
149  // if(detsel->second.isValid() && detsel->second.isSelected(detid)) (*mults)[detsel->first] += det->size();
150  if(detsel->second.isValid() && detsel->second.isSelected(detid)) (*mults)[detsel->first] += multiplicity(det);
151 
152  }
153 
154  }
155 
156 
157  for(std::map<unsigned int,int>::const_iterator it=mults->begin();it!=mults->end();++it) {
158  LogDebug("Multiplicity") << " Found " << it->second << " digis/clusters in " << it->first << " " << m_subdets[it->first];
159  }
160 
161  iEvent.put(std::move(mults));
162 
163 }
164 
165 // ------------ method called once each job just before starting event loop ------------
166 template <class T>
167 void
169 {
170 }
171 
172 // ------------ method called once each job just after ending the event loop ------------
173 template <class T>
174 void
176 }
177 
178 template <class T>
179 int
180 MultiplicityProducer<T>::multiplicity(typename T::const_iterator det) const {
181 
182  int mult = 0;
183  if(m_clustersize) {
184 
185 
186  // edm::LogInfo("multiplicitywithcustersize") << "sono qua: with size";
187  mult = detSetMultiplicity(det);
188 
189  }
190  else {
191 
192  mult = det->size();
193  // edm::LogInfo("multiplicitywithcustersize") << "sono qua senza size";
194 
195  }
196  return mult;
197 }
198 
199 
200 template <class T>
201 int
202 MultiplicityProducer<T>::detSetMultiplicity(typename T::const_iterator det) const {
203 
204  return det->size();
205 
206 }
207 
208 
209 template <>
210 int
212 
213  int mult = 0;
214 
215  for(edmNew::DetSet<SiStripCluster>::const_iterator clus=det->begin();clus!=det->end();++clus) {
216 
217  // edm::LogInfo("multiplicitywithcustersize") << "sono qua";
218  mult += clus->amplitudes().size();
219 
220 
221 
222  }
223 
224  return mult;
225 
226 }
227 
228 template <>
229 int
231 
232  int mult = 0;
233 
234  for(edmNew::DetSet<SiPixelCluster>::const_iterator clus=det->begin();clus!=det->end();++clus) {
235 
236  mult += clus->size();
237 
238  }
239 
240  return mult;
241 
242 }
243 
244 //define this as a plug-in
248 
249 
#define LogDebug(id)
T getParameter(std::string const &) const
MultiplicityProducer< edm::DetSetVector< SiStripDigi > > SiStripDigiMultiplicityProducer
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator end(bool update=false) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int detSetMultiplicity(typename T::const_iterator det) const
data_type const * const_iterator
Definition: DetSetNew.h:30
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< T > m_collectionToken
MultiplicityProducer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:230
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
virtual void produce(edm::Event &, const edm::EventSetup &) override
MultiplicityProducer< edmNew::DetSetVector< SiStripCluster > > SiStripClusterMultiplicityProducer
Definition: DetId.h:18
std::map< unsigned int, DetIdSelector > m_subdetsels
int multiplicity(typename T::const_iterator det) const
HLT enums.
virtual void beginJob() override
std::map< unsigned int, std::string > m_subdets
long double T
virtual void endJob() override
def move(src, dest)
Definition: eostools.py:510
const_iterator begin(bool update=false) const
MultiplicityProducer< edmNew::DetSetVector< SiPixelCluster > > SiPixelClusterMultiplicityProducer