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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#include "DQM/RPCMonitorClient/interface/RPCDataCertification.h"
#include "DQM/RPCMonitorClient/interface/RPCSummaryMapHisto.h"

#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include <fmt/format.h>

RPCDataCertification::RPCDataCertification(const edm::ParameterSet& ps) {
  numberOfDisks_ = ps.getUntrackedParameter<int>("NumberOfEndcapDisks", 4);
  FEDRange_.first = ps.getUntrackedParameter<unsigned int>("MinimumRPCFEDId", 790);
  FEDRange_.second = ps.getUntrackedParameter<unsigned int>("MaximumRPCFEDId", 792);
  NumberOfFeds_ = FEDRange_.second - FEDRange_.first + 1;
  offlineDQM_ = ps.getUntrackedParameter<bool>("OfflineDQM", true);

  runInfoToken_ = esConsumes<edm::Transition::EndLuminosityBlock>();

  init_ = false;
  defaultValue_ = 1.;
}

void RPCDataCertification::beginJob() {}

void RPCDataCertification::dqmEndLuminosityBlock(DQMStore::IBooker& ibooker,
                                                 DQMStore::IGetter& igetter,
                                                 edm::LuminosityBlock const& LB,
                                                 edm::EventSetup const& setup) {
  if (!init_) {
    this->checkFED(setup);

    if (!offlineDQM_) {
      this->myBooker(ibooker);
    }
  }
}

void RPCDataCertification::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
  if (offlineDQM_) {
    this->myBooker(ibooker);
  }
}

void RPCDataCertification::checkFED(edm::EventSetup const& setup) {
  double defaultValue = 1.;

  if (auto runInfoRec = setup.tryToGet<RunInfoRcd>()) {
    defaultValue = -1;
    //get fed summary information
    auto sumFED = runInfoRec->get(runInfoToken_);
    const std::vector<int> FedsInIds = sumFED.m_fed_in;
    unsigned int f = 0;
    bool flag = false;
    while (!flag && f < FedsInIds.size()) {
      int fedID = FedsInIds[f];
      //make sure fed id is in allowed range
      if (fedID >= FEDRange_.first && fedID <= FEDRange_.second) {
        defaultValue = 1;
        flag = true;
      }
      f++;
    }
  }

  defaultValue_ = defaultValue;

  init_ = true;
}

void RPCDataCertification::myBooker(DQMStore::IBooker& ibooker) {
  ibooker.setCurrentFolder("RPC/EventInfo");
  // global fraction
  totalCertFraction = ibooker.bookFloat("CertificationSummary");
  totalCertFraction->Fill(defaultValue_);

  CertMap_ = RPCSummaryMapHisto::book(ibooker, "CertificationSummaryMap", "RPC Certification Summary Map");

  //fill the histo with "1" --- just for the moment
  RPCSummaryMapHisto::setBinsBarrel(CertMap_, defaultValue_);
  RPCSummaryMapHisto::setBinsEndcap(CertMap_, defaultValue_);

  // book the ME
  ibooker.setCurrentFolder("RPC/EventInfo/CertificationContents");

  const int limit = std::max(2, numberOfDisks_);

  for (int i = -limit; i <= limit; ++i) {  //loop on wheels and disks
    if (i > -3 && i < nWheels_ - 2) {      //wheels
      const std::string binLabel = fmt::format("RPC_Wheel{}", i);
      certWheelFractions[i + 2] = ibooker.bookFloat(binLabel);
      certWheelFractions[i + 2]->Fill(defaultValue_);
    }

    if (i == 0 || i > numberOfDisks_ || i < (-numberOfDisks_))
      continue;

    if (i > -3 && i < nDisks_ - 2) {
      const std::string binLabel = fmt::format("RPC_Disk{}", i);
      certDiskFractions[i + 2] = ibooker.bookFloat(binLabel);
      certDiskFractions[i + 2]->Fill(defaultValue_);
    }
  }
}