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
#include "DQM/SiStripMonitorSummary/plugins/SiStripPlotGain.h"

SiStripPlotGain::SiStripPlotGain(const edm::ParameterSet &iConfig)
    : gainToken_{esConsumes<edm::Transition::BeginRun>()}, tTopoToken_{esConsumes<edm::Transition::BeginRun>()} {
  // now do what ever initialization is needed
  file = new TFile("correlTest.root", "RECREATE");
  tkmap = new TrackerMap();
}

void SiStripPlotGain::beginRun(const edm::Run &run, const edm::EventSetup &es) {
  if (gainWatcher_.check(es)) {
    edm::LogInfo("") << "[SiStripPlotGain::beginRun] cacheID " << es.get<SiStripApvGainRcd>().cacheIdentifier()
                     << std::endl;
    DoAnalysis(es.getData(tTopoToken_), es.getData(gainToken_));
  }
}

void SiStripPlotGain::DoAnalysis(const TrackerTopology &tTopo, const SiStripApvGain &gain) {
  edm::LogInfo("") << "[Doanalysis]";

  std::vector<TH1F *> histos;

  SiStripApvGain::RegistryPointers p = gain.getRegistryPointers();
  SiStripApvGain::RegistryConstIterator iter, iterE;
  iter = p.detid_begin;
  iterE = p.detid_end;

  float value;

  // Divide result by d
  for (; iter != iterE; ++iter) {
    getHistos(*iter, tTopo, histos);
    SiStripApvGain::Range range = SiStripApvGain::Range(p.getFirstElement(iter), p.getLastElement(iter));

    edm::LogInfo("") << "[Doanalysis] detid " << *iter << " range " << range.second - range.first;
    size_t apv = 0, apvE = (range.second - range.first);
    for (; apv < apvE; apv += 2) {
      value = gain.getApvGain(apv, range);
      tkmap->fill(*iter, value);
      for (size_t i = 0; i < histos.size(); ++i)
        histos[i]->Fill(value);
    }
  }
}

void SiStripPlotGain::getHistos(DetId detid, const TrackerTopology &tTopo, std::vector<TH1F *> &histos) {
  histos.clear();

  int subdet = -999;
  int component = -999;
  if (detid.subdetId() == 3) {
    subdet = 0;
    component = tTopo.tibLayer(detid);
  } else if (detid.subdetId() == 4) {
    subdet = 1;
    component = tTopo.tidSide(detid) == 2 ? tTopo.tidWheel(detid) : tTopo.tidWheel(detid) + 3;
  } else if (detid.subdetId() == 5) {
    subdet = 2;
    component = tTopo.tobLayer(detid);
  } else if (detid.subdetId() == 6) {
    subdet = 3;
    component = tTopo.tecSide(detid) == 2 ? tTopo.tecWheel(detid) : tTopo.tecWheel(detid) + 9;
  }

  int index = 100 + subdet * 100 + component;

  histos.push_back(getHisto(subdet + 1));
  histos.push_back(getHisto(index));
}

TH1F *SiStripPlotGain::getHisto(const long unsigned int &index) {
  if (vTH1.size() < index + 1)
    vTH1.resize(index + 1, nullptr);

  if (vTH1[index] == nullptr) {
    char name[128];
    sprintf(name, "%lu", index);
    edm::LogInfo("") << "[getHisto] creating index " << index << std::endl;
    vTH1[index] = new TH1F(name, name, 150, 0., 5.);
  }

  return vTH1[index];
}

void SiStripPlotGain::endJob() {
  for (size_t i = 0; i < vTH1.size(); i++)
    if (vTH1[i] != nullptr)
      vTH1[i]->Write();

  file->Write();
  file->Close();

  tkmap->save(false, 0, 0, "testTkMap.png");
}