CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TSync.cc
Go to the documentation of this file.
1 /*
2  * \file L1TSync.cc
3  *
4  * $Date: 2011/11/15 10:41:01 $
5  * $Revision: 1.10 $
6  * \author J. Pela, P. Musella
7  *
8  */
9 
10 //
12 
14 
18 
21 
22 #include "DataFormats/Common/interface/ConditionsInEdm.h" // Parameters associated to Run, LS and Event
23 
30 
31 // Luminosity Information
32 //#include "DataFormats/Luminosity/interface/LumiDetails.h"
33 //#include "DataFormats/Luminosity/interface/LumiSummary.h"
34 
35 // L1TMonitor includes
37 
38 #include "TList.h"
39 
40 using namespace edm;
41 using namespace std;
42 
43 //-------------------------------------------------------------------------------------
44 //-------------------------------------------------------------------------------------
46 
47  m_parameters = pset;
48 
49  // Mapping parameter input variables
50  m_scalersSource = pset.getParameter <InputTag>("inputTagScalersResults");
51  m_l1GtDataDaqInputTag = pset.getParameter <InputTag>("inputTagL1GtDataDaq");
52  m_l1GtEvmSource = pset.getParameter <InputTag>("inputTagtEvmSource");
53  m_verbose = pset.getUntrackedParameter<bool> ("verbose",false);
54  m_refPrescaleSet = pset.getParameter <int> ("refPrescaleSet");
55 
56  // Getting which categories to monitor
57  ParameterSet Categories = pset.getParameter< ParameterSet >("Categories");
58 
59  bool forceGlobalParameters = Categories.getParameter<bool>("forceGlobalParameters");
60  bool doGlobalAutoSelection = Categories.getParameter<bool>("doGlobalAutoSelection");
61 
62  ParameterSet CatBPTX = Categories.getParameter<ParameterSet>("BPTX");
63  ParameterSet CatMu = Categories.getParameter<ParameterSet>("Mu");
64  ParameterSet CatEG = Categories.getParameter<ParameterSet>("EG");
65  ParameterSet CatIsoEG = Categories.getParameter<ParameterSet>("IsoEG");
66  ParameterSet CatJet = Categories.getParameter<ParameterSet>("Jet");
67  ParameterSet CatCenJet = Categories.getParameter<ParameterSet>("CenJet");
68  ParameterSet CatForJet = Categories.getParameter<ParameterSet>("ForJet");
69  ParameterSet CatTauJet = Categories.getParameter<ParameterSet>("TauJet");
70  ParameterSet CatETM = Categories.getParameter<ParameterSet>("ETT");
71  ParameterSet CatETT = Categories.getParameter<ParameterSet>("ETM");
72  ParameterSet CatHTT = Categories.getParameter<ParameterSet>("HTT");
73  ParameterSet CatHTM = Categories.getParameter<ParameterSet>("HTM");
74 
75  // --> Setting parameters related to which algos to monitor
76  // If global parameters are forced they take precedence over algo-by-algo parameters
77  if(forceGlobalParameters){
78 
79  // If global automatic selection if enable all categories set to be monitored will have
80  // their algos auto selected (the lowest prescale algo will be selected)
81  if(doGlobalAutoSelection){
82 
83  if(CatMu .getParameter<bool>("monitor")){m_algoAutoSelect["Mu"] = true;}else{m_algoAutoSelect["Mu"] = false;}
84  if(CatEG .getParameter<bool>("monitor")){m_algoAutoSelect["EG"] = true;}else{m_algoAutoSelect["EG"] = false;}
85  if(CatIsoEG .getParameter<bool>("monitor")){m_algoAutoSelect["IsoEG"] = true;}else{m_algoAutoSelect["IsoEG"] = false;}
86  if(CatJet .getParameter<bool>("monitor")){m_algoAutoSelect["Jet"] = true;}else{m_algoAutoSelect["Jet"] = false;}
87  if(CatCenJet.getParameter<bool>("monitor")){m_algoAutoSelect["CenJet"] = true;}else{m_algoAutoSelect["CenJet"] = false;}
88  if(CatForJet.getParameter<bool>("monitor")){m_algoAutoSelect["ForJet"] = true;}else{m_algoAutoSelect["ForJet"] = false;}
89  if(CatTauJet.getParameter<bool>("monitor")){m_algoAutoSelect["TauJet"] = true;}else{m_algoAutoSelect["TauJet"] = false;}
90  if(CatETM .getParameter<bool>("monitor")){m_algoAutoSelect["ETM"] = true;}else{m_algoAutoSelect["ETM"] = false;}
91  if(CatETT .getParameter<bool>("monitor")){m_algoAutoSelect["ETT"] = true;}else{m_algoAutoSelect["ETT"] = false;}
92  if(CatHTM .getParameter<bool>("monitor")){m_algoAutoSelect["HTM"] = true;}else{m_algoAutoSelect["HTM"] = false;}
93  if(CatHTT .getParameter<bool>("monitor")){m_algoAutoSelect["HTT"] = true;}else{m_algoAutoSelect["HTT"] = false;}
94 
95  // If global non-automatic selection is enable all categories set to be monitored will use
96  // user defined algos
97  }else{
98 
99  m_algoAutoSelect["Mu"] = false;
100  m_algoAutoSelect["EG"] = false;
101  m_algoAutoSelect["IsoEG"] = false;
102  m_algoAutoSelect["Jet"] = false;
103  m_algoAutoSelect["CenJet"] = false;
104  m_algoAutoSelect["ForJet"] = false;
105  m_algoAutoSelect["TauJet"] = false;
106  m_algoAutoSelect["ETM"] = false;
107  m_algoAutoSelect["ETT"] = false;
108  m_algoAutoSelect["HTM"] = false;
109  m_algoAutoSelect["HTT"] = false;
110 
111  if(CatMu .getParameter<bool>("monitor")){m_selectedTriggers["Mu"] = CatMu .getParameter<string>("algo");}
112  if(CatEG .getParameter<bool>("monitor")){m_selectedTriggers["EG"] = CatEG .getParameter<string>("algo");}
113  if(CatIsoEG .getParameter<bool>("monitor")){m_selectedTriggers["IsoEG"] = CatIsoEG .getParameter<string>("algo");}
114  if(CatJet .getParameter<bool>("monitor")){m_selectedTriggers["Jet"] = CatJet .getParameter<string>("algo");}
115  if(CatCenJet.getParameter<bool>("monitor")){m_selectedTriggers["CenJet"] = CatCenJet.getParameter<string>("algo");}
116  if(CatForJet.getParameter<bool>("monitor")){m_selectedTriggers["CatForJet"] = CatForJet.getParameter<string>("algo");}
117  if(CatTauJet.getParameter<bool>("monitor")){m_selectedTriggers["TauJet"] = CatTauJet.getParameter<string>("algo");}
118  if(CatETM .getParameter<bool>("monitor")){m_selectedTriggers["ETM"] = CatETM .getParameter<string>("algo");}
119  if(CatETT .getParameter<bool>("monitor")){m_selectedTriggers["ETT"] = CatETT .getParameter<string>("algo");}
120  if(CatHTM .getParameter<bool>("monitor")){m_selectedTriggers["HTM"] = CatHTM .getParameter<string>("algo");}
121  if(CatHTT .getParameter<bool>("monitor")){m_selectedTriggers["HTT"] = CatHTT .getParameter<string>("algo");}
122 
123  }
124 
125  // If we are using algo-by-algo parametes we get them and set what is needed
126  }else{
127 
128  if(CatBPTX.getParameter<bool>("monitor")){
129  m_selectedTriggers["BPTX"] = CatBPTX.getParameter<string>("algo");
130  }
131 
132  if(CatMu.getParameter<bool>("monitor")){
133  m_algoAutoSelect["Mu"] = CatMu.getParameter<bool>("doAutoSelection");
134  if(!m_algoAutoSelect["Mu"]){m_selectedTriggers["Mu"] = CatMu.getParameter<string>("algo");}
135  }else{m_algoAutoSelect["Mu"] = false;}
136 
137  if(CatEG.getParameter<bool>("monitor")){
138  m_algoAutoSelect["EG"] = CatEG.getParameter<bool>("doAutoSelection");
139  if(!m_algoAutoSelect["EG"]){m_selectedTriggers["EG"] = CatEG.getParameter<string>("algo");}
140  }else{m_algoAutoSelect["EG"] = false;}
141 
142  if(CatIsoEG.getParameter<bool>("monitor")){
143  m_algoAutoSelect["IsoEG"] = CatIsoEG.getParameter<bool>("doAutoSelection");
144  if(!m_algoAutoSelect["IsoEG"]){m_selectedTriggers["IsoEG"] = CatIsoEG.getParameter<string>("algo");}
145  }else{m_algoAutoSelect["IsoEG"] = false;}
146 
147  if(CatJet.getParameter<bool>("monitor")){
148  m_algoAutoSelect["Jet"] = CatJet.getParameter<bool>("doAutoSelection");
149  if(!m_algoAutoSelect["Jet"]){m_selectedTriggers["Jet"] = CatJet.getParameter<string>("algo");}
150  }else{m_algoAutoSelect["Jet"] = false;}
151 
152  if(CatCenJet.getParameter<bool>("monitor")){
153  m_algoAutoSelect["CenJet"] = CatCenJet.getParameter<bool>("doAutoSelection");
154  if(!m_algoAutoSelect["CenJet"]){m_selectedTriggers["CenJet"] = CatCenJet.getParameter<string>("algo");}
155  }else{m_algoAutoSelect["CenJet"] = false;}
156 
157  if(CatForJet.getParameter<bool>("monitor")){
158  m_algoAutoSelect["CatForJet"] = CatForJet.getParameter<bool>("doAutoSelection");
159  if(!m_algoAutoSelect["CatForJet"]){m_selectedTriggers["CatForJet"] = CatForJet.getParameter<string>("algo");}
160  }else{m_algoAutoSelect["CatForJet"] = false;}
161 
162  if(CatTauJet.getParameter<bool>("monitor")){
163  m_algoAutoSelect["TauJet"] = CatTauJet.getParameter<bool>("doAutoSelection");
164  if(!m_algoAutoSelect["TauJet"]){m_selectedTriggers["TauJet"] = CatTauJet.getParameter<string>("algo");}
165  }else{m_algoAutoSelect["TauJet"] = false;}
166 
167  if(CatETM.getParameter<bool>("monitor")){
168  m_algoAutoSelect["ETM"] = CatETM.getParameter<bool>("doAutoSelection");
169  if(!m_algoAutoSelect["ETM"]){m_selectedTriggers["ETM"] = CatETM.getParameter<string>("algo");}
170  }else{m_algoAutoSelect["ETM"] = false;}
171 
172  if(CatETT.getParameter<bool>("monitor")){
173  m_algoAutoSelect["ETT"] = CatETT.getParameter<bool>("doAutoSelection");
174  if(!m_algoAutoSelect["ETT"]){m_selectedTriggers["ETT"] = CatETT.getParameter<string>("algo");}
175  }else{m_algoAutoSelect["ETT"] = false;}
176 
177  if(CatHTM.getParameter<bool>("monitor")){
178  m_algoAutoSelect["HTM"] = CatHTM.getParameter<bool>("doAutoSelection");
179  if(!m_algoAutoSelect["HTM"]){m_selectedTriggers["HTM"] = CatHTM.getParameter<string>("algo");}
180  }else{m_algoAutoSelect["HTM"] = false;}
181 
182  if(CatHTT.getParameter<bool>("monitor")){
183  m_algoAutoSelect["HTT"] = CatHTT.getParameter<bool>("doAutoSelection");
184  if(!m_algoAutoSelect["HTT"]){m_selectedTriggers["HTT"] = CatHTT.getParameter<string>("algo");}
185  }else{m_algoAutoSelect["HTT"] = false;}
186 
187  }
188 
189 
190  if (pset.getUntrackedParameter < bool > ("dqmStore", false)) {
191  dbe = Service < DQMStore > ().operator->();
192  dbe->setVerbose(0);
193  }
194 
195  m_outputFile = pset.getUntrackedParameter < std::string > ("outputFile","");
196 
197  if (m_outputFile.size() != 0) {
198  std::cout << "L1T Monitoring histograms will be saved to " << m_outputFile.c_str() << std::endl;
199  }
200 
201  bool disable = pset.getUntrackedParameter < bool > ("disableROOToutput", false);
202  if (disable) {m_outputFile = "";}
203 
204  if (dbe != NULL) {dbe->setCurrentFolder("L1T/L1TSync");}
205 
206 }
207 
208 //-------------------------------------------------------------------------------------
209 //-------------------------------------------------------------------------------------
211 
212 //-------------------------------------------------------------------------------------
213 //-------------------------------------------------------------------------------------
214 void L1TSync::beginJob(void){
215 
216  if (m_verbose){cout << "[L1TSync] Called beginJob." << endl;}
217 
218  // get hold of back-end interface
219  DQMStore *dbe = 0;
220  dbe = Service < DQMStore > ().operator->();
221 
222  if (dbe) {
223  dbe->setCurrentFolder("L1T/L1TSync");
224  dbe->rmdir("L1T/L1TSync");
225  }
226 
227 }
228 
229 //-------------------------------------------------------------------------------------
230 //-------------------------------------------------------------------------------------
231 void L1TSync::endJob(void){
232 
233  if (m_verbose){cout << "[L1TSync] Called endJob." << endl;}
234 
235  if (m_outputFile.size() != 0 && dbe)
236  dbe->save(m_outputFile);
237 
238  return;
239 
240 }
241 
242 //-------------------------------------------------------------------------------------
244 //-------------------------------------------------------------------------------------
245 void L1TSync::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup){
246 
247  if (m_verbose){cout << "[L1TSync] Called beginRun." << endl;}
248 
249  // Initializing variables
250  int maxNbins = 2501;
251 
252  // Reseting run dependent variables
253  m_lhcFill = 0;
254  m_currentLS = 0;
255  m_certFirstLS.clear();
256  m_certLastLS .clear();
257 
258  // Getting Trigger menu from GT
260  iSetup.get<L1GtTriggerMenuRcd>().get(menuRcd);
261  const L1GtTriggerMenu* menu = menuRcd.product();
262 
263  // Filling Alias-Bit Map
264  for (CItAlgo algo = menu->gtAlgorithmAliasMap().begin(); algo!=menu->gtAlgorithmAliasMap().end(); ++algo){
265  m_algoBit[(algo->second).algoAlias()] = (algo->second).algoBitNumber();
266  }
267 
268  // Getting fill number for this run
269  //Handle<ConditionsInRunBlock> runConditions;
270  //iRun.getByType(runConditions);
271  //int lhcFillNumber = runConditions->lhcFillNumber;
272  //
273  //ESHandle<L1GtPrescaleFactors> l1GtPfAlgo;
274  //iSetup.get<L1GtPrescaleFactorsAlgoTrigRcd>().get(l1GtPfAlgo);
275  //const L1GtPrescaleFactors* m_l1GtPfAlgo = l1GtPfAlgo.product();
276 
277  L1TMenuHelper myMenuHelper = L1TMenuHelper(iSetup);
278 
279  m_selectedTriggers = myMenuHelper.testAlgos(m_selectedTriggers);
280 
281  map<string,string> tAutoSelTrig = myMenuHelper.getLUSOTrigger(m_algoAutoSelect,m_refPrescaleSet);
282  m_selectedTriggers.insert(tAutoSelTrig.begin(),tAutoSelTrig.end());
283 
284  // Initializing DQM Monitor Elements
285  dbe->setCurrentFolder("L1T/L1TSync");
286  m_ErrorMonitor = dbe->book1D("ErrorMonitor","ErrorMonitor",7,0,7);
287  m_ErrorMonitor->setBinLabel(UNKNOWN ,"UNKNOWN");
288  m_ErrorMonitor->setBinLabel(WARNING_DB_CONN_FAILED ,"WARNING_DB_CONN_FAILED"); // Errors from L1TOMDSHelper
289  m_ErrorMonitor->setBinLabel(WARNING_DB_QUERY_FAILED ,"WARNING_DB_QUERY_FAILED"); // Errors from L1TOMDSHelper
290  m_ErrorMonitor->setBinLabel(WARNING_DB_INCORRECT_NBUNCHES,"WARNING_DB_INCORRECT_NBUNCHES"); // Errors from L1TOMDSHelper
291  m_ErrorMonitor->setBinLabel(ERROR_UNABLE_RETRIVE_PRODUCT ,"ERROR_UNABLE_RETRIVE_PRODUCT");
292  m_ErrorMonitor->setBinLabel(ERROR_TRIGGERALIAS_NOTVALID ,"ERROR_TRIGGERALIAS_NOTVALID");
293  m_ErrorMonitor->setBinLabel(ERROR_LSBLOCK_NOTVALID ,"ERROR_LSBLOCK_NOTVALID");
294 
295  // Looping over selected triggers
296  for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
297 
298  string tCategory = (*i).first;
299  string tTrigger = (*i).second;
300 
301  // Initializing LS blocks for certification
302  m_certFirstLS[(*i).second] = 0;
303  m_certLastLS [(*i).second] = 0;
304 
305  // Initializing DQM Monitors
306  dbe->setCurrentFolder("L1T/L1TSync/AlgoVsBunchStructure/");
307  m_algoVsBunchStructure[tTrigger] = dbe->book2D(tCategory,"min #Delta("+tTrigger+",Bunch)",maxNbins,-0.5,double(maxNbins)-0.5,5,-2.5,2.5);
308  m_algoVsBunchStructure[tTrigger] ->setAxisTitle("Lumi Section" ,1);
309 
310  dbe->setCurrentFolder("L1T/L1TSync/Certification/");
311  m_algoCertification[tTrigger] = dbe->book1D(tCategory, "fraction of in sync: "+tTrigger,maxNbins,-0.5,double(maxNbins)-0.5);
312  m_algoCertification[tTrigger] ->setAxisTitle("Lumi Section" ,1);
313 
314  }
315 
316 }
317 
318 //_____________________________________________________________________
319 // Function: beginLuminosityBlock
320 //_____________________________________________________________________
322 
323  if (m_verbose){cout << "[L1TSync] Called beginLuminosityBlock." << endl;}
324 
325  // If this LS is not the next to last one force closing of current LS blocks
326  // for certification
327  if(m_currentLS !=0 && m_currentLS+1 != lumiBlock.id().luminosityBlock()){
328 
329  if (m_verbose){
330  cout << "[L1TSync] None consecutive: doFractionInSync() - LAST="
331  << m_currentLS << " CURRENT=" << lumiBlock.id().luminosityBlock() << endl;
332  }
333 
334  doFractionInSync(true,false);
335 
336  }
337 
338  // Updating current LS number
339  m_currentLS = lumiBlock.id().luminosityBlock();
340 
341  // If this is the fist valid LS update first LS for certification
342  for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
343 
344  string theTriggerAlias = (*i).second;
345  if(m_certFirstLS[theTriggerAlias]==0){m_certFirstLS[theTriggerAlias] = m_currentLS;}
346 
347  }
348 
349  // A LS will be valid if:
350  // * BeamMode == STABLE for all events monitored
351  m_currentLSValid = true;
352 
353 }
354 
355 //_____________________________________________________________________
356 // Function: endLuminosityBlock
357 // * Fills LS by LS ration of trigger out of sync
358 //_____________________________________________________________________
359 void L1TSync::endLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) {
360 
361  if(m_verbose){cout << "[L1TSync] Called endLuminosityBlock." << endl;}
362 
363  if(m_verbose){
364  cout << "[L1TSync] m_currentLSValid : " << m_currentLSValid << endl;
365  cout << "[L1TSync] m_beamConfig.isValid(): " << m_beamConfig.isValid() << endl;
366  }
367 
368  for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
369 
370  // Update last LS for certification
371  string theTriggerAlias = (*i).second;
372  m_certLastLS[theTriggerAlias] = m_currentLS;
373 
374  }
375 
376  // If this LS is valid (i.e. all events recorded with stable beams)
377  if(m_currentLSValid && m_beamConfig.isValid()){
378 
379  if(m_verbose){cout << "[L1TSync] Regular call: doFractionInSync()" << endl;}
380  doFractionInSync(false,false);
381 
382  }
383  // If this LS is not valid it can be in the following context:
384  // * We still hadn't stable beam (no need to certify nothing
385  // * Beam just got unstable or dumped (we may have a complete block of data do certify)
386  else{
387 
388  //-> First we close all blocks from certFirstLS[] to m_currentLS-1
389  for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
390 
391  string theTriggerAlias = (*i).second;
392 
393  int fLs = m_certFirstLS[theTriggerAlias];
394  int lLS = m_certLastLS [theTriggerAlias];
395 
396  // If this is a single LS block we do nothing (in this step)
397  if(fLs == lLS){
398  m_certFirstLS[theTriggerAlias] = 0;
399  m_certLastLS [theTriggerAlias] = 0;
400  }
401  // If block is multi LS then we remove the current LS
402  else{
403  m_certLastLS [theTriggerAlias] = m_currentLS-1;
404  }
405 
406  }
407  doFractionInSync(true,false);
408 
409  //-> Second we mark this single LS bad for all triggers
410  for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
411  string theTriggerAlias = (*i).second;
412  m_certFirstLS[theTriggerAlias] = m_currentLS;
413  m_certLastLS [theTriggerAlias] = m_currentLS;
414  }
415  doFractionInSync(true,true);
416 
417  if(m_verbose){cout << "[L1TSync] Error call: doFractionInSync()" << endl;}
418 
419  }
420 
421 }
422 
423 //_____________________________________________________________________
424 void L1TSync::endRun(const edm::Run& run, const edm::EventSetup& iSetup){
425 
426  if(m_verbose){cout << "[L1TSync] Called endRun." << endl;}
427 
428  // When the run end for closing of the LS certification blocks and evaluation
429  // of synchronization for that block
430  doFractionInSync(true,false);
431 
432 }
433 
434 //_____________________________________________________________________
435 void L1TSync::analyze(const Event & iEvent, const EventSetup & eventSetup){
436 
437  if(m_verbose){cout << "[L1TSync] Called analyze." << endl;}
438 
439  // We only start analyzing if current LS is still valid
440  if(m_currentLSValid){
441 
442  if(m_verbose){cout << "[L1TSync] -> m_currentLSValid=" << m_currentLSValid << endl;}
443 
444  // Retriving information from GT
446  iEvent.getByLabel(m_l1GtEvmSource, gtEvmReadoutRecord);
447 
448  // Determining beam mode and fill number
449  if(gtEvmReadoutRecord.isValid()){
450 
451  const L1GtfeExtWord& gtfeEvmWord = gtEvmReadoutRecord->gtfeWord();
452  unsigned int lhcBeamMode = gtfeEvmWord.beamMode(); // Updating beam mode
453 
454  if(m_lhcFill == 0){
455  m_lhcFill = gtfeEvmWord.lhcFillNumber(); // Getting LHC Fill Number from GT
456  getBeamConfOMDS(); // Getting Beam Configuration from OMDS
457  }
458 
459  if(lhcBeamMode != STABLE){m_currentLSValid = false;} // If Beams are not stable we invalidate this LS
460 
461  }else{
462  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT);
463  eCount++;
464  m_ErrorMonitor->getTH1()->SetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT,eCount);
465  }
466  }else{
467  if(m_verbose){cout << "[L1TSync] -> m_currentLSValid=" << m_currentLSValid << endl;}
468  }
469 
470  //------------------------------------------------------------------------------
471  // If current LS is valid and Beam Configuration is Valid we analyse this event
472  //------------------------------------------------------------------------------
473  if(m_currentLSValid && m_beamConfig.isValid()){
474 
475  // Getting Final Decision Logic (FDL) Data from GT
476  edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecordData;
477  iEvent.getByLabel(m_l1GtDataDaqInputTag, gtReadoutRecordData);
478 
479  if(gtReadoutRecordData.isValid()){
480 
481  const vector<L1GtFdlWord>& gtFdlVectorData = gtReadoutRecordData->gtFdlVector();
482 
483  // Running over selected triggers
484  for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
485 
486  string tTrigger = (*i).second;
487 
488  // Analyse only defined triggers
489  if(tTrigger != "Undefined" && tTrigger != "Undefined (Wrong Name)"){
490 
491  bool beamSingleConfig = false; // Single beam configured for this event
492  bool firedAlgo = false; // Algo fired in this event
493  int eventBx = -1;
494 
495  // Running over FDL results to get which bits fired
496  for(unsigned int a=0 ; a<gtFdlVectorData.size() ; a++){
497 
498  // Selecting the FDL that triggered
499  if(gtFdlVectorData[a].bxInEvent() == 0){
500  eventBx = gtFdlVectorData[a].localBxNr();
501  if(gtFdlVectorData[a].gtDecisionWord()[ m_algoBit[tTrigger] ]){firedAlgo = true;}
502  }
503  }
504 
505  // Checking beam configuration
506  if( m_beamConfig.beam1[eventBx] && !m_beamConfig.beam2[eventBx]){beamSingleConfig = true;}
507  if(!m_beamConfig.beam1[eventBx] && m_beamConfig.beam2[eventBx]){beamSingleConfig = true;}
508 
509  // Analyse only if this trigger fired in this event
510  // NOTE: Veto cases where a single beam is configured since
511  // for this cases this could be a real-satelite bunch collision
512  // -> Calculate the minimum bx diference between this event and a configured bx
513  if(firedAlgo && !beamSingleConfig){
514 
515  int DifAlgoVsBunchStructure = 9999; // Majorated
516 
517  for(unsigned int a=0 ; a<gtFdlVectorData.size() ; a++){
518 
519  int bxFDL = gtFdlVectorData[a].localBxNr();
520  int bxInEvent = gtFdlVectorData[a].bxInEvent();
521 
522  if(m_beamConfig.bxConfig(bxFDL) && abs(bxInEvent)<abs(DifAlgoVsBunchStructure)){
523  DifAlgoVsBunchStructure = -1*bxInEvent;
524  }
525  }
526 
527  m_algoVsBunchStructure[tTrigger]->Fill(m_currentLS,DifAlgoVsBunchStructure);
528 
529  }
530  }
531  }
532  }
533  else{
534  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT);
535  eCount++;
536  m_ErrorMonitor->getTH1()->SetBinContent(ERROR_UNABLE_RETRIVE_PRODUCT,eCount);
537  }
538 
539  }
540 }
541 
542 //_____________________________________________________________________
543 // Method: getBunchStructureOMDS
544 // Description: Attempt to retrive Beam Configuration from OMDS and if
545 // we find error handle it
546 //_____________________________________________________________________
548 
549  //Getting connection paremeters
550  string oracleDB = m_parameters.getParameter<string>("oracleDB");
551  string pathCondDB = m_parameters.getParameter<string>("pathCondDB");
552 
553  // Connecting to OMDS
554  L1TOMDSHelper myOMDSHelper = L1TOMDSHelper();
555  int conError;
556  myOMDSHelper.connect(oracleDB,pathCondDB,conError);
557 
558  if(conError == L1TOMDSHelper::NO_ERROR){
559 
560  int errorRetrive;
561  m_beamConfig = myOMDSHelper.getBeamConfiguration(m_lhcFill,errorRetrive);
562 
564  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_INCORRECT_NBUNCHES);
565  eCount++;
566  m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_INCORRECT_NBUNCHES,eCount);
567  }
568  else if(conError == L1TOMDSHelper::WARNING_DB_QUERY_FAILED){
569  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_QUERY_FAILED);
570  eCount++;
571  m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_QUERY_FAILED,eCount);
572  }
573  else{
574  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(UNKNOWN);
575  eCount++;
576  m_ErrorMonitor->getTH1()->SetBinContent(UNKNOWN,eCount);
577  }
578 
579  }else{
580 
582  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_DB_CONN_FAILED);
583  eCount++;
584  m_ErrorMonitor->getTH1()->SetBinContent(WARNING_DB_CONN_FAILED,eCount);
585  }else{
586  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(UNKNOWN);
587  eCount++;
588  m_ErrorMonitor->getTH1()->SetBinContent(UNKNOWN,eCount);
589  }
590 
591  }
592 
593 }
594 
595 //_____________________________________________________________________
596 // Method: doFractionInSync
597 // Description: Produce plot with the fraction of in sync trigger for
598 // LS blocks with enough statistics.
599 // Variable: iForce - Forces closing of all blocks and calculation of
600 // the respective fractions
601 // Variable: iBad - (Only works with iForce=true) Forces the current
602 // all current blocks to be marked as bad
603 //_____________________________________________________________________
604 void L1TSync::doFractionInSync(bool iForce,bool iBad){
605 
606  for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
607 
608  string theCategory = (*i).first;
609  string theTriggerAlias = (*i).second;
610 
611  // Caching frequently used values from maps
612  unsigned int fLS = m_certFirstLS[theTriggerAlias];
613  unsigned int lLS = m_certLastLS [theTriggerAlias];
614 
615  // Checking validity of the trigger alias and of the LS block
616  bool triggerAlias_isValid = theTriggerAlias != "Undefined" && theTriggerAlias != "Undefined (Wrong Name)";
617  bool lsBlock_exists = !(fLS == 0 && lLS == 0);
618  bool lsBlock_isValid = fLS <= lLS && fLS > 0 && lLS > 0;
619 
620  if(triggerAlias_isValid && lsBlock_exists && lsBlock_isValid){
621 
622  // If we are forced to close blocks and mark them bad
623  if(iForce && iBad){
624  certifyLSBlock(theTriggerAlias,fLS,lLS,-1);
625  m_certFirstLS[theTriggerAlias] = 0;
626  m_certLastLS [theTriggerAlias] = 0;
627  }
628 
629  // If we are not forced to mark bad, we check if we have enough statistics
630  else{
631 
632  // Getting events with 0 bx difference between BPTX and Algo for current LS
633  double CountSync = 0;
634  double CountAll = 0;
635 
636  // Adding all entries for current LS block
637  for(unsigned int ls=fLS ; ls<=lLS ; ls++){
638 
639  CountSync += m_algoVsBunchStructure[theTriggerAlias]->getBinContent(ls+1,3);
640  for(int a=1 ; a<6 ; a++){
641  CountAll += m_algoVsBunchStructure[theTriggerAlias]->getBinContent(ls+1,a);
642  }
643  }
644 
645  if(m_verbose){
646  cout << "Alias = " << theTriggerAlias
647  << " InitLS=" << fLS
648  << " EndLS=" << lLS
649  << " Events=" << CountAll ;
650  }
651 
652  if(iForce ||
653  CountAll >= m_parameters.getParameter<ParameterSet>("Categories")
654  .getParameter<ParameterSet>(theCategory)
655  .getParameter<int>("CertMinEvents")){
656 
657  if(m_verbose){cout << " <--------------- Enough Statistics: ";}
658 
659 
660  // Calculating fraction of in time
661  double fraction = 0;
662  if(CountAll >0){fraction = CountSync/CountAll;}
663 
664  // This is to avoid having an entry equal to zero and thus
665  // disregarded by the automatic tests
666  if(fraction==0){fraction=0.000001;}
667 
668  certifyLSBlock(theTriggerAlias,fLS,lLS,fraction);
669  m_certFirstLS[theTriggerAlias] = 0;
670  m_certLastLS [theTriggerAlias] = 0;
671  }
672 
673  if(m_verbose){cout << endl;}
674 
675  }
676  }
677 
678  // A problem was found. We report it and set a not physical vale (-1) to the certification plot
679  else{
680 
681  // If trigger alias is not valid report it to m_ErrorMonitor
682  if(!triggerAlias_isValid){
683  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_TRIGGERALIAS_NOTVALID);
684  eCount++;
685  m_ErrorMonitor->getTH1()->SetBinContent(ERROR_TRIGGERALIAS_NOTVALID,eCount);
686  certifyLSBlock(theTriggerAlias,fLS,lLS,-1);
687  m_certFirstLS[theTriggerAlias] = 0;
688  m_certLastLS [theTriggerAlias] = 0;
689  }
690 
691  // If LS Block is not valid report it to m_ErrorMonitor
692  if(lsBlock_exists && !lsBlock_isValid){
693  int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_LSBLOCK_NOTVALID);
694  eCount++;
695  m_ErrorMonitor->getTH1()->SetBinContent(ERROR_LSBLOCK_NOTVALID,eCount);
696  certifyLSBlock(theTriggerAlias,fLS,lLS,-1);
697  m_certFirstLS[theTriggerAlias] = 0;
698  m_certLastLS [theTriggerAlias] = 0;
699  }
700 
701  }
702  }
703 
704 }
705 
706 
707 //_____________________________________________________________________
708 // Method: certifyLSBlock
709 // Description: Fill the trigger certification plot by blocks
710 // Variable: iTrigger - Which trigger to certify
711 // Variable: iInitLs - Blocks initial LS
712 // Variable: iEndLs - Blocks end LS
713 // Variable: iValue - Value to be used to fill
714 //_____________________________________________________________________
715 void L1TSync::certifyLSBlock(string iTrigger, int iInitLs, int iEndLs ,float iValue){
716 
717  // Finding correct bins in the histogram for this block
718  int binInit = m_algoCertification[iTrigger]->getTH1()->FindBin(iInitLs);
719  int binEnd = m_algoCertification[iTrigger]->getTH1()->FindBin(iEndLs);
720 
721  for(int ls=binInit ; ls<=binEnd ; ls++){
722  m_algoCertification[iTrigger]->setBinContent(ls,iValue);
723  }
724 
725 }
726 
727 //define this as a plug-in
LuminosityBlockID id() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void beginJob()
Definition: L1TSync.cc:214
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2530
void doFractionInSync(bool iForce=false, bool iBad=false)
Definition: L1TSync.cc:604
0: Unidentified isolated particle
Definition: ParticleCode.h:19
L1TSync(const edm::ParameterSet &ps)
Definition: L1TSync.cc:45
#define abs(x)
Definition: mlp_lapack.h:159
std::map< std::string, std::string > getLUSOTrigger(std::map< std::string, bool > iCategories, int IndexRefPrescaleFactors)
#define NULL
Definition: scimark2.h:8
DEFINE_FWK_MODULE(HiMixingModule)
virtual void beginLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
Definition: L1TSync.cc:321
void analyze(const edm::Event &e, const edm::EventSetup &c)
Definition: L1TSync.cc:435
AlgorithmMap::const_iterator CItAlgo
iterators through map containing the algorithms
int iEvent
Definition: GenABIO.cc:243
void certifyLSBlock(std::string iTrigger, int iInitLs, int iEndLs, float iValue)
Definition: L1TSync.cc:715
void endJob(void)
Definition: L1TSync.cc:231
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
virtual void endLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
Definition: L1TSync.cc:359
const cms_uint32_t lhcFillNumber() const
void getBeamConfOMDS()
Definition: L1TSync.cc:547
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
LuminosityBlockNumber_t luminosityBlock() const
void endRun(const edm::Run &run, const edm::EventSetup &iSetup)
Definition: L1TSync.cc:424
double a
Definition: hdecay.h:121
tuple cout
Definition: gather_cfg.py:121
std::map< std::string, std::string > testAlgos(std::map< std::string, std::string >)
virtual ~L1TSync()
Definition: L1TSync.cc:210
LimitAlgo * algo
Definition: Combine.cc:60
const AlgorithmMap & gtAlgorithmAliasMap() const
get / set the algorithm map (by alias)
void beginRun(const edm::Run &run, const edm::EventSetup &iSetup)
BeginRun.
Definition: L1TSync.cc:245
const cms_uint16_t beamMode() const
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
Definition: Run.h:33