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
/*
 * \file DTScalerInfoTask.cc
 *
 * \author C. Battilana - CIEMAT
 *
*/

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

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

// DT DQM
#include "DQM/DTMonitorModule/interface/DTTimeEvolutionHisto.h"

#include <sstream>
#include <iostream>
#include <fstream>

using namespace edm;
using namespace std;

DTScalerInfoTask::DTScalerInfoTask(const edm::ParameterSet& ps) : nEvents(0) {
  LogTrace("DTDQM|DTMonitorModule|DTScalerInfoTask") << "[DTScalerInfoTask]: Constructor" << endl;

  scalerToken_ = consumes<LumiScalersCollection>(ps.getUntrackedParameter<InputTag>("inputTagScaler"));
  theParams = ps;
}

DTScalerInfoTask::~DTScalerInfoTask() {
  LogTrace("DTDQM|DTMonitorModule|DTScalerInfoTask") << "[DTScalerInfoTask]: analyzed " << nEvents << " events" << endl;
}

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

void DTScalerInfoTask::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
  nEventsInLS = 0;

  LogTrace("DTDQM|DTMonitorModule|DTScalerInfoTask") << "[DTScalerInfoTask]: Begin of LS transition" << endl;
}

void DTScalerInfoTask::endLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
  LogTrace("DTDQM|DTMonitorModule|DTScalerInfoTask") << "[DTScalerInfoTask]: End of LS transition" << endl;

  int block = lumiSeg.luminosityBlock();

  map<string, DTTimeEvolutionHisto*>::const_iterator histoIt = trendHistos.begin();
  map<string, DTTimeEvolutionHisto*>::const_iterator histoEnd = trendHistos.end();
  for (; histoIt != histoEnd; ++histoIt) {
    histoIt->second->updateTimeSlot(block, nEventsInLS);
  }
}

void DTScalerInfoTask::analyze(const edm::Event& e, const edm::EventSetup& c) {
  nEvents++;
  nEventsInLS++;
  nEventMonitor->Fill(nEvents);

  //retrieve the luminosity
  edm::Handle<LumiScalersCollection> lumiScalers;
  if (e.getByToken(scalerToken_, lumiScalers)) {
    if (lumiScalers->begin() != lumiScalers->end()) {
      LumiScalersCollection::const_iterator lumiIt = lumiScalers->begin();
      trendHistos["AvgLumivsLumiSec"]->accumulateValueTimeSlot(lumiIt->instantLumi());
    } else {
      LogVerbatim("DTDQM|DTMonitorModule|DTScalerInfoTask")
          << "[DTScalerInfoTask]: LumiScalersCollection size == 0" << endl;
    }
  } else {
    LogVerbatim("DTDQM|DTMonitorModule|DTScalerInfoTask")
        << "[DTScalerInfoTask]: LumiScalersCollection getByToken call failed" << endl;
  }
}

void DTScalerInfoTask::bookHistograms(DQMStore::IBooker& ibooker,
                                      edm::Run const& iRun,
                                      edm::EventSetup const& context) {
  ibooker.setCurrentFolder("DT/EventInfo/Counters");
  nEventMonitor = ibooker.bookFloat("nProcessedEventsScalerInfo");

  ibooker.setCurrentFolder("DT/00-DataIntegrity/ScalerInfo");

  string histoName = "AvgLumivsLumiSec";
  string histoTitle = "Average Lumi vs LumiSec";
  trendHistos[histoName] = new DTTimeEvolutionHisto(ibooker, histoName, histoTitle, 200, 10, true, 0);
}

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