CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GEMPadDigiClusterProducer.cc
Go to the documentation of this file.
1 
21 
27 
30 
34 
35 #include <string>
36 #include <map>
37 #include <vector>
38 
40 public:
41  // all clusters per eta partition
42  typedef std::vector<GEMPadDigiCluster> GEMPadDigiClusters;
43  typedef std::map<GEMDetId, GEMPadDigiClusters> GEMPadDigiClusterContainer;
44 
45  // all clusters sorted by chamber, by opthohybrid and by eta partition
46  typedef std::map<GEMDetId, std::vector<std::vector<std::pair<GEMDetId, GEMPadDigiClusters> > > >
48 
49  explicit GEMPadDigiClusterProducer(const edm::ParameterSet& ps);
50 
51  ~GEMPadDigiClusterProducer() override;
52 
53  void beginRun(const edm::Run&, const edm::EventSetup&) override;
54 
55  void produce(edm::Event&, const edm::EventSetup&) override;
56 
57  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
58 
59 private:
98  void buildClusters(const GEMPadDigiCollection& pads, GEMPadDigiClusterContainer& out_clusters) const;
99  void sortClusters(const GEMPadDigiClusterContainer& in_clusters,
100  GEMPadDigiClusterSortedContainer& out_clusters) const;
102  template <class T>
103  void checkValid(const T& cluster, const GEMDetId& id) const;
104 
109 
110  unsigned int maxClustersOHGE11_;
111  unsigned int maxClustersOHGE21_;
112  unsigned int nOHGE11_;
113  unsigned int nOHGE21_;
114  unsigned int maxClusterSize_;
116 
118 };
119 
121  pads_ = ps.getParameter<edm::InputTag>("InputCollection");
122  maxClustersOHGE11_ = ps.getParameter<unsigned int>("maxClustersOHGE11");
123  maxClustersOHGE21_ = ps.getParameter<unsigned int>("maxClustersOHGE21");
124  nOHGE11_ = ps.getParameter<unsigned int>("nOHGE11");
125  nOHGE21_ = ps.getParameter<unsigned int>("nOHGE21");
126  maxClusterSize_ = ps.getParameter<unsigned int>("maxClusterSize");
127  sendOverflowClusters_ = ps.getParameter<bool>("sendOverflowClusters");
128 
129  if (sendOverflowClusters_) {
130  maxClustersOHGE11_ *= 2;
131  maxClustersOHGE21_ *= 2;
132  }
133 
134  pad_token_ = consumes<GEMPadDigiCollection>(pads_);
135  geom_token_ = esConsumes<GEMGeometry, MuonGeometryRecord, edm::Transition::BeginRun>();
136 
137  produces<GEMPadDigiClusterCollection>();
138  consumes<GEMPadDigiCollection>(pads_);
139 }
140 
142 
145  desc.add<edm::InputTag>("InputCollection", edm::InputTag("simMuonGEMPadDigis"));
146  desc.add<unsigned int>("maxClustersOHGE11", 4);
147  desc.add<unsigned int>("maxClustersOHGE21", 5);
148  desc.add<unsigned int>("nOHGE11", 2);
149  desc.add<unsigned int>("nOHGE21", 4);
150  desc.add<unsigned int>("maxClusterSize", 8);
151  desc.add<bool>("sendOverflowClusters", false);
152 
153  descriptions.add("simMuonGEMPadDigiClustersDef", desc);
154 }
155 
158  geometry_ = &*hGeom;
159 }
160 
163  e.getByToken(pad_token_, hpads);
164 
165  // Create empty output
166  std::unique_ptr<GEMPadDigiClusterCollection> pClusters(new GEMPadDigiClusterCollection());
167 
168  // build the proto clusters (per partition)
169  GEMPadDigiClusterContainer proto_clusters;
170  buildClusters(*(hpads.product()), proto_clusters);
171 
172  // // sort clusters per chamber, per OH, per partition number and per pad number
173  GEMPadDigiClusterSortedContainer sorted_clusters;
174  sortClusters(proto_clusters, sorted_clusters);
175 
176  // select the clusters from sorted clusters
177  selectClusters(sorted_clusters, *pClusters);
178 
179  // store them in the event
180  e.put(std::move(pClusters));
181 }
182 
184  GEMPadDigiClusterContainer& proto_clusters) const {
185  // clear the container
186  proto_clusters.clear();
187 
188  // construct clusters
189  for (const auto& part : geometry_->etaPartitions()) {
190  // clusters are not build for ME0
191  // -> ignore hits from station 0
192  if (part->isME0())
193  continue;
194 
195  GEMPadDigiClusters all_pad_clusters;
196 
197  auto pads = det_pads.get(part->id());
198  std::vector<uint16_t> cl;
199  int startBX = 99;
200 
201  for (auto d = pads.first; d != pads.second; ++d) {
202  // check if the input pad is valid
203  checkValid(*d, part->id());
204 
205  // number of eta partitions
206  unsigned nPart = d->nPartitions();
207 
208  if (cl.empty()) {
209  cl.push_back((*d).pad());
210  } else {
211  if ((*d).bx() == startBX and // same bunch crossing
212  (*d).pad() == cl.back() + 1 // pad difference is 1
213  and cl.size() < maxClusterSize_) { // max 8 in cluster
214  cl.push_back((*d).pad());
215  } else {
216  // put the current cluster in the proto collection
217  GEMPadDigiCluster pad_cluster(cl, startBX, part->subsystem(), nPart);
218 
219  // check if the output cluster is valid
220  checkValid(pad_cluster, part->id());
221 
222  all_pad_clusters.emplace_back(pad_cluster);
223 
224  // start a new cluster
225  cl.clear();
226  cl.push_back((*d).pad());
227  }
228  }
229  startBX = (*d).bx();
230  }
231 
232  // put the last cluster in the proto collection
233  if (pads.first != pads.second) {
234  // number of eta partitions
235  unsigned nPart = (pads.first)->nPartitions();
236 
237  GEMPadDigiCluster pad_cluster(cl, startBX, part->subsystem(), nPart);
238 
239  // check if the output cluster is valid
240  checkValid(pad_cluster, part->id());
241 
242  all_pad_clusters.emplace_back(pad_cluster);
243  }
244  proto_clusters.emplace(part->id(), all_pad_clusters);
245 
246  } // end of partition loop
247 }
248 
250  GEMPadDigiClusterSortedContainer& sorted_clusters) const {
251  // The sorting of the clusters favors lower eta partitions and lower pad numbers
252  // By default the eta partitions are sorted by Id
253 
254  sorted_clusters.clear();
255 
256  for (const auto& ch : geometry_->chambers()) {
257  // check the station number
258  const unsigned nOH = ch->id().isGE11() ? nOHGE11_ : nOHGE21_;
259  const unsigned nPartOH = ch->nEtaPartitions() / nOH;
260 
261  std::vector<std::vector<std::pair<GEMDetId, GEMPadDigiClusters> > > temp_clustersCH;
262 
263  for (unsigned int iOH = 0; iOH < nOH; iOH++) {
264  // all clusters for a set of eta partitions
265  std::vector<std::pair<GEMDetId, GEMPadDigiClusters> > temp_clustersOH;
266 
267  // loop over the 4 or 2 eta partitions for this optohybrid
268  for (unsigned iPart = 1; iPart <= nPartOH; iPart++) {
269  // get the clusters for this eta partition
270  const GEMDetId& partId = ch->etaPartition(iPart + iOH * nPartOH)->id();
271  if (proto_clusters.find(partId) != proto_clusters.end()) {
272  temp_clustersOH.emplace_back(partId, proto_clusters.at(partId));
273  }
274  } // end of eta partition loop
275 
276  temp_clustersCH.emplace_back(temp_clustersOH);
277  } // end of OH loop
278 
279  sorted_clusters.emplace(ch->id(), temp_clustersCH);
280  } // end of chamber loop
281 }
282 
284  GEMPadDigiClusterCollection& out_clusters) const {
285  // loop over chambers
286  for (const auto& ch : geometry_->chambers()) {
287  const unsigned maxClustersOH = ch->id().isGE11() ? maxClustersOHGE11_ : maxClustersOHGE21_;
288 
289  // loop over the optohybrids
290  for (const auto& optohybrid : sorted_clusters.at(ch->id())) {
291  // at most maxClustersOH per OH!
292  unsigned nClusters = 0;
293 
294  // loop over the eta partitions for this OH
295  for (const auto& etapart : optohybrid) {
296  const auto& detid(etapart.first);
297  const auto& clusters(etapart.second);
298 
299  // pick the clusters with lowest pad number
300  for (const auto& clus : clusters) {
301  if (nClusters < maxClustersOH) {
302  // check if the output cluster is valid
303  checkValid(clus, detid);
304 
305  out_clusters.insertDigi(detid, clus);
306  nClusters++;
307  }
308  } // end of cluster loop
309  } // end of eta partition loop
310  } // end of OH loop
311  } // end of chamber loop
312 }
313 
314 template <class T>
315 void GEMPadDigiClusterProducer::checkValid(const T& tp, const GEMDetId& id) const {
316  // check if the pad/cluster is valid
317  // in principle, invalid pads/clusters can appear in the CMS raw data
318  if (!tp.isValid()) {
319  edm::LogWarning("GEMPadDigiClusterProducer") << "Invalid " << tp << " in " << id;
320  }
321 }
322 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void sortClusters(const GEMPadDigiClusterContainer &in_clusters, GEMPadDigiClusterSortedContainer &out_clusters) const
uint16_t *__restrict__ id
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geom_token_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
tuple cl
Definition: haddnano.py:49
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
tuple d
Definition: ztail.py:151
def move
Definition: eostools.py:511
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
TString nPart(Int_t part, TString string, TString delimit=";", Bool_t removerest=true)
T const * product() const
Definition: Handle.h:70
void buildClusters(const GEMPadDigiCollection &pads, GEMPadDigiClusterContainer &out_clusters) const
part
Definition: HCALResponse.h:20
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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.
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
Log< level::Warning, false > LogWarning
void checkValid(const T &cluster, const GEMDetId &id) const
long double T
std::vector< GEMPadDigiCluster > GEMPadDigiClusters
Definition: Run.h:45