Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-07-22 00:50:12

0001 // system include files
0002 #include <memory>
0003 
0004 // user include files
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/one/EDProducer.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0011 
0012 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0013 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0014 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0015 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
0016 #include "DataFormats/EcalRawData/interface/EcalListOfFEDS.h"
0017 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidateFwd.h"
0018 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidate.h"
0019 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0020 #include "DataFormats/Math/interface/RectangularEtaPhiRegion.h"
0021 
0022 #include "EventFilter/EcalRawToDigi/interface/EcalRegionCabling.h"
0023 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
0024 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
0025 
0026 class ECALRegFEDSelector : public edm::one::EDProducer<> {
0027 public:
0028   ECALRegFEDSelector(const edm::ParameterSet&);
0029   ~ECALRegFEDSelector() override = default;
0030 
0031   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0032 
0033 private:
0034   void beginJob() override {}
0035   void produce(edm::Event&, const edm::EventSetup&) override;
0036   void endJob() override {}
0037 
0038   std::unique_ptr<const EcalElectronicsMapping> ec_mapping;
0039 
0040   const double delta_;
0041   bool fedSaved[1200];
0042 
0043   const edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs> tok_seed_;
0044   const edm::EDGetTokenT<FEDRawDataCollection> tok_raw_;
0045 };
0046 
0047 ECALRegFEDSelector::ECALRegFEDSelector(const edm::ParameterSet& iConfig)
0048     : delta_(iConfig.getParameter<double>("delta")),
0049       tok_seed_(consumes<trigger::TriggerFilterObjectWithRefs>(iConfig.getParameter<edm::InputTag>("regSeedLabel"))),
0050       tok_raw_(consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("rawInputLabel"))) {
0051   ec_mapping = std::make_unique<EcalElectronicsMapping>();
0052 
0053   produces<FEDRawDataCollection>();
0054   produces<EcalListOfFEDS>();
0055 
0056   for (int p = 0; p < 1200; p++) {
0057     fedSaved[p] = false;
0058   }
0059 }
0060 
0061 void ECALRegFEDSelector::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0062   for (int p = 0; p < 1200; p++) {
0063     fedSaved[p] = false;
0064   }
0065 
0066   auto producedData = std::make_unique<FEDRawDataCollection>();
0067 
0068   auto fedList = std::make_unique<EcalListOfFEDS>();
0069 
0070   const edm::Handle<trigger::TriggerFilterObjectWithRefs>& trigSeedTrks = iEvent.getHandle(tok_seed_);
0071 
0072   std::vector<edm::Ref<reco::IsolatedPixelTrackCandidateCollection> > isoPixTrackRefs;
0073   trigSeedTrks->getObjects(trigger::TriggerTrack, isoPixTrackRefs);
0074 
0075   const edm::Handle<FEDRawDataCollection>& rawIn = iEvent.getHandle(tok_raw_);
0076 
0077   //  std::vector<int> EC_FED_IDs;
0078 
0079   for (uint32_t p = 0; p < isoPixTrackRefs.size(); p++) {
0080     double etaObj_ = isoPixTrackRefs[p]->track()->eta();
0081     double phiObj_ = isoPixTrackRefs[p]->track()->phi();
0082 
0083     RectangularEtaPhiRegion ecEtaPhi(etaObj_ - delta_, etaObj_ + delta_, phiObj_ - delta_, phiObj_ + delta_);
0084 
0085     const std::vector<int> EC_FED_IDs = ec_mapping->GetListofFEDs(ecEtaPhi);
0086 
0087     const FEDRawDataCollection* rdc = rawIn.product();
0088 
0089     for (int j = 0; j < FEDNumbering::MAXFEDID; j++) {
0090       bool rightFED = false;
0091       for (uint32_t k = 0; k < EC_FED_IDs.size(); k++) {
0092         if (j == EcalRegionCabling::fedIndex(EC_FED_IDs[k])) {
0093           if (!fedSaved[j]) {
0094             fedList->AddFED(j);
0095             rightFED = true;
0096             fedSaved[j] = true;
0097           }
0098         }
0099       }
0100       if (j >= FEDNumbering::MINPreShowerFEDID && j <= FEDNumbering::MAXPreShowerFEDID) {
0101         fedSaved[j] = true;
0102         rightFED = true;
0103       }
0104       if (!rightFED)
0105         continue;
0106       const FEDRawData& fedData = rdc->FEDData(j);
0107       size_t size = fedData.size();
0108 
0109       if (size > 0) {
0110         // this fed has data -- lets copy it
0111         FEDRawData& fedDataProd = producedData->FEDData(j);
0112         if (fedDataProd.size() != 0) {
0113           edm::LogVerbatim("HcalCalib") << " More than one FEDRawDataCollection with data in FED " << j
0114                                         << " Skipping the 2nd";
0115           continue;
0116         }
0117         fedDataProd.resize(size);
0118         unsigned char* dataProd = fedDataProd.data();
0119         const unsigned char* data = fedData.data();
0120         for (unsigned int k = 0; k < size; ++k) {
0121           dataProd[k] = data[k];
0122         }
0123       }
0124     }
0125   }
0126 
0127   iEvent.put(std::move(producedData));
0128   iEvent.put(std::move(fedList));
0129 }
0130 
0131 void ECALRegFEDSelector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0132   edm::ParameterSetDescription desc;
0133   desc.add<edm::InputTag>("regSeedLabel", edm::InputTag("hltPixelIsolTrackFilter"));
0134   desc.add<edm::InputTag>("rawInputLabel", edm::InputTag("rawDataCollector"));
0135   desc.add<double>("delta", 1.0);
0136   descriptions.add("ecalFED", desc);
0137 }
0138 
0139 #include "FWCore/PluginManager/interface/ModuleDef.h"
0140 #include "FWCore/Framework/interface/MakerMacros.h"
0141 
0142 DEFINE_FWK_MODULE(ECALRegFEDSelector);