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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
/*
 *  See header file for a description of this class.
 *
 *  \author C. Battilana S. Marcellini - INFN Bologna
 *
 *  threadsafe version (//-) oct/nov 2014 - WATWanAbdullah ncpp-um-my
 *
 */

// This class header
#include "DQM/DTMonitorClient/src/DTLocalTriggerBaseTest.h"

// Framework headers
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DQMServices/Core/interface/DQMStore.h"

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

// Root
#include "TF1.h"
#include "TProfile.h"

//C++ headers
#include <iostream>
#include <sstream>

using namespace edm;
using namespace std;

DTLocalTriggerBaseTest::~DTLocalTriggerBaseTest() {
  LogVerbatim(category()) << "[" << testName << "Test]: analyzed " << nevents << " events";
}

void DTLocalTriggerBaseTest::beginRun(edm::Run const& run, edm::EventSetup const& context) {
  nevents = 0;
  nLumiSegs = 0;

  LogVerbatim(category()) << "[" << testName << "Test]: BeginRun";
  muonGeom = &context.getData(muonGeomToken_);
}

void DTLocalTriggerBaseTest::dqmEndLuminosityBlock(DQMStore::IBooker& ibooker,
                                                   DQMStore::IGetter& igetter,
                                                   edm::LuminosityBlock const& lumiSeg,
                                                   edm::EventSetup const& context) {
  if (!runOnline)
    return;

  LogVerbatim("DTDQM|DTMonitorClient|DTLocalTriggerTest")
      << "[" << testName << "Test]: End of LS transition, performing the DQM client operation";

  // counts number of lumiSegs and prescale
  nLumiSegs++;
  if (nLumiSegs % prescaleFactor != 0)
    return;

  LogVerbatim("DTDQM|DTMonitorClient|DTLocalTriggerTest") << "[" << testName << "Test]: " << nLumiSegs << " updates";

  runClientDiagnostic(ibooker, igetter);
}

void DTLocalTriggerBaseTest::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
  LogTrace(category()) << "[" << testName << "Test] endJob called!";

  if (!runOnline) {
    LogVerbatim(category()) << "[" << testName << "Test] Client called in offline mode, performing client operations";
    runClientDiagnostic(ibooker, igetter);
  }
}

void DTLocalTriggerBaseTest::endRun(Run const& run, EventSetup const& context) {
  LogTrace(category()) << "[" << testName << "Test] endRun called!";
}

void DTLocalTriggerBaseTest::setConfig(const edm::ParameterSet& ps, string name) {
  testName = name;

  LogTrace(category()) << "[" << testName << "Test]: Constructor";

  sourceFolder = ps.getUntrackedParameter<string>("folderRoot", "");
  runOnline = ps.getUntrackedParameter<bool>("runOnline", true);
  hwSources = ps.getUntrackedParameter<vector<string> >("hwSources");

  if (ps.getUntrackedParameter<bool>("localrun", true)) {
    trigSources.push_back("");
  } else {
    trigSources = ps.getUntrackedParameter<vector<string> >("trigSources");
  }

  parameters = ps;
  nevents = 0;

  prescaleFactor = parameters.getUntrackedParameter<int>("diagnosticPrescale", 1);
}

string DTLocalTriggerBaseTest::fullName(string htype) { return hwSource + "_" + htype + trigSource; }

string DTLocalTriggerBaseTest::getMEName(string histoTag, string subfolder, const DTChamberId& chambid) {
  stringstream wheel;
  wheel << chambid.wheel();
  stringstream station;
  station << chambid.station();
  stringstream sector;
  sector << chambid.sector();

  string folderName = topFolder() + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() + "/";
  if (!subfolder.empty()) {
    folderName += subfolder + "/";
  }

  string histoname = sourceFolder + folderName + fullName(histoTag) + "_W" + wheel.str() + "_Sec" + sector.str() +
                     "_St" + station.str();

  return histoname;
}

string DTLocalTriggerBaseTest::getMEName(string histoTag, string subfolder, int wh) {
  stringstream wheel;
  wheel << wh;

  string folderName = topFolder() + "Wheel" + wheel.str() + "/";
  if (!subfolder.empty()) {
    folderName += subfolder + "/";
  }

  string histoname = sourceFolder + folderName + fullName(histoTag) + "_W" + wheel.str();

  return histoname;
}

