Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-28 01:32:08

0001 // system include files
0002 #include <memory>
0003 
0004 // user include files
0005 #include "CalibFormats/SiStripObjects/interface/SiStripRegionCabling.h"
0006 #include "CalibTracker/Records/interface/SiStripRegionCablingRcd.h"
0007 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
0008 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0009 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0010 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0011 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidate.h"
0012 #include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidateFwd.h"
0013 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0014 
0015 #include "FWCore/Framework/interface/Frameworkfwd.h"
0016 #include "FWCore/Framework/interface/global/EDProducer.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0021 
0022 class SiStripRegFEDSelector : public edm::global::EDProducer<> {
0023 public:
0024   SiStripRegFEDSelector(const edm::ParameterSet&);
0025   ~SiStripRegFEDSelector() override;
0026 
0027   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0028 
0029 private:
0030   void beginJob() override {}
0031   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0032   void endJob() override {}
0033 
0034   const edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs> tok_seed_;
0035   const edm::EDGetTokenT<FEDRawDataCollection> tok_raw_;
0036   const edm::ESGetToken<SiStripRegionCabling, SiStripRegionCablingRcd> tok_strip_;
0037   const double delta_;
0038 };
0039 
0040 SiStripRegFEDSelector::SiStripRegFEDSelector(const edm::ParameterSet& iConfig)
0041     : tok_seed_(consumes<trigger::TriggerFilterObjectWithRefs>(iConfig.getParameter<edm::InputTag>("regSeedLabel"))),
0042       tok_raw_(consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("rawInputLabel"))),
0043       tok_strip_(esConsumes<SiStripRegionCabling, SiStripRegionCablingRcd>()),
0044       delta_(iConfig.getParameter<double>("delta")) {
0045   produces<FEDRawDataCollection>();
0046 }
0047 
0048 SiStripRegFEDSelector::~SiStripRegFEDSelector() {}
0049 
0050 void SiStripRegFEDSelector::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0051   auto producedData = std::make_unique<FEDRawDataCollection>();
0052 
0053   const edm::Handle<trigger::TriggerFilterObjectWithRefs>& trigSeedTrks = iEvent.getHandle(tok_seed_);
0054 
0055   std::vector<edm::Ref<reco::IsolatedPixelTrackCandidateCollection> > isoPixTrackRefs;
0056   trigSeedTrks->getObjects(trigger::TriggerTrack, isoPixTrackRefs);
0057 
0058   const edm::Handle<FEDRawDataCollection>& rawIn = iEvent.getHandle(tok_raw_);
0059 
0060   const SiStripRegionCabling* strip_cabling = &iSetup.getData(tok_strip_);
0061   std::vector<int> stripFEDVec;
0062 
0063   //get vector of regions
0064   const SiStripRegionCabling::Cabling& ccab = strip_cabling->getRegionCabling();
0065 
0066   //size of region (eta,phi)
0067   const std::pair<double, double> regDim = strip_cabling->regionDimensions();
0068 
0069   const SiStripRegionCabling::ElementCabling elcabling;
0070 
0071   bool fedSaved[1000];
0072   for (int i = 0; i < 1000; i++)
0073     fedSaved[i] = false;
0074 
0075   //cycle on seeds
0076   for (uint32_t p = 0; p < isoPixTrackRefs.size(); p++) {
0077     double etaObj_ = isoPixTrackRefs[p]->track()->eta();
0078     double phiObj_ = isoPixTrackRefs[p]->track()->phi();
0079 
0080     //cycle on regions
0081     for (uint32_t i = 0; i < ccab.size(); i++) {
0082       SiStripRegionCabling::Position pos = strip_cabling->position(i);
0083       double dphi = fabs(pos.second - phiObj_);
0084       if (dphi > acos(-1))
0085         dphi = 2 * acos(-1) - dphi;
0086       double R = sqrt(pow(pos.first - etaObj_, 2) + dphi * dphi);
0087       if (R - sqrt(pow(regDim.first / 2, 2) + pow(regDim.second / 2, 2)) > delta_)
0088         continue;
0089       //get vector of subdets within region
0090       const SiStripRegionCabling::RegionCabling regSubdets = ccab[i];
0091       //cycle on subdets
0092       for (uint32_t idet = 0; idet < SiStripRegionCabling::ALLSUBDETS; idet++) {
0093         //get vector of layers within subdet of region
0094         const SiStripRegionCabling::WedgeCabling regSubdetLayers = regSubdets[idet];
0095         for (uint32_t ilayer = 0; ilayer < SiStripRegionCabling::ALLLAYERS; ilayer++) {
0096           //get map of vectors of feds withing the layer of subdet of region
0097           const SiStripRegionCabling::ElementCabling fedVectorMap = regSubdetLayers[ilayer];
0098           SiStripRegionCabling::ElementCabling::const_iterator it = fedVectorMap.begin();
0099           for (; it != fedVectorMap.end(); it++) {
0100             for (uint32_t op = 0; op < (it->second).size(); op++) {
0101               //get fed id
0102               int fediid = (it->second)[op].fedId();
0103               if (!fedSaved[fediid]) {
0104                 stripFEDVec.push_back(fediid);
0105               }
0106               fedSaved[fediid] = true;
0107             }
0108           }
0109         }
0110       }
0111     }
0112   }
0113 
0114   /////////////// Copying FEDs:
0115 
0116   const FEDRawDataCollection* rdc = rawIn.product();
0117 
0118   //   if ( ( rawData[i].provenance()->processName() != e.processHistory().rbegin()->processName() ) )
0119   //       continue ; // skip all raw collections not produced by the current process
0120 
0121   for (int j = 0; j < FEDNumbering::MAXFEDID; ++j) {
0122     bool rightFED = false;
0123     for (uint32_t k = 0; k < stripFEDVec.size(); k++) {
0124       if (j == stripFEDVec[k]) {
0125         rightFED = true;
0126       }
0127     }
0128     if (!rightFED)
0129       continue;
0130     const FEDRawData& fedData = rdc->FEDData(j);
0131     size_t size = fedData.size();
0132 
0133     if (size > 0) {
0134       // this fed has data -- lets copy it
0135       FEDRawData& fedDataProd = producedData->FEDData(j);
0136       if (fedDataProd.size() != 0) {
0137         edm::LogVerbatim("HcalIsoTrack") << " More than one FEDRawDataCollection with data in FED " << j
0138                                          << " Skipping the 2nd *****";
0139         continue;
0140       }
0141       fedDataProd.resize(size);
0142       unsigned char* dataProd = fedDataProd.data();
0143       const unsigned char* data = fedData.data();
0144       for (unsigned int k = 0; k < size; ++k) {
0145         dataProd[k] = data[k];
0146       }
0147     }
0148   }
0149 
0150   iEvent.put(std::move(producedData));
0151 }
0152 
0153 void SiStripRegFEDSelector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0154   edm::ParameterSetDescription desc;
0155   desc.add<edm::InputTag>("regSeedLabel", edm::InputTag("hltIsolPixelTrackFilter"));
0156   desc.add<edm::InputTag>("rawInputLabel", edm::InputTag("rawDataCollector"));
0157   desc.add<double>("delta", 1.0);
0158   descriptions.add("stripFED", desc);
0159 }
0160 
0161 #include "FWCore/PluginManager/interface/ModuleDef.h"
0162 #include "FWCore/Framework/interface/MakerMacros.h"
0163 
0164 DEFINE_FWK_MODULE(SiStripRegFEDSelector);