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
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
00028
00029 SiStripTrackerMapCreator::~SiStripTrackerMapCreator() {
00030 if (trackerMap_) delete trackerMap_;
00031 }
00032
00033
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 tkMapMax = 0.0;
00045 tkMapMin = 0.0;
00046
00047 if (map_type == "QTestAlarm") {
00048 trackerMap_->fillc_all_blank();
00049 const std::vector<uint16_t>& feds = fedcabling->feds();
00050 uint32_t detId_save = 0;
00051 for(std::vector<unsigned short>::const_iterator ifed = feds.begin();
00052 ifed < feds.end(); ifed++){
00053 const std::vector<FedChannelConnection> fedChannels = fedcabling->connections( *ifed );
00054 for(std::vector<FedChannelConnection>::const_iterator iconn = fedChannels.begin(); iconn < fedChannels.end(); iconn++){
00055
00056 uint32_t detId = iconn->detId();
00057 if (detId == 0 || detId == 0xFFFFFFFF) continue;
00058 if (detId_save != detId) {
00059 detId_save = detId;
00060 paintTkMapFromAlarm(detId, dqm_store);
00061 }
00062 }
00063 }
00064 } else {
00065 trackerMap_->fill_all_blank();
00066 setTkMapFromHistogram(dqm_store, map_type);
00067 setTkMapRange(map_type);
00068 }
00069 trackerMap_->printonline();
00070 delete trackerMap_;
00071 trackerMap_ = 0;
00072 }
00073
00074
00075
00076 void SiStripTrackerMapCreator::createForOffline(const edm::ParameterSet & tkmapPset,
00077 DQMStore* dqm_store, std::string& map_type){
00078 if (trackerMap_) delete trackerMap_;
00079 trackerMap_ = new TrackerMap(tkmapPset);
00080
00081 std::string tmap_title = " Tracker Map from " + map_type;
00082 trackerMap_->setTitle(tmap_title);
00083
00084 setTkMapFromHistogram(dqm_store, map_type);
00085 setTkMapRange(map_type);
00086
00087 trackerMap_->save(true, tkMapMin,tkMapMax, map_type+".svg");
00088 trackerMap_->save(true, tkMapMin,tkMapMax, map_type+".png",4500,2400);
00089 delete trackerMap_;
00090 trackerMap_ = 0;
00091 }
00092
00093
00094
00095 void SiStripTrackerMapCreator::paintTkMapFromAlarm(uint32_t det_id, DQMStore* dqm_store) {
00096
00097 std::ostringstream comment;
00098 uint16_t flag = 0;
00099 flag = getDetectorFlagAndComment(dqm_store, det_id, comment);
00100
00101 int rval, gval, bval;
00102 SiStripUtility::getDetectorStatusColor(flag, rval, gval, bval);
00103 trackerMap_->setText(det_id, comment.str());
00104 trackerMap_->fillc(det_id, rval, gval, bval);
00105 }
00106
00107
00108
00109 void SiStripTrackerMapCreator::setTkMapFromHistogram(DQMStore* dqm_store, std::string& htype) {
00110 dqm_store->cd();
00111
00112 std::string mdir = "MechanicalView";
00113 if (!SiStripUtility::goToDir(dqm_store, mdir)) return;
00114 std::string mechanicalview_dir = dqm_store->pwd();
00115
00116 std::vector<std::string> subdet_folder;
00117 subdet_folder.push_back("TIB");
00118 subdet_folder.push_back("TOB");
00119 subdet_folder.push_back("TEC/side_1");
00120 subdet_folder.push_back("TEC/side_2");
00121 subdet_folder.push_back("TID/side_1");
00122 subdet_folder.push_back("TID/side_2");
00123
00124 nDet = 0;
00125 tkMapMax = 0.0;
00126 tkMapMin = 0.0;
00127
00128 for (std::vector<std::string>::const_iterator it = subdet_folder.begin(); it != subdet_folder.end(); it++) {
00129 std::string dname = mechanicalview_dir + "/" + (*it);
00130 if (!dqm_store->dirExists(dname)) continue;
00131 dqm_store->cd(dname);
00132 std::vector<std::string> layerVec = dqm_store->getSubdirs();
00133 for (std::vector<std::string>::const_iterator iLayer = layerVec.begin(); iLayer != layerVec.end(); iLayer++) {
00134 if ((*iLayer).find("BadModuleList") !=std::string::npos) continue;
00135 std::vector<MonitorElement*> meVec = dqm_store->getContents((*iLayer));
00136 MonitorElement* tkhmap_me = 0;
00137 std::string name;
00138 for (std::vector<MonitorElement*>::const_iterator itkh = meVec.begin(); itkh != meVec.end(); itkh++) {
00139 name = (*itkh)->getName();
00140 if (name.find("TkHMap") == std::string::npos) continue;
00141 if (htype == "QTestAlarm" ){
00142 tkhmap_me = (*itkh);
00143 break;
00144 } else if (name.find(htype) != std::string::npos) {
00145 tkhmap_me = (*itkh);
00146 break;
00147 }
00148 }
00149 if (tkhmap_me != 0) {
00150 paintTkMapFromHistogram(dqm_store,tkhmap_me, htype);
00151 }
00152 }
00153 dqm_store->cd(mechanicalview_dir);
00154 }
00155 dqm_store->cd();
00156 }
00157 void SiStripTrackerMapCreator::paintTkMapFromHistogram(DQMStore* dqm_store, MonitorElement* me, std::string& htype) {
00158 std::string name = me->getName();
00159 std::string lname = name.substr(name.find("TkHMap_")+7);
00160 lname = lname.substr(lname.find("_T")+1);
00161 std::vector<uint32_t> layer_detids;
00162 tkDetMap_->getDetsForLayer(tkDetMap_->getLayerNum(lname), layer_detids);
00163 for (std::vector<uint32_t>::const_iterator idet = layer_detids.begin(); idet != layer_detids.end(); idet++) {
00164 uint32_t det_id= (*idet);
00165 if (det_id <= 0) continue;
00166 nDet++;
00167 std::ostringstream comment;
00168 uint32_t flag = 0;
00169 flag = getDetectorFlagAndComment(dqm_store, det_id, comment);
00170 trackerMap_->setText(det_id, comment.str());
00171 const TkLayerMap::XYbin& xyval = tkDetMap_->getXY(det_id);
00172 float fval = 0.0;
00173 if ( (name.find("NumberOfOfffTrackCluster") != std::string::npos) ||
00174 (name.find("NumberOfOnTrackCluster") != std::string::npos) ) {
00175 if (me->kind() == MonitorElement::DQM_KIND_TPROFILE2D) {
00176 TProfile2D* tp = me->getTProfile2D() ;
00177 fval = tp->GetBinEntries(tp->GetBin(xyval.ix, xyval.iy)) * tp->GetBinContent(xyval.ix, xyval.iy);
00178 }
00179 } else fval = me->getBinContent(xyval.ix, xyval.iy);
00180 if (htype == "QTestAlarm") {
00181 int rval, gval, bval;
00182 SiStripUtility::getDetectorStatusColor(flag, rval, gval, bval);
00183 trackerMap_->fillc(det_id, rval, gval, bval);
00184 } else {
00185 tkMapMax += fval;
00186 if (fval == 0.0) trackerMap_->fillc(det_id,255, 255, 255);
00187 else {
00188 trackerMap_->fill_current_val(det_id, fval);
00189 }
00190 }
00191 }
00192 }
00193
00194
00195
00196 void SiStripTrackerMapCreator::setTkMapRange(std::string& map_type) {
00197 tkMapMin = 0.0;
00198 if (tkMapMax == 0.0) {
00199 if (map_type.find("FractionOfBadChannels") != std::string::npos) tkMapMax = 1.0;
00200 else if (map_type.find("NumberOfCluster") != std::string::npos) tkMapMax = 0.01;
00201 else if (map_type.find("NumberOfDigi") != std::string::npos) tkMapMax = 0.6;
00202 else if (map_type.find("NumberOfOffTrackCluster") != std::string::npos) tkMapMax = 100.0;
00203 else if (map_type.find("NumberOfOnTrackCluster") != std::string::npos) tkMapMax = 50.0;
00204 else if (map_type.find("StoNCorrOnTrack") != std::string::npos) tkMapMax = 200.0;
00205 } else {
00206 tkMapMax = tkMapMax/nDet*1.0;
00207 tkMapMax = tkMapMax * 2.5;
00208 }
00209 trackerMap_->setRange(tkMapMin, tkMapMax);
00210 }
00211
00212
00213
00214 uint16_t SiStripTrackerMapCreator::getDetectorFlagAndComment(DQMStore* dqm_store, uint32_t det_id, std::ostringstream& comment) {
00215 comment << " DetId " << det_id << " : ";
00216 uint16_t flag = 0;
00217
00218 SiStripFolderOrganizer folder_organizer;
00219 std::string subdet_folder, badmodule_folder;
00220
00221 folder_organizer.getSubDetFolder(det_id, subdet_folder);
00222 if (dqm_store->dirExists(subdet_folder)){
00223 badmodule_folder = subdet_folder + "/BadModuleList";
00224 } else {
00225 badmodule_folder = dqm_store->pwd() + "/BadModuleList";
00226 }
00227 if (!dqm_store->dirExists(badmodule_folder)) return flag;
00228
00229 std::ostringstream badmodule_path;
00230 badmodule_path << badmodule_folder << "/" << det_id;
00231
00232 MonitorElement* bad_module_me = dqm_store->get(badmodule_path.str());
00233 if (bad_module_me && bad_module_me->kind() == MonitorElement::DQM_KIND_INT) {
00234 flag = bad_module_me->getIntValue();
00235 std::string message;
00236 SiStripUtility::getBadModuleStatus(flag, message);
00237 comment << message.c_str();
00238 }
00239 return flag;
00240 }