CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/DQMOffline/CalibTracker/plugins/SiStripNoisesDQMService.cc

Go to the documentation of this file.
00001 #include "DQMOffline/CalibTracker/plugins/SiStripNoisesDQMService.h"
00002 #include "DQMServices/Core/interface/MonitorElement.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00005 #include <string>
00006 #include <sstream>
00007 #include <cctype>
00008 #include <time.h>
00009 #include <boost/cstdint.hpp>
00010 
00011 using namespace std;
00012 
00013 SiStripNoisesDQMService::SiStripNoisesDQMService(const edm::ParameterSet& iConfig,const edm::ActivityRegistry& aReg):
00014   // SiStripCondObjBuilderBase<SiStripNoises>::SiStripCondObjBuilderBase(iConfig),
00015   SiStripBaseServiceFromDQM<SiStripNoises>::SiStripBaseServiceFromDQM(iConfig),
00016   iConfig_(iConfig),
00017   fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat")))
00018 {
00019   obj_ = 0;
00020   edm::LogInfo("SiStripNoisesDQMService") <<  "[SiStripNoisesDQMService::SiStripNoisesDQMService]";
00021 }
00022 
00023 SiStripNoisesDQMService::~SiStripNoisesDQMService()
00024 {
00025   edm::LogInfo("SiStripNoisesDQMService") <<  "[SiStripNoisesDQMService::~SiStripNoisesDQMService]";
00026 }
00027 
00028 void SiStripNoisesDQMService::readNoises()
00029 {
00030   std::cout << "SiStripNoisesDQMService::readNoises" << std::endl;
00031 
00032   openRequestedFile();
00033 
00034   std::cout << "[readBadComponents]: opened requested file" << std::endl;
00035 
00036   obj_= new SiStripNoises;
00037 
00038   SiStripDetInfoFileReader reader(fp_.fullPath());
00039 
00040   // dqmStore_->cd(iConfig_.getUntrackedParameter<std::string>("ME_DIR"));
00041   dqmStore_->cd();
00042 
00043   uint32_t stripsPerApv = 128;
00044 
00045   // Get the full list of monitoring elements
00046   // const std::vector<MonitorElement*>& MEs = dqmStore_->getAllContents(iConfig_.getUntrackedParameter<std::string>("ME_DIR","DQMData"));
00047 
00048   // Take a copy of the vector
00049   std::vector<MonitorElement*> MEs = dqmStore_->getAllContents(iConfig_.getUntrackedParameter<std::string>("ME_DIR","DQMData"));
00050   // Remove all but the MEs we are using
00051   std::vector<MonitorElement*>::iterator newEnd = remove_if(MEs.begin(), MEs.end(), StringNotMatch("CMSubNoisePerStrip__det__"));
00052   MEs.erase(newEnd, MEs.end());
00053 
00054   // The histograms are one per DetId, loop on all the DetIds and extract the corresponding histogram
00055   const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo> DetInfos  = reader.getAllData();
00056   for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator it = DetInfos.begin(); it != DetInfos.end(); ++it) {
00057 
00058 
00059     SiStripNoises::InputVector theSiStripVector;
00060 
00061     // Take the path for each DetId and build the complete path + histogram name
00062 
00063 
00064     // MonitorElement * mE = getModuleHistogram(it->first, "PedsPerStrip");
00065 
00066 
00067     MonitorElement * mE = 0;
00068     std::string MEname("CMSubNoisePerStrip__det__"+boost::lexical_cast<string>(it->first));
00069     for( std::vector<MonitorElement*>::const_iterator MEit = MEs.begin();
00070          MEit != MEs.end(); ++MEit ) {
00071       if( (*MEit)->getName() == MEname ) {
00072         mE = *MEit;
00073         break;
00074       }
00075     }
00076 
00077     // find( MEs.begin(), MEs.end(), "PedsPerStrip__det__"+boost::lexical_cast<string>(it->first), findMEbyName() );
00078     // MonitorElement * mE = *(find( MEs.begin(), MEs.end(), findMEbyName("PedsPerStrip__det__"+boost::lexical_cast<string>(it->first)) ));
00079 
00080     if( mE != 0 ) {
00081       TH1F* histo = mE->getTH1F();
00082 
00083       if( histo != 0 ) {
00084 
00085         // Read the noise from the histograms
00086         uint32_t nBinsX = histo->GetXaxis()->GetNbins();
00087 
00088         if( nBinsX != stripsPerApv*(it->second.nApvs) ) {
00089           std::cout << "ERROR: number of bin = " << nBinsX << " != number of strips = " << stripsPerApv*(it->second.nApvs) << std::endl;
00090         }
00091 
00092         // std::cout << "Bin 0 = " << histo->GetBinContent(0) << std::endl;
00093 
00094         // TH1 bins start from 1, 0 is the underflow, nBinsX+1 the overflow.
00095         for( uint32_t iBin = 1; iBin <= nBinsX; ++iBin ) {
00096           // encode the pedestal value and put it in the vector (push_back)
00097           obj_->setData( histo->GetBinContent(iBin), theSiStripVector );
00098         }
00099       }
00100       else {
00101         std::cout << "ERROR: histo = " << histo << std::endl;
00102       }
00103     }
00104     else {
00105       std::cout << "ERROR: ME = " << mE << std::endl;
00106     }
00107     // If the ME was absent fill the vector with 50 (we want a high noise to avoid these modules being considered good by mistake)
00108     if( theSiStripVector.empty() ) {
00109       for(unsigned short j=0; j<128*it->second.nApvs; ++j){
00110         obj_->setData(50, theSiStripVector);
00111       }
00112     }
00113 
00114     if ( ! obj_->put(it->first, theSiStripVector) )
00115       edm::LogError("SiStripNoisesFakeESSource::produce ")<<" detid already exists"<<std::endl;
00116   }
00117   dqmStore_->cd();
00118 }