void DTLocalTriggerBaseTest::bookSectorHistos(
    DQMStore::IBooker& ibooker, int wheel, int sector, string hTag, string folder) {
  stringstream wh;
  wh << wheel;
  stringstream sc;
  sc << sector;
  int sectorid = (wheel + 3) + (sector - 1) * 5;
  string basedir = topFolder() + "Wheel" + wh.str() + "/Sector" + sc.str() + "/";
  if (!folder.empty()) {
    basedir += folder + "/";
  }

  ibooker.setCurrentFolder(basedir);

  string fullTag = fullName(hTag);
  string hname = fullTag + "_W" + wh.str() + "_Sec" + sc.str();
  LogTrace(category()) << "[" << testName << "Test]: booking " << basedir << hname;
  if (hTag.find("BXDistribPhi") != string::npos) {
    MonitorElement* me = ibooker.book2D(hname.c_str(), hname.c_str(), 25, -4.5, 20.5, 4, 0.5, 4.5);
    me->setBinLabel(1, "MB1", 2);
    me->setBinLabel(2, "MB2", 2);
    me->setBinLabel(3, "MB3", 2);
    me->setBinLabel(4, "MB4", 2);
    secME[sectorid][fullTag] = me;
    return;
  } else if (hTag.find("QualDistribPhi") != string::npos) {
    MonitorElement* me = ibooker.book2D(hname.c_str(), hname.c_str(), 7, -0.5, 6.5, 4, 0.5, 4.5);
    me->setBinLabel(1, "MB1", 2);
    me->setBinLabel(2, "MB2", 2);
    me->setBinLabel(3, "MB3", 2);
    me->setBinLabel(4, "MB4", 2);
    me->setBinLabel(1, "LI", 1);
    me->setBinLabel(2, "LO", 1);
    me->setBinLabel(3, "HI", 1);
    me->setBinLabel(4, "HO", 1);
    me->setBinLabel(5, "LL", 1);
    me->setBinLabel(6, "HL", 1);
    me->setBinLabel(7, "HH", 1);
    secME[sectorid][fullTag] = me;
    return;
  } else if (hTag.find("Phi") != string::npos || hTag.find("TkvsTrig") != string::npos) {
    MonitorElement* me = ibooker.book1D(hname.c_str(), hname.c_str(), 4, 0.5, 4.5);
    me->setBinLabel(1, "MB1", 1);
    me->setBinLabel(2, "MB2", 1);
    me->setBinLabel(3, "MB3", 1);
    me->setBinLabel(4, "MB4", 1);
    secME[sectorid][fullTag] = me;
    return;
  }

  if (hTag.find("Theta") != string::npos) {
    MonitorElement* me = ibooker.book1D(hname.c_str(), hname.c_str(), 3, 0.5, 3.5);
    me->setBinLabel(1, "MB1", 1);
    me->setBinLabel(2, "MB2", 1);
    me->setBinLabel(3, "MB3", 1);
    secME[sectorid][fullTag] = me;
    return;
  }
}

void DTLocalTriggerBaseTest::bookCmsHistos(DQMStore::IBooker& ibooker, string hTag, string folder, bool isGlb) {
  string basedir = topFolder();
  if (!folder.empty()) {
    basedir += folder + "/";
  }

  ibooker.setCurrentFolder(basedir);

  string hname = isGlb ? hTag : fullName(hTag);
  LogTrace(category()) << "[" << testName << "Test]: booking " << basedir << hname;

  MonitorElement* me = ibooker.book2D(hname.c_str(), hname.c_str(), 12, 1, 13, 5, -2, 3);
  me->setAxisTitle("Sector", 1);
  me->setAxisTitle("Wheel", 2);
  cmsME[hname] = me;
}

void DTLocalTriggerBaseTest::bookWheelHistos(DQMStore::IBooker& ibooker, int wheel, string hTag, string folder) {
  stringstream wh;
  wh << wheel;
  string basedir;
  if (hTag.find("Summary") != string::npos) {
    basedir = topFolder();  //Book summary histo outside wheel directories
  } else {
    basedir = topFolder() + "Wheel" + wh.str() + "/";
  }
  if (!folder.empty()) {
    basedir += folder + "/";
  }

  ibooker.setCurrentFolder(basedir);

  string fullTag = fullName(hTag);
  string hname = fullTag + "_W" + wh.str();

  LogTrace(category()) << "[" << testName << "Test]: booking " << basedir << hname;

  if (hTag.find("Phi") != string::npos || hTag.find("Summary") != string::npos) {
    MonitorElement* me = ibooker.book2D(hname.c_str(), hname.c_str(), 12, 1, 13, 4, 1, 5);

    //     setLabelPh(me);
    me->setBinLabel(1, "MB1", 2);
    me->setBinLabel(2, "MB2", 2);
    me->setBinLabel(3, "MB3", 2);
    me->setBinLabel(4, "MB4", 2);
    me->setAxisTitle("Sector", 1);

    whME[wheel][fullTag] = me;
    return;
  }

  if (hTag.find("Theta") != string::npos) {
    MonitorElement* me = ibooker.book2D(hname.c_str(), hname.c_str(), 12, 1, 13, 3, 1, 4);

    //     setLabelTh(me);
    me->setBinLabel(1, "MB1", 2);
    me->setBinLabel(2, "MB2", 2);
    me->setBinLabel(3, "MB3", 2);
    me->setAxisTitle("Sector", 1);

    whME[wheel][fullTag] = me;
    return;
  }
}

pair<float, float> DTLocalTriggerBaseTest::phiRange(const DTChamberId& id) {
  float min, max;
  int station = id.station();
  int sector = id.sector();
  int wheel = id.wheel();

  const DTLayer* layer = muonGeom->layer(DTLayerId(id, 1, 1));
  const DTTopology& topo = layer->specificTopology();
  min = topo.wirePosition(topo.firstChannel());
  max = topo.wirePosition(topo.lastChannel());

  if (station == 4) {
    const DTLayer* layer2;
    float lposx;

    if (sector == 4) {
      layer2 = muonGeom->layer(DTLayerId(wheel, station, 13, 1, 1));
      lposx = layer->toLocal(layer2->position()).x();
    } else if (sector == 10) {
      layer2 = muonGeom->layer(DTLayerId(wheel, station, 14, 1, 1));
      lposx = layer->toLocal(layer2->position()).x();
    } else
      return make_pair(min, max);

    DTTopology topo2 = layer2->specificTopology();

    if (lposx > 0) {
      max = lposx * .5 + topo2.wirePosition(topo2.lastChannel());
      min -= lposx * .5;
    } else {
      min = lposx * .5 + topo2.wirePosition(topo2.firstChannel());
      max -= lposx * .5;
    }
  }

  return make_pair(min, max);
}