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 j = upBinStrip,
k = lowBinStrip;
j <= maxBinStrip;
j++,
k--) {
423 if (!hservice_->isStripMasked(iTestName,
j, pAxis) && !hservice_->isStripMasked(iTestName,
k, pAxis)) {
424 maxAvgs[nActualStrips] =
TMath::Max(getAvrg(diffHist, iTestName, pAxis, nBinsY,
j, pAverageMode),
425 getAvrg(diffHist, iTestName, pAxis, nBinsY,
k, pAverageMode));
430 vector<double> defaultMu0up;
431 defaultMu0up.push_back(13.7655);
432 defaultMu0up.push_back(184.742);
433 defaultMu0up.push_back(50735.3);
434 defaultMu0up.push_back(-97.6793);
436 TF1 tf(
"myFunc",
"[0]*(TMath::Log(x*[1]+[2]))+[3]", 10., 11000.);
438 for (
unsigned int i = 0;
i <
params.size();
i++) {
441 int statsup = (
int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
443 vector<double> defaultMu0low;
444 defaultMu0low.push_back(2.19664);
445 defaultMu0low.push_back(1.94546);
446 defaultMu0low.push_back(-99.3263);
447 defaultMu0low.push_back(19.388);
450 for (
unsigned int i = 0;
i <
params.size();
i++) {
453 int statslow = (
int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
456 cout <<
"nbins: " << hservice_->getNBinsHistogram(iTestName) << endl;
457 cout <<
"statsup= " << statsup <<
", statslow= " << statslow << endl;
460 if (nActualStrips > 0) {
461 enoughStats = TMath::MinElement(nActualStrips, maxAvgs.get()) >
TMath::Max(statsup, statslow);
462 }
else if (verbose_) {
463 cout <<
"No valid strips found, insufficient statistics." << endl;
466 cout <<
"stats: " << TMath::MinElement(nActualStrips, maxAvgs.get())
467 <<
", statsAvg: " << diffHist->GetEntries() / hservice_->getNBinsHistogram(iTestName)
468 <<
", threshold: " <<
TMath::Max(statsup, statslow) << endl;
474 for (; upBinStrip <= maxBinStrip; upBinStrip++, lowBinStrip--) {
475 double avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, upBinStrip, pAverageMode);
477 diffHist, iTestName, lowBinStrip, nBinsY, pAxis, avg, ps, deadChannels);
479 avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, lowBinStrip, pAverageMode);
481 diffHist, iTestName, upBinStrip, nBinsY, pAxis, avg, ps, deadChannels);
487 else if (pAxis == 2) {
488 int maxBinStrip, centralBinStrip;
490 maxBinStrip = nBinsY;
494 centralBinStrip = nBinsY / 2 + 1;
496 double pAxisSymmetryValue = ps.
getParameter<
double>(
"axisSymmetryValue");
497 getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 2);
501 int lowBinStrip = centralBinStrip, upBinStrip = centralBinStrip;
504 if (nBinsX % 2 == 0) {
510 std::unique_ptr<double[]> maxAvgs(
new double[maxBinStrip - upBinStrip + 1]);
511 int nActualStrips = 0;
512 for (
int j = upBinStrip,
k = lowBinStrip;
j <= maxBinStrip;
j++,
k--) {
513 if (!hservice_->isStripMasked(iTestName,
j, pAxis) && !hservice_->isStripMasked(iTestName,
k, pAxis)) {
514 maxAvgs[nActualStrips] =
TMath::Max(getAvrg(diffHist, iTestName, pAxis, nBinsX,
j, pAverageMode),
515 getAvrg(diffHist, iTestName, pAxis, nBinsX,
k, pAverageMode));
520 vector<double> defaultMu0up;
521 defaultMu0up.push_back(13.7655);
522 defaultMu0up.push_back(184.742);
523 defaultMu0up.push_back(50735.3);
524 defaultMu0up.push_back(-97.6793);
527 TF1 tf(
"myFunc",
"[0]*(TMath::Log(x*[1]+[2]))+[3]", 10., 11000.);
528 for (
unsigned int i = 0;
i <
params.size();
i++) {
531 int statsup = (
int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
533 vector<double> defaultMu0low;
534 defaultMu0low.push_back(2.19664);
535 defaultMu0low.push_back(1.94546);
536 defaultMu0low.push_back(-99.3263);
537 defaultMu0low.push_back(19.388);
540 for (
unsigned int i = 0;
i <
params.size();
i++) {
543 int statslow = (
int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
545 cout <<
"statsup= " << statsup <<
", statslow= " << statslow << endl;
547 if (nActualStrips > 0) {
548 enoughStats = TMath::MinElement(nActualStrips, maxAvgs.get()) >
TMath::Max(statsup, statslow);
549 }
else if (verbose_) {
550 cout <<
"No valid strips found, insufficient statistics." << endl;
553 cout <<
"stats: " << TMath::MinElement(nActualStrips, maxAvgs.get())
554 <<
", statsAvg: " << diffHist->GetEntries() / hservice_->getNBinsHistogram(iTestName)
555 <<
", threshold: " <<
TMath::Max(statsup, statslow) << endl;
561 for (; upBinStrip <= maxBinStrip; upBinStrip++, lowBinStrip--) {
562 double avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, upBinStrip, pAverageMode);
564 diffHist, iTestName, lowBinStrip, nBinsX, pAxis, avg, ps, deadChannels);
566 avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, lowBinStrip, pAverageMode);
568 diffHist, iTestName, upBinStrip, nBinsX, pAxis, avg, ps, deadChannels);
573 cout <<
"Invalid axis" << endl;
577 return (deadChannels.size() - hservice_->getNBinsMasked(iTestName)) * 1.0 / hservice_->getNBinsHistogram(iTestName);
596 TH1D*
proj =
nullptr;
597 TH2F*
histo =
new TH2F(*iHist);
599 std::vector<double>
values;
606 marked = hservice_->maskBins(iTestName,
histo, iBinStrip, iAxis);
608 avg =
proj->GetBinContent(iBinStrip) / (iNBins - marked);
613 marked = hservice_->maskBins(iTestName,
histo, iBinStrip, iAxis);
614 proj =
histo->ProjectionY(
"_py", iBinStrip, iBinStrip);
615 for (
int i = 0;
i < iNBins;
i++) {
618 avg = TMath::Median(iNBins, &
values[0]);
622 cout <<
"Invalid averaging mode!" << endl;
626 }
else if (iAxis == 2) {
630 marked = hservice_->maskBins(iTestName,
histo, iBinStrip, iAxis);
632 avg =
proj->GetBinContent(iBinStrip) / (iNBins - marked);
636 marked = hservice_->maskBins(iTestName,
histo, iBinStrip, iAxis);
637 proj =
histo->ProjectionX(
"_px", iBinStrip, iBinStrip);
638 for (
int i = 0;
i < iNBins;
i++) {
642 avg = TMath::Median(iNBins, &
values[0]);
646 cout <<
"invalid averaging mode!" << endl;
652 cout <<
"invalid axis" << endl;
670 TH2F* oHistDeadChannels,
671 const vector<std::pair<int, double> >& statDev,
674 oHistDeadChannels->Reset();
676 cout <<
"suspect or masked channels of " << iTestName <<
": ";
682 for (
std::vector<pair<int, double> >::const_iterator
it = iDeadChannels.begin();
it != iDeadChannels.end();
it++) {
683 int bin = (*it).first;
684 oHistDeadChannels->GetBinXYZ(
bin,
x, y, z);
686 if (hservice_->isMasked(iTestName,
x, y)) {
687 oHistDeadChannels->SetBinContent(
bin, -1);
689 printf(
"(%4i,%4i) Masked\n",
x, y);
692 oHistDeadChannels->SetBinContent(
bin, 1);
694 printf(
"(%4i,%4i) Failed test\n",
x, y);
700 cout <<
"total number of suspect channels: " << (iDeadChannels.size() - (hservice_->getNBinsMasked(iTestName)))
727 vector<pair<int, double> >& oChannels) {
733 TF1* fmuup =
new TF1(
"fmuup",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
734 TF1* fmulow =
new TF1(
"fmulow",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
736 fmuup->SetParameter(1, iAvg);
738 fmulow->SetParameter(1, iAvg);
740 TF1* fchi =
new TF1(
"fchi",
"[0]*x**2+[1]*x+[2]", 0., 1500.);
743 vector<double> defaultChi2up;
744 defaultChi2up.push_back(5.45058
e-05);
745 defaultChi2up.push_back(0.268756);
746 defaultChi2up.push_back(-11.7515);
749 for (
unsigned int i = 0;
i <
params.size();
i++) {
752 double sigma_up = fchi->Eval(iAvg);
755 vector<double> defaultChi2low;
756 defaultChi2low.push_back(4.11095
e-05);
757 defaultChi2low.push_back(0.577451);
758 defaultChi2low.push_back(-10.378);
761 for (
unsigned int i = 0;
i <
params.size();
i++) {
764 double sigma_low = fchi->Eval(iAvg);
767 cout <<
"binstrip= " << iBinStrip <<
", sigmaup= " << sigma_up <<
", sigmalow= " << sigma_low << endl;
770 for (
int i = 1;
i <= iNBins;
i++) {
772 cout <<
" " <<
i <<
" binContent: up:" << fmuup->Eval(iHist->GetBinContent(iBinStrip,
i))
773 <<
" low: " << fmulow->Eval(iHist->GetBinContent(iBinStrip,
i)) << endl;
777 double muup = fmuup->Eval(iHist->GetBinContent(iBinStrip,
i));
778 double mulow = fmulow->Eval(iHist->GetBinContent(iBinStrip,
i));
781 if (hservice_->isMasked(iTestName, iBinStrip,
i)) {
782 oChannels.push_back(pair<int, double>(iHist->GetBin(iBinStrip,
i), -1.0));
785 else if (muup > sigma_up || mulow > sigma_low ||
790 pair<int, double>(iHist->GetBin(iBinStrip,
i),
abs(iHist->GetBinContent(iBinStrip,
i) - iAvg) / iAvg));
795 else if (iAxis == 2) {
797 TF1* fmuup =
new TF1(
"fmuup",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
798 TF1* fmulow =
new TF1(
"fmulow",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
800 fmuup->SetParameter(1, iAvg);
802 fmulow->SetParameter(1, iAvg);
804 TF1* fchi =
new TF1(
"fchi",
"[0]*x**2+[1]*x+[2]", 0., 1500.);
807 vector<double> defaultChi2up;
808 defaultChi2up.push_back(5.45058
e-05);
809 defaultChi2up.push_back(0.268756);
810 defaultChi2up.push_back(-11.7515);
813 for (
unsigned int i = 0;
i <
params.size();
i++) {
816 double sigma_up = fchi->Eval(iAvg);
819 vector<double> defaultChi2low;
820 defaultChi2low.push_back(4.11095
e-05);
821 defaultChi2low.push_back(0.577451);
822 defaultChi2low.push_back(-10.378);
825 for (
unsigned int i = 0;
i <
params.size();
i++) {
828 double sigma_low = fchi->Eval(iAvg);
831 cout <<
"binstrip= " << iBinStrip <<
", sigmaup= " << sigma_up <<
", sigmalow= " << sigma_low << endl;
834 for (
int i = 1;
i <= iNBins;
i++) {
836 cout <<
" " <<
i <<
" binContent: up:" << fmuup->Eval(iHist->GetBinContent(
i, iBinStrip))
837 <<
" low: " << fmulow->Eval(iHist->GetBinContent(
i, iBinStrip)) << endl;
841 double muup = fmuup->Eval(iHist->GetBinContent(
i, iBinStrip));
842 double mulow = fmulow->Eval(iHist->GetBinContent(
i, iBinStrip));
845 if (hservice_->isMasked(iTestName,
i, iBinStrip)) {
846 oChannels.push_back(pair<int, double>(iHist->GetBin(iBinStrip,
i), -1.0));
849 else if (muup > sigma_up || mulow > sigma_low ||
854 pair<int, double>(iHist->GetBin(
i, iBinStrip),
abs(iHist->GetBinContent(
i, iBinStrip) - iAvg) / iAvg));
859 cout <<
"invalid axis" << endl;
876 int nBinsX = iHist->GetNbinsX();
877 int nBinsY = iHist->GetNbinsY();
880 int global = iHist->GetXaxis()->FindFixBin(iValue);
883 if (global > nBinsX * nBinsY) {
884 global = iHist->GetXaxis()->GetLast();
889 iHist->GetBinXYZ(global, oBinCoordinate, y, z);
890 }
else if (iAxis == 2) {
891 int global = iHist->GetYaxis()->FindFixBin(iValue);
894 if (global > nBinsX * nBinsY) {
895 global = iHist->GetYaxis()->GetLast();
900 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.