CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 /*
00002  * \class L1TLSBlock
00003  *
00004  *
00005  * Description: offline DQM class for LS blocking
00006  * 
00007  * Implementation:
00008  *   <TODO: enter implementation details>
00009  *
00010  * \author: Pietro Vischia - LIP Lisbon pietro.vischia@gmail.com
00011  *
00012  * Changelog:
00013  *    2012/10/23 12:01:01: Class
00014  *
00015  * Todo: see header file
00016  *
00017  * $Date: 2012/11/27 14:56:17 $
00018  * $Revision: 1.1 $
00019  *
00020  */
00021 
00022 // 
00023 
00024 // This class header
00025 #include "DQMOffline/L1Trigger/interface/L1TLSBlock.h"
00026 
00027 // System include files
00028 // --
00029 
00031 //#include "DQMServices/Core/interface/DQMStore.h"
00032 //
00033 //#include "DataFormats/Scalers/interface/LumiScalers.h"
00034 //#include "DataFormats/Scalers/interface/Level1TriggerRates.h"
00035 //#include "DataFormats/Scalers/interface/Level1TriggerScalers.h"
00036 //
00037 //#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00038 //#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
00039 //
00040 //#include "DataFormats/Common/interface/ConditionsInEdm.h" // Parameters associated to Run, LS and Event
00041 //
00042 //#include "CondFormats/L1TObjects/interface/L1GtTriggerMenuFwd.h"
00043 //#include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00044 //#include "CondFormats/L1TObjects/interface/L1GtPrescaleFactors.h"
00045 //#include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
00046 //#include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsAlgoTrigRcd.h"
00047 //#include "CondFormats/L1TObjects/interface/L1GtMuonTemplate.h"
00052 //
00055 //#include "DQMOffline/L1Trigger/interface/L1TMenuHelper.h"
00056 //
00057 //#include "TList.h"
00058 
00059 using namespace std;
00060 
00061 //-------------------------------------------------------------------------------------
00062 //-------------------------------------------------------------------------------------
00063 
00064 L1TLSBlock::L1TLSBlock(){
00065 
00066   // Initialize LumiRangeList object. This will be redone at every doBlocking call. Perhaps rethink this
00067   initializeIO(false);
00068   
00069 }
00070 
00071 //-------------------------------------------------------------------------------------
00072 //-------------------------------------------------------------------------------------
00073 
00074 L1TLSBlock::~L1TLSBlock(){}
00075 
00076 //-------------------------------------------------------------------------------------
00077 //-------------------------------------------------------------------------------------
00078 
00079 L1TLSBlock::LumiRangeList L1TLSBlock::doBlocking(LumiTestDoubleList inputList, double threshold, BLOCKBY blockingMethod)
00080 {
00081   inputDoubleList_ = inputList;
00082   thresholdD_ = threshold;
00083   
00084   initializeIO(true);
00085   
00086   orderTestDoubleList();
00087   
00088   switch(blockingMethod){
00089   case STATISTICS:
00090     blockByStatistics();
00091     break;
00092   default:
00093     cout << "[L1TLSBlock::doBlocking()]: Blocking method does not exist or is not implemented" << endl;
00094   }
00095   
00096   
00097   return outputList_;
00098 }
00099 
00100 //-------------------------------------------------------------------------------------
00101 //-------------------------------------------------------------------------------------
00102 
00103 L1TLSBlock::LumiRangeList L1TLSBlock::doBlocking(LumiTestIntList inputList, int threshold, BLOCKBY blockingMethod)
00104 {
00105   inputIntList_ = inputList;
00106   thresholdI_ = threshold;
00107   
00108   initializeIO(true);
00109   
00110   orderTestIntList();
00111   
00112   switch(blockingMethod){
00113   case STATISTICS:
00114     cout << "[L1TLSBlock::doBlocking()]: Blocking by statistics require doubles as inputs for test variable and threshold" << endl;
00115     break;
00116   default:
00117     cout << "[L1TLSBlock::doBlocking()]: Blocking method does not exist or is not implemented" << endl;
00118   }
00119   
00120   return outputList_;
00121 }
00122 
00123 //-------------------------------------------------------------------------------------
00124 //-------------------------------------------------------------------------------------
00125 
00126 void L1TLSBlock::initializeIO(bool outputOnly){
00127   if(!outputOnly){
00128     inputIntList_.clear();
00129     inputDoubleList_.clear();
00130   }
00131   outputList_.clear();
00132 }
00133 
00134 //-------------------------------------------------------------------------------------
00135 //-------------------------------------------------------------------------------------
00136 
00137 void L1TLSBlock::orderTestDoubleList(){
00138   std::sort(inputDoubleList_.begin(), inputDoubleList_.end(), sort_pair_first<int, double>());
00139   // std::sort(v.begin(), v.end(), sort_pair_second<int, std::greater<int> >());
00140 }
00141 
00142 //-------------------------------------------------------------------------------------
00143 //-------------------------------------------------------------------------------------
00144 
00145 void L1TLSBlock::orderTestIntList(){
00146   std::sort(inputIntList_.begin(), inputIntList_.end(), sort_pair_first<int, int>());
00147 }
00148 
00149 //-------------------------------------------------------------------------------------
00150 //-------------------------------------------------------------------------------------
00151 
00152 void L1TLSBlock::blockByStatistics(){
00153   LumiRange currentRange;
00154   double currentError(0);
00155   bool resetFlag(true);
00156 
00157   for(LumiTestDoubleList::iterator i=inputDoubleList_.begin(); i!=inputDoubleList_.end(); i++){
00158     if(resetFlag){
00159       currentRange = std::make_pair(i->first,i->first);
00160       resetFlag = false;
00161     }
00162     else
00163       currentRange = std::make_pair(currentRange.first,i->first);
00164     currentError = computeErrorFromRange(currentRange);
00165     if(currentError < thresholdD_){
00166       outputList_.push_back(currentRange);
00167       resetFlag = true;
00168     }
00169     
00170   }
00171 }
00172 
00173 double L1TLSBlock::computeErrorFromRange(LumiRange& lumiRange){
00174   std::vector<double> errorList;
00175   errorList.clear();
00176 
00177   for(size_t i=0; i < inputDoubleList_.size(); i++){
00178     if(inputDoubleList_[i].first>lumiRange.first && inputDoubleList_[i].first<lumiRange.second)
00179       errorList.push_back(inputDoubleList_[i].second);
00180   }
00181   
00182   double error(-1);
00183   for(size_t i=0; i<errorList.size(); i++)
00184     error += 1 / (errorList[i] * errorList[i] );
00185   return error;
00186 
00187 }