Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-04 00:29:53

0001 #include "DataFormats/DetId/interface/DetId.h"
0002 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0003 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0004 #include "DataFormats/EcalRecHit/interface/EcalRecHitHostCollection.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/Framework/interface/global/EDProducer.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/ParameterSet/interface/EmptyGroupDescription.h"
0011 #include "FWCore/Utilities/interface/EDGetToken.h"
0012 #include "FWCore/Utilities/interface/EDPutToken.h"
0013 
0014 class EcalRecHitSoAToLegacy : public edm::global::EDProducer<> {
0015 public:
0016   explicit EcalRecHitSoAToLegacy(edm::ParameterSet const &ps);
0017   ~EcalRecHitSoAToLegacy() override = default;
0018   static void fillDescriptions(edm::ConfigurationDescriptions &);
0019 
0020 private:
0021   using InputProduct = EcalRecHitHostCollection;
0022   void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override;
0023 
0024 private:
0025   const bool isPhase2_;
0026   const edm::EDGetTokenT<InputProduct> inputTokenEB_;
0027   const edm::EDGetTokenT<InputProduct> inputTokenEE_;
0028   const edm::EDPutTokenT<EBRecHitCollection> outputTokenEB_;
0029   const edm::EDPutTokenT<EERecHitCollection> outputTokenEE_;
0030 };
0031 
0032 void EcalRecHitSoAToLegacy::fillDescriptions(edm::ConfigurationDescriptions &confDesc) {
0033   edm::ParameterSetDescription desc;
0034 
0035   desc.add<edm::InputTag>("inputCollectionEB", edm::InputTag("ecalRecHitPortable", "EcalRecHitsEB"));
0036   desc.add<std::string>("outputLabelEB", "EcalRecHitsEB");
0037   desc.ifValue(edm::ParameterDescription<bool>("isPhase2", false, true),
0038                false >> (edm::ParameterDescription<edm::InputTag>(
0039                              "inputCollectionEE", edm::InputTag("ecalRecHitPortable", "EcalRecHitsEE"), true) and
0040                          edm::ParameterDescription<std::string>("outputLabelEE", "EcalRecHitsEE", true)) or
0041                    true >> edm::EmptyGroupDescription());
0042   confDesc.add("ecalRecHitSoAToLegacy", desc);
0043 }
0044 
0045 EcalRecHitSoAToLegacy::EcalRecHitSoAToLegacy(edm::ParameterSet const &ps)
0046     : isPhase2_{ps.getParameter<bool>("isPhase2")},
0047       inputTokenEB_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("inputCollectionEB"))},
0048       inputTokenEE_{isPhase2_ ? edm::EDGetTokenT<InputProduct>{}
0049                               : consumes<InputProduct>(ps.getParameter<edm::InputTag>("inputCollectionEE"))},
0050       outputTokenEB_{produces<EBRecHitCollection>(ps.getParameter<std::string>("outputLabelEB"))},
0051       outputTokenEE_{isPhase2_ ? edm::EDPutTokenT<EERecHitCollection>{}
0052                                : produces<EERecHitCollection>(ps.getParameter<std::string>("outputLabelEE"))} {}
0053 
0054 void EcalRecHitSoAToLegacy::produce(edm::StreamID sid, edm::Event &event, edm::EventSetup const &setup) const {
0055   auto const &inputCollEB = event.get(inputTokenEB_);
0056   auto const &inputCollEBView = inputCollEB.const_view();
0057   auto outputCollEB = std::make_unique<EBRecHitCollection>();
0058   outputCollEB->reserve(inputCollEBView.size());
0059 
0060   for (uint32_t i = 0; i < inputCollEBView.size(); ++i) {
0061     // Save only if energy is >= 0 !
0062     // This is important because the channels that were supposed
0063     // to be excluded get "-1" as energy
0064     if (inputCollEBView.energy()[i] >= 0.) {
0065       outputCollEB->emplace_back(DetId{inputCollEBView.id()[i]},
0066                                  inputCollEBView.energy()[i],
0067                                  inputCollEBView.time()[i],
0068                                  inputCollEBView.extra()[i],
0069                                  inputCollEBView.flagBits()[i]);
0070     }
0071   }
0072   event.put(outputTokenEB_, std::move(outputCollEB));
0073 
0074   if (!isPhase2_) {
0075     auto const &inputCollEE = event.get(inputTokenEE_);
0076     auto const &inputCollEEView = inputCollEE.const_view();
0077     auto outputCollEE = std::make_unique<EERecHitCollection>();
0078     outputCollEE->reserve(inputCollEEView.size());
0079 
0080     for (uint32_t i = 0; i < inputCollEEView.size(); ++i) {
0081       // Save only if energy is >= 0 !
0082       // This is important because the channels that were supposed
0083       // to be excluded get "-1" as energy
0084       if (inputCollEEView.energy()[i] >= 0.) {
0085         outputCollEE->emplace_back(DetId{inputCollEEView.id()[i]},
0086                                    inputCollEEView.energy()[i],
0087                                    inputCollEEView.time()[i],
0088                                    inputCollEEView.extra()[i],
0089                                    inputCollEEView.flagBits()[i]);
0090       }
0091     }
0092     event.put(outputTokenEE_, std::move(outputCollEE));
0093   }
0094 }
0095 
0096 DEFINE_FWK_MODULE(EcalRecHitSoAToLegacy);