CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/DQMOffline/CalibTracker/plugins/SiStripDQMProfileToTkMapConverter.cc

Go to the documentation of this file.
00001 #include "DQMOffline/CalibTracker/plugins/SiStripDQMProfileToTkMapConverter.h"
00002 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00003 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00004 #include "DataFormats/SiStripDetId/interface/SiStripSubStructure.h"
00005 
00006 
00007 SiStripDQMProfileToTkMapConverter::SiStripDQMProfileToTkMapConverter(const edm::ParameterSet& iConfig) : 
00008   conf_(iConfig), 
00009   filename(iConfig.getUntrackedParameter<std::string>("rootFilename","CondDB_TKCC_20X_v3_hlt_50822.root")),
00010   dirpath(iConfig.getUntrackedParameter<std::string>("rootDirPath","")),
00011   TkMapFileName_(iConfig.getUntrackedParameter<std::string>("TkMapFileName",""))
00012 {
00013   edm::LogInfo("SiStripDQMProfileToTkMapConverter") << " ctor ";  
00014   reader = new SiStripDetInfoFileReader(fp_.fullPath());  
00015   
00016   edm::LogInfo("SiStripDQMProfileToTkMapConverter") << " before opening file " << filename.c_str();  
00017   dqmStore_ = edm::Service<DQMStore>().operator->(); 
00018   dqmStore_->setVerbose(iConfig.getUntrackedParameter<uint32_t>("verbosity",0)); 
00019   
00020   dqmStore_->open(filename.c_str(), false,dirpath); 
00021   edm::LogInfo("SiStripDQMProfileToTkMapConverter") << " after opening file ";  
00022 }
00023 
00024 
00025 SiStripDQMProfileToTkMapConverter::~SiStripDQMProfileToTkMapConverter(){
00026   edm::LogInfo("SiStripDQMProfileToTkMapConverter") << " dtor";
00027 }
00028 
00029 void SiStripDQMProfileToTkMapConverter::beginRun(const edm::Run& run, const edm::EventSetup& es){
00030 
00031   tkMap=new TrackerMap( "DigiOcc" );
00032   tkhisto=new TkHistoMap("DigiOcc","DigiOcc",-1.);
00033  
00034   //******************************
00035   //Get DetCabling to translate the DQM TProfile in TkMaps
00036   
00037   edm::ESHandle<SiStripDetCabling> tkmechstruct;
00038   es.get<SiStripDetCablingRcd>().get(tkmechstruct);
00039     
00040   // get list of active detectors from SiStripDetCabling
00041   std::vector<uint32_t> activeDets; 
00042   activeDets.clear(); // just in case
00043   tkmechstruct->addActiveDetectorsRawIds(activeDets);
00044   SiStripSubStructure substructure;
00045     
00046   std::vector<uint32_t> SelectedDetIds[34];
00047   size_t i=0;
00048 
00049   //i=0-3
00050   for(size_t j=1;j<5;j++)
00051     substructure.getTIBDetectors(activeDets,SelectedDetIds[i++],j,0,0,0);
00052 
00053   //i=4-9
00054   for(size_t j=1;j<7;j++)
00055     substructure.getTOBDetectors(activeDets,SelectedDetIds[i++],j,0,0);
00056 
00057   //i=10-12
00058   for(size_t j=1;j<4;j++)
00059     substructure.getTIDDetectors(activeDets,SelectedDetIds[i++],1,j,0,0);
00060 
00061   //i=13-15
00062   for(size_t j=1;j<4;j++)
00063     substructure.getTIDDetectors(activeDets,SelectedDetIds[i++],2,j,0,0);
00064           
00065   //i=16-24
00066   for(size_t j=1;j<10;j++)
00067     substructure.getTECDetectors(activeDets,SelectedDetIds[i++],1,j,0,0,0,0);
00068 
00069   //i=25-33
00070   for(size_t j=1;j<10;j++)
00071     substructure.getTECDetectors(activeDets,SelectedDetIds[i++],2,j,0,0,0,0);
00072   
00073   //******************************
00074 
00075 
00076   //**********************
00077   // Get ME from the DQM root file and search for interesting histograms
00078 
00079   edm::LogInfo("SiStripDQMProfileToTkMapConverter") <<" [SiStripDQMProfileToTkMapConverter] dirpath " << dirpath << std::endl;
00080   
00081   std::vector<MonitorElement*> MEs = dqmStore_->getAllContents(dirpath);
00082   
00083   edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::bookHistos] vector size " << MEs.size()<< std::endl;
00084 
00085   std::vector<MonitorElement*>::const_iterator iter=MEs.begin();
00086   std::vector<MonitorElement*>::const_iterator iterEnd=MEs.end();
00087 
00088   std::stringstream ssFull, ssReport;
00089 
00090   const TProfile* histo;
00091   size_t layerIdx;
00092   for (; iter!=iterEnd;++iter) {
00093     std::string me_name = (*iter)->getName();
00094     
00095     if (strstr(me_name.c_str(),"NumberOfDigiProfile__")==NULL)
00096       continue;
00097 
00098     ssFull << me_name.c_str() << std::endl;
00099     layerIdx=0;
00100    
00101     std::stringstream ss;
00102     if(strstr(me_name.c_str(),"TIB")!=NULL){
00103       ss<<strstr(me_name.c_str(), "layer__")[7];
00104       ssReport << "\nTIB Layer " << ss.str() << "\n";
00105       layerIdx=atoi(ss.str().c_str());
00106     }else if(strstr(me_name.c_str(),"TOB")!=NULL){
00107       ss<<strstr(me_name.c_str(), "layer__")[7];
00108       layerIdx=atoi(ss.str().c_str())+4;
00109       ssReport << "\nTOB Layer " << ss.str() << "\n";
00110     }else if(strstr(me_name.c_str(),"TID")!=NULL){
00111       ss<<strstr(me_name.c_str(), "wheel__")[7];
00112       layerIdx=atoi(ss.str().c_str())+10;
00113       if(strstr(me_name.c_str(),"side__2")!=NULL){
00114         layerIdx+=3;
00115       }
00116       ssReport << "\nTID Disk " << ss.str() << "\n";
00117     }else if(strstr(me_name.c_str(),"TEC")!=NULL){
00118       ss<<strstr(me_name.c_str(), "wheel__")[7];
00119       layerIdx=atoi(ss.str().c_str())+16;
00120       if(strstr(me_name.c_str(),"side__2")!=NULL){
00121         layerIdx+=9;
00122       }
00123       ssReport << "\nTEC Wheel " << ss.str() << "\n";
00124     }      
00125     
00126     std::cout << ss.str() << " " << layerIdx << " selected dets size " << SelectedDetIds[layerIdx-1].size()<< std::endl;
00127     
00128     if(layerIdx!=0){
00129       histo= (TProfile *) (*(*iter)).getTProfile();
00130       for(int ibin=1;ibin<histo->GetNbinsX();++ibin){
00131         ssFull << layerIdx << " " << ibin << " " << SelectedDetIds[layerIdx-1][ibin-1] << " " <<  histo->GetBinContent(ibin) << std::endl;
00132         tkMap->fill(SelectedDetIds[layerIdx-1][ibin-1],1/(histo->GetBinContent(ibin)+0.0000001));
00133         tkhisto->fill(SelectedDetIds[layerIdx-1][ibin-1],1/(histo->GetBinContent(ibin)+0.0000001));
00134         
00135         if(histo->GetBinContent(ibin)==0)
00136           ssReport << "\t" << layerIdx << " \t " << ibin << " \t " << SelectedDetIds[layerIdx-1][ibin-1] << std::endl;
00137       }
00138     }
00139   }
00140   LogDebug("SiStripDQMProfileToTkMapConverter") <<" [SiStripDQMProfileToTkMapConverter] fullPrint " << ssFull.str() << std::endl;
00141   edm::LogInfo("SiStripDQMProfileToTkMapConverter") <<" [SiStripDQMProfileToTkMapConverter] fullPrint " << ssReport.str() << std::endl;
00142 }
00143 
00144 void SiStripDQMProfileToTkMapConverter::endJob(){
00145 
00146   std::string filename=TkMapFileName_;
00147   if (filename!=""){
00148     edm::LogInfo("SiStripDQMProfileToTkMapConverter") <<" [SiStripDQMProfileToTkMapConverter] endJob Saving.........." << std::endl;
00149     tkMap->save(false,0,0,filename.c_str());
00150     filename.erase(filename.begin()+filename.find("."),filename.end());      
00151     tkhisto->save(filename+".root");
00152     tkhisto->saveAsCanvas(filename+"_Canvas.root",conf_.getUntrackedParameter<std::string>("TkMapDrawOption","E"));
00153   }
00154 
00155 }
00156 
00157 
00158