Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:11

0001 #include "CondTools/Hcal/interface/HcalAutoPedestalValidator.h"
0002 
0003 HcalAutoPedestalValidator::HcalAutoPedestalValidator(edm::ParameterSet const& ps) {
0004   outfile = ps.getUntrackedParameter<std::string>("outFile", "changed.bool");
0005   epsilon = ps.getUntrackedParameter<double>("deltaP", .25);
0006   m_tok1 = esConsumes<HcalPedestals, HcalPedestalsRcd>(edm::ESInputTag("", "update"));
0007   m_tok2 = esConsumes<HcalPedestals, HcalPedestalsRcd>(edm::ESInputTag("", "reference"));
0008 }
0009 
0010 HcalAutoPedestalValidator::~HcalAutoPedestalValidator() {}
0011 
0012 void HcalAutoPedestalValidator::analyze(const edm::Event& ev, const edm::EventSetup& es) {
0013   using namespace edm::eventsetup;
0014   // get fake pedestals from file ("new pedestals")
0015   const HcalPedestals* myNewPeds = &es.getData(m_tok1);
0016 
0017   // get DB pedestals from Frontier/OrcoX ("reference")
0018   const HcalPedestals* myRefPeds = &es.getData(m_tok2);
0019 
0020   std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
0021   std::vector<DetId> listRefChan = myRefPeds->getAllChannels();
0022   std::vector<DetId>::iterator cell;
0023   bool failflag = false;
0024   for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
0025     DetId mydetid = *it;
0026     cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
0027     if (cell == listNewChan.end()) {
0028       continue;
0029     } else {
0030       const float* values = (myNewPeds->getValues(mydetid))->getValues();
0031       const float* oldvalue = (myRefPeds->getValues(mydetid))->getValues();
0032       if ((*values == 0) && (*(values + 1) == 0) && (*(values + 2) == 0) && (*(values + 3) == 0))
0033         continue;
0034       if ((*oldvalue - *values) + (*(oldvalue + 1) - *(values + 1)) + (*(oldvalue + 2) - *(values + 2)) +
0035               (*(oldvalue + 3) - *(values + 3)) / 4 >
0036           epsilon) {
0037         std::cout << "Channel " << std::hex << mydetid.rawId() << " Values differ by " << std::dec
0038                   << (*oldvalue - *values) << "  " << (*(oldvalue + 1) - *(values + 1)) << "  "
0039                   << (*(oldvalue + 2) - *(values + 2)) << "  " << (*(oldvalue + 3) - *(values + 3)) << std::endl;
0040         failflag = true;
0041       }
0042       listNewChan.erase(cell);  // fix 25.02.08
0043     }
0044   }
0045 
0046   if (!failflag)
0047     std::cout << "These are identical to within deltaP" << std::endl;
0048   if (failflag) {
0049     // if changed, this creates the empty file changed.bool which the auto job uses as a flag
0050     std::ofstream outStream3(outfile.c_str());
0051     std::cout << "--- Pedestals changed! ---" << std::endl;
0052   }
0053 }
0054 
0055 DEFINE_FWK_MODULE(HcalAutoPedestalValidator);