CMS 3D CMS Logo

HcalDetIdTableProducer.cc
Go to the documentation of this file.
1 #include <memory>
2 
11 
14 
24 
25 class HcalDetIdTableProducer : public edm::global::EDProducer<edm::BeginRunProducer> {
26 private:
32 
33 public:
34  explicit HcalDetIdTableProducer(const edm::ParameterSet& iConfig)
36  hbDetIdListToken_ = produces<std::vector<HcalDetId>, edm::Transition::BeginRun>("HBDetIdList");
37  heDetIdListToken_ = produces<std::vector<HcalDetId>, edm::Transition::BeginRun>("HEDetIdList");
38  hfDetIdListToken_ = produces<std::vector<HcalDetId>, edm::Transition::BeginRun>("HFDetIdList");
39  hoDetIdListToken_ = produces<std::vector<HcalDetId>, edm::Transition::BeginRun>("HODetIdList");
40 
41  produces<nanoaod::FlatTable, edm::Transition::BeginRun>("HBDetIdList");
42  produces<nanoaod::FlatTable, edm::Transition::BeginRun>("HEDetIdList");
43  produces<nanoaod::FlatTable, edm::Transition::BeginRun>("HFDetIdList");
44  produces<nanoaod::FlatTable, edm::Transition::BeginRun>("HODetIdList");
45  };
46 
47  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
48  void globalBeginRunProduce(edm::Run& iRun, edm::EventSetup const& iSetup) const override;
49 };
50 
52 
54  // Setup products
55  const std::vector<HcalSubdetector> subdets = {HcalBarrel, HcalEndcap, HcalForward, HcalOuter};
56  std::map<HcalSubdetector, std::unique_ptr<std::vector<HcalDetId>>> didLists;
57  didLists[HcalBarrel] = std::make_unique<std::vector<HcalDetId>>();
58  didLists[HcalEndcap] = std::make_unique<std::vector<HcalDetId>>();
59  didLists[HcalForward] = std::make_unique<std::vector<HcalDetId>>();
60  didLists[HcalOuter] = std::make_unique<std::vector<HcalDetId>>();
61 
62  // Load channels from emap
64  HcalElectronicsMap const* emap = dbService->getHcalMapping();
65 
66  std::vector<HcalGenericDetId> alldids = emap->allPrecisionId();
67  for (auto it_did = alldids.begin(); it_did != alldids.end(); ++it_did) {
68  if (!it_did->isHcalDetId()) {
69  continue;
70  }
71  HcalDetId did = HcalDetId(it_did->rawId());
72  if (!(did.subdet() == HcalBarrel || did.subdet() == HcalEndcap || did.subdet() == HcalForward ||
73  did.subdet() == HcalOuter)) {
74  continue;
75  }
76 
77  // TODO: Add filtering, for example on FED whitelist
78 
79  didLists[did.subdet()]->push_back(did);
80  }
81 
82  // Sort HcalDetIds
83  for (auto& it_subdet : subdets) {
84  std::sort(didLists[it_subdet]->begin(), didLists[it_subdet]->end());
85  }
86 
87  // Make NanoAOD tables
88  std::map<HcalSubdetector, std::string> subdetNames = {
89  {HcalBarrel, "HB"}, {HcalEndcap, "HE"}, {HcalForward, "HF"}, {HcalOuter, "HO"}};
90 
91  for (auto& it_subdet : subdets) {
92  auto didTable =
93  std::make_unique<nanoaod::FlatTable>(didLists[it_subdet]->size(), subdetNames[it_subdet], false, false);
94 
95  std::vector<int> vdids;
96  for (auto& it_did : *(didLists[it_subdet])) {
97  vdids.push_back(it_did.rawId());
98  }
99  didTable->addColumn<int>("did", vdids, "HcalDetId");
100 
101  iRun.put(std::move(didTable), subdetNames[it_subdet] + "DetIdList");
102  iRun.put(std::move(didLists[it_subdet]), subdetNames[it_subdet] + "DetIdList");
103  }
104 }
105 
107 //define this as a plug-in
edm::EDPutTokenT< std::vector< HcalDetId > > hbDetIdListToken_
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
void globalBeginRunProduce(edm::Run &iRun, edm::EventSetup const &iSetup) const override
HcalDetIdTableProducer(const edm::ParameterSet &iConfig)
edm::EDPutTokenT< std::vector< HcalDetId > > heDetIdListToken_
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
edm::EDPutTokenT< std::vector< HcalDetId > > hfDetIdListToken_
void put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Run.h:109
edm::ESGetToken< HcalDbService, HcalDbRecord > tokenHcalDbService_
edm::EDPutTokenT< std::vector< HcalDetId > > hoDetIdListToken_
HLT enums.
std::vector< HcalGenericDetId > allPrecisionId() const
static const std::string subdets[7]
Definition: TrackUtils.cc:60
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
static const char * subdetNames[]