File indexing completed on 2024-04-06 12:10:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024
0025 #include "FWCore/Framework/interface/one/EDFilter.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030
0031 #include <string>
0032 #include <iostream>
0033
0034 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0035 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0036 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0037 #include "DataFormats/HcalDigi/interface/HcalCalibrationEventTypes.h"
0038 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
0039
0040
0041
0042
0043
0044 class HcalCalibTypeFilter : public edm::one::EDFilter<> {
0045 public:
0046 explicit HcalCalibTypeFilter(const edm::ParameterSet&);
0047 ~HcalCalibTypeFilter() override;
0048
0049 private:
0050 void beginJob() override;
0051 bool filter(edm::Event&, const edm::EventSetup&) override;
0052 void endJob() override;
0053
0054
0055
0056 edm::EDGetTokenT<FEDRawDataCollection> tok_data_;
0057 bool Summary_;
0058 std::vector<int> CalibTypes_;
0059 std::vector<int> eventsByType;
0060 };
0061
0062
0063
0064
0065 HcalCalibTypeFilter::HcalCalibTypeFilter(const edm::ParameterSet& iConfig) {
0066
0067
0068 tok_data_ = consumes<FEDRawDataCollection>(edm::InputTag(iConfig.getParameter<std::string>("InputLabel")));
0069 Summary_ = iConfig.getUntrackedParameter<bool>("FilterSummary", false);
0070 CalibTypes_ = iConfig.getParameter<std::vector<int> >("CalibTypes");
0071 }
0072
0073 HcalCalibTypeFilter::~HcalCalibTypeFilter() {
0074
0075
0076 }
0077
0078
0079
0080
0081
0082
0083 bool HcalCalibTypeFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0084 using namespace edm;
0085
0086 edm::Handle<FEDRawDataCollection> rawdata;
0087 iEvent.getByToken(tok_data_, rawdata);
0088
0089 if (!rawdata.isValid()) {
0090 return false;
0091 }
0092
0093
0094 int calibType = -1;
0095 int numEmptyFEDs = 0;
0096 std::vector<int> calibTypeCounter(8, 0);
0097 for (int i = FEDNumbering::MINHCALFEDID; i <= FEDNumbering::MAXHCALFEDID; i++) {
0098 const FEDRawData& fedData = rawdata->FEDData(i);
0099 if (fedData.size() < 24)
0100 numEmptyFEDs++;
0101 if (fedData.size() < 24)
0102 continue;
0103 int value = ((const HcalDCCHeader*)(fedData.data()))->getCalibType();
0104 calibTypeCounter.at(value)++;
0105 }
0106
0107 int maxCount = 0;
0108 int numberOfFEDIds = FEDNumbering::MAXHCALFEDID - FEDNumbering::MINHCALFEDID + 1;
0109 for (unsigned int i = 0; i < calibTypeCounter.size(); i++) {
0110 if (calibTypeCounter.at(i) > maxCount) {
0111 calibType = i;
0112 maxCount = calibTypeCounter.at(i);
0113 }
0114 if (maxCount == numberOfFEDIds)
0115 break;
0116 }
0117 if (maxCount != (numberOfFEDIds - numEmptyFEDs))
0118 edm::LogWarning("HcalCalibTypeFilter") << "Conflicting calibration types found. Assigning type " << calibType;
0119 LogDebug("HcalCalibTypeFilter") << "Calibration type is: " << calibType;
0120 eventsByType.at(calibType)++;
0121 for (unsigned int i = 0; i < CalibTypes_.size(); i++)
0122 if (calibType == CalibTypes_.at(i))
0123 return true;
0124 return false;
0125 }
0126
0127
0128 void HcalCalibTypeFilter::beginJob() {
0129 eventsByType.clear();
0130 eventsByType.resize(8, 0);
0131 }
0132
0133
0134 void HcalCalibTypeFilter::endJob() {
0135 if (Summary_)
0136 edm::LogWarning("HcalCalibTypeFilter")
0137 << "Summary of filter decisions: " << eventsByType.at(hc_Null) << "(No Calib), " << eventsByType.at(hc_Pedestal)
0138 << "(Pedestal), " << eventsByType.at(hc_RADDAM) << "(RADDAM), " << eventsByType.at(hc_HBHEHPD) << "(HBHE/HPD), "
0139 << eventsByType.at(hc_HOHPD) << "(HO/HPD), " << eventsByType.at(hc_HFPMT) << "(HF/PMT)";
0140 }
0141
0142
0143 DEFINE_FWK_MODULE(HcalCalibTypeFilter);