Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-14 02:50:07

0001 // -*- C++ -*-
0002 //
0003 // Package:    HcalCalibTypeFilter
0004 // Class:      HcalCalibTypeFilter
0005 //
0006 /**\class HcalCalibTypeFilter HcalCalibTypeFilter.cc filter/HcalCalibTypeFilter/src/HcalCalibTypeFilter.cc
0007 
0008 Description: <one line class summary>
0009 
0010 Implementation:
0011 <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Giovanni FRANZONI
0015 //         Created:  Tue Jan 22 13:55:00 CET 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
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 // class declaration
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   // ----------member data ---------------------------
0055 
0056   edm::EDGetTokenT<FEDRawDataCollection> tok_data_;
0057   bool Summary_;
0058   std::vector<int> CalibTypes_;
0059   std::vector<int> eventsByType;
0060 };
0061 
0062 //
0063 // constructors and destructor
0064 //
0065 HcalCalibTypeFilter::HcalCalibTypeFilter(const edm::ParameterSet& iConfig) {
0066   //now do what ever initialization is needed
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   // do anything here that needs to be done at desctruction time
0075   // (e.g. close files, deallocate resources etc.)
0076 }
0077 
0078 //
0079 // member functions
0080 //
0081 
0082 // ------------ method called on each new Event  ------------
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   // checking FEDs for calibration information
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)++;  // increment the counter for this calib type
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 // ------------ method called once each job just before starting event loop  ------------
0128 void HcalCalibTypeFilter::beginJob() {
0129   eventsByType.clear();
0130   eventsByType.resize(8, 0);
0131 }
0132 
0133 // ------------ method called once each job just after ending the event loop  ------------
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 //define this as a plug-in
0143 DEFINE_FWK_MODULE(HcalCalibTypeFilter);