18 #include <TDirectory.h> 36 tests_ = ps.
getParameter<std::vector<ParameterSet> >(
"testParams");
38 if(verbose_){
cout <<
"[L1TOccupancyClient:] Called constructor" << endl;}
46 if(verbose_){
cout <<
"[L1TOccupancyClient:] Called destructor" << endl;}
61 cout <<
"[L1TOccupancyClient:] Called beginRun" << endl;
64 file_ = TFile::Open(
"DQM_L1TOccupancyClient_Snapshots_LS.root",
"RECREATE");
73 for (vector<ParameterSet>::iterator it = tests_.begin(); it != tests_.end(); it++) {
76 if((*it).getUntrackedParameter<
string>(
"algoName",
"XYSymmetry")==
"XYSymmetry") {
79 string testName = (*it).getParameter<
string> (
"testName");
81 string histPath = algoParameters.
getParameter<
string>(
"histPath");
84 cout <<
"[L1TOccupancyClient:] Monitored histogram path: " << histPath << endl;
98 if(hservice_->loadHisto(igetter, testName,histPath)){
103 hservice_->setMaskedBins(testName,algoParameters.getParameter<vector<ParameterSet> >(
"maskedAreas"));
108 string title = testName;
117 m = ibooker.
book2D(title.c_str(),hservice_->getDifferentialHistogram(testName));
120 meDifferential[
title] =
m;
125 m = ibooker.
book1D(title.c_str(),title.c_str(),2500,-.5,2500.-.5);
127 meCertification[
title] =
m;
129 mValidTests.push_back(&(*it));
146 book(ibooker, igetter);
148 if(verbose_){
cout <<
"[L1TOccupancyClient:] Called endRun()" << endl;}
151 for (std::vector<ParameterSet*>::iterator it = mValidTests.begin(); it != mValidTests.end(); it++) {
155 string test_name = test.
getParameter <
string>(
"testName");
157 if(verbose_) {
cout <<
"[L1TOccupancyClient:] Starting calculations for: " << algo_name <<
" on: " << test_name << endl;}
159 if(algo_name ==
"XYSymmetry") {
164 vector<pair<int,double> > deadChannels;
165 vector<pair<int,double> > statDev;
166 bool enoughStats =
false;
169 hservice_->updateHistogramEndRun(test_name);
172 double dead = xySymmetry(ps,test_name,deadChannels,statDev,enoughStats);
174 str << test_name <<
"_cumu_LS_EndRun";
177 TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
179 cumulative_save->SetTitle(str.str().c_str());
181 TDirectory* td = file_->GetDirectory(test_name.c_str());
183 td->cd(
string(test_name+
"_Histos_AllLS").c_str());
185 cumulative_save->Write();
191 printDeadChannels(deadChannels,meResults[test_name]->getTH2F(),statDev,test_name);
194 TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
195 cumulative_save->SetTitle(str.str().c_str());
196 TDirectory* td = file_->GetDirectory((
"DQM_L1TOccupancyClient_Snapshots_LS.root:/"+test_name).c_str());
197 td->cd(
string(test_name+
"_Histos").c_str());
198 cumulative_save->Write();
201 TH2F* h2f = meResults[test_name]->getTH2F();
203 str2 << test_name <<
"_result_LS_EndRun";
204 TH2F* dead_save = (TH2F*) h2f->Clone(str2.str().c_str());
206 td->cd(
string(test_name+
"_Results").c_str());
207 dead_save->SetTitle(str2.str().c_str());
212 meDifferential[test_name]->Reset();
213 meDifferential[test_name]->getTH2F()->Add(hservice_->getDifferentialHistogram(test_name));
215 vector<int> lsCertification = hservice_->getLSCertification(test_name);
218 for(
unsigned int i=0;
i<lsCertification.size();
i++){
219 int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[
i]);
220 meCertification[test_name]->getTH1()->SetBinContent(bin,1-dead);
224 hservice_->resetHisto(test_name);
226 if(verbose_) {
cout <<
"Now we have enough statstics for " << test_name << endl;}
229 if(verbose_){
cout <<
"we don't have enough statstics for " << test_name << endl;}
232 vector<int> lsCertification = hservice_->getLSCertification(test_name);
235 for(
unsigned int i=0;
i<lsCertification.size();
i++){
236 int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[
i]);
237 meCertification[test_name]->getTH1()->SetBinContent(bin,-1);
240 }
else {
if(verbose_){
cout <<
"No valid algorithm" << std::endl;}}
243 if(verbose_){file_->Close();}
266 book(ibooker, igetter);
271 cout <<
"[L1TOccupancyClient:] Called endLuminosityBlock()" << endl;
272 cout <<
"[L1TOccupancyClient:] Lumisection: " << eventLS << endl;
276 for (std::vector<ParameterSet*>::const_iterator it = mValidTests.begin(); it != mValidTests.end(); it++) {
280 string test_name = test.
getParameter <
string>(
"testName");
282 if(verbose_) {
cout <<
"[L1TOccupancyClient:] Starting calculations for " << algo_name <<
" on:" << test_name << endl;}
284 if(algo_name ==
"XYSymmetry") {
289 vector<pair<int,double> > deadChannels;
290 vector<pair<int,double> > statDev;
291 bool enoughStats =
false;
294 hservice_->updateHistogramEndLS(igetter, test_name,histPath,eventLS);
297 double dead = xySymmetry(ps,test_name,deadChannels,statDev,enoughStats);
299 str << test_name <<
"_cumu_LS_" << eventLS;
302 TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
303 cumulative_save->SetTitle(str.str().c_str());
304 TDirectory* td = file_->GetDirectory(test_name.c_str());
305 td->cd(
string(test_name+
"_Histos_AllLS").c_str());
306 cumulative_save->Write();
313 printDeadChannels(deadChannels,meResults[test_name]->getTH2F(),statDev,test_name);
316 TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
317 cumulative_save->SetTitle(str.str().c_str());
318 TDirectory* td = file_->GetDirectory((
"DQM_L1TOccupancyClient_Snapshots_LS.root:/"+test_name).c_str());
319 td->cd(
string(test_name+
"_Histos").c_str());
320 cumulative_save->Write();
323 TH2F* h2f = meResults[test_name]->getTH2F();
325 str2 << test_name <<
"_result_LS_" << eventLS;
326 TH2F* dead_save = (TH2F*) h2f->Clone(str2.str().c_str());
328 td->cd(
string(test_name+
"_Results").c_str());
329 dead_save->SetTitle(str2.str().c_str());
334 meDifferential[test_name]->Reset();
335 meDifferential[test_name]->getTH2F()->Add(hservice_->getDifferentialHistogram(test_name));
337 vector<int> lsCertification = hservice_->getLSCertification(test_name);
340 for(
unsigned int i=0;
i<lsCertification.size();
i++){
341 int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[
i]);
342 meCertification[test_name]->getTH1()->SetBinContent(bin,1-dead);
346 hservice_->resetHisto(test_name);
348 if(verbose_) {
cout <<
"Now we have enough statstics for " << test_name << endl;}
350 }
else{
if(verbose_){
cout <<
"we don't have enough statstics for " << test_name << endl;}}
351 }
else {
if(verbose_){
cout <<
"No valid algorithm" << std::endl;}}
378 vector< pair<int,double> >& deadChannels,
379 vector< pair<int,double> >& statDev,
383 TH2F* diffHist = hservice_->getDifferentialHistogram(iTestName);
387 int nBinsX = diffHist->GetNbinsX();
388 int nBinsY = diffHist->GetNbinsY();
393 int maxBinStrip, centralBinStrip;
395 maxBinStrip = nBinsX;
401 double pAxisSymmetryValue = ps.
getParameter <
double>(
"axisSymmetryValue");
402 getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 1);
406 int upBinStrip = centralBinStrip;
407 int lowBinStrip = centralBinStrip;
410 if(nBinsX%2==0){lowBinStrip--;}
413 std::unique_ptr<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(
"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.get())>
TMath::Max(statsup,statslow);
455 cout <<
"stats: " << TMath::MinElement(nActualStrips,maxAvgs.get()) <<
", 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 std::unique_ptr<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(
"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.get())>
TMath::Max(statsup,statslow);
535 cout <<
"stats: " << TMath::MinElement(nActualStrips,maxAvgs.get()) <<
", 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 =
new TH2F(*iHist);
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
T x() const
Cartesian x coordinate.
void book(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
MonitorElement * book1D(Args &&...args)
Abs< T >::type abs(const T &t)
bin
set the eta bin as selection string.
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
void dqmEndLuminosityBlock(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
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.