TkVoltageMapCreator

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
//G.Benelli Aug 26 2010
//Plugin adapted from Andrea Venturi's myTkAnalyses/PSTools to create Voltage (LV/HV) ON/OFF Tracke maps in the context of Strip DCS O2O.

// system include files
#include <memory>

// user include files

#include <iostream>
#include <fstream>
#include <string>

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "Geometry/Records/interface/TrackerTopologyRcd.h"

#include "DQM/SiStripCommon/interface/TkHistoMap.h"
#include "CommonTools/TrackerMap/interface/TrackerMap.h"

//
// class decleration
//

class TkVoltageMapCreator : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
public:
  explicit TkVoltageMapCreator(const edm::ParameterSet&);
  ~TkVoltageMapCreator() override;

private:
  void beginJob() override;
  void beginRun(const edm::Run&, const edm::EventSetup&) override;
  void endRun(const edm::Run&, const edm::EventSetup&) override;
  void analyze(const edm::Event&, const edm::EventSetup&) override;
  void endJob() override;

  // ----------member data ---------------------------

  const std::string _lvfile;
  const std::string _lvtkmapname;
  const std::string _hvfile;
  const std::string _hvtkmapname;

  edm::ESGetToken<TkDetMap, TrackerTopologyRcd> tkDetMapToken_;
};

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
TkVoltageMapCreator::TkVoltageMapCreator(const edm::ParameterSet& iConfig)
    : _lvfile(iConfig.getParameter<std::string>("LVStatusFile")),
      _lvtkmapname(iConfig.getParameter<std::string>("LVTkMapName")),
      _hvfile(iConfig.getParameter<std::string>("HVStatusFile")),
      _hvtkmapname(iConfig.getParameter<std::string>("HVTkMapName")),
      tkDetMapToken_(esConsumes<edm::Transition::BeginRun>())

{
  //now do what ever initialization is needed
}

TkVoltageMapCreator::~TkVoltageMapCreator() = default;

//
// member functions
//

// ------------ method called to for each event  ------------
void TkVoltageMapCreator::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { using namespace edm; }

void TkVoltageMapCreator::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
  const TkDetMap* tkDetMap = &iSetup.getData(tkDetMapToken_);

  TrackerMap lvmap, hvmap;

  TkHistoMap lvhisto(tkDetMap, "LV_Status", "LV_Status", -1);
  TkHistoMap hvhisto(tkDetMap, "HV_Status", "HV_Status", -1);

  std::ifstream lvdata(_lvfile.c_str());
  std::ifstream hvdata(_hvfile.c_str());

  // HV channel map filling

  unsigned int detid;
  std::string lvstatus;

  while (lvdata >> detid >> lvstatus) {
    double cha = 0.;
    if (lvstatus == "ON")
      cha = 0.5;  //GREEN
    if (lvstatus == "OFF")
      cha = 1.;  //RED
    lvhisto.fill(detid, cha);
  }

  std::string hvstatus;

  while (hvdata >> detid >> hvstatus) {
    double cha = 0.;
    if (hvstatus == "ON")
      cha = 0.5;  //GREEN
    if (hvstatus == "OFF")
      cha = 1.;  //RED
    hvhisto.fill(detid, cha);
  }

  lvmap.setPalette(1);
  hvmap.setPalette(1);

  lvhisto.dumpInTkMap(&lvmap);
  hvhisto.dumpInTkMap(&hvmap);

  lvmap.save(true, 0, 0, _lvtkmapname);
  hvmap.save(true, 0, 0, _hvtkmapname);

  //TODO could make the root file name a parameter to avoid overwriting everytime...
  std::string rootmapname = "VoltageStatus.root";
  lvhisto.save(rootmapname);
  hvhisto.save(rootmapname);
}

void TkVoltageMapCreator::endRun(const edm::Run& iRun, const edm::EventSetup&) {}

// ------------ method called once each job just before starting event loop  ------------
void TkVoltageMapCreator::beginJob() {}

// ------------ method called once each job just after ending the event loop  ------------
void TkVoltageMapCreator::endJob() {}

//define this as a plug-in
DEFINE_FWK_MODULE(TkVoltageMapCreator);