Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ecalpedestal pcl improved #18512

Merged
merged 4 commits into from
May 3, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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
};
13 changes: 10 additions & 3 deletions Calibration/EcalCalibAlgos/interface/ECALpedestalPCLworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ class ECALpedestalPCLworker : public DQMEDAnalyzer {
std::vector<MonitorElement *> meEB_;
std::vector<MonitorElement *> 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello @argiro

With the noise being significantly different between EB and EE (factor 2-3),
and somewhat |eta| dependent in EE
the significance to have "signal" in EB and EE dataframes
could be set here in relative terms in units of of sigma's of the noise
and the check carried out against Numsigna's x sigma_in_db


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);}
Expand Down
15 changes: 5 additions & 10 deletions Calibration/EcalCalibAlgos/python/ecalPedestalPCLHarvester_cfi.py
Original file line number Diff line number Diff line change
@@ -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')
)
10 changes: 9 additions & 1 deletion Calibration/EcalCalibAlgos/python/ecalPedestalPCLworker_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
57 changes: 52 additions & 5 deletions Calibration/EcalCalibAlgos/src/ECALpedestalPCLHarvester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,26 @@ ECALpedestalPCLHarvester::ECALpedestalPCLHarvester(const edm::ParameterSet& ps):

chStatusToExclude_= StringToEnumValue<EcalChannelStatusCode::Code>(ps.getParameter<std::vector<std::string> >("ChannelStatusToExclude"));
minEntries_=ps.getParameter<int>("MinEntries");

checkAnomalies_ = ps.getParameter<bool>("checkAnomalies");
nSigma_ = ps.getParameter<double>("nSigma");
thresholdAnomalies_ = ps.getParameter<double>("thresholdAnomalies");
dqmDir_ = ps.getParameter<std::string>("dqmDir");
}

void ECALpedestalPCLHarvester::dqmEndJob(DQMStore::IBooker& ibooker_, DQMStore::IGetter& igetter_) {


// 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());

Expand All @@ -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();
Expand All @@ -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<cond::service::PoolDBOutputService> poolDbService;
Expand Down Expand Up @@ -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++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @argiro - please use std:abs.


}

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 true;

return false;


}
78 changes: 61 additions & 17 deletions Calibration/EcalCalibAlgos/src/ECALpedestalPCLworker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iostream>
#include <sstream>

Expand All @@ -16,6 +19,15 @@ ECALpedestalPCLworker::ECALpedestalPCLworker(const edm::ParameterSet& iConfig)

digiTokenEB_ = consumes<EBDigiCollection>(digiTagEB_);
digiTokenEE_ = consumes<EEDigiCollection>(digiTagEE_);

pedestalSamples_ = iConfig.getParameter<uint32_t>("pedestalSamples");
checkSignal_ = iConfig.getParameter<bool>("checkSignal");
sThreshold_ = iConfig.getParameter<uint32_t>("sThreshold");

dynamicBooking_ = iConfig.getParameter<bool>("dynamicBooking");
fixedBookingCenterBin_ = iConfig.getParameter<int>("fixedBookingCenterBin");
nBins_ = iConfig.getParameter<int>("nBins");
dqmDir_ = iConfig.getParameter<std::string>("dqmDir");
}


Expand All @@ -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);

Expand Down Expand Up @@ -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<EcalPedestals> peds;
es.get<EcalPedestalsRcd>().get(peds);


for ( uint32_t i = 0 ; i< EBDetId::kSizeForDenseIndexing; ++i){
std::stringstream hname;
hname<<"eb_"<<i;
meEB_.push_back(ibooker.book1D(hname.str(),hname.str(),100,150,250));

std::string hname = "eb_" + std::to_string(i);
DetId id = EBDetId::detIdFromDenseIndex(i);
int centralBin = fixedBookingCenterBin_;

if (dynamicBooking_){
centralBin = int ((peds->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_"<<i;
meEE_.push_back(ibooker.book1D(hname.str(),hname.str(),100,150,250));

std::string hname = "ee_" + std::to_string(i);

DetId id = EEDetId::detIdFromDenseIndex(i);
int centralBin = fixedBookingCenterBin_;

if (dynamicBooking_){
centralBin = int ((peds->find(id))->mean_x12) ;
}

int min = centralBin - nBins_/2;
int max = centralBin + nBins_/2;

meEE_.push_back(ibooker.book1D(hname,hname,nBins_,min,max));

}

Expand Down