CMS 3D CMS Logo

GEMPadDigiClusterProducer.cc
Go to the documentation of this file.
1 
21 
26 
29 
33 
34 #include <string>
35 #include <map>
36 #include <vector>
37 
39 public:
40  // all clusters per eta partition
41  typedef std::vector<GEMPadDigiCluster> GEMPadDigiClusters;
42  typedef std::map<GEMDetId, GEMPadDigiClusters> GEMPadDigiClusterContainer;
43 
44  // all clusters sorted by chamber, by opthohybrid and by eta partition
45  typedef std::map<GEMDetId, std::vector<std::vector<std::pair<GEMDetId, GEMPadDigiClusters> > > >
47 
48  explicit GEMPadDigiClusterProducer(const edm::ParameterSet& ps);
49 
50  ~GEMPadDigiClusterProducer() override;
51 
52  void beginRun(const edm::Run&, const edm::EventSetup&) override;
53 
54  void produce(edm::Event&, const edm::EventSetup&) override;
55 
56  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
57 
58 private:
97  void buildClusters(const GEMPadDigiCollection& pads, GEMPadDigiClusterContainer& out_clusters) const;
98  void sortClusters(const GEMPadDigiClusterContainer& in_clusters,
99  GEMPadDigiClusterSortedContainer& out_clusters) const;
101 
105 
106  unsigned int maxClustersOHGE11_;
107  unsigned int maxClustersOHGE21_;
108  unsigned int nOHGE11_;
109  unsigned int nOHGE21_;
110  unsigned int maxClusterSize_;
111 
113 };
114 
116  pads_ = ps.getParameter<edm::InputTag>("InputCollection");
117  maxClustersOHGE11_ = ps.getParameter<unsigned int>("maxClustersOHGE11");
118  maxClustersOHGE21_ = ps.getParameter<unsigned int>("maxClustersOHGE21");
119  nOHGE11_ = ps.getParameter<unsigned int>("nOHGE11");
120  nOHGE21_ = ps.getParameter<unsigned int>("nOHGE21");
121  maxClusterSize_ = ps.getParameter<unsigned int>("maxClusterSize");
122 
123  pad_token_ = consumes<GEMPadDigiCollection>(pads_);
124 
125  produces<GEMPadDigiClusterCollection>();
126  consumes<GEMPadDigiCollection>(pads_);
127 }
128 
130 
133  desc.add<edm::InputTag>("InputCollection", edm::InputTag("simMuonGEMPadDigis"));
134  desc.add<unsigned int>("maxClustersOHGE11", 4);
135  desc.add<unsigned int>("maxClustersOHGE21", 5);
136  desc.add<unsigned int>("nOHGE11", 2);
137  desc.add<unsigned int>("nOHGE21", 4);
138  desc.add<unsigned int>("maxClusterSize", 8);
139 
140  descriptions.add("simMuonGEMPadDigiClustersDef", desc);
141 }
142 
145  eventSetup.get<MuonGeometryRecord>().get(hGeom);
146  geometry_ = &*hGeom;
147 }
148 
151  e.getByToken(pad_token_, hpads);
152 
153  // Create empty output
154  std::unique_ptr<GEMPadDigiClusterCollection> pClusters(new GEMPadDigiClusterCollection());
155 
156  // build the proto clusters (per partition)
157  GEMPadDigiClusterContainer proto_clusters;
158  buildClusters(*(hpads.product()), proto_clusters);
159 
160  // // sort clusters per chamber, per OH, per partition number and per pad number
161  GEMPadDigiClusterSortedContainer sorted_clusters;
162  sortClusters(proto_clusters, sorted_clusters);
163 
164  // select the clusters from sorted clusters
165  selectClusters(sorted_clusters, *pClusters);
166 
167  // store them in the event
168  e.put(std::move(pClusters));
169 }
170 
172  GEMPadDigiClusterContainer& proto_clusters) const {
173  // clear the container
174  proto_clusters.clear();
175 
176  // construct clusters
177  for (const auto& part : geometry_->etaPartitions()) {
178  GEMPadDigiClusters all_pad_clusters;
179 
180  auto pads = det_pads.get(part->id());
181  std::vector<uint16_t> cl;
182  int startBX = 99;
183 
184  for (auto d = pads.first; d != pads.second; ++d) {
185  if (cl.empty()) {
186  cl.push_back((*d).pad());
187  } else {
188  if ((*d).bx() == startBX and // same bunch crossing
189  (*d).pad() == cl.back() + 1 // pad difference is 1
190  and cl.size() < maxClusterSize_) { // max 8 in cluster
191  cl.push_back((*d).pad());
192  } else {
193  // put the current cluster in the proto collection
194  GEMPadDigiCluster pad_cluster(cl, startBX);
195 
196  all_pad_clusters.emplace_back(pad_cluster);
197 
198  // start a new cluster
199  cl.clear();
200  cl.push_back((*d).pad());
201  }
202  }
203  startBX = (*d).bx();
204  }
205 
206  // put the last cluster in the proto collection
207  if (pads.first != pads.second) {
208  GEMPadDigiCluster pad_cluster(cl, startBX);
209  all_pad_clusters.emplace_back(pad_cluster);
210  }
211  proto_clusters.emplace(part->id(), all_pad_clusters);
212 
213  } // end of partition loop
214 }
215 
217  GEMPadDigiClusterSortedContainer& sorted_clusters) const {
218  // The sorting of the clusters favors lower eta partitions and lower pad numbers
219  // By default the eta partitions are sorted by Id
220 
221  sorted_clusters.clear();
222 
223  for (const auto& ch : geometry_->chambers()) {
224  // check the station number
225  const int station = ch->id().station();
226  const bool isGE11 = (station == 1);
227  const unsigned nOH = isGE11 ? nOHGE11_ : nOHGE21_;
228  const unsigned nPartOH = ch->nEtaPartitions() / nOH;
229 
230  std::vector<std::vector<std::pair<GEMDetId, GEMPadDigiClusters> > > temp_clustersCH;
231 
232  for (unsigned int iOH = 0; iOH < nOH; iOH++) {
233  // all clusters for a set of eta partitions
234  std::vector<std::pair<GEMDetId, GEMPadDigiClusters> > temp_clustersOH;
235 
236  // loop over the 4 or 2 eta partitions for this optohybrid
237  for (unsigned iPart = 1; iPart <= nPartOH; iPart++) {
238  // get the clusters for this eta partition
239  const GEMDetId& partId = ch->etaPartition(iPart + iOH * nPartOH)->id();
240  if (proto_clusters.find(partId) != proto_clusters.end()) {
241  temp_clustersOH.emplace_back(partId, proto_clusters.at(partId));
242  }
243  } // end of eta partition loop
244 
245  temp_clustersCH.emplace_back(temp_clustersOH);
246  } // end of OH loop
247 
248  sorted_clusters.emplace(ch->id(), temp_clustersCH);
249  } // end of chamber loop
250 }
251 
253  GEMPadDigiClusterCollection& out_clusters) const {
254  // loop over chambers
255  for (const auto& ch : geometry_->chambers()) {
256  const int station = ch->id().station();
257  const bool isGE11 = (station == 1);
258  const unsigned maxClustersOH = isGE11 ? maxClustersOHGE11_ : maxClustersOHGE21_;
259 
260  // loop over the optohybrids
261  for (const auto& optohybrid : sorted_clusters.at(ch->id())) {
262  // at most maxClustersOH per OH!
263  unsigned nClusters = 0;
264 
265  // loop over the eta partitions for this OH
266  for (const auto& etapart : optohybrid) {
267  const auto& detid(etapart.first);
268  const auto& clusters(etapart.second);
269 
270  // pick the clusters with lowest pad number
271  for (const auto& clus : clusters) {
272  if (nClusters < maxClustersOH) {
273  out_clusters.insertDigi(detid, clus);
274  nClusters++;
275  }
276  } // end of cluster loop
277  } // end of eta partition loop
278  } // end of OH loop
279  } // end of chamber loop
280 }
281 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
void sortClusters(const GEMPadDigiClusterContainer &in_clusters, GEMPadDigiClusterSortedContainer &out_clusters) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
#define nullptr
std::map< GEMDetId, std::vector< std::vector< std::pair< GEMDetId, GEMPadDigiClusters > > > > GEMPadDigiClusterSortedContainer
void produce(edm::Event &, const edm::EventSetup &) override
GEMPadDigiClusterProducer(const edm::ParameterSet &ps)
MuonDigiCollection< GEMDetId, GEMPadDigiCluster > GEMPadDigiClusterCollection
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const std::vector< const GEMEtaPartition * > & etaPartitions() const
Return a vector of all GEM eta partitions.
Definition: GEMGeometry.cc:40
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::map< GEMDetId, GEMPadDigiClusters > GEMPadDigiClusterContainer
d
Definition: ztail.py:151
T const * product() const
Definition: Handle.h:69
void buildClusters(const GEMPadDigiCollection &pads, GEMPadDigiClusterContainer &out_clusters) const
part
Definition: HCALResponse.h:20
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void selectClusters(const GEMPadDigiClusterSortedContainer &in, GEMPadDigiClusterCollection &out) const
const std::vector< const GEMChamber * > & chambers() const
Return a vector of all GEM chambers.
Definition: GEMGeometry.cc:38
void beginRun(const edm::Run &, const edm::EventSetup &) override
edm::EDGetTokenT< GEMPadDigiCollection > pad_token_
Name of input digi Collection.
T get() const
Definition: EventSetup.h:73
def move(src, dest)
Definition: eostools.py:511
std::vector< GEMPadDigiCluster > GEMPadDigiClusters
Definition: Run.h:45