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 // L1TMonitor includes
3 
5 
7 
12 #include "DataFormats/Common/interface/ConditionsInEdm.h" // Parameters associated to Run, LS and Event
13 #include "DataFormats/Luminosity/interface/LumiDetails.h" // Luminosity Information
14 #include "DataFormats/Luminosity/interface/LumiSummary.h" // Luminosity Information
15 
23 
25 
26 #include "TList.h"
27 
28 using namespace edm;
29 using namespace std;
30 
31 //_____________________________________________________________________
33 
34  m_maxNbins = 2500; // Maximum LS for each run (for binning purposes)
35  m_parameters = ps;
36 
37  // Mapping parameter input variables
38  m_scalersSource = m_parameters.getParameter <InputTag>("inputTagScalersResults");
39  m_l1GtDataDaqInputTag = m_parameters.getParameter <InputTag>("inputTagL1GtDataDaq");
40  m_verbose = m_parameters.getUntrackedParameter<bool> ("verbose",false);
41  m_refPrescaleSet = m_parameters.getParameter <int> ("refPrescaleSet");
42  m_lsShiftGTRates = m_parameters.getUntrackedParameter<int> ("lsShiftGTRates",0);
43 
44  // Getting which categories to monitor
45  ParameterSet Categories = ps.getParameter<ParameterSet>("categories");
46  m_inputCategories["Mu"] = Categories.getUntrackedParameter<bool>("Mu");
47  m_inputCategories["EG"] = Categories.getUntrackedParameter<bool>("EG");
48  m_inputCategories["IsoEG"] = Categories.getUntrackedParameter<bool>("IsoEG");
49  m_inputCategories["Jet"] = Categories.getUntrackedParameter<bool>("Jet");
50  m_inputCategories["CenJet"] = Categories.getUntrackedParameter<bool>("CenJet");
51  m_inputCategories["ForJet"] = Categories.getUntrackedParameter<bool>("ForJet");
52  m_inputCategories["TauJet"] = Categories.getUntrackedParameter<bool>("TauJet");
53  m_inputCategories["ETM"] = Categories.getUntrackedParameter<bool>("ETM");
54  m_inputCategories["ETT"] = Categories.getUntrackedParameter<bool>("ETT");
55  m_inputCategories["HTT"] = Categories.getUntrackedParameter<bool>("HTT");
56  m_inputCategories["HTM"] = Categories.getUntrackedParameter<bool>("HTM");
57 
58  // Inicializing Variables
59  dbe = NULL;
60 
61  if (ps.getUntrackedParameter < bool > ("dqmStore", false)) {
62  dbe = Service < DQMStore > ().operator->();
63  dbe->setVerbose(0);
64  }
65 
66  // What to do if we want our output to be saved to a external file
67  m_outputFile = ps.getUntrackedParameter < string > ("outputFile", "");
68 
69  if (m_outputFile.size() != 0) {
70  cout << "L1T Monitoring histograms will be saved to " << m_outputFile.c_str() << endl;
71  }
72 
73  bool disable = ps.getUntrackedParameter < bool > ("disableROOToutput", false);
74  if (disable) {m_outputFile = "";}
75 
76  if (dbe != NULL) {dbe->setCurrentFolder("L1T/L1TRate");}
77 
78 }
79 
80 //_____________________________________________________________________
82 
83 //_____________________________________________________________________
85 
86  if (m_verbose) {cout << "[L1TRate_Harvest:] Called beginJob." << endl;}
87 
88  // get hold of back-end interface
89  DQMStore *dbe = 0;
90  dbe = Service < DQMStore > ().operator->();
91 
92  if (dbe) {
93  dbe->setCurrentFolder("L1T/L1TRate");
94  dbe->rmdir("L1T/L1TRate");
95  }
96 
97 }
98 
99 //_____________________________________________________________________
101 
102  if (m_verbose) {cout << "[L1TRate_Harvest:] Called endJob." << endl;}
103 
104  if (m_outputFile.size() != 0 && dbe)
105  dbe->save(m_outputFile);
106 
107  return;
108 
109 }
110 
111 //_____________________________________________________________________
112 // BeginRun: as input you get filtered events...
113 //_____________________________________________________________________
115 
116  if (m_verbose) {cout << "[L1TRate_Harvest:] Called beginRun." << endl;}
117 
118 // ESHandle<L1GtTriggerMenu> menuRcd;
119 // ESHandle<L1GtPrescaleFactors> l1GtPfAlgo;
120 
121 // iSetup.get<L1GtTriggerMenuRcd>() .get(menuRcd);
122 // iSetup.get<L1GtPrescaleFactorsAlgoTrigRcd>().get(l1GtPfAlgo);
123 
124 // const L1GtTriggerMenu* menu = menuRcd .product();
125 // const L1GtPrescaleFactors* m_l1GtPfAlgo = l1GtPfAlgo.product();
126 
127 // // Initializing DQM Monitor Elements
128 // dbe->setCurrentFolder("L1T/L1TRate");
129 // m_ErrorMonitor = dbe->book1D("ErrorMonitor", "ErrorMonitor",2,0,2);
130 // m_ErrorMonitor->setBinLabel(UNKNOWN ,"UNKNOWN");
131 // m_ErrorMonitor->setBinLabel(WARNING_PY_MISSING_FIT,"WARNING_PY_MISSING_FIT");
132 
133 // cout << "[L1TRate_Harvest:] m_ErrorMonitor: " << m_ErrorMonitor << endl;
134 
135 // // Retriving the list of prescale sets
136 // m_listsPrescaleFactors = &(m_l1GtPfAlgo->gtPrescaleFactors());
137 
138 // // Getting Lowest Prescale Single Object Triggers from the menu
139 // L1TMenuHelper myMenuHelper = L1TMenuHelper(iSetup);
140 // m_selectedTriggers = myMenuHelper.getLUSOTrigger(m_inputCategories,m_refPrescaleSet);
141 
142 // //-> Getting template fits for the algLo cross sections
143 // getXSexFitsPython(m_parameters);
144 
145 // for (CItAlgo algo = menu->gtAlgorithmMap().begin(); algo!=menu->gtAlgorithmMap().end(); ++algo){
146 // m_algoBit[(algo->second).algoAlias()] = (algo->second).algoBitNumber();
147 // }
148 
149 // double minInstantLuminosity = m_parameters.getParameter<double>("minInstantLuminosity");
150 // double maxInstantLuminosity = m_parameters.getParameter<double>("maxInstantLuminosity");
151 
152 // // Initializing DQM Monitor Elements
153 // for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
154 
155 // TString tCategory = (*i).first;
156 // TString tTrigger = (*i).second;
157 
158 // TString tErrorMessage = "";
159 // TF1* tTestFunction;
160 
161 // if(tTrigger != "Undefined" && m_templateFunctions.find(tTrigger) != m_templateFunctions.end()){
162 // tTestFunction = m_templateFunctions[tTrigger];
163 // }
164 // else if(tTrigger == "Undefined"){
165 // TString tFunc = "-1";
166 // tTestFunction = new TF1("FitParametrization_"+tTrigger,tFunc,0,double(m_maxNbins)-0.5);
167 // }
168 // else if(m_templateFunctions.find(tTrigger) == m_templateFunctions.end()){
169 // TString tFunc = "-1";
170 // tTestFunction = new TF1("FitParametrization_"+tTrigger,tFunc,0,double(m_maxNbins)-0.5);
171 // tErrorMessage = " (Undefined Test Function)";
172 // }
173 // else{
174 // TString tFunc = "-1";
175 // tTestFunction = new TF1("FitParametrization_"+tTrigger,tFunc,0,double(m_maxNbins)-0.5);
176 // }
177 
178 // if(tTrigger != "Undefined"){
179 
180 // if(myMenuHelper.getPrescaleByAlias(tCategory,tTrigger) != 1){
181 // tErrorMessage += " WARNING: Default Prescale = ";
182 // tErrorMessage += myMenuHelper.getPrescaleByAlias(tCategory,tTrigger);
183 // }
184 
185 // if (tCategory == "Mu" && myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger) != 4294967295){ //hexadecimal of the whole range
186 // tErrorMessage += " WARNING: Eta Range = ";
187 // tErrorMessage += myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger);
188 // }
189 // else if(tCategory == "EG" && myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger) != 32639){
190 // tErrorMessage += " WARNING: Eta Range = ";
191 // tErrorMessage += myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger);
192 // }
193 // else if(tCategory == "IsoEG" && myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger) != 32639){
194 // tErrorMessage += " WARNING: Eta Range = ";
195 // tErrorMessage += myMenuHelper.getEtaRangeByAlias(tCategory,tTrigger);
196 // }
197 
198 // if(tCategory == "Mu" && myMenuHelper.getQualityAlias(tCategory,tTrigger) != 240){
199 // tErrorMessage += " WARNING: Quality = ";
200 // tErrorMessage += myMenuHelper.getQualityAlias(tCategory,tTrigger);
201 // }
202 
203 // }
204 
205 // dbe->setCurrentFolder("L1T/L1TRate/TriggerCounts"); // trigger counts...
206 // m_CountsVsLS[tTrigger] = dbe->bookProfile(tCategory,
207 // "Cross Sec. vs Inst. Lumi Algo: "+tTrigger+tErrorMessage,
208 // m_maxNbins,
209 // minInstantLuminosity,
210 // maxInstantLuminosity,0,500);
211 // m_CountsVsLS[tTrigger] ->setAxisTitle("Instantaneous Luminosity [10^{30}cm^{-2}s^{-1}]" ,1);
212 // m_CountsVsLS[tTrigger] ->setAxisTitle("Algorithm #sigma [#mu b]" ,2);
213 // m_CountsVsLS[tTrigger] ->getTProfile()->GetListOfFunctions()->Add(tTestFunction);
214 // m_CountsVsLS[tTrigger] ->getTProfile()->SetMarkerStyle(23);
215 
216 // m_algoFit[tTrigger] = (TF1*) tTestFunction->Clone("Fit_"+tTrigger); // NOTE: Workaround
217 
218 // dbe->setCurrentFolder("L1T/L1TRate/Ratio");
219 // m_xSecObservedToExpected[tTrigger] = dbe->book1D(tCategory, "Algo: "+tTrigger+tErrorMessage,m_maxNbins,-0.5,double(m_maxNbins)-0.5);
220 // m_xSecObservedToExpected[tTrigger] ->setAxisTitle("Lumi Section" ,1);
221 // m_xSecObservedToExpected[tTrigger] ->setAxisTitle("#sigma_{obs} / #sigma_{exp}" ,2);
222 
223 
224 // }
225 
226 }
227 
228 
229 //_____________________________________________________________________
231 
232  if (m_verbose) {cout << "[L1TRate_Harvest:] Called endRun." << endl;}
233 }
234 
235 
236 
237 
238 //_____________________________________________________________________
240 
241 // if (m_verbose) {cout << "[L1TRate_Harvest:] Called beginLuminosityBlock at LS=" << lumiBlock.id().luminosityBlock() << endl;}
242 
243 }
244 
245 //_____________________________________________________________________
247 
248 // int eventLS = lumiBlock.id().luminosityBlock();
249 // if (m_verbose) {cout << "[L1TRate_Harvest:] Called endLuminosityBlock at LS=" << eventLS << endl;}
250 
251 // // We can certify LS -1 since we should have available:
252 // // gt rates: (current LS)-1
253 // // prescale: current LS
254 // // lumi : current LS
255 // //eventLS--;
256 
257 // // Checking if all necessary quantities are defined for our calculations
258 // //bool isDefRate,isDefLumi,isDefPrescaleIndex;
259 // bool isDefLumi,isDefPrescaleIndex;
260 // //map<TString,double>* rates=0;
261 // double lumi=0;
262 // int prescalesIndex=0;
263 
264 // bool isDefCount;
265 // map<TString,double>* counts=0;
266 
267 // // Resetting MonitorElements so we can refill them
268 // for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
269 // string tTrigger = (*i).second;
270 // m_CountsVsLS [tTrigger]->getTH1()->Reset("ICE");
271 // m_xSecObservedToExpected[tTrigger]->getTH1()->Reset("ICE");
272 
273 // }
274 
275 // //Trying to do the same with Counts....
276 // for(map<int,map<TString,double> >::iterator j=m_lsRates.begin() ; j!=m_lsRates.end() ; j++){
277 
278 // unsigned int lsOffline = (*j).first;
279 // counts = &(*j).second;
280 // isDefCount=true;
281 
282 // unsigned int lsPreInd;
283 
284 // if(m_lsLuminosity.find(lsOffline)==m_lsLuminosity.end()){isDefLumi=false;}
285 // else{
286 // isDefLumi=true;
287 // lumi=m_lsLuminosity[lsOffline];
288 // }
289 
290 // lsPreInd = lsOffline + 1; // NOTE: Workaround
291 
292 // if(m_lsPrescaleIndex.find(lsPreInd)==m_lsPrescaleIndex.end()){isDefPrescaleIndex=false;}
293 // else{
294 // isDefPrescaleIndex=true;
295 // prescalesIndex=m_lsPrescaleIndex[lsPreInd];
296 // }
297 
298 // if(isDefCount && isDefLumi && isDefPrescaleIndex){
299 
300 // //const vector<int>& currentPrescaleFactors = (*m_listsPrescaleFactors).at(prescalesIndex);
301 
302 // for(map<string,string>::const_iterator j=m_selectedTriggers.begin() ; j!=m_selectedTriggers.end() ; j++){
303 
304 // string tTrigger = (*j).second;
305 // double trigCount = (*counts)[tTrigger];
306 
307 // // TF1* tTestFunction = (TF1*) m_CountsVsLS[tTrigger]->getTProfile()->GetListOfFunctions()->First();
308 // TF1* tTestFunction = m_algoFit[tTrigger]; // NOTE: Workaround....
309 
310 
311 // // If trigger name is defined we get the rate fit parameters
312 // if(tTrigger != "Undefined"){
313 
314 
315 // if(lumi!=0 && trigCount!=0 && prescalesIndex!=0){
316 
317 // double AlgoXSec = (prescalesIndex*trigCount)/lumi;
318 // double TemplateFunctionValue = tTestFunction->Eval(lumi);
319 
320 // // Checking against Template function
321 // m_CountsVsLS [tTrigger]->Fill(lumi,AlgoXSec);
322 
323 // int ibin = m_xSecObservedToExpected[tTrigger]->getTH1()->FindBin(lsOffline);
324 // m_xSecObservedToExpected[tTrigger]->setBinContent(ibin,AlgoXSec/TemplateFunctionValue);
325 
326 // }
327 // else {
328 // m_CountsVsLS [tTrigger]->Fill(0.000001,0.000001);
329 
330 // int ibin = m_xSecObservedToExpected[tTrigger]->getTH1()->FindBin(lsOffline);
331 // m_xSecObservedToExpected[tTrigger]->setBinContent(ibin,0.000001);
332 // }
333 // }
334 // }
335 // }
336 // }
337 }
338 
339 
340 
341 //_____________________________________________________________________
342 //void L1TRate_Harvest::analyze(const Event & iEvent, const EventSetup & eventSetup){
343 //
344 //}
345 
346 
347 //_____________________________________________________________________
348 // function: getXSexFitsPython
349 // Imputs:
350 // * const edm::ParameterSet& ps = ParameterSet contaning the fit
351 // functions and parameters for the selected triggers
352 // Outputs:
353 // * int error = Number of algos where you did not find a
354 // corresponding fit
355 //_____________________________________________________________________
357 
358  // error meaning
359  bool noError = true;
360 
361  // Getting fit parameters
362  std::vector<edm::ParameterSet> m_fitParameters = ps.getParameter< vector<ParameterSet> >("fitParameters");
363 
364  double minInstantLuminosity = m_parameters.getParameter<double>("minInstantLuminosity");
365  double maxInstantLuminosity = m_parameters.getParameter<double>("maxInstantLuminosity");
366 
367  // Getting rate fit parameters for all input triggers
368  for(map<string,string>::const_iterator a=m_selectedTriggers.begin() ; a!=m_selectedTriggers.end() ; a++){
369 
370  string tTrigger = (*a).second;
371 
372  // If trigger name is defined we get the rate fit parameters
373  if(tTrigger != "Undefined"){
374 
375  bool foundFit = false;
376 
377  for(unsigned int b=0 ; b<m_fitParameters.size() ; b++){
378 
379  if(tTrigger == m_fitParameters[b].getParameter<string>("AlgoName")){
380 
381  TString tAlgoName = m_fitParameters[b].getParameter< string > ("AlgoName");
382  TString tTemplateFunction = m_fitParameters[b].getParameter< string > ("TemplateFunction");
383  vector<double> tParameters = m_fitParameters[b].getParameter< vector<double> >("Parameters");
384 
385  // Retriving and populating the m_templateFunctions array
386  m_templateFunctions[tTrigger] = new TF1("FitParametrization_"+tAlgoName,tTemplateFunction,
387  minInstantLuminosity,maxInstantLuminosity);
388  m_templateFunctions[tTrigger] ->SetParameters(&tParameters[0]);
389  m_templateFunctions[tTrigger] ->SetLineWidth(1);
390  m_templateFunctions[tTrigger] ->SetLineColor(kRed);
391 
392  foundFit = true;
393  break;
394  }
395 
396  if(!foundFit){
397 
398  noError = false;
399 
400  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_PY_MISSING_FIT);
401  eCount++;
402  m_ErrorMonitor->getTH1()->SetBinContent(WARNING_PY_MISSING_FIT,eCount);
403 
404  }
405  }
406  }
407  }
408 
409  return noError;
410 
411 }
412 
413 
414 //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:3101
void beginRun(const edm::Run &run, const edm::EventSetup &iSetup)
void endRun(const edm::Run &run, const edm::EventSetup &iSetup)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void endLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
bool getXSexFitsPython(const edm::ParameterSet &ps)
#define NULL
Definition: scimark2.h:8
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:667
Definition: Run.h:41