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