From afbc6b9a1144de0c6737f42072391ccaf2109839 Mon Sep 17 00:00:00 2001 From: Stefano Argiro Date: Fri, 28 Apr 2017 13:12:15 +0200 Subject: [PATCH 1/4] added flexibility in the pedestal PCL workflow --- .../interface/ECALpedestalPCLHarvester.h | 6 ++ .../interface/ECALpedestalPCLworker.h | 13 +++- .../python/ecalPedestalPCLHarvester_cfi.py | 15 ++-- .../python/ecalPedestalPCLworker_cfi.py | 10 ++- .../src/ECALpedestalPCLHarvester.cc | 57 ++++++++++++-- .../src/ECALpedestalPCLworker.cc | 78 +++++++++++++++---- 6 files changed, 143 insertions(+), 36 deletions(-) diff --git a/Calibration/EcalCalibAlgos/interface/ECALpedestalPCLHarvester.h b/Calibration/EcalCalibAlgos/interface/ECALpedestalPCLHarvester.h index b320c410ca71f..78b679486ed06 100644 --- a/Calibration/EcalCalibAlgos/interface/ECALpedestalPCLHarvester.h +++ b/Calibration/EcalCalibAlgos/interface/ECALpedestalPCLHarvester.h @@ -43,6 +43,12 @@ class ECALpedestalPCLHarvester : public DQMEDHarvester { const EcalPedestals * currentPedestals_; const EcalChannelStatus * channelStatus_; bool checkStatusCode(const DetId& id); + bool checkVariation(const EcalPedestalsMap& oldPedestals, const EcalPedestalsMap& newPedestals); std::vector chStatusToExclude_; int minEntries_; + + bool checkAnomalies_ ; // whether or not to avoid creating sqlite file in case of many changed pedestals + double nSigma_; // threshold in sigmas to define a pedestal as changed + double thresholdAnomalies_; // threshold (fraction of changed pedestals) to avoid creation of sqlite file + std::string dqmDir_; // DQM directory where histograms are stored }; diff --git a/Calibration/EcalCalibAlgos/interface/ECALpedestalPCLworker.h b/Calibration/EcalCalibAlgos/interface/ECALpedestalPCLworker.h index d6059361e7c7b..7f3421c585d24 100644 --- a/Calibration/EcalCalibAlgos/interface/ECALpedestalPCLworker.h +++ b/Calibration/EcalCalibAlgos/interface/ECALpedestalPCLworker.h @@ -53,9 +53,16 @@ class ECALpedestalPCLworker : public DQMEDAnalyzer { std::vector meEB_; std::vector meEE_; - static const int kPedestalSamples = 3; - static const int kThreshold = 10; // threshold (in adc count) above which we'll assume - // there's signal and not just pedestal + uint32_t pedestalSamples_ ; // number of presamples to be used for pedestal determination + bool checkSignal_; // avoid frames containing a signal + uint32_t sThreshold_ ; // if checkSignal = true threshold (in adc count) above which we'll assume + // there's signal and not just pedestal + + bool dynamicBooking_; // use old pedestal to book histograms + int fixedBookingCenterBin_; // if dynamicBooking_ = false, use this as bin center + int nBins_ ; // number of bins per histogram + std::string dqmDir_; // DQM directory where histograms are stored + // compare ADC values static bool adc_compare(uint16_t a, uint16_t b) { return ( a&0xFFF ) < (b&0xFFF);} diff --git a/Calibration/EcalCalibAlgos/python/ecalPedestalPCLHarvester_cfi.py b/Calibration/EcalCalibAlgos/python/ecalPedestalPCLHarvester_cfi.py index b7e81110d9d9d..a2376966b4d3c 100644 --- a/Calibration/EcalCalibAlgos/python/ecalPedestalPCLHarvester_cfi.py +++ b/Calibration/EcalCalibAlgos/python/ecalPedestalPCLHarvester_cfi.py @@ -1,14 +1,9 @@ import FWCore.ParameterSet.Config as cms ECALpedestalPCLHarvester = cms.EDAnalyzer('ECALpedestalPCLHarvester', MinEntries = cms.int32(100), #skip channel if stat is low - ChannelStatusToExclude = cms.vstring('kDAC', - 'kNoisy', - 'kNNoisy', - 'kFixedG6', - 'kFixedG1', - 'kFixedG0', - 'kNonRespondingIsolated', - 'kDeadVFE', - 'kDeadFE', - 'kNoDataNoTP',) + ChannelStatusToExclude = cms.vstring(), # db statuses to exclude + checkAnomalies = cms.bool(False), # whether or not to avoid creating sqlite file in case of many changed pedestals + nSigma = cms.double(5.0), # threshold in sigmas to define a pedestal as anomally changed + thresholdAnomalies = cms.double(0.1),# threshold (fraction of changed pedestals) to avoid creation of sqlite file + dqmDir = cms.string('AlCaReco/EcalPedestalsPCL') ) diff --git a/Calibration/EcalCalibAlgos/python/ecalPedestalPCLworker_cfi.py b/Calibration/EcalCalibAlgos/python/ecalPedestalPCLworker_cfi.py index a41c81d51da18..da6c41a0a7384 100644 --- a/Calibration/EcalCalibAlgos/python/ecalPedestalPCLworker_cfi.py +++ b/Calibration/EcalCalibAlgos/python/ecalPedestalPCLworker_cfi.py @@ -2,4 +2,12 @@ ecalpedestalPCL =cms.EDAnalyzer('ECALpedestalPCLworker', BarrelDigis=cms.InputTag('ecalDigis','ebDigis'), - EndcapDigis=cms.InputTag('ecalDigis','eeDigis')) + EndcapDigis=cms.InputTag('ecalDigis','eeDigis'), + pedestalSamples=cms.uint32(2), # number of presamples to be used for pedestal determination + checkSignal = cms.bool(False), # whether or not to exclude digis containing a signal + sThreshold = cms.uint32(10), # threshold to define a digi as containing signal + dqmDir = cms.string('AlCaReco/EcalPedestalsPCL'), + dynamicBooking = cms.bool(True), # use old pedestal to book histograms (central bin) + fixedBookingCenterBin = cms.int32(200), # if dynamicBooking = false, use this as center bin + nBins = cms.int32(40) # number of bins per histogram +) diff --git a/Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc b/Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc index 8fde1ddf76716..0472abad06ffb 100644 --- a/Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc +++ b/Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc @@ -22,7 +22,10 @@ ECALpedestalPCLHarvester::ECALpedestalPCLHarvester(const edm::ParameterSet& ps): chStatusToExclude_= StringToEnumValue(ps.getParameter >("ChannelStatusToExclude")); minEntries_=ps.getParameter("MinEntries"); - + checkAnomalies_ = ps.getParameter("checkAnomalies"); + nSigma_ = ps.getParameter("nSigma"); + thresholdAnomalies_ = ps.getParameter("thresholdAnomalies"); + dqmDir_ = ps.getParameter("dqmDir"); } void ECALpedestalPCLHarvester::dqmEndJob(DQMStore::IBooker& ibooker_, DQMStore::IGetter& igetter_) { @@ -30,15 +33,15 @@ void ECALpedestalPCLHarvester::dqmEndJob(DQMStore::IBooker& ibooker_, DQMStore:: // calculate pedestals and fill db record EcalPedestals pedestals; - std::string hname; + for (uint16_t i =0; i< EBDetId::kSizeForDenseIndexing; ++i) { - hname = "AlCaReco/EcalPedestalsPCL/eb_" + std::to_string(i); + std::string hname = dqmDir_+"/eb_" + std::to_string(i); MonitorElement* ch= igetter_.get(hname); double mean = ch->getMean(); double rms = ch->getRMS(); - DetId id = EBDetId::detIdFromDenseIndex(i); + DetId id = EBDetId::detIdFromDenseIndex(i); EcalPedestal ped; EcalPedestal oldped=* currentPedestals_->find(id.rawId()); @@ -63,8 +66,9 @@ void ECALpedestalPCLHarvester::dqmEndJob(DQMStore::IBooker& ibooker_, DQMStore:: for (uint16_t i =0; i< EEDetId::kSizeForDenseIndexing; ++i) { - hname = "AlCaReco/EcalPedestalsPCL/ee_" + std::to_string(i); + std::string hname = dqmDir_+"/ee_" + std::to_string(i); + MonitorElement* ch= igetter_.get(hname); double mean = ch->getMean(); double rms = ch->getRMS(); @@ -91,7 +95,14 @@ void ECALpedestalPCLHarvester::dqmEndJob(DQMStore::IBooker& ibooker_, DQMStore:: } + // check if there are large variations wrt exisiting pedstals + if (checkAnomalies_){ + if (checkVariation(*currentPedestals_, pedestals)) { + edm::LogError("Large Variations found wrt to old pedestals, no file created"); + return; + } + } // write out pedestal record edm::Service poolDbService; @@ -141,3 +152,39 @@ bool ECALpedestalPCLHarvester::checkStatusCode(const DetId& id){ return true; } + + +bool ECALpedestalPCLHarvester::checkVariation(const EcalPedestalsMap& oldPedestals, + const EcalPedestalsMap& newPedestals) { + + uint32_t nAnomaliesEB =0; + uint32_t nAnomaliesEE =0; + + for (uint16_t i =0; i< EBDetId::kSizeForDenseIndexing; ++i) { + + DetId id = EBDetId::detIdFromDenseIndex(i); + const EcalPedestal& newped=* newPedestals.find(id.rawId()); + const EcalPedestal& oldped=* oldPedestals.find(id.rawId()); + + if (abs(newped.mean_x12 -oldped.mean_x12) > nSigma_ * oldped.rms_x12) nAnomaliesEB++; + + } + + for (uint16_t i =0; i< EEDetId::kSizeForDenseIndexing; ++i) { + + DetId id = EEDetId::detIdFromDenseIndex(i); + const EcalPedestal& newped=* newPedestals.find(id.rawId()); + const EcalPedestal& oldped=* oldPedestals.find(id.rawId()); + + if (abs(newped.mean_x12 -oldped.mean_x12) > nSigma_ * oldped.rms_x12) nAnomaliesEE++; + + } + + if (nAnomaliesEB > thresholdAnomalies_ * EBDetId::kSizeForDenseIndexing || + nAnomaliesEE > thresholdAnomalies_ * EEDetId::kSizeForDenseIndexing) + return false; + + return true; + + +} diff --git a/Calibration/EcalCalibAlgos/src/ECALpedestalPCLworker.cc b/Calibration/EcalCalibAlgos/src/ECALpedestalPCLworker.cc index ff453ac27f5f5..f00caa0b9d285 100644 --- a/Calibration/EcalCalibAlgos/src/ECALpedestalPCLworker.cc +++ b/Calibration/EcalCalibAlgos/src/ECALpedestalPCLworker.cc @@ -2,7 +2,10 @@ #include "Calibration/EcalCalibAlgos/interface/ECALpedestalPCLworker.h" #include "DataFormats/EcalDetId/interface/EBDetId.h" #include "DataFormats/EcalDetId/interface/EEDetId.h" - +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "CondFormats/EcalObjects/interface/EcalPedestals.h" +#include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h" #include #include @@ -16,6 +19,15 @@ ECALpedestalPCLworker::ECALpedestalPCLworker(const edm::ParameterSet& iConfig) digiTokenEB_ = consumes(digiTagEB_); digiTokenEE_ = consumes(digiTagEE_); + + pedestalSamples_ = iConfig.getParameter("pedestalSamples"); + checkSignal_ = iConfig.getParameter("checkSignal"); + sThreshold_ = iConfig.getParameter("sThreshold"); + + dynamicBooking_ = iConfig.getParameter("dynamicBooking"); + fixedBookingCenterBin_ = iConfig.getParameter("fixedBookingCenterBin"); + nBins_ = iConfig.getParameter("nBins"); + dqmDir_ = iConfig.getParameter("dqmDir"); } @@ -40,32 +52,39 @@ ECALpedestalPCLworker::analyze(const edm::Event& iEvent, const edm::EventSetup& uint32_t hashedId = id.hashedIndex(); EBDataFrame digi( *pDigi ); + + if (checkSignal_){ + uint16_t maxdiff = *std::max_element(digi.frame().begin(), digi.frame().end(), adc_compare ) - + *std::min_element(digi.frame().begin(), digi.frame().end(), adc_compare ); + if ( maxdiff> sThreshold_ ) continue; // assume there is signal in this frame + } - uint16_t maxdiff = *std::max_element(digi.frame().begin(), digi.frame().end(), adc_compare ) - - *std::min_element(digi.frame().begin(), digi.frame().end(), adc_compare ); - if ( maxdiff> kThreshold ) continue; // assume there is signal in this frame //for (auto& mgpasample : digi.frame()) meEB_[hashedId]->Fill(mgpasample&0xFFF); for (edm::DataFrame::iterator mgpasample = digi.frame().begin(); - mgpasample!=digi.frame().begin()+kPedestalSamples; + mgpasample!=digi.frame().begin()+pedestalSamples_; ++mgpasample ) meEB_[hashedId]->Fill(*mgpasample&0xFFF); } // eb digis + for (EEDigiCollection::const_iterator pDigi=pDigiEE->begin(); pDigi!=pDigiEE->end(); ++pDigi){ EEDetId id = pDigi->id(); uint32_t hashedId = id.hashedIndex(); - EBDataFrame digi( *pDigi ); + EEDataFrame digi( *pDigi ); + + if (checkSignal_){ + uint16_t maxdiff = *std::max_element(digi.frame().begin(), digi.frame().end(), adc_compare ) - + *std::min_element(digi.frame().begin(), digi.frame().end(), adc_compare ); + if ( maxdiff> sThreshold_ ) continue; // assume there is signal in this frame + } - uint16_t maxdiff = *std::max_element(digi.frame().begin(), digi.frame().end(), adc_compare ) - - *std::min_element(digi.frame().begin(), digi.frame().end(), adc_compare ); - if ( maxdiff> kThreshold ) continue; // assume there is signal in this frame //for (auto& mgpasample : digi.frame()) meEE_[hashedId]->Fill(mgpasample&0xFFF); for (edm::DataFrame::iterator mgpasample = digi.frame().begin(); - mgpasample!=digi.frame().begin()+kPedestalSamples; + mgpasample!=digi.frame().begin()+pedestalSamples_; ++mgpasample ) meEE_[hashedId]->Fill(*mgpasample&0xFFF); @@ -101,18 +120,43 @@ void ECALpedestalPCLworker::bookHistograms(DQMStore::IBooker & ibooker, edm::Run const & run, edm::EventSetup const & es){ ibooker.cd(); - ibooker.setCurrentFolder("AlCaReco/EcalPedestalsPCL"); + ibooker.setCurrentFolder(dqmDir_); + + edm::ESHandle peds; + es.get().get(peds); + for ( uint32_t i = 0 ; i< EBDetId::kSizeForDenseIndexing; ++i){ - std::stringstream hname; - hname<<"eb_"<find(id))->mean_x12) ; + } + + int min = centralBin - nBins_/2; + int max = centralBin + nBins_/2; + + meEB_.push_back(ibooker.book1D(hname,hname,nBins_,min,max)); } for ( uint32_t i = 0 ; i< EEDetId::kSizeForDenseIndexing; ++i){ - std::stringstream hname; - hname<<"ee_"<find(id))->mean_x12) ; + } + + int min = centralBin - nBins_/2; + int max = centralBin + nBins_/2; + + meEE_.push_back(ibooker.book1D(hname,hname,nBins_,min,max)); } From 772c5466ffb2efb74aeaf1626a1c0e1d79e04710 Mon Sep 17 00:00:00 2001 From: Stefano Argiro Date: Fri, 28 Apr 2017 13:19:43 +0200 Subject: [PATCH 2/4] fixed but --- Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc b/Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc index 0472abad06ffb..5be11eac1b5d7 100644 --- a/Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc +++ b/Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc @@ -182,9 +182,9 @@ bool ECALpedestalPCLHarvester::checkVariation(const EcalPedestalsMap& oldPedesta if (nAnomaliesEB > thresholdAnomalies_ * EBDetId::kSizeForDenseIndexing || nAnomaliesEE > thresholdAnomalies_ * EEDetId::kSizeForDenseIndexing) - return false; + return true; - return true; + return false; } From 835f249a5a0081a82445f4a4c9f35105940db891 Mon Sep 17 00:00:00 2001 From: Stefano Argiro Date: Tue, 2 May 2017 17:08:18 +0200 Subject: [PATCH 3/4] separate thresholds to define signal in EE and EB --- .../EcalCalibAlgos/interface/ECALpedestalPCLworker.h | 4 +++- .../EcalCalibAlgos/python/ecalPedestalPCLworker_cfi.py | 7 ++++--- Calibration/EcalCalibAlgos/src/ECALpedestalPCLworker.cc | 7 ++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Calibration/EcalCalibAlgos/interface/ECALpedestalPCLworker.h b/Calibration/EcalCalibAlgos/interface/ECALpedestalPCLworker.h index 7f3421c585d24..cee684ed6c426 100644 --- a/Calibration/EcalCalibAlgos/interface/ECALpedestalPCLworker.h +++ b/Calibration/EcalCalibAlgos/interface/ECALpedestalPCLworker.h @@ -55,9 +55,11 @@ class ECALpedestalPCLworker : public DQMEDAnalyzer { uint32_t pedestalSamples_ ; // number of presamples to be used for pedestal determination bool checkSignal_; // avoid frames containing a signal - uint32_t sThreshold_ ; // if checkSignal = true threshold (in adc count) above which we'll assume + uint32_t sThresholdEB_ ; // if checkSignal = true threshold (in adc count) above which we'll assume // there's signal and not just pedestal + uint32_t sThresholdEE_ ; + bool dynamicBooking_; // use old pedestal to book histograms int fixedBookingCenterBin_; // if dynamicBooking_ = false, use this as bin center int nBins_ ; // number of bins per histogram diff --git a/Calibration/EcalCalibAlgos/python/ecalPedestalPCLworker_cfi.py b/Calibration/EcalCalibAlgos/python/ecalPedestalPCLworker_cfi.py index da6c41a0a7384..c88db6dda2343 100644 --- a/Calibration/EcalCalibAlgos/python/ecalPedestalPCLworker_cfi.py +++ b/Calibration/EcalCalibAlgos/python/ecalPedestalPCLworker_cfi.py @@ -3,9 +3,10 @@ ecalpedestalPCL =cms.EDAnalyzer('ECALpedestalPCLworker', BarrelDigis=cms.InputTag('ecalDigis','ebDigis'), EndcapDigis=cms.InputTag('ecalDigis','eeDigis'), - pedestalSamples=cms.uint32(2), # number of presamples to be used for pedestal determination - checkSignal = cms.bool(False), # whether or not to exclude digis containing a signal - sThreshold = cms.uint32(10), # threshold to define a digi as containing signal + pedestalSamples=cms.uint32(2), # number of presamples to be used for pedestal determination + checkSignal = cms.bool(False), # whether or not to exclude digis containing a signal + sThresholdEB = cms.uint32(10), # threshold to define a digi as containing signal + sThresholdEE = cms.uint32(15), dqmDir = cms.string('AlCaReco/EcalPedestalsPCL'), dynamicBooking = cms.bool(True), # use old pedestal to book histograms (central bin) fixedBookingCenterBin = cms.int32(200), # if dynamicBooking = false, use this as center bin diff --git a/Calibration/EcalCalibAlgos/src/ECALpedestalPCLworker.cc b/Calibration/EcalCalibAlgos/src/ECALpedestalPCLworker.cc index f00caa0b9d285..00228e2e29e36 100644 --- a/Calibration/EcalCalibAlgos/src/ECALpedestalPCLworker.cc +++ b/Calibration/EcalCalibAlgos/src/ECALpedestalPCLworker.cc @@ -22,7 +22,8 @@ ECALpedestalPCLworker::ECALpedestalPCLworker(const edm::ParameterSet& iConfig) pedestalSamples_ = iConfig.getParameter("pedestalSamples"); checkSignal_ = iConfig.getParameter("checkSignal"); - sThreshold_ = iConfig.getParameter("sThreshold"); + sThresholdEB_ = iConfig.getParameter("sThresholdEB"); + sThresholdEE_ = iConfig.getParameter("sThresholdEE"); dynamicBooking_ = iConfig.getParameter("dynamicBooking"); fixedBookingCenterBin_ = iConfig.getParameter("fixedBookingCenterBin"); @@ -56,7 +57,7 @@ ECALpedestalPCLworker::analyze(const edm::Event& iEvent, const edm::EventSetup& if (checkSignal_){ uint16_t maxdiff = *std::max_element(digi.frame().begin(), digi.frame().end(), adc_compare ) - *std::min_element(digi.frame().begin(), digi.frame().end(), adc_compare ); - if ( maxdiff> sThreshold_ ) continue; // assume there is signal in this frame + if ( maxdiff> sThresholdEB_ ) continue; // assume there is signal in this frame } //for (auto& mgpasample : digi.frame()) meEB_[hashedId]->Fill(mgpasample&0xFFF); @@ -79,7 +80,7 @@ ECALpedestalPCLworker::analyze(const edm::Event& iEvent, const edm::EventSetup& if (checkSignal_){ uint16_t maxdiff = *std::max_element(digi.frame().begin(), digi.frame().end(), adc_compare ) - *std::min_element(digi.frame().begin(), digi.frame().end(), adc_compare ); - if ( maxdiff> sThreshold_ ) continue; // assume there is signal in this frame + if ( maxdiff> sThresholdEE_ ) continue; // assume there is signal in this frame } //for (auto& mgpasample : digi.frame()) meEE_[hashedId]->Fill(mgpasample&0xFFF); From 32290877b2c699ce14a345790a4b03d6b69e52bd Mon Sep 17 00:00:00 2001 From: Stefano Argiro Date: Wed, 3 May 2017 14:02:45 +0200 Subject: [PATCH 4/4] abs to std::abs --- Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc b/Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc index 5be11eac1b5d7..d001b2920028d 100644 --- a/Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc +++ b/Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc @@ -166,7 +166,7 @@ bool ECALpedestalPCLHarvester::checkVariation(const EcalPedestalsMap& oldPedesta const EcalPedestal& newped=* newPedestals.find(id.rawId()); const EcalPedestal& oldped=* oldPedestals.find(id.rawId()); - if (abs(newped.mean_x12 -oldped.mean_x12) > nSigma_ * oldped.rms_x12) nAnomaliesEB++; + if (std::abs(newped.mean_x12 -oldped.mean_x12) > nSigma_ * oldped.rms_x12) nAnomaliesEB++; } @@ -176,7 +176,7 @@ bool ECALpedestalPCLHarvester::checkVariation(const EcalPedestalsMap& oldPedesta const EcalPedestal& newped=* newPedestals.find(id.rawId()); const EcalPedestal& oldped=* oldPedestals.find(id.rawId()); - if (abs(newped.mean_x12 -oldped.mean_x12) > nSigma_ * oldped.rms_x12) nAnomaliesEE++; + if (std::abs(newped.mean_x12 -oldped.mean_x12) > nSigma_ * oldped.rms_x12) nAnomaliesEE++; }