CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TRate_Harvest.cc
Go to the documentation of this file.
1 /*
2  * \file L1TRate_Harvest.cc
3  *
4  * $Date: 2012/11/28 13:58:12 $
5  * $Revision: 1.2 $
6  * \author J. Pela, P. Musella
7  *
8  */
9 
10 // L1TMonitor includes
12 
14 
16 
21 #include "DataFormats/Common/interface/ConditionsInEdm.h" // Parameters associated to Run, LS and Event
22 #include "DataFormats/Luminosity/interface/LumiDetails.h" // Luminosity Information
23 #include "DataFormats/Luminosity/interface/LumiSummary.h" // Luminosity Information
24 
32 
34 
35 #include "TList.h"
36 
37 using namespace edm;
38 using namespace std;
39 
40 //_____________________________________________________________________
42 
43  m_maxNbins = 2500; // Maximum LS for each run (for binning purposes)
44  m_parameters = ps;
45 
46  // Mapping parameter input variables
47  m_scalersSource = m_parameters.getParameter <InputTag>("inputTagScalersResults");
48  m_l1GtDataDaqInputTag = m_parameters.getParameter <InputTag>("inputTagL1GtDataDaq");
49  m_verbose = m_parameters.getUntrackedParameter<bool> ("verbose",false);
50  m_refPrescaleSet = m_parameters.getParameter <int> ("refPrescaleSet");
51  m_lsShiftGTRates = m_parameters.getUntrackedParameter<int> ("lsShiftGTRates",0);
52 
53  // Getting which categories to monitor
54  ParameterSet Categories = ps.getParameter<ParameterSet>("categories");
55  m_inputCategories["Mu"] = Categories.getUntrackedParameter<bool>("Mu");
56  m_inputCategories["EG"] = Categories.getUntrackedParameter<bool>("EG");
57  m_inputCategories["IsoEG"] = Categories.getUntrackedParameter<bool>("IsoEG");
58  m_inputCategories["Jet"] = Categories.getUntrackedParameter<bool>("Jet");
59  m_inputCategories["CenJet"] = Categories.getUntrackedParameter<bool>("CenJet");
60  m_inputCategories["ForJet"] = Categories.getUntrackedParameter<bool>("ForJet");
61  m_inputCategories["TauJet"] = Categories.getUntrackedParameter<bool>("TauJet");
62  m_inputCategories["ETM"] = Categories.getUntrackedParameter<bool>("ETM");
63  m_inputCategories["ETT"] = Categories.getUntrackedParameter<bool>("ETT");
64  m_inputCategories["HTT"] = Categories.getUntrackedParameter<bool>("HTT");
65  m_inputCategories["HTM"] = Categories.getUntrackedParameter<bool>("HTM");
66 
67  // Inicializing Variables
68  dbe = NULL;
69 
70  if (ps.getUntrackedParameter < bool > ("dqmStore", false)) {
71  dbe = Service < DQMStore > ().operator->();
72  dbe->setVerbose(0);
73  }
74 
75  // What to do if we want our output to be saved to a external file
76  m_outputFile = ps.getUntrackedParameter < string > ("outputFile", "");
77 
78  if (m_outputFile.size() != 0) {
79  cout << "L1T Monitoring histograms will be saved to " << m_outputFile.c_str() << endl;
80  }
81 
82  bool disable = ps.getUntrackedParameter < bool > ("disableROOToutput", false);
83  if (disable) {m_outputFile = "";}
84 
85  if (dbe != NULL) {dbe->setCurrentFolder("L1T/L1TRate_Harvest");}
86 
87 }
88 
89 //_____________________________________________________________________
91 
92 //_____________________________________________________________________
94 
95  if (m_verbose) {cout << "[L1TRate_Harvest:] Called beginJob." << endl;}
96 
97  // get hold of back-end interface
98  DQMStore *dbe = 0;
99  dbe = Service < DQMStore > ().operator->();
100 
101  if (dbe) {
102  dbe->setCurrentFolder("L1T/L1TRate_Harvest");
103  dbe->rmdir("L1T/L1TRate_Harvest");
104  }
105 
106 }
107 
108 //_____________________________________________________________________
110 
111  if (m_verbose) {cout << "[L1TRate_Harvest:] Called endJob." << endl;}
112 
113  if (m_outputFile.size() != 0 && dbe)
114  dbe->save(m_outputFile);
115 
116  return;
117 
118 }
119 
120 //_____________________________________________________________________
121 // BeginRun: as input you get filtered events...
122 //_____________________________________________________________________
124 
125 // if (m_verbose) {cout << "[L1TRate_Harvest:] Called beginRun." << endl;}
126 
127 // ESHandle<L1GtTriggerMenu> menuRcd;
128 // ESHandle<L1GtPrescaleFactors> l1GtPfAlgo;
129 
130 // iSetup.get<L1GtTriggerMenuRcd>() .get(menuRcd);
131 // iSetup.get<L1GtPrescaleFactorsAlgoTrigRcd>().get(l1GtPfAlgo);
132 
133 // const L1GtTriggerMenu* menu = menuRcd .product();
134 // const L1GtPrescaleFactors* m_l1GtPfAlgo = l1GtPfAlgo.product();
135 
136 // // Initializing DQM Monitor Elements
137 // dbe->setCurrentFolder("L1T/L1TRate_Harvest");
138 
139 // // Retriving the list of prescale sets
140 // m_listsPrescaleFactors = &(m_l1GtPfAlgo->gtPrescaleFactors());
141 
142 // // Getting Lowest Prescale Single Object Triggers from the menu
143 // L1TMenuHelper myMenuHelper = L1TMenuHelper(iSetup);
144 // m_selectedTriggers = myMenuHelper.getLUSOTrigger(m_inputCategories,m_refPrescaleSet);
145 
146 // //-> Getting template fits for the algLo cross sections
147 // int srcAlgoXSecFit = m_parameters.getParameter<int>("srcAlgoXSecFit");
148 // if (srcAlgoXSecFit == 0){getXSexFitsOMDS (m_parameters);}
149 // else if(srcAlgoXSecFit == 1){getXSexFitsPython(m_parameters);}
150 
151 // for (CItAlgo algo = menu->gtAlgorithmMap().begin(); algo!=menu->gtAlgorithmMap().end(); ++algo){
152 // m_algoBit[(algo->second).algoAlias()] = (algo->second).algoBitNumber();
153 // }
154 
155 // // double minRate = m_parameters.getParameter<double>("minRate");
156 // // double maxRate = m_parameters.getParameter<double>("maxRate");
157 
158 // // Initializing DQM Monitor Elements
159 // for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
160 
161 // TString tCategory = (*i).first;
162 // TString tTrigger = (*i).second;
163 
164 // TString tErrorMessage = "";
165 // TF1* tTestFunction;
166 
167 // if(tTrigger != "Undefined" && m_templateFunctions.find(tTrigger) != m_templateFunctions.end()){
168 // tTestFunction = m_templateFunctions[tTrigger];
169 // }
170 // else if(tTrigger == "Undefined"){
171 // TString tFunc = "-1";
172 // tTestFunction = new TF1("FitParametrization_"+tTrigger,tFunc,0,double(m_maxNbins)-0.5);
173 // }
174 // else if(m_templateFunctions.find(tTrigger) == m_templateFunctions.end()){
175 // TString tFunc = "-1";
176 // tTestFunction = new TF1("FitParametrization_"+tTrigger,tFunc,0,double(m_maxNbins)-0.5);
177 // tErrorMessage = " (Undefined Test Function)";
178 // }
179 // else{
180 // TString tFunc = "-1";
181 // tTestFunction = new TF1("FitParametrization_"+tTrigger,tFunc,0,double(m_maxNbins)-0.5);
182 // }
183 
184 // if(tTrigger != "Undefined"){
185 
186 // if(myMenuHelper.getPrescaleByAlias(tCategory,tTrigger) != 1){
187 // tErrorMessage += " WARNING: Default Prescale = ";
188 // tErrorMessage += myMenuHelper.getPrescaleByAlias(tCategory,tTrigger);
189 // }
190 
191 // if (tCategory == "Mu" && myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger) != 4294967295){ //hexadecimal of the whole range
192 // tErrorMessage += " WARNING: Eta Range = ";
193 // tErrorMessage += myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger);
194 // }
195 // else if(tCategory == "EG" && myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger) != 32639){
196 // tErrorMessage += " WARNING: Eta Range = ";
197 // tErrorMessage += myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger);
198 // }
199 // else if(tCategory == "IsoEG" && myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger) != 32639){
200 // tErrorMessage += " WARNING: Eta Range = ";
201 // tErrorMessage += myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger);
202 // }
203 
204 // if(tCategory == "Mu" && myMenuHelper.getQualityAlias(tCategory,tTrigger) != 240){
205 // tErrorMessage += " WARNING: Quality = ";
206 // tErrorMessage += myMenuHelper.getQualityAlias(tCategory,tTrigger);
207 // }
208 
209 // }
210 
211 
212 // dbe->setCurrentFolder("L1T/L1TRate_Harvest/TriggerRates"); // rate of the trigger...
213 // m_xSecVsInstLumi[tTrigger] = dbe->book1D(tCategory,
214 // "Rate "+tTrigger+tErrorMessage,
215 // m_maxNbins,0.5,m_maxNbins+0.5);
216 // m_xSecVsInstLumi[tTrigger] ->setAxisTitle("Luminosity Section" ,1);
217 // m_xSecVsInstLumi[tTrigger] ->setAxisTitle("Rate [Hz]" ,2);
218 // // m_xSecVsInstLumi[tTrigger] ->getTProfile()->GetListOfFunctions()->Add(tTestFunction);
219 // m_xSecVsInstLumi[tTrigger] ->getTH1()->SetMarkerStyle(23);
220 
221 // }
222 
223 }
224 
225 //_____________________________________________________________________
227 // if (m_verbose) {cout << "[L1TRate_Harvest:] Called endRun." << endl;}
228 }
229 
230 //_____________________________________________________________________
232 
233  // if (m_verbose) {cout << "[L1TRate_Harvest:] Called beginLuminosityBlock at LS=" << lumiBlock.id().luminosityBlock() << endl;}
234 
235 }
236 
237 //_____________________________________________________________________
239 
240 // int eventLS = lumiBlock.id().luminosityBlock();
241 // if (m_verbose) {cout << "[L1TRate_Harvest:] Called endLuminosityBlock at LS=" << eventLS << endl;}
242 
243 // // We can certify LS -1 since we should have available:
244 // // gt rates: (current LS)-1
245 // // prescale: current LS
246 // // lumi : current LS
247 // //eventLS--;
248 
249 // // Checking if all necessary quantities are defined for our calculations
250 // bool isDefRate,isDefLumi,isDefPrescaleIndex;
251 // map<TString,double>* rates=0;
252 // double lumi=0;
253 // int prescalesIndex=0;
254 
255 // // Reseting MonitorElements so we can refill them
256 // for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
257 // string tTrigger = (*i).second;
258 // // m_xSecObservedToExpected[tTrigger]->getTH1()->Reset("ICE");
259 // m_xSecVsInstLumi [tTrigger]->getTH1()->Reset("ICE");
260 // }
261 
262 // for(map<int,map<TString,double> >::iterator i=m_lsRates.begin() ; i!=m_lsRates.end() ; i++){
263 
264 // unsigned int ls = (*i).first;
265 // rates = &(*i).second;
266 // isDefRate=true;
267 
268 // if(m_lsLuminosity.find(ls)==m_lsLuminosity.end()){isDefLumi=false;}
269 // else{
270 // isDefLumi=true;
271 // lumi=m_lsLuminosity[ls];
272 // }
273 
274 // if(m_lsPrescaleIndex.find(ls)==m_lsPrescaleIndex.end()){isDefPrescaleIndex=false;}
275 // else{
276 // isDefPrescaleIndex=true;
277 // prescalesIndex=m_lsPrescaleIndex[ls];
278 // }
279 
280 // if(isDefRate && isDefLumi && isDefPrescaleIndex){
281 
282 // const vector<int>& currentPrescaleFactors = (*m_listsPrescaleFactors).at(prescalesIndex);
283 
284 // for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
285 
286 // string tTrigger = (*i).second;
287 // // TF1* tTestFunction = (TF1*) m_xSecVsInstLumi[tTrigger]->getTProfile()->GetListOfFunctions()->First();
288 
289 // // If trigger name is defined we get the rate fit parameters
290 // if(tTrigger != "Undefined"){
291 
292 // unsigned int trigBit = m_algoBit[tTrigger];
293 // double trigPrescale = currentPrescaleFactors[trigBit];
294 // double trigRate = (*rates)[tTrigger];
295 
296 // if(lumi!=0 && trigPrescale!=0 && trigRate!=0){
297 
298 // // double AlgoXSec = (trigPrescale*trigRate)/lumi;
299 // // double TemplateFunctionValue = tTestFunction->Eval(lumi);
300 
301 // // Checking against Template function
302 // int ibin = m_xSecVsInstLumi[tTrigger]->getTH1()->FindBin(ls);
303 // // m_xSecObservedToExpected[tTrigger]->setBinContent(ibin,AlgoXSec/TemplateFunctionValue);
304 // m_xSecVsInstLumi[tTrigger]->setBinContent(trigPrescale*trigRate,ibin);
305 
306 // // if(m_verbose){cout<<"[L1TRate_Harvest:] ls="<<ls<<" Algo="<<tTrigger<<" XSec="<<AlgoXSec<<" Test="<<AlgoXSec/TemplateFunctionValue<<endl;}
307 
308 // }
309 // // else{
310 // // int ibin = m_xSecObservedToExpected[tTrigger]->getTH1()->FindBin(ls);
311 // // m_xSecObservedToExpected[tTrigger]->setBinContent(ibin,0.000001);
312 // // if(m_verbose){cout << "[L1TRate_Harvest:] Algo="<< tTrigger<< " XSec=Failed" << endl;}
313 // //}
314 // }
315 // }
316 // }
317 // }
318 }
319 
320 //_____________________________________________________________________
321 void L1TRate_Harvest::analyze(const Event & iEvent, const EventSetup & eventSetup){
322 
323 // edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecordData;
324 // edm::Handle<Level1TriggerScalersCollection> triggerScalers;
325 // edm::Handle<LumiScalersCollection> colLScal;
326 
327 // iEvent.getByLabel(m_l1GtDataDaqInputTag, gtReadoutRecordData);
328 // iEvent.getByLabel(m_scalersSource , colLScal);
329 // iEvent.getByLabel(m_scalersSource , triggerScalers);
330 
331 // // Integers
332 // int EventRun = iEvent.id().run();
333 // unsigned int eventLS = iEvent.id().luminosityBlock();
334 
335 // // Getting the trigger trigger rates from GT and buffering it
336 // if(triggerScalers.isValid()){
337 
338 // Level1TriggerScalersCollection::const_iterator itL1TScalers = triggerScalers->begin();
339 // Level1TriggerRates trigRates(*itL1TScalers,EventRun);
340 
341 // int gtLS = (*itL1TScalers).lumiSegmentNr()+m_lsShiftGTRates;
342 
343 // // If we haven't got the data from this LS yet get it
344 // if(m_lsRates.find(gtLS)==m_lsRates.end()){
345 
346 // if (m_verbose) {cout << "[L1TRate_Harvest:] Buffering GT Rates for LS=" << gtLS << endl;}
347 // map<TString,double> bufferRate;
348 
349 // // Buffer the rate informations for all selected bits
350 // for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
351 
352 // string tTrigger = (*i).second;
353 
354 // // If trigger name is defined we store the rate
355 // if(tTrigger != "Undefined"){
356 
357 // unsigned int trigBit = m_algoBit[tTrigger];
358 // double trigRate = trigRates.gtAlgoCountsRate()[trigBit];
359 
360 // bufferRate[tTrigger] = trigRate;
361 // }
362 // }
363 // m_lsRates[gtLS] = bufferRate;
364 // }
365 // }
366 
367 // // Getting from the SCAL the luminosity information and buffering it
368 // if(colLScal.isValid() && colLScal->size()){
369 
370 // LumiScalersCollection::const_iterator itLScal = colLScal->begin();
371 // unsigned int scalLS = itLScal->sectionNumber();
372 
373 // // If we haven't got the data from this SCAL LS yet get it
374 // if(m_lsLuminosity.find(scalLS)==m_lsLuminosity.end()){
375 
376 // if (m_verbose) {cout << "[L1TRate_Harvest:] Buffering SCAL-HF Lumi for LS=" << scalLS << endl;}
377 // double instLumi = itLScal->instantLumi(); // Getting Instant Lumi from HF (via SCAL)
378 // double deadTimeNormHF = itLScal->deadTimeNormalization(); // Getting Dead Time Normalization from HF (via SCAL)
379 
380 // // If HF Dead Time Corrections is requested we apply it
381 // // NOTE: By default this is assumed false since for now WbM fits do NOT assume this correction
382 // if(m_parameters.getUntrackedParameter<bool>("useHFDeadTimeNormalization",false)){
383 
384 // // Protecting for deadtime = 0
385 // if(deadTimeNormHF==0){instLumi = 0;}
386 // else {instLumi = instLumi/deadTimeNormHF;}
387 // }
388 // // Buffering the luminosity information
389 // m_lsLuminosity[scalLS]=instLumi;
390 // }
391 // }
392 
393 // // Getting the prescale index used when this event was triggered
394 // if(gtReadoutRecordData.isValid()){
395 
396 // // If we haven't got the data from this LS yet get it
397 // if(m_lsPrescaleIndex.find(eventLS)==m_lsPrescaleIndex.end()){
398 
399 // if (m_verbose) {cout << "[L1TRate_Harvest:] Buffering Prescale Index for LS=" << eventLS << endl;}
400 
401 // // Getting Final Decision Logic (FDL) Data from GT
402 // const vector<L1GtFdlWord>& gtFdlVectorData = gtReadoutRecordData->gtFdlVector();
403 
404 // // Getting the index for the fdl data for this event
405 // int indexFDL=0;
406 // for(unsigned int i=0; i<gtFdlVectorData.size(); i++){
407 // if(gtFdlVectorData[i].bxInEvent()==0){indexFDL=i; break;}
408 // }
409 
410 // int CurrentPrescalesIndex = gtFdlVectorData[indexFDL].gtPrescaleFactorIndexAlgo();
411 // m_lsPrescaleIndex[eventLS] = CurrentPrescalesIndex;
412 // }
413 // }
414 }
415 
416 //_____________________________________________________________________
417 // function: getXSexFitsPython
418 // Imputs:
419 // * const edm::ParameterSet& ps = ParameterSet contaning the fit
420 // functions and parameters for the selected triggers
421 // Outputs:
422 // * int error = Number of algos where you did not find a
423 // corresponding fit
424 //_____________________________________________________________________
426 
427  // error meaning
428  bool noError = true;
429  cout<<"WP01"<<endl;
430  // Getting fit parameters
431  std::vector<edm::ParameterSet> m_fitParameters = ps.getParameter< vector<ParameterSet> >("fitParameters");
432  cout<<"WP02"<<endl;
433  double minInstantLuminosity = m_parameters.getParameter<double>("minInstantLuminosity");
434  double maxInstantLuminosity = m_parameters.getParameter<double>("maxInstantLuminosity");
435  cout<<"WP03"<<endl;
436  // Getting rate fit parameters for all input triggers
437  for(map<string,string>::const_iterator a=m_selectedTriggers.begin() ; a!=m_selectedTriggers.end() ; a++){
438  cout<<"WP04-1"<<endl;
439  string tTrigger = (*a).second;
440 
441  // If trigger name is defined we get the rate fit parameters
442  if(tTrigger != "Undefined"){
443  cout<<"WP04-2"<<endl;
444  bool foundFit = false;
445 
446  for(unsigned int b=0 ; b<m_fitParameters.size() ; b++){
447  cout<<"WP05-1"<<endl;
448  if(tTrigger == m_fitParameters[b].getParameter<string>("AlgoName")){
449  cout<<"WP05-2"<<endl;
450  TString tAlgoName = m_fitParameters[b].getParameter< string > ("AlgoName");
451  TString tTemplateFunction = m_fitParameters[b].getParameter< string > ("TemplateFunction");
452  vector<double> tParameters = m_fitParameters[b].getParameter< vector<double> >("Parameters");
453 
454  // Retriving and populating the m_templateFunctions array
455  m_templateFunctions[tTrigger] = new TF1("FitParametrization_"+tAlgoName,tTemplateFunction,
456  minInstantLuminosity,maxInstantLuminosity);
457  m_templateFunctions[tTrigger] ->SetParameters(&tParameters[0]);
458  m_templateFunctions[tTrigger] ->SetLineWidth(1);
459  m_templateFunctions[tTrigger] ->SetLineColor(kRed);
460 
461  foundFit = true;
462  break;
463  }
464 
465  if(!foundFit){
466  cout<<"WP05-3"<<endl;
467  noError = false;
468 
469  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_PY_MISSING_FIT);
470  eCount++;
471  m_ErrorMonitor->getTH1()->SetBinContent(WARNING_PY_MISSING_FIT,eCount);
472 
473  cout<<"WP05-4"<<endl;
474  }
475  }
476  }
477  }
478 
479  return noError;
480 
481 }
482 
483 
484 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2535
void beginRun(const edm::Run &run, const edm::EventSetup &iSetup)
void endRun(const edm::Run &run, const edm::EventSetup &iSetup)
virtual void endLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
bool getXSexFitsPython(const edm::ParameterSet &ps)
#define NULL
Definition: scimark2.h:8
DEFINE_FWK_MODULE(HiMixingModule)
void analyze(const edm::Event &e, const edm::EventSetup &c)
int iEvent
Definition: GenABIO.cc:243
virtual ~L1TRate_Harvest()
L1TRate_Harvest(const edm::ParameterSet &ps)
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
tuple cout
Definition: gather_cfg.py:121
virtual void beginLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434
Definition: Run.h:36