CMS 3D CMS Logo

SiStripHistoricPlot.cc

Go to the documentation of this file.
00001 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00002 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00003 #include "CondFormats/SiStripObjects/interface/SiStripPerformanceSummary.h"
00004 #include "CondFormats/DataRecord/interface/SiStripPerformanceSummaryRcd.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "DQM/SiStripHistoricInfoClient/interface/SiStripHistoricPlot.h"
00007 #include <iostream>
00008 #include <sstream>
00009 #include <stdio.h>
00010 #include <sys/time.h>
00011 using namespace cms;
00012 
00013 //--------------------------------------------------------------------------------------
00014 SiStripHistoricPlot::SiStripHistoricPlot( const edm::ParameterSet& iConfig ):
00015   printdebug_(iConfig.getUntrackedParameter<bool>("printDebug",false)),presentRunNr_(0){}
00016 SiStripHistoricPlot::~SiStripHistoricPlot(){}
00017 
00018 //--------------------------------------------------------------------------------------
00019 void SiStripHistoricPlot::analyze( const edm::Event& e, const edm::EventSetup& iSetup){
00020 /*
00021   edm::LogInfo("SiStripHistoricPlot") << "[SiStripHistoricPlot::analyze] Start Reading SiStripPerformanceSummary" << std::endl;
00022   edm::ESHandle<SiStripPerformanceSummary> SiStripPerformanceSummary_;
00023   iSetup.get<SiStripPerformanceSummaryRcd>().get(SiStripPerformanceSummary_);
00024   if(presentRunNr_ != SiStripPerformanceSummary_->getRunNr()){ // only analyze the SiStripPerformanceSummary objects once
00025     presentRunNr_ = SiStripPerformanceSummary_->getRunNr();
00026     SiStripPerformanceSummary_->print();
00027   }
00028 */
00029 //  std::vector<uint32_t> all_detids;
00030 //  all_detids.clear();
00031 //  SiStripPerformanceSummary_->getDetIds(all_detids);
00032 //  if( all_detids.size()>0 ) SiStripPerformanceSummary_->print(all_detids[0]);
00033 //  SiStripPerformanceSummary_->printall(); // print all summaries
00034 }
00035 
00036 //--------------------------------------------------------------------------------------
00037 void SiStripHistoricPlot::beginRun(const edm::Run& run, const edm::EventSetup& iSetup){
00038   //
00039   edm::ESHandle<SiStripPerformanceSummary> SiStripPerformanceSummary_;
00040   iSetup.get<SiStripPerformanceSummaryRcd>().get(SiStripPerformanceSummary_);
00041 //  edm::LogInfo("SiStripHistoricPlot")<<"SiStripPerformanceSummary for run="<<run.id()<<" SiStripPerformanceSummary_->getRunNr()="<<SiStripPerformanceSummary_->getRunNr()<< std::endl;
00042   if(presentRunNr_ != SiStripPerformanceSummary_->getRunNr()){ // only analyze the SiStripPerformanceSummary objects once
00043     // book histograms
00044     std::ostringstream oshistoid; TString ohistoid;
00045     oshistoid.str(""); oshistoid <<"ARun"<<run.id()<< "_ClusterSizesAllDets"; ohistoid=oshistoid.str();
00046     ClusterSizesAllDets = new TH1F(ohistoid,ohistoid,1,0,1); ClusterSizesAllDets->SetBit(TH1::kCanRebin);
00047     oshistoid.str(""); oshistoid <<"ARun"<<run.id()<< "_ClusterChargeAllDets"; ohistoid=oshistoid.str();
00048     ClusterChargeAllDets = new TH1F(ohistoid,ohistoid,1,0,1); ClusterChargeAllDets->SetBit(TH1::kCanRebin);
00049     oshistoid.str(""); oshistoid <<"ARun"<<run.id()<< "_OccupancyAllDets"; ohistoid=oshistoid.str();
00050     OccupancyAllDets = new TH1F(ohistoid,ohistoid,1,0,1); OccupancyAllDets->SetBit(TH1::kCanRebin);
00051     oshistoid.str(""); oshistoid <<"ARun"<<run.id()<< "_PercentNoisyStripsAllDets"; ohistoid=oshistoid.str();
00052     PercentNoisyStripsAllDets = new TH1F(ohistoid,ohistoid,1,0,1); PercentNoisyStripsAllDets->SetBit(TH1::kCanRebin);
00053     //
00054     presentRunNr_ = SiStripPerformanceSummary_->getRunNr();
00055     SiStripPerformanceSummary_->print();
00056     fillHistograms(SiStripPerformanceSummary_);
00057   }
00058 }
00059 
00060 void SiStripHistoricPlot::endRun(const edm::Run& run, const edm::EventSetup& iSetup){
00061 }
00062 
00063 void SiStripHistoricPlot::fillHistograms(edm::ESHandle<SiStripPerformanceSummary> pS){
00064   std::vector<uint32_t> vdetids; vdetids.clear();
00065   pS->getDetIds(vdetids); //  vdetids = activeDets;
00066   for(std::vector<uint32_t>::const_iterator idet = vdetids.begin(); idet != vdetids.end(); ++idet){
00067     std::vector<float> allValues; allValues.clear();
00068     pS->getSummary(*idet, allValues);
00069     if(allValues.size()==7){
00070       std::ostringstream osdetid; osdetid<<*idet; TString sdetid = osdetid.str();
00071       int jbin;
00072       ClusterSizesAllDets->Fill(sdetid,allValues[0]);
00073       jbin = ClusterSizesAllDets->GetXaxis()->FindBin(sdetid);
00074       ClusterSizesAllDets->SetBinError(jbin,allValues[1]);
00075       ClusterChargeAllDets->Fill(sdetid,allValues[2]);
00076       jbin = ClusterChargeAllDets->GetXaxis()->FindBin(sdetid);
00077       ClusterChargeAllDets->SetBinError(jbin,allValues[3]);
00078       OccupancyAllDets->Fill(sdetid,allValues[4]);
00079       jbin = OccupancyAllDets->GetXaxis()->FindBin(sdetid);
00080       OccupancyAllDets->SetBinError(jbin,allValues[5]);
00081       float percent_noisy_strips = allValues[6];
00082       if(percent_noisy_strips>0.5) percent_noisy_strips = 0.; // this value makes no sense, probably 0/0 division, check in historic producer
00083       PercentNoisyStripsAllDets->Fill(sdetid,percent_noisy_strips);
00084       // 
00085       std::vector<uint32_t>::const_iterator aDet = std::find(activeDets.begin(),activeDets.end(), *idet);
00086       if( aDet!=activeDets.end() ){
00087         std::ostringstream osrunid; osrunid<<presentRunNr_; TString srunid = osrunid.str();
00088         int ibin; TString ohistoid;
00089         ohistoid=detHistoTitle(*idet,"ClusterSizesAllRuns");
00090         ((TH1F*) AllDetHistograms->FindObject(ohistoid))->Fill(srunid,allValues[0]);
00091         ibin = ((TH1F*) AllDetHistograms->FindObject(ohistoid))->GetXaxis()->FindBin(srunid);
00092         ((TH1F*) AllDetHistograms->FindObject(ohistoid))->SetBinError(ibin,allValues[1]);
00093         ohistoid=detHistoTitle(*idet,"ClusterChargeAllRuns");
00094         ((TH1F*) AllDetHistograms->FindObject(ohistoid))->Fill(srunid,allValues[2]);
00095         ibin = ((TH1F*) AllDetHistograms->FindObject(ohistoid))->GetXaxis()->FindBin(srunid);
00096         ((TH1F*) AllDetHistograms->FindObject(ohistoid))->SetBinError(ibin,allValues[3]);
00097         ohistoid=detHistoTitle(*idet,"OccupancyAllRuns");
00098         ((TH1F*) AllDetHistograms->FindObject(ohistoid))->Fill(srunid,allValues[4]);
00099         ibin = ((TH1F*) AllDetHistograms->FindObject(ohistoid))->GetXaxis()->FindBin(srunid);
00100         ((TH1F*) AllDetHistograms->FindObject(ohistoid))->SetBinError(ibin,allValues[5]);
00101         ohistoid=detHistoTitle(*idet,"PercentNoisyStripsAllRuns");
00102         ((TH1F*) AllDetHistograms->FindObject(ohistoid))->Fill(srunid,allValues[6]);
00103       }
00104     }else{
00105       edm::LogError("WrongSize")<<" performance summary has wrong size allValues.size()="<<allValues.size();
00106     }
00107   }
00108 
00109   //
00110   ClusterSizesAllDets->LabelsDeflate("X");
00111   ClusterChargeAllDets->LabelsDeflate("X");
00112   OccupancyAllDets->LabelsDeflate("X");
00113   PercentNoisyStripsAllDets->LabelsDeflate("X");
00114 }
00115 
00116 
00117 void SiStripHistoricPlot::beginJob(const edm::EventSetup& iSetup){
00118   AllDetHistograms = new TObjArray();
00119   outputfile = new TFile("historic_plot.root","RECREATE");
00120   activeDets.clear();
00121 /*
00122   activeDets.push_back(369345800);
00123   activeDets.push_back(369345804);
00124   activeDets.push_back(369346052);
00125   activeDets.push_back(369346056);
00126   activeDets.push_back(369346060);
00127   activeDets.push_back(369346308);
00128   activeDets.push_back(369346312);
00129   activeDets.push_back(369346316);
00130   activeDets.push_back(369346564);
00131   activeDets.push_back(369346568);
00132   activeDets.push_back(436309262);
00133   activeDets.push_back(436309265);
00134   activeDets.push_back(436309266);
00135 */
00136   // take from eventSetup the SiStripDetCabling object
00137   edm::ESHandle<SiStripDetCabling> tkmechstruct;
00138   iSetup.get<SiStripDetCablingRcd>().get(tkmechstruct);
00139   // get list of active detectors from SiStripDetCabling - this will change and be taken from a SiStripDetControl object
00140   tkmechstruct->addActiveDetectorsRawIds(activeDets);
00141   //
00142   for(std::vector<uint32_t>::const_iterator idet = activeDets.begin(); idet != activeDets.end(); ++idet){
00143      TString ohistoid;
00144      ohistoid = detHistoTitle(*idet,"ClusterSizesAllRuns");
00145      AllDetHistograms->Add( new TH1F(ohistoid,ohistoid,1,0,1));
00146      ((TH1F*) AllDetHistograms->FindObject(ohistoid))->SetBit(TH1::kCanRebin);
00147      ohistoid = detHistoTitle(*idet,"ClusterChargeAllRuns");
00148      AllDetHistograms->Add( new TH1F(ohistoid,ohistoid,1,0,1));
00149      ((TH1F*) AllDetHistograms->FindObject(ohistoid))->SetBit(TH1::kCanRebin);
00150      ohistoid = detHistoTitle(*idet,"OccupancyAllRuns");
00151      AllDetHistograms->Add( new TH1F(ohistoid,ohistoid,1,0,1));
00152      ((TH1F*) AllDetHistograms->FindObject(ohistoid))->SetBit(TH1::kCanRebin);
00153      ohistoid = detHistoTitle(*idet,"PercentNoisyStripsAllRuns");
00154      AllDetHistograms->Add( new TH1F(ohistoid,ohistoid,1,0,1));
00155      ((TH1F*) AllDetHistograms->FindObject(ohistoid))->SetBit(TH1::kCanRebin);
00156   }
00157 
00158 // contiguous maps
00159   std::map<uint32_t, unsigned int> allContiguous; tkmechstruct->getAllDetectorsContiguousIds(allContiguous);
00160   std::map<uint32_t, unsigned int> activeContiguous; tkmechstruct->getActiveDetectorsContiguousIds(activeContiguous);
00161 
00162   std::cout<<"Contiguous"<<"allContiguous.size()="<<allContiguous.size()<<std::endl;
00163   for(std::map<uint32_t, unsigned int>::const_iterator deco=allContiguous.begin(); deco!=allContiguous.end(); ++deco){
00164     std::cout<<"Contiguous"<<"allContiguous "<<deco->first<<" -  "<<deco->second<<std::endl;
00165   }
00166 
00167   std::cout<<"Contiguous"<<"activeContiguous.size()="<<activeContiguous.size()<<std::endl;
00168   for(std::map<uint32_t, unsigned int>::const_iterator deco=activeContiguous.begin(); deco!=activeContiguous.end(); ++deco){
00169     std::cout<<"Contiguous"<<"activeContiguous "<<deco->first<<" -  "<<deco->second<<std::endl;
00170   }
00171 }
00172 
00173 
00174 void SiStripHistoricPlot::endJob(){
00175   for(std::vector<uint32_t>::const_iterator idet = activeDets.begin(); idet != activeDets.end(); ++idet){
00176     ((TH1F*) AllDetHistograms->FindObject(detHistoTitle(*idet,"ClusterSizesAllRuns")))->LabelsDeflate("X");
00177     ((TH1F*) AllDetHistograms->FindObject(detHistoTitle(*idet,"ClusterChargeAllRuns")))->LabelsDeflate("X");
00178     ((TH1F*) AllDetHistograms->FindObject(detHistoTitle(*idet,"OccupancyAllRuns")))->LabelsDeflate("X");
00179     ((TH1F*) AllDetHistograms->FindObject(detHistoTitle(*idet,"PercentNoisyStripsAllRuns")))->LabelsDeflate("X");
00180   }
00181   outputfile->Write();
00182   outputfile->Close();
00183 }
00184 
00185 
00186 TString SiStripHistoricPlot::detHistoTitle(uint32_t detid, std::string description){
00187   std::ostringstream oshistoid; TString ohistoid;
00188   oshistoid.str(""); oshistoid <<"DetId"<<detid<<"_"<<description; ohistoid=oshistoid.str();
00189   return ohistoid;
00190 }
00191 

Generated on Tue Jun 9 17:33:34 2009 for CMSSW by  doxygen 1.5.4