Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-03 22:27:55

0001 #include "Calibration/EcalAlCaRecoProducers/plugins/SelectedElectronFEDListProducer.h"
0002 
0003 #include <fstream>
0004 #include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"
0005 
0006 #include "FWCore/Framework/interface/ESTransientHandle.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 
0011 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0012 #include "FWCore/Utilities/interface/InputTag.h"
0013 // raw data
0014 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0015 
0016 // Geometry
0017 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0018 
0019 // egamma objects
0020 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0021 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
0022 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
0023 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidateFwd.h"
0024 #include "DataFormats/EgammaCandidates/interface/Electron.h"
0025 #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
0026 
0027 // Hcal objects
0028 #include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
0029 
0030 // Strip and pixel
0031 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0032 
0033 // detector id
0034 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0035 #include "DataFormats/HcalDetId/interface/HcalElectronicsId.h"
0036 // Hcal rec hit
0037 #include "DataFormats/CaloRecHit/interface/CaloRecHit.h"
0038 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
0039 // Geometry
0040 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0041 #include "Geometry/EcalAlgo/interface/EcalPreshowerGeometry.h"
0042 // strip geometry
0043 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0044 // Message logger
0045 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0046 // Strip and pixel
0047 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
0048 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h"
0049 
0050 using namespace std;
0051 
0052 /// Producer constructor
0053 template <typename TEle, typename TCand>
0054 SelectedElectronFEDListProducer<TEle, TCand>::SelectedElectronFEDListProducer(const edm::ParameterSet& iConfig)
0055     : hcalDbToken_(esConsumes()),
0056       ecalMappingToken_(esConsumes()),
0057       caloGeometryToken_(esConsumes()),
0058       siPixelFedCablingMapToken_(esConsumes()),
0059       trackerGeometryToken_(esConsumes()),
0060       siStripRegionCablingToken_(esConsumes()) {
0061   // input electron collection Tag
0062   if (iConfig.existsAs<std::vector<edm::InputTag>>("electronTags")) {
0063     electronTags_ = iConfig.getParameter<std::vector<edm::InputTag>>("electronTags");
0064     if (electronTags_.empty())
0065       throw cms::Exception("Configuration")
0066           << "[SelectedElectronFEDListProducer] empty electron collection is given --> at least one \n";
0067   } else
0068     throw cms::Exception("Configuration")
0069         << "[SelectedElectronFEDListProducer] no electron collection are given --> need at least one \n";
0070 
0071   // Consumes for the electron collection
0072   LogDebug("SelectedElectronFEDListProducer") << " Electron Collections" << std::endl;
0073   for (std::vector<edm::InputTag>::const_iterator itEleTag = electronTags_.begin(); itEleTag != electronTags_.end();
0074        ++itEleTag) {
0075     electronToken_.push_back(consumes<TEleColl>(*itEleTag));
0076     LogDebug("SelectedElectronFEDListProducer") << " Ele collection: " << *(itEleTag) << std::endl;
0077   }
0078 
0079   // input RecoEcalCandidate collection Tag
0080   if (iConfig.existsAs<std::vector<edm::InputTag>>("recoEcalCandidateTags")) {
0081     recoEcalCandidateTags_ = iConfig.getParameter<std::vector<edm::InputTag>>("recoEcalCandidateTags");
0082     if (recoEcalCandidateTags_.empty())
0083       throw cms::Exception("Configuration") << "[SelectedElectronFEDListProducer] empty ecal candidate collections "
0084                                                "collection is given --> at least one \n";
0085   } else
0086     throw cms::Exception("Configuration") << "[SelectedElectronFEDListProducer] no electron reco ecal candidate "
0087                                              "collection are given --> need at least one \n";
0088 
0089   // Consumes for the recoEcal candidate collection
0090   for (std::vector<edm::InputTag>::const_iterator itEcalCandTag = recoEcalCandidateTags_.begin();
0091        itEcalCandTag != recoEcalCandidateTags_.end();
0092        ++itEcalCandTag) {
0093     recoEcalCandidateToken_.push_back(consumes<trigger::TriggerFilterObjectWithRefs>(*itEcalCandTag));
0094     LogDebug("SelectedElectronFEDListProducer") << " Reco ecal candidate collection: " << *(itEcalCandTag) << std::endl;
0095   }
0096 
0097   // list of gsf collections
0098   if (iConfig.existsAs<std::vector<int>>("isGsfElectronCollection")) {
0099     isGsfElectronCollection_ = iConfig.getParameter<std::vector<int>>("isGsfElectronCollection");
0100     if (isGsfElectronCollection_.empty())
0101       throw cms::Exception("Configuration")
0102           << "[SelectedElectronFEDListProducer] empty electron flag collection --> at least one \n";
0103   } else
0104     throw cms::Exception("Configuration")
0105         << "[SelectedElectronFEDListProducer] no electron flag are given --> need at least one \n";
0106 
0107   if (isGsfElectronCollection_.size() != electronTags_.size() or
0108       isGsfElectronCollection_.size() != recoEcalCandidateTags_.size())
0109     throw cms::Exception("Configuration") << "[SelectedElectronFEDListProducer] electron flag , electron collection "
0110                                              "and reco ecal cand collection must have the same size ! \n";
0111 
0112   // take the beam spot Tag
0113   if (iConfig.existsAs<edm::InputTag>("beamSpot"))
0114     beamSpotTag_ = iConfig.getParameter<edm::InputTag>("beamSpot");
0115   else
0116     beamSpotTag_ = edm::InputTag("hltOnlineBeamSpot");
0117 
0118   if (!(beamSpotTag_ == edm::InputTag("")))
0119     beamSpotToken_ = consumes<reco::BeamSpot>(beamSpotTag_);
0120 
0121   LogDebug("SelectedElectronFEDListProducer") << " Beam Spot Tag " << beamSpotTag_ << std::endl;
0122 
0123   // take the HBHE recHit Tag
0124   if (iConfig.existsAs<edm::InputTag>("HBHERecHitTag"))
0125     HBHERecHitTag_ = iConfig.getParameter<edm::InputTag>("HBHERecHitTag");
0126   else
0127     HBHERecHitTag_ = edm::InputTag("hltHbhereco");
0128 
0129   if (!(HBHERecHitTag_ == edm::InputTag("")))
0130     hbheRecHitToken_ = consumes<HBHERecHitCollection>(HBHERecHitTag_);
0131 
0132   // raw data collector label
0133   if (iConfig.existsAs<edm::InputTag>("rawDataTag"))
0134     rawDataTag_ = iConfig.getParameter<edm::InputTag>("rawDataTag");
0135   else
0136     rawDataTag_ = edm::InputTag("rawDataCollector");
0137 
0138   if (!(rawDataTag_ == edm::InputTag("")))
0139     rawDataToken_ = consumes<FEDRawDataCollection>(rawDataTag_);
0140 
0141   LogDebug("SelectedElectronFEDListProducer") << " RawDataInput " << rawDataTag_ << std::endl;
0142 
0143   // add a set of selected feds
0144   if (iConfig.existsAs<std::vector<int>>("addThisSelectedFEDs")) {
0145     addThisSelectedFEDs_ = iConfig.getParameter<std::vector<int>>("addThisSelectedFEDs");
0146     if (addThisSelectedFEDs_.empty())
0147       addThisSelectedFEDs_.push_back(-1);
0148   } else
0149     addThisSelectedFEDs_.push_back(-1);
0150 
0151   std::vector<int>::const_iterator AddFed = addThisSelectedFEDs_.begin();
0152   for (; AddFed != addThisSelectedFEDs_.end(); ++AddFed)
0153     LogDebug("SelectedElectronFEDListProducer") << " Additional FED: " << *(AddFed) << std::endl;
0154 
0155   // ES look up table path
0156   if (iConfig.existsAs<std::string>("ESLookupTable"))
0157     ESLookupTable_ = iConfig.getParameter<edm::FileInPath>("ESLookupTable");
0158   else
0159     ESLookupTable_ = edm::FileInPath("EventFilter/ESDigiToRaw/data/ES_lookup_table.dat");
0160 
0161   // output model label
0162   if (iConfig.existsAs<std::string>("outputLabelModule"))
0163     outputLabelModule_ = iConfig.getParameter<std::string>("outputLabelModule");
0164   else
0165     outputLabelModule_ = "streamElectronRawData";
0166 
0167   LogDebug("SelectedElectronFEDListProducer") << " Output Label " << outputLabelModule_ << std::endl;
0168 
0169   // dR for the strip region
0170   if (iConfig.existsAs<double>("dRStripRegion"))
0171     dRStripRegion_ = iConfig.getParameter<double>("dRStripRegion");
0172   else
0173     dRStripRegion_ = 0.5;
0174 
0175   LogDebug("SelectedElectronFEDListProducer") << " dRStripRegion " << dRStripRegion_ << std::endl;
0176 
0177   // dR for the hcal region
0178   if (iConfig.existsAs<double>("dRHcalRegion"))
0179     dRHcalRegion_ = iConfig.getParameter<double>("dRHcalRegion");
0180   else
0181     dRHcalRegion_ = 0.5;
0182 
0183   // dPhi, dEta and maxZ for pixel dump
0184   if (iConfig.existsAs<double>("dPhiPixelRegion"))
0185     dPhiPixelRegion_ = iConfig.getParameter<double>("dPhiPixelRegion");
0186   else
0187     dPhiPixelRegion_ = 0.5;
0188 
0189   if (iConfig.existsAs<double>("dEtaPixelRegion"))
0190     dEtaPixelRegion_ = iConfig.getParameter<double>("dEtaPixelRegion");
0191   else
0192     dEtaPixelRegion_ = 0.5;
0193 
0194   if (iConfig.existsAs<double>("maxZPixelRegion"))
0195     maxZPixelRegion_ = iConfig.getParameter<double>("maxZPixelRegion");
0196   else
0197     maxZPixelRegion_ = 24.;
0198 
0199   LogDebug("SelectedElectronFEDListProducer")
0200       << " dPhiPixelRegion " << dPhiPixelRegion_ << " dEtaPixelRegion " << dEtaPixelRegion_ << " MaxZPixelRegion "
0201       << maxZPixelRegion_ << std::endl;
0202 
0203   // bool
0204   if (iConfig.existsAs<bool>("dumpSelectedEcalFed"))
0205     dumpSelectedEcalFed_ = iConfig.getParameter<bool>("dumpSelectedEcalFed");
0206   else
0207     dumpSelectedEcalFed_ = true;
0208 
0209   if (iConfig.existsAs<bool>("dumpSelectedSiStripFed"))
0210     dumpSelectedSiStripFed_ = iConfig.getParameter<bool>("dumpSelectedSiStripFed");
0211   else
0212     dumpSelectedSiStripFed_ = true;
0213 
0214   if (iConfig.existsAs<bool>("dumpSelectedSiPixelFed"))
0215     dumpSelectedSiPixelFed_ = iConfig.getParameter<bool>("dumpSelectedSiPixelFed");
0216   else
0217     dumpSelectedSiPixelFed_ = true;
0218 
0219   if (iConfig.existsAs<bool>("dumpSelectedHCALFed"))
0220     dumpSelectedHCALFed_ = iConfig.getParameter<bool>("dumpSelectedHCALFed");
0221   else
0222     dumpSelectedHCALFed_ = true;
0223 
0224   LogDebug("SelectedElectronFEDListProducer")
0225       << " DumpEcalFedList set to " << dumpSelectedEcalFed_ << " DumpSelectedSiStripFed " << dumpSelectedSiStripFed_
0226       << " DumpSelectedSiPixelFed " << dumpSelectedSiPixelFed_ << std::endl;
0227 
0228   if (iConfig.existsAs<bool>("dumpAllEcalFed"))
0229     dumpAllEcalFed_ = iConfig.getParameter<bool>("dumpAllEcalFed");
0230   else
0231     dumpAllEcalFed_ = false;
0232 
0233   if (iConfig.existsAs<bool>("dumpAllTrackerFed"))
0234     dumpAllTrackerFed_ = iConfig.getParameter<bool>("dumpAllTrackerFed");
0235   else
0236     dumpAllTrackerFed_ = false;
0237 
0238   if (iConfig.existsAs<bool>("dumpAllHCALFed"))
0239     dumpAllHCALFed_ = iConfig.getParameter<bool>("dumpAllHCALFed");
0240   else
0241     dumpAllHCALFed_ = false;
0242 
0243   LogDebug("SelectedElectronFEDListProducer")
0244       << " DumpAllEcalFed " << dumpAllEcalFed_ << " DumpAllTrackerFed " << dumpAllTrackerFed_ << " Dump all HCAL fed "
0245       << dumpAllHCALFed_ << std::endl;
0246 
0247   // initialize pre-shower fed id --> look up table
0248   for (int i = 0; i < 2; ++i)
0249     for (int j = 0; j < 2; ++j)
0250       for (int k = 0; k < 40; ++k)
0251         for (int m = 0; m < 40; m++)
0252           ES_fedId_[i][j][k][m] = -1;
0253 
0254   // read in look-up table
0255   int nLines, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
0256   std::ifstream ES_file;
0257   ES_file.open(ESLookupTable_.fullPath().c_str());
0258   LogDebug("SelectedElectronFEDListProducer")
0259       << " Look Up table for ES " << ESLookupTable_.fullPath().c_str() << std::endl;
0260   if (ES_file.is_open()) {
0261     ES_file >> nLines;
0262     for (int i = 0; i < nLines; ++i) {
0263       ES_file >> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
0264       ES_fedId_[(3 - iz) / 2 - 1][ip - 1][ix - 1][iy - 1] = fed;
0265     }
0266   } else
0267     LogDebug("SelectedElectronFEDListProducer")
0268         << " Look up table file can not be found in " << ESLookupTable_.fullPath().c_str() << std::endl;
0269   ES_file.close();
0270 
0271   // produce the final collection
0272   produces<FEDRawDataCollection>(outputLabelModule_);  // produce exit collection
0273 }
0274 
0275 template <typename TEle, typename TCand>
0276 SelectedElectronFEDListProducer<TEle, TCand>::~SelectedElectronFEDListProducer() {
0277   if (!electronTags_.empty())
0278     electronTags_.clear();
0279   if (!recoEcalCandidateTags_.empty())
0280     recoEcalCandidateTags_.clear();
0281   if (!recoEcalCandidateToken_.empty())
0282     recoEcalCandidateToken_.clear();
0283   if (!electronToken_.empty())
0284     electronToken_.clear();
0285   if (!fedList_.empty())
0286     fedList_.clear();
0287   if (!pixelModuleVector_.empty())
0288     pixelModuleVector_.clear();
0289 }
0290 
0291 template <typename TEle, typename TCand>
0292 void SelectedElectronFEDListProducer<TEle, TCand>::beginJob() {
0293   LogDebug("SelectedElectronFEDListProducer") << " Begin of the Job " << std::endl;
0294 }
0295 
0296 template <typename TEle, typename TCand>
0297 void SelectedElectronFEDListProducer<TEle, TCand>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0298   // get the hcal electronics map
0299   const auto& pSetup = iSetup.getData(hcalDbToken_);
0300   HcalReadoutMap_ = pSetup.getHcalMapping();
0301 
0302   // get the ecal electronics map
0303   EcalMapping_ = &iSetup.getData(ecalMappingToken_);
0304 
0305   // get the calo geometry
0306   const auto& caloGeometry = iSetup.getData(caloGeometryToken_);
0307   GeometryCalo_ = &caloGeometry;
0308 
0309   //ES geometry
0310   GeometryES_ = caloGeometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
0311 
0312   // pixel tracker cabling map
0313   const auto pixelCablingMap = iSetup.getTransientHandle(siPixelFedCablingMapToken_);
0314   PixelCabling_.reset();
0315   PixelCabling_ = pixelCablingMap->cablingTree();
0316 
0317   const auto& trackerGeometry = iSetup.getData(trackerGeometryToken_);
0318 
0319   if (pixelModuleVector_.empty()) {
0320     // build the tracker pixel module map
0321     std::vector<const GeomDet*>::const_iterator itTracker = trackerGeometry.dets().begin();
0322     for (; itTracker != trackerGeometry.dets().end(); ++itTracker) {
0323       int subdet = (*itTracker)->geographicalId().subdetId();
0324       if (!(subdet == PixelSubdetector::PixelBarrel || subdet == PixelSubdetector::PixelEndcap))
0325         continue;
0326       PixelModule module;
0327       module.x = (*itTracker)->position().x();
0328       module.y = (*itTracker)->position().y();
0329       module.z = (*itTracker)->position().z();
0330       module.Phi = (*itTracker)->position().phi();
0331       module.Eta = (*itTracker)->position().eta();
0332       module.DetId = (*itTracker)->geographicalId().rawId();
0333       const std::vector<sipixelobjects::CablingPathToDetUnit> path2det = PixelCabling_->pathToDetUnit(module.DetId);
0334       module.Fed = path2det[0].fed;
0335 
0336       pixelModuleVector_.push_back(module);
0337     }
0338     std::sort(pixelModuleVector_.begin(), pixelModuleVector_.end());
0339   }
0340 
0341   StripRegionCabling_ = &iSetup.getData(siStripRegionCablingToken_);
0342 
0343   SiStripRegionCabling::Cabling SiStripCabling;
0344   SiStripCabling = StripRegionCabling_->getRegionCabling();
0345   regionDimension_ = StripRegionCabling_->regionDimensions();
0346 
0347   // event by event analysis
0348   // Get event raw data
0349   edm::Handle<FEDRawDataCollection> rawdata;
0350   if (!(rawDataTag_ == edm::InputTag("")))
0351     iEvent.getByToken(rawDataToken_, rawdata);
0352 
0353   // take the beam spot position
0354   edm::Handle<reco::BeamSpot> beamSpot;
0355   if (!(beamSpotTag_ == edm::InputTag("")))
0356     iEvent.getByToken(beamSpotToken_, beamSpot);
0357   if (!beamSpot.failedToGet())
0358     beamSpotPosition_ = beamSpot->position();
0359   else
0360     beamSpotPosition_.SetXYZ(0, 0, 0);
0361 
0362   // take the calo tower collection
0363   edm::Handle<HBHERecHitCollection> hbheRecHitHandle;
0364   if (!(HBHERecHitTag_ == edm::InputTag("")))
0365     iEvent.getByToken(hbheRecHitToken_, hbheRecHitHandle);
0366   const HBHERecHitCollection* hcalRecHitCollection = nullptr;
0367   if (!hbheRecHitHandle.failedToGet())
0368     hcalRecHitCollection = hbheRecHitHandle.product();
0369 
0370   double radTodeg = 180. / Geom::pi();
0371 
0372   if (dumpAllEcalFed_) {
0373     for (uint32_t iEcalFed = FEDNumbering::MINECALFEDID; iEcalFed <= FEDNumbering::MAXECALFEDID; iEcalFed++)
0374       fedList_.push_back(iEcalFed);
0375     for (uint32_t iESFed = FEDNumbering::MINPreShowerFEDID; iESFed <= FEDNumbering::MAXPreShowerFEDID; iESFed++)
0376       fedList_.push_back(iESFed);
0377   }
0378 
0379   if (dumpAllTrackerFed_) {
0380     for (uint32_t iPixelFed = FEDNumbering::MINSiPixelFEDID; iPixelFed <= FEDNumbering::MAXSiPixelFEDID; iPixelFed++)
0381       fedList_.push_back(iPixelFed);
0382     for (uint32_t iStripFed = FEDNumbering::MINSiStripFEDID; iStripFed <= FEDNumbering::MAXSiStripFEDID; iStripFed++)
0383       fedList_.push_back(iStripFed);
0384   }
0385 
0386   if (dumpAllHCALFed_) {
0387     for (uint32_t iHcalFed = FEDNumbering::MINHCALFEDID; iHcalFed <= FEDNumbering::MAXHCALFEDID; iHcalFed++)
0388       fedList_.push_back(iHcalFed);
0389   }
0390 
0391   // loop on the input electron collection vector
0392   TEle electron;
0393   edm::Ref<TCandColl> recoEcalCand;
0394   edm::Handle<TEleColl> electrons;
0395   edm::Handle<trigger::TriggerFilterObjectWithRefs> triggerRecoEcalCandidateCollection;
0396   std::vector<edm::Ref<TCandColl>> recoEcalCandColl;
0397 
0398   // iterator to electron and ecal candidate collections
0399   typename std::vector<edm::EDGetTokenT<TEleColl>>::const_iterator itElectronColl = electronToken_.begin();
0400   std::vector<int>::const_iterator itElectronCollFlag = isGsfElectronCollection_.begin();
0401   std::vector<edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs>>::const_iterator itRecoEcalCandColl =
0402       recoEcalCandidateToken_.begin();
0403 
0404   // if you want to dump just FED related to the triggering electron/s
0405   if (!dumpAllTrackerFed_ || !dumpAllEcalFed_) {
0406     // loop on the same time on ecal candidate and elctron collection and boolean for Gsf ones
0407     for (; itRecoEcalCandColl != recoEcalCandidateToken_.end() and itElectronColl != electronToken_.end() and
0408            itElectronCollFlag != isGsfElectronCollection_.end();
0409          ++itElectronColl, ++itElectronCollFlag, ++itRecoEcalCandColl) {
0410       // get ecal candidate collection
0411       iEvent.getByToken(*itRecoEcalCandColl, triggerRecoEcalCandidateCollection);
0412       if (triggerRecoEcalCandidateCollection.failedToGet())
0413         continue;
0414 
0415       // get gsf electron collection
0416       iEvent.getByToken(*itElectronColl, electrons);
0417       if (electrons.failedToGet())
0418         continue;
0419 
0420       triggerRecoEcalCandidateCollection->getObjects(trigger::TriggerCluster, recoEcalCandColl);
0421       if (recoEcalCandColl.empty())
0422         triggerRecoEcalCandidateCollection->getObjects(trigger::TriggerPhoton, recoEcalCandColl);
0423       if (recoEcalCandColl.empty())
0424         triggerRecoEcalCandidateCollection->getObjects(trigger::TriggerElectron, recoEcalCandColl);
0425 
0426       typename std::vector<edm::Ref<TCandColl>>::const_iterator itRecoEcalCand =
0427           recoEcalCandColl.begin();  // loop on recoEcalCandidate objects
0428 
0429       // loop on the recoEcalCandidates
0430       for (; itRecoEcalCand != recoEcalCandColl.end(); ++itRecoEcalCand) {
0431         recoEcalCand = (*itRecoEcalCand);
0432         reco::SuperClusterRef scRefRecoEcalCand =
0433             recoEcalCand->superCluster();  // take the supercluster in order to match with electron objects
0434 
0435         typename TEleColl::const_iterator itEle = electrons->begin();
0436         for (; itEle != electrons->end(); ++itEle) {  // loop on all the electrons inside a collection
0437           // get electron supercluster and the associated hit -> detID
0438           electron = (*itEle);
0439           reco::SuperClusterRef scRef = electron.superCluster();
0440           if (scRefRecoEcalCand != scRef)
0441             continue;  // mathching
0442 
0443           const std::vector<std::pair<DetId, float>>& hits = scRef->hitsAndFractions();
0444           // start in dump the ecal FED associated to the electron
0445           std::vector<std::pair<DetId, float>>::const_iterator itSChits = hits.begin();
0446           if (!dumpAllEcalFed_) {
0447             for (; itSChits != hits.end(); ++itSChits) {
0448               if ((*itSChits).first.subdetId() == EcalBarrel) {  // barrel part
0449                 EBDetId idEBRaw((*itSChits).first);
0450                 GlobalPoint point = GeometryCalo_->getPosition(idEBRaw);
0451                 int hitFED = FEDNumbering::MINECALFEDID +
0452                              EcalMapping_->GetFED(double(point.eta()), double(point.phi()) * radTodeg);
0453                 if (hitFED < FEDNumbering::MINECALFEDID || hitFED > FEDNumbering::MAXECALFEDID)
0454                   continue;
0455 
0456                 LogDebug("SelectedElectronFEDListProducer")
0457                     << " electron hit detID Barrel " << (*itSChits).first.rawId() << " eta " << double(point.eta())
0458                     << " phi " << double(point.phi()) * radTodeg << " FED " << hitFED << std::endl;
0459 
0460                 if (dumpSelectedEcalFed_) {
0461                   if (!fedList_.empty()) {
0462                     if (std::find(fedList_.begin(), fedList_.end(), hitFED) == fedList_.end())
0463                       fedList_.push_back(hitFED);  // in order not to duplicate info
0464                   } else
0465                     fedList_.push_back(hitFED);
0466                 }
0467               } else if ((*itSChits).first.subdetId() == EcalEndcap) {  // endcap one
0468                 EEDetId idEERaw((*itSChits).first);
0469                 GlobalPoint point = GeometryCalo_->getPosition(idEERaw);
0470                 int hitFED = FEDNumbering::MINECALFEDID +
0471                              EcalMapping_->GetFED(double(point.eta()), double(point.phi()) * radTodeg);
0472                 if (hitFED < FEDNumbering::MINECALFEDID || hitFED > FEDNumbering::MAXECALFEDID)
0473                   continue;
0474 
0475                 LogDebug("SelectedElectronFEDListProducer")
0476                     << " electron hit detID Endcap " << (*itSChits).first.rawId() << " eta " << double(point.eta())
0477                     << " phi " << double(point.phi()) * radTodeg << " FED " << hitFED << std::endl;
0478                 if (dumpSelectedEcalFed_) {
0479                   if (!fedList_.empty()) {
0480                     if (std::find(fedList_.begin(), fedList_.end(), hitFED) == fedList_.end())
0481                       fedList_.push_back(hitFED);
0482                   } else
0483                     fedList_.push_back(hitFED);
0484 
0485                   // preshower hit for each ecal endcap hit
0486                   DetId tmpX =
0487                       (dynamic_cast<const EcalPreshowerGeometry*>(GeometryES_))->getClosestCellInPlane(point, 1);
0488                   ESDetId stripX = (tmpX == DetId(0)) ? ESDetId(0) : ESDetId(tmpX);
0489                   int hitFED =
0490                       ES_fedId_[(3 - stripX.zside()) / 2 - 1][stripX.plane() - 1][stripX.six() - 1][stripX.siy() - 1];
0491                   LogDebug("SelectedElectronFEDListProducer")
0492                       << " ES hit plane X (deiID) " << stripX.rawId() << " six " << stripX.six() << " siy "
0493                       << stripX.siy() << " plane " << stripX.plane() << " FED ID " << hitFED << std::endl;
0494                   if (hitFED < FEDNumbering::MINPreShowerFEDID || hitFED > FEDNumbering::MAXPreShowerFEDID)
0495                     continue;
0496                   if (hitFED < 0)
0497                     continue;
0498                   if (!fedList_.empty()) {
0499                     if (std::find(fedList_.begin(), fedList_.end(), hitFED) == fedList_.end())
0500                       fedList_.push_back(hitFED);
0501                   } else
0502                     fedList_.push_back(hitFED);
0503 
0504                   DetId tmpY =
0505                       (dynamic_cast<const EcalPreshowerGeometry*>(GeometryES_))->getClosestCellInPlane(point, 2);
0506                   ESDetId stripY = (tmpY == DetId(0)) ? ESDetId(0) : ESDetId(tmpY);
0507                   hitFED =
0508                       ES_fedId_[(3 - stripY.zside()) / 2 - 1][stripY.plane() - 1][stripY.six() - 1][stripY.siy() - 1];
0509                   if (hitFED < FEDNumbering::MINPreShowerFEDID || hitFED > FEDNumbering::MAXPreShowerFEDID)
0510                     continue;
0511                   LogDebug("SelectedElectronFEDListProducer")
0512                       << " ES hit plane Y (deiID) " << stripY.rawId() << " six " << stripY.six() << " siy "
0513                       << stripY.siy() << " plane " << stripY.plane() << " FED ID " << hitFED << std::endl;
0514                   if (hitFED < 0)
0515                     continue;
0516                   if (!fedList_.empty()) {
0517                     if (std::find(fedList_.begin(), fedList_.end(), hitFED) == fedList_.end())
0518                       fedList_.push_back(hitFED);
0519                   } else
0520                     fedList_.push_back(hitFED);
0521                 }
0522               }  // end endcap
0523             }    // end loop on SC hit
0524 
0525             // check HCAL behind each hit
0526             if (dumpSelectedHCALFed_) {
0527               HBHERecHitCollection::const_iterator itHcalRecHit = hcalRecHitCollection->begin();
0528               for (; itHcalRecHit != hcalRecHitCollection->end(); ++itHcalRecHit) {
0529                 HcalDetId recHitId(itHcalRecHit->id());
0530                 const HcalGeometry* cellGeometry =
0531                     static_cast<const HcalGeometry*>(GeometryCalo_->getSubdetectorGeometry(recHitId));
0532                 float dR = reco::deltaR(scRef->eta(),
0533                                         scRef->phi(),
0534                                         cellGeometry->getPosition(recHitId).eta(),
0535                                         cellGeometry->getPosition(recHitId).phi());
0536                 if (dR <= dRHcalRegion_) {
0537                   const HcalElectronicsId electronicId = HcalReadoutMap_->lookup(recHitId);
0538                   int hitFED = electronicId.dccid() + FEDNumbering::MINHCALFEDID;
0539                   LogDebug("SelectedElectronFEDListProducer")
0540                       << " matched hcal recHit : HcalDetId " << recHitId << " HcalElectronicsId " << electronicId
0541                       << " dcc id " << electronicId.dccid() << " spigot " << electronicId.spigot() << " fiber channel "
0542                       << electronicId.fiberChanId() << " fiber index " << electronicId.fiberIndex() << std::endl;
0543                   if (hitFED < FEDNumbering::MINHCALFEDID || hitFED > FEDNumbering::MAXHCALFEDID)
0544                     continue;  //first eighteen feds are for HBHE
0545                   if (hitFED < 0)
0546                     continue;
0547                   if (!fedList_.empty()) {
0548                     if (std::find(fedList_.begin(), fedList_.end(), hitFED) == fedList_.end())
0549                       fedList_.push_back(hitFED);
0550                   } else
0551                     fedList_.push_back(hitFED);
0552                 }
0553               }
0554             }  // End Hcal
0555           }    // End Ecal
0556 
0557           // get the electron track
0558           if (!dumpAllTrackerFed_) {
0559             //loop on the region
0560             if (dumpSelectedSiStripFed_) {
0561               double eta;
0562               double phi;
0563               if (*itElectronCollFlag) {
0564                 eta = electron.gsfTrack()->eta();
0565                 phi = electron.gsfTrack()->phi();
0566               } else {
0567                 eta = electron.track()->eta();
0568                 phi = electron.track()->phi();
0569               }
0570               for (uint32_t iCabling = 0; iCabling < SiStripCabling.size(); iCabling++) {
0571                 SiStripRegionCabling::Position pos = StripRegionCabling_->position(iCabling);
0572                 double dphi = fabs(pos.second - phi);
0573                 if (dphi > acos(-1))
0574                   dphi = 2 * acos(-1) - dphi;
0575                 double R = sqrt(pow(pos.first - eta, 2) + dphi * dphi);
0576                 if (R - sqrt(pow(regionDimension_.first / 2, 2) + pow(regionDimension_.second / 2, 2)) > dRStripRegion_)
0577                   continue;
0578                 //get vector of subdets within region
0579                 const SiStripRegionCabling::RegionCabling regSubdets = SiStripCabling[iCabling];
0580                 //cycle on subdets
0581                 for (uint32_t idet = 0; idet < SiStripRegionCabling::ALLSUBDETS; idet++) {  //cicle between 1 and 4
0582                   //get vector of layers whin subdet of region
0583                   const SiStripRegionCabling::WedgeCabling regSubdetLayers = regSubdets[idet];  // at most 10 layers
0584                   for (uint32_t ilayer = 0; ilayer < SiStripRegionCabling::ALLLAYERS; ilayer++) {
0585                     //get map of vectors of feds withing the layer of subdet of region
0586                     const SiStripRegionCabling::ElementCabling fedVectorMap =
0587                         regSubdetLayers[ilayer];  // vector of the fed
0588                     SiStripRegionCabling::ElementCabling::const_iterator itFedMap = fedVectorMap.begin();
0589                     for (; itFedMap != fedVectorMap.end(); itFedMap++) {
0590                       for (uint32_t op = 0; op < (itFedMap->second).size(); op++) {
0591                         int hitFED = (itFedMap->second)[op].fedId();
0592                         if (hitFED < FEDNumbering::MINSiStripFEDID || hitFED > FEDNumbering::MAXSiStripFEDID)
0593                           continue;
0594                         LogDebug("SelectedElectronFEDListProducer") << " SiStrip (FedID) " << hitFED << std::endl;
0595                         if (!fedList_.empty()) {
0596                           if (std::find(fedList_.begin(), fedList_.end(), hitFED) == fedList_.end())
0597                             fedList_.push_back(hitFED);
0598                         } else
0599                           fedList_.push_back(hitFED);
0600                       }
0601                     }
0602                   }
0603                 }
0604               }
0605             }  // end si strip
0606             if (dumpSelectedSiPixelFed_) {
0607               math::XYZVector momentum;
0608               if (*itElectronCollFlag)
0609                 momentum = electron.gsfTrack()->momentum();
0610               else
0611                 momentum = electron.track()->momentum();
0612               PixelRegion region(momentum, dPhiPixelRegion_, dEtaPixelRegion_, maxZPixelRegion_);
0613               PixelModule lowerBound(region.vector.phi() - region.dPhi, region.vector.eta() - region.dEta);
0614               PixelModule upperBound(region.vector.phi() + region.dPhi, region.vector.eta() + region.dEta);
0615 
0616               std::vector<PixelModule>::const_iterator itUp, itDn;
0617               if (lowerBound.Phi >= -M_PI && upperBound.Phi <= M_PI) {
0618                 itDn = std::lower_bound(pixelModuleVector_.begin(), pixelModuleVector_.end(), lowerBound);
0619                 itUp = std::upper_bound(pixelModuleVector_.begin(), pixelModuleVector_.end(), upperBound);
0620                 pixelFedDump(itDn, itUp, region);
0621               } else {
0622                 if (lowerBound.Phi < -M_PI)
0623                   lowerBound.Phi = lowerBound.Phi + 2 * M_PI;
0624                 PixelModule phi_p(M_PI, region.vector.eta() - region.dEta);
0625                 itDn = std::lower_bound(pixelModuleVector_.begin(), pixelModuleVector_.end(), lowerBound);
0626                 itUp = std::upper_bound(pixelModuleVector_.begin(), pixelModuleVector_.end(), phi_p);
0627                 pixelFedDump(itDn, itUp, region);
0628 
0629                 if (upperBound.Phi < -M_PI)
0630                   upperBound.Phi = upperBound.Phi - 2 * M_PI;
0631                 PixelModule phi_m(-M_PI, region.vector.eta() - region.dEta);
0632                 itDn = std::lower_bound(pixelModuleVector_.begin(), pixelModuleVector_.end(), phi_m);
0633                 itUp = std::upper_bound(pixelModuleVector_.begin(), pixelModuleVector_.end(), upperBound);
0634                 pixelFedDump(itDn, itUp, region);
0635               }
0636             }
0637           }  // end tracker analysis
0638         }    // end loop on the electron candidate
0639       }      // end loop on the electron collection collection
0640     }        // end loop on the recoEcal candidate
0641   }          // end loop on the recoEcal candidate collection
0642   // add a set of chosen FED
0643   for (unsigned int iFed = 0; iFed < addThisSelectedFEDs_.size(); iFed++) {
0644     if (addThisSelectedFEDs_.at(iFed) == -1)
0645       continue;
0646     fedList_.push_back(addThisSelectedFEDs_.at(iFed));
0647   }
0648 
0649   // make the final raw data collection
0650   auto streamFEDRawProduct = std::make_unique<FEDRawDataCollection>();
0651   std::sort(fedList_.begin(), fedList_.end());
0652   std::vector<uint32_t>::const_iterator itfedList = fedList_.begin();
0653   for (; itfedList != fedList_.end(); ++itfedList) {
0654     LogDebug("SelectedElectronFEDListProducer") << " fed point " << *itfedList << "  ";
0655     const FEDRawData& data = rawdata->FEDData(*itfedList);
0656     if (data.size() > 0) {
0657       FEDRawData& fedData = streamFEDRawProduct->FEDData(*itfedList);
0658       fedData.resize(data.size());
0659       memcpy(fedData.data(), data.data(), data.size());
0660     }
0661   }
0662 
0663   iEvent.put(std::move(streamFEDRawProduct), outputLabelModule_);
0664 
0665   if (!fedList_.empty())
0666     fedList_.clear();
0667 }
0668 
0669 template <typename TEle, typename TCand>
0670 void SelectedElectronFEDListProducer<TEle, TCand>::endJob() {
0671   LogDebug("SelectedElectronFEDListProducer") << " End of the Job " << std::endl;
0672 }
0673 
0674 template <typename TEle, typename TCand>
0675 void SelectedElectronFEDListProducer<TEle, TCand>::pixelFedDump(std::vector<PixelModule>::const_iterator& itDn,
0676                                                                 std::vector<PixelModule>::const_iterator& itUp,
0677                                                                 const PixelRegion& region) {
0678   for (; itDn != itUp; ++itDn) {
0679     float zmodule = itDn->z - ((itDn->x - beamSpotPosition_.x()) * region.cosphi +
0680                                (itDn->y - beamSpotPosition_.y()) * region.sinphi) *
0681                                   region.atantheta;
0682     if (std::abs(zmodule) > region.maxZ)
0683       continue;
0684     int hitFED = itDn->Fed;
0685     if (hitFED < FEDNumbering::MINSiPixelFEDID || hitFED > FEDNumbering::MAXSiPixelFEDID)
0686       continue;
0687     LogDebug("SelectedElectronFEDListProducer")
0688         << " electron pixel hit " << itDn->DetId << " hitFED " << hitFED << std::endl;
0689     if (!fedList_.empty()) {
0690       if (std::find(fedList_.begin(), fedList_.end(), hitFED) == fedList_.end())
0691         fedList_.push_back(hitFED);
0692     } else
0693       fedList_.push_back(hitFED);
0694   }
0695 
0696   return;
0697 }
0698 
0699 template <typename TEle, typename TCand>
0700 void SelectedElectronFEDListProducer<TEle, TCand>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0701   edm::ParameterSetDescription desc;
0702   desc.add<vector<edm::InputTag>>("electronTags", {edm::InputTag("hltEgammaGsfElectrons")});
0703   desc.add<vector<edm::InputTag>>("recoEcalCandidateTags", {edm::InputTag("hltL1EG25Ele27WP85GsfTrackIsoFilter")});
0704   desc.add<edm::FileInPath>("ESLookupTable", edm::FileInPath("EventFilter/ESDigiToRaw/data/ES_lookup_table.dat"));
0705   desc.add<edm::InputTag>("HBHERecHitTag", edm::InputTag("hltHbhereco"));
0706   desc.add<edm::InputTag>("beamSpotTag", edm::InputTag("hltOnlineBeamSpot"));
0707   desc.add<edm::InputTag>("rawDataTag", edm::InputTag("rawDataCollector"));
0708   desc.add<vector<int>>("addThisSelectedFEDs", {812, 813});
0709   desc.add<vector<int>>("isGsfElectronCollection", {true});
0710   desc.add<std::string>("outputLabelModule", "StreamElectronRawFed");
0711   desc.add<bool>("dumpSelectedSiPixelFed", true);
0712   desc.add<bool>("dumpSelectedSiStripFed", true);
0713   desc.add<bool>("dumpSelectedEcalFed", true);
0714   desc.add<bool>("dumpSelectedHCALFed", true);
0715   desc.add<double>("dPhiPixelRegion", 0.3);
0716   desc.add<double>("dEtaPixelRegion", 0.3);
0717   desc.add<double>("dRStripRegion", 0.3);
0718   desc.add<double>("dRHcalRegion", 0.3);
0719   desc.add<double>("maxZPixelRegion", 24);
0720   desc.add<bool>("dumpAllTrackerFed", false);
0721   desc.add<bool>("dumpAllEcalFed", false);
0722   desc.add<bool>("dumpAllHcalFed", false);
0723 
0724   descriptions.add(defaultModuleLabel<SelectedElectronFEDListProducer<TEle, TCand>>(), desc);
0725 }
0726 
0727 #include "FWCore/PluginManager/interface/ModuleDef.h"
0728 #include "FWCore/Framework/interface/MakerMacros.h"
0729 typedef SelectedElectronFEDListProducer<reco::Electron, reco::RecoEcalCandidate> SelectedElectronFEDListProducerGsf;
0730 DEFINE_FWK_MODULE(SelectedElectronFEDListProducerGsf);