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

Run3-hcx282 Use ESGetToken in CalibCalorimetry/CastorCalib #32604

Merged
merged 2 commits into from Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion CalibCalorimetry/CastorCalib/interface/CastorLedAnalysis.h
Expand Up @@ -7,7 +7,6 @@
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Framework/interface/ESHandle.h"

#include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"

Expand Down
Expand Up @@ -7,7 +7,6 @@
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
#include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
Expand Down
@@ -1,7 +1,6 @@
#ifndef CastorPedestalsAnalysis_H
#define CastorPedestalsAnalysis_H

#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
Expand Down Expand Up @@ -97,6 +96,9 @@ class CastorPedestalsAnalysis : public edm::EDAnalyzer {
std::string XMLtag;
std::string ZSfilename;

edm::ESGetToken<CastorDbService, CastorDbRecord> tok_cond_;
edm::ESGetToken<CastorElectronicsMap, CastorElectronicsMapRcd> tok_map_;

TH1F *CASTORMeans;
TH1F *CASTORWidths;

Expand Down
17 changes: 6 additions & 11 deletions CalibCalorimetry/CastorCalib/plugins/CastorPedestalsAnalysis.cc
Expand Up @@ -16,6 +16,9 @@ CastorPedestalsAnalysis::CastorPedestalsAnalysis(const edm::ParameterSet& ps)
firstTS = ps.getUntrackedParameter<int>("firstTS", 0);
lastTS = ps.getUntrackedParameter<int>("lastTS", 9);
firsttime = true;

tok_cond_ = esConsumes<CastorDbService, CastorDbRecord>();
tok_map_ = esConsumes<CastorElectronicsMap, CastorElectronicsMapRcd>();
}

