CMS 3D CMS Logo

SiStripQualityStatistics.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripQualityStatistics
4 // Class: SiStripQualityStatistics
5 //
13 //
14 // Original Author: Domenico GIORDANO
15 // Created: Wed Oct 3 12:11:10 CEST 2007
16 //
17 //
19 
21 
24 
25 #include <iostream>
26 #include <iomanip>
27 #include <cstdio>
28 #include <sys/time.h>
29 
30 
32  m_cacheID_(0),
33  dataLabel_(iConfig.getUntrackedParameter<std::string>("dataLabel","")),
34  TkMapFileName_(iConfig.getUntrackedParameter<std::string>("TkMapFileName","")),
35  fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"))),
36  saveTkHistoMap_(iConfig.getUntrackedParameter<bool>("SaveTkHistoMap",true)),
37  tkMap(nullptr),tkMapFullIOVs(nullptr)
38 {
40 
41  tkMapFullIOVs=new TrackerMap( "BadComponents" );
42  tkhisto=nullptr;
43 }
44 
46 
48  if (filename!=""){
49  tkMapFullIOVs->save(false,0,0,filename);
50  filename.erase(filename.begin()+filename.find("."),filename.end());
51  tkMapFullIOVs->print(false,0,0,filename);
52 
53  if(saveTkHistoMap_){
54  tkhisto->save(filename+".root");
55  tkhisto->saveAsCanvas(filename+"_Canvas.root","E");
56  }
57  }
58 }
59 
61  //Retrieve tracker topology from geometry
63  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
64  const TrackerTopology* const tTopo = tTopoHandle.product();
65  if ( ( ! tkhisto ) && ( ! TkMapFileName_.empty() ) ) {
66  edm::ESHandle<TkDetMap> tkDetMapHandle;
67  iSetup.get<TrackerTopologyRcd>().get(tkDetMapHandle);
68  //here the baseline (the value of the empty,not assigned bins) is put to -1 (default is zero)
69  tkhisto = std::make_unique<TkHistoMap>(tkDetMapHandle.product(), "BadComp","BadComp",-1.);
70  }
71 
72  unsigned long long cacheID = iSetup.get<SiStripQualityRcd>().cacheIdentifier();
73 
74  std::stringstream ss;
75 
76  if (m_cacheID_ == cacheID)
77  return;
78 
79  m_cacheID_ = cacheID;
80 
81  edm::ESHandle<SiStripQuality> SiStripQuality_;
82  iSetup.get<SiStripQualityRcd>().get(dataLabel_,SiStripQuality_);
83 
84  for(int i=0;i<4;++i){
85  NTkBadComponent[i]=0;
86  for(int j=0;j<19;++j){
87  ssV[i][j].str("");
88  for(int k=0;k<4;++k)
89  NBadComponent[i][j][k]=0;
90  }
91  }
92 
93  if (tkMap)
94  delete tkMap;
95  tkMap=new TrackerMap( "BadComponents" );
96 
97 
98  ss.str("");
99  std::vector<uint32_t> detids=reader->getAllDetIds();
100  std::vector<uint32_t>::const_iterator idet=detids.begin();
101  for(;idet!=detids.end();++idet){
102  ss << "detid " << (*idet) << " IsModuleUsable " << SiStripQuality_->IsModuleUsable((*idet)) << "\n";
103  if (SiStripQuality_->IsModuleUsable((*idet)))
104  tkMap->fillc(*idet,0x00ff00);
105  }
106  LogDebug("SiStripQualityStatistics") << ss.str() << std::endl;
107 
108 
109  std::vector<SiStripQuality::BadComponent> BC = SiStripQuality_->getBadComponentList();
110 
111  for (size_t i=0;i<BC.size();++i){
112 
113  //&&&&&&&&&&&&&
114  //Full Tk
115  //&&&&&&&&&&&&&
116 
117  if (BC[i].BadModule)
118  NTkBadComponent[0]++;
119  if (BC[i].BadFibers)
120  NTkBadComponent[1]+= ( (BC[i].BadFibers>>2)&0x1 )+ ( (BC[i].BadFibers>>1)&0x1 ) + ( (BC[i].BadFibers)&0x1 );
121  if (BC[i].BadApvs)
122  NTkBadComponent[2]+= ( (BC[i].BadApvs>>5)&0x1 )+ ( (BC[i].BadApvs>>4)&0x1 ) + ( (BC[i].BadApvs>>3)&0x1 ) +
123  ( (BC[i].BadApvs>>2)&0x1 )+ ( (BC[i].BadApvs>>1)&0x1 ) + ( (BC[i].BadApvs)&0x1 );
124 
125  //&&&&&&&&&&&&&&&&&
126  //Single SubSyste
127  //&&&&&&&&&&&&&&&&&
128  int component;
129  DetId detectorId=DetId(BC[i].detid);
130  int subDet = detectorId.subdetId();
131  if ( subDet == StripSubdetector::TIB ){
132  //&&&&&&&&&&&&&&&&&
133  //TIB
134  //&&&&&&&&&&&&&&&&&
135 
136  component=tTopo->tibLayer(BC[i].detid);
137  SetBadComponents(0, component, BC[i]);
138 
139  } else if ( subDet == StripSubdetector::TID ) {
140  //&&&&&&&&&&&&&&&&&
141  //TID
142  //&&&&&&&&&&&&&&&&&
143 
144  component=tTopo->tidSide(BC[i].detid)==2?tTopo->tidWheel(BC[i].detid):tTopo->tidWheel(BC[i].detid)+3;
145  SetBadComponents(1, component, BC[i]);
146 
147  } else if ( subDet == StripSubdetector::TOB ) {
148  //&&&&&&&&&&&&&&&&&
149  //TOB
150  //&&&&&&&&&&&&&&&&&
151 
152  component=tTopo->tobLayer(BC[i].detid);
153  SetBadComponents(2, component, BC[i]);
154 
155  } else if ( subDet == StripSubdetector::TEC ) {
156  //&&&&&&&&&&&&&&&&&
157  //TEC
158  //&&&&&&&&&&&&&&&&&
159 
160  component=tTopo->tecSide(BC[i].detid)==2?tTopo->tecWheel(BC[i].detid):tTopo->tecWheel(BC[i].detid)+9;
161  SetBadComponents(3, component, BC[i]);
162 
163  }
164  }
165 
166  //&&&&&&&&&&&&&&&&&&
167  // Single Strip Info
168  //&&&&&&&&&&&&&&&&&&
169  float percentage=0;
170 
171  SiStripQuality::RegistryIterator rbegin = SiStripQuality_->getRegistryVectorBegin();
172  SiStripQuality::RegistryIterator rend = SiStripQuality_->getRegistryVectorEnd();
173 
174  for (SiStripBadStrip::RegistryIterator rp=rbegin; rp != rend; ++rp) {
175  uint32_t detid=rp->detid;
176 
177  int subdet=-999; int component=-999;
178  DetId detectorId=DetId(detid);
179  int subDet = detectorId.subdetId();
180  if ( subDet == StripSubdetector::TIB ){
181  subdet=0;
182  component=tTopo->tibLayer(detid);
183  } else if ( subDet == StripSubdetector::TID ) {
184  subdet=1;
185  component=tTopo->tidSide(detid)==2?tTopo->tidWheel(detid):tTopo->tidWheel(detid)+3;
186  } else if ( subDet == StripSubdetector::TOB ) {
187  subdet=2;
188  component=tTopo->tobLayer(detid);
189  } else if ( subDet == StripSubdetector::TEC ) {
190  subdet=3;
191  component=tTopo->tecSide(detid)==2?tTopo->tecWheel(detid):tTopo->tecWheel(detid)+9;
192  }
193 
194  SiStripQuality::Range sqrange = SiStripQuality::Range( SiStripQuality_->getDataVectorBegin()+rp->ibegin , SiStripQuality_->getDataVectorBegin()+rp->iend );
195 
196  percentage=0;
197  for(int it=0;it<sqrange.second-sqrange.first;it++){
198  unsigned int range=SiStripQuality_->decode( *(sqrange.first+it) ).range;
199  NTkBadComponent[3]+=range;
200  NBadComponent[subdet][0][3]+=range;
201  NBadComponent[subdet][component][3]+=range;
202  percentage+=range;
203  }
204  if(percentage!=0)
205  percentage/=128.*reader->getNumberOfApvsAndStripLength(detid).first;
206  if(percentage>1)
207  edm::LogError("SiStripQualityStatistics") << "PROBLEM detid " << detid << " value " << percentage<< std::endl;
208 
209  //------- Global Statistics on percentage of bad components along the IOVs ------//
210  tkMapFullIOVs->fill(detid,percentage);
211  if(tkhisto!=nullptr)
212  tkhisto->fill(detid,percentage);
213  }
214 
215 
216  //&&&&&&&&&&&&&&&&&&
217  // printout
218  //&&&&&&&&&&&&&&&&&&
219 
220  ss.str("");
221  ss << "\n-----------------\nNew IOV starting from run " << e.id().run() << " event " << e.id().event() << " lumiBlock " << e.luminosityBlock() << " time " << e.time().value() << " chacheID " << m_cacheID_ << "\n-----------------\n";
222  ss << "\n-----------------\nGlobal Info\n-----------------";
223  ss << "\nBadComponent \t Modules \tFibers \tApvs\tStrips\n----------------------------------------------------------------";
224  ss << "\nTracker:\t\t"<<NTkBadComponent[0]<<"\t"<<NTkBadComponent[1]<<"\t"<<NTkBadComponent[2]<<"\t"<<NTkBadComponent[3];
225  ss<< "\n";
226  ss << "\nTIB:\t\t\t"<<NBadComponent[0][0][0]<<"\t"<<NBadComponent[0][0][1]<<"\t"<<NBadComponent[0][0][2]<<"\t"<<NBadComponent[0][0][3];
227  ss << "\nTID:\t\t\t"<<NBadComponent[1][0][0]<<"\t"<<NBadComponent[1][0][1]<<"\t"<<NBadComponent[1][0][2]<<"\t"<<NBadComponent[1][0][3];
228  ss << "\nTOB:\t\t\t"<<NBadComponent[2][0][0]<<"\t"<<NBadComponent[2][0][1]<<"\t"<<NBadComponent[2][0][2]<<"\t"<<NBadComponent[2][0][3];
229  ss << "\nTEC:\t\t\t"<<NBadComponent[3][0][0]<<"\t"<<NBadComponent[3][0][1]<<"\t"<<NBadComponent[3][0][2]<<"\t"<<NBadComponent[3][0][3];
230  ss << "\n";
231 
232  for (int i=1;i<5;++i)
233  ss << "\nTIB Layer " << i << " :\t\t"<<NBadComponent[0][i][0]<<"\t"<<NBadComponent[0][i][1]<<"\t"<<NBadComponent[0][i][2]<<"\t"<<NBadComponent[0][i][3];
234  ss << "\n";
235  for (int i=1;i<4;++i)
236  ss << "\nTID+ Disk " << i << " :\t\t"<<NBadComponent[1][i][0]<<"\t"<<NBadComponent[1][i][1]<<"\t"<<NBadComponent[1][i][2]<<"\t"<<NBadComponent[1][i][3];
237  for (int i=4;i<7;++i)
238  ss << "\nTID- Disk " << i-3 << " :\t\t"<<NBadComponent[1][i][0]<<"\t"<<NBadComponent[1][i][1]<<"\t"<<NBadComponent[1][i][2]<<"\t"<<NBadComponent[1][i][3];
239  ss << "\n";
240  for (int i=1;i<7;++i)
241  ss << "\nTOB Layer " << i << " :\t\t"<<NBadComponent[2][i][0]<<"\t"<<NBadComponent[2][i][1]<<"\t"<<NBadComponent[2][i][2]<<"\t"<<NBadComponent[2][i][3];
242  ss << "\n";
243  for (int i=1;i<10;++i)
244  ss << "\nTEC+ Disk " << i << " :\t\t"<<NBadComponent[3][i][0]<<"\t"<<NBadComponent[3][i][1]<<"\t"<<NBadComponent[3][i][2]<<"\t"<<NBadComponent[3][i][3];
245  for (int i=10;i<19;++i)
246  ss << "\nTEC- Disk " << i-9 << " :\t\t"<<NBadComponent[3][i][0]<<"\t"<<NBadComponent[3][i][1]<<"\t"<<NBadComponent[3][i][2]<<"\t"<<NBadComponent[3][i][3];
247  ss<< "\n";
248 
249  ss << "\n----------------------------------------------------------------\n\t\t Detid \tModules Fibers Apvs\n----------------------------------------------------------------";
250  for (int i=1;i<5;++i)
251  ss << "\nTIB Layer " << i << " :" << ssV[0][i].str();
252  ss << "\n";
253  for (int i=1;i<4;++i)
254  ss << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
255  for (int i=4;i<7;++i)
256  ss << "\nTID- Disk " << i-3 << " :" << ssV[1][i].str();
257  ss << "\n";
258  for (int i=1;i<7;++i)
259  ss << "\nTOB Layer " << i << " :" << ssV[2][i].str();
260  ss << "\n";
261  for (int i=1;i<10;++i)
262  ss << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
263  for (int i=10;i<19;++i)
264  ss << "\nTEC- Disk " << i-9 << " :" << ssV[3][i].str();
265 
266 
267  edm::LogInfo("SiStripQualityStatistics") << ss.str() << std::endl;
268 
270  std::stringstream sRun; sRun.str("");
271  sRun << "_Run_" << std::setw(6) << std::setfill('0')<< e.id().run() << std::setw(0) ;
272 
273  if (filename!=""){
274  filename.insert(filename.find("."),sRun.str());
275  tkMap->save(true,0,0,filename);
276  filename.erase(filename.begin()+filename.find("."),filename.end());
277  tkMap->print(true,0,0,filename);
278  }
279 }
280 
281 
283 
284  int napv=reader->getNumberOfApvsAndStripLength(BC.detid).first;
285 
286  ssV[i][component] << "\n\t\t "
287  << BC.detid
288  << " \t " << BC.BadModule << " \t "
289  << ( (BC.BadFibers)&0x1 ) << " ";
290  if (napv==4)
291  ssV[i][component] << "x " <<( (BC.BadFibers>>1)&0x1 );
292 
293  if (napv==6)
294  ssV[i][component] << ( (BC.BadFibers>>1)&0x1 ) << " "
295  << ( (BC.BadFibers>>2)&0x1 );
296  ssV[i][component] << " \t "
297  << ( (BC.BadApvs)&0x1 ) << " "
298  << ( (BC.BadApvs>>1)&0x1 ) << " ";
299  if (napv==4)
300  ssV[i][component] << "x x " << ( (BC.BadApvs>>2)&0x1 ) << " "
301  << ( (BC.BadApvs>>3)&0x1 );
302  if (napv==6)
303  ssV[i][component] << ( (BC.BadApvs>>2)&0x1 ) << " "
304  << ( (BC.BadApvs>>3)&0x1 ) << " "
305  << ( (BC.BadApvs>>4)&0x1 ) << " "
306  << ( (BC.BadApvs>>5)&0x1 ) << " ";
307 
308  if (BC.BadApvs){
309  NBadComponent[i][0][2]+= ( (BC.BadApvs>>5)&0x1 )+ ( (BC.BadApvs>>4)&0x1 ) + ( (BC.BadApvs>>3)&0x1 ) +
310  ( (BC.BadApvs>>2)&0x1 )+ ( (BC.BadApvs>>1)&0x1 ) + ( (BC.BadApvs)&0x1 );
311  NBadComponent[i][component][2]+= ( (BC.BadApvs>>5)&0x1 )+ ( (BC.BadApvs>>4)&0x1 ) + ( (BC.BadApvs>>3)&0x1 ) +
312  ( (BC.BadApvs>>2)&0x1 )+ ( (BC.BadApvs>>1)&0x1 ) + ( (BC.BadApvs)&0x1 );
313  tkMap->fillc(BC.detid,0xff0000);
314  }
315  if (BC.BadFibers){
316  NBadComponent[i][0][1]+= ( (BC.BadFibers>>2)&0x1 )+ ( (BC.BadFibers>>1)&0x1 ) + ( (BC.BadFibers)&0x1 );
317  NBadComponent[i][component][1]+= ( (BC.BadFibers>>2)&0x1 )+ ( (BC.BadFibers>>1)&0x1 ) + ( (BC.BadFibers)&0x1 );
318  tkMap->fillc(BC.detid,0x0000ff);
319  }
320  if (BC.BadModule){
321  NBadComponent[i][0][0]++;
322  NBadComponent[i][component][0]++;
323  tkMap->fillc(BC.detid,0x0);
324  }
325 }
#define LogDebug(id)
unsigned short range
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
const std::vector< BadComponent > & getBadComponentList() const
unsigned int tibLayer(const DetId &id) const
void SetBadComponents(int, int, SiStripQuality::BadComponent &)
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
unsigned int tidWheel(const DetId &id) const
Registry::const_iterator RegistryIterator
#define nullptr
RegistryIterator getRegistryVectorEnd() const
unsigned int tidSide(const DetId &id) const
const std::vector< uint32_t > & getAllDetIds() const
bool IsModuleUsable(const uint32_t &detid) const
void save(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap.svg", int width=1500, int height=800)
Definition: TrackerMap.cc:699
filetype
Definition: symbols.py:48
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
void fillc(int idmod, int RGBcode)
Definition: TrackerMap.h:109
std::stringstream ssV[4][19]
int k[5][pyjets_maxn]
ContainerIterator getDataVectorBegin() const
Definition: DetId.h:18
void analyze(const edm::Event &, const edm::EventSetup &) override
std::unique_ptr< TkHistoMap > tkhisto
const T & get() const
Definition: EventSetup.h:58
RegistryIterator getRegistryVectorBegin() const
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
std::pair< ContainerIterator, ContainerIterator > Range
void print(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap")
Definition: TrackerMap.cc:2442
std::string fullPath() const
Definition: FileInPath.cc:184
SiStripDetInfoFileReader * reader
SiStripQualityStatistics(const edm::ParameterSet &)
unsigned int tecWheel(const DetId &id) const
T const * product() const
Definition: ESHandle.h:86
TimeValue_t value() const
Definition: Timestamp.h:56
edm::Timestamp time() const
Definition: EventBase.h:61
void fill(int layer, int ring, int nmod, float x)
Definition: TrackerMap.cc:2786
data decode(const unsigned int &value) const
unsigned int tobLayer(const DetId &id) const
unsigned int tecSide(const DetId &id) const