46 std::unique_ptr<SiStripBadStrip>
getNewObject()
override;
54 <<
" There are " << tkGeom_->detUnits().size() <<
" modules in this geometry.";
56 for (
auto const& det_u : tkGeom_->detUnits()) {
57 const DetId detid = det_u->geographicalId();
63 LogDebug(
"SiPhase2BadStripChannelBuilder") <<
rawId <<
" is a " << subid <<
" det";
79 engine_.seed(
event.id().event() + (
event.id().luminosityBlock() << 10) + (
event.id().run() << 20));
83 const std::vector<Phase2TrackerDigi::PackedDigiType>&
maskedChannels);
86 std::unique_ptr<TrackerTopology>
tTopo_;
96 std::vector<const Phase2TrackerGeomDetUnit*>
theOTDets;
104 printdebug_(iConfig.getUntrackedParameter<
bool>(
"printDebug",
false)),
105 popConAlgo_(iConfig.getParameter<unsigned
int>(
"popConAlgo")),
106 badComponentsFraction_(iConfig.getParameter<double>(
"badComponentsFraction")) {
109 <<
"[SiPhase2BadStripChannelBuilder::c'tor] the requested fraction of bad components is unphysical. \n";
116 edm::LogInfo(
"SiPhase2BadStripChannelBuilder") <<
"... creating dummy SiStripBadStrip Data";
118 auto obj = std::make_unique<SiStripBadStrip>();
126 uint32_t
rawId = pixdet->geographicalId().rawId();
127 int subid = pixdet->geographicalId().subdetId();
131 const int nrows = topol.
nrows();
132 const int ncols = topol.ncolumns();
134 LogDebug(
"SiPhase2BadStripChannelBuilder")
135 <<
"DetId: " <<
rawId <<
" subdet: " << subid <<
" nrows: " << nrows <<
" ncols: " <<
ncols;
137 std::vector<unsigned int> theSiStripVector;
141 LogDebug(
"SiPhase2BadStripChannelBuilder") <<
"using the NAIVE algorithm";
143 auto dis1 = std::uniform_int_distribution<>(0, nrows - 1);
144 auto dis2 = std::uniform_int_distribution<>(1, 10);
146 unsigned short firstBadStrip = std::floor(dis1(
engine_));
147 unsigned short NconsecutiveBadStrips = std::floor(dis2(
engine_));
150 if (firstBadStrip + NconsecutiveBadStrips > nrows) {
151 NconsecutiveBadStrips = nrows - firstBadStrip;
154 unsigned int theBadStripRange;
155 theBadStripRange =
obj->encodePhase2(firstBadStrip, NconsecutiveBadStrips);
159 <<
"detid " <<
rawId <<
" \t" 160 <<
" firstBadStrip " << firstBadStrip <<
"\t " 161 <<
" NconsecutiveBadStrips " << NconsecutiveBadStrips <<
"\t " 162 <<
" packed integer " << std::hex << theBadStripRange <<
std::dec;
164 theSiStripVector.push_back(theBadStripRange);
168 LogDebug(
"SiPhase2BadStripChannelBuilder") <<
"using the RANDOM algorithm";
171 std::vector<Phase2TrackerDigi::PackedDigiType> usedChannels;
175 LogDebug(
"SiPhase2BadStripChannelBuilder")
176 << __FUNCTION__ <<
" " << __LINE__ <<
" will mask: " << nmaxBadStrips <<
" strips";
178 auto disRows = std::uniform_int_distribution<>(0, nrows - 1);
179 auto disCols = std::uniform_int_distribution<>(0,
ncols - 1);
181 while (usedChannels.size() < nmaxBadStrips) {
182 unsigned short badStripRow = std::floor(disRows(
engine_));
183 unsigned short badStripCol = std::floor(disCols(
engine_));
187 LogDebug(
"SiPhase2BadStripChannelBuilder") << __FUNCTION__ <<
" " << __LINE__ <<
": masking channel " 188 << badChannel <<
" (" << badStripRow <<
"," << badStripCol <<
")";
190 if (
std::find(usedChannels.begin(), usedChannels.end(), badChannel) == usedChannels.end()) {
191 usedChannels.push_back(badChannel);
197 for (
const auto& [
first, consec] : badChannelsGroups) {
198 unsigned int theBadChannelsRange;
199 theBadChannelsRange =
obj->encodePhase2(
first, consec);
203 <<
"detid " <<
rawId <<
" \t" 204 <<
" firstBadStrip " <<
first <<
"\t " 205 <<
" NconsecutiveBadStrips " << consec <<
"\t " 206 <<
" packed integer " << std::hex << theBadChannelsRange <<
std::dec;
208 theSiStripVector.push_back(theBadChannelsRange);
215 throw cms::Exception(
"Inconsistent configuration") <<
"Did not specifiy the right algorithm to be run";
221 <<
"[SiPhase2BadStripChannelBuilder::getNewObject] detid already exists";
235 edm::LogError(
"SiPhase2BadStripChannelBuilder") <<
"Service is unavailable";
243 const std::vector<Phase2TrackerDigi::PackedDigiType>&
maskedChannels) {
245 std::map<unsigned short, unsigned short>
result{};
246 std::map<int, std::string> printresult{};
252 auto startOfSequence =
data.begin();
255 while (startOfSequence !=
data.end()) {
258 std::adjacent_find(startOfSequence,
data.end(), [](
const auto& v1,
const auto& v2) {
return v2 != v1 + 1; });
259 if (endOfSequence !=
data.end())
260 std::advance(endOfSequence, 1);
262 auto consecutiveStrips =
std::distance(startOfSequence, endOfSequence);
263 result[*startOfSequence] = consecutiveStrips;
267 std::ostringstream oss{};
268 bool writeDash =
false;
269 for (
auto it = startOfSequence;
it != endOfSequence; ++
it) {
275 for (
auto it = startOfSequence;
it != endOfSequence; ++
it)
276 printresult[*
it] = oss.str();
280 startOfSequence = endOfSequence;
285 for (
const auto& [
value,
text] : printresult)
286 edm::LogInfo(
"SiPhase2BadStripChannelBuilder") << std::left << std::setw(2) <<
value <<
" -> " <<
text <<
"\n";
295 desc.setComment(
"Module to build SiStripBadStrip Payloads for the Phase-2 Outer Tracker");
297 desc.addUntracked<
bool>(
"printDebug",
false)->setComment(
"maximum amount of print-outs");
298 desc.add<
unsigned int>(
"popConAlgo", 1)->setComment(
"algorithm to populate the payload: 1=NAIVE,2=RANDOM");
299 desc.add<
double>(
"badComponentsFraction", 0.01)->setComment(
"fraction of bad components to populate the payload");
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
void algoBeginRun(const edm::Run &run, const edm::EventSetup &es) override
void algoAnalyze(const edm::Event &event, const edm::EventSetup &es) override
cond::Time_t beginOfTime() const
virtual int nrows() const =0
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
Log< level::Error, false > LogError
~SiPhase2BadStripChannelBuilder() override=default
std::vector< const Phase2TrackerGeomDetUnit * > theOTDets
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
constexpr Detector det() const
get the detector field from this detid
static std::string to_string(const XMLCh *ch)
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
static void fillPSetDescription(edm::ParameterSetDescription &desc)
std::unique_ptr< TrackerTopology > tTopo_
bool isNewTagRequest(const std::string &recordName)
cond::Time_t currentTime() const
static PackedDigiType pixelToChannel(unsigned int row, unsigned int col)
#define DEFINE_FWK_MODULE(type)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
static constexpr auto TOB
std::unique_ptr< SiStripBadStrip > getNewObject() override
Log< level::Info, false > LogInfo
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
std::map< unsigned short, unsigned short > clusterizeBadChannels(const std::vector< Phase2TrackerDigi::PackedDigiType > &maskedChannels)
constexpr uint32_t rawId() const
get the raw id
char data[epos_bytes_allocation]
std::pair< ContainerIterator, ContainerIterator > Range
const float badComponentsFraction_
badChannelAlgo theBCAlgo_
static constexpr auto TID
SiPhase2BadStripChannelBuilder(const edm::ParameterSet &)
const unsigned int popConAlgo_