Back to home page

Project CMSSW displayed by LXR

 
 

    


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   // get fake pedestals from file ("new pedestals")
0021   const HcalPedestals* myNewPeds = &es.getData(m_tok1);
0022 
0023   // get DB pedestals from Frontier/OrcoX ("reference")
0024   const HcalPedestals* myRefPeds = &es.getData(m_tok2);
0025 
0026   // get e-map from reference
0027   const HcalElectronicsMap* myRefEMap = &es.getData(m_tokmap);
0028 
0029   // dump pedestals:
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())  // not present in new list, take old pedestals
0050       {
0051         throw cms::Exception("DataDoesNotMatch") << "Channel missing";
0052         failflag = true;
0053         break;
0054       } else  // present in new list, take new pedestals
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         // compare the values of the pedestals for valid channels between update and reference
0065 
0066         listNewChan.erase(cell);  // fix 25.02.08
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);  // fix 25.02.08
0093       }
0094     }
0095     if (!failflag)
0096       std::cout << "These are identical to within deltaP" << std::endl;
0097   }
0098   if (!(outfile == "null")) {
0099     // first get the list of all channels from the update
0100     std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
0101 
0102     // go through list of valid channels from reference, look up if pedestals exist for update
0103     // push back into new vector the corresponding updated pedestals,
0104     // or if it doesn't exist, the reference
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())  // not present in new list, take old pedestals
0112       {
0113         //   bool addValue (DetId fId, const float fValues [4]);
0114         const HcalPedestal* item = myRefPeds->getValues(mydetid);
0115         std::cout << "o";
0116         resultPeds->addValues(*item);
0117       } else  // present in new list, take new pedestals
0118       {
0119         const HcalPedestal* item = myNewPeds->getValues(mydetid);
0120         std::cout << "n";
0121         resultPeds->addValues(*item);
0122         // compare the values of the pedestals for valid channels between update and reference
0123         listNewChan.erase(cell);  // fix 25.02.08
0124       }
0125     }
0126 
0127     for (std::vector<DetId>::iterator it = listNewChan.begin(); it != listNewChan.end(); it++)  // fix 25.02.08
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     // get the e-map list of channels
0139     std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
0140     // look up if emap channels are all present in pedestals, if not then cerr
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         //  std::cout << "id = " << mygenid << ", hashed id = " << mygenid.hashedId() << std::endl;
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     // dump the resulting list of pedestals into a file
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   // const float* values = myped->getValues (channelID);
0159   //    if (values) std::cout << "pedestals for channel " << channelID << ": "
0160   //              << values [0] << '/' << values [1] << '/' << values [2] << '/' << values [3] << std::endl;
0161 }
0162 
0163 //vecDetId HcalPedestalsCheck::getMissingDetIds(vector<HcalPedestals> & myPedestals)
0164 //{
0165 //  HcalGeometry myHcalGeometry;
0166 //  // get the valid detid from the various subdetectors
0167 //  vecDetId validHB = myHcalGeometry.getValidDetIds(Hcal,HcalBarrel);  // check these numbers
0168 //  vecDetId validHE = myHcalGeometry.getValidDetIds(Hcal,HcalEndcap);
0169 //  vecDetId validHF = myHcalGeometry.getValidDetIds(Hcal,HcalForward);
0170 //  vecDetId validHO = myHcalGeometry.getValidDetIds(Hcal,HcalOuter);
0171 //  vecDetId validZDC = myHcalGeometry.getValidDetIds(Calo,2);
0172 //
0173 //  // check if everything is there in pedestals
0174 //
0175 //
0176 //}
0177 
0178 DEFINE_FWK_MODULE(HcalPedestalsCheck);