Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:08

0001 #include "CondTools/Hcal/interface/HcalQIEDataCheck.h"
0002 
0003 HcalQIEDataCheck::HcalQIEDataCheck(edm::ParameterSet const& ps) {
0004   outfile = ps.getUntrackedParameter<std::string>("outFile", "null");
0005   dumprefs = ps.getUntrackedParameter<std::string>("dumpRefQIEsTo", "null");
0006   dumpupdate = ps.getUntrackedParameter<std::string>("dumpUpdateQIEsTo", "null");
0007   checkemapflag = ps.getUntrackedParameter<bool>("checkEmap", false);
0008   validateflag = ps.getUntrackedParameter<bool>("validateQIEs", false);
0009   //  epsilon = ps.getUntrackedParameter<double>("deltaQIE",0);
0010   m_tok1 = esConsumes<HcalQIEData, HcalQIEDataRcd>(edm::ESInputTag("", "update"));
0011   m_tok2 = esConsumes<HcalQIEData, HcalQIEDataRcd>(edm::ESInputTag("", "reference"));
0012   m_tokmap = esConsumes<HcalElectronicsMap, HcalElectronicsMapRcd>(edm::ESInputTag("", "reference"));
0013 }
0014 
0015 HcalQIEDataCheck::~HcalQIEDataCheck() {}
0016 
0017 void HcalQIEDataCheck::analyze(const edm::Event& ev, const edm::EventSetup& es) {
0018   using namespace edm::eventsetup;
0019 
0020   const HcalQIEData* myNewQIEs = &es.getData(m_tok1);
0021   const HcalQIEData* myRefQIEs = &es.getData(m_tok2);
0022   const HcalElectronicsMap* myRefEMap = &es.getData(m_tokmap);
0023 
0024   if (dumpupdate != "null") {
0025     std::ofstream outStream(dumpupdate.c_str());
0026     std::cout << "--- Dumping QIEs - update ---" << std::endl;
0027     HcalDbASCIIIO::dumpObject(outStream, (*myNewQIEs));
0028   }
0029   if (dumprefs != "null") {
0030     std::ofstream outStream2(dumprefs.c_str());
0031     std::cout << "--- Dumping QIEs - reference ---" << std::endl;
0032     HcalDbASCIIIO::dumpObject(outStream2, (*myRefQIEs));
0033   }
0034 
0035   // first get the list of all channels from the update
0036   std::vector<DetId> listNewChan = myNewQIEs->getAllChannels();
0037 
0038   HcalQIEData* resultQIEs = new HcalQIEData(myRefQIEs->topo());
0039   std::vector<DetId> listRefChan = myRefQIEs->getAllChannels();
0040   std::vector<DetId>::iterator cell;
0041 
0042   if (validateflag) {
0043     for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
0044       DetId mydetid = *it;
0045       cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
0046       if (cell == listNewChan.end())  // not present in new list
0047       {
0048         throw cms::Exception("DataDoesNotMatch") << "Value not found in reference" << std::endl;
0049       } else  // present in new list
0050       {
0051         const HcalQIECoder* first = myNewQIEs->getCoder(mydetid);
0052         const HcalQIECoder* second = myRefQIEs->getCoder(mydetid);
0053         {
0054           bool failflag = false;
0055           if (first->offset(0, 0) != second->offset(0, 0))
0056             failflag = true;
0057           if (first->offset(0, 1) != second->offset(0, 1))
0058             failflag = true;
0059           if (first->offset(0, 2) != second->offset(0, 2))
0060             failflag = true;
0061           if (first->offset(0, 3) != second->offset(0, 3))
0062             failflag = true;
0063           if (first->offset(1, 0) != second->offset(1, 0))
0064             failflag = true;
0065           if (first->offset(1, 1) != second->offset(1, 1))
0066             failflag = true;
0067           if (first->offset(1, 2) != second->offset(1, 2))
0068             failflag = true;
0069           if (first->offset(1, 3) != second->offset(1, 3))
0070             failflag = true;
0071           if (first->offset(2, 0) != second->offset(2, 0))
0072             failflag = true;
0073           if (first->offset(2, 1) != second->offset(2, 1))
0074             failflag = true;
0075           if (first->offset(2, 2) != second->offset(2, 2))
0076             failflag = true;
0077           if (first->offset(2, 3) != second->offset(2, 3))
0078             failflag = true;
0079           if (first->offset(3, 0) != second->offset(3, 0))
0080             failflag = true;
0081           if (first->offset(3, 1) != second->offset(3, 1))
0082             failflag = true;
0083           if (first->offset(3, 2) != second->offset(3, 2))
0084             failflag = true;
0085           if (first->offset(3, 3) != second->offset(3, 3))
0086             failflag = true;
0087           if (first->slope(0, 0) != second->slope(0, 0))
0088             failflag = true;
0089           if (first->slope(0, 1) != second->slope(0, 1))
0090             failflag = true;
0091           if (first->slope(0, 2) != second->slope(0, 2))
0092             failflag = true;
0093           if (first->slope(0, 3) != second->slope(0, 3))
0094             failflag = true;
0095           if (first->slope(1, 0) != second->slope(1, 0))
0096             failflag = true;
0097           if (first->slope(1, 1) != second->slope(1, 1))
0098             failflag = true;
0099           if (first->slope(1, 2) != second->slope(1, 2))
0100             failflag = true;
0101           if (first->slope(1, 3) != second->slope(1, 3))
0102             failflag = true;
0103           if (first->slope(2, 0) != second->slope(2, 0))
0104             failflag = true;
0105           if (first->slope(2, 1) != second->slope(2, 1))
0106             failflag = true;
0107           if (first->slope(2, 2) != second->slope(2, 2))
0108             failflag = true;
0109           if (first->slope(2, 3) != second->slope(2, 3))
0110             failflag = true;
0111           if (first->slope(3, 0) != second->slope(3, 0))
0112             failflag = true;
0113           if (first->slope(3, 1) != second->slope(3, 1))
0114             failflag = true;
0115           if (first->slope(3, 2) != second->slope(3, 2))
0116             failflag = true;
0117           if (first->slope(3, 3) != second->slope(3, 3))
0118             failflag = true;
0119           if (failflag)
0120             throw cms::Exception("DataDoesNotMatch") << "Values are do not match";
0121         }
0122         listNewChan.erase(cell);  // fix 25.02.08
0123       }
0124     }
0125     std::cout << "These are identical" << std::endl;
0126   }
0127 
0128   //  if(epsilon!=0){
0129   //implement compare qies -- different epsilon for slope and offset?
0130   //  }
0131 
0132   if (outfile != "null") {
0133     for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
0134       DetId mydetid = *it;
0135       cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
0136       if (cell == listNewChan.end())  // not present in new list
0137       {
0138         const HcalQIECoder* myCoder = myRefQIEs->getCoder(mydetid);
0139         std::cout << "o";
0140         resultQIEs->addCoder(*myCoder);
0141       } else  // present in new list
0142       {
0143         const HcalQIECoder* myCoder = myNewQIEs->getCoder(mydetid);
0144         std::cout << "n";
0145         resultQIEs->addCoder(*myCoder);
0146         listNewChan.erase(cell);  // fix 25.02.08
0147       }
0148     }
0149     for (std::vector<DetId>::iterator it = listNewChan.begin(); it != listNewChan.end(); it++)  // fix 25.02.08
0150     {
0151       DetId mydetid = *it;
0152       const HcalQIECoder* myCoder = myNewQIEs->getCoder(mydetid);
0153       std::cout << "N";
0154       resultQIEs->addCoder(*myCoder);
0155     }
0156 
0157     std::ofstream outStream3(outfile.c_str());
0158     std::cout << "--- Dumping QIEs - the combined ones ---" << std::endl;
0159     resultQIEs->sort();
0160     HcalDbASCIIIO::dumpObject(outStream3, (*resultQIEs));
0161   }
0162 
0163   std::cout << std::endl;
0164   if (checkemapflag) {
0165     std::vector<DetId> listResult = resultQIEs->getAllChannels();
0166     // get the e-map list of channels
0167     std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
0168     for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++) {
0169       DetId mydetid = DetId(it->rawId());
0170       if (std::find(listResult.begin(), listResult.end(), mydetid) == listResult.end()) {
0171         std::cout << "Conditions not found for DetId = " << HcalGenericDetId(it->rawId()) << std::endl;
0172       }
0173     }
0174   }
0175 }
0176 
0177 DEFINE_FWK_MODULE(HcalQIEDataCheck);