Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:10:02

0001 #include "DQM/EcalPreshowerMonitorClient/interface/ESPedestalClient.h"
0002 
0003 #include "FWCore/ParameterSet/interface/FileInPath.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 
0006 #include <fstream>
0007 #include <iostream>
0008 #include <memory>
0009 #include <string>
0010 
0011 using namespace std;
0012 
0013 ESPedestalClient::ESPedestalClient(const edm::ParameterSet &ps)
0014     : ESClient(ps),
0015       fitPedestal_(ps.getUntrackedParameter<bool>("fitPedestal")),
0016       fg_(new TF1("fg", "gaus")),
0017       senZ_(),
0018       senP_(),
0019       senX_(),
0020       senY_() {
0021   for (int i = 0; i < 2; i++)
0022     for (int j = 0; j < 2; j++)
0023       for (int k = 0; k < 40; k++)
0024         for (int m = 0; m < 40; m++) {
0025           hPed_[i][j][k][m] = nullptr;
0026           hTotN_[i][j][k][m] = nullptr;
0027         }
0028 
0029   std::string lutPath(ps.getUntrackedParameter<edm::FileInPath>("LookupTable").fullPath());
0030 
0031   // read in look-up table
0032   int nLines, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
0033   ifstream file(lutPath);
0034 
0035   if (file.is_open()) {
0036     file >> nLines;
0037 
0038     for (int i = 0; i < nLines; ++i) {
0039       file >> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
0040 
0041       senZ_.push_back(iz);
0042       senP_.push_back(ip);
0043       senX_.push_back(ix);
0044       senY_.push_back(iy);
0045     }
0046 
0047     file.close();
0048   } else {
0049     cout << "ESPedestalClient : Look up table file can not be found in " << lutPath << endl;
0050   }
0051 }
0052 
0053 ESPedestalClient::~ESPedestalClient() { delete fg_; }
0054 
0055 void ESPedestalClient::endJobAnalyze(DQMStore::IGetter &_igetter) {
0056   if (debug_)
0057     cout << "ESPedestalClient: endJob" << endl;
0058 
0059   // Preform pedestal fit
0060   char hname[300];
0061   int iz = 0;
0062   if (fitPedestal_) {
0063     if (verbose_)
0064       cout << "ESPedestalClient: Fit Pedestal" << endl;
0065 
0066     for (unsigned i = 0; i < senZ_.size(); ++i) {
0067       iz = (senZ_[i] == 1) ? 0 : 1;
0068 
0069       for (int is = 0; is < 32; ++is) {
0070         string dirname = prefixME_ + "/ESPedestalTask/";
0071         sprintf(hname, "ADC Z %d P %d X %d Y %d Str %d", senZ_[i], senP_[i], senX_[i], senY_[i], is + 1);
0072         MonitorElement *meFit = _igetter.get(dirname + hname);
0073 
0074         if (meFit == nullptr)
0075           continue;
0076         TH1F *rootHisto = meFit->getTH1F();
0077 
0078         rootHisto->Fit(fg_, "Q", "", 500, 1800);
0079         rootHisto->Fit(fg_,
0080                        "RQ",
0081                        "",
0082                        fg_->GetParameter(1) - 2. * fg_->GetParameter(2),
0083                        fg_->GetParameter(1) + 2. * fg_->GetParameter(2));
0084         hPed_[iz][senP_[i] - 1][senX_[i] - 1][senY_[i] - 1]->setBinContent(is + 1, (int)(fg_->GetParameter(1) + 0.5));
0085         hTotN_[iz][senP_[i] - 1][senX_[i] - 1][senY_[i] - 1]->setBinContent(is + 1, fg_->GetParameter(2));
0086       }
0087     }
0088 
0089   } else {
0090     if (verbose_)
0091       cout << "ESPedestalClient: Use Histogram Mean" << endl;
0092 
0093     for (unsigned i = 0; i < senZ_.size(); ++i) {
0094       iz = (senZ_[i] == 1) ? 0 : 1;
0095 
0096       for (int is = 0; is < 32; ++is) {
0097         string dirname = prefixME_ + "/ESPedestalTask/";
0098         sprintf(hname, "ADC Z %d P %d X %d Y %d Str %d", senZ_[i], senP_[i], senX_[i], senY_[i], is + 1);
0099         MonitorElement *meMean = _igetter.get(dirname + hname);
0100 
0101         if (meMean == nullptr)
0102           continue;
0103         TH1F *rootHisto = meMean->getTH1F();
0104 
0105         hPed_[iz][senP_[i] - 1][senX_[i] - 1][senY_[i] - 1]->setBinContent(is + 1, (int)(rootHisto->GetMean() + 0.5));
0106         hTotN_[iz][senP_[i] - 1][senX_[i] - 1][senY_[i] - 1]->setBinContent(is + 1, rootHisto->GetRMS());
0107       }
0108     }
0109   }
0110 }
0111 
0112 void ESPedestalClient::book(DQMStore::IBooker &_ibooker) {
0113   // define histograms
0114   _ibooker.setCurrentFolder(prefixME_ + "/ESPedestalClient");
0115 
0116   char hname[300];
0117   for (unsigned i = 0; i < senZ_.size(); ++i) {
0118     int iz = (senZ_[i] == 1) ? 0 : 1;
0119 
0120     sprintf(hname, "Ped Z %d P %d X %d Y %d", senZ_[i], senP_[i], senX_[i], senY_[i]);
0121     hPed_[iz][senP_[i] - 1][senX_[i] - 1][senY_[i] - 1] = _ibooker.book1D(hname, hname, 32, 0, 32);
0122 
0123     sprintf(hname, "Total Noise Z %d P %d X %d Y %d", senZ_[i], senP_[i], senX_[i], senY_[i]);
0124     hTotN_[iz][senP_[i] - 1][senX_[i] - 1][senY_[i] - 1] = _ibooker.book1D(hname, hname, 32, 0, 32);
0125   }
0126 }