CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
55  int multiplicity(typename T::const_iterator det) const;
56  int detSetMultiplicity(typename T::const_iterator det) const;
57 
58  // ----------member data ---------------------------
59 
61  const bool m_clustersize;
62  std::map<unsigned int, std::string> m_subdets;
63  std::map<unsigned int, DetIdSelector> m_subdetsels;
64 };
65 
66 //
67 // constants, enums and typedefs
68 //
69 
70 //
71 // static data member definitions
72 //
73 
74 //
75 // constructors and destructor
76 //
77 template <class T>
79  : m_collectionToken(consumes<T>(iConfig.getParameter<edm::InputTag>("clusterdigiCollection"))),
80  m_clustersize(iConfig.getUntrackedParameter<bool>("withClusterSize", false)),
81  m_subdets(),
82  m_subdetsels() {
83  produces<std::map<unsigned int, int> >();
84 
85  //now do what ever other initialization is needed
86 
87  std::vector<edm::ParameterSet> wantedsubds(iConfig.getParameter<std::vector<edm::ParameterSet> >("wantedSubDets"));
88 
89  for (std::vector<edm::ParameterSet>::iterator ps = wantedsubds.begin(); ps != wantedsubds.end(); ++ps) {
90  m_subdets[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("detLabel");
91  m_subdetsels[ps->getParameter<unsigned int>("detSelection")] =
92  DetIdSelector(ps->getUntrackedParameter<std::vector<std::string> >("selection", std::vector<std::string>()));
93  }
94 }
95 
96 template <class T>
98  // do anything here that needs to be done at desctruction time
99  // (e.g. close files, deallocate resources etc.)
100 }
101 
102 //
103 // member functions
104 //
105 
106 // ------------ method called to produce the data ------------
107 template <class T>
109  LogDebug("Multiplicity") << " Ready to loop";
110 
111  using namespace edm;
112 
113  std::unique_ptr<std::map<unsigned int, int> > mults(new std::map<unsigned int, int>);
114 
115  Handle<T> digis;
116  iEvent.getByToken(m_collectionToken, digis);
117 
118  for (std::map<unsigned int, std::string>::const_iterator sdet = m_subdets.begin(); sdet != m_subdets.end(); ++sdet) {
119  (*mults)[sdet->first] = 0;
120  }
121 
122  for (typename T::const_iterator det = digis->begin(); det != digis->end(); ++det) {
123  // if(m_subdets.find(0)!=m_subdets.end()) (*mults)[0]+= det->size();
124  if (m_subdets.find(0) != m_subdets.end())
125  (*mults)[0] += multiplicity(det);
126 
127  DetId detid(det->detId());
128  unsigned int subdet = detid.subdetId();
129 
130  // if(m_subdets.find(subdet)!=m_subdets.end() && !m_subdetsels[subdet].isValid() ) (*mults)[subdet] += det->size();
131  if (m_subdets.find(subdet) != m_subdets.end()) {
132  auto detsel = m_subdetsels.find(subdet);
133  if (detsel == m_subdetsels.end() or !detsel->second.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.find(it->first)->second;
148  }
149 
150  iEvent.put(std::move(mults));
151 }
152 
153 template <class T>
154 int MultiplicityProducer<T>::multiplicity(typename T::const_iterator det) const {
155  int mult = 0;
156  if (m_clustersize) {
157  // edm::LogInfo("multiplicitywithcustersize") << "sono qua: with size";
158  mult = detSetMultiplicity(det);
159 
160  } else {
161  mult = det->size();
162  // edm::LogInfo("multiplicitywithcustersize") << "sono qua senza size";
163  }
164  return mult;
165 }
166 
167 template <class T>
168 int MultiplicityProducer<T>::detSetMultiplicity(typename T::const_iterator det) const {
169  return det->size();
170 }
171 
172 template <>
175  int mult = 0;
176 
177  for (edmNew::DetSet<SiStripCluster>::const_iterator clus = det->begin(); clus != det->end(); ++clus) {
178  // edm::LogInfo("multiplicitywithcustersize") << "sono qua";
179  mult += clus->amplitudes().size();
180  }
181 
182  return mult;
183 }
184 
185 template <>
188  int mult = 0;
189 
190  for (edmNew::DetSet<SiPixelCluster>::const_iterator clus = det->begin(); clus != det->end(); ++clus) {
191  mult += clus->size();
192  }
193 
194  return mult;
195 }
196 
197 //define this as a plug-in
201 
MultiplicityProducer< edm::DetSetVector< SiStripDigi > > SiStripDigiMultiplicityProducer
const_iterator end(bool update=false) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
int detSetMultiplicity(typename T::const_iterator det) const
data_type const * const_iterator
Definition: DetSetNew.h:31
edm::EDGetTokenT< T > m_collectionToken
MultiplicityProducer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
def move
Definition: eostools.py:511
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
MultiplicityProducer< edmNew::DetSetVector< SiStripCluster > > SiStripClusterMultiplicityProducer
Definition: DetId.h:17
std::map< unsigned int, DetIdSelector > m_subdetsels
int multiplicity(typename T::const_iterator det) const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::map< unsigned int, std::string > m_subdets
long double T
const_iterator begin(bool update=false) const
MultiplicityProducer< edmNew::DetSetVector< SiPixelCluster > > SiPixelClusterMultiplicityProducer
#define LogDebug(id)