CMS 3D CMS Logo

L1TCaloParamsOnlineProd.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <stdexcept>
4 #include <sstream>
5 
14 #include "OnlineDBqueryHelper.h"
15 
16 #include "xercesc/util/PlatformUtils.hpp"
17 using namespace XERCES_CPP_NAMESPACE;
18 
19 class L1TCaloParamsOnlineProd : public L1ConfigOnlineProdBaseExt<L1TCaloParamsO2ORcd,l1t::CaloParams> {
20 private:
21 public:
22  virtual std::shared_ptr<l1t::CaloParams> newObject(const std::string& objectKey, const L1TCaloParamsO2ORcd& record) override ;
23 
26 };
27 
28 bool
29 readCaloLayer1OnlineSettings(l1t::CaloParamsHelper& paramsHelper, std::map<std::string, l1t::Parameter>& conf, std::map<std::string, l1t::Mask>& ) {
30  const char * expectedParams[] = {
31  "layer1ECalScaleFactors",
32  "layer1HCalScaleFactors",
33  "layer1HFScaleFactors",
34  "layer1ECalScaleETBins",
35  "layer1HCalScaleETBins",
36  "layer1HFScaleETBins"
37  };
38  for (const auto param : expectedParams) {
39  if ( conf.find(param) == conf.end() ) {
40  std::cerr << "Unable to locate expected CaloLayer1 parameter: " << param << " in L1 settings payload!";
41  return false;
42  }
43  }
44  // Layer 1 LUT specification
45  paramsHelper.setLayer1ECalScaleFactors((conf["layer1ECalScaleFactors"].getVector<double>()));
46  paramsHelper.setLayer1HCalScaleFactors((conf["layer1HCalScaleFactors"].getVector<double>()));
47  paramsHelper.setLayer1HFScaleFactors ((conf["layer1HFScaleFactors"] .getVector<double>()));
48  paramsHelper.setLayer1ECalScaleETBins(conf["layer1ECalScaleETBins"].getVector<int>());
49  paramsHelper.setLayer1HCalScaleETBins(conf["layer1HCalScaleETBins"].getVector<int>());
50  paramsHelper.setLayer1HFScaleETBins (conf["layer1HFScaleETBins"] .getVector<int>());
51 
52  return true;
53 }
54 
55 bool
56 readCaloLayer2OnlineSettings(l1t::CaloParamsHelper& paramsHelper, std::map<std::string, l1t::Parameter>& conf, std::map<std::string, l1t::Mask>& ) {
57  const char * expectedParams[] = {
58  "leptonSeedThreshold",
59  "leptonTowerThreshold",
60  "pileUpTowerThreshold",
61  "jetSeedThreshold",
62  "jetMaxEta",
63  "HTMHT_maxJetEta",
64  "HT_jetThreshold",
65  "MHT_jetThreshold",
66  "jetEnergyCalibLUT",
67  "ETMET_maxTowerEta",
68  "ET_energyCalibLUT",
69  "ecalET_energyCalibLUT",
70  "METX_energyCalibLUT",
71  "METY_energyCalibLUT",
72  "egammaRelaxationThreshold",
73  "egammaMaxEta",
74  "egammaEnergyCalibLUT",
75  "egammaIsoLUT",
76  "tauMaxEta",
77  "tauEnergyCalibLUT",
78  "tauIsoLUT1",
79  "tauIsoLUT2",
80  "towerCountThreshold",
81  "towerCountMaxEta",
82  "ET_towerThreshold",
83  "MET_towerThreshold",
84  "jetBypassPileUpSub",
85  "egammaBypassCuts",
86  "egammaHOverECut_iEtaLT15",
87  "egammaHOverECut_iEtaGTEq15"
88  };
89  for (const auto param : expectedParams) {
90  if ( conf.find(param) == conf.end() ) {
91  std::cerr << "Unable to locate expected CaloLayer2 parameter: " << param << " in L1 settings payload!";
92  return false;
93  }
94  }
95  // Layer 2 params specification
96  paramsHelper.setEgSeedThreshold((conf["leptonSeedThreshold"].getValue<int>())/2);
97  paramsHelper.setTauSeedThreshold((conf["leptonSeedThreshold"].getValue<int>())/2);
98  paramsHelper.setEgNeighbourThreshold((conf["leptonTowerThreshold"].getValue<int>())/2);
99  paramsHelper.setTauNeighbourThreshold((conf["leptonTowerThreshold"].getValue<int>())/2);
100  paramsHelper.setJetSeedThreshold((conf["jetSeedThreshold"].getValue<int>())/2);
101  paramsHelper.setJetBypassPUS(conf["jetBypassPileUpSub"].getValue<bool>());
102  paramsHelper.setEgBypassEGVetos(conf["egammaBypassCuts"].getValue<bool>());
103  paramsHelper.setEgHOverEcutBarrel(conf["egammaHOverECut_iEtaLT15"].getValue<int>());
104  paramsHelper.setEgHOverEcutEndcap(conf["egammaHOverECut_iEtaGTEq15"].getValue<int>());
105 
106 
107  // Currently not used // paramsHelper.setEgPileupTowerThresh((conf["pileUpTowerThreshold"].getValue<int>()));
108  // Currently not used // paramsHelper.setTauPileupTowerThresh((conf["pileUpTowerThreshold"].getValue<int>()));
109  // Currently not used // paramsHelper.setJetMaxEta((conf["jetMaxEta"].getValue<int>()));
110 
111  std::vector<int> etSumEtaMax;
112  std::vector<int> etSumEtThresh;
113 
114  etSumEtaMax.push_back(conf["ETMET_maxTowerEta"].getValue<int>());
115  etSumEtaMax.push_back(conf["HTMHT_maxJetEta"].getValue<int>());
116  etSumEtaMax.push_back(conf["ETMET_maxTowerEta"].getValue<int>());
117  etSumEtaMax.push_back(conf["HTMHT_maxJetEta"].getValue<int>());
118  etSumEtaMax.push_back(conf["towerCountMaxEta"].getValue<int>());
119 
120  etSumEtThresh.push_back(conf["ET_towerThreshold"].getValue<int>()/2); // ETT tower threshold
121  etSumEtThresh.push_back(conf["HT_jetThreshold"].getValue<int>()/2);
122  etSumEtThresh.push_back(conf["MET_towerThreshold"].getValue<int>()/2); // ETM tower threshold
123  etSumEtThresh.push_back(conf["MHT_jetThreshold"].getValue<int>()/2);
124  etSumEtThresh.push_back(conf["ET_towerThreshold"].getValue<int>()/2);
125 
126  for (uint i=0; i<5; ++i) {
127  paramsHelper.setEtSumEtaMax(i, etSumEtaMax.at(i));
128  paramsHelper.setEtSumEtThreshold(i, etSumEtThresh.at(i));
129  }
130 
131  paramsHelper.setJetCalibrationLUT ( l1t::convertToLUT( conf["jetEnergyCalibLUT"].getVector<uint32_t>() ) );
132  paramsHelper.setEtSumEttPUSLUT ( l1t::convertToLUT( conf["ET_energyCalibLUT"].getVector<int>() ) );
133  paramsHelper.setEtSumEcalSumPUSLUT( l1t::convertToLUT( conf["ecalET_energyCalibLUT"].getVector<int>() ) );
134  paramsHelper.setEtSumXPUSLUT ( l1t::convertToLUT( conf["METX_energyCalibLUT"].getVector<int>() ) );
135  paramsHelper.setEgMaxPtHOverE((conf["egammaRelaxationThreshold"].getValue<int>())/2.);
136  paramsHelper.setEgEtaCut((conf["egammaMaxEta"].getValue<int>()));
137  paramsHelper.setEgCalibrationLUT ( l1t::convertToLUT( conf["egammaEnergyCalibLUT"].getVector<int>() ) );
138  paramsHelper.setEgIsolationLUT ( l1t::convertToLUT( conf["egammaIsoLUT"].getVector<int>() ) );
139 
140  paramsHelper.setIsoTauEtaMax((conf["tauMaxEta"].getValue<int>()));
141 
142  paramsHelper.setTauCalibrationLUT( l1t::convertToLUT( conf["tauEnergyCalibLUT"].getVector<int>() ) );
143  paramsHelper.setTauIsolationLUT ( l1t::convertToLUT( conf["tauIsoLUT1"].getVector<int>() ) );
144  paramsHelper.setTauIsolationLUT2 ( l1t::convertToLUT( conf["tauIsoLUT2"].getVector<int>() ) );
145 
146  return true;
147 }
148 
150 
151 std::shared_ptr<l1t::CaloParams> L1TCaloParamsOnlineProd::newObject(const std::string& objectKey, const L1TCaloParamsO2ORcd& record) {
152  using namespace edm::es;
153 
154  const L1TCaloStage2ParamsRcd& baseRcd = record.template getRecord< L1TCaloStage2ParamsRcd >() ;
155  edm::ESHandle< l1t::CaloParams > baseSettings ;
156  baseRcd.get( baseSettings ) ;
157 
158 
159  if( objectKey.empty() ){
160  edm::LogError( "L1-O2O: L1TCaloParamsOnlineProd" ) << "Key is empty, returning empty l1t::CaloParams";
161  throw std::runtime_error("Empty objectKey");
162  }
163 
164  std::string tscKey = objectKey.substr(0, objectKey.find(":") );
165  std::string rsKey = objectKey.substr( objectKey.find(":")+1, std::string::npos );
166 
167  edm::LogInfo( "L1-O2O: L1TCaloParamsOnlineProd" ) << "Producing L1TCaloParamsOnlineProd with TSC key = " << tscKey << " and RS key = " << rsKey ;
168 
169  std::string calol1_top_key, calol1_algo_key;
170  std::string calol1_algo_payload;
171  std::string calol2_top_key, calol2_algo_key, calol2_hw_key;
172  std::string calol2_hw_payload;
173  std::map<std::string,std::string> calol2_algo_payloads; // key -> XML payload
174  try {
175  std::map<std::string,std::string> topKeys =
176  l1t::OnlineDBqueryHelper::fetch( {"CALOL1_KEY","CALOL2_KEY"},
177  "L1_TRG_CONF_KEYS",
178  tscKey,
180  );
181  calol1_top_key = topKeys["CALOL1_KEY"];
182 
183  calol1_algo_key = l1t::OnlineDBqueryHelper::fetch( {"ALGO"},
184  "CALOL1_KEYS",
185  calol1_top_key,
187  ) ["ALGO"];
188 
189  calol1_algo_payload = l1t::OnlineDBqueryHelper::fetch( {"CONF"},
190  "CALOL1_CLOBS",
191  calol1_algo_key,
193  ) ["CONF"];
194 
195  calol2_top_key = topKeys["CALOL2_KEY"];
196 
197  std::map<std::string,std::string> calol2_keys =
198  l1t::OnlineDBqueryHelper::fetch( {"ALGO","HW"},
199  "CALOL2_KEYS",
200  calol2_top_key,
202  );
203 
204  calol2_hw_key = calol2_keys["HW"];
205  calol2_hw_payload = l1t::OnlineDBqueryHelper::fetch( {"CONF"},
206  "CALOL2_CLOBS",
207  calol2_hw_key,
209  ) ["CONF"];
210 
211  calol2_algo_key = calol2_keys["ALGO"];
212 
213  std::map<std::string,std::string> calol2_algo_keys =
214  l1t::OnlineDBqueryHelper::fetch( {"DEMUX","MPS_COMMON","MPS_JET","MP_EGAMMA","MP_SUM","MP_TAU"},
215  "CALOL2_ALGO_KEYS",
216  calol2_algo_key,
218  );
219 
220  for(auto &key : calol2_algo_keys)
221  calol2_algo_payloads[ key.second ] =
223  "CALOL2_CLOBS",
224  key.second,
226  ) ["CONF"];
227 
228  } catch ( std::runtime_error &e ) {
229  edm::LogError( "L1-O2O: L1TCaloParamsOnlineProd" ) << e.what();
230  throw std::runtime_error("Broken key");
231  }
232 
233  // for debugging purposes dump the configs to local files
234  for(auto &conf : calol2_algo_payloads){
235  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0,conf.first.find("/"))).append(".xml"));
236  output<<conf.second;
237  output.close();
238  }
239  {
240  std::ofstream output(std::string("/tmp/").append(calol2_hw_key.substr(0,calol2_hw_key.find("/"))).append(".xml"));
241  output << calol2_hw_payload;
242  output.close();
243  }
244  {
245  std::ofstream output(std::string("/tmp/").append(calol1_algo_key.substr(0,calol1_algo_key.find("/"))).append(".xml"));
246  output << calol1_algo_payload;
247  output.close();
248  }
249 
250 
251 
252  l1t::XmlConfigParser xmlReader1;
253  xmlReader1.readDOMFromString( calol1_algo_payload );
254 
255  l1t::TriggerSystem calol1;
256  calol1.addProcessor("processors", "processors","-1","-1");
257  xmlReader1.readRootElement( calol1, "calol1" );
258  calol1.setConfigured();
259 
260  std::map<std::string, l1t::Parameter> calol1_conf = calol1.getParameters("processors");
261  std::map<std::string, l1t::Mask> calol1_rs ;//= calol1.getMasks ("processors");
262 
263  l1t::TriggerSystem calol2;
264 
265  l1t::XmlConfigParser xmlReader2;
266  xmlReader2.readDOMFromString( calol2_hw_payload );
267  xmlReader2.readRootElement( calol2, "calol2" );
268 
269  for(auto &conf : calol2_algo_payloads){
270  xmlReader2.readDOMFromString( conf.second );
271  xmlReader2.readRootElement( calol2, "calol2" );
272  }
273 
274 // calol2.setSystemId("calol2");
275  calol2.setConfigured();
276 
277  // Perhaps layer 2 has to look at settings for demux and mp separately? // => No demux settings required
278  std::map<std::string, l1t::Parameter> calol2_conf = calol2.getParameters("MP1");
279  std::map<std::string, l1t::Mask> calol2_rs ;//= calol2.getMasks ("processors");
280 
281  l1t::CaloParamsHelper m_params_helper( *(baseSettings.product()) );
282 
283  if( !readCaloLayer1OnlineSettings(m_params_helper, calol1_conf, calol1_rs) )
284  throw std::runtime_error("Parsing error for CaloLayer1");
285  if( !readCaloLayer2OnlineSettings(m_params_helper, calol2_conf, calol2_rs) )
286  throw std::runtime_error("Parsing error for CaloLayer2");
287 
288  std::shared_ptr< l1t::CaloParams > retval = std::make_shared< l1t::CaloParams >( m_params_helper ) ;
289  return retval;
290 }
291 
292 //define this as a plug-in
294 
void setEtSumEtaMax(unsigned isum, int eta)
int i
Definition: DBlmapReader.cc:9
void setConfigured(bool state=true) noexcept
Definition: TriggerSystem.h:73
void setLayer1HCalScaleETBins(const std::vector< int > params)
void setIsoTauEtaMax(int value)
void setEgNeighbourThreshold(double thresh)
void setTauCalibrationLUT(const l1t::LUT &lut)
JetCorrectorParameters::Record record
Definition: classes.h:7
void setTauIsolationLUT(const l1t::LUT &lut)
void setJetCalibrationLUT(const l1t::LUT &lut)
void setTauNeighbourThreshold(double thresh)
void setEgHOverEcutEndcap(int cut)
virtual std::shared_ptr< l1t::CaloParams > newObject(const std::string &objectKey, const L1TCaloParamsO2ORcd &record) override
void setEtSumXPUSLUT(const l1t::LUT &lut)
delete x;
Definition: CaloConfig.h:22
void setEgCalibrationLUT(const l1t::LUT &lut)
L1TCaloParamsOnlineProd(const edm::ParameterSet &)
void setEtSumEttPUSLUT(const l1t::LUT &lut)
void setEgHOverEcutBarrel(int cut)
bool readCaloLayer2OnlineSettings(l1t::CaloParamsHelper &paramsHelper, std::map< std::string, l1t::Parameter > &conf, std::map< std::string, l1t::Mask > &)
void readDOMFromString(const std::string &str, xercesc::DOMDocument *&doc)
void setEgBypassEGVetos(unsigned flag)
static std::map< std::string, std::string > fetch(const std::vector< std::string > &queryColumns, const std::string &table, const std::string &key, l1t::OMDSReader &m_omdsReader)
void get(HolderT &iHolder) const
void setLayer1HFScaleETBins(const std::vector< int > params)
void setEtSumEtThreshold(unsigned isum, double thresh)
void setLayer1ECalScaleETBins(const std::vector< int > params)
void setTauSeedThreshold(double thresh)
l1t::LUT convertToLUT(const std::vector< uint64_t > &v, int padding=-1) noexcept
Definition: ConvertToLUT.h:10
void setEgEtaCut(int mask)
void setLayer1HCalScaleFactors(const std::vector< double > params)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void setLayer1HFScaleFactors(const std::vector< double > params)
const std::map< std::string, Parameter > & getParameters(const char *processor) const
void setJetSeedThreshold(double thresh)
void setEgMaxPtHOverE(double thresh)
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
void setEgIsolationLUT(const l1t::LUT &lut)
void addProcessor(const char *processor, const char *role, const char *crate, const char *slot)
void setTauIsolationLUT2(const l1t::LUT &lut)
void setJetBypassPUS(unsigned flag)
void setEgSeedThreshold(double thresh)
void setLayer1ECalScaleFactors(const std::vector< double > params)
bool readCaloLayer1OnlineSettings(l1t::CaloParamsHelper &paramsHelper, std::map< std::string, l1t::Parameter > &conf, std::map< std::string, l1t::Mask > &)
void setEtSumEcalSumPUSLUT(const l1t::LUT &lut)