CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQMOffline/L1Trigger/src/L1TSync_Harvest.cc

Go to the documentation of this file.
00001 /*
00002  * \class L1TSync_Harvest
00003  *
00004  *
00005  * Description: offline DQM module for L1Trigger/bunchStructure synchronization
00006  * 
00007  * Implementation:
00008  *   <TODO: enter implementation details>
00009  *
00010  * \author: Pietro Vischia - LIP Lisbon pietro.vischia@gmail.com
00011  *
00012  * Changelog:
00013  *    2012/08/10 11:01:01: First creation. Dummy module with actual code commented.
00014  *
00015  * Todo:
00016  *  - implement the module in offline
00017  *  - check if there are user includes specific for offline/online that should be changed
00018  *
00019  * $Date: 2012/11/27 14:56:17 $
00020  * $Revision: 1.1 $
00021  *
00022  */
00023 
00024 // 
00025 
00026 // This class header
00027 #include "DQMOffline/L1Trigger/interface/L1TSync_Harvest.h"
00028 
00029 // System include files
00030 // --
00031 
00032 // User include files
00033 #include "DQMServices/Core/interface/DQMStore.h"
00034 
00035 
00036 using namespace edm;
00037 using namespace std;
00038 
00039 //-------------------------------------------------------------------------------------
00040 //-------------------------------------------------------------------------------------
00041 L1TSync_Harvest::L1TSync_Harvest(const ParameterSet & pset){
00042 
00186   if (pset.getUntrackedParameter < bool > ("dqmStore", false)) {
00187     dbe = Service < DQMStore > ().operator->();
00188     dbe->setVerbose(0);
00189   }
00190 
00191   m_outputFile = pset.getUntrackedParameter < std::string > ("outputFile","");
00192 
00193   if (m_outputFile.size() != 0) {
00194     std::cout << "L1T Monitoring histograms will be saved to " <<       m_outputFile.c_str() << std::endl;
00195   }
00196 
00197   bool disable = pset.getUntrackedParameter < bool > ("disableROOToutput", false);
00198   if (disable) {m_outputFile = "";}
00199 
00200   if (dbe != NULL) {dbe->setCurrentFolder("L1T/L1TSync");}
00201 
00202 }
00203 
00204 //-------------------------------------------------------------------------------------
00205 //-------------------------------------------------------------------------------------
00206 L1TSync_Harvest::~L1TSync_Harvest(){}
00207 
00208 //-------------------------------------------------------------------------------------
00209 //-------------------------------------------------------------------------------------
00210 void L1TSync_Harvest::beginJob(void){
00211 
00212   if (m_verbose){cout << "[L1TSync_Harvest] Called beginJob." << endl;}
00213 
00214   // get hold of back-end interface
00215   DQMStore *dbe = 0;
00216   dbe = Service < DQMStore > ().operator->();
00217 
00218   if (dbe) {
00219     dbe->setCurrentFolder("L1T/L1TSync");
00220     dbe->rmdir("L1T/L1TSync");
00221   }
00222  
00223 }
00224 
00225 //-------------------------------------------------------------------------------------
00226 //-------------------------------------------------------------------------------------
00227 void L1TSync_Harvest::endJob(void){
00228 
00229   if (m_verbose){cout << "[L1TSync_Harvest] Called endJob." << endl;}
00230 
00231   if (m_outputFile.size() != 0 && dbe)
00232     dbe->save(m_outputFile);
00233 
00234   return;
00235 
00236 }
00237 
00238 //-------------------------------------------------------------------------------------
00240 //-------------------------------------------------------------------------------------
00241 void L1TSync_Harvest::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup){
00242 
00312 }
00313 
00314 //_____________________________________________________________________
00315 // Function: beginLuminosityBlock
00316 //_____________________________________________________________________
00317 void L1TSync_Harvest::beginLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) {
00318 
00319   if (m_verbose){cout << "[L1TSync_Harvest] Called beginLuminosityBlock." << endl;}
00320 
00321   // If this LS is not the next to last one force closing of current LS blocks
00322   // for certification
00323   if(m_currentLS !=0 && m_currentLS+1 != lumiBlock.id().luminosityBlock()){
00324 
00325     if (m_verbose){
00326       cout << "[L1TSync_Harvest] None consecutive: doFractionInSync() - LAST=" 
00327            << m_currentLS << " CURRENT=" << lumiBlock.id().luminosityBlock() << endl;
00328     }
00329 
00330     doFractionInSync(true,false);    
00331 
00332   }
00333     
00334   // Updating current LS number
00335   m_currentLS = lumiBlock.id().luminosityBlock();
00336 
00337   // If this is the fist valid LS update first LS for certification 
00338   for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
00339 
00340     string theTriggerAlias = (*i).second;
00341     if(m_certFirstLS[theTriggerAlias]==0){m_certFirstLS[theTriggerAlias] = m_currentLS;}
00342 
00343   }
00344 
00345   // A LS will be valid if:
00346   //   * BeamMode == STABLE for all events monitored
00347   m_currentLSValid = true; 
00348 
00349 }
00350 
00351 //_____________________________________________________________________
00352 // Function: endLuminosityBlock
00353 // * Fills LS by LS ration of trigger out of sync
00354 //_____________________________________________________________________
00355 void L1TSync_Harvest::endLuminosityBlock(LuminosityBlock const& lumiBlock, EventSetup const& c) {
00356 
00357   if(m_verbose){cout << "[L1TSync_Harvest] Called endLuminosityBlock." << endl;}
00358 
00359   if(m_verbose){
00360     cout << "[L1TSync_Harvest] m_currentLSValid      : " << m_currentLSValid       << endl;
00361     cout << "[L1TSync_Harvest] m_beamConfig.isValid(): " << m_beamConfig.isValid() << endl;
00362   }  
00363 
00364   for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
00365 
00366     // Update last LS for certification      
00367     string theTriggerAlias = (*i).second;
00368     m_certLastLS[theTriggerAlias] = m_currentLS;
00369 
00370   }
00371 
00372   // If this LS is valid (i.e. all events recorded with stable beams)
00373   if(m_currentLSValid && m_beamConfig.isValid()){
00374 
00375     if(m_verbose){cout << "[L1TSync_Harvest] Regular call: doFractionInSync()" << endl;}
00376     doFractionInSync(false,false);
00377     
00378   }
00379   // If this LS is not valid it can be in the following context:
00380   //  * We still hadn't stable beam (no need to certify nothing
00381   //  * Beam just got unstable or dumped (we may have a complete block of data do certify)  
00382   else{
00383     
00384     //-> First we close all blocks from certFirstLS[] to m_currentLS-1
00385     for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
00386 
00387       string theTriggerAlias = (*i).second;
00388       
00389       int fLs = m_certFirstLS[theTriggerAlias];
00390       int lLS = m_certLastLS [theTriggerAlias];
00391 
00392       // If this is a single LS block we do nothing (in this step)
00393       if(fLs == lLS){
00394         m_certFirstLS[theTriggerAlias] = 0;
00395         m_certLastLS [theTriggerAlias] = 0;
00396       }
00397       // If block is multi LS then we remove the current LS 
00398       else{
00399         m_certLastLS [theTriggerAlias] = m_currentLS-1;
00400       }
00401 
00402     }
00403     doFractionInSync(true,false);
00404 
00405     //-> Second we mark this single LS bad for all triggers
00406     for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
00407       string theTriggerAlias = (*i).second;
00408       m_certFirstLS[theTriggerAlias] = m_currentLS;
00409       m_certLastLS [theTriggerAlias] = m_currentLS;
00410     }
00411     doFractionInSync(true,true);
00412 
00413     if(m_verbose){cout << "[L1TSync_Harvest] Error call: doFractionInSync()" << endl;}  
00414 
00415   }
00416 
00417 }
00418 
00419 //_____________________________________________________________________
00420 void L1TSync_Harvest::endRun(const edm::Run& run, const edm::EventSetup& iSetup){
00421   
00422   if(m_verbose){cout << "[L1TSync_Harvest] Called endRun." << endl;}
00423   
00424   // When the run end for closing of the LS certification blocks and evaluation
00425   // of synchronization for that block
00426   doFractionInSync(true,false);    
00427 
00428 }
00429 
00430 //_____________________________________________________________________
00431 void L1TSync_Harvest::analyze(const Event & iEvent, const EventSetup & eventSetup){
00432  
00536 }
00537 
00538 //_____________________________________________________________________
00539 // Method: getBunchStructureOMDS
00540 // Description: Attempt to retrive Beam Configuration from OMDS and if
00541 //              we find error handle it
00542 //_____________________________________________________________________
00543 
00544 //_____________________________________________________________________
00545 // Method: doFractionInSync
00546 // Description: Produce plot with the fraction of in sync trigger for
00547 //              LS blocks with enough statistics.
00548 // Variable: iForce - Forces closing of all blocks and calculation of 
00549 //                    the respective fractions
00550 // Variable: iBad   - (Only works with iForce=true) Forces the current 
00551 //                    all current blocks to be marked as bad 
00552 //_____________________________________________________________________
00553 void L1TSync_Harvest::doFractionInSync(bool iForce,bool iBad){
00554   
00555   for(map<string,string>::const_iterator i=m_selectedTriggers.begin() ; i!=m_selectedTriggers.end() ; i++){
00556 
00557     string theCategory     = (*i).first;
00558     string theTriggerAlias = (*i).second;
00559 
00560     // Caching frequently used values from maps
00561     unsigned int fLS = m_certFirstLS[theTriggerAlias];
00562     unsigned int lLS = m_certLastLS [theTriggerAlias];
00563     
00564     // Checking validity of the trigger alias and of the LS block
00565     bool triggerAlias_isValid = theTriggerAlias != "Undefined" && theTriggerAlias != "Undefined (Wrong Name)";
00566     bool lsBlock_exists       = !(fLS == 0 && lLS == 0);
00567     bool lsBlock_isValid      = fLS <= lLS && fLS > 0 && lLS > 0; 
00568 
00569     if(triggerAlias_isValid && lsBlock_exists && lsBlock_isValid){
00570 
00571       // If we are forced to close blocks and mark them bad
00572       if(iForce && iBad){
00573         certifyLSBlock(theTriggerAlias,fLS,lLS,-1);
00574         m_certFirstLS[theTriggerAlias] = 0;
00575         m_certLastLS [theTriggerAlias] = 0;
00576       }
00577 
00578       // If we are not forced to mark bad, we check if we have enough statistics
00579       else{
00580 
00581         // Getting events with 0 bx difference between BPTX and Algo for current LS
00582         double CountSync = 0;
00583         double CountAll  = 0;
00584   
00585         // Adding all entries for current LS block
00586         for(unsigned int ls=fLS ; ls<=lLS ; ls++){
00587 
00588           CountSync += m_algoVsBunchStructure[theTriggerAlias]->getBinContent(ls+1,3);
00589           for(int a=1 ; a<6 ; a++){
00590             CountAll  += m_algoVsBunchStructure[theTriggerAlias]->getBinContent(ls+1,a);
00591           }
00592         }
00593 
00594         if(m_verbose){
00595           cout << "Alias = " << theTriggerAlias 
00596                << " InitLS=" << fLS 
00597                << " EndLS=" <<  lLS 
00598                << " Events=" << CountAll ;
00599         } 
00600 
00601         if(iForce ||
00602            CountAll >= m_parameters.getParameter<ParameterSet>("Categories")
00603                                    .getParameter<ParameterSet>(theCategory)
00604                                    .getParameter<int>("CertMinEvents")){
00605 
00606           if(m_verbose){cout << " <--------------- Enough Statistics: ";}
00607 
00608         
00609           // Calculating fraction of in time 
00610           double fraction = 0;
00611           if(CountAll >0){fraction = CountSync/CountAll;}
00612 
00613           // This is to avoid having an entry equal to zero and thus
00614           // disregarded by the automatic tests
00615           if(fraction==0){fraction=0.000001;}
00616         
00617           certifyLSBlock(theTriggerAlias,fLS,lLS,fraction);
00618           m_certFirstLS[theTriggerAlias] = 0;
00619           m_certLastLS [theTriggerAlias] = 0;
00620         }
00621 
00622         if(m_verbose){cout << endl;}
00623 
00624       }
00625     }
00626 
00627     // A problem was found. We report it and set a not physical vale (-1) to the certification plot
00628     else{
00629 
00630       // If trigger alias is not valid report it to m_ErrorMonitor
00631       if(!triggerAlias_isValid){
00632         int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_TRIGGERALIAS_NOTVALID);
00633         eCount++;
00634         m_ErrorMonitor->getTH1()->SetBinContent(ERROR_TRIGGERALIAS_NOTVALID,eCount);
00635         certifyLSBlock(theTriggerAlias,fLS,lLS,-1);
00636         m_certFirstLS[theTriggerAlias] = 0;
00637         m_certLastLS [theTriggerAlias] = 0;
00638       }
00639 
00640       // If LS Block is not valid report it to m_ErrorMonitor
00641       if(lsBlock_exists && !lsBlock_isValid){
00642         int eCount = m_ErrorMonitor->getTH1()->GetBinContent(ERROR_LSBLOCK_NOTVALID);
00643         eCount++;
00644         m_ErrorMonitor->getTH1()->SetBinContent(ERROR_LSBLOCK_NOTVALID,eCount);
00645         certifyLSBlock(theTriggerAlias,fLS,lLS,-1);
00646         m_certFirstLS[theTriggerAlias] = 0;
00647         m_certLastLS [theTriggerAlias] = 0;
00648       }
00649 
00650     }
00651   }
00652 
00653 }
00654 
00655 
00656 //_____________________________________________________________________
00657 // Method: certifyLSBlock
00658 // Description: Fill the trigger certification plot by blocks
00659 // Variable: iTrigger - Which trigger to certify
00660 // Variable: iInitLs  - Blocks initial LS
00661 // Variable: iEndLs   - Blocks end LS
00662 // Variable: iValue   - Value to be used to fill
00663 //_____________________________________________________________________
00664 void L1TSync_Harvest::certifyLSBlock(string iTrigger, int iInitLs, int iEndLs ,float iValue){
00665   
00673 
00674 }
00675 
00676 //define this as a plug-in
00677 DEFINE_FWK_MODULE(L1TSync_Harvest);