CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Validation/HcalDigis/src/HcalDigisClient.cc

Go to the documentation of this file.
00001 #include <Validation/HcalDigis/interface/HcalDigisClient.h>
00002 // -*- C++ -*-
00003 //
00004 // Package:    HcalDigisClient
00005 // Class:      HcalDigisClient
00006 //
00014 //
00015 // Original Author:  Ali Fahim,22 R-013,+41227672649,
00016 //         Created:  Wed Mar 23 22:54:28 CET 2011
00017 // $Id: HcalDigisClient.cc,v 1.3 2012/08/15 12:47:37 abdullin Exp $
00018 //
00019 //
00020 
00021 
00022 // system include files
00023 
00024 HcalDigisClient::HcalDigisClient(const edm::ParameterSet& iConfig) {
00025     dbe_ = edm::Service<DQMStore > ().operator->();
00026     outputFile_ = iConfig.getUntrackedParameter<std::string > ("outputFile", "HcalDigisClient.root");
00027     dirName_ = iConfig.getParameter<std::string > ("DQMDirName");
00028     if (!dbe_) edm::LogError("HcalDigisClient") << "unable to get DQMStore service, upshot is no client histograms will be made";
00029     msm_ = new std::map<std::string, MonitorElement*>();
00030     //if (iConfig.getUntrackedParameter<bool>("DQMStore", false)) if (dbe_) dbe_->setVerbose(0);
00031 
00032     //    std::cout << "dirName: " <<  dirName_ << std::endl;
00033     //dbe_->setCurrentFolder(dirName_);
00034     dbe_->setCurrentFolder("HcalDigisV/HcalDigiTask");
00035 
00036     booking("HB");
00037     booking("HE");
00038     booking("HO");
00039     booking("HF");
00040 }
00041 
00042 void HcalDigisClient::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00043     using namespace edm;
00044 
00045 
00046 }
00047 
00048 void HcalDigisClient::booking(std::string subdetopt) {
00049 
00050     std::string strtmp;
00051     HistLim ietaLim(82, -41., 41.);
00052 
00053     for (int depth = 1; depth <= 4; depth++) {
00054         strtmp = "HcalDigiTask_occupancy_vs_ieta_depth" + str(depth) + "_" + subdetopt;
00055         book1D(strtmp, ietaLim);
00056     }
00057 
00058 }
00059 
00060 void HcalDigisClient::runClient() {
00061     if (!dbe_) return; //we dont have the DQMStore so we cant do anything
00062     dbe_->setCurrentFolder(dirName_);
00063     std::vector<MonitorElement*> hcalMEs;
00064     // Since out folders are fixed to three, we can just go over these three folders
00065     // i.e., CaloTowersV/CaloTowersTask, HcalRecHitsV/HcalRecHitTask, NoiseRatesV/NoiseRatesTask.
00066     std::vector<std::string> fullPathHLTFolders = dbe_->getSubdirs();
00067     for (unsigned int i = 0; i < fullPathHLTFolders.size(); i++) {
00068         dbe_->setCurrentFolder(fullPathHLTFolders[i]);
00069         std::vector<std::string> fullSubPathHLTFolders = dbe_->getSubdirs();
00070         for (unsigned int j = 0; j < fullSubPathHLTFolders.size(); j++) {
00071             if (strcmp(fullSubPathHLTFolders[j].c_str(), "HcalDigisV/HcalDigiTask") == 0) {
00072                 hcalMEs = dbe_->getContents(fullSubPathHLTFolders[j]);
00073                 if (!HcalDigisEndjob(hcalMEs, "HB")) 
00074                   edm::LogError("HcalDigisClient") << "Error in HcalDigisEndjob! HB"; 
00075                 if (!HcalDigisEndjob(hcalMEs, "HE")) 
00076                   edm::LogError("HcalDigisClient") << "Error in HcalDigisEndjob! HE"; 
00077                 if (!HcalDigisEndjob(hcalMEs, "HO")) 
00078                   edm::LogError("HcalDigisClient") << "Error in HcalDigisEndjob! HO"; 
00079                 if (!HcalDigisEndjob(hcalMEs, "HF")) 
00080                   edm::LogError("HcalDigisClient") << "Error in HcalDigisEndjob! HF";             }
00081         }
00082     }
00083 }
00084 
00085 int HcalDigisClient::HcalDigisEndjob(const std::vector<MonitorElement*> &hcalMEs, std::string subdet_) {
00086 
00087     using namespace std;
00088     string strtmp;
00089 
00090 
00091     MonitorElement * nevtot(0);
00092     MonitorElement * ieta_iphi_occupancy_map1(0);
00093     MonitorElement * ieta_iphi_occupancy_map2(0);
00094     MonitorElement * ieta_iphi_occupancy_map3(0);
00095     MonitorElement * ieta_iphi_occupancy_map4(0);
00096 
00097 
00098     std::cout << " Number of histos " <<     hcalMEs.size() << std::endl;
00099 
00100     for (unsigned int ih = 0; ih < hcalMEs.size(); ih++) {
00101          if (hcalMEs[ih]->getName() == "nevtot") nevtot = hcalMEs[ih];
00102 
00103          strtmp = "HcalDigiTask_ieta_iphi_occupancy_map_depth1_" + subdet_;
00104          if (hcalMEs[ih]->getName() == strtmp) ieta_iphi_occupancy_map1 = hcalMEs[ih];
00105          strtmp = "HcalDigiTask_ieta_iphi_occupancy_map_depth2_" + subdet_;
00106          if (hcalMEs[ih]->getName() == strtmp) ieta_iphi_occupancy_map2 = hcalMEs[ih];
00107          strtmp = "HcalDigiTask_ieta_iphi_occupancy_map_depth3_" + subdet_;
00108          if (hcalMEs[ih]->getName() == strtmp) ieta_iphi_occupancy_map3 = hcalMEs[ih];
00109          strtmp = "HcalDigiTask_ieta_iphi_occupancy_map_depth4_" + subdet_;
00110          if (hcalMEs[ih]->getName() == strtmp) ieta_iphi_occupancy_map4 = hcalMEs[ih];
00111 
00112     }//
00113 
00114     if (nevtot                   == 0 ||
00115         ieta_iphi_occupancy_map1 == 0 ||
00116         ieta_iphi_occupancy_map2 == 0 ||
00117         ieta_iphi_occupancy_map3 == 0 ||
00118         ieta_iphi_occupancy_map4 == 0   
00119         ) {
00120       edm::LogError("HcalDigisClient") << "No nevtot or maps histo found..."; 
00121       return 0;
00122     }
00123 
00124     int ev = nevtot->getEntries();
00125     if(ev <= 0) {
00126       edm::LogError("HcalDigisClient") << "normalization factor <= 0!"; 
00127       return 0;
00128     }
00129 
00130     float fev = (float) nevtot->getEntries();
00131 
00132     int nx = ieta_iphi_occupancy_map1->getNbinsX();
00133     int ny = ieta_iphi_occupancy_map1->getNbinsY();
00134     float sumphi_1, sumphi_2, sumphi_3, sumphi_4;
00135     float phi_factor;
00136     float cnorm;
00137     
00138     for (int i = 1; i <= nx; i++) {
00139         sumphi_1 = 0.;
00140         sumphi_2 = 0.;
00141         sumphi_3 = 0.;
00142         sumphi_4 = 0.;
00143 
00144         for (int j = 1; j <= ny; j++) {
00145 
00146             // occupancies
00147 
00148              strtmp = "HcalDigiTask_ieta_iphi_occupancy_map_depth1_" + subdet_;
00149              cnorm = ieta_iphi_occupancy_map1->getBinContent(i, j) / fev;
00150              ieta_iphi_occupancy_map1->setBinContent(i, j, cnorm);
00151              sumphi_1 += ieta_iphi_occupancy_map1->getBinContent(i, j);
00152 
00153              strtmp = "HcalDigiTask_ieta_iphi_occupancy_map_depth2_" + subdet_;
00154              cnorm = ieta_iphi_occupancy_map2->getBinContent(i, j) / fev;
00155              ieta_iphi_occupancy_map2->setBinContent(i, j, cnorm);
00156              sumphi_2 += ieta_iphi_occupancy_map2->getBinContent(i, j);
00157 
00158              strtmp = "HcalDigiTask_ieta_iphi_occupancy_map_depth3_" + subdet_;
00159              cnorm = ieta_iphi_occupancy_map3->getBinContent(i, j) / fev; 
00160              ieta_iphi_occupancy_map3->setBinContent(i, j, cnorm);
00161              sumphi_3 += ieta_iphi_occupancy_map3->getBinContent(i, j);
00162 
00163              strtmp = "HcalDigiTask_ieta_iphi_occupancy_map_depth4_" + subdet_;
00164              cnorm = ieta_iphi_occupancy_map4->getBinContent(i, j) / fev; 
00165              ieta_iphi_occupancy_map4->setBinContent(i, j, cnorm);
00166              sumphi_4 += ieta_iphi_occupancy_map4->getBinContent(i, j);
00167 
00168         }    
00169 
00170         int ieta = i - 42; // -41 -1, 0 40
00171         if (ieta >= 0) ieta += 1; // -41 -1, 1 41  - to make it detector-like
00172 
00173         if (ieta >= -20 && ieta <= 20) {
00174           phi_factor = 72.; 
00175         } else {
00176           if (ieta >= 40 || ieta <= -40) 
00177               phi_factor = 18.; 
00178            else 
00179               phi_factor = 36.; 
00180         }    
00181         
00182         if (ieta >= 0) ieta -= 1; // -41 -1, 0 40  - to bring back to strtmp num !!!
00183         double deta = double(ieta);
00184 
00185         // occupancies vs ieta
00186         cnorm = sumphi_1 / phi_factor;
00187         strtmp = "HcalDigiTask_occupancy_vs_ieta_depth1_" + subdet_;
00188         fill1D(strtmp, deta, cnorm);
00189 
00190         cnorm = sumphi_2 / phi_factor;
00191         strtmp = "HcalDigiTask_occupancy_vs_ieta_depth2_" + subdet_;
00192         fill1D(strtmp, deta, cnorm);
00193 
00194         cnorm = sumphi_3 / phi_factor;
00195         strtmp = "HcalDigiTask_occupancy_vs_ieta_depth3_" + subdet_;
00196         fill1D(strtmp, deta, cnorm);
00197 
00198         cnorm = sumphi_4 / phi_factor;
00199         strtmp = "HcalDigiTask_occupancy_vs_ieta_depth4_" + subdet_;
00200         fill1D(strtmp, deta, cnorm);
00201 
00202     } // end of i-loop
00203 
00204   return 1;
00205 }
00206 
00207 MonitorElement* HcalDigisClient::monitor(std::string name) {
00208     if (!msm_->count(name)) return NULL;
00209     else return msm_->find(name)->second;
00210 }
00211 
00212 std::string HcalDigisClient::str(int x) {
00213     std::stringstream out;
00214     out << x;
00215     return out.str();
00216 }
00217 
00218 double HcalDigisClient::integralMETH2D(MonitorElement* ME, int i0, int i1, int j0, int j1) {
00219     double sum(0);
00220     for (int i = i0; i <= i1; i++) {
00221         for (int j = j0; j <= j1; j++) {
00222             sum += ME->getBinContent(i, j);
00223         }
00224     }
00225 
00226     return sum;
00227 }
00228 
00229 void HcalDigisClient::scaleMETH2D(MonitorElement* ME, double s) {
00230     int nx = ME->getNbinsX();
00231     int ny = ME->getNbinsY();
00232 
00233     double content(0);
00234     for (int i = 1; i <= nx; i++) {
00235         for (int j = 1; j <= ny; j++) {
00236             content = ME->getBinContent(i, j);
00237             content *= s;
00238             ME->setBinContent(i, j, content);
00239         }
00240     }
00241 }
00242 
00243 //define this as a plug-in
00244 DEFINE_FWK_MODULE(HcalDigisClient);
00245