File indexing completed on 2024-04-06 12:18:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include <memory>
0020
0021
0022 #include "FWCore/Framework/interface/Frameworkfwd.h"
0023 #include "FWCore/Framework/interface/stream/EDProducer.h"
0024 #include "FWCore/Framework/interface/Event.h"
0025 #include "FWCore/Framework/interface/MakerMacros.h"
0026
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028
0029 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0030 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0031 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0032 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0033 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
0034
0035 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
0036 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
0037
0038
0039 #include "CalibCalorimetry/EcalTPGTools/interface/EcalReadoutTools.h"
0040 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
0041
0042
0043
0044
0045
0046 class HLTRechitsToDigis : public edm::stream::EDProducer<> {
0047 public:
0048 explicit HLTRechitsToDigis(const edm::ParameterSet&);
0049 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0050 enum ecalRegion { invalidRegion = 0, barrel, endcap };
0051 static const HLTRechitsToDigis::ecalRegion stringToRegion(const std::string& region);
0052
0053 private:
0054 void produce(edm::Event&, edm::EventSetup const&) override;
0055
0056
0057
0058 edm::EDGetTokenT<EBDigiCollection> digisEBInToken_;
0059 edm::EDGetTokenT<EEDigiCollection> digisEEInToken_;
0060 edm::EDGetTokenT<EcalRecHitCollection> recHitsToken_;
0061
0062 edm::EDGetTokenT<EBSrFlagCollection> srFlagsEBInToken_;
0063 edm::EDGetTokenT<EESrFlagCollection> srFlagsEEInToken_;
0064
0065 EcalReadoutTools::ESGetTokens const ecalReadoutToolsESGetTokens_;
0066
0067
0068 edm::InputTag digisIn_;
0069 edm::InputTag recHits_;
0070
0071 edm::InputTag srFlagsIn_;
0072
0073
0074 std::string digisOut_;
0075 ecalRegion region_;
0076
0077 std::string srFlagsOut_;
0078 };
0079
0080
0081
0082
0083
0084 HLTRechitsToDigis::HLTRechitsToDigis(const edm::ParameterSet& iConfig)
0085 : ecalReadoutToolsESGetTokens_{iConfig, consumesCollector()} {
0086
0087 region_ = stringToRegion(iConfig.getParameter<std::string>("region"));
0088
0089
0090 digisIn_ = iConfig.getParameter<edm::InputTag>("digisIn");
0091 digisOut_ = iConfig.getParameter<std::string>("digisOut");
0092
0093
0094 recHits_ = iConfig.getParameter<edm::InputTag>("recHits");
0095
0096
0097 srFlagsIn_ = iConfig.getParameter<edm::InputTag>("srFlagsIn");
0098 srFlagsOut_ = iConfig.getParameter<std::string>("srFlagsOut");
0099
0100
0101 switch (region_) {
0102 case barrel:
0103 digisEBInToken_ = consumes<EBDigiCollection>(digisIn_);
0104 produces<EBDigiCollection>(digisOut_);
0105
0106 if (not srFlagsIn_.label().empty()) {
0107 srFlagsEBInToken_ = consumes<EBSrFlagCollection>(srFlagsIn_);
0108 produces<EBSrFlagCollection>(srFlagsOut_);
0109 }
0110 break;
0111 case endcap:
0112 digisEEInToken_ = consumes<EEDigiCollection>(digisIn_);
0113 produces<EEDigiCollection>(digisOut_);
0114
0115 if (not srFlagsIn_.label().empty()) {
0116 srFlagsEEInToken_ = consumes<EESrFlagCollection>(srFlagsIn_);
0117 produces<EESrFlagCollection>(srFlagsOut_);
0118 }
0119 break;
0120 case invalidRegion:
0121 break;
0122 }
0123
0124 recHitsToken_ = consumes<EcalRecHitCollection>(recHits_);
0125 }
0126
0127
0128
0129
0130 const HLTRechitsToDigis::ecalRegion HLTRechitsToDigis::stringToRegion(const std::string& region) {
0131 if (region == "barrel")
0132 return barrel;
0133 else if (region == "endcap")
0134 return endcap;
0135 else
0136 return invalidRegion;
0137 }
0138
0139
0140 void HLTRechitsToDigis::produce(edm::Event& iEvent, edm::EventSetup const& setup) {
0141 using namespace edm;
0142
0143 Handle<EBDigiCollection> digisEBHandle;
0144 Handle<EEDigiCollection> digisEEHandle;
0145
0146
0147 std::unique_ptr<EBDigiCollection> outputEBDigiCollection(new EBDigiCollection);
0148 std::unique_ptr<EEDigiCollection> outputEEDigiCollection(new EEDigiCollection);
0149
0150
0151 Handle<EBSrFlagCollection> srFlagsEBHandle;
0152 Handle<EESrFlagCollection> srFlagsEEHandle;
0153
0154
0155 std::unique_ptr<EBSrFlagCollection> outputEBSrFlagCollection(new EBSrFlagCollection);
0156 std::unique_ptr<EESrFlagCollection> outputEESrFlagCollection(new EESrFlagCollection);
0157 EcalReadoutTools ecalReadOutTool(iEvent, setup, ecalReadoutToolsESGetTokens_);
0158
0159
0160 Handle<EcalRecHitCollection> recHitsHandle;
0161 iEvent.getByToken(recHitsToken_, recHitsHandle);
0162
0163
0164 switch (region_) {
0165 case barrel: {
0166 iEvent.getByToken(digisEBInToken_, digisEBHandle);
0167 const EBDigiCollection* digisEB = digisEBHandle.product();
0168
0169 const EBSrFlagCollection* srFlagsEB = nullptr;
0170
0171 if (not srFlagsEBInToken_.isUninitialized()) {
0172 iEvent.getByToken(srFlagsEBInToken_, srFlagsEBHandle);
0173 srFlagsEB = srFlagsEBHandle.product();
0174 }
0175
0176
0177
0178 EcalRecHitCollection::const_iterator ituneEB;
0179 for (ituneEB = recHitsHandle->begin(); ituneEB != recHitsHandle->end(); ituneEB++) {
0180 EcalRecHit const& hit = (*ituneEB);
0181 EcalDigiCollection::const_iterator digiLookUp = digisEB->find(hit.id());
0182
0183 if (digiLookUp == digisEB->end())
0184 continue;
0185 outputEBDigiCollection->push_back(digiLookUp->id(), digiLookUp->begin());
0186
0187 EBSrFlagCollection::const_iterator srFlagLookUp;
0188 if (not srFlagsEBInToken_.isUninitialized()) {
0189
0190
0191 const EcalTrigTowerDetId& ttId = ecalReadOutTool.readOutUnitOf(static_cast<EBDetId>(hit.id()));
0192
0193 if (outputEBSrFlagCollection->find(ttId) != outputEBSrFlagCollection->end())
0194 continue;
0195 srFlagLookUp = srFlagsEB->find(ttId);
0196
0197 if (srFlagLookUp == srFlagsEB->end())
0198 continue;
0199 outputEBSrFlagCollection->push_back(*srFlagLookUp);
0200 }
0201 }
0202
0203
0204 iEvent.put(std::move(outputEBDigiCollection), digisOut_);
0205 if (not srFlagsEBInToken_.isUninitialized())
0206 iEvent.put(std::move(outputEBSrFlagCollection), srFlagsOut_);
0207 break;
0208 }
0209 case endcap: {
0210 iEvent.getByToken(digisEEInToken_, digisEEHandle);
0211 const EEDigiCollection* digisEE = digisEEHandle.product();
0212
0213 const EESrFlagCollection* srFlagsEE = nullptr;
0214
0215 if (not srFlagsEEInToken_.isUninitialized()) {
0216 iEvent.getByToken(srFlagsEEInToken_, srFlagsEEHandle);
0217 srFlagsEE = srFlagsEEHandle.product();
0218 }
0219
0220
0221
0222 EcalRecHitCollection::const_iterator ituneEE;
0223 for (ituneEE = recHitsHandle->begin(); ituneEE != recHitsHandle->end(); ituneEE++) {
0224 EcalRecHit const& hit = (*ituneEE);
0225 EcalDigiCollection::const_iterator digiLookUp = digisEE->find(hit.id());
0226
0227 if (digiLookUp == digisEE->end())
0228 continue;
0229 outputEEDigiCollection->push_back(digiLookUp->id(), digiLookUp->begin());
0230
0231 EESrFlagCollection::const_iterator srFlagLookUp;
0232 if (not srFlagsEEInToken_.isUninitialized()) {
0233
0234
0235 const EcalScDetId& scId = ecalReadOutTool.readOutUnitOf(static_cast<EEDetId>(hit.id()));
0236
0237 if (outputEESrFlagCollection->find(scId) != outputEESrFlagCollection->end())
0238 continue;
0239 srFlagLookUp = srFlagsEE->find(scId);
0240
0241 if (srFlagLookUp == srFlagsEE->end())
0242 continue;
0243 outputEESrFlagCollection->push_back(*srFlagLookUp);
0244 }
0245 }
0246
0247
0248 iEvent.put(std::move(outputEEDigiCollection), digisOut_);
0249 if (not srFlagsEEInToken_.isUninitialized())
0250 iEvent.put(std::move(outputEESrFlagCollection), srFlagsOut_);
0251 break;
0252 }
0253 case invalidRegion: {
0254 break;
0255 }
0256 }
0257 }
0258
0259
0260 void HLTRechitsToDigis::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0261
0262
0263 edm::ParameterSetDescription desc;
0264
0265 desc.add<std::string>("region", "barrel")
0266 ->setComment("Region of rechits to save Digis for. Allowed values: barrel or endcap.");
0267 desc.add<edm::InputTag>("digisIn", edm::InputTag("ecalDigis", "ebDigis"))
0268 ->setComment("The collection of either barrel or endcap digis which correspond to the rechit collection");
0269 desc.add<std::string>("digisOut", "pi0EBDigis")->setComment("Name for the collection of Digis saved by the module");
0270 desc.add<edm::InputTag>("recHits", edm::InputTag("hltAlCaPi0EBUncalibrator", "pi0EcalRecHitsEB"))
0271 ->setComment("Collection of rechits to match Digis to");
0272 desc.add<edm::InputTag>("srFlagsIn", edm::InputTag())
0273 ->setComment("The collection of either barrel or endcap srFlags which correspond to the rechit collection");
0274 desc.add<std::string>("srFlagsOut", "pi0EBSrFlags")
0275 ->setComment("Name for the collection of SrFlags saved by the module");
0276 descriptions.add("hltFindMatchingECALDigisToRechits", desc);
0277 }
0278
0279
0280 DEFINE_FWK_MODULE(HLTRechitsToDigis);