16 #include <TDirectory.h> 32 tests_ = ps.
getParameter<std::vector<ParameterSet> >(
"testParams");
35 cout <<
"[L1TOccupancyClient:] Called constructor" << endl;
45 cout <<
"[L1TOccupancyClient:] Called destructor" << endl;
60 cout <<
"[L1TOccupancyClient:] Called beginRun" << endl;
63 file_ = TFile::Open(
"DQM_L1TOccupancyClient_Snapshots_LS.root",
"RECREATE");
72 for (vector<ParameterSet>::iterator
it = tests_.begin();
it != tests_.end();
it++) {
74 if ((*it).getUntrackedParameter<
string>(
"algoName",
"XYSymmetry") ==
"XYSymmetry") {
76 string testName = (*it).getParameter<
string>(
"testName");
78 string histPath = algoParameters.getParameter<
string>(
"histPath");
81 cout <<
"[L1TOccupancyClient:] Monitored histogram path: " <<
histPath << endl;
97 hservice_->setMaskedBins(
testName, algoParameters.getParameter<vector<ParameterSet> >(
"maskedAreas"));
114 meDifferential[
title] =
m;
121 meCertification[
title] =
m;
123 mValidTests.push_back(&(*
it));
137 book(ibooker, igetter);
140 cout <<
"[L1TOccupancyClient:] Called endRun()" << endl;
144 for (std::vector<ParameterSet*>::iterator
it = mValidTests.begin();
it != mValidTests.end();
it++) {
146 string algo_name =
test.getUntrackedParameter<
string>(
"algoName",
"XYSymmetry");
147 string test_name =
test.getParameter<
string>(
"testName");
150 cout <<
"[L1TOccupancyClient:] Starting calculations for: " <<
algo_name <<
" on: " << test_name << endl;
157 vector<pair<int, double> > deadChannels;
158 vector<pair<int, double> > statDev;
159 bool enoughStats =
false;
162 hservice_->updateHistogramEndRun(test_name);
165 double dead = xySymmetry(ps, test_name, deadChannels, statDev, enoughStats);
167 str << test_name <<
"_cumu_LS_EndRun";
170 TH2F* cumulative_save = (TH2F*)hservice_->getDifferentialHistogram(test_name)->Clone(
str.str().c_str());
172 cumulative_save->SetTitle(
str.str().c_str());
174 TDirectory* td = file_->GetDirectory(test_name.c_str());
176 td->cd(
string(test_name +
"_Histos_AllLS").c_str());
178 cumulative_save->Write();
183 printDeadChannels(deadChannels, meResults[test_name]->getTH2F(), statDev, test_name);
186 TH2F* cumulative_save = (TH2F*)hservice_->getDifferentialHistogram(test_name)->Clone(
str.str().c_str());
187 cumulative_save->SetTitle(
str.str().c_str());
188 TDirectory* td = file_->GetDirectory((
"DQM_L1TOccupancyClient_Snapshots_LS.root:/" + test_name).c_str());
189 td->cd(
string(test_name +
"_Histos").c_str());
190 cumulative_save->Write();
193 TH2F* h2f = meResults[test_name]->getTH2F();
195 str2 << test_name <<
"_result_LS_EndRun";
196 TH2F* dead_save = (TH2F*)h2f->Clone(str2.str().c_str());
198 td->cd(
string(test_name +
"_Results").c_str());
199 dead_save->SetTitle(str2.str().c_str());
204 meDifferential[test_name]->Reset();
205 meDifferential[test_name]->getTH2F()->Add(hservice_->getDifferentialHistogram(test_name));
207 vector<int> lsCertification = hservice_->getLSCertification(test_name);
210 for (
unsigned int i = 0;
i < lsCertification.size();
i++) {
211 int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[
i]);
212 meCertification[test_name]->getTH1()->SetBinContent(
bin, 1 - dead);
216 hservice_->resetHisto(test_name);
219 cout <<
"Now we have enough statstics for " << test_name << endl;
224 cout <<
"we don't have enough statstics for " << test_name << endl;
228 vector<int> lsCertification = hservice_->getLSCertification(test_name);
231 for (
unsigned int i = 0;
i < lsCertification.size();
i++) {
232 int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[
i]);
233 meCertification[test_name]->getTH1()->SetBinContent(
bin, -1);
238 cout <<
"No valid algorithm" << std::endl;
261 book(ibooker, igetter);
266 cout <<
"[L1TOccupancyClient:] Called endLuminosityBlock()" << endl;
267 cout <<
"[L1TOccupancyClient:] Lumisection: " << eventLS << endl;
271 for (std::vector<ParameterSet*>::const_iterator
it = mValidTests.begin();
it != mValidTests.end();
it++) {
273 string algo_name =
test.getUntrackedParameter<
string>(
"algoName",
"XYSymmetry");
274 string test_name =
test.getParameter<
string>(
"testName");
277 cout <<
"[L1TOccupancyClient:] Starting calculations for " <<
algo_name <<
" on:" << test_name << endl;
284 vector<pair<int, double> > deadChannels;
285 vector<pair<int, double> > statDev;
286 bool enoughStats =
false;
289 hservice_->updateHistogramEndLS(igetter, test_name,
histPath, eventLS);
292 double dead = xySymmetry(ps, test_name, deadChannels, statDev, enoughStats);
294 str << test_name <<
"_cumu_LS_" << eventLS;
297 TH2F* cumulative_save = (TH2F*)hservice_->getDifferentialHistogram(test_name)->Clone(
str.str().c_str());
298 cumulative_save->SetTitle(
str.str().c_str());
299 TDirectory* td = file_->GetDirectory(test_name.c_str());
300 td->cd(
string(test_name +
"_Histos_AllLS").c_str());
301 cumulative_save->Write();
307 printDeadChannels(deadChannels, meResults[test_name]->getTH2F(), statDev, test_name);
310 TH2F* cumulative_save = (TH2F*)hservice_->getDifferentialHistogram(test_name)->Clone(
str.str().c_str());
311 cumulative_save->SetTitle(
str.str().c_str());
312 TDirectory* td = file_->GetDirectory((
"DQM_L1TOccupancyClient_Snapshots_LS.root:/" + test_name).c_str());
313 td->cd(
string(test_name +
"_Histos").c_str());
314 cumulative_save->Write();
317 TH2F* h2f = meResults[test_name]->getTH2F();
319 str2 << test_name <<
"_result_LS_" << eventLS;
320 TH2F* dead_save = (TH2F*)h2f->Clone(str2.str().c_str());
322 td->cd(
string(test_name +
"_Results").c_str());
323 dead_save->SetTitle(str2.str().c_str());
328 meDifferential[test_name]->Reset();
329 meDifferential[test_name]->getTH2F()->Add(hservice_->getDifferentialHistogram(test_name));
331 vector<int> lsCertification = hservice_->getLSCertification(test_name);
334 for (
unsigned int i = 0;
i < lsCertification.size();
i++) {
335 int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[
i]);
336 meCertification[test_name]->getTH1()->SetBinContent(
bin, 1 - dead);
340 hservice_->resetHisto(test_name);
343 cout <<
"Now we have enough statstics for " << test_name << endl;
348 cout <<
"we don't have enough statstics for " << test_name << endl;
353 cout <<
"No valid algorithm" << std::endl;
382 vector<pair<int, double> >& deadChannels,
383 vector<pair<int, double> >& statDev,
386 TH2F* diffHist = hservice_->getDifferentialHistogram(iTestName);
390 int nBinsX = diffHist->GetNbinsX();
391 int nBinsY = diffHist->GetNbinsY();
395 int maxBinStrip, centralBinStrip;
397 maxBinStrip = nBinsX;
402 centralBinStrip = nBinsX / 2 + 1;
404 double pAxisSymmetryValue = ps.
getParameter<
double>(
"axisSymmetryValue");
405 getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 1);
409 int upBinStrip = centralBinStrip;
410 int lowBinStrip = centralBinStrip;
413 if (nBinsX % 2 == 0) {
418 std::unique_ptr<double[]> maxAvgs(
new double[maxBinStrip - upBinStrip + 1]);
420 int nActualStrips = 0;
421 for (
int i = 0,
j = upBinStrip,
k = lowBinStrip;
j <= maxBinStrip;
i++,
j++,
k--) {
422 double avg1 = getAvrg(diffHist, iTestName, pAxis, nBinsY,
j, pAverageMode);
423 double avg2 = getAvrg(diffHist, iTestName, pAxis, nBinsY,
k, pAverageMode);
426 if (!hservice_->isStripMasked(iTestName,
j, pAxis) && !hservice_->isStripMasked(iTestName,
k, pAxis)) {
432 vector<double> defaultMu0up;
433 defaultMu0up.push_back(13.7655);
434 defaultMu0up.push_back(184.742);
435 defaultMu0up.push_back(50735.3);
436 defaultMu0up.push_back(-97.6793);
438 TF1 tf(
"myFunc",
"[0]*(TMath::Log(x*[1]+[2]))+[3]", 10., 11000.);
440 for (
unsigned int i = 0;
i <
params.size();
i++) {
443 int statsup = (
int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
445 vector<double> defaultMu0low;
446 defaultMu0low.push_back(2.19664);
447 defaultMu0low.push_back(1.94546);
448 defaultMu0low.push_back(-99.3263);
449 defaultMu0low.push_back(19.388);
452 for (
unsigned int i = 0;
i <
params.size();
i++) {
455 int statslow = (
int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
458 cout <<
"nbins: " << hservice_->getNBinsHistogram(iTestName) << endl;
459 cout <<
"statsup= " << statsup <<
", statslow= " << statslow << endl;
462 enoughStats = TMath::MinElement(nActualStrips, maxAvgs.get()) >
TMath::Max(statsup, statslow);
464 cout <<
"stats: " << TMath::MinElement(nActualStrips, maxAvgs.get())
465 <<
", statsAvg: " << diffHist->GetEntries() / hservice_->getNBinsHistogram(iTestName)
466 <<
", threshold: " <<
TMath::Max(statsup, statslow) << endl;
472 for (; upBinStrip <= maxBinStrip; upBinStrip++, lowBinStrip--) {
473 double avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, upBinStrip, pAverageMode);
475 diffHist, iTestName, lowBinStrip, nBinsY, pAxis, avg, ps, deadChannels);
477 avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, lowBinStrip, pAverageMode);
479 diffHist, iTestName, upBinStrip, nBinsY, pAxis, avg, ps, deadChannels);
485 else if (pAxis == 2) {
486 int maxBinStrip, centralBinStrip;
488 maxBinStrip = nBinsY;
492 centralBinStrip = nBinsY / 2 + 1;
494 double pAxisSymmetryValue = ps.
getParameter<
double>(
"axisSymmetryValue");
495 getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 2);
499 int lowBinStrip = centralBinStrip, upBinStrip = centralBinStrip;
502 if (nBinsX % 2 == 0) {
508 std::unique_ptr<double[]> maxAvgs(
new double[maxBinStrip - upBinStrip + 1]);
509 int nActualStrips = 0;
510 for (
int i = 0,
j = upBinStrip,
k = lowBinStrip;
j <= maxBinStrip;
i++,
j++,
k--) {
511 double avg1 = getAvrg(diffHist, iTestName, pAxis, nBinsX,
j, pAverageMode);
512 double avg2 = getAvrg(diffHist, iTestName, pAxis, nBinsX,
k, pAverageMode);
513 if (!hservice_->isStripMasked(iTestName,
j, pAxis) && !hservice_->isStripMasked(iTestName,
k, pAxis)) {
519 vector<double> defaultMu0up;
520 defaultMu0up.push_back(13.7655);
521 defaultMu0up.push_back(184.742);
522 defaultMu0up.push_back(50735.3);
523 defaultMu0up.push_back(-97.6793);
526 TF1 tf(
"myFunc",
"[0]*(TMath::Log(x*[1]+[2]))+[3]", 10., 11000.);
527 for (
unsigned int i = 0;
i <
params.size();
i++) {
530 int statsup = (
int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
532 vector<double> defaultMu0low;
533 defaultMu0low.push_back(2.19664);
534 defaultMu0low.push_back(1.94546);
535 defaultMu0low.push_back(-99.3263);
536 defaultMu0low.push_back(19.388);
539 for (
unsigned int i = 0;
i <
params.size();
i++) {
542 int statslow = (
int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
544 cout <<
"statsup= " << statsup <<
", statslow= " << statslow << endl;
546 enoughStats = TMath::MinElement(nActualStrips, maxAvgs.get()) >
TMath::Max(statsup, statslow);
548 cout <<
"stats: " << TMath::MinElement(nActualStrips, maxAvgs.get())
549 <<
", statsAvg: " << diffHist->GetEntries() / hservice_->getNBinsHistogram(iTestName)
550 <<
", threshold: " <<
TMath::Max(statsup, statslow) << endl;
556 for (; upBinStrip <= maxBinStrip; upBinStrip++, lowBinStrip--) {
557 double avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, upBinStrip, pAverageMode);
559 diffHist, iTestName, lowBinStrip, nBinsX, pAxis, avg, ps, deadChannels);
561 avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, lowBinStrip, pAverageMode);
563 diffHist, iTestName, upBinStrip, nBinsX, pAxis, avg, ps, deadChannels);
568 cout <<
"Invalid axis" << endl;
572 return (deadChannels.size() - hservice_->getNBinsMasked(iTestName)) * 1.0 / hservice_->getNBinsHistogram(iTestName);
591 TH1D*
proj =
nullptr;
592 TH2F*
histo =
new TH2F(*iHist);
594 std::vector<double>
values;
601 marked = hservice_->maskBins(iTestName,
histo, iBinStrip, iAxis);
603 avg =
proj->GetBinContent(iBinStrip) / (iNBins - marked);
608 marked = hservice_->maskBins(iTestName,
histo, iBinStrip, iAxis);
609 proj =
histo->ProjectionY(
"_py", iBinStrip, iBinStrip);
610 for (
int i = 0;
i < iNBins;
i++) {
613 avg = TMath::Median(iNBins, &
values[0]);
617 cout <<
"Invalid averaging mode!" << endl;
621 }
else if (iAxis == 2) {
625 marked = hservice_->maskBins(iTestName,
histo, iBinStrip, iAxis);
627 avg =
proj->GetBinContent(iBinStrip) / (iNBins - marked);
631 marked = hservice_->maskBins(iTestName,
histo, iBinStrip, iAxis);
632 proj =
histo->ProjectionX(
"_px", iBinStrip, iBinStrip);
633 for (
int i = 0;
i < iNBins;
i++) {
637 avg = TMath::Median(iNBins, &
values[0]);
641 cout <<
"invalid averaging mode!" << endl;
647 cout <<
"invalid axis" << endl;
665 TH2F* oHistDeadChannels,
666 const vector<std::pair<int, double> >& statDev,
669 oHistDeadChannels->Reset();
671 cout <<
"suspect or masked channels of " << iTestName <<
": ";
677 for (
std::vector<pair<int, double> >::const_iterator
it = iDeadChannels.begin();
it != iDeadChannels.end();
it++) {
678 int bin = (*it).first;
679 oHistDeadChannels->GetBinXYZ(
bin,
x, y, z);
681 if (hservice_->isMasked(iTestName,
x, y)) {
682 oHistDeadChannels->SetBinContent(
bin, -1);
684 printf(
"(%4i,%4i) Masked\n",
x, y);
687 oHistDeadChannels->SetBinContent(
bin, 1);
689 printf(
"(%4i,%4i) Failed test\n",
x, y);
695 cout <<
"total number of suspect channels: " << (iDeadChannels.size() - (hservice_->getNBinsMasked(iTestName)))
722 vector<pair<int, double> >& oChannels) {
728 TF1* fmuup =
new TF1(
"fmuup",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
729 TF1* fmulow =
new TF1(
"fmulow",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
731 fmuup->SetParameter(1, iAvg);
733 fmulow->SetParameter(1, iAvg);
735 TF1* fchi =
new TF1(
"fchi",
"[0]*x**2+[1]*x+[2]", 0., 1500.);
738 vector<double> defaultChi2up;
739 defaultChi2up.push_back(5.45058
e-05);
740 defaultChi2up.push_back(0.268756);
741 defaultChi2up.push_back(-11.7515);
744 for (
unsigned int i = 0;
i <
params.size();
i++) {
747 double sigma_up = fchi->Eval(iAvg);
750 vector<double> defaultChi2low;
751 defaultChi2low.push_back(4.11095
e-05);
752 defaultChi2low.push_back(0.577451);
753 defaultChi2low.push_back(-10.378);
756 for (
unsigned int i = 0;
i <
params.size();
i++) {
759 double sigma_low = fchi->Eval(iAvg);
762 cout <<
"binstrip= " << iBinStrip <<
", sigmaup= " << sigma_up <<
", sigmalow= " << sigma_low << endl;
765 for (
int i = 1;
i <= iNBins;
i++) {
767 cout <<
" " <<
i <<
" binContent: up:" << fmuup->Eval(iHist->GetBinContent(iBinStrip,
i))
768 <<
" low: " << fmulow->Eval(iHist->GetBinContent(iBinStrip,
i)) << endl;
772 double muup = fmuup->Eval(iHist->GetBinContent(iBinStrip,
i));
773 double mulow = fmulow->Eval(iHist->GetBinContent(iBinStrip,
i));
776 if (hservice_->isMasked(iTestName, iBinStrip,
i)) {
777 oChannels.push_back(pair<int, double>(iHist->GetBin(iBinStrip,
i), -1.0));
780 else if (muup > sigma_up || mulow > sigma_low ||
785 pair<int, double>(iHist->GetBin(iBinStrip,
i),
abs(iHist->GetBinContent(iBinStrip,
i) - iAvg) / iAvg));
790 else if (iAxis == 2) {
792 TF1* fmuup =
new TF1(
"fmuup",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
793 TF1* fmulow =
new TF1(
"fmulow",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
795 fmuup->SetParameter(1, iAvg);
797 fmulow->SetParameter(1, iAvg);
799 TF1* fchi =
new TF1(
"fchi",
"[0]*x**2+[1]*x+[2]", 0., 1500.);
802 vector<double> defaultChi2up;
803 defaultChi2up.push_back(5.45058
e-05);
804 defaultChi2up.push_back(0.268756);
805 defaultChi2up.push_back(-11.7515);
808 for (
unsigned int i = 0;
i <
params.size();
i++) {
811 double sigma_up = fchi->Eval(iAvg);
814 vector<double> defaultChi2low;
815 defaultChi2low.push_back(4.11095
e-05);
816 defaultChi2low.push_back(0.577451);
817 defaultChi2low.push_back(-10.378);
820 for (
unsigned int i = 0;
i <
params.size();
i++) {
823 double sigma_low = fchi->Eval(iAvg);
826 cout <<
"binstrip= " << iBinStrip <<
", sigmaup= " << sigma_up <<
", sigmalow= " << sigma_low << endl;
829 for (
int i = 1;
i <= iNBins;
i++) {
831 cout <<
" " <<
i <<
" binContent: up:" << fmuup->Eval(iHist->GetBinContent(
i, iBinStrip))
832 <<
" low: " << fmulow->Eval(iHist->GetBinContent(
i, iBinStrip)) << endl;
836 double muup = fmuup->Eval(iHist->GetBinContent(
i, iBinStrip));
837 double mulow = fmulow->Eval(iHist->GetBinContent(
i, iBinStrip));
840 if (hservice_->isMasked(iTestName,
i, iBinStrip)) {
841 oChannels.push_back(pair<int, double>(iHist->GetBin(iBinStrip,
i), -1.0));
844 else if (muup > sigma_up || mulow > sigma_low ||
849 pair<int, double>(iHist->GetBin(
i, iBinStrip),
abs(iHist->GetBinContent(
i, iBinStrip) - iAvg) / iAvg));
854 cout <<
"invalid axis" << endl;
871 int nBinsX = iHist->GetNbinsX();
872 int nBinsY = iHist->GetNbinsY();
875 int global = iHist->GetXaxis()->FindFixBin(iValue);
878 if (global > nBinsX * nBinsY) {
879 global = iHist->GetXaxis()->GetLast();
884 iHist->GetBinXYZ(global, oBinCoordinate, y, z);
885 }
else if (iAxis == 2) {
886 int global = iHist->GetYaxis()->FindFixBin(iValue);
889 if (global > nBinsX * nBinsY) {
890 global = iHist->GetYaxis()->GetLast();
895 iHist->GetBinXYZ(global,
x, oBinCoordinate, z);
LuminosityBlockNumber_t luminosityBlock() const
T getParameter(std::string const &) const
void getBinCoordinateOnAxisWithValue(TH2F *h2f, double content, int &coord, int axis)
virtual void setCurrentFolder(std::string const &fullpath)
void printDeadChannels(const std::vector< std::pair< int, double > > &deadChannels, TH2F *h2f, const std::vector< std::pair< int, double > > &statDev, std::string test_name)
double getAvrg(TH2F *h2f, std::string test, int axis, int nBins, int binStrip, int avrgMode)
double xySymmetry(const edm::ParameterSet &ps, std::string test_name, std::vector< std::pair< int, double > > &deadChannels, std::vector< std::pair< int, double > > &statDev, bool &enoughStats)
void dqmEndJob(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) override
T getUntrackedParameter(std::string const &, T const &) const
void book(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
Abs< T >::type abs(const T &t)
#define DEFINE_FWK_MODULE(type)
LuminosityBlockID id() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
void dqmEndLuminosityBlock(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
int compareWithStrip(TH2F *histo, std::string test, int binStrip, int nBins, int axis, double avg, const edm::ParameterSet &ps, std::vector< std::pair< int, double > > &deadChannels)
L1TOccupancyClient(const edm::ParameterSet &ps)
Constructor.
~L1TOccupancyClient() override
Destructor.