00001 #include "DQM/L1TMonitorClient/interface/L1TOccupancyClient.h"
00002
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "DQMServices/Core/interface/QReport.h"
00009 #include "DQMServices/Core/interface/DQMStore.h"
00010 #include "DQMServices/Core/interface/MonitorElement.h"
00011 #include "DataFormats/Histograms/interface/MEtoEDMFormat.h"
00012 #include <stdio.h>
00013 #include <sstream>
00014 #include <math.h>
00015 #include <vector>
00016 #include <TMath.h>
00017 #include <limits.h>
00018 #include <TFile.h>
00019 #include <TDirectory.h>
00020 #include <TProfile.h>
00021
00022 using namespace std;
00023 using namespace edm;
00024
00025
00026
00027
00028
00029
00030
00031 L1TOccupancyClient::L1TOccupancyClient(const edm::ParameterSet& ps){
00032
00033
00034
00035 parameters_ = ps;
00036 verbose_ = ps.getParameter<bool> ("verbose");
00037 tests_ = ps.getParameter<std::vector<ParameterSet> >("testParams");
00038
00039 if(verbose_){cout << "[L1TOccupancyClient:] Called constructor" << endl;}
00040
00041
00042 dbe_ = Service<DQMStore>().operator->();
00043
00044 }
00045
00046
00047
00048
00049
00050 L1TOccupancyClient::~L1TOccupancyClient(){
00051 if(verbose_){cout << "[L1TOccupancyClient:] Called destructor" << endl;}
00052 }
00053
00054
00055
00056
00057
00058 void L1TOccupancyClient::beginJob(void){
00059
00060 if(verbose_){cout << "[L1TOccupancyClient:] Called BeginJob" << endl;}
00061
00062
00063 dbe_ = Service<DQMStore>().operator->();
00064
00065 if (dbe_) {
00066 dbe_->setCurrentFolder("L1T/L1TOccupancy");
00067 dbe_->rmdir("L1T/L1TOccupancy");
00068 }
00069 }
00070
00071
00072
00073
00074
00075 void L1TOccupancyClient::endJob(){
00076
00077 if(verbose_){cout << "[L1TOccupancyClient:] Called endJob" << endl;}
00078
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088 void L1TOccupancyClient::beginRun(const Run& r, const EventSetup& context){
00089
00090 hservice_ = new L1TOccupancyClientHistogramService(parameters_,dbe_,verbose_);
00091
00092 if(verbose_){
00093 cout << "[L1TOccupancyClient:] Called beginRun" << endl;
00094
00095
00096 file_ = TFile::Open("DQM_L1TOccupancyClient_Snapshots_LS.root","RECREATE");
00097 }
00098
00099 dbe_->setCurrentFolder("L1T/L1TOccupancy/");
00100 dbe_->setCurrentFolder("L1T/L1TOccupancy/Results");
00101 dbe_->setCurrentFolder("L1T/L1TOccupancy/BadCellValues");
00102 dbe_->setCurrentFolder("L1T/L1TOccupancy/Certification");
00103
00104
00105 for (vector<ParameterSet>::iterator it = tests_.begin(); it != tests_.end(); it++) {
00106
00107
00108 if((*it).getUntrackedParameter<string>("algoName","XYSymmetry")=="XYSymmetry") {
00109
00110
00111 string testName = (*it).getParameter<string> ("testName");
00112 ParameterSet algoParameters = (*it).getParameter<ParameterSet> ("algoParams");
00113 string histPath = algoParameters.getParameter<string>("histPath");
00114
00115 if(verbose_){
00116 cout << "[L1TOccupancyClient:] Monitored histogram path: " << histPath << endl;
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 }
00128
00129
00130 if(hservice_->loadHisto(testName,histPath)){
00131
00132
00133
00134
00135 hservice_->setMaskedBins(testName,algoParameters.getParameter<vector<ParameterSet> >("maskedAreas"));
00136
00137
00138
00139 dbe_->setCurrentFolder("L1T/L1TOccupancy/Results");
00140 string title = testName;
00141 MonitorElement* m = dbe_->book2D(title.c_str(),hservice_->getDifferentialHistogram(testName));
00142 m->setTitle(title.c_str());
00143 m->Reset();
00144 meResults[title] = m;
00145
00146
00147 dbe_->setCurrentFolder("L1T/L1TOccupancy/HistogramDiff");
00148 title = testName;
00149 m = dbe_->book2D(title.c_str(),hservice_->getDifferentialHistogram(testName));
00150 m->Reset();
00151 m->setTitle(title.c_str());
00152 meDifferential[title] = m;
00153
00154
00155 dbe_->setCurrentFolder("L1T/L1TOccupancy/Certification");
00156 title = testName;
00157 m = dbe_->book1D(title.c_str(),title.c_str(),2500,-.5,2500.-.5);
00158 m->setTitle(title.c_str());
00159 meCertification[title] = m;
00160
00161 mValidTests.push_back(&(*it));
00162
00163 }
00164
00165 }
00166 }
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176 void L1TOccupancyClient::endRun(const Run& r, const EventSetup& context){
00177
00178 if(verbose_){cout << "[L1TOccupancyClient:] Called endRun()" << endl;}
00179
00180
00181 for (std::vector<ParameterSet*>::iterator it = mValidTests.begin(); it != mValidTests.end(); it++) {
00182
00183 ParameterSet &test = (**it);
00184 string algo_name = test.getUntrackedParameter<string>("algoName","XYSymmetry");
00185 string test_name = test.getParameter <string>("testName");
00186
00187 if(verbose_) {cout << "[L1TOccupancyClient:] Starting calculations for: " << algo_name << " on: " << test_name << endl;}
00188
00189 if(algo_name == "XYSymmetry") {
00190
00191 ParameterSet ps = (**it).getParameter<ParameterSet>("algoParams");
00192 string histPath = ps.getParameter<string>("histPath");
00193
00194 vector<pair<int,double> > deadChannels;
00195 vector<pair<int,double> > statDev;
00196 bool enoughStats = false;
00197
00198
00199 hservice_->updateHistogramEndRun(test_name);
00200
00201
00202 double dead = xySymmetry(ps,test_name,deadChannels,statDev,enoughStats);
00203 stringstream str;
00204 str << test_name << "_cumu_LS_EndRun";
00205
00206 if(verbose_) {
00207 TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
00208
00209 cumulative_save->SetTitle(str.str().c_str());
00210
00211 TDirectory* td = file_->GetDirectory(test_name.c_str());
00212
00213 td->cd(string(test_name+"_Histos_AllLS").c_str());
00214
00215 cumulative_save->Write();
00216 }
00217
00218 if(enoughStats) {
00219
00220
00221 printDeadChannels(deadChannels,meResults[test_name]->getTH2F(),statDev,test_name);
00222
00223 if(verbose_) {
00224 TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
00225 cumulative_save->SetTitle(str.str().c_str());
00226 TDirectory* td = file_->GetDirectory(("DQM_L1TOccupancyClient_Snapshots_LS.root:/"+test_name).c_str());
00227 td->cd(string(test_name+"_Histos").c_str());
00228 cumulative_save->Write();
00229
00230
00231 TH2F* h2f = meResults[test_name]->getTH2F();
00232 stringstream str2;
00233 str2 << test_name << "_result_LS_EndRun";
00234 TH2F* dead_save = (TH2F*) h2f->Clone(str2.str().c_str());
00235
00236 td->cd(string(test_name+"_Results").c_str());
00237 dead_save->SetTitle(str2.str().c_str());
00238 dead_save->Write();
00239 }
00240
00241
00242 meDifferential[test_name]->Reset();
00243 meDifferential[test_name]->getTH2F()->Add(hservice_->getDifferentialHistogram(test_name));
00244
00245 vector<int> lsCertification = hservice_->getLSCertification(test_name);
00246
00247
00248 for(unsigned int i=0;i<lsCertification.size();i++){
00249 int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[i]);
00250 meCertification[test_name]->getTH1()->SetBinContent(bin,1-dead);
00251 }
00252
00253
00254 hservice_->resetHisto(test_name);
00255
00256 if(verbose_) {cout << "Now we have enough statstics for " << test_name << endl;}
00257
00258 }else{
00259 if(verbose_){cout << "we don't have enough statstics for " << test_name << endl;}
00260
00261
00262 vector<int> lsCertification = hservice_->getLSCertification(test_name);
00263
00264
00265 for(unsigned int i=0;i<lsCertification.size();i++){
00266 int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[i]);
00267 meCertification[test_name]->getTH1()->SetBinContent(bin,-1);
00268 }
00269 }
00270 }else {if(verbose_){cout << "No valid algorithm" << std::endl;}}
00271 }
00272
00273 if(verbose_){file_->Close();}
00274
00275 delete hservice_;
00276
00277 }
00278
00279
00280
00281
00282
00283
00284
00285
00286 void L1TOccupancyClient::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
00287 if(verbose_){cout << "[L1TOccupancyClient:] Called beginLuminosityBlock()" << endl;}
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297 void L1TOccupancyClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00298 const edm::EventSetup& c){
00299
00300 int eventLS = lumiSeg.id().luminosityBlock();
00301
00302 if(verbose_) {
00303 cout << "[L1TOccupancyClient:] Called endLuminosityBlock()" << endl;
00304 cout << "[L1TOccupancyClient:] Lumisection: " << eventLS << endl;
00305 }
00306
00307
00308 for (std::vector<ParameterSet*>::const_iterator it = mValidTests.begin(); it != mValidTests.end(); it++) {
00309
00310 ParameterSet &test = (**it);
00311 string algo_name = test.getUntrackedParameter<string>("algoName","XYSymmetry");
00312 string test_name = test.getParameter <string>("testName");
00313
00314 if(verbose_) {cout << "[L1TOccupancyClient:] Starting calculations for " << algo_name << " on:" << test_name << endl;}
00315
00316 if(algo_name == "XYSymmetry") {
00317
00318 ParameterSet ps = (**it).getParameter<ParameterSet>("algoParams");
00319 string histPath = ps.getParameter<string>("histPath");
00320
00321 vector<pair<int,double> > deadChannels;
00322 vector<pair<int,double> > statDev;
00323 bool enoughStats = false;
00324
00325
00326 hservice_->updateHistogramEndLS(test_name,histPath,eventLS);
00327
00328
00329 double dead = xySymmetry(ps,test_name,deadChannels,statDev,enoughStats);
00330 stringstream str;
00331 str << test_name << "_cumu_LS_" << eventLS;
00332
00333 if(verbose_) {
00334 TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
00335 cumulative_save->SetTitle(str.str().c_str());
00336 TDirectory* td = file_->GetDirectory(test_name.c_str());
00337 td->cd(string(test_name+"_Histos_AllLS").c_str());
00338 cumulative_save->Write();
00339 }
00340
00341
00342 if(enoughStats) {
00343
00344
00345 printDeadChannels(deadChannels,meResults[test_name]->getTH2F(),statDev,test_name);
00346
00347 if(verbose_) {
00348 TH2F* cumulative_save = (TH2F*) hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
00349 cumulative_save->SetTitle(str.str().c_str());
00350 TDirectory* td = file_->GetDirectory(("DQM_L1TOccupancyClient_Snapshots_LS.root:/"+test_name).c_str());
00351 td->cd(string(test_name+"_Histos").c_str());
00352 cumulative_save->Write();
00353
00354
00355 TH2F* h2f = meResults[test_name]->getTH2F();
00356 stringstream str2;
00357 str2 << test_name << "_result_LS_" << eventLS;
00358 TH2F* dead_save = (TH2F*) h2f->Clone(str2.str().c_str());
00359
00360 td->cd(string(test_name+"_Results").c_str());
00361 dead_save->SetTitle(str2.str().c_str());
00362 dead_save->Write();
00363 }
00364
00365
00366 meDifferential[test_name]->Reset();
00367 meDifferential[test_name]->getTH2F()->Add(hservice_->getDifferentialHistogram(test_name));
00368
00369 vector<int> lsCertification = hservice_->getLSCertification(test_name);
00370
00371
00372 for(unsigned int i=0;i<lsCertification.size();i++){
00373 int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[i]);
00374 meCertification[test_name]->getTH1()->SetBinContent(bin,1-dead);
00375 }
00376
00377
00378 hservice_->resetHisto(test_name);
00379
00380 if(verbose_) {cout << "Now we have enough statstics for " << test_name << endl;}
00381
00382 }else{if(verbose_){cout << "we don't have enough statstics for " << test_name << endl;}}
00383 }else {if(verbose_){cout << "No valid algorithm" << std::endl;}}
00384 }
00385 }
00386
00387
00388
00389
00390
00391
00392
00393
00394 void L1TOccupancyClient::analyze(const Event& e, const EventSetup& context){}
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408 double L1TOccupancyClient::xySymmetry(ParameterSet ps,
00409 string iTestName,
00410 vector< pair<int,double> >& deadChannels,
00411 vector< pair<int,double> >& statDev,
00412 bool& enoughStats){
00413
00414
00415 TH2F* diffHist = hservice_->getDifferentialHistogram(iTestName);
00416
00417 int pAxis = ps.getUntrackedParameter<int> ("axis",1);
00418 int pAverageMode = ps.getUntrackedParameter<int> ("averageMode",2);
00419 int nBinsX = diffHist->GetNbinsX();
00420 int nBinsY = diffHist->GetNbinsY();
00421
00422
00423 if(pAxis==1){
00424
00425 int maxBinStrip, centralBinStrip;
00426
00427 maxBinStrip = nBinsX;
00428
00429
00430
00431 if(ps.getUntrackedParameter<bool>("takeCenter",true)){centralBinStrip = nBinsX / 2 + 1;}
00432 else {
00433 double pAxisSymmetryValue = ps.getParameter <double>("axisSymmetryValue");
00434 getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 1);
00435 }
00436
00437
00438 int upBinStrip = centralBinStrip;
00439 int lowBinStrip = centralBinStrip;
00440
00441
00442 if(nBinsX%2==0){lowBinStrip--;}
00443
00444
00445 double* maxAvgs = new double[maxBinStrip-upBinStrip+1];
00446 int nActualStrips=0;
00447 for(int i=0, j=upBinStrip, k=lowBinStrip;j<=maxBinStrip;i++,j++,k--) {
00448 double avg1 = getAvrg(diffHist,iTestName,pAxis,nBinsY,j,pAverageMode);
00449 double avg2 = getAvrg(diffHist,iTestName,pAxis,nBinsY,k,pAverageMode);
00450
00451
00452 if(!hservice_->isStripMasked(iTestName,j,pAxis) && !hservice_->isStripMasked(iTestName,k,pAxis)) {
00453 maxAvgs[i] = TMath::Max(avg1,avg2);
00454 nActualStrips++;
00455 }
00456 }
00457
00458 vector<double> defaultMu0up;
00459 defaultMu0up.push_back(13.7655);
00460 defaultMu0up.push_back(184.742);
00461 defaultMu0up.push_back(50735.3);
00462 defaultMu0up.push_back(-97.6793);
00463
00464 TF1* tf = new TF1("myFunc","[0]*(TMath::Log(x*[1]+[2]))+[3]",10.,11000.);
00465 vector<double> params = ps.getUntrackedParameter< vector<double> >("params_mu0_up",defaultMu0up);
00466 for(unsigned int i=0;i<params.size();i++) {tf->SetParameter(i,params[i]);}
00467 int statsup = (int)tf->Eval(hservice_->getNBinsHistogram(iTestName));
00468
00469 vector<double> defaultMu0low;
00470 defaultMu0low.push_back(2.19664);
00471 defaultMu0low.push_back(1.94546);
00472 defaultMu0low.push_back(-99.3263);
00473 defaultMu0low.push_back(19.388);
00474
00475 params = ps.getUntrackedParameter<vector<double> >("params_mu0_low",defaultMu0low);
00476 for(unsigned int i=0;i<params.size();i++) {tf->SetParameter(i,params[i]);}
00477 int statslow = (int)tf->Eval(hservice_->getNBinsHistogram(iTestName));
00478
00479 if(verbose_) {
00480 cout << "nbins: " << hservice_->getNBinsHistogram(iTestName) << endl;
00481 cout << "statsup= " << statsup << ", statslow= " << statslow << endl;
00482 }
00483
00484 enoughStats = TMath::MinElement(nActualStrips,maxAvgs)>TMath::Max(statsup,statslow);
00485 if(verbose_) {
00486 cout << "stats: " << TMath::MinElement(nActualStrips,maxAvgs) << ", statsAvg: " << diffHist->GetEntries()/hservice_->getNBinsHistogram(iTestName) << ", threshold: " << TMath::Max(statsup,statslow) << endl;
00487 }
00488
00489
00490
00491 if(enoughStats) {
00492 for(;upBinStrip<=maxBinStrip;upBinStrip++,lowBinStrip--) {
00493 double avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, upBinStrip, pAverageMode);
00494 compareWithStrip(diffHist,iTestName,lowBinStrip,nBinsY,pAxis,avg,ps,deadChannels);
00495
00496 avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, lowBinStrip, pAverageMode);
00497 compareWithStrip(diffHist,iTestName,upBinStrip,nBinsY,pAxis,avg,ps,deadChannels);
00498 }
00499 }
00500 }
00501
00502
00503 else if(pAxis==2) {
00504 int maxBinStrip, centralBinStrip;
00505
00506 maxBinStrip = nBinsY;
00507
00508
00509 if(ps.getUntrackedParameter<bool>("takeCenter",true)){centralBinStrip = nBinsY / 2 + 1;}
00510 else {
00511 double pAxisSymmetryValue = ps.getParameter<double>("axisSymmetryValue");
00512 getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 2);
00513
00514 }
00515
00516
00517 int lowBinStrip = centralBinStrip, upBinStrip = centralBinStrip;
00518
00519
00520 if(nBinsX%2==0) {
00521
00522 lowBinStrip--;
00523 }
00524
00525
00526 double* maxAvgs = new double[maxBinStrip-upBinStrip+1];
00527 int nActualStrips = 0;
00528 for(int i=0, j=upBinStrip, k=lowBinStrip;j<=maxBinStrip;i++,j++,k--) {
00529 double avg1 = getAvrg(diffHist, iTestName, pAxis, nBinsX, j, pAverageMode);
00530 double avg2 = getAvrg(diffHist, iTestName, pAxis, nBinsX, k, pAverageMode);
00531 if(!hservice_->isStripMasked(iTestName,j,pAxis) && !hservice_->isStripMasked(iTestName,k,pAxis)) {
00532 maxAvgs[i] = TMath::Max(avg1,avg2);
00533 nActualStrips++;
00534 }
00535 }
00536
00537 vector<double> defaultMu0up;
00538 defaultMu0up.push_back(13.7655);
00539 defaultMu0up.push_back(184.742);
00540 defaultMu0up.push_back(50735.3);
00541 defaultMu0up.push_back(-97.6793);
00542
00543 vector<double> params = ps.getUntrackedParameter<std::vector<double> >("params_mu0_up",defaultMu0up);
00544 TF1* tf = new TF1("myFunc","[0]*(TMath::Log(x*[1]+[2]))+[3]",10.,11000.);
00545 for(unsigned int i=0;i<params.size();i++) {
00546 tf->SetParameter(i,params[i]);
00547 }
00548 int statsup = (int)tf->Eval(hservice_->getNBinsHistogram(iTestName));
00549
00550 vector<double> defaultMu0low;
00551 defaultMu0low.push_back(2.19664);
00552 defaultMu0low.push_back(1.94546);
00553 defaultMu0low.push_back(-99.3263);
00554 defaultMu0low.push_back(19.388);
00555
00556 params = ps.getUntrackedParameter<std::vector<double> >("params_mu0_low",defaultMu0low);
00557 for(unsigned int i=0;i<params.size();i++) {
00558 tf->SetParameter(i,params[i]);
00559 }
00560 int statslow = (int)tf->Eval(hservice_->getNBinsHistogram(iTestName));
00561 if(verbose_) {
00562 cout << "statsup= " << statsup << ", statslow= " << statslow << endl;
00563 }
00564 enoughStats = TMath::MinElement(nActualStrips,maxAvgs)>TMath::Max(statsup,statslow);
00565 if(verbose_) {
00566 cout << "stats: " << TMath::MinElement(nActualStrips,maxAvgs) << ", statsAvg: " << diffHist->GetEntries()/hservice_->getNBinsHistogram(iTestName) << ", threshold: " << TMath::Max(statsup,statslow) << endl;
00567 }
00568
00569
00570
00571 if(enoughStats) {
00572 for(;upBinStrip<=maxBinStrip;upBinStrip++,lowBinStrip--) {
00573 double avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, upBinStrip, pAverageMode);
00574 compareWithStrip(diffHist,iTestName, lowBinStrip,nBinsX,pAxis,avg,ps,deadChannels);
00575
00576 avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, lowBinStrip, pAverageMode);
00577 compareWithStrip(diffHist,iTestName, upBinStrip,nBinsX,pAxis,avg,ps,deadChannels);
00578 }
00579 }
00580 }
00581 else {if(verbose_){cout << "Invalid axis" << endl;}}
00582
00583 return (deadChannels.size()-hservice_->getNBinsMasked(iTestName))*1.0/hservice_->getNBinsHistogram(iTestName);
00584 }
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600 double L1TOccupancyClient::getAvrg(TH2F* iHist, string iTestName, int iAxis, int iNBins, int iBinStrip, int iAvgMode) {
00601
00602 double avg = 0.0;
00603 TH1D* proj = NULL;
00604 TH2F* histo = (TH2F*) iHist->Clone();
00605
00606 std::vector<double> values;
00607 int marked;
00608
00609 if(iAxis==1) {
00610
00611 switch(iAvgMode) {
00612
00613
00614 case 1:
00615 marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
00616 proj = histo->ProjectionX();
00617 avg = proj->GetBinContent(iBinStrip)/(iNBins-marked);
00618 break;
00619
00620
00621 case 2:
00622 marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
00623 proj = histo->ProjectionY("_py",iBinStrip,iBinStrip);
00624 for(int i=0;i<iNBins;i++) {
00625 values.push_back(proj->GetBinContent(i+1));
00626 }
00627 avg = TMath::Median(iNBins,&values[0]);
00628 break;
00629 default:
00630 if(verbose_){cout << "Invalid averaging mode!" << endl;}
00631 break;
00632 }
00633 }
00634 else if(iAxis==2) {
00635
00636 switch(iAvgMode) {
00637
00638 case 1:
00639 marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
00640 proj = histo->ProjectionY();
00641 avg = proj->GetBinContent(iBinStrip)/(iNBins-marked);
00642 break;
00643
00644 case 2:
00645 marked = hservice_->maskBins(iTestName,histo,iBinStrip,iAxis);
00646 proj = histo->ProjectionX("_px",iBinStrip,iBinStrip);
00647 for(int i=0;i<iNBins;i++) {
00648 values.push_back(proj->GetBinContent(i+1));
00649 }
00650
00651 avg = TMath::Median(iNBins,&values[0]);
00652 break;
00653 default:
00654 if(verbose_) { cout << "invalid averaging mode!" << endl;}
00655 break;
00656 }
00657 }
00658 else {
00659 if(verbose_) {cout << "invalid axis" << endl;}
00660 }
00661 delete histo;
00662 delete proj;
00663 return avg;
00664 }
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675 void L1TOccupancyClient::printDeadChannels(vector< pair<int,double> > iDeadChannels, TH2F* oHistDeadChannels, vector<std::pair<int,double> > statDev, string iTestName) {
00676
00677
00678 oHistDeadChannels->Reset();
00679 if(verbose_) {cout << "suspect or masked channels of " << iTestName << ": ";}
00680
00681 int x,y,z;
00682 float chi2 = 0.0;
00683
00684
00685 for (std::vector<pair<int,double> >::const_iterator it = iDeadChannels.begin(); it != iDeadChannels.end(); it++) {
00686
00687 int bin = (*it).first;
00688 oHistDeadChannels->GetBinXYZ(bin,x,y,z);
00689
00690 if(hservice_->isMasked(iTestName,x,y)){
00691 oHistDeadChannels->SetBinContent(bin,-1);
00692 if(verbose_){printf("(%4i,%4i) Masked\n",x,y);}
00693 }
00694 else{
00695 oHistDeadChannels->SetBinContent(bin, 1);
00696 if(verbose_){printf("(%4i,%4i) Failed test\n",x,y);}
00697 }
00698 }
00699
00700
00701 for (std::vector<pair<int,double> >::const_iterator it = statDev.begin(); it != statDev.end(); it++) {
00702 double dev = (*it).second;
00703 chi2 += dev;
00704 }
00705
00706
00707 if(verbose_) {
00708 cout << "total number of suspect channels: " << (iDeadChannels.size()-(hservice_->getNBinsMasked(iTestName))) << endl;
00709 }
00710 }
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727 int L1TOccupancyClient::compareWithStrip(TH2F* iHist, string iTestName, int iBinStrip, int iNBins, int iAxis, double iAvg, ParameterSet iPS, vector<pair<int,double> >& oChannels) {
00728
00729 int dead = 0;
00730
00731
00732 if(iAxis==1) {
00733
00734
00735 TF1* fmuup = new TF1("fmuup" ,"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
00736 TF1* fmulow = new TF1("fmulow","TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
00737 fmuup ->SetParameter(0,iAvg*iPS.getUntrackedParameter<double>("factorup",2.0));
00738 fmuup ->SetParameter(1,iAvg);
00739 fmulow->SetParameter(0,iAvg*iPS.getUntrackedParameter<double>("factorlow",0.1));
00740 fmulow->SetParameter(1,iAvg);
00741
00742 TF1* fchi = new TF1("fchi","[0]*x**2+[1]*x+[2]",0.,1500.);
00743
00744
00745 vector<double> defaultChi2up;
00746 defaultChi2up.push_back(5.45058e-05);
00747 defaultChi2up.push_back(0.268756);
00748 defaultChi2up.push_back(-11.7515);
00749
00750 vector<double> params = iPS.getUntrackedParameter< vector<double> >("params_chi2_up",defaultChi2up);
00751 for(unsigned int i=0; i<params.size(); i++){fchi->SetParameter(i,params[i]);}
00752 double sigma_up = fchi->Eval(iAvg);
00753
00754
00755 vector<double> defaultChi2low;
00756 defaultChi2low.push_back(4.11095e-05);
00757 defaultChi2low.push_back(0.577451);
00758 defaultChi2low.push_back(-10.378);
00759
00760 params = iPS.getUntrackedParameter< vector<double> >("params_chi2_low",defaultChi2low);
00761 for(unsigned int i=0; i<params.size(); i++){fchi->SetParameter(i,params[i]);}
00762 double sigma_low = fchi->Eval(iAvg);
00763
00764 if(verbose_){cout << "binstrip= " << iBinStrip << ", sigmaup= " << sigma_up << ", sigmalow= " << sigma_low << endl;}
00765
00766 for(int i=1;i<=iNBins;i++) {
00767 if(verbose_) {
00768 cout << " " << i << " binContent: up:" << fmuup ->Eval(iHist->GetBinContent(iBinStrip,i))
00769 << " low: " << fmulow->Eval(iHist->GetBinContent(iBinStrip,i)) << endl;
00770 }
00771
00772
00773 double muup = fmuup ->Eval(iHist->GetBinContent(iBinStrip,i));
00774 double mulow = fmulow->Eval(iHist->GetBinContent(iBinStrip,i));
00775
00776
00777 if(hservice_->isMasked(iTestName,iBinStrip,i)) {
00778 oChannels.push_back(pair<int,double>(iHist->GetBin(iBinStrip,i),-1.0));
00779 }
00780
00781 else if(muup > sigma_up ||
00782 mulow > sigma_low ||
00783 ((fabs(muup) == std::numeric_limits<double>::infinity()) && (
00784 fabs(mulow) == std::numeric_limits<double>::infinity()))) {
00785 dead++;
00786 oChannels.push_back(pair<int,double>(iHist->GetBin(iBinStrip,i),abs(iHist->GetBinContent(iBinStrip,i)-iAvg)/iAvg));
00787 }
00788 }
00789 }
00790
00791 else if(iAxis==2){
00792
00793
00794 TF1* fmuup = new TF1("fmuup" ,"TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
00795 TF1* fmulow = new TF1("fmulow","TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))",-10000.,10000.);
00796 fmuup ->SetParameter(0,iAvg*iPS.getUntrackedParameter<double>("factorup",2.0));
00797 fmuup ->SetParameter(1,iAvg);
00798 fmulow->SetParameter(0,iAvg*iPS.getUntrackedParameter<double>("factorlow",0.1));
00799 fmulow->SetParameter(1,iAvg);
00800
00801 TF1* fchi = new TF1("fchi","[0]*x**2+[1]*x+[2]",0.,1500.);
00802
00803
00804 vector<double> defaultChi2up;
00805 defaultChi2up.push_back(5.45058e-05);
00806 defaultChi2up.push_back(0.268756);
00807 defaultChi2up.push_back(-11.7515);
00808
00809 vector<double> params = iPS.getUntrackedParameter<vector<double> >("params_chi2_up",defaultChi2up);
00810 for(unsigned int i=0;i<params.size();i++){fchi->SetParameter(i,params[i]);}
00811 double sigma_up = fchi->Eval(iAvg);
00812
00813
00814 vector<double> defaultChi2low;
00815 defaultChi2low.push_back(4.11095e-05);
00816 defaultChi2low.push_back(0.577451);
00817 defaultChi2low.push_back(-10.378);
00818
00819 params = iPS.getUntrackedParameter<vector<double> >("params_chi2_low",defaultChi2low);
00820 for(unsigned int i=0;i<params.size();i++){fchi->SetParameter(i,params[i]);}
00821 double sigma_low = fchi->Eval(iAvg);
00822
00823 if(verbose_) {cout << "binstrip= " << iBinStrip << ", sigmaup= " << sigma_up << ", sigmalow= " << sigma_low << endl;}
00824
00825 for(int i=1;i<=iNBins;i++) {
00826 if(verbose_) {
00827 cout << " " << i << " binContent: up:" << fmuup ->Eval(iHist->GetBinContent(i,iBinStrip))
00828 << " low: " << fmulow->Eval(iHist->GetBinContent(i,iBinStrip)) << endl;
00829 }
00830
00831
00832 double muup = fmuup ->Eval(iHist->GetBinContent(i,iBinStrip));
00833 double mulow = fmulow->Eval(iHist->GetBinContent(i,iBinStrip));
00834
00835
00836 if(hservice_->isMasked(iTestName,i,iBinStrip)) {
00837 oChannels.push_back(pair<int,double>(iHist->GetBin(iBinStrip,i),-1.0));
00838 }
00839
00840 else if(muup > sigma_up ||
00841 mulow > sigma_low ||
00842 ((fabs(muup) == std::numeric_limits<double>::infinity()) &&
00843 (fabs(mulow) == std::numeric_limits<double>::infinity()))) {
00844 dead++;
00845 oChannels.push_back(pair<int,double>(iHist->GetBin(i,iBinStrip),abs(iHist->GetBinContent(i,iBinStrip)-iAvg)/iAvg));
00846 }
00847 }
00848 }
00849 else {if(verbose_) {cout << "invalid axis" << endl;}}
00850
00851 return dead;
00852 }
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863 void L1TOccupancyClient::getBinCoordinateOnAxisWithValue(TH2F* iHist, double iValue, int& oBinCoordinate, int iAxis) {
00864
00865 int nBinsX = iHist->GetNbinsX();
00866 int nBinsY = iHist->GetNbinsY();
00867
00868 if(iAxis==1){
00869 int global = iHist->GetXaxis()->FindFixBin(iValue);
00870
00871
00872 if(global > nBinsX*nBinsY) {global = iHist->GetXaxis()->GetLast();}
00873
00874
00875 int y,z;
00876 iHist->GetBinXYZ(global,oBinCoordinate,y,z);
00877 }
00878 else if(iAxis==2){
00879 int global = iHist->GetYaxis()->FindFixBin(iValue);
00880
00881
00882 if(global > nBinsX*nBinsY) {global = iHist->GetYaxis()->GetLast();}
00883
00884
00885 int x,z;
00886 iHist->GetBinXYZ(global,x,oBinCoordinate,z);
00887 }
00888 }
00889
00890
00891 DEFINE_FWK_MODULE(L1TOccupancyClient);