Skip to content
Snippets Groups Projects
Commit 8316c326 authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

Merge branch 'mhodgkin_updatePFlowEOverPCellTool_BinsToJson' into 'main'

Update PFlowCellEOverPTool to read bin boundaries from json

See merge request atlas/athena!70782
parents 2964e33d f2c2ce96
No related branches found
No related tags found
No related merge requests found
......@@ -26,22 +26,12 @@ class PFCellEOverPTool : public IEFlowCellEOverPTool {
private:
std::vector<double> m_eBinValues;
std::vector<double> m_etaBinBounds;
std::vector<std::string> m_eBinLabels;
std::vector<std::string> m_etaBinLabels;
static std::string_view eBinsToString(const E_BINS& e_bins) ;
static std::string_view etaBinsToString(const ETA_BINS& eta_bins) ;
const std::array<E_BINS,6> m_e_bins{E001bin,E003point5bin,E010bin,E020bin,E032point5bin,E040bin};
const std::array<ETA_BINS,4> m_eta_bins{eta050bin,eta100bin,eta150bin,eta250bin};
const std::array<eflowFirstIntRegions::J1STLAYER,8> m_firstInt_bins{eflowFirstIntRegions::EMB1,eflowFirstIntRegions::EMB2,eflowFirstIntRegions::EMB3,eflowFirstIntRegions::EME1,eflowFirstIntRegions::EME2,
eflowFirstIntRegions::EME3,eflowFirstIntRegions::HEC,eflowFirstIntRegions::Tile};
const std::array<eflowCalo::LAYER,13> m_layerBins{eflowCalo::EMB1,eflowCalo::EMB2,eflowCalo::EMB3,eflowCalo::EME1,eflowCalo::EME2,eflowCalo::EME3,eflowCalo::HEC1,eflowCalo::HEC2,eflowCalo::HEC3
,eflowCalo::HEC4,eflowCalo::Tile1,eflowCalo::Tile2,eflowCalo::Tile3};
std::vector<double> m_energyBinLowerBoundaries;
std::vector<double> m_etaBinLowerBoundaries;
std::vector<int> m_firstIntBinLowerBoundaries;
std::vector<int> m_caloLayerBins;
/** Location for e/p and cell ordering reference files */
Gaudi::Property<std::string> m_referenceFileLocation{this,"referenceFileLocation","/eos/user/m/mhodgkin/EoverP_Results/Run3_mc21_rel22/","Location for e/p and cell ordering reference files"};
Gaudi::Property<std::string> m_referenceFileLocation{this,"referenceFileLocation","/home/markhodgkinson.linux/Releases/RLatest_eOvperP/athena/EOverPTools/EoverpNtupleAnalysis/ResultsDir/","Location for e/p and cell ordering reference files"};
};
#endif
......@@ -23,97 +23,74 @@ PFCellEOverPTool::PFCellEOverPTool(const std::string& type,
declareInterface<IEFlowCellEOverPTool>(this);
m_eBinValues.push_back( 1.0*Gaudi::Units::GeV );
m_eBinValues.push_back( 3.5*Gaudi::Units::GeV );
m_eBinValues.push_back( 10.0*Gaudi::Units::GeV );
m_eBinValues.push_back( 25.0*Gaudi::Units::GeV );
m_eBinValues.push_back( 32.5*Gaudi::Units::GeV );
m_eBinValues.push_back( 40.0*Gaudi::Units::GeV );
for (double x = 0.0; x < 2.0; x+=0.5) {
m_etaBinBounds.push_back(x);
}
m_etaBinBounds.push_back(2.5);
}
StatusCode PFCellEOverPTool::initialize(){
return StatusCode::SUCCESS;
}
std::string_view PFCellEOverPTool::eBinsToString(const E_BINS& e_bins){
std::ifstream binBoundariesFile(m_referenceFileLocation+"EOverPBinBoundaries.json");
nlohmann::json json_binBoundaries;
binBoundariesFile >> json_binBoundaries;
switch(e_bins){
case E001bin : return "E001bin";
case E003point5bin: return "E003point5bin";
case E010bin: return "E010bin";
case E020bin: return "E020bin";
case E032point5bin: return "E032point5bin";
case E040bin: return "E040bin";
default: throw std::invalid_argument("Please choose a valid E_BINS value");
}
}
auto fillBinBoundaries = [](auto && binBoundaries, const nlohmann::json &json_binBoundaries, const std::string &binName){
if (json_binBoundaries.find(binName) != json_binBoundaries.end()){
for (auto binBoundary : json_binBoundaries[binName]) binBoundaries.push_back(binBoundary);
}
else std::cout << "Did not find binName:" << binName << std::endl;
};
std::string_view PFCellEOverPTool::etaBinsToString(const ETA_BINS& eta_bins) {
fillBinBoundaries(m_energyBinLowerBoundaries, json_binBoundaries, "energyBinBoundaries");
fillBinBoundaries(m_etaBinLowerBoundaries, json_binBoundaries, "etaBinBoundaries");
fillBinBoundaries(m_firstIntBinLowerBoundaries, json_binBoundaries, "firstIntBinBoundaries");
fillBinBoundaries(m_caloLayerBins, json_binBoundaries, "caloLayerBinBoundaries");
switch(eta_bins){
case eta050bin : return "eta050bin";
case eta100bin : return "eta100bin";
case eta150bin : return "eta150bin";
case eta250bin : return "eta250bin";
case eta350bin : return "eta350bin";
case eta450bin : return "eta450bin";
default: throw std::invalid_argument("Please choose a valid ETA_BINS value");
}
return StatusCode::SUCCESS;
}
StatusCode PFCellEOverPTool::fillBinnedParameters(eflowEEtaBinnedParameters *binnedParameters) const {
if (binnedParameters) {
binnedParameters->initialise(m_eBinValues, m_etaBinBounds);
binnedParameters->initialise(m_energyBinLowerBoundaries, m_etaBinLowerBoundaries);
std::ifstream inputFile_eoverp(m_referenceFileLocation+"EOverP.json");
std::ifstream inputFile_eoverp(m_referenceFileLocation+"EoverP.json");
nlohmann::json json_eoverp;
inputFile_eoverp >> json_eoverp;
std::ifstream inputFile_cellOrdering(m_referenceFileLocation+"CellOrdering.json");
std::ifstream inputFile_cellOrdering(m_referenceFileLocation+"cellOrdering.json");
nlohmann::json json_cellOrdering;
inputFile_cellOrdering >> json_cellOrdering;
//Loop over energy, eta and first int bins
//For each combination we set the e/p mean and width from the json file values
for (auto thisEBin : m_e_bins){
//convert string_view to string so we can combine with "" later on.
std::string currentEBin(eBinsToString(thisEBin));
for (auto thisEtaBin : m_eta_bins){
//convert string_view to string so we can combine with "" later on.
std::string currentEtaBin(etaBinsToString(thisEtaBin));
for (auto thisFirstIntRegionBin : m_firstInt_bins){
for (auto thisEBin : m_energyBinLowerBoundaries){
std::string currentEBin = std::to_string(thisEBin);
for (auto thisEtaBin : m_etaBinLowerBoundaries){
std::string currentEtaBin = std::to_string(thisEtaBin);
for (auto thisFirstIntRegionBin_Int : m_firstIntBinLowerBoundaries){
auto thisFirstIntRegionBin = static_cast<eflowFirstIntRegions::J1STLAYER>(thisFirstIntRegionBin_Int);
std::string currentFirstIntBin = eflowFirstIntRegions::name(thisFirstIntRegionBin);
std::string eOverPBin = currentEBin+"_"+currentEtaBin+"_"+currentFirstIntBin;
std::string eOverPBin = "energyBinLowerBound_"+currentEBin+"_etaBinLowerBound_"+currentEtaBin+"_firstIntBinLowerBound_"+currentFirstIntBin;
if (json_eoverp.find(eOverPBin+"_mean") != json_eoverp.end()){
binnedParameters->setFudgeMean(thisEBin,thisEtaBin,thisFirstIntRegionBin,json_eoverp[eOverPBin+"_mean"]);
}
if (json_eoverp.find(eOverPBin+"_sigma") != json_eoverp.end()){
binnedParameters->setFudgeStdDev(thisEBin,thisEtaBin,thisFirstIntRegionBin,json_eoverp[eOverPBin+"_sigma"]);
}
for (auto thisLayerBin : m_layerBins){
std::string currentLayerBin = eflowCalo::name(thisLayerBin);
std::string cellOrderingBin = currentEBin+"_"+currentEtaBin+"_"+currentFirstIntBin+"-"+currentLayerBin;
for (auto thisLayerBin : m_caloLayerBins){
eflowCalo::LAYER thisLayerBinEnum = static_cast<eflowCalo::LAYER>(thisLayerBin);
std::string currentLayerBin = eflowCalo::name(thisLayerBinEnum);
std::string cellOrderingBin = eOverPBin + "_caloLayer_"+currentLayerBin;
if (json_cellOrdering.find(cellOrderingBin+"_norm1") != json_cellOrdering.end()){
binnedParameters->setShapeParam(thisEBin,thisEtaBin,thisFirstIntRegionBin,thisLayerBin,NORM1,json_cellOrdering[cellOrderingBin+"_norm1"]);
binnedParameters->setShapeParam(thisEBin,thisEtaBin,thisFirstIntRegionBin,thisLayerBinEnum,NORM1,json_cellOrdering[cellOrderingBin+"_norm1"]);
}
if (json_cellOrdering.find(cellOrderingBin+"_sigma1") != json_cellOrdering.end()){
binnedParameters->setShapeParam(thisEBin,thisEtaBin,thisFirstIntRegionBin,thisLayerBin,WIDTH1,json_cellOrdering[cellOrderingBin+"_sigma1"]);
binnedParameters->setShapeParam(thisEBin,thisEtaBin,thisFirstIntRegionBin,thisLayerBinEnum,WIDTH1,json_cellOrdering[cellOrderingBin+"_sigma1"]);
}
if (json_cellOrdering.find(cellOrderingBin+"_norm2") != json_cellOrdering.end()){
binnedParameters->setShapeParam(thisEBin,thisEtaBin,thisFirstIntRegionBin,thisLayerBin,NORM2,json_cellOrdering[cellOrderingBin+"_norm2"]);
binnedParameters->setShapeParam(thisEBin,thisEtaBin,thisFirstIntRegionBin,thisLayerBinEnum,NORM2,json_cellOrdering[cellOrderingBin+"_norm2"]);
}
if (json_cellOrdering.find(cellOrderingBin+"_sigma2") != json_cellOrdering.end()){
binnedParameters->setShapeParam(thisEBin,thisEtaBin,thisFirstIntRegionBin,thisLayerBin,WIDTH2,json_cellOrdering[cellOrderingBin+"_sigma2"]);
binnedParameters->setShapeParam(thisEBin,thisEtaBin,thisFirstIntRegionBin,thisLayerBinEnum,WIDTH2,json_cellOrdering[cellOrderingBin+"_sigma2"]);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment