forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding a pedestals cond format, filler and tester
- Loading branch information
Showing
17 changed files
with
352 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
CalibCalorimetry/HGCalPlugins/plugins/HGCalPedestalsESSource.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
#include "FWCore/Framework/interface/SourceFactory.h" | ||
#include "FWCore/Framework/interface/ESHandle.h" | ||
#include "FWCore/Framework/interface/ESProducer.h" | ||
#include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h" | ||
#include "FWCore/Framework/interface/ESProducts.h" | ||
#include "FWCore/ParameterSet/interface/FileInPath.h" | ||
#include "DataFormats/Math/interface/libminifloat.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "CondFormats/DataRecord/interface/HGCalCondSerializablePedestalsRcd.h" | ||
#include "CondFormats/HGCalObjects/interface/HGCalCondSerializablePedestals.h" | ||
|
||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <sstream> | ||
|
||
/** | ||
@short simple plugin to parse a pedestals file and construct the pedestals object | ||
*/ | ||
class HGCalPedestalsESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder { | ||
public: | ||
explicit HGCalPedestalsESSource(const edm::ParameterSet& iConfig) | ||
: filename_(iConfig.getParameter<std::string>("filename")) { | ||
setWhatProduced(this); | ||
findingRecord<HGCalCondSerializablePedestalsRcd>(); | ||
} | ||
|
||
std::unique_ptr<HGCalCondSerializablePedestals> produce(const HGCalCondSerializablePedestalsRcd&) { return parsePedestals(filename_); } | ||
|
||
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.add<std::string>("filename", {}); | ||
descriptions.addWithDefaultLabel(desc); | ||
} | ||
|
||
private: | ||
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&, | ||
const edm::IOVSyncValue&, | ||
edm::ValidityInterval& oValidity) override { | ||
oValidity = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime()); | ||
} | ||
|
||
std::unique_ptr<HGCalCondSerializablePedestals> parsePedestals(const std::string& filename); | ||
|
||
const std::string filename_; | ||
}; | ||
|
||
|
||
// | ||
std::unique_ptr<HGCalCondSerializablePedestals> HGCalPedestalsESSource::parsePedestals(const std::string& filename) | ||
{ | ||
auto cond = std::make_unique<HGCalCondSerializablePedestals>(); | ||
|
||
//open file | ||
edm::FileInPath fip(filename); | ||
std::ifstream file(fip.fullPath()); | ||
std::string line; | ||
uint32_t id; | ||
float ped,cm_slope,cm_off,kappa_bxm1; | ||
while(std::getline(file, line)) | ||
{ | ||
if(line.find("Channel")!=std::string::npos || line.find("#")!=std::string::npos) continue; | ||
|
||
std::istringstream stream(line); | ||
stream >> id >> ped >> cm_slope >> cm_off >> kappa_bxm1; | ||
|
||
//reduce to half-point float and fill the pedestals of this channel | ||
HGCalPedestals m; | ||
m.pedestal = MiniFloatConverter::float32to16(ped); | ||
m.cm_slope = MiniFloatConverter::float32to16(cm_slope); | ||
m.cm_offset = MiniFloatConverter::float32to16(cm_off); | ||
m.kappa_bxm1 = MiniFloatConverter::float32to16(kappa_bxm1); | ||
cond->addParameter(id,m); | ||
} | ||
|
||
//return the conditions | ||
return cond; | ||
} | ||
|
||
|
||
DEFINE_FWK_EVENTSETUP_SOURCE(HGCalPedestalsESSource); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
CalibCalorimetry/HGCalPlugins/test/HGCalPedestalsESSourceAnalyzer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/Framework/interface/one/EDAnalyzer.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/EventSetup.h" | ||
#include "FWCore/Framework/interface/ESHandle.h" | ||
#include "FWCore/Framework/interface/ESWatcher.h" | ||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "DataFormats/Math/interface/libminifloat.h" | ||
#include "DataFormats/HGCalDigi/interface/HGCalElectronicsId.h" | ||
#include "CondFormats/DataRecord/interface/HGCalCondSerializablePedestalsRcd.h" | ||
#include "CondFormats/HGCalObjects/interface/HGCalCondSerializablePedestals.h" | ||
|
||
class HGCalPedestalsESSourceAnalyzer : public edm::one::EDAnalyzer<> { | ||
public: | ||
explicit HGCalPedestalsESSourceAnalyzer(const edm::ParameterSet& iConfig) | ||
: tokenConds_(esConsumes<HGCalCondSerializablePedestals, HGCalCondSerializablePedestalsRcd>( | ||
edm::ESInputTag(iConfig.getParameter<std::string>("label")))) {} | ||
|
||
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.add<std::string>("label", {}); | ||
descriptions.addWithDefaultLabel(desc); | ||
} | ||
|
||
private: | ||
|
||
void analyze(const edm::Event&, const edm::EventSetup& iSetup) override { | ||
|
||
//check if there are new conditions and read them | ||
if (!cfgWatcher_.check(iSetup)) return; | ||
auto conds=iSetup.getData(tokenConds_); | ||
size_t nconds=conds.params_.size(); | ||
edm::LogInfo("HGCalPedestalsESSourceAnalyzer") << "Conditions retrieved:\n" << nconds; | ||
|
||
//print out all conditions readout | ||
std::cout << "ID\teRx\tROC\tChannel\tIs CM?\tPedestal\tCM slope\tCM offset\tkappa(BX-1)" << std::endl; | ||
for(auto it : conds.params_) { | ||
|
||
HGCalElectronicsId id(it.first); | ||
bool cmflag=id.isCM(); | ||
uint32_t eRx=(uint32_t) id.econdeRx(); | ||
uint32_t roc=(uint32_t) eRx/2; | ||
uint32_t seqch=id.sequentialHalfrocChannel(); | ||
|
||
HGCalPedestals table(it.second); | ||
float pedestal = MiniFloatConverter::float16to32(table.pedestal); | ||
float cm_slope = MiniFloatConverter::float16to32(table.cm_slope); | ||
float cm_offset = MiniFloatConverter::float16to32(table.cm_offset); | ||
float kappa_bxm1 = MiniFloatConverter::float16to32(table.kappa_bxm1); | ||
|
||
std::cout << std::hex << id.raw() << " " | ||
<< std::dec << eRx << " " << roc << " " << seqch << " " << cmflag << " " | ||
<< std::setprecision(3) << " " << pedestal << " " << cm_slope << " " << cm_offset << " " << kappa_bxm1 << std::endl; | ||
} | ||
|
||
} | ||
|
||
edm::ESWatcher<HGCalCondSerializablePedestalsRcd> cfgWatcher_; | ||
edm::ESGetToken<HGCalCondSerializablePedestals, HGCalCondSerializablePedestalsRcd> tokenConds_; | ||
}; | ||
|
||
DEFINE_FWK_MODULE(HGCalPedestalsESSourceAnalyzer); |
62 changes: 62 additions & 0 deletions
62
CalibCalorimetry/HGCalPlugins/test/hgcal_pedestals_reader_cfg.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
process = cms.Process("Calib") | ||
|
||
process.MessageLogger = cms.Service("MessageLogger", | ||
cerr = cms.untracked.PSet( | ||
enable = cms.untracked.bool(False) | ||
), | ||
cout = cms.untracked.PSet( | ||
enable = cms.untracked.bool(True), | ||
threshold = cms.untracked.string('INFO') | ||
) | ||
) | ||
|
||
process.source = cms.Source('EmptyIOVSource', | ||
timetype = cms.string('runnumber'), | ||
firstValue = cms.uint64(1), | ||
lastValue = cms.uint64(1), | ||
interval = cms.uint64(1) | ||
) | ||
|
||
process.load('CalibCalorimetry.HGCalPlugins.hgCalPedestalsESSource_cfi') | ||
process.hgCalPedestalsESSource.filename = 'CalibCalorimetry/HGCalPlugins/test/pedestals_test.txt' | ||
|
||
#generate values for a test file | ||
import numpy as np | ||
import itertools | ||
import scipy.constants as k | ||
consts=np.array([k.pi,k.golden,k.c/1e8,k.g,k.h/1e-34,k.alpha/1e-2,np.exp(1)]) | ||
rows=[] | ||
for erx,ich in itertools.product(range(6),range(39)): | ||
|
||
#identifier | ||
cmflag=(ich>36) | ||
ch=(ich-37)%2 if cmflag else ich | ||
id=(cmflag << 28) | ((erx & 0xf)<<6) | (ch & 0x3f) | ||
|
||
#random values | ||
np.random.shuffle(consts) | ||
vals=consts[0:4] | ||
rows.append( [id] + vals.tolist() ) | ||
|
||
#write the test file | ||
import pandas as pd | ||
from pathlib import Path | ||
import os | ||
test_dir = os.path.dirname(Path( __file__ ).absolute()) | ||
df=pd.DataFrame(rows,columns=['Channel','Pedestal','CM_slope','CM_offset','kappa_BXm1']) | ||
df.to_csv(os.path.join(test_dir,'pedestals_test.txt'),index=False,sep=' ',header=True, mode='w') | ||
|
||
#instantiate the analyzer | ||
process.analyzer = cms.EDAnalyzer("HGCalPedestalsESSourceAnalyzer", | ||
label = cms.string('')) | ||
|
||
process.source = cms.Source('EmptySource') | ||
|
||
process.maxEvents = cms.untracked.PSet( | ||
input = cms.untracked.int32(1) | ||
) | ||
|
||
process.p = cms.Path( | ||
process.analyzer | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
CondFormats/DataRecord/interface/HGCalCondSerializablePedestalsRcd.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef HGCalCondSerializablePedestalsRcd_HGCalCondSerializablePedestalsRcd_h | ||
#define HGCalCondSerializablePedestalsRcd_HGCalCondSerializablePedestalsRcd_h | ||
// -*- C++ -*- | ||
// | ||
// Package: CondFormats/DataRecord | ||
// Class : HGCalCondSerializablePedestalsRcd | ||
// | ||
/**\class HGCalCondSerializablePedestalsRcd HGCalCondSerializablePedestalsRcd.h CondFormats/DataRecord/interface/HGCalCondSerializablePedestalsRcd.h | ||
Description: [one line class summary] | ||
Usage: | ||
<usage> | ||
*/ | ||
// | ||
// Author: Pedro Vieira De Castro Ferreira Da Silva | ||
// Created: Thu, 01 Jun 2023 09:12:22 GMT | ||
// | ||
|
||
#include "FWCore/Framework/interface/EventSetupRecordImplementation.h" | ||
|
||
class HGCalCondSerializablePedestalsRcd : public edm::eventsetup::EventSetupRecordImplementation<HGCalCondSerializablePedestalsRcd> {}; | ||
|
||
#endif |
15 changes: 15 additions & 0 deletions
15
CondFormats/DataRecord/src/HGCalCondSerializablePedestalsRcd.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// -*- C++ -*- | ||
// | ||
// Package: CondFormats/DataRecord | ||
// Class : HGCalCondSerializablePedestalsRcd | ||
// | ||
// Implementation: | ||
// [Notes on implementation] | ||
// | ||
// Author: Pedro Vieira De Castro Ferreira Da Silva | ||
// Created: Thu, 01 Jun 2023 09:12:22 GMT | ||
|
||
#include "CondFormats/DataRecord/interface/HGCalCondSerializablePedestalsRcd.h" | ||
#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h" | ||
|
||
EVENTSETUP_RECORD_REG(HGCalCondSerializablePedestalsRcd); |
45 changes: 45 additions & 0 deletions
45
CondFormats/HGCalObjects/interface/HGCalCondSerializablePedestals.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef CondFormats_HGCalObjects_HGCalCondSerializablePedestals_h | ||
#define CondFormats_HGCalObjects_HGCalCondSerializablePedestals_h | ||
|
||
#include <map> | ||
#include <cstdint> | ||
|
||
#include "CondFormats/Serialization/interface/Serializable.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
#include "FWCore/Utilities/interface/Exception.h" | ||
|
||
/** | ||
@short representation of a si-cell channel information read from a txt file or db | ||
*/ | ||
struct HGCalPedestals { | ||
uint16_t pedestal, cm_slope, cm_offset, kappa_bxm1; | ||
COND_SERIALIZABLE; | ||
}; | ||
|
||
/** | ||
@holder for the si cell channel mappeing | ||
*/ | ||
class HGCalCondSerializablePedestals { | ||
|
||
public: | ||
|
||
HGCalCondSerializablePedestals() {} | ||
virtual ~HGCalCondSerializablePedestals() {} | ||
inline HGCalCondSerializablePedestals& addParameter(uint32_t id,HGCalPedestals &p) { | ||
if (params_.count(id) != 0) | ||
throw cms::Exception("HGCalCondSerializablePedestals") << "Already existing parameter with id='" << id << "'."; | ||
params_[id] = p; | ||
return *this; | ||
} | ||
inline const HGCalPedestals& parameters(uint32_t id) { | ||
if (params_.count(id) != 0) | ||
throw cms::Exception("HGCalCondSerializablePedestals") << "Failed to retrieve parameter with id='" << id << "'."; | ||
return params_[id]; | ||
} | ||
|
||
std::map<uint32_t,HGCalPedestals> params_; | ||
|
||
COND_SERIALIZABLE; | ||
}; | ||
|
||
#endif |
4 changes: 4 additions & 0 deletions
4
CondFormats/HGCalObjects/src/T_EventSetup_HGCalCondSerializablePedestals.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include "CondFormats/HGCalObjects/interface/HGCalCondSerializablePedestals.h" | ||
#include "FWCore/Utilities/interface/typelookup.h" | ||
|
||
TYPELOOKUP_DATA_REG(HGCalCondSerializablePedestals); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.