CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQM/SiPixelHistoricInfoClient/plugins/SiPixelHistoryDQMService.cc

Go to the documentation of this file.
00001 #include "DQM/SiPixelHistoricInfoClient/plugins/SiPixelHistoryDQMService.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "DQMServices/Core/interface/MonitorElement.h"
00004 #include "DQMServices/Diagnostic/interface/HDQMfitUtilities.h"
00005 #include "DQM/SiPixelHistoricInfoClient/interface/SiPixelSummary.h"
00006 
00007 
00008 SiPixelHistoryDQMService::SiPixelHistoryDQMService(const edm::ParameterSet& iConfig,const edm::ActivityRegistry& aReg)
00009 : DQMHistoryServiceBase::DQMHistoryServiceBase(iConfig, aReg), iConfig_(iConfig)
00010 {
00011   //setSeperator("@@#@@"); // Change the seperator used in DB
00012   edm::LogInfo("SiPixelHistoryDQMService") <<  "[SiPixelHistoryDQMService::SiPixelHistoryDQMService]";
00013 }
00014 
00015 
00016 SiPixelHistoryDQMService::~SiPixelHistoryDQMService() { 
00017   edm::LogInfo("SiPixelHistoryDQMService") <<  "[SiPixelHistoryDQMService::~SiPixelHistoryDQMService]";
00018 }
00019 
00020 
00021 uint32_t SiPixelHistoryDQMService::returnDetComponent(const MonitorElement* ME){
00022   LogTrace("SiPixelHistoryDQMService") <<  "[SiPixelHistoryDQMService::returnDetComponent]";
00023   std::string str=ME->getName();
00024   size_t __key_length__=7;
00025   size_t __detid_length__=9;
00026 
00027 
00028   if(str.find("__det__")!= std::string::npos){
00029     return atoi(str.substr(str.find("__det__")+__key_length__,__detid_length__).c_str());
00030   }
00031   else if(str.find("Barrel")!= std::string::npos)
00032   {return sipixelsummary::Barrel;}
00033   else if(str.find("Shell_mI")!= std::string::npos)
00034   {return sipixelsummary::Shell_mI;}
00035   else if(str.find("Shell_mO")!= std::string::npos)
00036   {return sipixelsummary::Shell_mO;}
00037   else if(str.find("Shell_pI")!= std::string::npos)
00038   {return sipixelsummary::Shell_pI;}
00039   else if(str.find("Shell_pO")!= std::string::npos)
00040   {return sipixelsummary::Shell_pO;}
00041   else if(str.find("Endcap")!= std::string::npos)
00042   {return sipixelsummary::Endcap;}
00043   else if(str.find("HalfCylinder_mI")!= std::string::npos)
00044   {return sipixelsummary::HalfCylinder_mI;}
00045   else if(str.find("HalfCylinder_mO")!= std::string::npos)
00046   {return sipixelsummary::HalfCylinder_mO;}
00047   else if(str.find("HalfCylinder_pI")!= std::string::npos)
00048   {return sipixelsummary::HalfCylinder_pI;}
00049   else if(str.find("HalfCylinder_pO")!= std::string::npos)
00050   {return sipixelsummary::HalfCylinder_pO;}
00051   else {
00052     return sipixelsummary::TRACKER; //Full Tracker
00053   }
00054 
00055 }
00056 
00057 
00058 
00059 
00060 
00061 //Example on how to define an user function for the statistic extraction
00062 bool SiPixelHistoryDQMService::setDBLabelsForUser  (std::string& keyName, std::vector<std::string>& userDBContent, std::string& quantity){
00063   if (quantity == "user_ymean") {
00064     userDBContent.push_back(keyName+fSep+std::string("yMean"));
00065     userDBContent.push_back(keyName+fSep+std::string("yError"));
00066   } else if (quantity == "user_A") {
00067     userDBContent.push_back(keyName+fSep+std::string("NTracksPixOverAll"));
00068     userDBContent.push_back(keyName+fSep+std::string("NTracksPixOverAllError"));
00069   } else if (quantity == "user_B") {
00070     userDBContent.push_back(keyName+fSep+std::string("NTracksFPixOverBPix"));
00071     userDBContent.push_back(keyName+fSep+std::string("NTracksFPixOverBPixError"));
00072   } else {
00073     edm::LogError("SiPixelHistoryDQMService") << "ERROR: quantity does not exist in SiPixelHistoryDQMService::setDBValuesForUser(): " << quantity;
00074     return false;
00075   }
00076   return true;
00077 }
00078 bool SiPixelHistoryDQMService::setDBValuesForUser(std::vector<MonitorElement*>::const_iterator iterMes, HDQMSummary::InputVector& values, std::string& quantity  ){
00079 
00080   if (quantity == "user_ymean") {
00081     TH1F* Hist = (TH1F*) (*iterMes)->getTH1F()->Clone();
00082     // if( Hist == 0 || Hist->Integral() == 0 ) {
00083     //   std::cout << "Error: histogram not found or empty!!" << std::endl;
00084     //   values.push_back( 0. );
00085     //   values.push_back( 0. );
00086     // }
00087     // else
00088     // if(  ) {
00089     Hist->Fit("pol0");
00090     TF1* Fit = Hist->GetFunction("pol0");
00091     float FitValue = Fit ? Fit->GetParameter(0) : 0;
00092     float FitError = Fit ? Fit->GetParError(0) : 0;
00093     std::cout << "FITERROR: " << FitError << std::endl;
00094 
00095     values.push_back( FitValue );
00096     values.push_back( FitError );
00097     // }
00098   } else if (quantity == "user_A") {
00099     TH1F* Hist = (TH1F*) (*iterMes)->getTH1F();
00100     if( Hist->GetBinContent(1) != 0 && Hist->GetBinContent(2) != 0 ) {
00101       values.push_back( Hist->GetBinContent(2) / Hist->GetBinContent(1) );
00102       values.push_back( TMath::Abs(Hist->GetBinContent(2) / Hist->GetBinContent(1)) * TMath::Sqrt( ( TMath::Power( Hist->GetBinError(1)/Hist->GetBinContent(1), 2) + TMath::Power( Hist->GetBinError(2)/Hist->GetBinContent(2), 2) )) );
00103     }
00104     else {
00105       values.push_back( 0. );
00106       values.push_back( 0. );
00107     }
00108   } else if (quantity == "user_B") {
00109     TH1F* Hist = (TH1F*) (*iterMes)->getTH1F();
00110     if( Hist->GetBinContent(3) != 0 && Hist->GetBinContent(4) != 0 ) {
00111       values.push_back( Hist->GetBinContent(4) / Hist->GetBinContent(3) );
00112       values.push_back( TMath::Abs(Hist->GetBinContent(4) / Hist->GetBinContent(3)) * TMath::Sqrt( ( TMath::Power( Hist->GetBinError(3)/Hist->GetBinContent(3), 2) + TMath::Power( Hist->GetBinError(4)/Hist->GetBinContent(4), 2) )) );
00113     }
00114     else {
00115       values.push_back( 0. );
00116       values.push_back( 0. );
00117     }
00118   } else {
00119     edm::LogError("SiPixelHistoryDQMService") << "ERROR: quantity does not exist in SiPixelHistoryDQMService::setDBValuesForUser(): " << quantity;
00120     return false;
00121   }
00122 
00123   return true;
00124 }
00125