Skip to content

Commit

Permalink
Merge pull request #36508 from mmusich/commentMiscalibratorTools
Browse files Browse the repository at this point in the history
`CondTools/SiStrip` unit tests: introduce gain rescaler tool in unit tests
  • Loading branch information
cmsbuild committed Jan 12, 2022
2 parents bdb4a76 + 257ac11 commit f2f7bd4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 29 deletions.
29 changes: 14 additions & 15 deletions CondTools/SiStrip/plugins/SiStripApvGainRescaler.cc
Expand Up @@ -50,12 +50,11 @@ class SiStripApvGainRescaler : public edm::one::EDAnalyzer<> {
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
void beginJob() override;
void analyze(const edm::Event&, const edm::EventSetup&) override;
std::unique_ptr<SiStripApvGain> getNewObject(const std::map<std::pair<uint32_t, int>, float>& theMap);
void endJob() override;

// ----------member data ---------------------------
const uint32_t m_printdebug;
const std::string m_Record;

// take G2_old and G1_old from the regular gain handle
Expand All @@ -68,9 +67,10 @@ class SiStripApvGainRescaler : public edm::one::EDAnalyzer<> {
// constructors and destructor
//
SiStripApvGainRescaler::SiStripApvGainRescaler(const edm::ParameterSet& iConfig)
: m_Record(iConfig.getParameter<std::string>("Record")), g1g2Token_(esConsumes()), g3Token_(esConsumes()) {
//now do what ever initialization is needed
}
: m_printdebug{iConfig.getUntrackedParameter<uint32_t>("printDebug", 1)},
m_Record(iConfig.getParameter<std::string>("Record")),
g1g2Token_(esConsumes()),
g3Token_(esConsumes()) {}

SiStripApvGainRescaler::~SiStripApvGainRescaler() = default;
//
Expand Down Expand Up @@ -129,40 +129,38 @@ void SiStripApvGainRescaler::analyze(const edm::Event& iEvent, const edm::EventS
throw std::runtime_error("PoolDBService required.");
}

// ------------ method called once each job just before starting event loop ------------
void SiStripApvGainRescaler::beginJob() {}

// ------------ method called once each job just after ending the event loop ------------
void SiStripApvGainRescaler::endJob() {}

//********************************************************************************//
std::unique_ptr<SiStripApvGain> SiStripApvGainRescaler::getNewObject(
const std::map<std::pair<uint32_t, int>, float>& theMap) {
std::unique_ptr<SiStripApvGain> obj = std::make_unique<SiStripApvGain>();

std::vector<float> theSiStripVector;
uint32_t PreviousDetId = 0;
unsigned int countDetIds(0); // count DetIds to print
for (const auto& element : theMap) {
uint32_t DetId = element.first.first;
if (DetId != PreviousDetId) {
if (!theSiStripVector.empty()) {
SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
if (!obj->put(PreviousDetId, range))
printf("Bug to put detId = %i\n", PreviousDetId);
edm::LogError("SiStripApvGainRescaler") << "Bug to put detId = " << PreviousDetId << "\n";
}
theSiStripVector.clear();
PreviousDetId = DetId;
countDetIds++;
}
theSiStripVector.push_back(element.second);

edm::LogInfo("SiStripApvGainRescaler")
<< " DetId: " << DetId << " APV: " << element.first.second << " Gain: " << element.second << std::endl;
if (countDetIds <= m_printdebug) {
edm::LogInfo("SiStripApvGainRescaler")
<< __FUNCTION__ << " DetId: " << DetId << " APV: " << element.first.second << " Gain: " << element.second;
}
}

if (!theSiStripVector.empty()) {
SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
if (!obj->put(PreviousDetId, range))
printf("Bug to put detId = %i\n", PreviousDetId);
edm::LogError("SiStripApvGainRescaler") << "Bug to put detId = " << PreviousDetId << "\n";
}

return obj;
Expand All @@ -178,6 +176,7 @@ void SiStripApvGainRescaler::fillDescriptions(edm::ConfigurationDescriptions& de
"PoolDBOutputService must be set up for 'SiStripApvGainRcd'.");

desc.add<std::string>("Record", "SiStripApvGainRcd");
desc.addUntracked<unsigned int>("printDebug", 1);
descriptions.add("rescaleGain2byGain1", desc);
}

Expand Down
26 changes: 16 additions & 10 deletions CondTools/SiStrip/test/SiStripApvGainRescaler_cfg.py
Expand Up @@ -8,17 +8,23 @@
options = VarParsing.VarParsing("analysis")

options.register ('globalTag',
"92X_dataRun2_Prompt_v11",
VarParsing.VarParsing.multiplicity.singleton, # singleton or list
"auto:run3_data_prompt",
VarParsing.VarParsing.multiplicity.singleton, # singleton or list
VarParsing.VarParsing.varType.string, # string, int, or float
"GlobalTag")

options.register ('runNumber',
303014,
1,
VarParsing.VarParsing.multiplicity.singleton, # singleton or list
VarParsing.VarParsing.varType.int, # string, int, or float
VarParsing.VarParsing.varType.int, # string, int, or float
"run number")

options.register ('additionalConds',
"sqlite_file:gainManipulations.db",
VarParsing.VarParsing.multiplicity.singleton, # singleton or list
VarParsing.VarParsing.varType.string, # string, int, or float
"location of the additional conditions")

options.parseArguments()


Expand All @@ -27,7 +33,7 @@
##
process.load('FWCore.MessageService.MessageLogger_cfi')
process.MessageLogger.cerr.enable = False
process.MessageLogger.SiStripGain2RescaleByGain1=dict()
process.MessageLogger.SiStripApvGainRescaler=dict()
process.MessageLogger.cout = cms.untracked.PSet(
enable = cms.untracked.bool(True),
enableStatistics = cms.untracked.bool(True),
Expand All @@ -36,7 +42,7 @@
FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1),
reportEvery = cms.untracked.int32(1000)
),
SiStripGain2RescaleByGain1 = cms.untracked.PSet( limit = cms.untracked.int32(-1))
SiStripApvGainRescaler = cms.untracked.PSet( limit = cms.untracked.int32(-1))
)

