Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-03 23:51:42

0001 
0002 #include "Calibration/EcalCalibAlgos/interface/ECALpedestalPCLworker.h"
0003 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0004 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include <sstream>
0007 
0008 ECALpedestalPCLworker::ECALpedestalPCLworker(const edm::ParameterSet& iConfig)
0009     : pedestalToken_(esConsumes<edm::Transition::BeginRun>()) {
0010   edm::InputTag digiTagEB = iConfig.getParameter<edm::InputTag>("BarrelDigis");
0011   edm::InputTag digiTagEE = iConfig.getParameter<edm::InputTag>("EndcapDigis");
0012 
0013   digiTokenEB_ = consumes<EBDigiCollection>(digiTagEB);
0014   digiTokenEE_ = consumes<EEDigiCollection>(digiTagEE);
0015 
0016   pedestalSamples_ = iConfig.getParameter<uint32_t>("pedestalSamples");
0017   checkSignal_ = iConfig.getParameter<bool>("checkSignal");
0018   sThresholdEB_ = iConfig.getParameter<uint32_t>("sThresholdEB");
0019   sThresholdEE_ = iConfig.getParameter<uint32_t>("sThresholdEE");
0020 
0021   dynamicBooking_ = iConfig.getParameter<bool>("dynamicBooking");
0022   fixedBookingCenterBin_ = iConfig.getParameter<int>("fixedBookingCenterBin");
0023   nBins_ = iConfig.getParameter<int>("nBins");
0024   dqmDir_ = iConfig.getParameter<std::string>("dqmDir");
0025 
0026   edm::InputTag tcdsRecord = iConfig.getParameter<edm::InputTag>("tcdsRecord");
0027   tcdsToken_ = consumes<TCDSRecord>(tcdsRecord);
0028   requireStableBeam_ = iConfig.getParameter<bool>("requireStableBeam");
0029 }
0030 
0031 // ------------ method called for each event  ------------
0032 void ECALpedestalPCLworker::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0033   using namespace edm;
0034 
0035   Handle<EBDigiCollection> pDigiEB;
0036   iEvent.getByToken(digiTokenEB_, pDigiEB);
0037 
0038   Handle<EEDigiCollection> pDigiEE;
0039   iEvent.getByToken(digiTokenEE_, pDigiEE);
0040 
0041   // Only Events with stable beam
0042 
0043   if (requireStableBeam_) {
0044     edm::Handle<TCDSRecord> tcdsData;
0045     iEvent.getByToken(tcdsToken_, tcdsData);
0046     int beamMode = tcdsData->getBST().getBeamMode();
0047     if (beamMode != BSTRecord::BeamMode::STABLE)
0048       return;
0049   }
0050 
0051   for (EBDigiCollection::const_iterator pDigi = pDigiEB->begin(); pDigi != pDigiEB->end(); ++pDigi) {
0052     EBDetId id = pDigi->id();
0053     uint32_t hashedId = id.hashedIndex();
0054 
0055     EBDataFrame digi(*pDigi);
0056 
0057     if (checkSignal_) {
0058       uint16_t maxdiff = *std::max_element(digi.frame().begin(), digi.frame().end(), adc_compare) -
0059                          *std::min_element(digi.frame().begin(), digi.frame().end(), adc_compare);
0060       if (maxdiff > sThresholdEB_)
0061         continue;  // assume there is signal in this frame
0062     }
0063 
0064     //for (auto& mgpasample : digi.frame()) meEB_[hashedId]->Fill(mgpasample&0xFFF);
0065     for (edm::DataFrame::iterator mgpasample = digi.frame().begin();
0066          mgpasample != digi.frame().begin() + pedestalSamples_;
0067          ++mgpasample)
0068       meEB_[hashedId]->Fill(*mgpasample & 0xFFF);
0069 
0070   }  // eb digis
0071 
0072   for (EEDigiCollection::const_iterator pDigi = pDigiEE->begin(); pDigi != pDigiEE->end(); ++pDigi) {
0073     EEDetId id = pDigi->id();
0074     uint32_t hashedId = id.hashedIndex();
0075 
0076     EEDataFrame digi(*pDigi);
0077 
0078     if (checkSignal_) {
0079       uint16_t maxdiff = *std::max_element(digi.frame().begin(), digi.frame().end(), adc_compare) -
0080                          *std::min_element(digi.frame().begin(), digi.frame().end(), adc_compare);
0081       if (maxdiff > sThresholdEE_)
0082         continue;  // assume there is signal in this frame
0083     }
0084 
0085     //for (auto& mgpasample : digi.frame()) meEE_[hashedId]->Fill(mgpasample&0xFFF);
0086     for (edm::DataFrame::iterator mgpasample = digi.frame().begin();
0087          mgpasample != digi.frame().begin() + pedestalSamples_;
0088          ++mgpasample)
0089       meEE_[hashedId]->Fill(*mgpasample & 0xFFF);
0090 
0091   }  // ee digis
0092 }
0093 
0094 void ECALpedestalPCLworker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0095   edm::ParameterSetDescription desc;
0096   desc.setUnknown();
0097   descriptions.addDefault(desc);
0098 }
0099 
0100 void ECALpedestalPCLworker::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& run, edm::EventSetup const& es) {
0101   ibooker.cd();
0102   ibooker.setCurrentFolder(dqmDir_);
0103 
0104   const auto& peds = es.getData(pedestalToken_);
0105 
0106   for (uint32_t i = 0; i < EBDetId::kSizeForDenseIndexing; ++i) {
0107     ibooker.setCurrentFolder(dqmDir_ + "/EB/" + std::to_string(int(i / 100)));
0108 
0109     std::string hname = "eb_" + std::to_string(i);
0110     DetId id = EBDetId::detIdFromDenseIndex(i);
0111     int centralBin = fixedBookingCenterBin_;
0112 
0113     if (dynamicBooking_) {
0114       centralBin = int((peds.find(id))->mean_x12);
0115     }
0116 
0117     int min = centralBin - nBins_ / 2;
0118     int max = centralBin + nBins_ / 2;
0119 
0120     meEB_.push_back(ibooker.book1D(hname, hname, nBins_, min, max));
0121   }
0122 
0123   for (uint32_t i = 0; i < EEDetId::kSizeForDenseIndexing; ++i) {
0124     ibooker.setCurrentFolder(dqmDir_ + "/EE/" + std::to_string(int(i / 100)));
0125 
0126     std::string hname = "ee_" + std::to_string(i);
0127 
0128     DetId id = EEDetId::detIdFromDenseIndex(i);
0129     int centralBin = fixedBookingCenterBin_;
0130 
0131     if (dynamicBooking_) {
0132       centralBin = int((peds.find(id))->mean_x12);
0133     }
0134 
0135     int min = centralBin - nBins_ / 2;
0136     int max = centralBin + nBins_ / 2;
0137 
0138     meEE_.push_back(ibooker.book1D(hname, hname, nBins_, min, max));
0139   }
0140 }