40 #include "CLHEP/Random/RandFlat.h" 41 #include "CLHEP/Random/JamesRandom.h" 59 const std::vector<Phase2TrackerDigi::PackedDigiType>&
maskedChannels);
66 std::unique_ptr<CLHEP::HepRandomEngine>
engine_;
74 : engine_(new
CLHEP::HepJamesRandom(iConfig.getParameter<unsigned
int>(
"seed"))) {
84 <<
"[SiPhase2BadStripChannelBuilder::c'tor] the requested fraction of bad components is unphysical. \n";
87 findingRecord<SiPhase2OuterTrackerBadStripRcd>();
105 auto badStrips = std::make_unique<SiStripBadStrip>();
112 LogDebug(
"SiPhase2BadStripConfigurableFakeESSource")
113 <<
" There are " << tGeom.
detUnits().size() <<
" modules in this geometry.";
116 for (
auto const& det_u : tGeom.
detUnits()) {
117 const DetId detid = det_u->geographicalId();
128 const int nrows = topol.
nrows();
129 const int ncols = topol.ncolumns();
131 LogDebug(
"SiPhase2BadStripConfigurableFakeESSource")
132 <<
"DetId: " <<
rawId <<
" subdet: " << subid <<
" nrows: " << nrows <<
" ncols: " <<
ncols;
135 std::vector<Phase2TrackerDigi::PackedDigiType> usedChannels;
139 while (usedChannels.size() < nmaxBadStrips) {
140 unsigned short badStripRow = std::floor(CLHEP::RandFlat::shoot(
engine_.get(), 0, nrows));
141 unsigned short badStripCol = std::floor(CLHEP::RandFlat::shoot(
engine_.get(), 0,
ncols));
143 if (
std::find(usedChannels.begin(), usedChannels.end(), badChannel) == usedChannels.end()) {
144 usedChannels.push_back(badChannel);
152 LogDebug(
"SiPhase2BadStripConfigurableFakeESSource")
154 <<
" masking " << nmaxBadStrips <<
" strips, used channels size: " << usedChannels.size()
155 <<
", clusters size: " << badChannelsGroups.size();
157 std::vector<unsigned int> theSiStripVector;
160 for (
const auto& [
first, consec] : badChannelsGroups) {
161 unsigned int theBadChannelsRange;
162 theBadChannelsRange = badStrips->encodePhase2(
first, consec);
165 edm::LogInfo(
"SiPhase2BadStripConfigurableFakeESSource")
166 <<
"detid " <<
rawId <<
" \t" 167 <<
" firstBadStrip " <<
first <<
"\t " 168 <<
" NconsecutiveBadStrips " << consec <<
"\t " 169 <<
" packed integer " << std::hex << theBadChannelsRange <<
std::dec;
171 theSiStripVector.push_back(theBadChannelsRange);
177 <<
"[SiPhase2BadStripConfigurableFakeESSource::produce] detid already exists";
186 LogDebug(
"SiPhase2BadStripConfigurableFakeESSource") <<
"end of the detId loops";
193 const std::vector<Phase2TrackerDigi::PackedDigiType>&
maskedChannels) {
195 std::map<unsigned short, unsigned short>
result{};
196 std::map<int, std::string> printresult{};
202 auto startOfSequence =
data.begin();
205 while (startOfSequence !=
data.end()) {
208 std::adjacent_find(startOfSequence,
data.end(), [](
const auto& v1,
const auto& v2) {
return v2 != v1 + 1; });
209 if (endOfSequence !=
data.end())
210 std::advance(endOfSequence, 1);
212 auto consecutiveStrips =
std::distance(startOfSequence, endOfSequence);
213 result[*startOfSequence] = consecutiveStrips;
217 std::ostringstream oss{};
218 bool writeDash =
false;
219 for (
auto it = startOfSequence; it != endOfSequence; ++it) {
225 for (
auto it = startOfSequence; it != endOfSequence; ++it)
226 printresult[*it] = oss.str();
230 startOfSequence = endOfSequence;
235 for (
const auto& [
value,
text] : printresult)
236 LogDebug(
"SiPhase2BadStripConfigurableFakeESSource")
237 << std::left << std::setw(2) <<
value <<
" -> " <<
text <<
"\n";
244 desc.setComment(
"Configurable Fake Phase-2 Outer Tracker Bad Strip ESSource");
245 desc.add<
unsigned int>(
"seed", 1)->setComment(
"random seed");
246 desc.addUntracked<
bool>(
"printDebug",
false)->setComment(
"maximum amount of print-outs");
247 desc.add<
double>(
"badComponentsFraction", 0.01)->setComment(
"fraction of bad components to populate the ES");
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
SiPhase2BadStripConfigurableFakeESSource(const edm::ParameterSet &)
uint32_t cc[maxCellsPerHit]
static const IOVSyncValue & endOfTime()
virtual int nrows() const =0
std::unique_ptr< CLHEP::HepRandomEngine > engine_
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
constexpr Detector det() const
get the detector field from this detid
static std::string to_string(const XMLCh *ch)
T getUntrackedParameter(std::string const &, T const &) const
std::map< unsigned short, unsigned short > clusterizeBadChannels(const std::vector< Phase2TrackerDigi::PackedDigiType > &maskedChannels)
static const IOVSyncValue & beginOfTime()
ModuleType getDetectorType(DetId) const
static PackedDigiType pixelToChannel(unsigned int row, unsigned int col)
~SiPhase2BadStripConfigurableFakeESSource() override=default
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
static constexpr auto TOB
Log< level::Info, false > LogInfo
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &iov, edm::ValidityInterval &iValidity) override
constexpr uint32_t rawId() const
get the raw id
std::unique_ptr< SiStripBadStrip > ReturnType
float badComponentsFraction_
ReturnType produce(const SiPhase2OuterTrackerBadStripRcd &)
static void fillDescriptions(edm::ConfigurationDescriptions &)
char data[epos_bytes_allocation]
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackTopoToken_
std::pair< ContainerIterator, ContainerIterator > Range
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
static constexpr auto TID