CastorPedestalsAnalysis::~CastorPedestalsAnalysis() {
Expand Down Expand Up @@ -250,15 +253,10 @@ CastorPedestalsAnalysis::~CastorPedestalsAnalysis() {

// ------------ method called to for each event ------------
void CastorPedestalsAnalysis::analyze(const edm::Event& e, const edm::EventSetup& iSetup) {
using namespace edm;
using namespace std;

edm::Handle<CastorDigiCollection> castor;
e.getByLabel(castorDigiCollectionTag, castor);

edm::ESHandle<CastorDbService> conditions;
iSetup.get<CastorDbRecord>().get(conditions);

auto conditions = &iSetup.getData(tok_cond_);
const CastorQIEShape* shape = conditions->getCastorShape();

if (firsttime) {
Expand Down Expand Up @@ -290,9 +288,7 @@ void CastorPedestalsAnalysis::analyze(const edm::Event& e, const edm::EventSetup
// dephist[2] = new TH2F("Pedestals (ADC)","Depth 3",89, -44, 44, 72, .5, 72.5);
// dephist[3] = new TH2F("Pedestals (ADC)","Depth 4",89, -44, 44, 72, .5, 72.5);

edm::ESHandle<CastorElectronicsMap> refEMap;
iSetup.get<CastorElectronicsMapRcd>().get(refEMap);
const CastorElectronicsMap* myRefEMap = refEMap.product();
const CastorElectronicsMap* myRefEMap = &iSetup.getData(tok_map_);
std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); ++it) {
HcalGenericDetId mygenid(it->rawId());
Expand All @@ -301,8 +297,7 @@ void CastorPedestalsAnalysis::analyze(const edm::Event& e, const edm::EventSetup
HcalCastorDetId chanid(mygenid.rawId());
a.detid = chanid;
a.usedflag = false;
string type;
type = "CASTOR";
std::string type = "CASTOR";
for (int i = 0; i != 4; i++) {
a.cap[i] = 0;
a.capfc[i] = 0;
Expand Down
53 changes: 27 additions & 26 deletions CalibCalorimetry/CastorCalib/src/CastorPedestalAnalysis.cc
Expand Up @@ -7,11 +7,10 @@
#include "CondFormats/CastorObjects/interface/CastorPedestalWidths.h"

#include "CalibCalorimetry/CastorCalib/interface/CastorPedestalAnalysis.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <TFile.h>
#include <cmath>

using namespace std;

CastorPedestalAnalysis::CastorPedestalAnalysis(const edm::ParameterSet& ps)
: fRefPedestals(nullptr),
fRefPedestalWidths(nullptr),
Expand All @@ -29,17 +28,17 @@ CastorPedestalAnalysis::CastorPedestalAnalysis(const edm::ParameterSet& ps)
state.push_back(true);

// user cfg parameters
m_outputFileMean = ps.getUntrackedParameter<string>("outputFileMeans", "");
m_outputFileMean = ps.getUntrackedParameter<std::string>("outputFileMeans", "");
if (!m_outputFileMean.empty()) {
cout << "Castor pedestal means will be saved to " << m_outputFileMean.c_str() << endl;
edm::LogWarning("Castor") << "Castor pedestal means will be saved to " << m_outputFileMean.c_str();
}
m_outputFileWidth = ps.getUntrackedParameter<string>("outputFileWidths", "");
m_outputFileWidth = ps.getUntrackedParameter<std::string>("outputFileWidths", "");
if (!m_outputFileWidth.empty()) {
cout << "Castor pedestal widths will be saved to " << m_outputFileWidth.c_str() << endl;
edm::LogWarning("Castor") << "Castor pedestal widths will be saved to " << m_outputFileWidth.c_str();
}
m_outputFileROOT = ps.getUntrackedParameter<string>("outputFileHist", "");
m_outputFileROOT = ps.getUntrackedParameter<std::string>("outputFileHist", "");
if (!m_outputFileROOT.empty()) {
cout << "Castor pedestal histograms will be saved to " << m_outputFileROOT.c_str() << endl;
edm::LogWarning("Castor") << "Castor pedestal histograms will be saved to " << m_outputFileROOT.c_str();
}
m_nevtsample = ps.getUntrackedParameter<int>("nevtsample", 0);
// for compatibility with previous versions
Expand All @@ -51,9 +50,9 @@ CastorPedestalAnalysis::CastorPedestalAnalysis(const edm::ParameterSet& ps)
if (m_pedValflag < 0)
m_pedValflag = 0;
if (m_nevtsample > 0 && m_pedValflag > 0) {
cout << "WARNING - incompatible cfg options: nevtsample = " << m_nevtsample << ", pedValflag = " << m_pedValflag
<< endl;
cout << "Setting pedValflag = 0" << endl;
edm::LogWarning("Castor") << "WARNING - incompatible cfg options: nevtsample = " << m_nevtsample
<< ", pedValflag = " << m_pedValflag;
edm::LogWarning("Castor") << "Setting pedValflag = 0";
m_pedValflag = 0;
}
if (m_pedValflag > 1)
Expand Down Expand Up @@ -146,7 +145,7 @@ void CastorPedestalAnalysis::per2CapsHists(int flag,
const HcalDetId detid,
const HcalQIESample& qie1,
const HcalQIESample& qie2,
map<HcalDetId, map<int, PEDBUNCH> >& toolT,
std::map<HcalDetId, std::map<int, PEDBUNCH> >& toolT,
const CastorDbService& cond) {
// this function is due to be called for every time slice, it fills either a charge
// histo for a single capID (flag=0) or a product histo for two capIDs (flag>0)
Expand All @@ -155,9 +154,9 @@ void CastorPedestalAnalysis::per2CapsHists(int flag,
static const int bins2 = 100;
float lo = -0.5;
float hi = 9.5;
map<int, PEDBUNCH> _mei;
static map<HcalDetId, map<int, float> > QieCalibMap;
string type = "Castor";
std::map<int, PEDBUNCH> _mei;
static std::map<HcalDetId, std::map<int, float> > QieCalibMap;
std::string type = "Castor";

/*
if(id==0){
Expand All @@ -176,8 +175,8 @@ void CastorPedestalAnalysis::per2CapsHists(int flag,

// if histos for the current channel do not exist, first create them,
if (_meot == toolT.end()) {
map<int, PEDBUNCH> insert;
map<int, float> qiecalib;
std::map<int, PEDBUNCH> insert;
std::map<int, float> qiecalib;
char name[1024];
for (int i = 0; i < 4; i++) {
lo = -0.5;
Expand Down Expand Up @@ -266,7 +265,7 @@ void CastorPedestalAnalysis::per2CapsHists(int flag,

// fill 2 capID histo
if (flag > 0) {
map<int, float> qiecalib = QieCalibMap[detid];
std::map<int, float> qiecalib = QieCalibMap[detid];
//float charge1=(qie1.adc()-qiecalib[qie1.capid()+4])/qiecalib[qie1.capid()];
//float charge2=(qie2.adc()-qiecalib[qie2.capid()+4])/qiecalib[qie2.capid()];
if (charge1 * charge2 < bins2) {
Expand All @@ -292,11 +291,11 @@ void CastorPedestalAnalysis::AllChanHists(const HcalDetId detid,
const HcalQIESample& qie3,
const HcalQIESample& qie4,
const HcalQIESample& qie5,
map<HcalDetId, map<int, PEDBUNCH> >& toolT) {
std::map<HcalDetId, std::map<int, PEDBUNCH> >& toolT) {
// this function is due to be called for every channel

_meot = toolT.find(detid);
map<int, PEDBUNCH> _mei = _meot->second;
std::map<int, PEDBUNCH> _mei = _meot->second;
_mei[16].first->Fill(qie4.adc() + qie5.adc() - 1.);
_mei[17].first->Fill(qie4.adc() + qie5.adc() - qie2.adc() - qie3.adc());
_mei[18].first->Fill(qie4.adc() + qie5.adc() - (qie0.adc() + qie1.adc() + qie2.adc() + qie3.adc()) / 2.);
Expand All @@ -316,7 +315,9 @@ void CastorPedestalAnalysis::SampleAnalysis() {
}

//-----------------------------------------------------------------------------
void CastorPedestalAnalysis::GetPedConst(map<HcalDetId, map<int, PEDBUNCH> >& toolT, TH1F* PedMeans, TH1F* PedWidths) {
void CastorPedestalAnalysis::GetPedConst(std::map<HcalDetId, std::map<int, PEDBUNCH> >& toolT,
TH1F* PedMeans,
TH1F* PedWidths) {
// Completely rewritten version oct 2006
// Compute pedestal constants and fill into CastorPedestals and CastorPedestalWidths objects
float cap[4];
Expand Down Expand Up @@ -547,18 +548,18 @@ int CastorPedestalAnalysis::done(const CastorPedestals* fInputPedestals,
castorHists.PEDMEAN->Write();

m_file->Close();
cout << "Hcal/Castor histograms written to " << m_outputFileROOT.c_str() << endl;
edm::LogWarning("Castor") << "Hcal/Castor histograms written to " << m_outputFileROOT.c_str();
return (int)m_AllPedsOK;
}

//-----------------------------------------------------------------------------
void CastorPedestalAnalysis::Trendings(map<HcalDetId, map<int, PEDBUNCH> >& toolT,
void CastorPedestalAnalysis::Trendings(std::map<HcalDetId, std::map<int, PEDBUNCH> >& toolT,
TH1F* Chi2,
TH1F* CapidAverage,
TH1F* CapidChi2) {
// check stability of pedestal constants in a single long run

map<int, std::vector<double> > AverageValues;
std::map<int, std::vector<double> > AverageValues;

for (_meot = toolT.begin(); _meot != toolT.end(); _meot++) {
for (int i = 0; i < 4; i++) {
Expand Down Expand Up @@ -727,8 +728,8 @@ int CastorPedestalAnalysis::CastorPedVal(int nstat[4],
float RefPedSigs[4][4];
float RawPedVals[4];
float RawPedSigs[4][4];
map<HcalDetId, bool> isinRaw;
map<HcalDetId, bool> isinRef;
std::map<HcalDetId, bool> isinRaw;
std::map<HcalDetId, bool> isinRef;
std::vector<DetId> RefChanns = fRefPedestals->getAllChannels();
std::vector<DetId> RawChanns = fRawPedestals->getAllChannels();
std::ofstream PedValLog;
Expand Down