Back to home page

Project CMSSW displayed by LXR

 
 

    


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   // get fake pedestals from file ("new pedestals")
0021   const HcalPedestalWidths* myNewPeds = &es.getData(m_tok1);
0022 
0023   // get DB pedestals from Frontier/OrcoX ("reference")
0024   const HcalPedestalWidths* 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 (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   // first get the list of all channels from the update
0041   std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
0042 
0043   // go through list of valid channels from reference, look up if pedestals exist for update
0044   // push back into new vector the corresponding updated pedestals,
0045   // or if it doesn't exist, the reference
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())  // not present in new list, take old pedestals
0055       {
0056         throw cms::Exception("DataDoesNotMatch") << "Value not found in reference" << std::endl;
0057       } else  // present in new list, take new pedestals
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);  // fix 25.02.08
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())  // not present in new list, take old pedestals
0081       {
0082         throw cms::Exception("DataDoesNotMatch") << "Value not found in reference" << std::endl;
0083       } else  // present in new list, take new pedestals
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);  // fix 25.02.08
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())  // not present in new list, take old pedestals
0106       {
0107         const HcalPedestalWidth* mywidth = myRefPeds->getValues(mydetid);
0108         std::cout << "o";
0109         resultPeds->addValues(*mywidth);
0110       } else  // present in new list, take new pedestals
0111       {
0112         const HcalPedestalWidth* mywidth = myNewPeds->getValues(mydetid);
0113         std::cout << "n";
0114         resultPeds->addValues(*mywidth);
0115 
0116         listNewChan.erase(cell);  // fix 25.02.08
0117       }
0118     }
0119 
0120     for (std::vector<DetId>::iterator it = listNewChan.begin(); it != listNewChan.end(); it++)  // fix 25.02.08
0121     {
0122       DetId mydetid = *it;
0123       const HcalPedestalWidth* mywidth = myNewPeds->getValues(mydetid);
0124       std::cout << "N";
0125       resultPeds->addValues(*mywidth);
0126     }
0127     // dump the resulting list of pedestals into a file
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     // get the e-map list of channels
0136     std::vector<HcalGenericDetId> listEMap = myRefEMap->allPrecisionId();
0137     // look up if emap channels are all present in pedestals, if not then cerr
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 //vecDetId HcalPedestalWidthsCheck::getMissingDetIds(vector<HcalPedestalWidths> & myPedestalWidths)
0148 //{
0149 //  HcalGeometry myHcalGeometry;
0150 //  // get the valid detid from the various subdetectors
0151 //  vecDetId validHB = myHcalGeometry.getValidDetIds(Hcal,HcalBarrel);  // check these numbers
0152 //  vecDetId validHE = myHcalGeometry.getValidDetIds(Hcal,HcalEndcap);
0153 //  vecDetId validHF = myHcalGeometry.getValidDetIds(Hcal,HcalForward);
0154 //  vecDetId validHO = myHcalGeometry.getValidDetIds(Hcal,HcalOuter);
0155 //  vecDetId validZDC = myHcalGeometry.getValidDetIds(Calo,2);
0156 //
0157 //  // check if everything is there in pedestals
0158 //
0159 //
0160 //}
0161 
0162 DEFINE_FWK_MODULE(HcalPedestalWidthsCheck);