27 #include "CLHEP/Random/RandFlat.h" 28 #include "CLHEP/Random/RandGauss.h" 45 std::unique_ptr<SiStripBadStrip>
getNewObject()
override;
62 const std::vector<Phase2TrackerDigi::PackedDigiType>&
maskedChannels);
65 std::unique_ptr<TrackerTopology>
tTopo_;
66 std::unique_ptr<TrackerGeometry>
tGeom_;
82 printdebug_(iConfig.getUntrackedParameter<
bool>(
"printDebug",
false)),
83 popConAlgo_(iConfig.getParameter<unsigned
int>(
"popConAlgo")),
84 badComponentsFraction_(iConfig.getParameter<double>(
"badComponentsFraction")) {
87 <<
"[SiPhase2BadStripChannelBuilder::c'tor] the requested fraction of bad components is unphysical. \n";
95 edm::LogInfo(
"SiPhase2BadStripChannelBuilder") <<
"... creating dummy SiStripBadStrip Data" << std::endl;
97 auto obj = std::make_unique<SiStripBadStrip>();
105 <<
" There are " <<
tGeom_->detUnits().size() <<
" modules in this geometry." << std::endl;
107 for (
auto const& det_u :
tGeom_->detUnits()) {
108 const DetId detid = det_u->geographicalId();
109 uint32_t rawId = detid.
rawId();
114 LogDebug(
"SiPhase2BadStripChannelBuilder") << rawId <<
" is a " << subid <<
" det" << std::endl;
120 const int nrows = topol.
nrows();
121 const int ncols = topol.ncolumns();
123 LogDebug(
"SiPhase2BadStripChannelBuilder")
124 <<
"DetId: " << rawId <<
" subdet: " << subid <<
" nrows: " << nrows <<
" ncols: " <<
ncols << std::endl;
126 std::vector<unsigned int> theSiStripVector;
130 LogDebug(
"SiPhase2BadStripChannelBuilder") <<
"using the NAIVE algorithm" << std::endl;
132 unsigned short firstBadStrip = std::floor(CLHEP::RandFlat::shoot(
engine_, 0, nrows));
133 unsigned short NconsecutiveBadStrips = std::floor(CLHEP::RandFlat::shoot(
engine_, 1, 10));
136 if (firstBadStrip + NconsecutiveBadStrips > nrows) {
137 NconsecutiveBadStrips = nrows - firstBadStrip;
140 unsigned int theBadStripRange;
141 theBadStripRange =
obj->encodePhase2(firstBadStrip, NconsecutiveBadStrips);
145 <<
"detid " << rawId <<
" \t" 146 <<
" firstBadStrip " << firstBadStrip <<
"\t " 147 <<
" NconsecutiveBadStrips " << NconsecutiveBadStrips <<
"\t " 148 <<
" packed integer " << std::hex << theBadStripRange <<
std::dec << std::endl;
150 theSiStripVector.push_back(theBadStripRange);
154 LogDebug(
"SiPhase2BadStripChannelBuilder") <<
"using the RANDOM algorithm" << std::endl;
157 std::vector<Phase2TrackerDigi::PackedDigiType> usedChannels;
161 LogDebug(
"SiPhase2BadStripChannelBuilder")
162 << __FUNCTION__ <<
" " << __LINE__ <<
" will mask: " << nmaxBadStrips <<
" strips" << std::endl;
164 while (usedChannels.size() < nmaxBadStrips) {
165 unsigned short badStripRow = std::floor(CLHEP::RandFlat::shoot(
engine_, 0, nrows));
166 unsigned short badStripCol = std::floor(CLHEP::RandFlat::shoot(
engine_, 0,
ncols));
169 LogDebug(
"SiPhase2BadStripChannelBuilder")
170 << __FUNCTION__ <<
" " << __LINE__ <<
": masking channel " << badChannel <<
" (" << badStripRow
171 <<
"," << badStripCol <<
")" << std::endl;
173 if (
std::find(usedChannels.begin(), usedChannels.end(), badChannel) == usedChannels.end()) {
174 usedChannels.push_back(badChannel);
180 for (
const auto& [
first, consec] : badChannelsGroups) {
181 unsigned int theBadChannelsRange;
182 theBadChannelsRange =
obj->encodePhase2(
first, consec);
186 <<
"detid " << rawId <<
" \t" 187 <<
" firstBadStrip " <<
first <<
"\t " 188 <<
" NconsecutiveBadStrips " << consec <<
"\t " 189 <<
" packed integer " << std::hex << theBadChannelsRange <<
std::dec << std::endl;
191 theSiStripVector.push_back(theBadChannelsRange);
198 throw cms::Exception(
"Inconsistent configuration") <<
"Did not specifiy the right algorithm to be run";
204 <<
"[SiPhase2BadStripChannelBuilder::getNewObject] detid already exists" << std::endl;
221 edm::LogError(
"SiPhase2BadStripChannelBuilder") <<
"Service is unavailable" << std::endl;
230 const std::vector<Phase2TrackerDigi::PackedDigiType>&
maskedChannels) {
232 std::map<unsigned short, unsigned short>
result{};
233 std::map<int, std::string> printresult{};
239 auto startOfSequence =
data.begin();
242 while (startOfSequence !=
data.end()) {
245 std::adjacent_find(startOfSequence,
data.end(), [](
const auto& v1,
const auto& v2) {
return v2 != v1 + 1; });
246 if (endOfSequence !=
data.end())
247 std::advance(endOfSequence, 1);
249 auto consecutiveStrips =
std::distance(startOfSequence, endOfSequence);
250 result[*startOfSequence] = consecutiveStrips;
254 std::ostringstream oss{};
255 bool writeDash =
false;
256 for (
auto it = startOfSequence; it != endOfSequence; ++it) {
262 for (
auto it = startOfSequence; it != endOfSequence; ++it)
263 printresult[*it] = oss.str();
267 startOfSequence = endOfSequence;
272 for (
const auto& [
value,
text] : printresult)
273 edm::LogInfo(
"SiPhase2BadStripChannelBuilder") << std::left << std::setw(2) <<
value <<
" -> " <<
text <<
"\n";
282 desc.setComment(
"Module to build SiStripBadStrip Payloads for the Phase-2 Outer Tracker");
284 desc.addUntracked<
bool>(
"printDebug",
false)->setComment(
"maximum amount of print-outs");
285 desc.add<
unsigned int>(
"popConAlgo", 1)->setComment(
"algorithm to populate the payload: 1=NAIVE,2=RANDOM");
286 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
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
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)
CLHEP::HepRandomEngine * engine_
std::unique_ptr< TrackerGeometry > tGeom_
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]
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
std::pair< ContainerIterator, ContainerIterator > Range
const float badComponentsFraction_
badChannelAlgo theBCAlgo_
static constexpr auto TID
SiPhase2BadStripChannelBuilder(const edm::ParameterSet &)
const unsigned int popConAlgo_