CMS 3D CMS Logo

ME0PadDigiClusterProducer.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<ME0PadDigiCollection>(pads_);
22 
23  produces<ME0PadDigiClusterCollection>();
24  consumes<ME0PadDigiCollection>(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<ME0PadDigiClusterCollection> pClusters(new ME0PadDigiClusterCollection());
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  ME0PadDigiClusterCollection &out_clusters)
58 {
59  // construct clusters
60  for (const auto& ch: geometry_->layers()) {
61 
62  // proto collection
63  std::vector<std::pair<ME0DetId, ME0PadDigiCluster> > 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  ME0PadDigiCluster 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  ME0PadDigiCluster 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
void produce(edm::Event &, const edm::EventSetup &) override
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
#define nullptr
U second(std::pair< T, U > const &p)
void beginRun(const edm::Run &, const edm::EventSetup &) override
T min(T a, T b)
Definition: MathUtil.h:58
void buildClusters(const ME0PadDigiCollection &pads, ME0PadDigiClusterCollection &out_clusters)
T const * product() const
Definition: Handle.h:81
part
Definition: HCALResponse.h:20
ME0PadDigiClusterProducer(const edm::ParameterSet &ps)
const std::vector< const ME0Layer * > & layers() const
Return a vector of all ME0 layers.
Definition: ME0Geometry.cc:54
T get() const
Definition: EventSetup.h:68
edm::EDGetTokenT< ME0PadDigiCollection > pad_token_
Name of input digi Collection.
MuonDigiCollection< ME0DetId, ME0PadDigiCluster > ME0PadDigiClusterCollection
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:44