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