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;
269 book(ibooker, igetter);
274 cout <<
"[L1TOccupancyClient:] Called endLuminosityBlock()" << endl;
275 cout <<
"[L1TOccupancyClient:] Lumisection: " << eventLS << endl;
279 for (std::vector<ParameterSet*>::const_iterator it = mValidTests.begin(); it != mValidTests.end(); it++) {
281 string algo_name =
test.getUntrackedParameter<
string>(
"algoName",
"XYSymmetry");
282 string test_name =
test.getParameter<
string>(
"testName");
285 cout <<
"[L1TOccupancyClient:] Starting calculations for " <<
algo_name <<
" on:" << test_name << endl;
292 vector<pair<int, double> > deadChannels;
293 vector<pair<int, double> > statDev;
294 bool enoughStats =
false;
297 hservice_->updateHistogramEndLS(igetter, test_name,
histPath, eventLS);
300 double dead = xySymmetry(ps, test_name, deadChannels, statDev, enoughStats);
302 str << test_name <<
"_cumu_LS_" << eventLS;
305 TH2F* cumulative_save = (TH2F*)hservice_->getDifferentialHistogram(test_name)->Clone(
str.str().c_str());
306 cumulative_save->SetTitle(
str.str().c_str());
307 TDirectory* td = file_->GetDirectory(test_name.c_str());
308 td->cd(
string(test_name +
"_Histos_AllLS").c_str());
309 cumulative_save->Write();
315 printDeadChannels(deadChannels, meResults[test_name]->getTH2F(), statDev, test_name);
318 TH2F* cumulative_save = (TH2F*)hservice_->getDifferentialHistogram(test_name)->Clone(
str.str().c_str());
319 cumulative_save->SetTitle(
str.str().c_str());
320 TDirectory* td = file_->GetDirectory((
"DQM_L1TOccupancyClient_Snapshots_LS.root:/" + test_name).c_str());
321 td->cd(
string(test_name +
"_Histos").c_str());
322 cumulative_save->Write();
325 TH2F* h2f = meResults[test_name]->getTH2F();
327 str2 << test_name <<
"_result_LS_" << eventLS;
328 TH2F* dead_save = (TH2F*)h2f->Clone(str2.str().c_str());
330 td->cd(
string(test_name +
"_Results").c_str());
331 dead_save->SetTitle(str2.str().c_str());
336 meDifferential[test_name]->Reset();
337 meDifferential[test_name]->getTH2F()->Add(hservice_->getDifferentialHistogram(test_name));
339 vector<int> lsCertification = hservice_->getLSCertification(test_name);
342 for (
unsigned int i = 0;
i < lsCertification.size();
i++) {
343 int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[
i]);
344 meCertification[test_name]->getTH1()->SetBinContent(
bin, 1 - dead);
348 hservice_->resetHisto(test_name);
351 cout <<
"Now we have enough statstics for " << test_name << endl;
356 cout <<
"we don't have enough statstics for " << test_name << endl;
361 cout <<
"No valid algorithm" << std::endl;
390 vector<pair<int, double> >& deadChannels,
391 vector<pair<int, double> >& statDev,
394 TH2F* diffHist = hservice_->getDifferentialHistogram(iTestName);
398 int nBinsX = diffHist->GetNbinsX();
399 int nBinsY = diffHist->GetNbinsY();
403 int maxBinStrip, centralBinStrip;
405 maxBinStrip = nBinsX;
410 centralBinStrip = nBinsX / 2 + 1;
412 double pAxisSymmetryValue = ps.
getParameter<
double>(
"axisSymmetryValue");
413 getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 1);
417 int upBinStrip = centralBinStrip;
418 int lowBinStrip = centralBinStrip;
421 if (nBinsX % 2 == 0) {
426 std::unique_ptr<double[]> maxAvgs(
new double[maxBinStrip - upBinStrip + 1]);
428 int nActualStrips = 0;
429 for (
int i = 0,
j = upBinStrip,
k = lowBinStrip;
j <= maxBinStrip;
i++,
j++,
k--) {
430 double avg1 = getAvrg(diffHist, iTestName, pAxis, nBinsY,
j, pAverageMode);
431 double avg2 = getAvrg(diffHist, iTestName, pAxis, nBinsY,
k, pAverageMode);
434 if (!hservice_->isStripMasked(iTestName,
j, pAxis) && !hservice_->isStripMasked(iTestName,
k, pAxis)) {
440 vector<double> defaultMu0up;
441 defaultMu0up.push_back(13.7655);
442 defaultMu0up.push_back(184.742);
443 defaultMu0up.push_back(50735.3);
444 defaultMu0up.push_back(-97.6793);
446 TF1 tf(
"myFunc",
"[0]*(TMath::Log(x*[1]+[2]))+[3]", 10., 11000.);
448 for (
unsigned int i = 0;
i <
params.size();
i++) {
451 int statsup = (
int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
453 vector<double> defaultMu0low;
454 defaultMu0low.push_back(2.19664);
455 defaultMu0low.push_back(1.94546);
456 defaultMu0low.push_back(-99.3263);
457 defaultMu0low.push_back(19.388);
460 for (
unsigned int i = 0;
i <
params.size();
i++) {
463 int statslow = (
int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
466 cout <<
"nbins: " << hservice_->getNBinsHistogram(iTestName) << endl;
467 cout <<
"statsup= " << statsup <<
", statslow= " << statslow << endl;
470 enoughStats = TMath::MinElement(nActualStrips, maxAvgs.get()) >
TMath::Max(statsup, statslow);
472 cout <<
"stats: " << TMath::MinElement(nActualStrips, maxAvgs.get())
473 <<
", statsAvg: " << diffHist->GetEntries() / hservice_->getNBinsHistogram(iTestName)
474 <<
", threshold: " <<
TMath::Max(statsup, statslow) << endl;
480 for (; upBinStrip <= maxBinStrip; upBinStrip++, lowBinStrip--) {
481 double avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, upBinStrip, pAverageMode);
483 diffHist, iTestName, lowBinStrip, nBinsY, pAxis, avg, ps, deadChannels);
485 avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, lowBinStrip, pAverageMode);
487 diffHist, iTestName, upBinStrip, nBinsY, pAxis, avg, ps, deadChannels);
493 else if (pAxis == 2) {
494 int maxBinStrip, centralBinStrip;
496 maxBinStrip = nBinsY;
500 centralBinStrip = nBinsY / 2 + 1;
502 double pAxisSymmetryValue = ps.
getParameter<
double>(
"axisSymmetryValue");
503 getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 2);
507 int lowBinStrip = centralBinStrip, upBinStrip = centralBinStrip;
510 if (nBinsX % 2 == 0) {
516 std::unique_ptr<double[]> maxAvgs(
new double[maxBinStrip - upBinStrip + 1]);
517 int nActualStrips = 0;
518 for (
int i = 0,
j = upBinStrip,
k = lowBinStrip;
j <= maxBinStrip;
i++,
j++,
k--) {
519 double avg1 = getAvrg(diffHist, iTestName, pAxis, nBinsX,
j, pAverageMode);
520 double avg2 = getAvrg(diffHist, iTestName, pAxis, nBinsX,
k, pAverageMode);
521 if (!hservice_->isStripMasked(iTestName,
j, pAxis) && !hservice_->isStripMasked(iTestName,
k, pAxis)) {
527 vector<double> defaultMu0up;
528 defaultMu0up.push_back(13.7655);
529 defaultMu0up.push_back(184.742);
530 defaultMu0up.push_back(50735.3);
531 defaultMu0up.push_back(-97.6793);
534 TF1 tf(
"myFunc",
"[0]*(TMath::Log(x*[1]+[2]))+[3]", 10., 11000.);
535 for (
unsigned int i = 0;
i <
params.size();
i++) {
538 int statsup = (
int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
540 vector<double> defaultMu0low;
541 defaultMu0low.push_back(2.19664);
542 defaultMu0low.push_back(1.94546);
543 defaultMu0low.push_back(-99.3263);
544 defaultMu0low.push_back(19.388);
547 for (
unsigned int i = 0;
i <
params.size();
i++) {
550 int statslow = (
int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
552 cout <<
"statsup= " << statsup <<
", statslow= " << statslow << endl;
554 enoughStats = TMath::MinElement(nActualStrips, maxAvgs.get()) >
TMath::Max(statsup, statslow);
556 cout <<
"stats: " << TMath::MinElement(nActualStrips, maxAvgs.get())
557 <<
", statsAvg: " << diffHist->GetEntries() / hservice_->getNBinsHistogram(iTestName)
558 <<
", threshold: " <<
TMath::Max(statsup, statslow) << endl;
564 for (; upBinStrip <= maxBinStrip; upBinStrip++, lowBinStrip--) {
565 double avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, upBinStrip, pAverageMode);
567 diffHist, iTestName, lowBinStrip, nBinsX, pAxis, avg, ps, deadChannels);
569 avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, lowBinStrip, pAverageMode);
571 diffHist, iTestName, upBinStrip, nBinsX, pAxis, avg, ps, deadChannels);
576 cout <<
"Invalid axis" << endl;
580 return (deadChannels.size() - hservice_->getNBinsMasked(iTestName)) * 1.0 / hservice_->getNBinsHistogram(iTestName);
599 TH1D*
proj =
nullptr;
600 TH2F*
histo =
new TH2F(*iHist);
602 std::vector<double>
values;
609 marked = hservice_->maskBins(iTestName,
histo, iBinStrip, iAxis);
611 avg =
proj->GetBinContent(iBinStrip) / (iNBins - marked);
616 marked = hservice_->maskBins(iTestName,
histo, iBinStrip, iAxis);
617 proj =
histo->ProjectionY(
"_py", iBinStrip, iBinStrip);
618 for (
int i = 0;
i < iNBins;
i++) {
621 avg = TMath::Median(iNBins, &
values[0]);
625 cout <<
"Invalid averaging mode!" << endl;
629 }
else if (iAxis == 2) {
633 marked = hservice_->maskBins(iTestName,
histo, iBinStrip, iAxis);
635 avg =
proj->GetBinContent(iBinStrip) / (iNBins - marked);
639 marked = hservice_->maskBins(iTestName,
histo, iBinStrip, iAxis);
640 proj =
histo->ProjectionX(
"_px", iBinStrip, iBinStrip);
641 for (
int i = 0;
i < iNBins;
i++) {
645 avg = TMath::Median(iNBins, &
values[0]);
649 cout <<
"invalid averaging mode!" << endl;
655 cout <<
"invalid axis" << endl;
673 TH2F* oHistDeadChannels,
674 const vector<std::pair<int, double> >& statDev,
677 oHistDeadChannels->Reset();
679 cout <<
"suspect or masked channels of " << iTestName <<
": ";
686 for (
std::vector<pair<int, double> >::const_iterator it = iDeadChannels.begin(); it != iDeadChannels.end(); it++) {
687 int bin = (*it).first;
688 oHistDeadChannels->GetBinXYZ(
bin,
x, y, z);
690 if (hservice_->isMasked(iTestName,
x, y)) {
691 oHistDeadChannels->SetBinContent(
bin, -1);
693 printf(
"(%4i,%4i) Masked\n",
x, y);
696 oHistDeadChannels->SetBinContent(
bin, 1);
698 printf(
"(%4i,%4i) Failed test\n",
x, y);
704 for (
std::vector<pair<int, double> >::const_iterator it = statDev.begin(); it != statDev.end(); it++) {
705 double dev = (*it).second;
711 cout <<
"total number of suspect channels: " << (iDeadChannels.size() - (hservice_->getNBinsMasked(iTestName)))
738 vector<pair<int, double> >& oChannels) {
744 TF1* fmuup =
new TF1(
"fmuup",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
745 TF1* fmulow =
new TF1(
"fmulow",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
747 fmuup->SetParameter(1, iAvg);
749 fmulow->SetParameter(1, iAvg);
751 TF1* fchi =
new TF1(
"fchi",
"[0]*x**2+[1]*x+[2]", 0., 1500.);
754 vector<double> defaultChi2up;
755 defaultChi2up.push_back(5.45058
e-05);
756 defaultChi2up.push_back(0.268756);
757 defaultChi2up.push_back(-11.7515);
760 for (
unsigned int i = 0;
i <
params.size();
i++) {
763 double sigma_up = fchi->Eval(iAvg);
766 vector<double> defaultChi2low;
767 defaultChi2low.push_back(4.11095
e-05);
768 defaultChi2low.push_back(0.577451);
769 defaultChi2low.push_back(-10.378);
772 for (
unsigned int i = 0;
i <
params.size();
i++) {
775 double sigma_low = fchi->Eval(iAvg);
778 cout <<
"binstrip= " << iBinStrip <<
", sigmaup= " << sigma_up <<
", sigmalow= " << sigma_low << endl;
781 for (
int i = 1;
i <= iNBins;
i++) {
783 cout <<
" " <<
i <<
" binContent: up:" << fmuup->Eval(iHist->GetBinContent(iBinStrip,
i))
784 <<
" low: " << fmulow->Eval(iHist->GetBinContent(iBinStrip,
i)) << endl;
788 double muup = fmuup->Eval(iHist->GetBinContent(iBinStrip,
i));
789 double mulow = fmulow->Eval(iHist->GetBinContent(iBinStrip,
i));
792 if (hservice_->isMasked(iTestName, iBinStrip,
i)) {
793 oChannels.push_back(pair<int, double>(iHist->GetBin(iBinStrip,
i), -1.0));
796 else if (muup > sigma_up || mulow > sigma_low ||
801 pair<int, double>(iHist->GetBin(iBinStrip,
i),
abs(iHist->GetBinContent(iBinStrip,
i) - iAvg) / iAvg));
806 else if (iAxis == 2) {
808 TF1* fmuup =
new TF1(
"fmuup",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
809 TF1* fmulow =
new TF1(
"fmulow",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
811 fmuup->SetParameter(1, iAvg);
813 fmulow->SetParameter(1, iAvg);
815 TF1* fchi =
new TF1(
"fchi",
"[0]*x**2+[1]*x+[2]", 0., 1500.);
818 vector<double> defaultChi2up;
819 defaultChi2up.push_back(5.45058
e-05);
820 defaultChi2up.push_back(0.268756);
821 defaultChi2up.push_back(-11.7515);
824 for (
unsigned int i = 0;
i <
params.size();
i++) {
827 double sigma_up = fchi->Eval(iAvg);
830 vector<double> defaultChi2low;
831 defaultChi2low.push_back(4.11095
e-05);
832 defaultChi2low.push_back(0.577451);
833 defaultChi2low.push_back(-10.378);
836 for (
unsigned int i = 0;
i <
params.size();
i++) {
839 double sigma_low = fchi->Eval(iAvg);
842 cout <<
"binstrip= " << iBinStrip <<
", sigmaup= " << sigma_up <<
", sigmalow= " << sigma_low << endl;
845 for (
int i = 1;
i <= iNBins;
i++) {
847 cout <<
" " <<
i <<
" binContent: up:" << fmuup->Eval(iHist->GetBinContent(
i, iBinStrip))
848 <<
" low: " << fmulow->Eval(iHist->GetBinContent(
i, iBinStrip)) << endl;
852 double muup = fmuup->Eval(iHist->GetBinContent(
i, iBinStrip));
853 double mulow = fmulow->Eval(iHist->GetBinContent(
i, iBinStrip));
856 if (hservice_->isMasked(iTestName,
i, iBinStrip)) {
857 oChannels.push_back(pair<int, double>(iHist->GetBin(iBinStrip,
i), -1.0));
860 else if (muup > sigma_up || mulow > sigma_low ||
865 pair<int, double>(iHist->GetBin(
i, iBinStrip),
abs(iHist->GetBinContent(
i, iBinStrip) - iAvg) / iAvg));
870 cout <<
"invalid axis" << endl;
887 int nBinsX = iHist->GetNbinsX();
888 int nBinsY = iHist->GetNbinsY();
891 int global = iHist->GetXaxis()->FindFixBin(iValue);
894 if (global > nBinsX * nBinsY) {
895 global = iHist->GetXaxis()->GetLast();
900 iHist->GetBinXYZ(global, oBinCoordinate, y, z);
901 }
else if (iAxis == 2) {
902 int global = iHist->GetYaxis()->FindFixBin(iValue);
905 if (global > nBinsX * nBinsY) {
906 global = iHist->GetYaxis()->GetLast();
911 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)
#define DEFINE_FWK_MODULE(type)
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)
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.