process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
Expand All @@ -46,17 +52,17 @@
### N.B. This contains the G1_new (to be used for the rescale)
cms.PSet(record = cms.string("SiStripApvGain3Rcd"),
tag = cms.string("G1_new"),
connect = cms.string("sqlite_file:G1_new.db")
connect = cms.string(options.additionalConds)
),
### N.B. This contains the G2_old (to be used for the rescale)
cms.PSet(record = cms.string("SiStripApvGain2Rcd"),
tag = cms.string("G2_old"),
connect = cms.string("sqlite_file:G2_old.db")
connect = cms.string(options.additionalConds)
),
### N.B. This contains the G1_old (to be used for the rescale)
cms.PSet(record = cms.string("SiStripApvGainRcd"),
tag = cms.string("G1_old"),
connect = cms.string("sqlite_file:G1_old.db")
connect = cms.string(options.additionalConds)
)
)

Expand All @@ -69,7 +75,7 @@

process.load("CondTools.SiStrip.rescaleGain2byGain1_cfi")

# process.demo = cms.EDAnalyzer('SiStripGain2RescaleByGain1',
# process.demo = cms.EDAnalyzer('SiStripApvGainRescaler',
# Record = cms.untracked.string("SiStripApvGainRcd"),
# )

Expand Down
30 changes: 26 additions & 4 deletions CondTools/SiStrip/test/testBuildersReaders.sh
Expand Up @@ -10,11 +10,12 @@ if test -f "SiStripConditionsDBFile.db"; then
echo "cleaning the local test area"
rm -fr SiStripConditionsDBFile.db # builders test
rm -fr modifiedSiStrip*.db # miscalibrator tests
rm -fr gainManipulations.db # rescaler tool
fi
pwd
echo " testing CondTools/SiStrip"

## do the builders first (need the input db file)
# do the builders first (need the input db file)
for entry in "${LOCAL_TEST_DIR}/"SiStrip*Builder_cfg.py
do
echo "===== Test \"cmsRun $entry \" ===="
Expand Down Expand Up @@ -43,6 +44,27 @@ done

echo -e " Done with the miscalibrators \n\n"

## do the scaler (commented for now)
#(cmsRun ${LOCAL_TEST_DIR}/SiStripApvGainRescaler_cfg.py) || die "Failure using cmsRun SiStripApvGainRescaler_cfg.py)" $?
#echo -e " Done with the gain rescaler \n\n"
## do the scaler

# copy all the necessary conditions in order to run the miscalibration tool
G1TAG=SiStripApvGain_GR10_v1_hlt
G2TAG=SiStripApvGain_FromParticles_GR10_v1_express
OLDG1since=325642
NEWG1since=343828
OLDG2since=336067

echo -e "\n\n Copying IOVs $OLDG1since and $NEWG1since from $G1TAG and IOV $OLDG2since from $G2TAG"

conddb --yes --db pro copy ${G1TAG} G1_old --from ${OLDG1since} --to $((++OLDG1since)) --destdb gainManipulations.db
conddb --yes --db pro copy ${G1TAG} G1_new --from ${NEWG1since} --to $((++NEWG1since)) --destdb gainManipulations.db
conddb --yes --db pro copy ${G2TAG} G2_old --from ${OLDG2since} --to $((++OLDG2since)) --destdb gainManipulations.db

sqlite3 gainManipulations.db "update IOV SET SINCE=1 where SINCE=$((--OLDG1since))" # sets the IOV since to 1
sqlite3 gainManipulations.db "update IOV SET SINCE=1 where SINCE=$((--NEWG1since))" # sets the IOV since to 1
sqlite3 gainManipulations.db "update IOV SET SINCE=1 where SINCE=$((--OLDG2since))" # sets the IOV since to 1

echo -e "\n\n Checking the content of the local conditions file \n\n"
sqlite3 gainManipulations.db "select * from IOV"

(cmsRun ${LOCAL_TEST_DIR}/SiStripApvGainRescaler_cfg.py additionalConds=sqlite_file:${PWD}/gainManipulations.db) || die "Failure using cmsRun SiStripApvGainRescaler_cfg.py)" $?
echo -e " Done with the gain rescaler \n\n"

0 comments on commit f2f7bd4

Please sign in to comment.