20 #include <boost/bind.hpp>
21 #include <boost/function.hpp>
25 FileInPath_(
"CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"),
26 SiStripDetCabling_(
NULL),
28 useEmptyRunInfo_(
false)
40 FileInPath_=other.FileInPath_;
42 toCleanUp=other.toCleanUp;
43 indexes=other.indexes;
44 v_badstrips=other.v_badstrips;
45 BadComponentVect=other.BadComponentVect;
46 SiStripDetCabling_=other.SiStripDetCabling_;
47 printDebug_=other.printDebug_;
48 useEmptyRunInfo_=other.useEmptyRunInfo_;
51 SiStripQuality::~SiStripQuality(){
52 LogTrace(
"SiStripQuality") <<
"SiStripQuality destructor" << std::endl;
61 this->fillBadComponents();
69 std::vector<unsigned int> ovect,vect;
71 unsigned short Nstrips;
76 Nstrips=
reader->getNumberOfApvsAndStripLength(detid).first*128;
82 if (range.first!=range.second){
89 if(orange.second-orange.first!=1
91 || data_.
range<Nstrips){
93 ovect.insert(ovect.end(),orange.first,orange.second);
94 vect.insert(vect.end(),range.first,range.second);
98 if ( ! put_replace(detid,newrange) )
99 edm::LogError(
"SiStripQuality")<<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
115 return a.getRegistryVectorBegin()==a.getRegistryVectorEnd();
122 std::vector<unsigned int> vect;
127 std::vector<uint32_t> vdets;
129 std::vector<uint32_t>::const_iterator
iter=vdets.begin();
130 std::vector<uint32_t>::const_iterator iterEnd=vdets.end();
132 for(;iter!=iterEnd;++
iter){
134 range = (short) (
reader->getNumberOfApvsAndStripLength(*iter).first*128.);
135 LogTrace(
"SiStripQuality") <<
"[add Voff] add detid " << *iter <<
" first strip " << firstStrip <<
" range " << range << std::endl;
136 vect.push_back(
encode(firstStrip,range));
144 bool allFedsEmpty = runInfo->
m_fed_in.empty();
146 std::stringstream
ss;
147 ss <<
"WARNING: the full list of feds in RunInfo is empty. ";
148 if( useEmptyRunInfo_ ) {
149 ss <<
" SiStripQuality will still use it and all tracker will be off." << std::endl;
152 ss <<
" SiStripQuality will not use it." << std::endl;
157 if( !allFedsEmpty || useEmptyRunInfo_ ) {
159 auto ids = SiStripDetCabling_->fedCabling()->fedIds();
161 std::vector<uint16_t> activeFedsFromCabling(ids.begin(), ids.end());
163 std::vector<int> activeFedsFromRunInfo;
165 std::remove_copy_if( runInfo->
m_fed_in.begin(),
167 std::back_inserter(activeFedsFromRunInfo),
168 !boost::bind(std::logical_and<bool>(),
176 std::sort(activeFedsFromCabling.begin(), activeFedsFromCabling.end());
177 std::sort(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end());
178 std::vector<int> differentFeds;
180 std::set_difference(activeFedsFromCabling.begin(), activeFedsFromCabling.end(),
181 activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(),
182 std::back_inserter(differentFeds));
190 turnOffFeds(differentFeds,
true, printDebug_);
194 std::vector<int>
check;
195 std::set_difference(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(),
196 activeFedsFromCabling.begin(), activeFedsFromCabling.end(),
197 std::back_inserter(check));
199 if( !check.empty() ) {
202 <<
"The cabling should always include the active feds in runInfo and possibly have some more"
203 <<
"there are instead " << check.size() <<
" feds only active in runInfo";
206 turnOffFeds(check,
false,
true);
213 SiStripDetCabling_=cab;
214 addInvalidConnectionFromCabling();
215 addNotConnectedConnectionFromCabling();
218 void SiStripQuality::addNotConnectedConnectionFromCabling()
220 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > allData =
reader->getAllData();
221 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator iter=allData.begin();
222 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator iterEnd=allData.end();
223 std::vector<unsigned int> vect;
226 for(;iter!=iterEnd;++
iter)
227 if (!SiStripDetCabling_->IsConnected(iter->first)){
229 range=iter->second.nApvs*128;
230 LogTrace(
"SiStripQuality") <<
"[addNotConnectedConnectionFromCabling] add detid " << iter->first << std::endl;
231 vect.push_back(
encode(firstStrip,range));
237 void SiStripQuality::addInvalidConnectionFromCabling()
239 std::vector<uint32_t> connected_detids;
240 SiStripDetCabling_->addActiveDetectorsRawIds(connected_detids);
241 std::vector<uint32_t>::const_iterator itdet = connected_detids.begin();
242 std::vector<uint32_t>::const_iterator itdetEnd = connected_detids.end();
243 for(;itdet!=itdetEnd;++itdet){
245 const std::vector<const FedChannelConnection *>& fedconns=SiStripDetCabling_->getConnections(*itdet);
246 std::vector<const FedChannelConnection *>::const_iterator itconns=fedconns.begin();
247 std::vector<const FedChannelConnection *>::const_iterator itconnsEnd=fedconns.end();
249 unsigned short nApvPairs=SiStripDetCabling_->nApvPairs(*itdet);
250 short ngoodConn=0, goodConn=0;
251 for(;itconns!=itconnsEnd;++itconns){
256 goodConn = goodConn | ( 0x1 << (*itconns)->apvPairNumber() );
259 if (ngoodConn!=nApvPairs){
260 std::vector<unsigned int> vect;
262 if( !(goodConn & ( 0x1 <<
idx)) ) {
263 short firstStrip=
idx*256;
265 LogTrace(
"SiStripQuality") <<
"[addInvalidConnectionFromCabling] add detid " <<*itdet <<
"firstStrip " << firstStrip<< std::endl;
266 vect.push_back(
encode(firstStrip,range));
285 uint32_t detid=basep->detid;
286 LogTrace(
"SiStripQuality") <<
"add detid " <<detid << std::endl;
290 add(detid,baserange);
296 std::vector<unsigned int> vect,
tmp;
298 unsigned short Nstrips=
reader->getNumberOfApvsAndStripLength(detid).first*128;
305 if (range.first==range.second){
306 LogTrace(
"SiStripQuality") <<
"new detid" << std::endl;
308 tmp.insert(tmp.end(),baserange.first,baserange.second);
309 std::stable_sort(tmp.begin(),tmp.end());
310 LogTrace(
"SiStripQuality") <<
"ordered" << std::endl;
312 LogTrace(
"SiStripQuality") <<
"already exists" << std::endl;
317 if(range.second-range.first==1
319 && data_.
range>=Nstrips){
320 LogTrace(
"SiStripQuality") <<
"full det is bad.. " << range.second-range.first <<
" " <<
decode(*(range.first)).firstStrip <<
" " <<
decode(*(range.first)).range <<
" " <<
decode(*(range.first)).flag <<
"\n"<< std::endl;
324 tmp.insert(tmp.end(),baserange.first,baserange.second);
325 tmp.insert(tmp.end(),range.first,range.second);
326 std::stable_sort(tmp.begin(),tmp.end());
327 LogTrace(
"SiStripQuality") <<
"ordered" << std::endl;
330 compact(tmp,vect,Nstrips);
332 if ( ! put_replace(detid,newrange) )
333 edm::LogError(
"SiStripQuality")<<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
336 void SiStripQuality::compact(
unsigned int& detid, std::vector<unsigned int>& vect)
338 std::vector<unsigned int> tmp=vect;
340 std::stable_sort(tmp.begin(),tmp.end());
341 unsigned short Nstrips=
reader->getNumberOfApvsAndStripLength(detid).first*128;
342 compact(tmp,vect,Nstrips);
350 size_t sd= input.second-input.first;
351 DetRegistry detregistry;
352 detregistry.detid=DetId;
353 detregistry.ibegin=v_badstrips.size();
354 detregistry.iend=v_badstrips.size()+
sd;
356 v_badstrips.insert(v_badstrips.end(),input.first,input.second);
358 if (p!=indexes.end() && p->detid==DetId){
359 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::put_replace] Replacing SiStripQuality for already stored DetID " << DetId << std::endl;
363 indexes.insert(p,detregistry);
380 uint16_t BadStripPerApv[6], ipos;
381 std::vector<unsigned int> vect;
383 for (; rp != rend; ++rp) {
384 uint32_t detid=rp->detid;
386 BadStripPerApv[0]=0; BadStripPerApv[1]=0; BadStripPerApv[2]=0; BadStripPerApv[3]=0; BadStripPerApv[4]=0; BadStripPerApv[5]=0;
391 for(
int it=0;it<sqrange.second-sqrange.first;it++){
393 data_=
decode( *(sqrange.first+it) );
394 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::ReduceGranularity] detid " << detid <<
" first strip " << data_.
firstStrip <<
" lastStrip " << data_.
firstStrip+data_.
range-1 <<
" range " << data_.
range;
403 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::ReduceGranularity] Total for detid " << detid <<
" values " << BadStripPerApv[0] <<
" " << BadStripPerApv[1] <<
" " << BadStripPerApv[2] <<
" " <<BadStripPerApv[3] <<
" " <<BadStripPerApv[4] <<
" " << BadStripPerApv[5];
407 for(
size_t i=0;
i<6;++
i){
408 if (BadStripPerApv[
i]>=threshold*128){
409 vect.push_back(
encode(
i*128,128));
420 void SiStripQuality::compact(std::vector<unsigned int>& tmp,std::vector<unsigned int>& vect,
unsigned short& Nstrips)
425 ContainerIterator it=tmp.begin();
435 for(;it!=tmp.end();++it){
461 ContainerIterator it=B.begin();
462 ContainerIterator itend=B.end();
463 for(;it!=itend;++it){
468 void SiStripQuality::subtraction(std::vector<unsigned int>& A,
const unsigned int& B)
471 std::vector<unsigned int>
tmp;
474 ContainerIterator jt=A.begin();
475 ContainerIterator jtend=A.end();
476 for(;jt!=jtend;++jt){
502 if (!toCleanUp && !force)
507 std::vector<unsigned int> v_badstrips_tmp=v_badstrips;
508 std::vector<DetRegistry> indexes_tmp=indexes;
510 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::cleanUp] before cleanUp v_badstrips.size()= " << v_badstrips.size() <<
" indexes.size()=" << indexes.size() << std::endl;
519 if(basep->ibegin!=basep->iend){
520 SiStripBadStrip::Range range( v_badstrips_tmp.begin()+basep->ibegin, v_badstrips_tmp.begin()+basep->iend );
521 if ( !
put(basep->detid,range) )
522 edm::LogError(
"SiStripQuality")<<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
526 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::cleanUp] after cleanUp v_badstrips.size()= " << v_badstrips.size() <<
" indexes.size()=" << indexes.size() << std::endl;
530 void SiStripQuality::fillBadComponents()
532 BadComponentVect.clear();
539 unsigned short resultA=0, resultF=0;
543 unsigned short Nstrips=
reader->getNumberOfApvsAndStripLength(basep->detid).first*128;
546 fs=
decode(*(range.first));
547 if (basep->iend - basep->ibegin == 1 &&
550 result.detid=basep->detid;
551 result.BadModule=
true;
552 result.BadFibers=(1<< (Nstrips/256))-1;
553 result.BadApvs=(1<< (Nstrips/128))-1;
555 BadComponentVect.push_back(result);
564 for(
short apvNb=0;apvNb<6;++apvNb){
566 resultA=resultA | (1<<apvNb);
570 for(
short fiberNb=0;fiberNb<3;++fiberNb){
572 resultF=resultF | (1<<fiberNb);
577 result.detid=basep->detid;
578 result.BadModule=
false;
579 result.BadFibers=resultF;
580 result.BadApvs=resultA;
581 BadComponentVect.push_back(result);
589 bool SiStripQuality::IsModuleUsable(
const uint32_t& detid)
const
591 std::vector<BadComponent>::const_iterator p = std::lower_bound(BadComponentVect.begin(),BadComponentVect.end(),
detid,SiStripQuality::BadComponentStrictWeakOrdering());
592 if (p!=BadComponentVect.end() && p->detid==
detid)
596 if (SiStripDetCabling_!=
NULL)
597 if(!SiStripDetCabling_->IsConnected(detid))
603 bool SiStripQuality::IsModuleBad(
const uint32_t& detid)
const
605 std::vector<BadComponent>::const_iterator p = std::lower_bound(BadComponentVect.begin(),BadComponentVect.end(),
detid,SiStripQuality::BadComponentStrictWeakOrdering());
606 if (p!=BadComponentVect.end() && p->detid==
detid)
611 bool SiStripQuality::IsFiberBad(
const uint32_t& detid,
const short& fiberNb)
const
613 std::vector<BadComponent>::const_iterator p = std::lower_bound(BadComponentVect.begin(),BadComponentVect.end(),
detid,SiStripQuality::BadComponentStrictWeakOrdering());
614 if (p!=BadComponentVect.end() && p->detid==
detid)
615 return ((p->BadFibers>>fiberNb)&0x1);
619 bool SiStripQuality::IsApvBad(
const uint32_t& detid,
const short& apvNb)
const
621 std::vector<BadComponent>::const_iterator p = std::lower_bound(BadComponentVect.begin(),BadComponentVect.end(),
detid,SiStripQuality::BadComponentStrictWeakOrdering());
622 if (p!=BadComponentVect.end() && p->detid==
detid)
623 return ((p->BadApvs>>apvNb)&0x1);
627 bool SiStripQuality::IsStripBad(
const uint32_t& detid,
const short& strip)
const
630 return IsStripBad(range,strip);
633 bool SiStripQuality::IsStripBad(
const Range& range,
const short& strip)
const
647 int SiStripQuality::nBadStripsOnTheLeft(
const Range& range,
const short& strip)
const
661 int SiStripQuality::nBadStripsOnTheRight(
const Range& range,
const short& strip)
const
675 short SiStripQuality::getBadApvs(
const uint32_t& detid)
const
677 std::vector<BadComponent>::const_iterator p = std::lower_bound(BadComponentVect.begin(),BadComponentVect.end(),
detid,SiStripQuality::BadComponentStrictWeakOrdering());
678 if (p!=BadComponentVect.end() && p->detid==
detid)
683 short SiStripQuality::getBadFibers(
const uint32_t& detid)
const
685 std::vector<BadComponent>::const_iterator p = std::lower_bound(BadComponentVect.begin(),BadComponentVect.end(),
detid,SiStripQuality::BadComponentStrictWeakOrdering());
686 if (p!=BadComponentVect.end() && p->detid==
detid)
691 void SiStripQuality::printDetInfo(
const uint32_t &detId,
const uint32_t &apvPairNumber, std::stringstream &ss)
697 switch (detid.subdetId()) {
700 TIBDetId theTIBDetId(detid.rawId());
701 layer = theTIBDetId.
layer();
702 stereo = theTIBDetId.stereo();
708 TOBDetId theTOBDetId(detid.rawId());
709 layer = theTOBDetId.
layer();
710 stereo = theTOBDetId.stereo();
716 TECDetId theTECDetId(detid.rawId());
718 layer = theTECDetId.
wheel();
719 stereo = theTECDetId.stereo();
725 TECDetId theTIDDetId(detid.rawId());
727 layer = theTIDDetId.
wheel();
728 stereo = theTIDDetId.stereo();
733 ss << detId <<
" and apv = " << apvPairNumber <<
" of subDet = " << subDetName <<
", layer = " << layer <<
" stereo = " << stereo << std::endl;
736 void SiStripQuality::printActiveFedsInfo(
const std::vector<uint16_t> & activeFedsFromCabling,
737 const std::vector<int> & activeFedsFromRunInfo,
738 const std::vector<int> & differentFeds,
741 std::ostringstream
ss;
744 ss <<
"activeFedsFromCabling:" << std::endl;
745 std::copy(activeFedsFromCabling.begin(), activeFedsFromCabling.end(), std::ostream_iterator<uint16_t>(
ss,
" "));
747 ss <<
"activeFedsFromRunInfo:" << std::endl;
748 std::copy(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(), std::ostream_iterator<int>(
ss,
" "));
751 if( differentFeds.size() != 440 ) {
752 ss <<
"differentFeds : " << std::endl;
753 std::copy(differentFeds.begin(), differentFeds.end(), std::ostream_iterator<int>(
ss,
" "));
757 ss <<
"There are 440 feds (all) active for Cabling but off for RunInfo. Tracker was probably not in this run" << std::endl;
759 edm::LogInfo(
"SiStripQuality") << ss.str() << std::endl;
762 void SiStripQuality::turnOffFeds(
const std::vector<int> & fedsList,
const bool turnOffStrips,
const bool printDebug)
765 std::stringstream
ss;
767 ss <<
"associated to detIds : " << std::endl;
770 std::vector<int>::const_iterator fedIdIt = fedsList.begin();
771 for( ; fedIdIt != fedsList.end(); ++fedIdIt ) {
772 std::vector<FedChannelConnection>::const_iterator fedChIt = SiStripDetCabling_->fedCabling()->fedConnections( *fedIdIt ).begin();
773 for( ; fedChIt != SiStripDetCabling_->fedCabling()->fedConnections( *fedIdIt ).end(); ++fedChIt ) {
774 uint32_t detId = fedChIt->detId();
775 if (detId == 0 || detId == 0xFFFFFFFF)
continue;
776 uint16_t apvPairNumber = fedChIt->apvPairNumber();
779 printDetInfo(detId, apvPairNumber, ss);
782 if( turnOffStrips ) {
784 std::vector<unsigned int> vect;
785 vect.push_back(
encode(apvPairNumber*256,256));
788 LogTrace(
"SiStripQuality") <<
"[addOffForRunInfo] adding apvPairNumber "<<apvPairNumber<<
" for detId "<<detId<<
" off according to RunInfo" << std::endl;
793 edm::LogInfo(
"SiStripQuality") << ss.str() << std::endl;
unsigned int layer() const
layer id
std::vector< unsigned int >::const_iterator ContainerIterator
MatrixMeschach operator-(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
Basic3DVector & operator-=(const Basic3DVector< U > &p)
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
Registry::const_iterator RegistryIterator
static std::string const input
void put(edm::Event &evt, double value, const char *instanceName)
RegistryIterator getRegistryVectorEnd() const
const T & max(const T &a, const T &b)
void getDetIds(std::vector< uint32_t > &DetIds_) const
std::vector< int > m_fed_in
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
bool decode(bool &, std::string const &)
std::pair< typename T::DetSet::const_iterator, typename T::DetSet::const_iterator > getRange(const T &detset, const DetId &id)
ContainerIterator getDataVectorBegin() const
tuple SiStripDetInfoFileReader
PixelRecoRange< float > Range
unsigned short firstStrip
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
static const uint16_t invalid_
unsigned int wheel() const
wheel id
void cleanUp(const std::string &connectionString, std::set< std::string > exclusionList=std::set< std::string >())
unsigned int layer() const
layer id
RegistryIterator getRegistryVectorBegin() const
std::vector< std::vector< double > > tmp
std::pair< ContainerIterator, ContainerIterator > Range
volatile std::atomic< bool > shutdown_flag false
Basic3DVector & operator+=(const Basic3DVector< U > &p)