|
| 1 | +// -*- C++ -*- |
| 2 | +// |
| 3 | +// Package: HGCalTestDDDCons.cc |
| 4 | +// Class: HGCalTestDDDCons |
| 5 | +// |
| 6 | +/**\class HGCalTestDDDCons HGCalTestDDDCons.cc |
| 7 | + test/HGCalTestDDDCons.cc |
| 8 | +
|
| 9 | + Description: <one line class summary> |
| 10 | +
|
| 11 | + Implementation: |
| 12 | + <Notes on implementation> |
| 13 | +*/ |
| 14 | +// |
| 15 | +// Original Author: Pruthvi Suryadevara |
| 16 | +// Created: Mon 2025/7/11 |
| 17 | +// |
| 18 | +// |
| 19 | + |
| 20 | +// system include files |
| 21 | +#include <fstream> |
| 22 | +#include <iostream> |
| 23 | +#include <sstream> |
| 24 | +#include <string> |
| 25 | +#include <vector> |
| 26 | +#include <cmath> |
| 27 | + |
| 28 | +// user include files |
| 29 | +#include "FWCore/Framework/interface/Frameworkfwd.h" |
| 30 | +#include "FWCore/Framework/interface/one/EDAnalyzer.h" |
| 31 | +#include "FWCore/Framework/interface/Event.h" |
| 32 | +#include "FWCore/Framework/interface/EventSetup.h" |
| 33 | +#include "FWCore/Framework/interface/MakerMacros.h" |
| 34 | +#include "FWCore/MessageLogger/interface/MessageLogger.h" |
| 35 | +#include "FWCore/ParameterSet/interface/FileInPath.h" |
| 36 | +#include "FWCore/ParameterSet/interface/ParameterSet.h" |
| 37 | +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" |
| 38 | +#include "FWCore/Utilities/interface/transform.h" |
| 39 | + |
| 40 | +#include "DataFormats/DetId/interface/DetId.h" |
| 41 | +#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h" |
| 42 | +#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h" |
| 43 | +#include "Geometry/HGCalCommonData/interface/HGCalGeomUtils.h" |
| 44 | +#include "Geometry/Records/interface/IdealGeometryRecord.h" |
| 45 | +#include "Geometry/HGCalCommonData/interface/HGCalCell.h" |
| 46 | +#include "Geometry/HGCalCommonData/interface/HGCalWaferIndex.h" |
| 47 | + |
| 48 | +class HGCalTestDDDCons : public edm::one::EDAnalyzer<edm::one::WatchRuns> { |
| 49 | +public: |
| 50 | + explicit HGCalTestDDDCons(const edm::ParameterSet &); |
| 51 | + ~HGCalTestDDDCons() override = default; |
| 52 | + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); |
| 53 | + |
| 54 | + void beginJob() override {} |
| 55 | + void beginRun(edm::Run const &, edm::EventSetup const &) override; |
| 56 | + void analyze(edm::Event const &iEvent, edm::EventSetup const &) override {} |
| 57 | + void endRun(edm::Run const &, edm::EventSetup const &) override {} |
| 58 | + void endJob() override {} |
| 59 | + |
| 60 | +private: |
| 61 | + const std::vector<std::string> nameDetectors_; |
| 62 | + const std::string fileName_; |
| 63 | + const std::vector<edm::ESGetToken<HGCalDDDConstants, IdealGeometryRecord>> tok_hgcal_; |
| 64 | + int size; |
| 65 | + std::vector<const HGCalDDDConstants *> hgcCons_; |
| 66 | + std::vector<std::pair<DetId, uint32_t>> detIds_; |
| 67 | + std::vector<double> xwafer_, ywafer_, xcell_, ycell_, xcellOff_, ycellOff_; |
| 68 | +}; |
| 69 | + |
| 70 | +HGCalTestDDDCons::HGCalTestDDDCons(const edm::ParameterSet &iC) |
| 71 | + : nameDetectors_(iC.getParameter<std::vector<std::string>>("nameDetectors")), |
| 72 | + fileName_(iC.getParameter<std::string>("fileName")), |
| 73 | + tok_hgcal_{edm::vector_transform(nameDetectors_, [this](const std::string &name) { |
| 74 | + return esConsumes<HGCalDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(edm::ESInputTag{"", name}); |
| 75 | + })} { |
| 76 | + std::ostringstream st1; |
| 77 | + for (const auto &name : nameDetectors_) |
| 78 | + st1 << " : " << name; |
| 79 | + edm::LogVerbatim("HGCGeom") << "Test validity of cells for " << nameDetectors_.size() << " detectors" << st1.str() |
| 80 | + << " with inputs from " << fileName_; |
| 81 | + if (!fileName_.empty()) { |
| 82 | + edm::FileInPath filetmp("Geometry/HGCalCommonData/data/" + fileName_); |
| 83 | + std::string fileName = filetmp.fullPath(); |
| 84 | + std::ifstream fInput(fileName.c_str()); |
| 85 | + if (!fInput.good()) { |
| 86 | + edm::LogVerbatim("HGCGeom") << "Cannot open file " << fileName; |
| 87 | + } else { |
| 88 | + char buffer[200]; |
| 89 | + const std::vector<DetId::Detector> dets = {DetId::HGCalEE, DetId::HGCalHSi, DetId::HGCalHSc}; |
| 90 | + while (fInput.getline(buffer, 200)) { |
| 91 | + std::vector<std::string> items = HGCalGeomUtils::splitString(std::string(buffer)); |
| 92 | + if (items.size() == 14) { |
| 93 | + DetId::Detector det = static_cast<DetId::Detector>(std::atoi(items[0].c_str())); |
| 94 | + auto itr = std::find(dets.begin(), dets.end(), det); |
| 95 | + if (itr != dets.end()) { |
| 96 | + uint32_t pos = static_cast<uint32_t>(itr - dets.begin()); |
| 97 | + DetId id(0); |
| 98 | + if ((det == DetId::HGCalEE) || (det == DetId::HGCalHSi)) { |
| 99 | + int type = std::atoi(items[1].c_str()); |
| 100 | + int zside = std::atoi(items[2].c_str()); |
| 101 | + int layer = std::atoi(items[3].c_str()); |
| 102 | + int waferU = std::atoi(items[4].c_str()); |
| 103 | + int waferV = std::atoi(items[5].c_str()); |
| 104 | + int cellU = std::atoi(items[6].c_str()); |
| 105 | + int cellV = std::atoi(items[7].c_str()); |
| 106 | + id = static_cast<DetId>(HGCSiliconDetId(det, zside, type, layer, waferU, waferV, cellU, cellV)); |
| 107 | + detIds_.emplace_back(id, pos); |
| 108 | + xwafer_.emplace_back(std::atof(items[8].c_str())); |
| 109 | + ywafer_.emplace_back(std::atof(items[9].c_str())); |
| 110 | + xcellOff_.emplace_back(std::atof(items[10].c_str())); |
| 111 | + ycellOff_.emplace_back(std::atof(items[11].c_str())); |
| 112 | + xcell_.emplace_back(std::atof(items[12].c_str())); |
| 113 | + ycell_.emplace_back(std::atof(items[13].c_str())); |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + fInput.close(); |
| 119 | + } |
| 120 | + } |
| 121 | + size = detIds_.size(); |
| 122 | + edm::LogVerbatim("HGCGeom") << "Reads " << detIds_.size() << " ID's from " << fileName_; |
| 123 | +} |
| 124 | + |
| 125 | +void HGCalTestDDDCons::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { |
| 126 | + std::vector<std::string> names = {"HGCalEESensitive", "HGCalHESiliconSensitive"}; |
| 127 | + edm::ParameterSetDescription desc; |
| 128 | + desc.add<std::vector<std::string>>("nameDetectors", names); |
| 129 | + desc.add<std::string>("fileName", "missD120.txt"); |
| 130 | + descriptions.add("hgcalTestDDDCons", desc); |
| 131 | +} |
| 132 | + |
| 133 | +// ------------ method called to produce the data ------------ |
| 134 | +void HGCalTestDDDCons::beginRun(edm::Run const &iRun, edm::EventSetup const &iSetup) { |
| 135 | + //initiating hgc Geometry |
| 136 | + std::vector<std::string> names = {"HGCalEESensitive", "HGCalHESiliconSensitive"}; |
| 137 | + std::vector<DetId::Detector> dets = {DetId::HGCalEE, DetId::HGCalHSi}; |
| 138 | + std::map<DetId::Detector, uint32_t> detMap; |
| 139 | + for (uint32_t i = 0; i < nameDetectors_.size(); i++) { |
| 140 | + edm::LogVerbatim("HGCGeom") << "Tries to initialize HGCalGeometry and HGCalDDDConstants for " << i << ":" |
| 141 | + << nameDetectors_[i]; |
| 142 | + const edm::ESHandle<HGCalDDDConstants> &hgcCons = iSetup.getHandle(tok_hgcal_[i]); |
| 143 | + if (hgcCons.isValid()) { |
| 144 | + hgcCons_.push_back(hgcCons.product()); |
| 145 | + } else { |
| 146 | + edm::LogWarning("HGCGeom") << "Cannot initiate HGCalDDDConstants for " << nameDetectors_[i] << std::endl; |
| 147 | + } |
| 148 | + auto ii = std::find(names.begin(), names.end(), nameDetectors_[i]); |
| 149 | + if (ii != names.end()) { |
| 150 | + uint32_t k = static_cast<uint32_t>(ii - names.begin()); |
| 151 | + detMap[dets[k]] = i; |
| 152 | + } |
| 153 | + } |
| 154 | + edm::LogVerbatim("HGCGeom") << "Loaded HGCalDDConstants for " << detMap.size() << " detectors"; |
| 155 | + |
| 156 | + for (auto itr = detMap.begin(); itr != detMap.end(); ++itr) |
| 157 | + edm::LogVerbatim("HGCGeom") << "[" << itr->second << "]: " << nameDetectors_[itr->second] << " for Detector " |
| 158 | + << itr->first; |
| 159 | + |
| 160 | + int cellU(0), cellV(0), waferType(-1), waferU(0), waferV(0); |
| 161 | + double wt(1.0); |
| 162 | + for (int k = 0; k < size; ++k) { |
| 163 | + const HGCalDDDConstants *cons = hgcCons_[detMap[(detIds_[k].first).det()]]; |
| 164 | + HGCSiliconDetId id(detIds_[k].first); |
| 165 | + auto hgpar_ = cons->getParameter(); |
| 166 | + HGCalCell celli(hgpar_->waferSize_, hgpar_->nCellsFine_, hgpar_->nCellsCoarse_); |
| 167 | + auto placement = cons->placementIndex(id); |
| 168 | + int ncell_ = id.lowDensity() ? hgpar_->nCellsCoarse_ : hgpar_->nCellsFine_; |
| 169 | + auto partialType = cons->partialWaferType(id.layer(), id.waferU(), id.waferV()); |
| 170 | + auto cellType = HGCalCell::cellType(id.cellU(), id.cellV(), ncell_, placement, partialType); |
| 171 | + auto waferxy = cons->waferPositionWithCshift(id.layer(), id.waferU(), id.waferV(), true, true, false); |
| 172 | + auto cellxy_cog = cons->locateCell(id, true, false); |
| 173 | + auto cellxy_ncog = cons->locateCell(id, false, false); |
| 174 | + waferU = id.waferU(); |
| 175 | + waferV = id.waferV(); |
| 176 | + double xx = id.zside() * xcell_[k]; |
| 177 | + cons->waferFromPosition( |
| 178 | + xx, ycell_[k], id.zside(), id.layer(), waferU, waferV, cellU, cellV, waferType, wt, false, false); |
| 179 | + auto valid = cons->isValidHex8(id.layer(), id.waferU(), id.waferV(), id.cellU(), id.cellV(), true); |
| 180 | + float scale = 0.1; |
| 181 | + edm::LogVerbatim("HGCGeom") << "Hit[" << k << "] " << id << " Valid " << valid |
| 182 | + << " zside:layer:waferU:waferV:cellU:cellV " << id.layer() << ":" << id.waferU() << ":" |
| 183 | + << id.waferV() << ":" << id.cellU() << ":" << id.cellV() |
| 184 | + << " Observed coordinates wafer:cellCOG:cell " << waferxy.first << "," << waferxy.second |
| 185 | + << ":" << cellxy_ncog.first << "," << cellxy_ncog.second << ":" << cellxy_cog.first |
| 186 | + << "," << cellxy_cog.second << " CellType:CellPosition " << cellType.second << ":" |
| 187 | + << cellType.first; |
| 188 | + if (std::sqrt(std::pow(waferxy.first + scale * xwafer_[k], 2) + std::pow(waferxy.second - scale * ywafer_[k], 2)) > |
| 189 | + 0.01) { |
| 190 | + edm::LogVerbatim("HGCGeom") << " Error wafer mismatch actual:observed (" << xwafer_[k] << "," << ywafer_[k] |
| 191 | + << "):(" << waferxy.first << "," << waferxy.second << ") "; |
| 192 | + } |
| 193 | + if (std::sqrt(std::pow(cellxy_ncog.first + scale * xcell_[k], 2) + |
| 194 | + std::pow(cellxy_ncog.second - scale * ycell_[k], 2)) > 0.01) { |
| 195 | + edm::LogVerbatim("HGCGeom") << " Error cell COG mismatch actual:observed (" << xcell_[k] << "," << ycell_[k] |
| 196 | + << "):(" << cellxy_ncog.first << "," << cellxy_ncog.second << ") "; |
| 197 | + } |
| 198 | + if (std::sqrt(std::pow(cellxy_cog.first + scale * xcellOff_[k], 2) + |
| 199 | + std::pow(cellxy_cog.second - scale * ycellOff_[k], 2)) > 0.01) { |
| 200 | + edm::LogVerbatim("HGCGeom") << " Error cell center mismatch actual:observed (" << xcellOff_[k] << "," |
| 201 | + << ycellOff_[k] << "):(" << cellxy_cog.first << "," << cellxy_cog.second << ") "; |
| 202 | + } |
| 203 | + } |
| 204 | +} |
| 205 | + |
| 206 | +// define this as a plug-in |
| 207 | +DEFINE_FWK_MODULE(HGCalTestDDDCons); |
0 commit comments