Skip to content

Commit

Permalink
Merge pull request #36952 from benitezj/master
Browse files Browse the repository at this point in the history
AlCaLumiPixelsCountsExpress and AlCaLumiPixelsCountsPrompt  PCL and PromptReco
  • Loading branch information
cmsbuild authored Mar 2, 2022
2 parents 4a20ef7 + ab32d50 commit 73943f5
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 118 deletions.
3 changes: 2 additions & 1 deletion Calibration/LumiAlCaRecoProducers/plugins/CorrPCCProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ class: CorrPCCProducer.cc
description: Computes the type 1 and type 2 corrections to the luminosity
type 1 - first (spillover from previous BXs real clusters)
type 2 - after (comes from real activation)
pedestal - is a constant noise term for low lumi period
authors:Sam Higginbotham ([email protected]) and Chris Palmer ([email protected])
authors:Sam Higginbotham ([email protected]) and Chris Palmer ([email protected]) , Jose Benitez ([email protected])
________________________________________________________________**/
#include <memory>
Expand Down
109 changes: 55 additions & 54 deletions Calibration/LumiAlCaRecoProducers/plugins/RawPCCProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class: RawPCCProducer.cc
description: Creates a LumiInfo object that will contain the luminosity per bunch crossing,
along with the total luminosity and the statistical error.
authors:Sam Higginbotham ([email protected]) and Chris Palmer ([email protected])
authors:Sam Higginbotham ([email protected]), Chris Palmer ([email protected]), Jose Benitez ([email protected])
________________________________________________________________**/
#include <string>
Expand Down Expand Up @@ -40,43 +40,45 @@ class RawPCCProducer : public edm::global::EDProducer<edm::EndLuminosityBlockPro
void globalEndLuminosityBlockProduce(edm::LuminosityBlock& lumiSeg, const edm::EventSetup& iSetup) const final;
void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const final;

//input object labels
edm::EDGetTokenT<reco::PixelClusterCounts> pccToken_;
//background corrections from DB
const edm::ESGetToken<LumiCorrections, LumiCorrectionsRcd> lumiCorrectionsToken_;
const edm::EDPutTokenT<LumiInfo> putToken_;
const std::string takeAverageValue_; //Output average values
//The list of modules to skip in the lumi calc.
const std::vector<int> modVeto_;
//background corrections
const bool applyCorr_;
//Output average values
const std::string takeAverageValue_;

const std::vector<int> modVeto_; //The list of modules to skip in the lumi calc.
//output object labels
const edm::EDPutTokenT<LumiInfo> putToken_;

//produce csv lumi file
const bool saveCSVFile_;
const std::string csvOutLabel_;
mutable std::mutex fileLock_;
const bool saveCSVFile_;

const bool applyCorr_;
};

