CMS 3D CMS Logo

GEMPadDigiClusterProducer.cc
Go to the documentation of this file.
8 
9 #include <string>
10 #include <map>
11 #include <vector>
12 
13 
15 : geometry_(nullptr)
16 {
17  pads_ = ps.getParameter<edm::InputTag>("InputCollection");
18  maxClusters_ = ps.getParameter<unsigned int>("maxClusters");
19  maxClusterSize_ = ps.getParameter<unsigned int>("maxClusterSize");
20 
21  pad_token_ = consumes<GEMPadDigiCollection>(pads_);
22 
23  produces<GEMPadDigiClusterCollection>();
24  consumes<GEMPadDigiCollection>(pads_);
25 }
26 
27 
29 {}
30 
31 
33 {
35  eventSetup.get<MuonGeometryRecord>().get(hGeom);
36  geometry_ = &*hGeom;
37 }
38 
39 
41 {
43  e.getByToken(pad_token_, hpads);
44 
45  // Create empty output
46  std::unique_ptr<GEMPadDigiClusterCollection> pClusters(new GEMPadDigiClusterCollection());
47 
48  // build the clusters
49  buildClusters(*(hpads.product()), *pClusters);
50 
51  // store them in the event
52  e.put(std::move(pClusters));
53 }
54 
55 
57  GEMPadDigiClusterCollection &out_clusters)
58 {
59  // construct clusters
60  for (const auto& ch: geometry_->chambers()) {
61 
62  // proto collection
63  std::vector<std::pair<GEMDetId, GEMPadDigiCluster> > proto_clusters;
64 
65  for (const auto& part: ch->etaPartitions()) {
66  auto pads = det_pads.get(part->id());
67  std::vector<uint16_t> cl;
68  int startBX = 99;
69  for (auto d = pads.first; d != pads.second; ++d) {
70  if (cl.empty()) {
71  cl.push_back((*d).pad());
72  }
73  else {
74  if ((*d).bx() == startBX and // same bunch crossing
75  (*d).pad() == cl.back() + 1 // pad difference is 1
76  and cl.size()<maxClusterSize_) { // max 8 in cluster
77  cl.push_back((*d).pad());
78  }
79  else {
80  // put the current cluster in the proto collection
81  GEMPadDigiCluster pad_cluster(cl, startBX);
82  proto_clusters.emplace_back(part->id(), pad_cluster);
83 
84  // start a new cluster
85  cl.clear();
86  cl.push_back((*d).pad());
87  }
88  }
89  startBX = (*d).bx();
90  }
91  // put the last cluster in the proto collection
92  if (pads.first != pads.second){
93  GEMPadDigiCluster pad_cluster(cl, startBX);
94  proto_clusters.emplace_back(part->id(), pad_cluster);
95  }
96  } // end of partition loop
97 
98  // cluster selection: pick first maxClusters_ for now
99  unsigned loopMax=std::min(maxClusters_,unsigned(proto_clusters.size()));
100  for ( unsigned int i=0; i<loopMax; i++) {
101  const auto& detid(proto_clusters[i].first);
102  const auto& cluster(proto_clusters[i].second);
103  out_clusters.insertDigi(detid, cluster);
104  }
105  } // end of chamber loop
106 }
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
void produce(edm::Event &, const edm::EventSetup &) override
#define nullptr
GEMPadDigiClusterProducer(const edm::ParameterSet &ps)
MuonDigiCollection< GEMDetId, GEMPadDigiCluster > GEMPadDigiClusterCollection
U second(std::pair< T, U > const &p)
void buildClusters(const GEMPadDigiCollection &pads, GEMPadDigiClusterCollection &out_clusters)
T min(T a, T b)
Definition: MathUtil.h:58
T const * product() const
Definition: Handle.h:81
part
Definition: HCALResponse.h:20
const std::vector< const GEMChamber * > & chambers() const
Return a vector of all GEM chambers.
Definition: GEMGeometry.cc:59
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:68
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:44