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  paramsHelper.setLayer1ECalScalePhiBins(conf.find("layer1ECalScalePhiBins") != conf.end() ? conf["layer1ECalScalePhiBins"].getVector<unsigned int>() : std::vector<unsigned>(36,0));
52  paramsHelper.setLayer1HCalScalePhiBins(conf.find("layer1HCalScalePhiBins") != conf.end() ? conf["layer1HCalScalePhiBins"].getVector<unsigned int>() : std::vector<unsigned>(36,0));
53  paramsHelper.setLayer1HFScalePhiBins (conf.find("layer1HFScalePhiBins") != conf.end() ? conf["layer1HFScalePhiBins"] .getVector<unsigned int>() : std::vector<unsigned>(36,0));
54 
55  return true;
56 }
57 
58 bool
59 readCaloLayer2OnlineSettings(l1t::CaloParamsHelper& paramsHelper, std::map<std::string, l1t::Parameter>& conf, std::map<std::string, l1t::Mask>& ) {
60  const char * expectedParams[] = {
61  "leptonSeedThreshold",
62  "leptonTowerThreshold",
63  "pileUpTowerThreshold",
64  "jetSeedThreshold",
65  "jetMaxEta",
66  "HTMHT_maxJetEta",
67  "HT_jetThreshold",
68  "MHT_jetThreshold",
69  "jetEnergyCalibLUT",
70  "ETMET_maxTowerEta",
71  "ET_energyCalibLUT",
72  "ecalET_energyCalibLUT",
73  "METX_energyCalibLUT",
74  "METY_energyCalibLUT",
75  "egammaRelaxationThreshold",
76  "egammaMaxEta",
77  "egammaEnergyCalibLUT",
78  "egammaIsoLUT",
79  "tauMaxEta",
80  "tauEnergyCalibLUT",
81  "tauIsoLUT1",
82  "tauIsoLUT2",
83  "towerCountThreshold",
84  "towerCountMaxEta",
85  "ET_towerThreshold",
86  "MET_towerThreshold",
87  "jetBypassPileUpSub",
88  "egammaBypassCuts",
89  "egammaHOverECut_iEtaLT15",
90  "egammaHOverECut_iEtaGTEq15"
91  };
92  for (const auto param : expectedParams) {
93  if ( conf.find(param) == conf.end() ) {
94  std::cerr << "Unable to locate expected CaloLayer2 parameter: " << param << " in L1 settings payload!";
95  return false;
96  }
97  }
98  // Layer 2 params specification
99  paramsHelper.setEgSeedThreshold((conf["leptonSeedThreshold"].getValue<int>())/2);
100  paramsHelper.setTauSeedThreshold((conf["leptonSeedThreshold"].getValue<int>())/2);
101  paramsHelper.setEgNeighbourThreshold((conf["leptonTowerThreshold"].getValue<int>())/2);
102  paramsHelper.setTauNeighbourThreshold((conf["leptonTowerThreshold"].getValue<int>())/2);
103  paramsHelper.setJetSeedThreshold((conf["jetSeedThreshold"].getValue<int>())/2);
104  paramsHelper.setJetBypassPUS(conf["jetBypassPileUpSub"].getValue<bool>());
105  paramsHelper.setEgBypassEGVetos(conf["egammaBypassCuts"].getValue<bool>());
106  paramsHelper.setEgHOverEcutBarrel(conf["egammaHOverECut_iEtaLT15"].getValue<int>());
107  paramsHelper.setEgHOverEcutEndcap(conf["egammaHOverECut_iEtaGTEq15"].getValue<int>());
108 
109 
110  // Currently not used // paramsHelper.setEgPileupTowerThresh((conf["pileUpTowerThreshold"].getValue<int>()));
111  // Currently not used // paramsHelper.setTauPileupTowerThresh((conf["pileUpTowerThreshold"].getValue<int>()));
112  // Currently not used // paramsHelper.setJetMaxEta((conf["jetMaxEta"].getValue<int>()));
113 
114  std::vector<int> etSumEtaMax;
115  std::vector<int> etSumEtThresh;
116 
117  etSumEtaMax.push_back(conf["ETMET_maxTowerEta"].getValue<int>());
118  etSumEtaMax.push_back(conf["HTMHT_maxJetEta"].getValue<int>());
119  etSumEtaMax.push_back(conf["ETMET_maxTowerEta"].getValue<int>());
120  etSumEtaMax.push_back(conf["HTMHT_maxJetEta"].getValue<int>());
121  etSumEtaMax.push_back(conf["towerCountMaxEta"].getValue<int>());
122 
123  etSumEtThresh.push_back(conf["ET_towerThreshold"].getValue<int>()/2); // ETT tower threshold
124  etSumEtThresh.push_back(conf["HT_jetThreshold"].getValue<int>()/2);
125  etSumEtThresh.push_back(conf["MET_towerThreshold"].getValue<int>()/2); // ETM tower threshold
126  etSumEtThresh.push_back(conf["MHT_jetThreshold"].getValue<int>()/2);
127  etSumEtThresh.push_back(conf["ET_towerThreshold"].getValue<int>()/2);
128 
129  for (uint i=0; i<5; ++i) {
130  paramsHelper.setEtSumEtaMax(i, etSumEtaMax.at(i));
131  paramsHelper.setEtSumEtThreshold(i, etSumEtThresh.at(i));
132  }
133 
134  paramsHelper.setJetCalibrationLUT ( l1t::convertToLUT( conf["jetEnergyCalibLUT"].getVector<uint32_t>() ) );
135  paramsHelper.setEtSumEttCalibrationLUT ( l1t::convertToLUT( conf["ET_energyCalibLUT"].getVector<int>() ) );
136  paramsHelper.setEtSumEcalSumCalibrationLUT( l1t::convertToLUT( conf["ecalET_energyCalibLUT"].getVector<int>() ) );
137  paramsHelper.setEtSumXCalibrationLUT ( l1t::convertToLUT( conf["METX_energyCalibLUT"].getVector<int>() ) );
138  paramsHelper.setEgMaxPtHOverE((conf["egammaRelaxationThreshold"].getValue<int>())/2.);
139  paramsHelper.setEgEtaCut((conf["egammaMaxEta"].getValue<int>()));
140  paramsHelper.setEgCalibrationLUT ( l1t::convertToLUT( conf["egammaEnergyCalibLUT"].getVector<int>() ) );
141  paramsHelper.setEgIsolationLUT ( l1t::convertToLUT( conf["egammaIsoLUT"].getVector<int>() ) );
142 
143  paramsHelper.setIsoTauEtaMax((conf["tauMaxEta"].getValue<int>()));
144 
145  paramsHelper.setTauCalibrationLUT( l1t::convertToLUT( conf["tauEnergyCalibLUT"].getVector<int>() ) );
146  paramsHelper.setTauIsolationLUT ( l1t::convertToLUT( conf["tauIsoLUT1"].getVector<int>() ) );
147  paramsHelper.setTauIsolationLUT2 ( l1t::convertToLUT( conf["tauIsoLUT2"].getVector<int>() ) );
148 
149  return true;
150 }
151 
153 
154 std::shared_ptr<l1t::CaloParams> L1TCaloParamsOnlineProd::newObject(const std::string& objectKey, const L1TCaloParamsO2ORcd& record) {
155  using namespace edm::es;
156 
157  const L1TCaloStage2ParamsRcd& baseRcd = record.template getRecord< L1TCaloStage2ParamsRcd >() ;
158  edm::ESHandle< l1t::CaloParams > baseSettings ;
159  baseRcd.get( baseSettings ) ;
160 
161 
162  if( objectKey.empty() ){
163  edm::LogError( "L1-O2O: L1TCaloParamsOnlineProd" ) << "Key is empty, returning empty l1t::CaloParams";
164  throw std::runtime_error("Empty objectKey");
165  }
166 
167  std::string tscKey = objectKey.substr(0, objectKey.find(":") );
168  std::string rsKey = objectKey.substr( objectKey.find(":")+1, std::string::npos );
169 
170  edm::LogInfo( "L1-O2O: L1TCaloParamsOnlineProd" ) << "Producing L1TCaloParamsOnlineProd with TSC key = " << tscKey << " and RS key = " << rsKey ;
171 
172  std::string calol1_top_key, calol1_algo_key, calol1_hw_key;
173  std::string calol1_hw_payload, calol1_algo_payload;
174  std::string calol2_top_key, calol2_algo_key, calol2_hw_key;
175  std::string calol2_hw_payload;
176  std::map<std::string,std::string> calol2_algo_payloads; // key -> XML payload
177  try {
178  std::map<std::string,std::string> topKeys =
179  l1t::OnlineDBqueryHelper::fetch( {"CALOL1_KEY","CALOL2_KEY"},
180  "L1_TRG_CONF_KEYS",
181  tscKey,
183  );
184  calol1_top_key = topKeys["CALOL1_KEY"];
185 
186  std::map<std::string,std::string> calol1_keys =
187  l1t::OnlineDBqueryHelper::fetch( {"ALGO","HW"},
188  "CALOL1_KEYS",
189  calol1_top_key,
191  );
192 
193  calol1_hw_key = calol1_keys["HW"];
194  calol1_hw_payload = l1t::OnlineDBqueryHelper::fetch( {"CONF"},
195  "CALOL1_CLOBS",
196  calol1_hw_key,
198  ) ["CONF"];
199 
200  calol1_algo_key = calol1_keys["ALGO"];
201 
202  calol1_algo_payload = l1t::OnlineDBqueryHelper::fetch( {"CONF"},
203  "CALOL1_CLOBS",
204  calol1_algo_key,
206  ) ["CONF"];
207 
208  calol2_top_key = topKeys["CALOL2_KEY"];
209 
210  std::map<std::string,std::string> calol2_keys =
211  l1t::OnlineDBqueryHelper::fetch( {"ALGO","HW"},
212  "CALOL2_KEYS",
213  calol2_top_key,
215  );
216 
217  calol2_hw_key = calol2_keys["HW"];
218  calol2_hw_payload = l1t::OnlineDBqueryHelper::fetch( {"CONF"},
219  "CALOL2_CLOBS",
220  calol2_hw_key,
222  ) ["CONF"];
223 
224  calol2_algo_key = calol2_keys["ALGO"];
225 
226  std::map<std::string,std::string> calol2_algo_keys =
227  l1t::OnlineDBqueryHelper::fetch( {"DEMUX","MPS_COMMON","MPS_JET","MP_EGAMMA","MP_SUM","MP_TAU"},
228  "CALOL2_ALGO_KEYS",
229  calol2_algo_key,
231  );
232 
233  for(auto &key : calol2_algo_keys)
234  calol2_algo_payloads[ key.second ] =
236  "CALOL2_CLOBS",
237  key.second,
239  ) ["CONF"];
240 
241  } catch ( std::runtime_error &e ) {
242  edm::LogError( "L1-O2O: L1TCaloParamsOnlineProd" ) << e.what();
243  throw std::runtime_error("Broken key");
244  }
245 
246  // for debugging purposes dump the configs to local files
247  for(auto &conf : calol2_algo_payloads){
248  std::ofstream output(std::string("/tmp/").append(conf.first.substr(0,conf.first.find("/"))).append(".xml"));
249  output<<conf.second;
250  output.close();
251  }
252  {
253  std::ofstream output(std::string("/tmp/").append(calol2_hw_key.substr(0,calol2_hw_key.find("/"))).append(".xml"));
254  output << calol2_hw_payload;
255  output.close();
256  }
257  {
258  std::ofstream output(std::string("/tmp/").append(calol1_algo_key.substr(0,calol1_algo_key.find("/"))).append(".xml"));
259  output << calol1_algo_payload;
260  output.close();
261  }
262 
263 
264  l1t::XmlConfigParser xmlReader1;
265  l1t::TriggerSystem calol1;
266 
267 if( true ){
268  xmlReader1.readDOMFromString( calol1_hw_payload );
269  xmlReader1.readRootElement ( calol1, "calol1" );
270 } else {
271  // explicitly make the parser aware of the processors
272  calol1.addProcessor("CTP7_Phi0", "Layer1Processor","-2","-0");
273  calol1.addProcessor("CTP7_Phi1", "Layer1Processor","-2","-1");
274  calol1.addProcessor("CTP7_Phi2", "Layer1Processor","-2","-2");
275  calol1.addProcessor("CTP7_Phi3", "Layer1Processor","-2","-3");
276  calol1.addProcessor("CTP7_Phi4", "Layer1Processor","-2","-4");
277  calol1.addProcessor("CTP7_Phi5", "Layer1Processor","-2","-5");
278  calol1.addProcessor("CTP7_Phi6", "Layer1Processor","-2","-6");
279  calol1.addProcessor("CTP7_Phi7", "Layer1Processor","-2","-7");
280  calol1.addProcessor("CTP7_Phi8", "Layer1Processor","-2","-8");
281  calol1.addProcessor("CTP7_Phi9", "Layer1Processor","-2","-9");
282  calol1.addProcessor("CTP7_Phi10","Layer1Processor","-2","-10");
283  calol1.addProcessor("CTP7_Phi11","Layer1Processor","-2","-11");
284  calol1.addProcessor("CTP7_Phi12","Layer1Processor","-2","-12");
285  calol1.addProcessor("CTP7_Phi13","Layer1Processor","-2","-13");
286  calol1.addProcessor("CTP7_Phi14","Layer1Processor","-2","-14");
287  calol1.addProcessor("CTP7_Phi15","Layer1Processor","-2","-15");
288  calol1.addProcessor("CTP7_Phi16","Layer1Processor","-2","-16");
289 }
290  calol1.addProcessor("defaultProc", "processors","-2","0");
291 
293  calol1.addProcessor("processor0", "processors","-1","-1");
294  calol1.addProcessor("processor1", "processors","-1","-2");
295  calol1.addProcessor("processor2", "processors","-1","-3");
296  calol1.addProcessor("processor3", "processors","-1","-4");
297  calol1.addProcessor("processor4", "processors","-1","-5");
298  calol1.addProcessor("processor5", "processors","-1","-6");
299  calol1.addProcessor("processor6", "processors","-1","-7");
300  calol1.addProcessor("processor7", "processors","-1","-8");
301  calol1.addProcessor("processor8", "processors","-1","-9");
302  calol1.addProcessor("processor9", "processors","-1","-10");
303  calol1.addProcessor("processor10", "processors","-1","-11");
304  calol1.addProcessor("processor11", "processors","-1","-12");
305  calol1.addProcessor("processor12", "processors","-1","-13");
306  calol1.addProcessor("processor13", "processors","-1","-14");
307  calol1.addProcessor("processor14", "processors","-1","-15");
308  calol1.addProcessor("processor15", "processors","-1","-16");
309  calol1.addProcessor("processor16", "processors","-1","-17");
310  calol1.addProcessor("processor17", "processors","-1","-18");
312 
313  xmlReader1.readDOMFromString( calol1_algo_payload );
314  xmlReader1.readRootElement( calol1, "calol1" );
315 
316  calol1.setConfigured();
317 
318  std::map<std::string, l1t::Parameter> calol1_conf = calol1.getParameters("defaultProc");
319  std::map<std::string, l1t::Mask> calol1_rs ;//= calol1.getMasks ("processors");
320 
321  l1t::TriggerSystem calol2;
322 
323  l1t::XmlConfigParser xmlReader2;
324  xmlReader2.readDOMFromString( calol2_hw_payload );
325  xmlReader2.readRootElement( calol2, "calol2" );
326 
327  for(auto &conf : calol2_algo_payloads){
328  xmlReader2.readDOMFromString( conf.second );
329  xmlReader2.readRootElement( calol2, "calol2" );
330  }
331 
332 // calol2.setSystemId("calol2");
333  calol2.setConfigured();
334 
335  // Perhaps layer 2 has to look at settings for demux and mp separately? // => No demux settings required
336  std::map<std::string, l1t::Parameter> calol2_conf = calol2.getParameters("MP1");
337  std::map<std::string, l1t::Mask> calol2_rs ;//= calol2.getMasks ("processors");
338 
339  l1t::CaloParamsHelper m_params_helper( *(baseSettings.product()) );
340 
341  if( !readCaloLayer1OnlineSettings(m_params_helper, calol1_conf, calol1_rs) )
342  throw std::runtime_error("Parsing error for CaloLayer1");
343  if( !readCaloLayer2OnlineSettings(m_params_helper, calol2_conf, calol2_rs) )
344  throw std::runtime_error("Parsing error for CaloLayer2");
345 
346  std::shared_ptr< l1t::CaloParams > retval = std::make_shared< l1t::CaloParams >( m_params_helper ) ;
347  return retval;
348 }
349 
350 //define this as a plug-in
352 
void setEtSumEtaMax(unsigned isum, int eta)
void setEtSumEcalSumCalibrationLUT(const l1t::LUT &lut)
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 setEtSumEttCalibrationLUT(const l1t::LUT &lut)
delete x;
Definition: CaloConfig.h:22
void setEgCalibrationLUT(const l1t::LUT &lut)
L1TCaloParamsOnlineProd(const edm::ParameterSet &)
void setLayer1ECalScalePhiBins(const std::vector< unsigned > params)
void setEgHOverEcutBarrel(int cut)
bool readCaloLayer2OnlineSettings(l1t::CaloParamsHelper &paramsHelper, std::map< std::string, l1t::Parameter > &conf, std::map< std::string, l1t::Mask > &)
void setEtSumXCalibrationLUT(const l1t::LUT &lut)
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)
void setLayer1HCalScalePhiBins(const std::vector< unsigned > params)
void setLayer1HFScalePhiBins(const std::vector< unsigned > params)
bool readCaloLayer1OnlineSettings(l1t::CaloParamsHelper &paramsHelper, std::map< std::string, l1t::Parameter > &conf, std::map< std::string, l1t::Mask > &)