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 std::unique_ptr<double[]> maxAvgs(
new double[maxBinStrip-upBinStrip+1]);
417 for(
int i=0,
j=upBinStrip,
k=lowBinStrip;
j<=maxBinStrip;
i++,
j++,
k--) {
418 double avg1 = getAvrg(diffHist,iTestName,pAxis,nBinsY,j,pAverageMode);
419 double avg2 = getAvrg(diffHist,iTestName,pAxis,nBinsY,
k,pAverageMode);
422 if(!hservice_->isStripMasked(iTestName,j,pAxis) && !hservice_->isStripMasked(iTestName,
k,pAxis)) {
428 vector<double> defaultMu0up;
429 defaultMu0up.push_back(13.7655);
430 defaultMu0up.push_back(184.742);
431 defaultMu0up.push_back(50735.3);
432 defaultMu0up.push_back(-97.6793);
434 TF1 tf(
"myFunc",
"[0]*(TMath::Log(x*[1]+[2]))+[3]",10.,11000.);
436 for(
unsigned int i=0;
i<params.size();
i++) {tf.SetParameter(
i,params[
i]);}
437 int statsup = (int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
439 vector<double> defaultMu0low;
440 defaultMu0low.push_back(2.19664);
441 defaultMu0low.push_back(1.94546);
442 defaultMu0low.push_back(-99.3263);
443 defaultMu0low.push_back(19.388);
446 for(
unsigned int i=0;
i<params.size();
i++) {tf.SetParameter(
i,params[
i]);}
447 int statslow = (int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
450 cout <<
"nbins: " << hservice_->getNBinsHistogram(iTestName) << endl;
451 cout <<
"statsup= " << statsup <<
", statslow= " << statslow << endl;
454 enoughStats = TMath::MinElement(nActualStrips,maxAvgs.get())>
TMath::Max(statsup,statslow);
456 cout <<
"stats: " << TMath::MinElement(nActualStrips,maxAvgs.get()) <<
", statsAvg: " << diffHist->GetEntries()/hservice_->getNBinsHistogram(iTestName) <<
", threshold: " <<
TMath::Max(statsup,statslow) << endl;
462 for(;upBinStrip<=maxBinStrip;upBinStrip++,lowBinStrip--) {
463 double avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, upBinStrip, pAverageMode);
464 compareWithStrip(diffHist,iTestName,lowBinStrip,nBinsY,pAxis,avg,ps,deadChannels);
466 avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, lowBinStrip, pAverageMode);
467 compareWithStrip(diffHist,iTestName,upBinStrip,nBinsY,pAxis,avg,ps,deadChannels);
474 int maxBinStrip, centralBinStrip;
476 maxBinStrip = nBinsY;
481 double pAxisSymmetryValue = ps.
getParameter<
double>(
"axisSymmetryValue");
482 getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 2);
487 int lowBinStrip = centralBinStrip, upBinStrip = centralBinStrip;
496 std::unique_ptr<double[]> maxAvgs(
new double[maxBinStrip-upBinStrip+1]);
497 int nActualStrips = 0;
498 for(
int i=0,
j=upBinStrip,
k=lowBinStrip;
j<=maxBinStrip;
i++,
j++,
k--) {
499 double avg1 = getAvrg(diffHist, iTestName, pAxis, nBinsX, j, pAverageMode);
500 double avg2 = getAvrg(diffHist, iTestName, pAxis, nBinsX,
k, pAverageMode);
501 if(!hservice_->isStripMasked(iTestName,j,pAxis) && !hservice_->isStripMasked(iTestName,
k,pAxis)) {
507 vector<double> defaultMu0up;
508 defaultMu0up.push_back(13.7655);
509 defaultMu0up.push_back(184.742);
510 defaultMu0up.push_back(50735.3);
511 defaultMu0up.push_back(-97.6793);
513 vector<double> params = ps.
getUntrackedParameter<std::vector<double> >(
"params_mu0_up",defaultMu0up);
514 TF1 tf(
"myFunc",
"[0]*(TMath::Log(x*[1]+[2]))+[3]",10.,11000.);
515 for(
unsigned int i=0;
i<params.size();
i++) {
516 tf.SetParameter(
i,params[
i]);
518 int statsup = (int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
520 vector<double> defaultMu0low;
521 defaultMu0low.push_back(2.19664);
522 defaultMu0low.push_back(1.94546);
523 defaultMu0low.push_back(-99.3263);
524 defaultMu0low.push_back(19.388);
527 for(
unsigned int i=0;
i<params.size();
i++) {
528 tf.SetParameter(
i,params[
i]);
530 int statslow = (int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
532 cout <<
"statsup= " << statsup <<
", statslow= " << statslow << endl;
534 enoughStats = TMath::MinElement(nActualStrips,maxAvgs.get())>
TMath::Max(statsup,statslow);
536 cout <<
"stats: " << TMath::MinElement(nActualStrips,maxAvgs.get()) <<
", statsAvg: " << diffHist->GetEntries()/hservice_->getNBinsHistogram(iTestName) <<
", threshold: " <<
TMath::Max(statsup,statslow) << endl;
542 for(;upBinStrip<=maxBinStrip;upBinStrip++,lowBinStrip--) {
543 double avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, upBinStrip, pAverageMode);
544 compareWithStrip(diffHist,iTestName, lowBinStrip,nBinsX,pAxis,avg,ps,deadChannels);
546 avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, lowBinStrip, pAverageMode);
547 compareWithStrip(diffHist,iTestName, upBinStrip,nBinsX,pAxis,avg,ps,deadChannels);
551 else {
if(verbose_){
cout <<
"Invalid axis" << endl;}}
553 return (deadChannels.size()-hservice_->getNBinsMasked(iTestName))*1.0/hservice_->getNBinsHistogram(iTestName);
574 TH2F*
histo =
new TH2F(*iHist);
576 std::vector<double>
values;
585 marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
586 proj = histo->ProjectionX();
587 avg = proj->GetBinContent(iBinStrip)/(iNBins-marked);
592 marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
593 proj = histo->ProjectionY(
"_py",iBinStrip,iBinStrip);
594 for(
int i=0;
i<iNBins;
i++) {
595 values.push_back(proj->GetBinContent(
i+1));
597 avg = TMath::Median(iNBins,&values[0]);
600 if(verbose_){
cout <<
"Invalid averaging mode!" << endl;}
609 marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
610 proj = histo->ProjectionY();
611 avg = proj->GetBinContent(iBinStrip)/(iNBins-marked);
615 marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
616 proj = histo->ProjectionX(
"_px",iBinStrip,iBinStrip);
617 for(
int i=0;
i<iNBins;
i++) {
618 values.push_back(proj->GetBinContent(
i+1));
621 avg = TMath::Median(iNBins,&values[0]);
624 if(verbose_) {
cout <<
"invalid averaging mode!" << endl;}
629 if(verbose_) {
cout <<
"invalid axis" << endl;}
648 oHistDeadChannels->Reset();
649 if(verbose_) {
cout <<
"suspect or masked channels of " << iTestName <<
": ";}
655 for (std::vector<pair<int,double> >::const_iterator it = iDeadChannels.begin(); it != iDeadChannels.end(); it++) {
657 int bin = (*it).first;
658 oHistDeadChannels->GetBinXYZ(bin,x,y,z);
660 if(hservice_->isMasked(iTestName,x,y)){
661 oHistDeadChannels->SetBinContent(bin,-1);
662 if(verbose_){printf(
"(%4i,%4i) Masked\n",x,y);}
665 oHistDeadChannels->SetBinContent(bin, 1);
666 if(verbose_){printf(
"(%4i,%4i) Failed test\n",x,y);}
671 for (std::vector<pair<int,double> >::const_iterator it = statDev.begin(); it != statDev.end(); it++) {
672 double dev = (*it).second;
678 cout <<
"total number of suspect channels: " << (iDeadChannels.size()-(hservice_->getNBinsMasked(iTestName))) << endl;
705 TF1* fmuup =
new TF1(
"fmuup" ,
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
706 TF1* fmulow =
new TF1(
"fmulow",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
708 fmuup ->SetParameter(1,iAvg);
710 fmulow->SetParameter(1,iAvg);
712 TF1* fchi =
new TF1(
"fchi",
"[0]*x**2+[1]*x+[2]",0.,1500.);
715 vector<double> defaultChi2up;
716 defaultChi2up.push_back(5.45058
e-05);
717 defaultChi2up.push_back(0.268756);
718 defaultChi2up.push_back(-11.7515);
721 for(
unsigned int i=0;
i<params.size();
i++){fchi->SetParameter(
i,params[
i]);}
722 double sigma_up = fchi->Eval(iAvg);
725 vector<double> defaultChi2low;
726 defaultChi2low.push_back(4.11095
e-05);
727 defaultChi2low.push_back(0.577451);
728 defaultChi2low.push_back(-10.378);
731 for(
unsigned int i=0;
i<params.size();
i++){fchi->SetParameter(
i,params[
i]);}
732 double sigma_low = fchi->Eval(iAvg);
734 if(verbose_){
cout <<
"binstrip= " << iBinStrip <<
", sigmaup= " << sigma_up <<
", sigmalow= " << sigma_low << endl;}
736 for(
int i=1;
i<=iNBins;
i++) {
738 cout <<
" " <<
i <<
" binContent: up:" << fmuup ->Eval(iHist->GetBinContent(iBinStrip,
i))
739 <<
" low: " << fmulow->Eval(iHist->GetBinContent(iBinStrip,
i)) << endl;
743 double muup = fmuup ->Eval(iHist->GetBinContent(iBinStrip,
i));
744 double mulow = fmulow->Eval(iHist->GetBinContent(iBinStrip,
i));
747 if(hservice_->isMasked(iTestName,iBinStrip,
i)) {
748 oChannels.push_back(pair<int,double>(iHist->GetBin(iBinStrip,
i),-1.0));
751 else if(muup > sigma_up ||
756 oChannels.push_back(pair<int,double>(iHist->GetBin(iBinStrip,
i),
abs(iHist->GetBinContent(iBinStrip,
i)-iAvg)/iAvg));
764 TF1* fmuup =
new TF1(
"fmuup" ,
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
765 TF1* fmulow =
new TF1(
"fmulow",
"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
767 fmuup ->SetParameter(1,iAvg);
769 fmulow->SetParameter(1,iAvg);
771 TF1* fchi =
new TF1(
"fchi",
"[0]*x**2+[1]*x+[2]",0.,1500.);
774 vector<double> defaultChi2up;
775 defaultChi2up.push_back(5.45058
e-05);
776 defaultChi2up.push_back(0.268756);
777 defaultChi2up.push_back(-11.7515);
780 for(
unsigned int i=0;
i<params.size();
i++){fchi->SetParameter(
i,params[
i]);}
781 double sigma_up = fchi->Eval(iAvg);
784 vector<double> defaultChi2low;
785 defaultChi2low.push_back(4.11095
e-05);
786 defaultChi2low.push_back(0.577451);
787 defaultChi2low.push_back(-10.378);
790 for(
unsigned int i=0;
i<params.size();
i++){fchi->SetParameter(
i,params[
i]);}
791 double sigma_low = fchi->Eval(iAvg);
793 if(verbose_) {
cout <<
"binstrip= " << iBinStrip <<
", sigmaup= " << sigma_up <<
", sigmalow= " << sigma_low << endl;}
795 for(
int i=1;
i<=iNBins;
i++) {
797 cout <<
" " <<
i <<
" binContent: up:" << fmuup ->Eval(iHist->GetBinContent(
i,iBinStrip))
798 <<
" low: " << fmulow->Eval(iHist->GetBinContent(
i,iBinStrip)) << endl;
802 double muup = fmuup ->Eval(iHist->GetBinContent(
i,iBinStrip));
803 double mulow = fmulow->Eval(iHist->GetBinContent(
i,iBinStrip));
806 if(hservice_->isMasked(iTestName,
i,iBinStrip)) {
807 oChannels.push_back(pair<int,double>(iHist->GetBin(iBinStrip,
i),-1.0));
810 else if(muup > sigma_up ||
815 oChannels.push_back(pair<int,double>(iHist->GetBin(
i,iBinStrip),
abs(iHist->GetBinContent(
i,iBinStrip)-iAvg)/iAvg));
819 else {
if(verbose_) {
cout <<
"invalid axis" << endl;}}
835 int nBinsX = iHist->GetNbinsX();
836 int nBinsY = iHist->GetNbinsY();
839 int global = iHist->GetXaxis()->FindFixBin(iValue);
842 if(global > nBinsX*nBinsY) {global = iHist->GetXaxis()->GetLast();}
846 iHist->GetBinXYZ(global,oBinCoordinate,y,z);
849 int global = iHist->GetYaxis()->FindFixBin(iValue);
852 if(global > nBinsX*nBinsY) {global = iHist->GetYaxis()->GetLast();}
856 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.