File indexing completed on 2024-04-06 12:03:08
0001 #include "CondTools/Hcal/interface/HcalPedestalWidthsCheck.h"
0002
0003 HcalPedestalWidthsCheck::HcalPedestalWidthsCheck(edm::ParameterSet const& ps) {
0004 outfile = ps.getUntrackedParameter<std::string>("outFile", "null");
0005 dumprefs = ps.getUntrackedParameter<std::string>("dumpRefWidthsTo", "null");
0006 dumpupdate = ps.getUntrackedParameter<std::string>("dumpUpdateWidthsTo", "null");
0007 checkemapflag = ps.getUntrackedParameter<bool>("checkEmap", false);
0008 validateflag = ps.getUntrackedParameter<bool>("validateWidths", false);
0009 epsilon = ps.getUntrackedParameter<double>("deltaW", 0);
0010 m_tok1 = esConsumes<HcalPedestalWidths, HcalPedestalWidthsRcd>(edm::ESInputTag("", "update"));
0011 m_tok2 = esConsumes<HcalPedestalWidths, HcalPedestalWidthsRcd>(edm::ESInputTag("", "reference"));
0012 m_tokmap = esConsumes<HcalElectronicsMap, HcalElectronicsMapRcd>(edm::ESInputTag("", "reference"));
0013 }
0014
0015 HcalPedestalWidthsCheck::~HcalPedestalWidthsCheck() {}
0016
0017 void HcalPedestalWidthsCheck::analyze(const edm::Event& ev, const edm::EventSetup& es) {
0018 using namespace edm::eventsetup;
0019
0020
0021 const HcalPedestalWidths* myNewPeds = &es.getData(m_tok1);
0022
0023
0024 const HcalPedestalWidths* myRefPeds = &es.getData(m_tok2);
0025
0026
0027 const HcalElectronicsMap* myRefEMap = &es.getData(m_tokmap);
0028
0029
0030 if (dumpupdate != "null") {
0031 std::ofstream outStream(dumpupdate.c_str());
0032 std::cout << "--- Dumping PedestalWidths - update ---" << std::endl;
0033 HcalDbASCIIIO::dumpObject(outStream, (*myNewPeds));
0034 }
0035 if (dumprefs != "null") {
0036 std::ofstream outStream2(dumprefs.c_str());
0037 std::cout << "--- Dumping PedestalWidths - reference ---" << std::endl;
0038 HcalDbASCIIIO::dumpObject(outStream2, (*myRefPeds));
0039 }
0040
0041 std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
0042
0043
0044
0045
0046 HcalPedestalWidths* resultPeds = new HcalPedestalWidths(myRefPeds->topo(), myRefPeds->isADC());
0047 std::vector<DetId> listRefChan = myRefPeds->getAllChannels();
0048 std::vector<DetId>::iterator cell;
0049
0050 if (validateflag) {
0051 for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
0052 DetId mydetid = *it;
0053 cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
0054 if (cell == listNewChan.end())
0055 {
0056 throw cms::Exception("DataDoesNotMatch") << "Value not found in reference" << std::endl;
0057 } else
0058 {
0059 const HcalPedestalWidth* first = myNewPeds->getValues(mydetid);
0060 const HcalPedestalWidth* second = myRefPeds->getValues(mydetid);
0061 const float* newwidth = first->getValues();
0062 const float* oldwidth = second->getValues();
0063 if ((*newwidth != *oldwidth) || (*(newwidth + 1) != *(oldwidth + 1)) || (*(newwidth + 2) != *(oldwidth + 2)) ||
0064 (*(newwidth + 3) != *(oldwidth + 3)) || (*(newwidth + 4) != *(oldwidth + 4)) ||
0065 (*(newwidth + 5) != *(oldwidth + 5)) || (*(newwidth + 6) != *(oldwidth + 6)) ||
0066 (*(newwidth + 7) != *(oldwidth + 7)) || (*(newwidth + 8) != *(oldwidth + 8)) ||
0067 (*(newwidth + 9) != *(oldwidth + 9))) {
0068 throw cms::Exception("DataDoesNotMatch") << "Values are not identical" << std::endl;
0069 }
0070 listNewChan.erase(cell);
0071 }
0072 }
0073 std::cout << "These are identical" << std::endl;
0074 }
0075
0076 if (epsilon != 0) {
0077 for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
0078 DetId mydetid = *it;
0079 cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
0080 if (cell == listNewChan.end())
0081 {
0082 throw cms::Exception("DataDoesNotMatch") << "Value not found in reference" << std::endl;
0083 } else
0084 {
0085 const HcalPedestalWidth* first = myNewPeds->getValues(mydetid);
0086 const HcalPedestalWidth* second = myRefPeds->getValues(mydetid);
0087 const float* newwidth = first->getValues();
0088 const float* oldwidth = second->getValues();
0089 if (fabs(*newwidth - *oldwidth) > epsilon || fabs(*(newwidth + 1) - *(oldwidth + 1)) > epsilon ||
0090 fabs(*(newwidth + 2) - *(oldwidth + 2)) > epsilon || fabs(*(newwidth + 3) - *(oldwidth + 3)) > epsilon ||
0091 fabs(*(newwidth + 4) - *(oldwidth + 4)) > epsilon || fabs(*(newwidth + 5) - *(oldwidth + 5)) > epsilon ||
0092 fabs(*(newwidth + 6) - *(oldwidth + 6)) > epsilon || fabs(*(newwidth + 7) - *(oldwidth + 7)) > epsilon ||
0093 fabs(*(newwidth + 8) - *(oldwidth + 8)) > epsilon || fabs(*(newwidth + 9) - *(oldwidth + 9)) > epsilon) {
0094 throw cms::Exception("DataDoesNotMatch") << "Values differ by more than deltaW" << std::endl;
0095 }
0096 listNewChan.erase(cell);
0097 }
0098 }
0099 std::cout << "These are identical" << std::endl;
0100 }
0101 if (outfile != "null") {
0102 for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
0103 DetId mydetid = *it;
0104 cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
0105 if (cell == listNewChan.end())
0106 {
0107 const HcalPedestalWidth* mywidth = myRefPeds->getValues(mydetid);
0108 std::cout << "o";
0109 resultPeds->addValues(*mywidth);
0110 } else
0111 {
0112 const HcalPedestalWidth* mywidth = myNewPeds->getValues(mydetid);
0113 std::cout << "n";
0114 resultPeds->addValues(*mywidth);
0115
0116 listNewChan.erase(cell);
0117 }
0118 }
0119
0120 for (std::vector<DetId>::iterator it = listNewChan.begin(); it != listNewChan.end(); it++)
0121 {
0122 DetId mydetid = *it;
0123 const HcalPedestalWidth* mywidth = myNewPeds->getValues(mydetid);
0124 std::cout << "N";
0125 resultPeds->addValues(*mywidth);
0126 }
0127
0128 std::ofstream outStream3(outfile.c_str());
0129 std::cout << "--- Dumping PedestalWidths - the combined ones ---" << std::endl;
0130 HcalDbASCIIIO::dumpObject(outStream3, (*resultPeds));
0131 }
0132 std::cout << std::endl;
0133 if (checkemapflag) {
0134 std::vector<DetId> listResult = resultPeds->getAllChannels();
0135
0136 std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
0137
0138 for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++) {
0139 DetId mydetid = DetId(it->rawId());
0140 if (std::find(listResult.begin(), listResult.end(), mydetid) == listResult.end()) {
0141 std::cout << "Conditions not found for DetId = " << HcalGenericDetId(it->rawId()) << std::endl;
0142 }
0143 }
0144 }
0145 }
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162 DEFINE_FWK_MODULE(HcalPedestalWidthsCheck);