CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/DQM/SiStripMonitorClient/src/SiStripTrackerMapCreator.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripMonitorClient/interface/SiStripTrackerMapCreator.h"
00002 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
00003 #include "CalibTracker/SiStripCommon/interface/TkDetMap.h"
00004 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
00005 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
00006 #include "DQM/SiStripMonitorClient/interface/SiStripConfigParser.h"
00007 #include "DQMServices/Core/interface/DQMStore.h"
00008 
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include <iostream>
00011 
00012 //
00013 // -- Constructor
00014 // 
00015 SiStripTrackerMapCreator::SiStripTrackerMapCreator() {
00016   trackerMap_ = 0;
00017   if(!edm::Service<TkDetMap>().isAvailable()){
00018     edm::LogError("TkHistoMap") <<
00019       "\n------------------------------------------"
00020       "\nUnAvailable Service TkHistoMap: please insert in the configuration file an instance like"
00021       "\n\tprocess.TkDetMap = cms.Service(\"TkDetMap\")"
00022       "\n------------------------------------------";
00023   }
00024   tkDetMap_=edm::Service<TkDetMap>().operator->();
00025 }
00026 //
00027 // -- Destructor
00028 //
00029 SiStripTrackerMapCreator::~SiStripTrackerMapCreator() {
00030   if (trackerMap_) delete trackerMap_;
00031 }
00032 //
00033 // -- Create Geometric and Fed Tracker Map
00034 //
00035 void SiStripTrackerMapCreator::create(const edm::ParameterSet & tkmapPset, 
00036      const edm::ESHandle<SiStripFedCabling>& fedcabling, DQMStore* dqm_store, std::string& map_type) {
00037 
00038   if (trackerMap_) delete trackerMap_;
00039   trackerMap_ = new TrackerMap(tkmapPset, fedcabling);
00040   std::string tmap_title = " Tracker Map from  " + map_type;
00041   trackerMap_->setTitle(tmap_title);
00042  
00043   nDet     = 0;
00044   tkMapLog = false;
00045   tkMapMax = 0.0; 
00046   tkMapMin = 0.0; 
00047 
00048   if (map_type == "QTestAlarm") {
00049     trackerMap_->fillc_all_blank();
00050     const std::vector<uint16_t>& feds = fedcabling->feds(); 
00051     uint32_t detId_save = 0;
00052     for(std::vector<unsigned short>::const_iterator ifed = feds.begin(); 
00053         ifed < feds.end(); ifed++){
00054       const std::vector<FedChannelConnection> fedChannels = fedcabling->connections( *ifed );
00055       for(std::vector<FedChannelConnection>::const_iterator iconn = fedChannels.begin(); iconn < fedChannels.end(); iconn++){
00056         
00057         uint32_t detId = iconn->detId();
00058         if (detId == 0 || detId == 0xFFFFFFFF)  continue;
00059         if (detId_save != detId) {
00060           detId_save = detId;
00061           paintTkMapFromAlarm(detId, dqm_store);
00062         }
00063       }
00064     } 
00065   } else {
00066     trackerMap_->fill_all_blank();
00067     setTkMapFromHistogram(dqm_store, map_type);
00068     setTkMapRange(map_type);
00069   }
00070   trackerMap_->printonline();
00071   delete trackerMap_;
00072   trackerMap_ = 0;
00073 }
00074 //
00075 // -- Create Tracker Map for Offline process
00076 //
00077 void SiStripTrackerMapCreator::createForOffline(const edm::ParameterSet & tkmapPset, 
00078                                                 const edm::ESHandle<SiStripFedCabling>& fedcabling,
00079                                                 DQMStore* dqm_store, std::string& map_type){
00080   if (trackerMap_) delete trackerMap_;
00081   trackerMap_ = new TrackerMap(tkmapPset,fedcabling);
00082 
00083   tkMapLog = tkmapPset.getUntrackedParameter<bool>("logScale",false);
00084   bool tkMapPSU = tkmapPset.getUntrackedParameter<bool>("psuMap",false);
00085  
00086   std::string tmap_title = " Tracker Map from  " + map_type;
00087   if(tkMapLog) tmap_title += ": Log10 scale";
00088   trackerMap_->setTitle(tmap_title);
00089 
00090   setTkMapFromHistogram(dqm_store, map_type);
00091   // if not overwitten by manual configuration min=0 and max= mean value * 2.5
00092   setTkMapRangeOffline();
00093 
00094   // check manual setting
00095   
00096   if(tkmapPset.exists("mapMax")) tkMapMax = tkmapPset.getUntrackedParameter<double>("mapMax");
00097   if(tkmapPset.exists("mapMin")) tkMapMin = tkmapPset.getUntrackedParameter<double>("mapMin");
00098   
00099   std::cout << "Ready to save TkMap " << map_type << " with range set to " << tkMapMin << " - " << tkMapMax << std::endl;
00100   
00101   trackerMap_->save(true, tkMapMin,tkMapMax, map_type+".svg");  
00102   trackerMap_->save(true, tkMapMin,tkMapMax, map_type+".png",4500,2400);
00103 
00104   if(tkMapPSU) {
00105 
00106     std::cout << "Ready to save PSU TkMap " << map_type << " with range set to " << tkMapMin << " - " << tkMapMax << std::endl;
00107     trackerMap_->save_as_psutrackermap(true, tkMapMin,tkMapMax, map_type+"_psu.svg");
00108     trackerMap_->save_as_psutrackermap(true, tkMapMin,tkMapMax, map_type+"_psu.png",6000,3200);
00109 
00110   }
00111 
00112   delete trackerMap_;
00113   trackerMap_ = 0;
00114 }
00115 //
00116 // -- Paint Tracker Map with QTest Alarms 
00117 //
00118 void SiStripTrackerMapCreator::paintTkMapFromAlarm(uint32_t det_id, DQMStore* dqm_store) {
00119   
00120   std::ostringstream comment;
00121   uint16_t flag = 0; 
00122   flag = getDetectorFlagAndComment(dqm_store, det_id, comment);
00123 
00124   int rval, gval, bval;
00125   SiStripUtility::getDetectorStatusColor(flag, rval, gval, bval);
00126   trackerMap_->setText(det_id, comment.str());
00127   trackerMap_->fillc(det_id, rval, gval, bval);
00128 }
00129 
00130 //
00131 // --  Paint Tracker Map from TkHistoMap Histograms
00132 void SiStripTrackerMapCreator::setTkMapFromHistogram(DQMStore* dqm_store, std::string& htype) {
00133   dqm_store->cd();
00134 
00135   std::string mdir = "MechanicalView";
00136   if (!SiStripUtility::goToDir(dqm_store, mdir)) return;
00137   std::string mechanicalview_dir = dqm_store->pwd();
00138 
00139   std::vector<std::string> subdet_folder;
00140   subdet_folder.push_back("TIB");
00141   subdet_folder.push_back("TOB");
00142   subdet_folder.push_back("TEC/side_1");
00143   subdet_folder.push_back("TEC/side_2");
00144   subdet_folder.push_back("TID/side_1");
00145   subdet_folder.push_back("TID/side_2");
00146 
00147   nDet     = 0;
00148   tkMapMax = 0.0; 
00149   tkMapMin = 0.0; 
00150 
00151   for (std::vector<std::string>::const_iterator it = subdet_folder.begin(); it != subdet_folder.end(); it++) {
00152     std::string dname = mechanicalview_dir + "/" + (*it);
00153     if (!dqm_store->dirExists(dname)) continue;
00154     dqm_store->cd(dname);  
00155     std::vector<std::string> layerVec = dqm_store->getSubdirs();
00156     for (std::vector<std::string>::const_iterator iLayer = layerVec.begin(); iLayer != layerVec.end(); iLayer++) { 
00157       if ((*iLayer).find("BadModuleList") !=std::string::npos) continue;
00158       std::vector<MonitorElement*> meVec = dqm_store->getContents((*iLayer));
00159       MonitorElement* tkhmap_me = 0;
00160       std::string name;
00161       for (std::vector<MonitorElement*>::const_iterator itkh = meVec.begin();  itkh != meVec.end(); itkh++) {
00162         name = (*itkh)->getName();
00163         if (name.find("TkHMap") == std::string::npos) continue;
00164         if (htype == "QTestAlarm" ){
00165           tkhmap_me = (*itkh);
00166           break;
00167         } else if (name.find(htype) != std::string::npos) {
00168           tkhmap_me = (*itkh);
00169           break; 
00170         } 
00171       }
00172       if (tkhmap_me != 0) {
00173         paintTkMapFromHistogram(dqm_store,tkhmap_me, htype);
00174       } 
00175     }
00176     dqm_store->cd(mechanicalview_dir);
00177   }
00178   dqm_store->cd();
00179 }
00180 void SiStripTrackerMapCreator::paintTkMapFromHistogram(DQMStore* dqm_store, MonitorElement* me, std::string& htype) {
00181   std::string name  = me->getName();
00182   std::string lname = name.substr(name.find("TkHMap_")+7);  
00183   lname = lname.substr(lname.find("_T")+1);
00184   std::vector<uint32_t> layer_detids;
00185   tkDetMap_->getDetsForLayer(tkDetMap_->getLayerNum(lname), layer_detids);
00186   for (std::vector<uint32_t>::const_iterator idet = layer_detids.begin(); idet != layer_detids.end(); idet++) {
00187     uint32_t det_id= (*idet);
00188     if (det_id <= 0) continue;
00189     nDet++;
00190     std::ostringstream comment;
00191     uint32_t flag = 0;
00192     flag = getDetectorFlagAndComment(dqm_store, det_id, comment);
00193     trackerMap_->setText(det_id, comment.str());
00194     const TkLayerMap::XYbin& xyval = tkDetMap_->getXY(det_id);
00195     float fval = 0.0;
00196     if ( (name.find("NumberOfOfffTrackCluster") != std::string::npos) || 
00197          (name.find("NumberOfOnTrackCluster") != std::string::npos) ) {
00198       if (me->kind() == MonitorElement::DQM_KIND_TPROFILE2D) {   
00199         TProfile2D* tp = me->getTProfile2D() ;
00200         fval =  tp->GetBinEntries(tp->GetBin(xyval.ix, xyval.iy)) * tp->GetBinContent(xyval.ix, xyval.iy);
00201       }
00202     } else  fval = me->getBinContent(xyval.ix, xyval.iy);
00203     if (htype == "QTestAlarm") {
00204       int rval, gval, bval;
00205       SiStripUtility::getDetectorStatusColor(flag, rval, gval, bval);
00206       trackerMap_->fillc(det_id, rval, gval, bval);
00207     } else {
00208       if (fval == 0.0) trackerMap_->fillc(det_id,255, 255, 255);  
00209       else {
00210         if(tkMapLog) fval = log(fval)/log(10);
00211         trackerMap_->fill_current_val(det_id, fval);
00212       }
00213       tkMapMax += fval;
00214     }
00215   }
00216 } 
00217 //
00218 // -- Get Tracker Map Fill Range
00219 //
00220 void SiStripTrackerMapCreator::setTkMapRange(std::string& map_type) {
00221   tkMapMin = 0.0;
00222   if (tkMapMax == 0.0) { 
00223     if (map_type.find("FractionOfBadChannels") != std::string::npos)        tkMapMax = 1.0;
00224     else if (map_type.find("NumberOfCluster") != std::string::npos)         tkMapMax = 0.01;
00225     else if (map_type.find("NumberOfDigi") != std::string::npos)            tkMapMax = 0.6;
00226     else if (map_type.find("NumberOfOffTrackCluster") != std::string::npos) tkMapMax = 100.0;
00227     else if (map_type.find("NumberOfOnTrackCluster") != std::string::npos)  tkMapMax = 50.0;
00228     else if (map_type.find("StoNCorrOnTrack") != std::string::npos)         tkMapMax = 200.0;
00229   } else {
00230     tkMapMax = tkMapMax/nDet*1.0;
00231     tkMapMax = tkMapMax * 2.5;
00232  }
00233   trackerMap_->setRange(tkMapMin, tkMapMax);
00234 }
00235 void SiStripTrackerMapCreator::setTkMapRangeOffline() {
00236   tkMapMin = 0.0;
00237   if (tkMapMax != 0.0) { 
00238     tkMapMax = tkMapMax/nDet*1.0;
00239     tkMapMax = tkMapMax * 2.5;
00240  }
00241   trackerMap_->setRange(tkMapMin, tkMapMax);
00242 }
00243 //
00244 // -- Get Flag and status Comment
00245 //
00246 uint16_t SiStripTrackerMapCreator::getDetectorFlagAndComment(DQMStore* dqm_store, uint32_t det_id, std::ostringstream& comment) {
00247   comment << " DetId " << det_id << " : ";
00248   uint16_t flag = 0;
00249 
00250   SiStripFolderOrganizer folder_organizer;
00251   std::string subdet_folder, badmodule_folder;
00252 
00253   folder_organizer.getSubDetFolder(det_id, subdet_folder);
00254   if (dqm_store->dirExists(subdet_folder)){ 
00255     badmodule_folder = subdet_folder + "/BadModuleList";
00256   } else {
00257     badmodule_folder = dqm_store->pwd() + "/BadModuleList"; 
00258   }
00259   if (!dqm_store->dirExists(badmodule_folder)) return flag;
00260 
00261   std::ostringstream badmodule_path;
00262   badmodule_path << badmodule_folder << "/" << det_id;
00263 
00264   MonitorElement* bad_module_me = dqm_store->get(badmodule_path.str());
00265   if (bad_module_me && bad_module_me->kind() == MonitorElement::DQM_KIND_INT) {
00266     flag = bad_module_me->getIntValue();
00267     std::string message;
00268     SiStripUtility::getBadModuleStatus(flag, message);
00269     comment << message.c_str();
00270   }
00271   return flag;
00272 }