Skip to content

Commit

Permalink
robustify TkHistoMap and related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmusich committed Sep 21, 2022
1 parent dee7c06 commit 6ed0ba6
Show file tree
Hide file tree
Showing 5 changed files with 15,199 additions and 9 deletions.
7 changes: 6 additions & 1 deletion CalibTracker/SiStripCommon/src/TkDetMap.cc
Expand Up @@ -149,7 +149,7 @@ const int16_t TkLayerMap::layerSearch(DetId detid, const TrackerTopology* tTopo)
case SiStripDetId::TEC:
return TkLayerMap::TECM_W1 - 1 + (tTopo->tecSide(detid) - 1) * 9 + tTopo->tecWheel(detid);
default:
return 0;
return TkLayerMap::INVALID;
}
}

Expand Down Expand Up @@ -575,6 +575,11 @@ int16_t TkDetMap::findLayer(DetId detid,
cached_detid = detid;

int16_t layer = TkLayerMap::layerSearch(detid, tTopo_);
if (layer == TkLayerMap::INVALID) {
// there is something wrong if the layer is 0, early return
return TkLayerMap::INVALID;
}

LogTrace("TkDetMap") << "[findLayer] detid " << detid.rawId() << " layer " << layer;
if (layer != cached_layer) {
cached_layer = layer;
Expand Down
30 changes: 29 additions & 1 deletion DQM/SiStripCommon/src/TkHistoMap.cc
Expand Up @@ -170,6 +170,11 @@ std::string TkHistoMap::folderDefinition(DQMStore::IBooker& ibooker,
void TkHistoMap::fillFromAscii(const std::string& filename) {
std::ifstream file;
file.open(filename.c_str());

if (file.fail()) {
throw cms::Exception("LogicError") << "failed to open input file" << std::endl;
}

float value;
uint32_t detid;
while (file.good()) {
Expand All @@ -181,6 +186,11 @@ void TkHistoMap::fillFromAscii(const std::string& filename) {

void TkHistoMap::fill(DetId detid, float value) {
int16_t layer = tkdetmap_->findLayer(detid, cached_detid, cached_layer, cached_XYbin);
if (layer == TkLayerMap::INVALID) {
edm::LogError("TkHistoMap") << " could not fill for detid " << detid.rawId() << ", as the layer is invalid";
return;
}

TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid, cached_detid, cached_layer, cached_XYbin);
#ifdef debug_TkHistoMap
LogTrace("TkHistoMap") << "[TkHistoMap::fill] Fill detid " << detid.rawId() << " Layer " << layer << " value "
Expand All @@ -191,7 +201,6 @@ void TkHistoMap::fill(DetId detid, float value) {
tkHistoMap_[layer]->getTProfile2D()->Fill(xybin.x, xybin.y, value);
else if (tkHistoMap_[layer]->kind() == MonitorElement::Kind::TH2F)
tkHistoMap_[layer]->getTH2F()->Fill(xybin.x, xybin.y, value);

#ifdef debug_TkHistoMap
LogTrace("TkHistoMap") << "[TkHistoMap::fill] "
<< tkHistoMap_[layer]->getTProfile2D()->GetBinContent(xybin.ix, xybin.iy);
Expand All @@ -209,7 +218,13 @@ void TkHistoMap::fill(DetId detid, float value) {

void TkHistoMap::setBinContent(DetId detid, float value) {
int16_t layer = tkdetmap_->findLayer(detid, cached_detid, cached_layer, cached_XYbin);
if (layer == TkLayerMap::INVALID) {
edm::LogError("TkHistoMap") << " could not setBinContent for detid " << detid.rawId()
<< ", as the layer is invalid";
return;
}
TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid, cached_detid, cached_layer, cached_XYbin);

if (tkHistoMap_[layer]->kind() == MonitorElement::Kind::TPROFILE2D) {
tkHistoMap_[layer]->getTProfile2D()->SetBinEntries(tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix, xybin.iy),
1);
Expand Down Expand Up @@ -240,6 +255,10 @@ void TkHistoMap::add(DetId detid, float value) {
LogTrace("TkHistoMap") << "[TkHistoMap::add]";
#endif
int16_t layer = tkdetmap_->findLayer(detid, cached_detid, cached_layer, cached_XYbin);
if (layer == TkLayerMap::INVALID) {
edm::LogError("TkHistoMap") << " could not add for detid " << detid.rawId() << ", as the layer is invalid";
return;
}
TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid, cached_detid, cached_layer, cached_XYbin);
if (tkHistoMap_[layer]->kind() == MonitorElement::Kind::TPROFILE2D)
setBinContent(detid,
Expand All @@ -255,6 +274,11 @@ void TkHistoMap::add(DetId detid, float value) {

float TkHistoMap::getValue(DetId detid) {
int16_t layer = tkdetmap_->findLayer(detid, cached_detid, cached_layer, cached_XYbin);
if (layer == TkLayerMap::INVALID) {
edm::LogError("TkHistoMap") << " could not getValue for detid " << detid.rawId() << ", as the layer is invalid";
return -99999.f;
}

TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid, cached_detid, cached_layer, cached_XYbin);

if (tkHistoMap_[layer]->kind() == MonitorElement::Kind::TH2F)
Expand All @@ -265,6 +289,10 @@ float TkHistoMap::getValue(DetId detid) {
}
float TkHistoMap::getEntries(DetId detid) {
int16_t layer = tkdetmap_->findLayer(detid, cached_detid, cached_layer, cached_XYbin);
if (layer == TkLayerMap::INVALID) {
edm::LogError("TkHistoMap") << " could not getValue for detid " << detid.rawId() << ", as the layer is invalid";
return -99999.f;
}

if (tkHistoMap_[layer]->kind() == MonitorElement::Kind::TH2F) {
return 1;
Expand Down

0 comments on commit 6ed0ba6

Please sign in to comment.