CMS 3D CMS Logo

GEMPadDigiClusterProducer.cc
Go to the documentation of this file.
1 
42 
48 
51 
55 
56 #include <string>
57 #include <map>
58 #include <vector>
59 
61 public:
62  typedef std::vector<GEMPadDigiCluster> GEMPadDigiClusters;
63  typedef std::map<GEMDetId, GEMPadDigiClusters> GEMPadDigiClusterContainer;
64 
65  explicit GEMPadDigiClusterProducer(const edm::ParameterSet& ps);
66 
67  ~GEMPadDigiClusterProducer() override;
68 
69  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
70 
71  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
72 
73 private:
76  template <class T>
77  void checkValid(const T& cluster, const GEMDetId& id) const;
78 
84 
85  unsigned int nPartitionsGE11_;
86  unsigned int nPartitionsGE21_;
89  unsigned int nOHGE11_;
90  unsigned int nOHGE21_;
91  unsigned int maxClustersOHGE11_;
92  unsigned int maxClustersOHGE21_;
93  unsigned int maxClusterSize_;
95 };
96 
98  pads_ = ps.getParameter<edm::InputTag>("InputCollection");
99  nPartitionsGE11_ = ps.getParameter<unsigned int>("nPartitionsGE11");
100  nPartitionsGE21_ = ps.getParameter<unsigned int>("nPartitionsGE21");
101  maxClustersPartitionGE11_ = ps.getParameter<unsigned int>("maxClustersPartitionGE11");
102  maxClustersPartitionGE21_ = ps.getParameter<unsigned int>("maxClustersPartitionGE21");
103  nOHGE11_ = ps.getParameter<unsigned int>("nOHGE11");
104  nOHGE21_ = ps.getParameter<unsigned int>("nOHGE21");
105  maxClustersOHGE11_ = ps.getParameter<unsigned int>("maxClustersOHGE11");
106  maxClustersOHGE21_ = ps.getParameter<unsigned int>("maxClustersOHGE21");
107  maxClusterSize_ = ps.getParameter<unsigned int>("maxClusterSize");
108  sendOverflowClusters_ = ps.getParameter<bool>("sendOverflowClusters");
109 
110  if (sendOverflowClusters_) {
111  maxClustersOHGE11_ *= 2;
112  maxClustersOHGE21_ *= 2;
113  }
114 
115  pad_token_ = consumes<GEMPadDigiCollection>(pads_);
116  geom_token_ = esConsumes<GEMGeometry, MuonGeometryRecord>();
117 
118  put_token_ = produces<GEMPadDigiClusterCollection>();
119 }
120 
122 
125  desc.add<edm::InputTag>("InputCollection", edm::InputTag("simMuonGEMPadDigis"));
126  desc.add<unsigned int>("nPartitionsGE11", 4); // Number of clusterizer partitions per OH
127  desc.add<unsigned int>("nPartitionsGE21", 4); // Number of clusterizer partitions per OH
128  desc.add<unsigned int>("maxClustersPartitionGE11", 4); // Maximum number of clusters per clusterizer partition
129  desc.add<unsigned int>("maxClustersPartitionGE21", 4); // Maximum number of clusters per clusterizer partition
130  desc.add<unsigned int>("nOHGE11", 1); // Number of OH boards per chamber
131  desc.add<unsigned int>("nOHGE21", 4); // Number of OH boards per chamber
132  desc.add<unsigned int>("maxClustersOHGE11", 8); // Maximum number of clusters per OH
133  desc.add<unsigned int>("maxClustersOHGE21", 8); // Maximum number of clusters per OH
134  desc.add<unsigned int>("maxClusterSize", 8); // Maximum cluster size (number of pads)
135  desc.add<bool>("sendOverflowClusters", false);
136 
137  descriptions.add("simMuonGEMPadDigiClustersDef", desc);
138 }
139 
141  auto const& geometry = eventSetup.getData(geom_token_);
142 
143  auto const& pads = e.get(pad_token_);
144 
145  // build the proto clusters (per partition)
146  GEMPadDigiClusterContainer proto_clusters = buildClusters(pads, geometry);
147 
148  // sort and select clusters per chamber, per OH, per partition number and per pad number
149  e.emplace(put_token_, selectClusters(proto_clusters, geometry));
150 }
151 
153  const GEMPadDigiCollection& det_pads, const GEMGeometry& geometry) const {
154  GEMPadDigiClusterContainer proto_clusters;
155 
156  // construct clusters
157  for (const auto& part : geometry.etaPartitions()) {
158  // clusters are not build for ME0
159  // -> ignore hits from station 0
160  if (part->isME0())
161  continue;
162 
163  GEMPadDigiClusters all_pad_clusters;
164 
165  auto pads = det_pads.get(part->id());
166  std::vector<uint16_t> cl;
167  int startBX = 99;
168 
169  for (auto d = pads.first; d != pads.second; ++d) {
170  // check if the input pad is valid
171  checkValid(*d, part->id());
172 
173  // number of eta partitions
174  unsigned nPart = d->nPartitions();
175 
176  if (cl.empty()) {
177  cl.push_back((*d).pad());
178  } else {
179  if ((*d).bx() == startBX and // same bunch crossing
180  (*d).pad() == cl.back() + 1 // pad difference is 1
181  and cl.size() < maxClusterSize_) { // max 8 in cluster
182  cl.push_back((*d).pad());
183  } else {
184  // put the current cluster in the proto collection
185  GEMPadDigiCluster pad_cluster(cl, startBX, part->subsystem(), nPart);
186 
187  // check if the output cluster is valid
188  checkValid(pad_cluster, part->id());
189 
190  all_pad_clusters.emplace_back(pad_cluster);
191 
192  // start a new cluster
193  cl.clear();
194  cl.push_back((*d).pad());
195  }
196  }
197  startBX = (*d).bx();
198  }
199 
200  // put the last cluster in the proto collection
201  if (pads.first != pads.second) {
202  // number of eta partitions
203  unsigned nPart = (pads.first)->nPartitions();
204 
205  GEMPadDigiCluster pad_cluster(cl, startBX, part->subsystem(), nPart);
206 
207  // check if the output cluster is valid
208  checkValid(pad_cluster, part->id());
209 
210  all_pad_clusters.emplace_back(pad_cluster);
211  }
212  proto_clusters.emplace(part->id(), all_pad_clusters);
213 
214  } // end of partition loop
215  return proto_clusters;
216 }
217 
219  const GEMGeometry& geometry) const {
220  GEMPadDigiClusterCollection out_clusters;
221  for (const auto& ch : geometry.chambers()) {
222  const unsigned nOH = ch->id().isGE11() ? nOHGE11_ : nOHGE21_;
223  const unsigned nPartitions = ch->id().isGE11() ? nPartitionsGE11_ : nPartitionsGE21_;
224  const unsigned nEtaPerPartition = ch->nEtaPartitions() / (nPartitions * nOH);
225  const unsigned maxClustersPart = ch->id().isGE11() ? maxClustersPartitionGE11_ : maxClustersPartitionGE21_;
226  const unsigned maxClustersOH = ch->id().isGE11() ? maxClustersOHGE11_ : maxClustersOHGE21_;
227 
228  // loop over OH in this chamber
229  for (unsigned int iOH = 0; iOH < nOH; iOH++) {
230  unsigned int nClustersOH = 0; // Up to 8 clusters per OH
231  // loop over clusterizer partitions
232  for (unsigned int iPart = 0; iPart < nPartitions; iPart++) {
233  unsigned int nClustersPart = 0; // Up to 4 clusters per clustizer partition
234  // loop over the eta partitions for this clusterizer partition
235  for (unsigned iEta = 1; iEta <= nEtaPerPartition; iEta++) {
236  // get the clusters for this eta partition
237  const GEMDetId& iEtaId =
238  ch->etaPartition(iEta + iPart * nEtaPerPartition + iOH * nPartitions * nEtaPerPartition)->id();
239  if (proto_clusters.find(iEtaId) != proto_clusters.end()) {
240  for (const auto& cluster : proto_clusters.at(iEtaId)) {
241  if (nClustersPart < maxClustersPart and nClustersOH < maxClustersOH) {
242  checkValid(cluster, iEtaId);
243  out_clusters.insertDigi(iEtaId, cluster);
244  nClustersPart++;
245  nClustersOH++;
246  }
247  } // end of loop on clusters in eta
248  }
249  } // end of eta partition loop
250  } // end of clusterizer partition loop
251  } // end of OH loop
252  } // end of chamber loop
253  return out_clusters;
254 }
255 
256 template <class T>
257 void GEMPadDigiClusterProducer::checkValid(const T& tp, const GEMDetId& id) const {
258  // check if the pad/cluster is valid
259  // in principle, invalid pads/clusters can appear in the CMS raw data
260  if (!tp.isValid()) {
261  edm::LogWarning("GEMPadDigiClusterProducer") << "Invalid " << tp << " in " << id;
262  }
263 }
264 
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
GEMPadDigiClusterCollection selectClusters(const GEMPadDigiClusterContainer &in_clusters, const GEMGeometry &) const
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geom_token_
edm::EDPutTokenT< GEMPadDigiClusterCollection > put_token_
void checkValid(const T &cluster, const GEMDetId &id) const
GEMPadDigiClusterProducer(const edm::ParameterSet &ps)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::map< GEMDetId, GEMPadDigiClusters > GEMPadDigiClusterContainer
d
Definition: ztail.py:151
TString nPart(Int_t part, TString string, TString delimit=";", Bool_t removerest=true)
part
Definition: HCALResponse.h:20
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
edm::EDGetTokenT< GEMPadDigiCollection > pad_token_
Name of input digi Collection.
Log< level::Warning, false > LogWarning
GEMPadDigiClusterContainer buildClusters(const GEMPadDigiCollection &pads, const GEMGeometry &) const
long double T
std::vector< GEMPadDigiCluster > GEMPadDigiClusters