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 beginRun(const edm::Run&, const edm::EventSetup&) override;
70 
71  void produce(edm::Event&, const edm::EventSetup&) override;
72 
73  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
74 
75 private:
76  void buildClusters(const GEMPadDigiCollection& pads, GEMPadDigiClusterContainer& out_clusters) const;
78  template <class T>
79  void checkValid(const T& cluster, const GEMDetId& id) const;
80 
85 
86  unsigned int nPartitionsGE11_;
87  unsigned int nPartitionsGE21_;
90  unsigned int nOHGE11_;
91  unsigned int nOHGE21_;
92  unsigned int maxClustersOHGE11_;
93  unsigned int maxClustersOHGE21_;
94  unsigned int maxClusterSize_;
96 
98 };
99 
101  pads_ = ps.getParameter<edm::InputTag>("InputCollection");
102  nPartitionsGE11_ = ps.getParameter<unsigned int>("nPartitionsGE11");
103  nPartitionsGE21_ = ps.getParameter<unsigned int>("nPartitionsGE21");
104  maxClustersPartitionGE11_ = ps.getParameter<unsigned int>("maxClustersPartitionGE11");
105  maxClustersPartitionGE21_ = ps.getParameter<unsigned int>("maxClustersPartitionGE21");
106  nOHGE11_ = ps.getParameter<unsigned int>("nOHGE11");
107  nOHGE21_ = ps.getParameter<unsigned int>("nOHGE21");
108  maxClustersOHGE11_ = ps.getParameter<unsigned int>("maxClustersOHGE11");
109  maxClustersOHGE21_ = ps.getParameter<unsigned int>("maxClustersOHGE21");
110  maxClusterSize_ = ps.getParameter<unsigned int>("maxClusterSize");
111  sendOverflowClusters_ = ps.getParameter<bool>("sendOverflowClusters");
112 
113  if (sendOverflowClusters_) {
114  maxClustersOHGE11_ *= 2;
115  maxClustersOHGE21_ *= 2;
116  }
117 
118  pad_token_ = consumes<GEMPadDigiCollection>(pads_);
119  geom_token_ = esConsumes<GEMGeometry, MuonGeometryRecord, edm::Transition::BeginRun>();
120 
121  produces<GEMPadDigiClusterCollection>();
122  consumes<GEMPadDigiCollection>(pads_);
123 }
124 
126 
129  desc.add<edm::InputTag>("InputCollection", edm::InputTag("simMuonGEMPadDigis"));
130  desc.add<unsigned int>("nPartitionsGE11", 4); // Number of clusterizer partitions per OH
131  desc.add<unsigned int>("nPartitionsGE21", 4); // Number of clusterizer partitions per OH
132  desc.add<unsigned int>("maxClustersPartitionGE11", 4); // Maximum number of clusters per clusterizer partition
133  desc.add<unsigned int>("maxClustersPartitionGE21", 4); // Maximum number of clusters per clusterizer partition
134  desc.add<unsigned int>("nOHGE11", 1); // Number of OH boards per chamber
135  desc.add<unsigned int>("nOHGE21", 4); // Number of OH boards per chamber
136  desc.add<unsigned int>("maxClustersOHGE11", 8); // Maximum number of clusters per OH
137  desc.add<unsigned int>("maxClustersOHGE21", 8); // Maximum number of clusters per OH
138  desc.add<unsigned int>("maxClusterSize", 8); // Maximum cluster size (number of pads)
139  desc.add<bool>("sendOverflowClusters", false);
140 
141  descriptions.add("simMuonGEMPadDigiClustersDef", desc);
142 }
143 
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 and select clusters per chamber, per OH, per partition number and per pad number
161  selectClusters(proto_clusters, *pClusters);
162 
163  // store them in the event
164  e.put(std::move(pClusters));
165 }
166 
168  GEMPadDigiClusterContainer& proto_clusters) const {
169  // clear the container
170  proto_clusters.clear();
171 
172  // construct clusters
173  for (const auto& part : geometry_->etaPartitions()) {
174  // clusters are not build for ME0
175  // -> ignore hits from station 0
176  if (part->isME0())
177  continue;
178 
179  GEMPadDigiClusters all_pad_clusters;
180 
181  auto pads = det_pads.get(part->id());
182  std::vector<uint16_t> cl;
183  int startBX = 99;
184 
185  for (auto d = pads.first; d != pads.second; ++d) {
186  // check if the input pad is valid
187  checkValid(*d, part->id());
188 
189  // number of eta partitions
190  unsigned nPart = d->nPartitions();
191 
192  if (cl.empty()) {
193  cl.push_back((*d).pad());
194  } else {
195  if ((*d).bx() == startBX and // same bunch crossing
196  (*d).pad() == cl.back() + 1 // pad difference is 1
197  and cl.size() < maxClusterSize_) { // max 8 in cluster
198  cl.push_back((*d).pad());
199  } else {
200  // put the current cluster in the proto collection
201  GEMPadDigiCluster pad_cluster(cl, startBX, part->subsystem(), nPart);
202 
203  // check if the output cluster is valid
204  checkValid(pad_cluster, part->id());
205 
206  all_pad_clusters.emplace_back(pad_cluster);
207 
208  // start a new cluster
209  cl.clear();
210  cl.push_back((*d).pad());
211  }
212  }
213  startBX = (*d).bx();
214  }
215 
216  // put the last cluster in the proto collection
217  if (pads.first != pads.second) {
218  // number of eta partitions
219  unsigned nPart = (pads.first)->nPartitions();
220 
221  GEMPadDigiCluster pad_cluster(cl, startBX, part->subsystem(), nPart);
222 
223  // check if the output cluster is valid
224  checkValid(pad_cluster, part->id());
225 
226  all_pad_clusters.emplace_back(pad_cluster);
227  }
228  proto_clusters.emplace(part->id(), all_pad_clusters);
229 
230  } // end of partition loop
231 }
232 
234  GEMPadDigiClusterCollection& out_clusters) const {
235  for (const auto& ch : geometry_->chambers()) {
236  const unsigned nOH = ch->id().isGE11() ? nOHGE11_ : nOHGE21_;
237  const unsigned nPartitions = ch->id().isGE11() ? nPartitionsGE11_ : nPartitionsGE21_;
238  const unsigned nEtaPerPartition = ch->nEtaPartitions() / (nPartitions * nOH);
239  const unsigned maxClustersPart = ch->id().isGE11() ? maxClustersPartitionGE11_ : maxClustersPartitionGE21_;
240  const unsigned maxClustersOH = ch->id().isGE11() ? maxClustersOHGE11_ : maxClustersOHGE21_;
241 
242  // loop over OH in this chamber
243  for (unsigned int iOH = 0; iOH < nOH; iOH++) {
244  unsigned int nClustersOH = 0; // Up to 8 clusters per OH
245  // loop over clusterizer partitions
246  for (unsigned int iPart = 0; iPart < nPartitions; iPart++) {
247  unsigned int nClustersPart = 0; // Up to 4 clusters per clustizer partition
248  // loop over the eta partitions for this clusterizer partition
249  for (unsigned iEta = 1; iEta <= nEtaPerPartition; iEta++) {
250  // get the clusters for this eta partition
251  const GEMDetId& iEtaId =
252  ch->etaPartition(iEta + iPart * nEtaPerPartition + iOH * nPartitions * nEtaPerPartition)->id();
253  if (proto_clusters.find(iEtaId) != proto_clusters.end()) {
254  for (const auto& cluster : proto_clusters.at(iEtaId)) {
255  if (nClustersPart < maxClustersPart and nClustersOH < maxClustersOH) {
256  checkValid(cluster, iEtaId);
257  out_clusters.insertDigi(iEtaId, cluster);
258  nClustersPart++;
259  nClustersOH++;
260  }
261  } // end of loop on clusters in eta
262  }
263  } // end of eta partition loop
264  } // end of clusterizer partition loop
265  } // end of OH loop
266  } // end of chamber loop
267 }
268 
269 template <class T>
270 void GEMPadDigiClusterProducer::checkValid(const T& tp, const GEMDetId& id) const {
271  // check if the pad/cluster is valid
272  // in principle, invalid pads/clusters can appear in the CMS raw data
273  if (!tp.isValid()) {
274  edm::LogWarning("GEMPadDigiClusterProducer") << "Invalid " << tp << " in " << id;
275  }
276 }
277 
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geom_token_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T const * product() const
Definition: Handle.h:70
void checkValid(const T &cluster, const GEMDetId &id) const
void produce(edm::Event &, const edm::EventSetup &) override
GEMPadDigiClusterProducer(const edm::ParameterSet &ps)
MuonDigiCollection< GEMDetId, GEMPadDigiCluster > GEMPadDigiClusterCollection
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const std::vector< const GEMChamber * > & chambers() const
Return a vector of all GEM chambers.
Definition: GEMGeometry.cc:38
std::map< GEMDetId, GEMPadDigiClusters > GEMPadDigiClusterContainer
d
Definition: ztail.py:151
void buildClusters(const GEMPadDigiCollection &pads, GEMPadDigiClusterContainer &out_clusters) const
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 beginRun(const edm::Run &, const edm::EventSetup &) override
edm::EDGetTokenT< GEMPadDigiCollection > pad_token_
Name of input digi Collection.
Log< level::Warning, false > LogWarning
long double T
void selectClusters(const GEMPadDigiClusterContainer &in_clusters, GEMPadDigiClusterCollection &out) const
def move(src, dest)
Definition: eostools.py:511
std::vector< GEMPadDigiCluster > GEMPadDigiClusters
Definition: Run.h:45
const std::vector< const GEMEtaPartition * > & etaPartitions() const
Return a vector of all GEM eta partitions.
Definition: GEMGeometry.cc:40