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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
/*
 * \file DTDCSByLumiTask.cc
 *
 * \author C. Battilana - CIEMAT
 * \author P. Bellan - INFN PD
 * \author A. Branca = INFN PD

 *
 */

#include "DQM/DTMonitorModule/src/DTDCSByLumiTask.h"

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

// Geometry
#include "Geometry/DTGeometry/interface/DTLayer.h"
#include "Geometry/DTGeometry/interface/DTTopology.h"

#include "DQMServices/Core/interface/DQMStore.h"
#include "FWCore/Framework/interface/EventSetupRecord.h"
#include "FWCore/Framework/interface/EventSetupRecordKey.h"
#include "FWCore/Utilities/interface/Transition.h"

#include <iostream>

using namespace edm;
using namespace std;

DTDCSByLumiTask::DTDCSByLumiTask(const edm::ParameterSet& ps)
    : theEvents(0),
      theLumis(0),
      dtGeometryToken_(esConsumes<DTGeometry, MuonGeometryRecord, edm::Transition::BeginRun>()),
      dtHVStatusToken_(esConsumes<DTHVStatus, DTHVStatusRcd, edm::Transition::EndLuminosityBlock>()) {
  LogTrace("DTDQM|DTMonitorModule|DTDCSByLumiTask") << "[DTDCSByLumiTask]: Constructor" << endl;

  // If needed put getParameter here
  // dtDCSByLumiLabel = ps.getParameter<InputTag>("dtDCSByLumiLabel");
}

DTDCSByLumiTask::~DTDCSByLumiTask() {
  LogTrace("DTDQM|DTMonitorModule|DTDCSByLumiTask")
      << "DTDCSByLumiTask: processed " << theEvents << " events in " << theLumis << " lumi sections" << endl;
}

void DTDCSByLumiTask::dqmBeginRun(const edm::Run& run, const edm::EventSetup& context) {
  LogTrace("DTDQM|DTMonitorModule|DTDCSByLumiTask") << "[DTDCSByLumiTask]: begin run" << endl;

  theDTGeom = context.getHandle(dtGeometryToken_);

  DTHVRecordFound = true;

  eventsetup::EventSetupRecordKey recordKey(eventsetup::EventSetupRecordKey::TypeTag::findType("DTHVStatusRcd"));

  std::vector<eventsetup::EventSetupRecordKey> recordKeys;
  context.fillAvailableRecordKeys(recordKeys);
  vector<eventsetup::EventSetupRecordKey>::iterator it = find(recordKeys.begin(), recordKeys.end(), recordKey);

  if (it == recordKeys.end()) {
    //record not found
    LogTrace("DTDQM|DTMonitorModule|DTDCSByLumiTask") << "Record DTHVStatusRcd does not exist " << std::endl;

    DTHVRecordFound = false;
  }
}

void DTDCSByLumiTask::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const&) {
  // Book bylumi histo (# of bins as reduced as possible)
  ibooker.setCurrentFolder(topFolder());

  for (int wheel = -2; wheel <= 2; wheel++) {
    stringstream wheel_str;
    wheel_str << wheel;

    {
      // Set Lumi scope in order to save histo every LS
      auto scope = DQMStore::IBooker::UseLumiScope(ibooker);
      MonitorElement* ME =
          ibooker.book1D("hActiveUnits" + wheel_str.str(), "Active Untis x LS Wh" + wheel_str.str(), 2, 0.5, 2.5);
      hActiveUnits.push_back(ME);
    }
  }
}

void DTDCSByLumiTask::dqmBeginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const&) {
  theLumis++;

  LogTrace("DTDQM|DTMonitorModule|DTDCSByLumiTask")
      << "[DTDCSByLumiTask]: Begin of processed lumi # " << lumiSeg.id().luminosityBlock() << " " << theLumis
      << " lumi processed by this job" << endl;

  for (int wheel = 0; wheel < 5; wheel++) {
    hActiveUnits[wheel]->Reset();  // Cb by lumi histo need to be resetted in between lumi boundaries
  }
}

void DTDCSByLumiTask::dqmEndLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& context) {
  const DTHVStatus* dtHVStatus = nullptr;
  if (DTHVRecordFound) {
    dtHVStatus = &context.getData(dtHVStatusToken_);
  }

  vector<const DTLayer*>::const_iterator layersIt = theDTGeom->layers().begin();
  vector<const DTLayer*>::const_iterator layersEnd = theDTGeom->layers().end();

  for (; layersIt != layersEnd; ++layersIt) {
    int wheel = (*layersIt)->id().wheel();

    int nWiresLayer = (*layersIt)->specificTopology().channels();
    hActiveUnits[wheel + 2]->Fill(1, nWiresLayer);  // CB first bin is # of layers
    int nActiveWires = nWiresLayer;

    int flagA = -100;
    int flagC = -100;
    int flagS = -100;
    int first = -100;
    int last = -100;

    // CB info is not stored if HV is ON -> in this case get returns 1
    // process all other cases and removed wires with "BAD HV" from active
    // wires list

    if (dtHVStatus) {
      if (!dtHVStatus->get((*layersIt)->id(), 0, first, last, flagA, flagC, flagS) && (flagA || flagC || flagS)) {
        nActiveWires -= (last - first + 1);
      }

      if (!dtHVStatus->get((*layersIt)->id(), 1, first, last, flagA, flagC, flagS) && (flagA || flagC || flagS)) {
        nActiveWires -= (last - first + 1);
      }
    } else {
      nActiveWires = -1.;
    }

    hActiveUnits[wheel + 2]->Fill(2, nActiveWires);  // CB 2nd bin is the list of wires wit HV ON
  }
}

void DTDCSByLumiTask::analyze(const edm::Event&, const edm::EventSetup&) { theEvents++; }

string DTDCSByLumiTask::topFolder() const { return string("DT/EventInfo/DCSContents"); }

// Local Variables:
// show-trailing-whitespace: t
// truncate-lines: t
// End: