72 template <
typename TEle,
typename TCand>
75 if (iConfig.
existsAs<std::vector<edm::InputTag>>(
"electronTags")) {
76 electronTags_ = iConfig.
getParameter<std::vector<edm::InputTag>>(
"electronTags");
77 if (electronTags_.empty())
79 <<
"[SelectedElectronFEDListProducer] empty electron collection is given --> at least one \n";
82 <<
"[SelectedElectronFEDListProducer] no electron collection are given --> need at least one \n";
85 LogDebug(
"SelectedElectronFEDListProducer") <<
" Electron Collections" << std::endl;
86 for (std::vector<edm::InputTag>::const_iterator itEleTag = electronTags_.begin(); itEleTag != electronTags_.end();
88 electronToken_.push_back(consumes<TEleColl>(*itEleTag));
89 LogDebug(
"SelectedElectronFEDListProducer") <<
" Ele collection: " << *(itEleTag) << std::endl;
93 if (iConfig.
existsAs<std::vector<edm::InputTag>>(
"recoEcalCandidateTags")) {
94 recoEcalCandidateTags_ = iConfig.
getParameter<std::vector<edm::InputTag>>(
"recoEcalCandidateTags");
95 if (recoEcalCandidateTags_.empty())
96 throw cms::Exception(
"Configuration") <<
"[SelectedElectronFEDListProducer] empty ecal candidate collections "
97 "collection is given --> at least one \n";
99 throw cms::Exception(
"Configuration") <<
"[SelectedElectronFEDListProducer] no electron reco ecal candidate "
100 "collection are given --> need at least one \n";
103 for (std::vector<edm::InputTag>::const_iterator itEcalCandTag = recoEcalCandidateTags_.begin();
104 itEcalCandTag != recoEcalCandidateTags_.end();
106 recoEcalCandidateToken_.push_back(consumes<trigger::TriggerFilterObjectWithRefs>(*itEcalCandTag));
107 LogDebug(
"SelectedElectronFEDListProducer") <<
" Reco ecal candidate collection: " << *(itEcalCandTag) << std::endl;
111 if (iConfig.
existsAs<std::vector<int>>(
"isGsfElectronCollection")) {
112 isGsfElectronCollection_ = iConfig.
getParameter<std::vector<int>>(
"isGsfElectronCollection");
113 if (isGsfElectronCollection_.empty())
115 <<
"[SelectedElectronFEDListProducer] empty electron flag collection --> at least one \n";
118 <<
"[SelectedElectronFEDListProducer] no electron flag are given --> need at least one \n";
120 if (isGsfElectronCollection_.size() != electronTags_.size()
or
121 isGsfElectronCollection_.size() != recoEcalCandidateTags_.size())
122 throw cms::Exception(
"Configuration") <<
"[SelectedElectronFEDListProducer] electron flag , electron collection "
123 "and reco ecal cand collection must have the same size ! \n";
132 beamSpotToken_ = consumes<reco::BeamSpot>(beamSpotTag_);
134 LogDebug(
"SelectedElectronFEDListProducer") <<
" Beam Spot Tag " << beamSpotTag_ << std::endl;
143 hbheRecHitToken_ = consumes<HBHERecHitCollection>(HBHERecHitTag_);
152 rawDataToken_ = consumes<FEDRawDataCollection>(rawDataTag_);
154 LogDebug(
"SelectedElectronFEDListProducer") <<
" RawDataInput " << rawDataTag_ << std::endl;
157 if (iConfig.
existsAs<std::vector<int>>(
"addThisSelectedFEDs")) {
158 addThisSelectedFEDs_ = iConfig.
getParameter<std::vector<int>>(
"addThisSelectedFEDs");
159 if (addThisSelectedFEDs_.empty())
160 addThisSelectedFEDs_.push_back(-1);
162 addThisSelectedFEDs_.push_back(-1);
164 std::vector<int>::const_iterator AddFed = addThisSelectedFEDs_.begin();
165 for (; AddFed != addThisSelectedFEDs_.end(); ++AddFed)
166 LogDebug(
"SelectedElectronFEDListProducer") <<
" Additional FED: " << *(AddFed) << std::endl;
172 ESLookupTable_ =
edm::FileInPath(
"EventFilter/ESDigiToRaw/data/ES_lookup_table.dat");
178 outputLabelModule_ =
"streamElectronRawData";
180 LogDebug(
"SelectedElectronFEDListProducer") <<
" Output Label " << outputLabelModule_ << std::endl;
183 if (iConfig.
existsAs<
double>(
"dRStripRegion"))
184 dRStripRegion_ = iConfig.
getParameter<
double>(
"dRStripRegion");
186 dRStripRegion_ = 0.5;
188 LogDebug(
"SelectedElectronFEDListProducer") <<
" dRStripRegion " << dRStripRegion_ << std::endl;
191 if (iConfig.
existsAs<
double>(
"dRHcalRegion"))
192 dRHcalRegion_ = iConfig.
getParameter<
double>(
"dRHcalRegion");
197 if (iConfig.
existsAs<
double>(
"dPhiPixelRegion"))
198 dPhiPixelRegion_ = iConfig.
getParameter<
double>(
"dPhiPixelRegion");
200 dPhiPixelRegion_ = 0.5;
202 if (iConfig.
existsAs<
double>(
"dEtaPixelRegion"))
203 dEtaPixelRegion_ = iConfig.
getParameter<
double>(
"dEtaPixelRegion");
205 dEtaPixelRegion_ = 0.5;
207 if (iConfig.
existsAs<
double>(
"maxZPixelRegion"))
208 maxZPixelRegion_ = iConfig.
getParameter<
double>(
"maxZPixelRegion");
210 maxZPixelRegion_ = 24.;
212 LogDebug(
"SelectedElectronFEDListProducer")
213 <<
" dPhiPixelRegion " << dPhiPixelRegion_ <<
" dEtaPixelRegion " << dEtaPixelRegion_ <<
" MaxZPixelRegion "
214 << maxZPixelRegion_ << std::endl;
217 if (iConfig.
existsAs<
bool>(
"dumpSelectedEcalFed"))
218 dumpSelectedEcalFed_ = iConfig.
getParameter<
bool>(
"dumpSelectedEcalFed");
220 dumpSelectedEcalFed_ =
true;
222 if (iConfig.
existsAs<
bool>(
"dumpSelectedSiStripFed"))
223 dumpSelectedSiStripFed_ = iConfig.
getParameter<
bool>(
"dumpSelectedSiStripFed");
225 dumpSelectedSiStripFed_ =
true;
227 if (iConfig.
existsAs<
bool>(
"dumpSelectedSiPixelFed"))
228 dumpSelectedSiPixelFed_ = iConfig.
getParameter<
bool>(
"dumpSelectedSiPixelFed");
230 dumpSelectedSiPixelFed_ =
true;
232 if (iConfig.
existsAs<
bool>(
"dumpSelectedHCALFed"))
233 dumpSelectedHCALFed_ = iConfig.
getParameter<
bool>(
"dumpSelectedHCALFed");
235 dumpSelectedHCALFed_ =
true;
237 LogDebug(
"SelectedElectronFEDListProducer")
238 <<
" DumpEcalFedList set to " << dumpSelectedEcalFed_ <<
" DumpSelectedSiStripFed " << dumpSelectedSiStripFed_
239 <<
" DumpSelectedSiPixelFed " << dumpSelectedSiPixelFed_ << std::endl;
241 if (iConfig.
existsAs<
bool>(
"dumpAllEcalFed"))
242 dumpAllEcalFed_ = iConfig.
getParameter<
bool>(
"dumpAllEcalFed");
244 dumpAllEcalFed_ =
false;
246 if (iConfig.
existsAs<
bool>(
"dumpAllTrackerFed"))
247 dumpAllTrackerFed_ = iConfig.
getParameter<
bool>(
"dumpAllTrackerFed");
249 dumpAllTrackerFed_ =
false;
251 if (iConfig.
existsAs<
bool>(
"dumpAllHCALFed"))
252 dumpAllHCALFed_ = iConfig.
getParameter<
bool>(
"dumpAllHCALFed");
254 dumpAllHCALFed_ =
false;
256 LogDebug(
"SelectedElectronFEDListProducer")
257 <<
" DumpAllEcalFed " << dumpAllEcalFed_ <<
" DumpAllTrackerFed " << dumpAllTrackerFed_ <<
" Dump all HCAL fed "
258 << dumpAllHCALFed_ << std::endl;
261 for (
int i = 0;
i < 2; ++
i)
262 for (
int j = 0;
j < 2; ++
j)
263 for (
int k = 0;
k < 40; ++
k)
264 for (
int m = 0;
m < 40;
m++)
265 ES_fedId_[
i][
j][
k][
m] = -1;
268 int nLines, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
269 std::ifstream ES_file;
270 ES_file.open(ESLookupTable_.fullPath().c_str());
271 LogDebug(
"SelectedElectronFEDListProducer")
272 <<
" Look Up table for ES " << ESLookupTable_.fullPath().c_str() << std::endl;
273 if (ES_file.is_open()) {
276 ES_file >> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
277 ES_fedId_[(3 - iz) / 2 - 1][ip - 1][ix - 1][iy - 1] = fed;
280 LogDebug(
"SelectedElectronFEDListProducer")
281 <<
" Look up table file can not be found in " << ESLookupTable_.fullPath().c_str() << std::endl;
285 produces<FEDRawDataCollection>(outputLabelModule_);
288 template <
typename TEle,
typename TCand>
290 if (!electronTags_.empty())
291 electronTags_.clear();
292 if (!recoEcalCandidateTags_.empty())
293 recoEcalCandidateTags_.clear();
294 if (!recoEcalCandidateToken_.empty())
295 recoEcalCandidateToken_.clear();
296 if (!electronToken_.empty())
297 electronToken_.clear();
298 if (!fedList_.empty())
300 if (!pixelModuleVector_.empty())
301 pixelModuleVector_.clear();
304 template <
typename TEle,
typename TCand>
306 LogDebug(
"SelectedElectronFEDListProducer") <<
" Begin of the Job " << std::endl;
309 template <
typename TEle,
typename TCand>
319 EcalMapping_ = ecalmapping.
product();
324 GeometryCalo_ = caloGeometry.
product();
332 PixelCabling_.reset();
338 if (pixelModuleVector_.empty()) {
340 std::vector<const GeomDet*>::const_iterator itTracker = trackerGeometry->
dets().begin();
341 for (; itTracker != trackerGeometry->
dets().end(); ++itTracker) {
342 int subdet = (*itTracker)->geographicalId().subdetId();
346 module.x = (*itTracker)->position().x();
347 module.y = (*itTracker)->position().y();
348 module.z = (*itTracker)->position().z();
349 module.Phi = (*itTracker)->position().phi();
350 module.Eta = (*itTracker)->position().eta();
351 module.DetId = (*itTracker)->geographicalId().rawId();
352 const std::vector<sipixelobjects::CablingPathToDetUnit> path2det = PixelCabling_->pathToDetUnit(
module.DetId);
353 module.Fed = path2det[0].fed;
355 pixelModuleVector_.push_back(
module);
357 std::sort(pixelModuleVector_.begin(), pixelModuleVector_.end());
362 StripRegionCabling_ = SiStripCablingHandle.
product();
366 regionDimension_ = StripRegionCabling_->regionDimensions();
372 iEvent.getByToken(rawDataToken_, rawdata);
379 beamSpotPosition_ =
beamSpot->position();
381 beamSpotPosition_.SetXYZ(0, 0, 0);
386 iEvent.getByToken(hbheRecHitToken_, hbheRecHitHandle);
389 hcalRecHitCollection = hbheRecHitHandle.
product();
391 double radTodeg = 180. /
Geom::pi();
393 if (dumpAllEcalFed_) {
395 fedList_.push_back(iEcalFed);
397 fedList_.push_back(iESFed);
400 if (dumpAllTrackerFed_) {
402 fedList_.push_back(iPixelFed);
404 fedList_.push_back(iStripFed);
407 if (dumpAllHCALFed_) {
409 fedList_.push_back(iHcalFed);
417 std::vector<edm::Ref<TCandColl>> recoEcalCandColl;
420 typename std::vector<edm::EDGetTokenT<TEleColl>>::const_iterator itElectronColl = electronToken_.begin();
421 std::vector<int>::const_iterator itElectronCollFlag = isGsfElectronCollection_.begin();
422 std::vector<edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs>>::const_iterator itRecoEcalCandColl =
423 recoEcalCandidateToken_.begin();
426 if (!dumpAllTrackerFed_ || !dumpAllEcalFed_) {
428 for (; itRecoEcalCandColl != recoEcalCandidateToken_.end() and itElectronColl != electronToken_.end() and
429 itElectronCollFlag != isGsfElectronCollection_.end();
430 ++itElectronColl, ++itElectronCollFlag, ++itRecoEcalCandColl) {
432 iEvent.getByToken(*itRecoEcalCandColl, triggerRecoEcalCandidateCollection);
433 if (triggerRecoEcalCandidateCollection.
failedToGet())
442 if (recoEcalCandColl.empty())
444 if (recoEcalCandColl.empty())
447 typename std::vector<edm::Ref<TCandColl>>::const_iterator itRecoEcalCand =
448 recoEcalCandColl.begin();
451 for (; itRecoEcalCand != recoEcalCandColl.end(); ++itRecoEcalCand) {
452 recoEcalCand = (*itRecoEcalCand);
454 recoEcalCand->superCluster();
456 typename TEleColl::const_iterator itEle =
electrons->begin();
457 for (; itEle !=
electrons->end(); ++itEle) {
461 if (scRefRecoEcalCand != scRef)
464 const std::vector<std::pair<DetId, float>>&
hits = scRef->hitsAndFractions();
466 std::vector<std::pair<DetId, float>>::const_iterator itSChits =
hits.begin();
467 if (!dumpAllEcalFed_) {
468 for (; itSChits !=
hits.end(); ++itSChits) {
469 if ((*itSChits).first.subdetId() ==
EcalBarrel) {
470 EBDetId idEBRaw((*itSChits).first);
473 EcalMapping_->GetFED(
double(
point.eta()),
double(
point.phi()) * radTodeg);
477 LogDebug(
"SelectedElectronFEDListProducer")
478 <<
" electron hit detID Barrel " << (*itSChits).first.rawId() <<
" eta " << double(
point.eta())
479 <<
" phi " <<
double(
point.phi()) * radTodeg <<
" FED " << hitFED << std::endl;
481 if (dumpSelectedEcalFed_) {
482 if (!fedList_.empty()) {
483 if (
std::find(fedList_.begin(), fedList_.end(), hitFED) == fedList_.end())
484 fedList_.push_back(hitFED);
486 fedList_.push_back(hitFED);
488 }
else if ((*itSChits).first.subdetId() ==
EcalEndcap) {
489 EEDetId idEERaw((*itSChits).first);
492 EcalMapping_->GetFED(
double(
point.eta()),
double(
point.phi()) * radTodeg);
496 LogDebug(
"SelectedElectronFEDListProducer")
497 <<
" electron hit detID Endcap " << (*itSChits).first.rawId() <<
" eta " << double(
point.eta())
498 <<
" phi " <<
double(
point.phi()) * radTodeg <<
" FED " << hitFED << std::endl;
499 if (dumpSelectedEcalFed_) {
500 if (!fedList_.empty()) {
501 if (
std::find(fedList_.begin(), fedList_.end(), hitFED) == fedList_.end())
502 fedList_.push_back(hitFED);
504 fedList_.push_back(hitFED);
508 (dynamic_cast<const EcalPreshowerGeometry*>(GeometryES_))->getClosestCellInPlane(
point, 1);
511 ES_fedId_[(3 - stripX.
zside()) / 2 - 1][stripX.
plane() - 1][stripX.
six() - 1][stripX.
siy() - 1];
512 LogDebug(
"SelectedElectronFEDListProducer")
513 <<
" ES hit plane X (deiID) " << stripX.
rawId() <<
" six " << stripX.
six() <<
" siy "
514 << stripX.
siy() <<
" plane " << stripX.
plane() <<
" FED ID " << hitFED << std::endl;
519 if (!fedList_.empty()) {
520 if (
std::find(fedList_.begin(), fedList_.end(), hitFED) == fedList_.end())
521 fedList_.push_back(hitFED);
523 fedList_.push_back(hitFED);
526 (dynamic_cast<const EcalPreshowerGeometry*>(GeometryES_))->getClosestCellInPlane(
point, 2);
529 ES_fedId_[(3 - stripY.
zside()) / 2 - 1][stripY.
plane() - 1][stripY.
six() - 1][stripY.
siy() - 1];
532 LogDebug(
"SelectedElectronFEDListProducer")
533 <<
" ES hit plane Y (deiID) " << stripY.
rawId() <<
" six " << stripY.
six() <<
" siy "
534 << stripY.
siy() <<
" plane " << stripY.
plane() <<
" FED ID " << hitFED << std::endl;
537 if (!fedList_.empty()) {
538 if (
std::find(fedList_.begin(), fedList_.end(), hitFED) == fedList_.end())
539 fedList_.push_back(hitFED);
541 fedList_.push_back(hitFED);
547 if (dumpSelectedHCALFed_) {
549 for (; itHcalRecHit != hcalRecHitCollection->
end(); ++itHcalRecHit) {
552 static_cast<const HcalGeometry*>(GeometryCalo_->getSubdetectorGeometry(recHitId));
555 cellGeometry->getPosition(recHitId).eta(),
556 cellGeometry->getPosition(recHitId).phi());
557 if (
dR <= dRHcalRegion_) {
560 LogDebug(
"SelectedElectronFEDListProducer")
561 <<
" matched hcal recHit : HcalDetId " << recHitId <<
" HcalElectronicsId " << electronicId
562 <<
" dcc id " << electronicId.
dccid() <<
" spigot " << electronicId.
spigot() <<
" fiber channel "
568 if (!fedList_.empty()) {
569 if (
std::find(fedList_.begin(), fedList_.end(), hitFED) == fedList_.end())
570 fedList_.push_back(hitFED);
572 fedList_.push_back(hitFED);
579 if (!dumpAllTrackerFed_) {
581 if (dumpSelectedSiStripFed_) {
584 if (*itElectronCollFlag) {
591 for (uint32_t iCabling = 0; iCabling < SiStripCabling.size(); iCabling++) {
593 double dphi = fabs(
pos.second - phi);
595 dphi = 2 * acos(-1) - dphi;
597 if (
R -
sqrt(
pow(regionDimension_.first / 2, 2) +
pow(regionDimension_.second / 2, 2)) > dRStripRegion_)
608 regSubdetLayers[ilayer];
609 SiStripRegionCabling::ElementCabling::const_iterator itFedMap = fedVectorMap.begin();
610 for (; itFedMap != fedVectorMap.end(); itFedMap++) {
611 for (uint32_t op = 0; op < (itFedMap->second).
size(); op++) {
612 int hitFED = (itFedMap->second)[op].
fedId();
615 LogDebug(
"SelectedElectronFEDListProducer") <<
" SiStrip (FedID) " << hitFED << std::endl;
616 if (!fedList_.empty()) {
617 if (
std::find(fedList_.begin(), fedList_.end(), hitFED) == fedList_.end())
618 fedList_.push_back(hitFED);
620 fedList_.push_back(hitFED);
627 if (dumpSelectedSiPixelFed_) {
629 if (*itElectronCollFlag)
630 momentum =
electron.gsfTrack()->momentum();
632 momentum =
electron.track()->momentum();
633 PixelRegion region(momentum, dPhiPixelRegion_, dEtaPixelRegion_, maxZPixelRegion_);
637 std::vector<PixelModule>::const_iterator itUp, itDn;
638 if (lowerBound.Phi >= -
M_PI && upperBound.Phi <=
M_PI) {
639 itDn =
std::lower_bound(pixelModuleVector_.begin(), pixelModuleVector_.end(), lowerBound);
640 itUp =
std::upper_bound(pixelModuleVector_.begin(), pixelModuleVector_.end(), upperBound);
641 pixelFedDump(itDn, itUp,
region);
643 if (lowerBound.Phi < -
M_PI)
644 lowerBound.Phi = lowerBound.Phi + 2 *
M_PI;
646 itDn =
std::lower_bound(pixelModuleVector_.begin(), pixelModuleVector_.end(), lowerBound);
647 itUp =
std::upper_bound(pixelModuleVector_.begin(), pixelModuleVector_.end(), phi_p);
648 pixelFedDump(itDn, itUp,
region);
650 if (upperBound.Phi < -
M_PI)
651 upperBound.Phi = upperBound.Phi - 2 *
M_PI;
653 itDn =
std::lower_bound(pixelModuleVector_.begin(), pixelModuleVector_.end(), phi_m);
654 itUp =
std::upper_bound(pixelModuleVector_.begin(), pixelModuleVector_.end(), upperBound);
655 pixelFedDump(itDn, itUp,
region);
664 for (
unsigned int iFed = 0; iFed < addThisSelectedFEDs_.size(); iFed++) {
665 if (addThisSelectedFEDs_.at(iFed) == -1)
667 fedList_.push_back(addThisSelectedFEDs_.at(iFed));
671 auto streamFEDRawProduct = std::make_unique<FEDRawDataCollection>();
672 std::sort(fedList_.begin(), fedList_.end());
673 std::vector<uint32_t>::const_iterator itfedList = fedList_.begin();
674 for (; itfedList != fedList_.end(); ++itfedList) {
675 LogDebug(
"SelectedElectronFEDListProducer") <<
" fed point " << *itfedList <<
" ";
677 if (
data.size() > 0) {
678 FEDRawData& fedData = streamFEDRawProduct->FEDData(*itfedList);
686 if (!fedList_.empty())
690 template <
typename TEle,
typename TCand>
692 LogDebug(
"SelectedElectronFEDListProducer") <<
" End of the Job " << std::endl;
695 template <
typename TEle,
typename TCand>
697 std::vector<PixelModule>::const_iterator& itUp,
699 for (; itDn != itUp; ++itDn) {
700 float zmodule = itDn->z - ((itDn->x - beamSpotPosition_.x()) *
region.cosphi +
701 (itDn->y - beamSpotPosition_.y()) *
region.sinphi) *
705 int hitFED = itDn->Fed;
708 LogDebug(
"SelectedElectronFEDListProducer")
709 <<
" electron pixel hit " << itDn->DetId <<
" hitFED " << hitFED << std::endl;
710 if (!fedList_.empty()) {
711 if (
std::find(fedList_.begin(), fedList_.end(), hitFED) == fedList_.end())
712 fedList_.push_back(hitFED);
714 fedList_.push_back(hitFED);
720 template <
typename TEle,
typename TCand>
723 desc.add<vector<edm::InputTag>>(
"electronTags", {
edm::InputTag(
"hltEgammaGsfElectrons")});
724 desc.add<vector<edm::InputTag>>(
"recoEcalCandidateTags", {
edm::InputTag(
"hltL1EG25Ele27WP85GsfTrackIsoFilter")});
729 desc.add<vector<int>>(
"addThisSelectedFEDs", {812, 813});
730 desc.add<vector<int>>(
"isGsfElectronCollection", {
true});
732 desc.add<
bool>(
"dumpSelectedSiPixelFed",
true);
733 desc.add<
bool>(
"dumpSelectedSiStripFed",
true);
734 desc.add<
bool>(
"dumpSelectedEcalFed",
true);
735 desc.add<
bool>(
"dumpSelectedHCALFed",
true);
736 desc.add<
double>(
"dPhiPixelRegion", 0.3);
737 desc.add<
double>(
"dEtaPixelRegion", 0.3);
738 desc.add<
double>(
"dRStripRegion", 0.3);
739 desc.add<
double>(
"dRHcalRegion", 0.3);
740 desc.add<
double>(
"maxZPixelRegion", 24);
741 desc.add<
bool>(
"dumpAllTrackerFed",
false);
742 desc.add<
bool>(
"dumpAllEcalFed",
false);
743 desc.add<
bool>(
"dumpAllHcalFed",
false);