Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:22

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1EmEtScaleOnlineProd
0004 // Class:      L1EmEtScaleOnlineProd
0005 //
0006 /**\class L1EmEtScaleOnlineProd L1EmEtScaleOnlineProd.h L1Trigger/L1EmEtScaleProducers/src/L1EmEtScaleOnlineProd.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Werner Man-Li Sun
0015 //         Created:  Tue Sep 16 22:43:22 CEST 2008
0016 //
0017 //
0018 
0019 // system include files
0020 
0021 // user include files
0022 #include "CondTools/L1Trigger/interface/L1ConfigOnlineProdBase.h"
0023 #include "CondFormats/L1TObjects/interface/L1CaloEcalScale.h"
0024 #include "CondFormats/DataRecord/interface/L1CaloEcalScaleRcd.h"
0025 #include "CondFormats/EcalObjects/interface/EcalTPGLutIdMap.h"
0026 #include "CondFormats/EcalObjects/interface/EcalTPGLutGroup.h"
0027 #include "CondFormats/EcalObjects/interface/EcalTPGPhysicsConst.h"
0028 #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h"
0029 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
0030 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
0031 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
0032 
0033 //
0034 // class declaration
0035 //
0036 
0037 class L1CaloEcalScaleConfigOnlineProd : public L1ConfigOnlineProdBase<L1CaloEcalScaleRcd, L1CaloEcalScale> {
0038 public:
0039   L1CaloEcalScaleConfigOnlineProd(const edm::ParameterSet&);
0040   ~L1CaloEcalScaleConfigOnlineProd() override;
0041 
0042   std::unique_ptr<L1CaloEcalScale> newObject(const std::string& objectKey) override;
0043 
0044 private:
0045   const EcalElectronicsMapping* theMapping_;
0046   std::map<int, std::vector<int>*> groupInfo;
0047   EcalTPGGroups* lutGrpMap;
0048 };
0049 
0050 L1CaloEcalScaleConfigOnlineProd::L1CaloEcalScaleConfigOnlineProd(const edm::ParameterSet& iConfig)
0051     : L1ConfigOnlineProdBase<L1CaloEcalScaleRcd, L1CaloEcalScale>(iConfig) {
0052   theMapping_ = new EcalElectronicsMapping();
0053   lutGrpMap = new EcalTPGGroups();
0054 }
0055 
0056 L1CaloEcalScaleConfigOnlineProd::~L1CaloEcalScaleConfigOnlineProd() {
0057   // do anything here that needs to be done at desctruction time
0058   // (e.g. close files, deallocate resources etc.)
0059   delete theMapping_;
0060 
0061   //  delete lutGrpMap;
0062   groupInfo.clear();
0063 }
0064 
0065 std::unique_ptr<L1CaloEcalScale> L1CaloEcalScaleConfigOnlineProd::newObject(const std::string& objectKey) {
0066   std::cout << "object Key " << objectKey << std::endl;
0067 
0068   if (objectKey == "NULL" || objectKey.empty()) {  // return default blank ecal scale
0069     return std::make_unique<L1CaloEcalScale>(0);
0070   }
0071   if (objectKey == "IDENTITY") {  // return identity ecal scale
0072     return std::make_unique<L1CaloEcalScale>(1);
0073   }
0074 
0075   double ee_lsb = 0.;
0076   double eb_lsb = 0.;
0077 
0078   std::vector<std::string> mainStrings;
0079 
0080   // ~~~~~~~~~ Cut values ~~~~~~~~~
0081 
0082   std::vector<std::string> paramStrings;
0083   paramStrings.push_back("LOGIC_ID");  // EB/EE
0084   paramStrings.push_back("ETSAT");     //Only object needed
0085 
0086   std::vector<std::string> IDStrings;
0087   IDStrings.push_back("NAME");
0088   IDStrings.push_back("ID1");
0089   IDStrings.push_back("ID2");
0090   IDStrings.push_back("maps_to");
0091 
0092   l1t::OMDSReader::QueryResults paramResults = m_omdsReader.basicQuery(paramStrings,
0093                                                                        "CMS_ECAL_CONF",
0094                                                                        "FE_CONFIG_LUTPARAM_DAT",
0095                                                                        "FE_CONFIG_LUTPARAM_DAT.LUT_CONF_ID",
0096                                                                        m_omdsReader.singleAttribute(objectKey));
0097 
0098   if (paramResults.queryFailed() || (paramResults.numberRows() == 0))  // check query successful
0099   {
0100     edm::LogError("L1-O2O") << "Problem with L1CaloEcalScale key.  Unable to find lutparam dat table";
0101     return std::unique_ptr<L1CaloEcalScale>();
0102   }
0103 
0104   for (int i = 0; i < paramResults.numberRows(); i++) {
0105     //EcalTPGPhysicsConst::Item item;
0106     float etSat;
0107     paramResults.fillVariableFromRow("ETSAT", i, etSat);
0108 
0109     std::string ecid_name;
0110     int logic_id;
0111     paramResults.fillVariableFromRow("LOGIC_ID", i, logic_id);
0112 
0113     l1t::OMDSReader::QueryResults logicID = m_omdsReader.basicQuery(
0114         IDStrings, "CMS_ECAL_COND", "CHANNELVIEW", "CHANNELVIEW.LOGIC_ID", m_omdsReader.singleAttribute(logic_id));
0115 
0116     logicID.fillVariable("NAME", ecid_name);
0117 
0118     if (ecid_name == "EB")
0119       eb_lsb = etSat / 1024;
0120     else if ("EE" == ecid_name)
0121       ee_lsb = etSat / 1024;
0122     else {
0123       edm::LogError("L1-O2O")
0124           << "Problem with L1CaloEcalScale  LOGIC_ID.  unable to find channel view with appropiate logic id";
0125       return std::unique_ptr<L1CaloEcalScale>();
0126     }
0127   }
0128   //     std::cout << " eb lsb " << eb_lsb << " ee_lsb " << ee_lsb << std::endl;
0129 
0130   std::vector<std::string> grpLUT;
0131   grpLUT.push_back("GROUP_ID");
0132   grpLUT.push_back("LUT_ID");
0133   grpLUT.push_back("LUT_VALUE");
0134 
0135   l1t::OMDSReader::QueryResults lutGrpResults = m_omdsReader.basicQuery(grpLUT,
0136                                                                         "CMS_ECAL_CONF",
0137                                                                         "FE_LUT_PER_GROUP_DAT",
0138                                                                         "FE_LUT_PER_GROUP_DAT.LUT_CONF_ID",
0139                                                                         m_omdsReader.singleAttribute(objectKey));
0140 
0141   if (lutGrpResults.queryFailed() || (lutGrpResults.numberRows() % 1024 != 0))  // check query successful
0142   {
0143     edm::LogError("L1-O2O") << "Problem with L1CaloEcalScale key.  No group info";
0144     return std::unique_ptr<L1CaloEcalScale>();
0145   }
0146 
0147   int nEntries = lutGrpResults.numberRows();
0148   for (int i = 0; i < nEntries; i++) {
0149     int group, lutID;
0150     float lutValue;
0151 
0152     lutGrpResults.fillVariableFromRow("GROUP_ID", i, group);
0153     if (groupInfo.find(group) == groupInfo.end()) {
0154       groupInfo[group] = new std::vector<int>;
0155       (groupInfo[group])->resize(1024);
0156     }
0157 
0158     lutGrpResults.fillVariableFromRow("LUT_ID", i, lutID);
0159     lutGrpResults.fillVariableFromRow("LUT_VALUE", i, lutValue);
0160     groupInfo[group]->at(lutID) = (int)lutValue;
0161   }
0162 
0163   std::map<int, std::vector<int> > tpgValueMap;
0164 
0165   std::map<int, std::vector<int>*>::iterator grpIt;
0166   for (grpIt = groupInfo.begin(); grpIt != groupInfo.end(); ++grpIt) {
0167     const std::vector<int>* lut_ = grpIt->second;
0168 
0169     std::vector<int> tpgValue;
0170     tpgValue.resize(256);
0171     int lastValue = 0;
0172     for (int tpg = 0; tpg < 256; tpg++) {
0173       for (int i = 0; i < 1024; i++) {
0174         if (tpg == (0xff & (lut_->at(i)))) {
0175           tpgValue[tpg] = i;
0176           lastValue = i;
0177           break;
0178         }
0179         tpgValue[tpg] = lastValue;
0180       }
0181     }
0182     tpgValueMap[grpIt->first] = tpgValue;
0183   }
0184 
0185   std::vector<std::string> groupMap;
0186   groupMap.push_back("LOGIC_ID");
0187   groupMap.push_back("GROUP_ID");
0188 
0189   l1t::OMDSReader::QueryResults grpMapResults = m_omdsReader.basicQuery(groupMap,
0190                                                                         "CMS_ECAL_CONF",
0191                                                                         "FE_CONFIG_LUT_DAT",
0192                                                                         "FE_CONFIG_LUT_DAT.LUT_CONF_ID",
0193                                                                         m_omdsReader.singleAttribute(objectKey));
0194   if (grpMapResults.queryFailed() || (grpMapResults.numberRows() == 0))  // check query successful
0195   {
0196     edm::LogError("L1-O2O") << "Problem with L1CaloEcalScale key. No fe_config_lut_dat info";
0197     return std::unique_ptr<L1CaloEcalScale>();
0198   }
0199 
0200   nEntries = grpMapResults.numberRows();
0201   for (int i = 0; i < nEntries; ++i) {
0202     std::string ecid_name;
0203     int logic_id;
0204     grpMapResults.fillVariableFromRow("LOGIC_ID", i, logic_id);
0205     int group_id;
0206     grpMapResults.fillVariableFromRow("GROUP_ID", i, group_id);
0207     //       if(logic_id >= 2100001901 && logic_id <= 2100001916)
0208     //   std::cout<< "missing logic id found " <<logic_id <<std::endl;
0209     l1t::OMDSReader::QueryResults IDResults = m_omdsReader.basicQuery(
0210         IDStrings, "CMS_ECAL_COND", "CHANNELVIEW", "CHANNELVIEW.LOGIC_ID", m_omdsReader.singleAttribute(logic_id));
0211     if (paramResults.queryFailed() || (paramResults.numberRows() == 0))  // check query successful
0212     {
0213       edm::LogError("L1-O2O") << "Problem with L1CaloEcalScale key.  Unable to find logic_id channel view";
0214       return std::unique_ptr<L1CaloEcalScale>();
0215     }
0216     for (int j = 0; j < IDResults.numberRows(); j++) {
0217       std::string ecid_name, maps_to;
0218 
0219       IDResults.fillVariableFromRow("NAME", j, ecid_name);
0220       IDResults.fillVariableFromRow("maps_to", j, maps_to);
0221       if (logic_id >= 2100001901 && logic_id <= 2100001916)
0222         //     std::cout << " name " << ecid_name << " maps to " << maps_to <<std::endl;
0223         if (ecid_name != maps_to) {
0224           continue;  // make sure they match
0225         }
0226       if (ecid_name == "EB_trigger_tower" || ecid_name == "EE_trigger_tower") {
0227         int id1, id2;
0228         IDResults.fillVariableFromRow("ID1", j, id1);
0229         IDResults.fillVariableFromRow("ID2", j, id2);
0230 
0231         if (ecid_name == "EB_trigger_tower")
0232           id1 += 36;  //lowest TCC for barrel 37
0233         EcalTrigTowerDetId temp = theMapping_->getTrigTowerDetId(id1, id2);
0234         /*     if(ecid_name == "EE_trigger_tower"){
0235          int testID = theMapping_->TCCid(temp);
0236 
0237          if( testID != id1 ){
0238                    std::cout << " unmatched mapping testID " <<testID <<std::endl;
0239            std::cout << "id1 " << id1 << " id2 " <<id2<< " iphi " << temp.iphi() <<"  ieta " << temp.ieta() <<std::endl;
0240          }
0241        }
0242        if(ecid_name == "EB_trigger_tower"){
0243          int testID = theMapping_->TCCid(temp);
0244          if( testID != id1 ){
0245            std::cout << " unmatched mapping testID " <<testID <<std::endl;
0246            std::cout << "id1 " << id1 << " id2 " <<id2<< " iphi " << temp.iphi() <<"  ieta " << temp.ieta() <<std::endl;
0247          }
0248        }
0249        */
0250         //     if(temp.ieta() == -18 || temp.ietaAbs() == 28)
0251         //     if(logic_id >= 2100001901 && logic_id <= 2100001916)
0252 
0253         lutGrpMap->setValue(temp, group_id);  // assume ee has less than 68 tt
0254         break;
0255       }
0256     }
0257   }
0258 
0259   const EcalTPGGroups::EcalTPGGroupsMap& gMap = lutGrpMap->getMap();
0260 
0261   auto ecalScale = std::make_unique<L1CaloEcalScale>(0);
0262 
0263   for (unsigned short ieta = 1; ieta <= L1CaloEcalScale::nBinEta; ++ieta) {
0264     EcalSubdetector subdet = (ieta <= 17) ? EcalBarrel : EcalEndcap;
0265     double et_lsb = (ieta <= 17) ? eb_lsb : ee_lsb;
0266     for (int pos = 0; pos <= 1; pos++) {
0267       int zside = (int)pow(-1, pos);
0268 
0269       //     std::cout << "ieta " <<zside*ieta ;
0270       for (int iphi = 1; iphi <= 72; iphi++) {
0271         if (!EcalTrigTowerDetId::validDetId(zside, subdet, ieta, iphi))
0272           continue;
0273         EcalTrigTowerDetId test(zside, subdet, ieta, iphi);
0274         EcalTPGGroups::EcalTPGGroupsMapItr itLut = gMap.find(test);
0275         if (itLut != gMap.end()) {
0276           //         std::cout << " non mapped section iphi " << iphi << " ieta " <<ieta << " tccid " << theMapping_->TCCid(test) << " iTT " << theMapping_->iTT(test)<< std::endl;
0277           std::vector<int> tpgValue = tpgValueMap[itLut->second];
0278 
0279           for (unsigned short irank = 0; irank < L1CaloEcalScale::nBinRank; ++irank) {
0280             ecalScale->setBin(irank, ieta, zside, et_lsb * tpgValue[irank]);
0281 
0282             //       std::cout << " irank " << irank << " etValue " << et_lsb*tpgValue[irank] << std::endl;
0283           }
0284 
0285           break;
0286         }
0287       }
0288     }
0289   }
0290 
0291   //     ecalScale->print(std::cout);
0292 
0293   // ------------ method called to produce the data  ------------
0294   return ecalScale;
0295 }
0296 //define this as a plug-in
0297 DEFINE_FWK_EVENTSETUP_MODULE(L1CaloEcalScaleConfigOnlineProd);