Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include "CondTools/Hcal/interface/HcalAutoPedestalValidator.h"

HcalAutoPedestalValidator::HcalAutoPedestalValidator(edm::ParameterSet const& ps) {
  outfile = ps.getUntrackedParameter<std::string>("outFile", "changed.bool");
  epsilon = ps.getUntrackedParameter<double>("deltaP", .25);
  m_tok1 = esConsumes<HcalPedestals, HcalPedestalsRcd>(edm::ESInputTag("", "update"));
  m_tok2 = esConsumes<HcalPedestals, HcalPedestalsRcd>(edm::ESInputTag("", "reference"));
}

HcalAutoPedestalValidator::~HcalAutoPedestalValidator() {}

void HcalAutoPedestalValidator::analyze(const edm::Event& ev, const edm::EventSetup& es) {
  using namespace edm::eventsetup;
  // get fake pedestals from file ("new pedestals")
  const HcalPedestals* myNewPeds = &es.getData(m_tok1);

  // get DB pedestals from Frontier/OrcoX ("reference")
  const HcalPedestals* myRefPeds = &es.getData(m_tok2);

  std::vector<DetId> listNewChan = myNewPeds->getAllChannels();
  std::vector<DetId> listRefChan = myRefPeds->getAllChannels();
  std::vector<DetId>::iterator cell;
  bool failflag = false;
  for (std::vector<DetId>::iterator it = listRefChan.begin(); it != listRefChan.end(); it++) {
    DetId mydetid = *it;
    cell = std::find(listNewChan.begin(), listNewChan.end(), mydetid);
    if (cell == listNewChan.end()) {
      continue;
    } else {
      const float* values = (myNewPeds->getValues(mydetid))->getValues();
      const float* oldvalue = (myRefPeds->getValues(mydetid))->getValues();
      if ((*values == 0) && (*(values + 1) == 0) && (*(values + 2) == 0) && (*(values + 3) == 0))
        continue;
      if ((*oldvalue - *values) + (*(oldvalue + 1) - *(values + 1)) + (*(oldvalue + 2) - *(values + 2)) +
              (*(oldvalue + 3) - *(values + 3)) / 4 >
          epsilon) {
        std::cout << "Channel " << std::hex << mydetid.rawId() << " Values differ by " << std::dec
                  << (*oldvalue - *values) << "  " << (*(oldvalue + 1) - *(values + 1)) << "  "
                  << (*(oldvalue + 2) - *(values + 2)) << "  " << (*(oldvalue + 3) - *(values + 3)) << std::endl;
        failflag = true;
      }
      listNewChan.erase(cell);  // fix 25.02.08
    }
  }

  if (!failflag)
    std::cout << "These are identical to within deltaP" << std::endl;
  if (failflag) {
    // if changed, this creates the empty file changed.bool which the auto job uses as a flag
    std::ofstream outStream3(outfile.c_str());
    std::cout << "--- Pedestals changed! ---" << std::endl;
  }
}

DEFINE_FWK_MODULE(HcalAutoPedestalValidator);