From f8ae0cb415ad53a484196c0c0e9824806f128c5e Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 1 Jun 2023 16:53:21 +0200 Subject: [PATCH] adding a pedestals cond format, filler and tester --- .../HGCalPlugins/plugins/BuildFile.xml | 4 + .../plugins/HGCalPedestalsESSource.cc | 82 +++++++++++++++++++ .../HGCalPlugins/test/BuildFile.xml | 7 +- .../test/HGCalPedestalsESSourceAnalyzer.cc | 63 ++++++++++++++ .../test/hgcal_pedestals_reader_cfg.py | 62 ++++++++++++++ CondCore/HGCalPlugins/src/plugin.cc | 3 + .../HGCalCondSerializablePedestalsRcd.h | 25 ++++++ .../src/HGCalCondSerializablePedestalsRcd.cc | 15 ++++ .../HGCalCondSerializablePedestals.h | 45 ++++++++++ ...entSetup_HGCalCondSerializablePedestals.cc | 4 + CondFormats/HGCalObjects/src/classes.h | 6 ++ CondFormats/HGCalObjects/src/classes_def.xml | 8 ++ CondFormats/HGCalObjects/src/headers.h | 1 + .../testSerializationHGCalCondDataFormats.cc | 5 ++ .../HGCalDigi/interface/HGCalElectronicsId.h | 5 +- .../HGCalDigi/src/HGCalElectronicsId.cc | 12 +++ .../HGCalDigi/test/HGCalElectronicsIdTest.cc | 11 ++- 17 files changed, 352 insertions(+), 6 deletions(-) create mode 100644 CalibCalorimetry/HGCalPlugins/plugins/HGCalPedestalsESSource.cc create mode 100644 CalibCalorimetry/HGCalPlugins/test/HGCalPedestalsESSourceAnalyzer.cc create mode 100644 CalibCalorimetry/HGCalPlugins/test/hgcal_pedestals_reader_cfg.py create mode 100644 CondFormats/DataRecord/interface/HGCalCondSerializablePedestalsRcd.h create mode 100644 CondFormats/DataRecord/src/HGCalCondSerializablePedestalsRcd.cc create mode 100644 CondFormats/HGCalObjects/interface/HGCalCondSerializablePedestals.h create mode 100644 CondFormats/HGCalObjects/src/T_EventSetup_HGCalCondSerializablePedestals.cc diff --git a/CalibCalorimetry/HGCalPlugins/plugins/BuildFile.xml b/CalibCalorimetry/HGCalPlugins/plugins/BuildFile.xml index a7c97c4837976..beb2271ed0e85 100644 --- a/CalibCalorimetry/HGCalPlugins/plugins/BuildFile.xml +++ b/CalibCalorimetry/HGCalPlugins/plugins/BuildFile.xml @@ -2,7 +2,11 @@ + + + + \ No newline at end of file diff --git a/CalibCalorimetry/HGCalPlugins/plugins/HGCalPedestalsESSource.cc b/CalibCalorimetry/HGCalPlugins/plugins/HGCalPedestalsESSource.cc new file mode 100644 index 0000000000000..75d5b56fc60ac --- /dev/null +++ b/CalibCalorimetry/HGCalPlugins/plugins/HGCalPedestalsESSource.cc @@ -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 +#include +#include +#include + +/** + @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("filename")) { + setWhatProduced(this); + findingRecord(); + } + + std::unique_ptr produce(const HGCalCondSerializablePedestalsRcd&) { return parsePedestals(filename_); } + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("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 parsePedestals(const std::string& filename); + + const std::string filename_; +}; + + +// +std::unique_ptr HGCalPedestalsESSource::parsePedestals(const std::string& filename) +{ + auto cond = std::make_unique(); + + //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); diff --git a/CalibCalorimetry/HGCalPlugins/test/BuildFile.xml b/CalibCalorimetry/HGCalPlugins/test/BuildFile.xml index c721364aa8a1f..15b3ecd6af2ee 100644 --- a/CalibCalorimetry/HGCalPlugins/test/BuildFile.xml +++ b/CalibCalorimetry/HGCalPlugins/test/BuildFile.xml @@ -2,7 +2,12 @@ + + - + + + + \ No newline at end of file diff --git a/CalibCalorimetry/HGCalPlugins/test/HGCalPedestalsESSourceAnalyzer.cc b/CalibCalorimetry/HGCalPlugins/test/HGCalPedestalsESSourceAnalyzer.cc new file mode 100644 index 0000000000000..def5b06e0de18 --- /dev/null +++ b/CalibCalorimetry/HGCalPlugins/test/HGCalPedestalsESSourceAnalyzer.cc @@ -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( + edm::ESInputTag(iConfig.getParameter("label")))) {} + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("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 cfgWatcher_; + edm::ESGetToken tokenConds_; +}; + +DEFINE_FWK_MODULE(HGCalPedestalsESSourceAnalyzer); diff --git a/CalibCalorimetry/HGCalPlugins/test/hgcal_pedestals_reader_cfg.py b/CalibCalorimetry/HGCalPlugins/test/hgcal_pedestals_reader_cfg.py new file mode 100644 index 0000000000000..ddc6bd9195c30 --- /dev/null +++ b/CalibCalorimetry/HGCalPlugins/test/hgcal_pedestals_reader_cfg.py @@ -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 +) diff --git a/CondCore/HGCalPlugins/src/plugin.cc b/CondCore/HGCalPlugins/src/plugin.cc index 34b43039b44a8..44aafce0a615a 100644 --- a/CondCore/HGCalPlugins/src/plugin.cc +++ b/CondCore/HGCalPlugins/src/plugin.cc @@ -7,8 +7,11 @@ #include "CondFormats/HGCalObjects/interface/HGCalCondSerializableSiPMTileInfo.h" #include "CondFormats/DataRecord/interface/HGCalCondSerializableModuleInfoRcd.h" #include "CondFormats/HGCalObjects/interface/HGCalCondSerializableModuleInfo.h" +#include "CondFormats/DataRecord/interface/HGCalCondSerializablePedestalsRcd.h" +#include "CondFormats/HGCalObjects/interface/HGCalCondSerializablePedestals.h" REGISTER_PLUGIN(HGCalCondSerializableGenericConfigRcd,HGCalCondSerializableGenericConfig); REGISTER_PLUGIN(HGCalCondSerializableSiCellChannelInfoRcd,HGCalCondSerializableSiCellChannelInfo); REGISTER_PLUGIN(HGCalCondSerializableSiPMTileInfoRcd,HGCalCondSerializableSiPMTileInfo); REGISTER_PLUGIN(HGCalCondSerializableModuleInfoRcd,HGCalCondSerializableModuleInfo); +REGISTER_PLUGIN(HGCalCondSerializablePedestalsRcd,HGCalCondSerializablePedestals); diff --git a/CondFormats/DataRecord/interface/HGCalCondSerializablePedestalsRcd.h b/CondFormats/DataRecord/interface/HGCalCondSerializablePedestalsRcd.h new file mode 100644 index 0000000000000..4ce3660dff724 --- /dev/null +++ b/CondFormats/DataRecord/interface/HGCalCondSerializablePedestalsRcd.h @@ -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: + + +*/ +// +// 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 {}; + +#endif diff --git a/CondFormats/DataRecord/src/HGCalCondSerializablePedestalsRcd.cc b/CondFormats/DataRecord/src/HGCalCondSerializablePedestalsRcd.cc new file mode 100644 index 0000000000000..1c2ddd2dfb184 --- /dev/null +++ b/CondFormats/DataRecord/src/HGCalCondSerializablePedestalsRcd.cc @@ -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); diff --git a/CondFormats/HGCalObjects/interface/HGCalCondSerializablePedestals.h b/CondFormats/HGCalObjects/interface/HGCalCondSerializablePedestals.h new file mode 100644 index 0000000000000..7f61ba3b01ce8 --- /dev/null +++ b/CondFormats/HGCalObjects/interface/HGCalCondSerializablePedestals.h @@ -0,0 +1,45 @@ +#ifndef CondFormats_HGCalObjects_HGCalCondSerializablePedestals_h +#define CondFormats_HGCalObjects_HGCalCondSerializablePedestals_h + +#include +#include + +#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 params_; + + COND_SERIALIZABLE; +}; + +#endif diff --git a/CondFormats/HGCalObjects/src/T_EventSetup_HGCalCondSerializablePedestals.cc b/CondFormats/HGCalObjects/src/T_EventSetup_HGCalCondSerializablePedestals.cc new file mode 100644 index 0000000000000..028eca07bffd3 --- /dev/null +++ b/CondFormats/HGCalObjects/src/T_EventSetup_HGCalCondSerializablePedestals.cc @@ -0,0 +1,4 @@ +#include "CondFormats/HGCalObjects/interface/HGCalCondSerializablePedestals.h" +#include "FWCore/Utilities/interface/typelookup.h" + +TYPELOOKUP_DATA_REG(HGCalCondSerializablePedestals); diff --git a/CondFormats/HGCalObjects/src/classes.h b/CondFormats/HGCalObjects/src/classes.h index 2b7e0c9fa6434..fe70d725cb24c 100644 --- a/CondFormats/HGCalObjects/src/classes.h +++ b/CondFormats/HGCalObjects/src/classes.h @@ -19,4 +19,10 @@ namespace CondFormats_HGCalObjects { std::vector v_hmi; HGCalCondSerializableModuleInfo h_csmi(); + HGCalPedestals hp; + std::pair p_hp; + std::map v_hp; + HGCalCondSerializablePedestals h_csp(); + + } // namespace CondFormats_HGCalObjects diff --git a/CondFormats/HGCalObjects/src/classes_def.xml b/CondFormats/HGCalObjects/src/classes_def.xml index 271032ff9f0bf..aa04b255a359d 100644 --- a/CondFormats/HGCalObjects/src/classes_def.xml +++ b/CondFormats/HGCalObjects/src/classes_def.xml @@ -25,4 +25,12 @@ + + + + + + + + diff --git a/CondFormats/HGCalObjects/src/headers.h b/CondFormats/HGCalObjects/src/headers.h index 5505ccd4beb6b..5052cd095a1f3 100644 --- a/CondFormats/HGCalObjects/src/headers.h +++ b/CondFormats/HGCalObjects/src/headers.h @@ -2,3 +2,4 @@ #include "CondFormats/HGCalObjects/interface/HGCalCondSerializableSiCellChannelInfo.h" #include "CondFormats/HGCalObjects/interface/HGCalCondSerializableSiPMTileInfo.h" #include "CondFormats/HGCalObjects/interface/HGCalCondSerializableModuleInfo.h" +#include "CondFormats/HGCalObjects/interface/HGCalCondSerializablePedestals.h" diff --git a/CondFormats/HGCalObjects/test/testSerializationHGCalCondDataFormats.cc b/CondFormats/HGCalObjects/test/testSerializationHGCalCondDataFormats.cc index 130540d27a3d5..bc46f290c6aa7 100644 --- a/CondFormats/HGCalObjects/test/testSerializationHGCalCondDataFormats.cc +++ b/CondFormats/HGCalObjects/test/testSerializationHGCalCondDataFormats.cc @@ -24,5 +24,10 @@ int main() testSerialization(); testSerialization>(); + //pedestals + testSerialization(); + testSerialization(); + testSerialization>(); + return 0; } diff --git a/DataFormats/HGCalDigi/interface/HGCalElectronicsId.h b/DataFormats/HGCalDigi/interface/HGCalElectronicsId.h index 57c2a1f84bc16..d3aaefa864455 100644 --- a/DataFormats/HGCalDigi/interface/HGCalElectronicsId.h +++ b/DataFormats/HGCalDigi/interface/HGCalElectronicsId.h @@ -42,6 +42,7 @@ class HGCalElectronicsId { */ HGCalElectronicsId() : value_(0) {} HGCalElectronicsId(bool cmflag,uint16_t fedid, uint8_t captureblock, uint8_t econdidx, uint8_t econderx, uint8_t halfrocch); + HGCalElectronicsId(uint16_t fedid, uint8_t captureblock, uint8_t econdidx, uint8_t econderx, uint8_t halfrocch); HGCalElectronicsId(uint32_t value) : value_(value) {} HGCalElectronicsId(const HGCalElectronicsId& o) : value_(o.value_) {} @@ -55,13 +56,15 @@ class HGCalElectronicsId { uint8_t econdIdx(); uint8_t econdeRx(); uint8_t halfrocChannel(); + uint8_t sequentialHalfrocChannel(); bool isCM(); void print(std::ostream& out = std::cout) { out << "Raw=0x" << std::hex << raw() << std::dec << std::endl << "\tFED-ID: " << (uint32_t)fedId() << " Capture Block: " << (uint32_t)captureBlock() << " ECON-D idx: " << (uint32_t)econdIdx() << " eRx: " << (uint32_t)econdeRx() - << " 1/2 ROC ch.: " << (uint32_t)halfrocChannel() << " isCM=" << isCM() << std::endl; + << " 1/2 ROC ch.: " << (uint32_t)halfrocChannel() << " (" << (uint32_t) sequentialHalfrocChannel() << ") " + << " isCM=" << isCM() << std::endl; } private: diff --git a/DataFormats/HGCalDigi/src/HGCalElectronicsId.cc b/DataFormats/HGCalDigi/src/HGCalElectronicsId.cc index ec0c30c287ade..a441fdc99b8ea 100644 --- a/DataFormats/HGCalDigi/src/HGCalElectronicsId.cc +++ b/DataFormats/HGCalDigi/src/HGCalElectronicsId.cc @@ -3,6 +3,9 @@ // HGCalElectronicsId::HGCalElectronicsId( bool cmflag,uint16_t fedid, uint8_t captureblock, uint8_t econdidx, uint8_t econderx, uint8_t halfrocch) { + + //there are 2 common mode channels per erdx + halfrocch = cmflag ? (halfrocch-37)%2 : halfrocch; value_ = ((cmflag & kCommonMode) << kCommonModeShift) | ((fedid & kFEDIDMask) << kFEDIDShift) | ((captureblock & kCaptureBlockMask) << kCaptureBlockShift) | @@ -10,6 +13,12 @@ HGCalElectronicsId::HGCalElectronicsId( ((halfrocch & kHalfROCChannelMask) << kHalfROCChannelShift); } +// +HGCalElectronicsId::HGCalElectronicsId( + uint16_t fedid, uint8_t captureblock, uint8_t econdidx, uint8_t econderx, uint8_t halfrocch) + : HGCalElectronicsId((halfrocch==37 || halfrocch==38), fedid, captureblock, econdidx, econderx, halfrocch) { +} + // bool HGCalElectronicsId::isCM() { return (value_ >> kCommonModeShift) & kCommonMode; } @@ -27,3 +36,6 @@ uint8_t HGCalElectronicsId::econdeRx() { return (value_ >> kECONDeRxShift) & kEC // uint8_t HGCalElectronicsId::halfrocChannel() { return (value_ >> kHalfROCChannelShift) & kHalfROCChannelMask; } + +// +uint8_t HGCalElectronicsId::sequentialHalfrocChannel() { return halfrocChannel() + isCM()*37; } diff --git a/DataFormats/HGCalDigi/test/HGCalElectronicsIdTest.cc b/DataFormats/HGCalDigi/test/HGCalElectronicsIdTest.cc index 11fde1a4c549d..21c8531bdf260 100644 --- a/DataFormats/HGCalDigi/test/HGCalElectronicsIdTest.cc +++ b/DataFormats/HGCalDigi/test/HGCalElectronicsIdTest.cc @@ -36,20 +36,23 @@ int main(int argc, char** argv) { // do the trials: time/performance test and exploit randomisation to check unsigned long int u = 0; for (; u < repetitions; u++) { - cmflag = (bool) (myrand()%2); + fedid = myrand() % 576; captureblock = myrand() % 10; econdidx = myrand() % 12; econderx = myrand() % 12; halfrocch = myrand() % 39; - - HGCalElectronicsId eid(cmflag,fedid, captureblock, econdidx, econderx, halfrocch); + cmflag = ((halfrocch==37) || (halfrocch==38)) ? true : false; + uint8_t croppedHalfRocCh(cmflag ? (halfrocch-37)%2 : halfrocch); + + HGCalElectronicsId eid(fedid, captureblock, econdidx, econderx, halfrocch); assert(cmflag == eid.isCM()); assert(fedid == eid.fedId()); assert(captureblock == eid.captureBlock()); assert(econdidx == eid.econdIdx()); assert(econderx == eid.econdeRx()); - assert(halfrocch == eid.halfrocChannel()); + assert(halfrocch == eid.sequentialHalfrocChannel()); + assert(croppedHalfRocCh == eid.halfrocChannel()); if (verbosity > 0) eid.print(std::cout);