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