CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/L1TriggerConfig/L1ScalesProducers/src/L1CaloEcalScaleConfigOnlineProd.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    L1EmEtScaleOnlineProd
00004 // Class:      L1EmEtScaleOnlineProd
00005 // 
00013 //
00014 // Original Author:  Werner Man-Li Sun
00015 //         Created:  Tue Sep 16 22:43:22 CEST 2008
00016 // $Id: L1CaloEcalScaleConfigOnlineProd.cc,v 1.4 2010/12/21 04:08:28 efron Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 
00023 // user include files
00024 #include "CondTools/L1Trigger/interface/L1ConfigOnlineProdBase.h"
00025 #include "CondFormats/L1TObjects/interface/L1CaloEcalScale.h"
00026 #include "CondFormats/DataRecord/interface/L1CaloEcalScaleRcd.h"
00027 #include "CondFormats/EcalObjects/interface/EcalTPGLutIdMap.h"
00028 #include "CondFormats/EcalObjects/interface/EcalTPGLutGroup.h"
00029 #include "CondFormats/EcalObjects/interface/EcalTPGPhysicsConst.h"
00030 #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h"
00031 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00032 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00033 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
00034 
00035 //
00036 // class declaration
00037 //
00038 
00039 class L1CaloEcalScaleConfigOnlineProd :
00040   public L1ConfigOnlineProdBase< L1CaloEcalScaleRcd, L1CaloEcalScale > {
00041    public:
00042       L1CaloEcalScaleConfigOnlineProd(const edm::ParameterSet&);
00043       ~L1CaloEcalScaleConfigOnlineProd();
00044 
00045   virtual boost::shared_ptr< L1CaloEcalScale > newObject(
00046     const std::string& objectKey ) ;
00047 
00048 
00049    private:
00050  const EcalElectronicsMapping * theMapping_ ;
00051   std::map<int, std::vector<int>* > groupInfo;
00052   EcalTPGGroups*  lutGrpMap;
00053   L1CaloEcalScale* ecalScale;
00054       // ----------member data ---------------------------
00055 };
00056 
00057 //
00058 // constants, enums and typedefs
00059 //
00060 
00061 //
00062 // static data member definitions
00063 //
00064 
00065 //
00066 // constructors and destructor
00067 //
00068 L1CaloEcalScaleConfigOnlineProd::L1CaloEcalScaleConfigOnlineProd(
00069   const edm::ParameterSet& iConfig)
00070   : L1ConfigOnlineProdBase< L1CaloEcalScaleRcd, L1CaloEcalScale >( iConfig )
00071 {
00072   ecalScale = new L1CaloEcalScale(0);
00073   theMapping_ = new EcalElectronicsMapping();
00074    lutGrpMap = new EcalTPGGroups();
00075 
00076 }
00077 
00078 
00079 L1CaloEcalScaleConfigOnlineProd::~L1CaloEcalScaleConfigOnlineProd()
00080 {
00081  
00082    // do anything here that needs to be done at desctruction time
00083    // (e.g. close files, deallocate resources etc.)
00084   delete theMapping_;
00085  
00086   //  delete ecalScale;
00087   //  delete lutGrpMap;
00088   groupInfo.clear();
00089 
00090 
00091 }
00092 
00093 boost::shared_ptr< L1CaloEcalScale >
00094 L1CaloEcalScaleConfigOnlineProd::newObject( const std::string& objectKey )
00095 {
00096      using namespace edm::es;
00097  
00098      std:: cout << "object Key " << objectKey <<std::endl;
00099 
00100      if(objectKey == "NULL" || objectKey == "")  // return default blank ecal scale      
00101         return boost::shared_ptr< L1CaloEcalScale >( ecalScale );
00102      if(objectKey == "IDENTITY"){  // return identity ecal scale  
00103        ecalScale = 0;
00104        ecalScale = new L1CaloEcalScale(1);
00105        return boost::shared_ptr< L1CaloEcalScale >( ecalScale);
00106      }
00107      
00108 
00109      double ee_lsb = 0.;
00110      double eb_lsb = 0.;
00111 
00112      std::vector < std::string > mainStrings;
00113   
00114      // ~~~~~~~~~ Cut values ~~~~~~~~~
00115 
00116  
00117      std::vector< std::string > paramStrings ;
00118      paramStrings.push_back("LOGIC_ID");  // EB/EE
00119      paramStrings.push_back("ETSAT");  //Only object needed
00120     
00121     
00122      std::vector< std::string> IDStrings;
00123      IDStrings.push_back("NAME");
00124      IDStrings.push_back("ID1");
00125      IDStrings.push_back("ID2");
00126      IDStrings.push_back("maps_to");
00127 
00128     l1t::OMDSReader::QueryResults paramResults =
00129        m_omdsReader.basicQuery( paramStrings,
00130                                 "CMS_ECAL_CONF",
00131                                 "FE_CONFIG_LUTPARAM_DAT",
00132                                 "FE_CONFIG_LUTPARAM_DAT.LUT_CONF_ID",
00133                                 m_omdsReader.singleAttribute(objectKey) 
00134                                 );
00135 
00136     if( paramResults.queryFailed()
00137         || (paramResults.numberRows()==0) ) // check query successful
00138        {
00139          edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key.  Unable to find lutparam dat table" ;
00140          return boost::shared_ptr< L1CaloEcalScale >() ;
00141        }
00142 
00143     
00144 
00145      for(int i = 0; i < paramResults.numberRows() ; i++){
00146        
00147        //EcalTPGPhysicsConst::Item item;
00148        float etSat;
00149        paramResults.fillVariableFromRow("ETSAT",i,etSat);
00150 
00151        std::string  ecid_name; 
00152        int logic_id;
00153        paramResults.fillVariableFromRow("LOGIC_ID",i, logic_id);
00154        
00155        
00156        l1t::OMDSReader::QueryResults logicID =
00157          m_omdsReader.basicQuery(IDStrings,
00158                                  "CMS_ECAL_COND",
00159                                  "CHANNELVIEW",
00160                                  "CHANNELVIEW.LOGIC_ID",
00161                                  m_omdsReader.singleAttribute(logic_id)
00162                                  );
00163        
00164        logicID.fillVariable("NAME",ecid_name);
00165 
00166        if(ecid_name =="EB")
00167          eb_lsb = etSat/1024;
00168        else if("EE" == ecid_name)
00169          ee_lsb = etSat/1024;
00170        else {
00171          edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale  LOGIC_ID.  unable to find channel view with appropiate logic id" ;
00172          return boost::shared_ptr< L1CaloEcalScale >() ;
00173        }
00174 
00175      }
00176      //     std::cout << " eb lsb " << eb_lsb << " ee_lsb " << ee_lsb << std::endl;
00177   
00178      std::vector< std::string > grpLUT;
00179      grpLUT.push_back("GROUP_ID");
00180      grpLUT.push_back("LUT_ID");
00181      grpLUT.push_back("LUT_VALUE");
00182      
00183      l1t::OMDSReader::QueryResults lutGrpResults = 
00184        m_omdsReader.basicQuery( grpLUT,
00185                                 "CMS_ECAL_CONF",
00186                                 "FE_LUT_PER_GROUP_DAT",
00187                                 "FE_LUT_PER_GROUP_DAT.LUT_CONF_ID",
00188                                 m_omdsReader.singleAttribute(objectKey)
00189                                 );
00190 
00191     if( lutGrpResults.queryFailed()
00192         || (lutGrpResults.numberRows()%1024 !=0) ) // check query successful
00193        {
00194          edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key.  No group info" ;
00195          return boost::shared_ptr< L1CaloEcalScale >() ;
00196        }
00197 
00198 
00199      int nEntries = lutGrpResults.numberRows();
00200      for(int i = 0; i <  nEntries; i++) {
00201        int group, lutID;
00202        float lutValue;
00203 
00204        lutGrpResults.fillVariableFromRow("GROUP_ID",i,group);
00205        if(groupInfo.find(group) == groupInfo.end()){
00206          groupInfo[group] = new std::vector<int>;
00207          (groupInfo[group])->resize(1024);
00208        }
00209       
00210        lutGrpResults.fillVariableFromRow("LUT_ID",i,lutID);
00211        lutGrpResults.fillVariableFromRow("LUT_VALUE",i,lutValue);
00212        groupInfo[group]->at(lutID) = (int) lutValue;
00213      }
00214 
00215      std::map<int, std::vector<int> >  tpgValueMap;
00216        
00217        std::map<int, std::vector<int>* >::iterator grpIt;
00218      for ( grpIt = groupInfo.begin(); grpIt != groupInfo.end() ; ++grpIt){
00219        const std::vector<int> * lut_ = grpIt->second;
00220      
00221        std::vector<int> tpgValue; 
00222        tpgValue.resize(256);
00223        int lastValue = 0;
00224        for(int tpg = 0; tpg < 256 ; tpg++){
00225 
00226          for(int i = 0; i < 1024 ; i++) {
00227 
00228            if(tpg == (0xff & (lut_->at(i)))){
00229              tpgValue[tpg] = i; 
00230              lastValue = i;
00231              break;
00232            }
00233            tpgValue[tpg] = lastValue;
00234          }
00235        }
00236        tpgValueMap[grpIt->first] = tpgValue;
00237      }
00238 
00239 
00240      std::vector < std::string > groupMap;
00241      groupMap.push_back("LOGIC_ID");
00242      groupMap.push_back("GROUP_ID");
00243 
00244 
00245      
00246      l1t::OMDSReader::QueryResults grpMapResults = 
00247        m_omdsReader.basicQuery( groupMap,
00248                                 "CMS_ECAL_CONF",
00249                                 "FE_CONFIG_LUT_DAT",
00250                                 "FE_CONFIG_LUT_DAT.LUT_CONF_ID",
00251                                 m_omdsReader.singleAttribute(objectKey)
00252                                 );
00253      if( grpMapResults.queryFailed()
00254         || (grpMapResults.numberRows()==0) ) // check query successful
00255        {
00256          edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key. No fe_config_lut_dat info" ;
00257          return boost::shared_ptr< L1CaloEcalScale >() ;
00258        }
00259 
00260      nEntries = grpMapResults.numberRows();
00261      for(int i = 0; i< nEntries; ++i){
00262        std::string  ecid_name; 
00263        int logic_id;
00264        grpMapResults.fillVariableFromRow("LOGIC_ID",i, logic_id);
00265        int group_id;
00266        grpMapResults.fillVariableFromRow("GROUP_ID",i, group_id);
00267        //       if(logic_id >= 2100001901 && logic_id <= 2100001916)
00268          //      std::cout<< "missing logic id found " <<logic_id <<std::endl;
00269        l1t::OMDSReader::QueryResults IDResults =
00270          m_omdsReader.basicQuery( IDStrings,
00271                                   "CMS_ECAL_COND",
00272                                   "CHANNELVIEW",
00273                                   "CHANNELVIEW.LOGIC_ID",
00274                                   m_omdsReader.singleAttribute(logic_id)
00275                                   );
00276        if( paramResults.queryFailed()
00277            || (paramResults.numberRows()==0) ) // check query successful
00278          {
00279          edm::LogError( "L1-O2O" ) << "Problem with L1CaloEcalScale key.  Unable to find logic_id channel view" ;
00280          return boost::shared_ptr< L1CaloEcalScale >() ;
00281        }
00282        for(int j = 0; j < IDResults.numberRows(); j++){
00283 
00284          std::string ecid_name, maps_to;
00285 
00286          IDResults.fillVariableFromRow("NAME",j, ecid_name);
00287          IDResults.fillVariableFromRow("maps_to",j, maps_to);
00288          if(logic_id >= 2100001901 && logic_id <= 2100001916)
00289            //      std::cout << " name " << ecid_name << " maps to " << maps_to <<std::endl;
00290          if(ecid_name != maps_to){
00291            continue;               // make sure they match
00292          }
00293          if(ecid_name== "EB_trigger_tower" || ecid_name == "EE_trigger_tower") {           
00294            int id1,id2;
00295            IDResults.fillVariableFromRow("ID1",j, id1);
00296            IDResults.fillVariableFromRow("ID2",j, id2);
00297          
00298            if(ecid_name == "EB_trigger_tower")
00299              id1+=36;  //lowest TCC for barrel 37
00300            EcalTrigTowerDetId temp = theMapping_->getTrigTowerDetId(id1,id2);
00301            /*      if(ecid_name == "EE_trigger_tower"){
00302              int testID = theMapping_->TCCid(temp);
00303 
00304              if( testID != id1 ){
00305                        std::cout << " unmatched mapping testID " <<testID <<std::endl;
00306                std::cout << "id1 " << id1 << " id2 " <<id2<< " iphi " << temp.iphi() <<"  ieta " << temp.ieta() <<std::endl;
00307              }
00308            }
00309            if(ecid_name == "EB_trigger_tower"){
00310              int testID = theMapping_->TCCid(temp);
00311              if( testID != id1 ){
00312                std::cout << " unmatched mapping testID " <<testID <<std::endl;
00313                std::cout << "id1 " << id1 << " id2 " <<id2<< " iphi " << temp.iphi() <<"  ieta " << temp.ieta() <<std::endl;
00314              }
00315            }
00316            */
00317            //      if(temp.ieta() == -18 || temp.ietaAbs() == 28)
00318              //    if(logic_id >= 2100001901 && logic_id <= 2100001916)
00319 
00320 
00321            lutGrpMap->setValue(temp, group_id);  // assume ee has less than 68 tt
00322            break;
00323          }
00324        }
00325      }
00326      
00327      const EcalTPGGroups::EcalTPGGroupsMap & gMap = lutGrpMap->getMap();
00328      
00329 
00330 
00331      for( unsigned short ieta = 1 ; ieta <= L1CaloEcalScale::nBinEta; ++ieta ){
00332        EcalSubdetector subdet = ( ieta <= 17  ) ? EcalBarrel : EcalEndcap ;
00333        double et_lsb = (ieta<=17) ?  eb_lsb : ee_lsb;
00334        for(int pos = 0; pos <=1; pos++){
00335          int zside = (int)  pow(-1,pos);
00336 
00337          //      std::cout << "ieta " <<zside*ieta ;
00338          for(int iphi = 1; iphi<=72; iphi++){
00339            if(!EcalTrigTowerDetId::validDetId(zside,subdet,ieta, iphi))
00340              continue;
00341            EcalTrigTowerDetId test(zside, subdet, ieta, iphi);
00342            EcalTPGGroups::EcalTPGGroupsMapItr  itLut = gMap.find(test) ;
00343            if(itLut != gMap.end()) {
00344              //      std::cout << " non mapped section iphi " << iphi << " ieta " <<ieta << " tccid " << theMapping_->TCCid(test) << " iTT " << theMapping_->iTT(test)<< std::endl;
00345              std::vector<int> tpgValue = tpgValueMap[itLut->second]; 
00346 
00347              for( unsigned short irank = 0 ; irank < L1CaloEcalScale::nBinRank; ++irank )
00348                {
00349                  ecalScale->setBin(irank, ieta, zside, et_lsb * tpgValue[irank]);
00350 
00351                  //              std::cout << " irank " << irank << " etValue " << et_lsb*tpgValue[irank] << std::endl;          
00352                }
00353              
00354              break;
00355            }
00356          }
00357        }
00358      }
00359 
00360      
00361      //     ecalScale->print(std::cout);
00362 
00363  
00364 // ------------ method called to produce the data  ------------
00365      return boost::shared_ptr< L1CaloEcalScale >( ecalScale );
00366 }
00367 //define this as a plug-in
00368 DEFINE_FWK_EVENTSETUP_MODULE(L1CaloEcalScaleConfigOnlineProd);