00001 #include <memory>
00002 #include <iostream>
00003 #include <fstream>
00004 #include <string>
00005 #include <vector>
00006
00007 #include "DQMServices/Core/interface/MonitorElement.h"
00008 #include "DQMServices/Core/interface/DQMStore.h"
00009
00010 #include "DQM/EcalPreshowerMonitorClient/interface/ESPedestalClient.h"
00011
00012 #include <TH1F.h>
00013
00014 using namespace edm;
00015 using namespace std;
00016
00017 ESPedestalClient::ESPedestalClient(const edm::ParameterSet& ps) {
00018
00019 verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00020 debug_ = ps.getUntrackedParameter<bool>("debug", true);
00021 prefixME_ = ps.getUntrackedParameter<string>("prefixME", "EcalPreshower");
00022 lookup_ = ps.getUntrackedParameter<FileInPath>("LookupTable");
00023 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00024 fitPedestal_ = ps.getUntrackedParameter<bool>("fitPedestal", false);
00025
00026 for (int i=0; i<2; i++)
00027 for (int j=0; j<2; j++)
00028 for (int k=0; k<40; k++)
00029 for (int m=0; m<40; m++) {
00030 hPed_[i][j][k][m] = 0;
00031 hTotN_[i][j][k][m] = 0;
00032 }
00033
00034 }
00035
00036 ESPedestalClient::~ESPedestalClient() {
00037 }
00038
00039 void ESPedestalClient::beginJob(DQMStore* dqmStore) {
00040
00041 dqmStore_ = dqmStore;
00042
00043 if ( debug_ ) cout << "ESPedestalClient: beginJob" << endl;
00044
00045 ievt_ = 0;
00046 jevt_ = 0;
00047
00048 }
00049
00050 void ESPedestalClient::beginRun(void) {
00051
00052 if ( debug_ ) cout << "ESPedestalClient: beginRun" << endl;
00053
00054 jevt_ = 0;
00055
00056 this->setup();
00057 }
00058
00059 void ESPedestalClient::endJob(void) {
00060
00061 if ( debug_ ) cout << "ESPedestalClient: endJob, ievt = " << ievt_ << endl;
00062
00063
00064 char hname[300];
00065 int iz = 0;
00066 if (fitPedestal_) {
00067
00068 if ( verbose_ ) cout<<"ESPedestalClient: Fit Pedestal"<<endl;
00069
00070 for (int i=0; i<nLines_; ++i) {
00071
00072 iz = (senZ_[i]==1) ? 0:1;
00073
00074 for (int is=0; is<32; ++is) {
00075
00076 string dirname = prefixME_ + "/ESPedestalTask/";
00077 sprintf(hname, "ADC Z %d P %d X %d Y %d Str %d", senZ_[i], senP_[i], senX_[i], senY_[i], is+1);
00078 MonitorElement *meFit = dqmStore_->get(dirname+hname);
00079
00080 if (meFit==0) continue;
00081 TH1F *rootHisto = meFit->getTH1F();
00082 rootHisto->Fit("fg", "Q", "", 500, 1800);
00083 rootHisto->Fit("fg", "RQ", "", fg->GetParameter(1)-2.*fg->GetParameter(2),fg->GetParameter(1)+2.*fg->GetParameter(2));
00084 hPed_[iz][senP_[i]-1][senX_[i]-1][senY_[i]-1]->setBinContent(is+1, (int)(fg->GetParameter(1)+0.5));
00085 hTotN_[iz][senP_[i]-1][senX_[i]-1][senY_[i]-1]->setBinContent(is+1, fg->GetParameter(2));
00086
00087 }
00088 }
00089
00090 } else {
00091
00092 if ( verbose_ ) cout<<"ESPedestalClient: Use Histogram Mean"<<endl;
00093
00094 for (int i=0; i<nLines_; ++i) {
00095
00096 iz = (senZ_[i]==1) ? 0:1;
00097
00098 for (int is=0; is<32; ++is) {
00099
00100 string dirname = prefixME_ + "/ESPedestalTask/";
00101 sprintf(hname, "ADC Z %d P %d X %d Y %d Str %d", senZ_[i], senP_[i], senX_[i], senY_[i], is+1);
00102 MonitorElement *meMean = dqmStore_->get(dirname+hname);
00103
00104 if (meMean==0) continue;
00105 TH1F *rootHisto = meMean->getTH1F();
00106
00107 hPed_[iz][senP_[i]-1][senX_[i]-1][senY_[i]-1]->setBinContent(is+1, (int)(rootHisto->GetMean()+0.5));
00108 hTotN_[iz][senP_[i]-1][senX_[i]-1][senY_[i]-1]->setBinContent(is+1, rootHisto->GetRMS());
00109
00110 }
00111 }
00112 }
00113
00114 this->cleanup();
00115 }
00116
00117 void ESPedestalClient::endRun(void) {
00118
00119 if ( debug_ ) cout << "ESPedestalClient: endRun, jevt = " << jevt_ << endl;
00120
00121 this->cleanup();
00122 }
00123
00124 void ESPedestalClient::setup(void) {
00125
00126
00127 int iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
00128 ifstream file;
00129
00130 file.open(lookup_.fullPath().c_str());
00131 if( file.is_open() ) {
00132
00133 file >> nLines_;
00134
00135 for (int i=0; i<nLines_; ++i) {
00136 file>> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
00137
00138 senZ_[i] = iz;
00139 senP_[i] = ip;
00140 senX_[i] = ix;
00141 senY_[i] = iy;
00142 }
00143
00144 } else {
00145 cout<<"ESPedestalClient : Look up table file can not be found in "<<lookup_.fullPath().c_str()<<endl;
00146 }
00147
00148
00149 dqmStore_->setCurrentFolder(prefixME_+"/ESPedestalClient");
00150
00151 char hname[300];
00152 for (int i=0; i<nLines_; ++i) {
00153
00154 iz = (senZ_[i]==1) ? 0:1;
00155
00156 sprintf(hname, "Ped Z %d P %d X %d Y %d", senZ_[i], senP_[i], senX_[i], senY_[i]);
00157 hPed_[iz][senP_[i]-1][senX_[i]-1][senY_[i]-1] = dqmStore_->book1D(hname, hname, 32, 0, 32);
00158
00159 sprintf(hname, "Total Noise Z %d P %d X %d Y %d", senZ_[i], senP_[i], senX_[i], senY_[i]);
00160 hTotN_[iz][senP_[i]-1][senX_[i]-1][senY_[i]-1] = dqmStore_->book1D(hname, hname, 32, 0, 32);
00161 }
00162
00163 fg = new TF1("fg", "gaus");
00164
00165 }
00166
00167 void ESPedestalClient::cleanup(void) {
00168
00169 if( ! enableCleanup_ ) return;
00170
00171 if ( debug_ ) cout << "ESPedestalClient: cleanup" << endl;
00172
00173 for (int i=0; i<2; i++)
00174 for (int j=0; j<2; j++)
00175 for (int k=0; k<40; k++)
00176 for (int m=0; m<40; m++) {
00177 hPed_[i][j][k][m] = 0;
00178 hTotN_[i][j][k][m] = 0;
00179 }
00180
00181 }
00182
00183 void ESPedestalClient::analyze() {
00184
00185 ievt_++;
00186 jevt_++;
00187
00188 }