CMS 3D CMS Logo

SiStripBadModuleConfigurableFakeESSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CalibTracker/SiStripESProducers
4 // Class: SiStripBadModuleConfigurableFakeESSource
5 //
14 // system include files
15 #include <memory>
16 
17 // user include files
20 
25 
27 public:
30 
32 
33  typedef std::unique_ptr<SiStripBadStrip> ReturnType;
34  ReturnType produce(const SiStripBadModuleRcd&);
35 
36 private:
37  using Parameters = std::vector<edm::ParameterSet>;
40 
41  std::vector<uint32_t> selectDetectors(const TrackerTopology* tTopo, const std::vector<uint32_t>& detIds) const;
42 };
43 
48 
50 {
51  setWhatProduced(this);
52  findingRecord<SiStripBadModuleRcd>();
53 
54  m_badComponentList = iConfig.getUntrackedParameter<Parameters>("BadComponentList");
55  m_printDebug = iConfig.getUntrackedParameter<bool>("printDebug", false);
56 }
57 
59 
61 {
62  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
63 }
64 
65 // ------------ method called to produce the data ------------
68 {
69  using namespace edm::es;
70 
72  iRecord.getRecord<TrackerTopologyRcd>().get(tTopo);
73 
74  auto quality = std::make_unique<SiStripQuality>();
75 
77  std::vector<uint32_t> selDetIds{selectDetectors(tTopo.product(), reader->getAllDetIds())};
78  edm::LogInfo("SiStripQualityConfigurableFakeESSource")<<"[produce] number of selected dets to be removed " << selDetIds.size() <<std::endl;
79 
80  std::stringstream ss;
81  for ( const auto selId : selDetIds ) {
82  SiStripQuality::InputVector theSiStripVector;
83 
84  unsigned short firstBadStrip{0};
85  unsigned short NconsecutiveBadStrips = reader->getNumberOfApvsAndStripLength(selId).first * 128;
86  unsigned int theBadStripRange{quality->encode(firstBadStrip,NconsecutiveBadStrips)};
87 
88  if (m_printDebug) {
89  ss << "detid " << selId << " \t"
90  << " firstBadStrip " << firstBadStrip << "\t "
91  << " NconsecutiveBadStrips " << NconsecutiveBadStrips << "\t "
92  << " packed integer " << std::hex << theBadStripRange << std::dec
93  << std::endl;
94  }
95 
96  theSiStripVector.push_back(theBadStripRange);
97 
98  if ( ! quality->put(selId,SiStripBadStrip::Range{theSiStripVector.begin(),theSiStripVector.end()}) ) {
99  edm::LogError("SiStripQualityConfigurableFakeESSource") << "[produce] detid already exists";
100  }
101  }
102  if (m_printDebug) {
103  edm::LogInfo("SiStripQualityConfigurableFakeESSource") << ss.str();
104  }
105  quality->cleanUp();
106  //quality->fillBadComponents();
107 
108  if (m_printDebug){
109  std::stringstream ss1;
110  for ( const auto& badComp : quality->getBadComponentList() ) {
111  ss1 << "bad module " << badComp.detid << " " << badComp.BadModule << "\n";
112  }
113  edm::LogInfo("SiStripQualityConfigurableFakeESSource") << ss1.str();
114  }
115 
116  return quality;
117 }
118 
119 namespace {
120  bool _isSel( uint32_t requested, uint32_t i )
121  { // internal helper: accept all i if requested is 0, otherwise require match
122  return ( requested == 0 ) || ( requested == i );
123  }
124 
125  SiStripDetId::SubDetector subDetFromString( const std::string& subDetStr )
126  {
128  if ( subDetStr=="TIB" ) subDet = SiStripDetId::TIB;
129  else if ( subDetStr=="TID" ) subDet = SiStripDetId::TID;
130  else if ( subDetStr=="TOB" ) subDet = SiStripDetId::TOB;
131  else if ( subDetStr=="TEC" ) subDet = SiStripDetId::TEC;
132  return subDet;
133  }
134 }
135 
136 std::vector<uint32_t> SiStripBadModuleConfigurableFakeESSource::selectDetectors(const TrackerTopology* tTopo, const std::vector<uint32_t>& detIds) const
137 {
138  std::vector<uint32_t> selList;
139  std::stringstream ss;
140  for ( const auto& badComp : m_badComponentList ) {
141  const std::string subDetStr{badComp.getParameter<std::string>("SubDet")};
142  if (m_printDebug) ss << "Bad SubDet " << subDetStr << " \t";
143  const SiStripDetId::SubDetector subDet = subDetFromString(subDetStr);
144 
145  const std::vector<uint32_t> genericBadDetIds{badComp.getUntrackedParameter<std::vector<uint32_t>>("detidList", std::vector<uint32_t>())};
146  const bool anySubDet{ ! genericBadDetIds.empty() };
147 
148  std::cout << "genericBadDetIds.size() = " << genericBadDetIds.size() << std::endl;
149 
150  using DetIdIt = std::vector<uint32_t>::const_iterator;
151  const DetIdIt beginDetIt = std::lower_bound(detIds.begin(), detIds.end(), DetId(DetId::Tracker, anySubDet ? SiStripDetId::TIB : subDet ).rawId());
152  const DetIdIt endDetIt = std::lower_bound(detIds.begin(), detIds.end(), DetId(DetId::Tracker, anySubDet ? SiStripDetId::TEC+1 : subDet+1).rawId());
153 
154  if ( anySubDet ) {
155  std::copy_if(beginDetIt, endDetIt, std::back_inserter(selList),
156  [&genericBadDetIds] ( uint32_t detId ) {
157  std::cout << "AnySubDet" << detId << std::endl;
158  return std::find(genericBadDetIds.begin(), genericBadDetIds.end(), detId) != genericBadDetIds.end();
159  });
160  } else {
161  switch (subDet) {
162  case SiStripDetId::TIB:
163  std::copy_if(beginDetIt, endDetIt, std::back_inserter(selList),
164  [tTopo,&badComp] ( uint32_t detectorId ) {
165  const DetId detId{detectorId};
166  return ( ( detId.subdetId() == SiStripDetId::TIB )
167  && _isSel(badComp.getParameter<uint32_t>("layer") , tTopo->tibLayer(detId))
168  && _isSel(badComp.getParameter<uint32_t>("bkw_frw"), tTopo->tibIsZPlusSide(detId) ? 2 : 1 )
169  && _isSel(badComp.getParameter<uint32_t>("int_ext"), tTopo->tibIsInternalString(detId) ? 1 : 2 )
170  && _isSel(badComp.getParameter<uint32_t>("ster") , tTopo->tibIsStereo(detId) ? 1 : ( tTopo->tibIsRPhi(detId) ? 2 : -1 ))
171  && _isSel(badComp.getParameter<uint32_t>("string_"), tTopo->tibString(detId))
172  && _isSel(badComp.getParameter<uint32_t>("detid") , detId.rawId())
173  );
174  } );
175  break;
176  case SiStripDetId::TID:
177  std::copy_if(beginDetIt, endDetIt, std::back_inserter(selList),
178  [tTopo,&badComp] ( uint32_t detectorId ) {
179  const DetId detId{detectorId};
180  return ( ( detId.subdetId() == SiStripDetId::TID )
181  && _isSel(badComp.getParameter<uint32_t>("wheel"), tTopo->tidWheel(detId))
182  && _isSel(badComp.getParameter<uint32_t>("side") , tTopo->tidIsZPlusSide(detId) ? 2 : 1 )
183  && _isSel(badComp.getParameter<uint32_t>("ster") , tTopo->tidIsStereo(detId) ? 1 : ( tTopo->tidIsRPhi(detId) ? 2 : -1 ) )
184  && _isSel(badComp.getParameter<uint32_t>("ring") , tTopo->tidRing(detId))
185  && _isSel(badComp.getParameter<uint32_t>("detid"), detId.rawId())
186  );
187  } );
188  break;
189  case SiStripDetId::TOB:
190  std::copy_if(beginDetIt, endDetIt, std::back_inserter(selList),
191  [tTopo,&badComp] ( uint32_t detectorId ) {
192  const DetId detId{detectorId};
193  return ( ( detId.subdetId() == SiStripDetId::TOB )
194  && _isSel(badComp.getParameter<uint32_t>("layer") , tTopo->tobLayer(detId))
195  && _isSel(badComp.getParameter<uint32_t>("bkw_frw"), tTopo->tobIsZPlusSide(detId) ? 2 : 1)
196  && _isSel(badComp.getParameter<uint32_t>("ster") , tTopo->tobIsStereo(detId) ? 1 : ( tTopo->tobIsRPhi(detId) ? 2 : -1 ))
197  && _isSel(badComp.getParameter<uint32_t>("rod") , tTopo->tobRod(detId))
198  && _isSel(badComp.getParameter<uint32_t>("detid") , detId.rawId())
199  );
200  } );
201  break;
202  case SiStripDetId::TEC:
203  std::copy_if(beginDetIt, endDetIt, std::back_inserter(selList),
204  [tTopo,&badComp] ( uint32_t detectorId ) {
205  const DetId detId{detectorId};
206  return ( ( detId.subdetId() == SiStripDetId::TEC )
207  && _isSel(badComp.getParameter<uint32_t>("wheel") , tTopo->tecWheel(detId))
208  && _isSel(badComp.getParameter<uint32_t>("side") , tTopo->tecIsZPlusSide(detId) ? 2 : 1 )
209  && _isSel(badComp.getParameter<uint32_t>("ster") , tTopo->tecIsStereo(detId) ? 1 : 2 )
210  && _isSel(badComp.getParameter<uint32_t>("petal_bkw_frw"), tTopo->tecIsFrontPetal(detId) ? 2 : 2)
211  && _isSel(badComp.getParameter<uint32_t>("petal") , tTopo->tecPetalNumber(detId))
212  && _isSel(badComp.getParameter<uint32_t>("ring") , tTopo->tecRing(detId))
213  && _isSel(badComp.getParameter<uint32_t>("detid") , detId.rawId())
214  );
215  } );
216  break;
217  default:
218  break;
219  }
220  }
221  }
222  if (m_printDebug) {
223  edm::LogInfo("SiStripBadModuleGenerator") << ss.str();
224  }
225  return selList;
226 }
227 
228 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
unsigned int tibLayer(const DetId &id) const
unsigned int tibString(const DetId &id) const
unsigned int tidRing(const DetId &id) const
bool tobIsStereo(const DetId &id) const
unsigned int tecRing(const DetId &id) const
ring id
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
unsigned int tidWheel(const DetId &id) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
bool tobIsRPhi(const DetId &id) const
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
bool tidIsStereo(const DetId &id) const
bool tibIsZPlusSide(const DetId &id) const
bool tecIsStereo(const DetId &id) const
bool tibIsRPhi(const DetId &id) const
static const IOVSyncValue & beginOfTime()
bool tobIsZPlusSide(const DetId &id) const
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &iov, edm::ValidityInterval &iValidity) override
bool tecIsFrontPetal(const DetId &id) const
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
Definition: DetId.h:18
bool tidIsRPhi(const DetId &id) const
bool tidIsZPlusSide(const DetId &id) const
std::vector< uint32_t > selectDetectors(const TrackerTopology *tTopo, const std::vector< uint32_t > &detIds) const
bool tibIsStereo(const DetId &id) const
bool tecIsZPlusSide(const DetId &id) const
std::pair< ContainerIterator, ContainerIterator > Range
unsigned int tecPetalNumber(const DetId &id) const
unsigned int tobRod(const DetId &id) const
bool tibIsInternalString(const DetId &id) const
unsigned int tecWheel(const DetId &id) const
T const * product() const
Definition: ESHandle.h:86
unsigned int tobLayer(const DetId &id) const
Container InputVector