19 #include <TDirectory.h>
37 tests_ = ps.
getParameter<std::vector<ParameterSet> >(
"testParams");
39 if(verbose_){
cout <<
"[L1TOccupancyClient:] Called constructor" << endl;}
47 if(verbose_){
cout <<
"[L1TOccupancyClient:] Called destructor" << endl;}
62 cout <<
"[L1TOccupancyClient:] Called beginRun" << endl;
65 file_ = TFile::Open(
"DQM_L1TOccupancyClient_Snapshots_LS.root",
"RECREATE");
74 for (vector<ParameterSet>::iterator it = tests_.begin(); it != tests_.end(); it++) {
77 if((*it).getUntrackedParameter<
string>(
"algoName",
"XYSymmetry")==
"XYSymmetry") {
80 string testName = (*it).getParameter<
string> (
"testName");
82 string histPath = algoParameters.
getParameter<
string>(
"histPath");
85 cout <<
"[L1TOccupancyClient:] Monitored histogram path: " << histPath << endl;
99 if(hservice_->loadHisto(igetter, testName,histPath)){
104 hservice_->setMaskedBins(testName,algoParameters.getParameter<vector<ParameterSet> >(
"maskedAreas"));
109 string title = testName;
118 m = ibooker.
book2D(title.c_str(),hservice_->getDifferentialHistogram(testName));
121 meDifferential[
title] =
m;
126 m = ibooker.
book1D(title.c_str(),title.c_str(),2500,-.5,2500.-.5);
128 meCertification[
title] =
m;
130 mValidTests.push_back(&(*it));
147 book(ibooker, igetter);
149 if(verbose_){
cout <<
"[L1TOccupancyClient:] Called endRun()" << endl;}
152 for (std::vector<ParameterSet*>::iterator it = mValidTests.begin(); it != mValidTests.end(); it++) {
156 string test_name = test.
getParameter <
string>(
"testName");
158 if(verbose_) {
cout <<
"[L1TOccupancyClient:] Starting calculations for: " << algo_name <<
" on: " << test_name << endl;}
160 if(algo_name ==
"XYSymmetry") {
165 vector<pair<int,double> > deadChannels;
166 vector<pair<int,double> > statDev;
167 bool enoughStats =
false;
170 hservice_->updateHistogramEndRun(test_name);
173 double dead = xySymmetry(ps,test_name,deadChannels,statDev,enoughStats);
175 str << test_name <<
"_cumu_LS_EndRun";
178 TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
180 cumulative_save->SetTitle(str.str().c_str());
182 TDirectory*
td = file_->GetDirectory(test_name.c_str());
184 td->cd(
string(test_name+
"_Histos_AllLS").c_str());
186 cumulative_save->Write();
192 printDeadChannels(deadChannels,meResults[test_name]->
getTH2F(),statDev,test_name);
195 TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
196 cumulative_save->SetTitle(str.str().c_str());
197 TDirectory*
td = file_->GetDirectory((
"DQM_L1TOccupancyClient_Snapshots_LS.root:/"+test_name).c_str());
198 td->cd(
string(test_name+
"_Histos").c_str());
199 cumulative_save->Write();
202 TH2F* h2f = meResults[test_name]->getTH2F();
204 str2 << test_name <<
"_result_LS_EndRun";
205 TH2F* dead_save = (TH2F*) h2f->Clone(str2.str().c_str());
207 td->cd(
string(test_name+
"_Results").c_str());
208 dead_save->SetTitle(str2.str().c_str());
213 meDifferential[test_name]->Reset();
214 meDifferential[test_name]->getTH2F()->Add(hservice_->getDifferentialHistogram(test_name));
216 vector<int> lsCertification = hservice_->getLSCertification(test_name);
219 for(
unsigned int i=0;
i<lsCertification.size();
i++){
220 int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[
i]);
221 meCertification[test_name]->getTH1()->SetBinContent(bin,1-dead);
225 hservice_->resetHisto(test_name);
227 if(verbose_) {
cout <<
"Now we have enough statstics for " << test_name << endl;}
230 if(verbose_){
cout <<
"we don't have enough statstics for " << test_name << endl;}
233 vector<int> lsCertification = hservice_->getLSCertification(test_name);
236 for(
unsigned int i=0;
i<lsCertification.size();
i++){
237 int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[
i]);
238 meCertification[test_name]->getTH1()->SetBinContent(bin,-1);
241 }
else {
if(verbose_){
cout <<
"No valid algorithm" << std::endl;}}
244 if(verbose_){file_->Close();}
267 book(ibooker, igetter);
272 cout <<
"[L1TOccupancyClient:] Called endLuminosityBlock()" << endl;
273 cout <<
"[L1TOccupancyClient:] Lumisection: " << eventLS << endl;
277 for (std::vector<ParameterSet*>::const_iterator it = mValidTests.begin(); it != mValidTests.end(); it++) {
281 string test_name = test.
getParameter <
string>(
"testName");
283 if(verbose_) {
cout <<
"[L1TOccupancyClient:] Starting calculations for " << algo_name <<
" on:" << test_name << endl;}
285 if(algo_name ==
"XYSymmetry") {
290 vector<pair<int,double> > deadChannels;
291 vector<pair<int,double> > statDev;
292 bool enoughStats =
false;
295 hservice_->updateHistogramEndLS(igetter, test_name,histPath,eventLS);
298 double dead = xySymmetry(ps,test_name,deadChannels,statDev,enoughStats);
300 str << test_name <<
"_cumu_LS_" << eventLS;
303 TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
304 cumulative_save->SetTitle(str.str().c_str());
305 TDirectory*
td = file_->GetDirectory(test_name.c_str());
306 td->cd(
string(test_name+
"_Histos_AllLS").c_str());
307 cumulative_save->Write();
314 printDeadChannels(deadChannels,meResults[test_name]->
getTH2F(),statDev,test_name);
317 TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
318 cumulative_save->SetTitle(str.str().c_str());
319 TDirectory*
td = file_->GetDirectory((
"DQM_L1TOccupancyClient_Snapshots_LS.root:/"+test_name).c_str());
320 td->cd(
string(test_name+
"_Histos").c_str());
321 cumulative_save->Write();
324 TH2F* h2f = meResults[test_name]->getTH2F();
326 str2 << test_name <<
"_result_LS_" << eventLS;
327 TH2F* dead_save = (TH2F*) h2f->Clone(str2.str().c_str());
329 td->cd(
string(test_name+
"_Results").c_str());
330 dead_save->SetTitle(str2.str().c_str());
335 meDifferential[test_name]->Reset();
336 meDifferential[test_name]->getTH2F()->Add(hservice_->getDifferentialHistogram(test_name));
338 vector<int> lsCertification = hservice_->getLSCertification(test_name);
341 for(
unsigned int i=0;
i<lsCertification.size();
i++){
342 int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[
i]);
343 meCertification[test_name]->getTH1()->SetBinContent(bin,1-dead);
347 hservice_->resetHisto(test_name);
349 if(verbose_) {
cout <<
"Now we have enough statstics for " << test_name << endl;}
351 }
else{
if(verbose_){
cout <<
"we don't have enough statstics for " << test_name << endl;}}
352 }
else {
if(verbose_){
cout <<
"No valid algorithm" << std::endl;}}
379 vector< pair<int,double> >& deadChannels,
380 vector< pair<int,double> >& statDev,
384 TH2F* diffHist = hservice_->getDifferentialHistogram(iTestName);
388 int nBinsX = diffHist->GetNbinsX();
389 int nBinsY = diffHist->GetNbinsY();
394 int maxBinStrip, centralBinStrip;
396 maxBinStrip = nBinsX;
402 double pAxisSymmetryValue = ps.
getParameter <
double>(
"axisSymmetryValue");
403 getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 1);
407 int upBinStrip = centralBinStrip;
408 int lowBinStrip = centralBinStrip;
411 if(nBinsX%2==0){lowBinStrip--;}
414 double* maxAvgs =
new double[maxBinStrip-upBinStrip+1];
416 for(
int i=0,
j=upBinStrip,
k=lowBinStrip;
j<=maxBinStrip;
i++,
j++,
k--) {
417 double avg1 = getAvrg(diffHist,iTestName,pAxis,nBinsY,j,pAverageMode);
418 double avg2 = getAvrg(diffHist,iTestName,pAxis,nBinsY,
k,pAverageMode);
421 if(!hservice_->isStripMasked(iTestName,j,pAxis) && !hservice_->isStripMasked(iTestName,
k,pAxis)) {
427 vector<double> defaultMu0up;
428 defaultMu0up.push_back(13.7655);
429 defaultMu0up.push_back(184.742);
430 defaultMu0up.push_back(50735.3);
431 defaultMu0up.push_back(-97.6793);
433 TF1* tf =
new TF1(
"myFunc",
"[0]*(TMath::Log(x*[1]+[2]))+[3]",10.,11000.);
435 for(
unsigned int i=0;
i<params.size();
i++) {tf->SetParameter(
i,params[
i]);}
436 int statsup = (int)tf->Eval(hservice_->getNBinsHistogram(iTestName));
438 vector<double> defaultMu0low;
439 defaultMu0low.push_back(2.19664);
440 defaultMu0low.push_back(1.94546);
441 defaultMu0low.push_back(-99.3263);
442 defaultMu0low.push_back(19.388);
445 for(
unsigned int i=0;
i<params.size();
i++) {tf->SetParameter(
i,params[
i]);}
446 int statslow = (int)tf->Eval(hservice_->getNBinsHistogram(iTestName));
449 cout <<
"nbins: " << hservice_->getNBinsHistogram(iTestName) << endl;
450 cout <<
"statsup= " << statsup <<
", statslow= " << statslow << endl;
453 enoughStats = TMath::MinElement(nActualStrips,maxAvgs)>
TMath::Max(statsup,statslow);
455 cout <<
"stats: " << TMath::MinElement(nActualStrips,maxAvgs) <<
", statsAvg: " << diffHist->GetEntries()/hservice_->getNBinsHistogram(iTestName) <<
", threshold: " <<
TMath::Max(statsup,statslow) << endl;
461 for(;upBinStrip<=maxBinStrip;upBinStrip++,lowBinStrip--) {
462 double avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, upBinStrip, pAverageMode);
463 compareWithStrip(diffHist,iTestName,lowBinStrip,nBinsY,pAxis,avg,ps,deadChannels);
465 avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, lowBinStrip, pAverageMode);
466 compareWithStrip(diffHist,iTestName,upBinStrip,nBinsY,pAxis,avg,ps,deadChannels);
473 int maxBinStrip, centralBinStrip;
475 maxBinStrip = nBinsY;
480 double pAxisSymmetryValue = ps.
getParameter<
double>(
"axisSymmetryValue");
481 getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 2);
486 int lowBinStrip = centralBinStrip, upBinStrip = centralBinStrip;
495 double* maxAvgs =
new double[maxBinStrip-upBinStrip+1];
496 int nActualStrips = 0;
497 for(
int i=0,
j=upBinStrip,
k=lowBinStrip;
j<=maxBinStrip;
i++,
j++,
k--) {
498 double avg1 = getAvrg(diffHist, iTestName, pAxis, nBinsX, j, pAverageMode);
499 double avg2 = getAvrg(diffHist, iTestName, pAxis, nBinsX,
k, pAverageMode);
500 if(!hservice_->isStripMasked(iTestName,j,pAxis) && !hservice_->isStripMasked(iTestName,
k,pAxis)) {
506 vector<double> defaultMu0up;
507 defaultMu0up.push_back(13.7655);
508 defaultMu0up.push_back(184.742);
509 defaultMu0up.push_back(50735.3);
510 defaultMu0up.push_back(-97.6793);
512 vector<double> params = ps.
getUntrackedParameter<std::vector<double> >(
"params_mu0_up",defaultMu0up);
513 TF1* tf =
new TF1(
"myFunc",
"[0]*(TMath::Log(x*[1]+[2]))+[3]",10.,11000.);
514 for(
unsigned int i=0;
i<params.size();
i++) {
515 tf->SetParameter(
i,params[
i]);
517 int statsup = (int)tf->Eval(hservice_->getNBinsHistogram(iTestName));
519 vector<double> defaultMu0low;
520 defaultMu0low.push_back(2.19664);
521 defaultMu0low.push_back(1.94546);
522 defaultMu0low.push_back(-99.3263);
523 defaultMu0low.push_back(19.388);
526 for(
unsigned int i=0;
i<params.size();
i++) {
527 tf->SetParameter(
i,params[
i]);
529 int statslow = (int)tf->Eval(hservice_->getNBinsHistogram(iTestName));
531 cout <<
"statsup= " << statsup <<
", statslow= " << statslow << endl;
533 enoughStats = TMath::MinElement(nActualStrips,maxAvgs)>
TMath::Max(statsup,statslow);
535 cout <<
"stats: " << TMath::MinElement(nActualStrips,maxAvgs) <<
", statsAvg: " << diffHist->GetEntries()/hservice_->getNBinsHistogram(iTestName) <<
", threshold: " <<
TMath::Max(statsup,statslow) << endl;
541 for(;upBinStrip<=maxBinStrip;upBinStrip++,lowBinStrip--) {
542 double avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, upBinStrip, pAverageMode);
543 compareWithStrip(diffHist,iTestName, lowBinStrip,nBinsX,pAxis,avg,ps,deadChannels);
545 avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, lowBinStrip, pAverageMode);
546 compareWithStrip(diffHist,iTestName, upBinStrip,nBinsX,pAxis,avg,ps,deadChannels);
550 else {
if(verbose_){
cout <<
"Invalid axis" << endl;}}
552 return (deadChannels.size()-hservice_->getNBinsMasked(iTestName))*1.0/hservice_->getNBinsHistogram(iTestName);
573 TH2F*
histo = (TH2F*) iHist->Clone();
575 std::vector<double>
values;
584 marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
585 proj = histo->ProjectionX();
586 avg = proj->GetBinContent(iBinStrip)/(iNBins-marked);
591 marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
592 proj = histo->ProjectionY(
"_py",iBinStrip,iBinStrip);
593 for(
int i=0;
i<iNBins;
i++) {
594 values.push_back(proj->GetBinContent(
i+1));
596 avg = TMath::Median(iNBins,&values[0]);
599 if(verbose_){
cout <<
"Invalid averaging mode!" << endl;}
608 marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
609 proj = histo->ProjectionY();
610 avg = proj->GetBinContent(iBinStrip)/(iNBins-marked);
614 marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
615 proj = histo->ProjectionX(
"_px",iBinStrip,iBinStrip);
616 for(
int i=0;
i<iNBins;
i++) {
617 values.push_back(proj->GetBinContent(
i+1));
620 avg = TMath::Median(iNBins,&values[0]);
623 if(verbose_) {
cout <<
"invalid averaging mode!" << endl;}
628 if(verbose_) {
cout <<
"invalid axis" << endl;}
647 oHistDeadChannels->Reset();
648 if(verbose_) {
cout <<
"suspect or masked channels of " << iTestName <<
": ";}
654 for (std::vector<pair<int,double> >::const_iterator it = iDeadChannels.begin(); it != iDeadChannels.end(); it++) {
656 int bin = (*it).first;
657 oHistDeadChannels->GetBinXYZ(bin,x,y,z);
659 if(hservice_->isMasked(iTestName,x,y)){
660 oHistDeadChannels->SetBinContent(bin,-1);
661 if(verbose_){printf(
"(%4i,%4i) Masked\n",x,y);}
664 oHistDeadChannels->SetBinContent(bin, 1);
665 if(verbose_){printf(
"(%4i,%4i) Failed test\n",x,y);}
670 for (std::vector<pair<int,double> >::const_iterator it = statDev.begin(); it != statDev.end(); it++) {
671 double dev = (*it).second;
677 cout <<
"total number of suspect channels: " << (iDeadChannels.size()-(hservice_->getNBinsMasked(iTestName))) << endl;
704 TF1* fmuup =
new TF1(
"fmuup" ,
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
705 TF1* fmulow =
new TF1(
"fmulow",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
707 fmuup ->SetParameter(1,iAvg);
709 fmulow->SetParameter(1,iAvg);
711 TF1* fchi =
new TF1(
"fchi",
"[0]*x**2+[1]*x+[2]",0.,1500.);
714 vector<double> defaultChi2up;
715 defaultChi2up.push_back(5.45058
e-05);
716 defaultChi2up.push_back(0.268756);
717 defaultChi2up.push_back(-11.7515);
720 for(
unsigned int i=0;
i<params.size();
i++){fchi->SetParameter(
i,params[
i]);}
721 double sigma_up = fchi->Eval(iAvg);
724 vector<double> defaultChi2low;
725 defaultChi2low.push_back(4.11095
e-05);
726 defaultChi2low.push_back(0.577451);
727 defaultChi2low.push_back(-10.378);
730 for(
unsigned int i=0;
i<params.size();
i++){fchi->SetParameter(
i,params[
i]);}
731 double sigma_low = fchi->Eval(iAvg);
733 if(verbose_){
cout <<
"binstrip= " << iBinStrip <<
", sigmaup= " << sigma_up <<
", sigmalow= " << sigma_low << endl;}
735 for(
int i=1;
i<=iNBins;
i++) {
737 cout <<
" " <<
i <<
" binContent: up:" << fmuup ->Eval(iHist->GetBinContent(iBinStrip,
i))
738 <<
" low: " << fmulow->Eval(iHist->GetBinContent(iBinStrip,
i)) << endl;
742 double muup = fmuup ->Eval(iHist->GetBinContent(iBinStrip,
i));
743 double mulow = fmulow->Eval(iHist->GetBinContent(iBinStrip,
i));
746 if(hservice_->isMasked(iTestName,iBinStrip,
i)) {
747 oChannels.push_back(pair<int,double>(iHist->GetBin(iBinStrip,
i),-1.0));
750 else if(muup > sigma_up ||
755 oChannels.push_back(pair<int,double>(iHist->GetBin(iBinStrip,
i),
abs(iHist->GetBinContent(iBinStrip,
i)-iAvg)/iAvg));
763 TF1* fmuup =
new TF1(
"fmuup" ,
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
764 TF1* fmulow =
new TF1(
"fmulow",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
766 fmuup ->SetParameter(1,iAvg);
768 fmulow->SetParameter(1,iAvg);
770 TF1* fchi =
new TF1(
"fchi",
"[0]*x**2+[1]*x+[2]",0.,1500.);
773 vector<double> defaultChi2up;
774 defaultChi2up.push_back(5.45058
e-05);
775 defaultChi2up.push_back(0.268756);
776 defaultChi2up.push_back(-11.7515);
779 for(
unsigned int i=0;
i<params.size();
i++){fchi->SetParameter(
i,params[
i]);}
780 double sigma_up = fchi->Eval(iAvg);
783 vector<double> defaultChi2low;
784 defaultChi2low.push_back(4.11095
e-05);
785 defaultChi2low.push_back(0.577451);
786 defaultChi2low.push_back(-10.378);
789 for(
unsigned int i=0;
i<params.size();
i++){fchi->SetParameter(
i,params[
i]);}
790 double sigma_low = fchi->Eval(iAvg);
792 if(verbose_) {
cout <<
"binstrip= " << iBinStrip <<
", sigmaup= " << sigma_up <<
", sigmalow= " << sigma_low << endl;}
794 for(
int i=1;
i<=iNBins;
i++) {
796 cout <<
" " <<
i <<
" binContent: up:" << fmuup ->Eval(iHist->GetBinContent(
i,iBinStrip))
797 <<
" low: " << fmulow->Eval(iHist->GetBinContent(
i,iBinStrip)) << endl;
801 double muup = fmuup ->Eval(iHist->GetBinContent(
i,iBinStrip));
802 double mulow = fmulow->Eval(iHist->GetBinContent(
i,iBinStrip));
805 if(hservice_->isMasked(iTestName,
i,iBinStrip)) {
806 oChannels.push_back(pair<int,double>(iHist->GetBin(iBinStrip,
i),-1.0));
809 else if(muup > sigma_up ||
814 oChannels.push_back(pair<int,double>(iHist->GetBin(
i,iBinStrip),
abs(iHist->GetBinContent(
i,iBinStrip)-iAvg)/iAvg));
818 else {
if(verbose_) {
cout <<
"invalid axis" << endl;}}
834 int nBinsX = iHist->GetNbinsX();
835 int nBinsY = iHist->GetNbinsY();
838 int global = iHist->GetXaxis()->FindFixBin(iValue);
841 if(global > nBinsX*nBinsY) {global = iHist->GetXaxis()->GetLast();}
845 iHist->GetBinXYZ(global,oBinCoordinate,y,z);
848 int global = iHist->GetYaxis()->FindFixBin(iValue);
851 if(global > nBinsX*nBinsY) {global = iHist->GetYaxis()->GetLast();}
855 iHist->GetBinXYZ(global,x,oBinCoordinate,z);
LuminosityBlockID id() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void getBinCoordinateOnAxisWithValue(TH2F *h2f, double content, int &coord, int axis)
virtual ~L1TOccupancyClient()
Destructor.
#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
void book(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
MonitorElement * book1D(Args &&...args)
Abs< T >::type abs(const T &t)
void setTitle(const std::string &title)
set (ie. change) histogram/profile title
void setCurrentFolder(const std::string &fullpath)
MonitorElement * book2D(Args &&...args)
LuminosityBlockNumber_t luminosityBlock() const
TH2F * getTH2F(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
void dqmEndLuminosityBlock(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
void Reset(void)
reset ME (ie. contents, errors, etc)
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.