-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36952 from benitezj/master
AlCaLumiPixelsCountsExpress and AlCaLumiPixelsCountsPrompt PCL and PromptReco
- Loading branch information
Showing
12 changed files
with
112 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
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 |
---|---|---|
|
@@ -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> | ||
|
@@ -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() {} | ||
|
@@ -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 { | ||
|
@@ -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])); | ||
} | ||
|
@@ -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); |
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
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.