//--------------------------------------------------------------------------------------------------
RawPCCProducer::RawPCCProducer(const edm::ParameterSet& iConfig)
: lumiCorrectionsToken_(esConsumes<edm::Transition::EndLuminosityBlock>()),
putToken_{produces<LumiInfo, edm::Transition::EndLuminosityBlock>(
: pccToken_(consumes<reco::PixelClusterCounts, edm::InLumi>(edm::InputTag(
iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters").getParameter<std::string>("inputPccLabel"),
iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters").getParameter<std::string>("ProdInst")))),
lumiCorrectionsToken_(esConsumes<edm::Transition::EndLuminosityBlock>()),
modVeto_(
iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters").getParameter<std::vector<int>>("modVeto")),
applyCorr_(iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
.getUntrackedParameter<bool>("ApplyCorrections", false)),
takeAverageValue_(iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
.getUntrackedParameter<std::string>("OutputValue", std::string("Average"))),
putToken_(produces<LumiInfo, edm::Transition::EndLuminosityBlock>(
iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
.getUntrackedParameter<std::string>("outputProductName", "alcaLumi"))},
takeAverageValue_{iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
.getUntrackedParameter<std::string>("OutputValue", std::string("Totals"))},
modVeto_{
iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters").getParameter<std::vector<int>>("modVeto")},
csvOutLabel_{iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
.getUntrackedParameter<std::string>("label", std::string("rawPCC.csv"))},
saveCSVFile_{iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
.getUntrackedParameter<bool>("saveCSVFile", false)},
applyCorr_{iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
.getUntrackedParameter<bool>("ApplyCorrections", false)} {
auto pccSource =
iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters").getParameter<std::string>("inputPccLabel");
auto prodInst =
iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters").getParameter<std::string>("ProdInst");

pccToken_ = consumes<reco::PixelClusterCounts, edm::InLumi>(edm::InputTag(pccSource, prodInst));
}
.getUntrackedParameter<std::string>("outputProductName", "alcaLumi"))),
saveCSVFile_(iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
.getUntrackedParameter<bool>("saveCSVFile", false)),
csvOutLabel_(iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
.getUntrackedParameter<std::string>("label", std::string("rawPCC.csv"))) {}

//--------------------------------------------------------------------------------------------------
RawPCCProducer::~RawPCCProducer() {}
Expand All @@ -87,45 +89,48 @@ void RawPCCProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::Event
//--------------------------------------------------------------------------------------------------
void RawPCCProducer::globalEndLuminosityBlockProduce(edm::LuminosityBlock& lumiSeg,
const edm::EventSetup& iSetup) const {
float totalLumi = 0.0; //The total raw luminosity from the pixel clusters - not scaled
float statErrOnLumi = 0.0; //the statistical error on the lumi - large num ie sqrt(N)
//The total raw luminosity from the pixel clusters - not scaled
float totalLumi = 0.0;
//the statistical error on the lumi - large num ie sqrt(N)
float statErrOnLumi = 0.0;

//new vector containing clusters per bxid
std::vector<int> clustersPerBXOutput(LumiConstants::numBX, 0);
//new vector containing clusters per bxid with afterglow corrections
std::vector<float> corrClustersPerBXOutput(LumiConstants::numBX, 0);

//The indicies of all the good modules - not vetoed
std::vector<int> goodMods;

edm::Handle<reco::PixelClusterCounts> pccHandle;
lumiSeg.getByToken(pccToken_, pccHandle);

//////////////////////////////////
/// read input , clusters per module per bx
/////////////////////////////////
const edm::Handle<reco::PixelClusterCounts> pccHandle = lumiSeg.getHandle(pccToken_);
const reco::PixelClusterCounts& inputPcc = *(pccHandle.product());

//vector with Module IDs 1-1 map to bunch x-ing in clusers
auto modID = inputPcc.readModID();
//vector with total events at each bxid.
auto events = inputPcc.readEvents();
//cluster counts per module per bx
auto clustersPerBXInput = inputPcc.readCounts();

//making list of modules to sum over
////////////////////////////
///Apply the module veto
///////////////////////////
std::vector<int> goodMods;
for (unsigned int i = 0; i < modID.size(); i++) {
if (std::find(modVeto_.begin(), modVeto_.end(), modID.at(i)) == modVeto_.end()) {
goodMods.push_back(i);
}
}

//summing over good modules only
for (int bx = 0; bx < int(LumiConstants::numBX); bx++) {
for (unsigned int i = 0; i < goodMods.size(); i++) {
clustersPerBXOutput.at(bx) += clustersPerBXInput.at(goodMods.at(i) * int(LumiConstants::numBX) + bx);
}
}

//////////////////////////////
//// Apply afterglow corrections
//////////////////////////////
std::vector<float> correctionScaleFactors;
if (applyCorr_) {
//Get PCC corrections from the event setup through a token
const auto pccCorrections = &iSetup.getData(lumiCorrectionsToken_);
correctionScaleFactors = pccCorrections->getCorrectionsBX();
} else {
Expand All @@ -145,14 +150,14 @@ void RawPCCProducer::globalEndLuminosityBlockProduce(edm::LuminosityBlock& lumiS
std::vector<float> errorPerBX; //Stat error (or number of events)
errorPerBX.assign(events.begin(), events.end());

//////////////////////////////////
/// Compute average number of clusters per event
////////////////////////////////
if (takeAverageValue_ == "Average") {
unsigned int NActiveBX = 0;
for (int bx = 0; bx < int(LumiConstants::numBX); bx++) {
if (events[bx] > 0) {
NActiveBX++;
// Counting where events are will only work
// for ZeroBias or AlwaysTrue triggers.
// Random triggers will get all BXs.
corrClustersPerBXOutput[bx] /= float(events[bx]);
errorPerBX[bx] = 1 / sqrt(float(events[bx]));
}
Expand All @@ -163,33 +168,29 @@ void RawPCCProducer::globalEndLuminosityBlockProduce(edm::LuminosityBlock& lumiS
}
}

///////////////////////////////////////////////////////
///Lumi saved in the LuminosityBlocks
LumiInfo outputLumiInfo;

outputLumiInfo.setTotalInstLumi(totalLumi);
outputLumiInfo.setTotalInstStatError(statErrOnLumi);

outputLumiInfo.setErrorLumiAllBX(errorPerBX);
outputLumiInfo.setInstLumiAllBX(corrClustersPerBXOutput);
lumiSeg.emplace(putToken_, std::move(outputLumiInfo));

//Lumi saved in the csv file
if (saveCSVFile_) {
std::lock_guard<std::mutex> lock(fileLock_);
std::ofstream csfile(csvOutLabel_, std::ios_base::app);
csfile << std::to_string(lumiSeg.run()) << ",";
csfile << std::to_string(lumiSeg.luminosityBlock()) << ",";
csfile << std::to_string(totalLumi);

if (totalLumi > 0) {
for (unsigned int bx = 0; bx < LumiConstants::numBX; bx++) {
csfile << "," << std::to_string(corrClustersPerBXOutput[bx]);
}
csfile << std::endl;
} else if (totalLumi < 0) {
edm::LogInfo("WARNING") << "WHY IS LUMI NEGATIVE?!?!?!? " << totalLumi;
}
for (unsigned int bx = 0; bx < LumiConstants::numBX; bx++)
csfile << "," << std::to_string(corrClustersPerBXOutput[bx]);
csfile << std::endl;

csfile.close();
}
lumiSeg.emplace(putToken_, std::move(outputLumiInfo));
}

DEFINE_FWK_MODULE(RawPCCProducer);
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
SelectEvents = cms.vstring('pathALCARECOAlCaPCCRandom')
),
outputCommands = cms.untracked.vstring(
'keep *_*alcaPCCProducerRandom*_*_*')
'keep *_alcaPCCIntegratorRandom_alcaPCCRandom_*')
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,13 @@
throw = cms.bool(False) # tolerate triggers stated above, but not available
)

from EventFilter.SiPixelRawToDigi.SiPixelRawToDigi_cfi import siPixelDigis
siPixelDigisForLumiR = siPixelDigis.cpu.clone(
InputLabel = "hltFEDSelectorLumiPixels"
)

from RecoLocalTracker.SiPixelClusterizer.SiPixelClusterizerPreSplitting_cfi import siPixelClustersPreSplitting
siPixelClustersForLumiR = siPixelClustersPreSplitting.cpu.clone(
src = "siPixelDigisForLumiR"
)
from Calibration.LumiAlCaRecoProducers.alcaPCCIntegrator_cfi import alcaPCCIntegrator
alcaPCCIntegratorRandom = alcaPCCIntegrator.clone()
alcaPCCIntegratorRandom.AlcaPCCIntegratorParameters.inputPccLabel="hltAlcaPixelClusterCounts"
alcaPCCIntegratorRandom.AlcaPCCIntegratorParameters.trigstring = "alcaPCCEvent"
alcaPCCIntegratorRandom.AlcaPCCIntegratorParameters.ProdInst = "alcaPCCRandom"

from Calibration.LumiAlCaRecoProducers.alcaPCCProducer_cfi import alcaPCCProducer
alcaPCCProducerRandom = alcaPCCProducer.clone()
alcaPCCProducerRandom.pixelClusterLabel = cms.InputTag("siPixelClustersForLumiR")
alcaPCCProducerRandom.trigstring = cms.untracked.string("alcaPCCRandom")

# Sequence #
seqALCARECOAlCaPCCRandom = cms.Sequence(ALCARECORandomHLT + siPixelDigisForLumiR + siPixelClustersForLumiR + alcaPCCProducerRandom)
seqALCARECOAlCaPCCRandom = cms.Sequence(ALCARECORandomHLT+alcaPCCIntegratorRandom)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
SelectEvents = cms.vstring('pathALCARECOAlCaPCCZeroBias')
),
outputCommands = cms.untracked.vstring(
'keep *_*alcaPCCProducerZeroBias_*_*')
'keep *_alcaPCCIntegratorZeroBias_alcaPCCZeroBias_*')
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,11 @@
throw = cms.bool(False) # tolerate triggers stated above, but not available
)

from EventFilter.SiPixelRawToDigi.SiPixelRawToDigi_cfi import siPixelDigis
siPixelDigisForLumiZB = siPixelDigis.cpu.clone(
InputLabel = "hltFEDSelectorLumiPixels"
)

from RecoLocalTracker.SiPixelClusterizer.SiPixelClusterizerPreSplitting_cfi import siPixelClustersPreSplitting
siPixelClustersForLumiZB = siPixelClustersPreSplitting.cpu.clone(
src = "siPixelDigisForLumiZB"
)
from Calibration.LumiAlCaRecoProducers.alcaPCCIntegrator_cfi import alcaPCCIntegrator
alcaPCCIntegratorZeroBias = alcaPCCIntegrator.clone()
alcaPCCIntegratorZeroBias.AlcaPCCIntegratorParameters.inputPccLabel="hltAlcaPixelClusterCounts"
alcaPCCIntegratorZeroBias.AlcaPCCIntegratorParameters.trigstring = "alcaPCCEvent"
alcaPCCIntegratorZeroBias.AlcaPCCIntegratorParameters.ProdInst = "alcaPCCZeroBias"

from Calibration.LumiAlCaRecoProducers.alcaPCCProducer_cfi import alcaPCCProducer
alcaPCCProducerZeroBias = alcaPCCProducer.clone()
alcaPCCProducerZeroBias.pixelClusterLabel = cms.InputTag("siPixelClustersForLumiZB")
alcaPCCProducerZeroBias.trigstring = cms.untracked.string("alcaPCCZeroBias")

# Sequence #
seqALCARECOAlCaPCCZeroBias = cms.Sequence(ALCARECOZeroBiasHLT + siPixelDigisForLumiZB + siPixelClustersForLumiZB + alcaPCCProducerZeroBias)
seqALCARECOAlCaPCCZeroBias = cms.Sequence(ALCARECOZeroBiasHLT + alcaPCCIntegratorZeroBias)
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
SelectEvents = cms.vstring('pathALCARECORawPCCProducer')
),
outputCommands = cms.untracked.vstring(
'keep *_rawPCCProd_*_*')
)
'keep *_ALCARECORawPCCProd*_*_*'
)
)


import copy
Expand Down
Loading

0 comments on commit 73943f5

Please sign in to comment.