CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: SiStripQualityStatistics.cc,v 1.15 2009/11/30 11:23:27 giordano Exp $
17 //
18 //
20 
22 
27 
28 #include <iostream>
29 #include <iomanip>
30 #include <stdio.h>
31 #include <sys/time.h>
32 
33 
35  m_cacheID_(0),
36  dataLabel_(iConfig.getUntrackedParameter<std::string>("dataLabel","")),
37  TkMapFileName_(iConfig.getUntrackedParameter<std::string>("TkMapFileName","")),
38  fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"))),
39  saveTkHistoMap_(iConfig.getUntrackedParameter<bool>("SaveTkHistoMap",true)),
40  tkMap(0),tkMapFullIOVs(0)
41 {
43 
44  tkMapFullIOVs=new TrackerMap( "BadComponents" );
45  tkhisto=0;
46  if (TkMapFileName_!=""){
47  tkhisto =new TkHistoMap("BadComp","BadComp",-1.); //here the baseline (the value of the empty,not assigned bins) is put to -1 (default is zero)
48  }
49 }
50 
52 
53  std::string filename=TkMapFileName_;
54  if (filename!=""){
55  tkMapFullIOVs->save(false,0,0,filename.c_str());
56  filename.erase(filename.begin()+filename.find("."),filename.end());
57  tkMapFullIOVs->print(false,0,0,filename.c_str());
58 
59  if(saveTkHistoMap_){
60  tkhisto->save(filename+".root");
61  tkhisto->saveAsCanvas(filename+"_Canvas.root","E");
62  }
63  }
64 }
65 
67 
68  unsigned long long cacheID = iSetup.get<SiStripQualityRcd>().cacheIdentifier();
69 
70  std::stringstream ss;
71 
72  if (m_cacheID_ == cacheID)
73  return;
74 
75  m_cacheID_ = cacheID;
76 
77  edm::ESHandle<SiStripQuality> SiStripQuality_;
78  iSetup.get<SiStripQualityRcd>().get(dataLabel_,SiStripQuality_);
79 
80  for(int i=0;i<4;++i){
81  NTkBadComponent[i]=0;
82  for(int j=0;j<19;++j){
83  ssV[i][j].str("");
84  for(int k=0;k<4;++k)
85  NBadComponent[i][j][k]=0;
86  }
87  }
88 
89  if (tkMap)
90  delete tkMap;
91  tkMap=new TrackerMap( "BadComponents" );
92 
93 
94  ss.str("");
95  std::vector<uint32_t> detids=reader->getAllDetIds();
96  std::vector<uint32_t>::const_iterator idet=detids.begin();
97  for(;idet!=detids.end();++idet){
98  ss << "detid " << (*idet) << " IsModuleUsable " << SiStripQuality_->IsModuleUsable((*idet)) << "\n";
99  if (SiStripQuality_->IsModuleUsable((*idet)))
100  tkMap->fillc(*idet,0x00ff00);
101  }
102  LogDebug("SiStripQualityStatistics") << ss.str() << std::endl;
103 
104 
105  std::vector<SiStripQuality::BadComponent> BC = SiStripQuality_->getBadComponentList();
106 
107  for (size_t i=0;i<BC.size();++i){
108 
109  //&&&&&&&&&&&&&
110  //Full Tk
111  //&&&&&&&&&&&&&
112 
113  if (BC[i].BadModule)
114  NTkBadComponent[0]++;
115  if (BC[i].BadFibers)
116  NTkBadComponent[1]+= ( (BC[i].BadFibers>>2)&0x1 )+ ( (BC[i].BadFibers>>1)&0x1 ) + ( (BC[i].BadFibers)&0x1 );
117  if (BC[i].BadApvs)
118  NTkBadComponent[2]+= ( (BC[i].BadApvs>>5)&0x1 )+ ( (BC[i].BadApvs>>4)&0x1 ) + ( (BC[i].BadApvs>>3)&0x1 ) +
119  ( (BC[i].BadApvs>>2)&0x1 )+ ( (BC[i].BadApvs>>1)&0x1 ) + ( (BC[i].BadApvs)&0x1 );
120 
121  //&&&&&&&&&&&&&&&&&
122  //Single SubSyste
123  //&&&&&&&&&&&&&&&&&
124 
125  int component;
126  SiStripDetId a(BC[i].detid);
127  if ( a.subdetId() == SiStripDetId::TIB ){
128  //&&&&&&&&&&&&&&&&&
129  //TIB
130  //&&&&&&&&&&&&&&&&&
131 
132  component=TIBDetId(BC[i].detid).layer();
133  SetBadComponents(0, component, BC[i]);
134 
135  } else if ( a.subdetId() == SiStripDetId::TID ) {
136  //&&&&&&&&&&&&&&&&&
137  //TID
138  //&&&&&&&&&&&&&&&&&
139 
140  component=TIDDetId(BC[i].detid).side()==2?TIDDetId(BC[i].detid).wheel():TIDDetId(BC[i].detid).wheel()+3;
141  SetBadComponents(1, component, BC[i]);
142 
143  } else if ( a.subdetId() == SiStripDetId::TOB ) {
144  //&&&&&&&&&&&&&&&&&
145  //TOB
146  //&&&&&&&&&&&&&&&&&
147 
148  component=TOBDetId(BC[i].detid).layer();
149  SetBadComponents(2, component, BC[i]);
150 
151  } else if ( a.subdetId() == SiStripDetId::TEC ) {
152  //&&&&&&&&&&&&&&&&&
153  //TEC
154  //&&&&&&&&&&&&&&&&&
155 
156  component=TECDetId(BC[i].detid).side()==2?TECDetId(BC[i].detid).wheel():TECDetId(BC[i].detid).wheel()+9;
157  SetBadComponents(3, component, BC[i]);
158 
159  }
160  }
161 
162  //&&&&&&&&&&&&&&&&&&
163  // Single Strip Info
164  //&&&&&&&&&&&&&&&&&&
165  float percentage=0;
166 
167  SiStripQuality::RegistryIterator rbegin = SiStripQuality_->getRegistryVectorBegin();
168  SiStripQuality::RegistryIterator rend = SiStripQuality_->getRegistryVectorEnd();
169 
170  for (SiStripBadStrip::RegistryIterator rp=rbegin; rp != rend; ++rp) {
171  uint32_t detid=rp->detid;
172 
173  int subdet=-999; int component=-999;
174  SiStripDetId a(detid);
175  if ( a.subdetId() == 3 ){
176  subdet=0;
177  component=TIBDetId(detid).layer();
178  } else if ( a.subdetId() == 4 ) {
179  subdet=1;
180  component=TIDDetId(detid).side()==2?TIDDetId(detid).wheel():TIDDetId(detid).wheel()+3;
181  } else if ( a.subdetId() == 5 ) {
182  subdet=2;
183  component=TOBDetId(detid).layer();
184  } else if ( a.subdetId() == 6 ) {
185  subdet=3;
186  component=TECDetId(detid).side()==2?TECDetId(detid).wheel():TECDetId(detid).wheel()+9;
187  }
188 
189  SiStripQuality::Range sqrange = SiStripQuality::Range( SiStripQuality_->getDataVectorBegin()+rp->ibegin , SiStripQuality_->getDataVectorBegin()+rp->iend );
190 
191  percentage=0;
192  for(int it=0;it<sqrange.second-sqrange.first;it++){
193  unsigned int range=SiStripQuality_->decode( *(sqrange.first+it) ).range;
194  NTkBadComponent[3]+=range;
195  NBadComponent[subdet][0][3]+=range;
196  NBadComponent[subdet][component][3]+=range;
197  percentage+=range;
198  }
199  if(percentage!=0)
200  percentage/=128.*reader->getNumberOfApvsAndStripLength(detid).first;
201  if(percentage>1)
202  edm::LogError("SiStripQualityStatistics") << "PROBLEM detid " << detid << " value " << percentage<< std::endl;
203 
204  //------- Global Statistics on percentage of bad components along the IOVs ------//
205  tkMapFullIOVs->fill(detid,percentage);
206  if(tkhisto!=NULL)
207  tkhisto->fill(detid,percentage);
208  }
209 
210 
211  //&&&&&&&&&&&&&&&&&&
212  // printout
213  //&&&&&&&&&&&&&&&&&&
214 
215  ss.str("");
216  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";
217  ss << "\n-----------------\nGlobal Info\n-----------------";
218  ss << "\nBadComponent \t Modules \tFibers \tApvs\tStrips\n----------------------------------------------------------------";
219  ss << "\nTracker:\t\t"<<NTkBadComponent[0]<<"\t"<<NTkBadComponent[1]<<"\t"<<NTkBadComponent[2]<<"\t"<<NTkBadComponent[3];
220  ss<< "\n";
221  ss << "\nTIB:\t\t\t"<<NBadComponent[0][0][0]<<"\t"<<NBadComponent[0][0][1]<<"\t"<<NBadComponent[0][0][2]<<"\t"<<NBadComponent[0][0][3];
222  ss << "\nTID:\t\t\t"<<NBadComponent[1][0][0]<<"\t"<<NBadComponent[1][0][1]<<"\t"<<NBadComponent[1][0][2]<<"\t"<<NBadComponent[1][0][3];
223  ss << "\nTOB:\t\t\t"<<NBadComponent[2][0][0]<<"\t"<<NBadComponent[2][0][1]<<"\t"<<NBadComponent[2][0][2]<<"\t"<<NBadComponent[2][0][3];
224  ss << "\nTEC:\t\t\t"<<NBadComponent[3][0][0]<<"\t"<<NBadComponent[3][0][1]<<"\t"<<NBadComponent[3][0][2]<<"\t"<<NBadComponent[3][0][3];
225  ss << "\n";
226 
227  for (int i=1;i<5;++i)
228  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];
229  ss << "\n";
230  for (int i=1;i<4;++i)
231  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];
232  for (int i=4;i<7;++i)
233  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];
234  ss << "\n";
235  for (int i=1;i<7;++i)
236  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];
237  ss << "\n";
238  for (int i=1;i<10;++i)
239  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];
240  for (int i=10;i<19;++i)
241  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];
242  ss<< "\n";
243 
244  ss << "\n----------------------------------------------------------------\n\t\t Detid \tModules Fibers Apvs\n----------------------------------------------------------------";
245  for (int i=1;i<5;++i)
246  ss << "\nTIB Layer " << i << " :" << ssV[0][i].str();
247  ss << "\n";
248  for (int i=1;i<4;++i)
249  ss << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
250  for (int i=4;i<7;++i)
251  ss << "\nTID- Disk " << i-3 << " :" << ssV[1][i].str();
252  ss << "\n";
253  for (int i=1;i<7;++i)
254  ss << "\nTOB Layer " << i << " :" << ssV[2][i].str();
255  ss << "\n";
256  for (int i=1;i<10;++i)
257  ss << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
258  for (int i=10;i<19;++i)
259  ss << "\nTEC- Disk " << i-9 << " :" << ssV[3][i].str();
260 
261 
262  edm::LogInfo("SiStripQualityStatistics") << ss.str() << std::endl;
263 
265  std::stringstream sRun; sRun.str("");
266  sRun << "_Run_" << std::setw(6) << std::setfill('0')<< e.id().run() << std::setw(0) ;
267 
268  if (filename!=""){
269  filename.insert(filename.find("."),sRun.str());
270  tkMap->save(true,0,0,filename.c_str());
271  filename.erase(filename.begin()+filename.find("."),filename.end());
272  tkMap->print(true,0,0,filename.c_str());
273  }
274 }
275 
276 
278 
279  int napv=reader->getNumberOfApvsAndStripLength(BC.detid).first;
280 
281  ssV[i][component] << "\n\t\t "
282  << BC.detid
283  << " \t " << BC.BadModule << " \t "
284  << ( (BC.BadFibers)&0x1 ) << " ";
285  if (napv==4)
286  ssV[i][component] << "x " <<( (BC.BadFibers>>1)&0x1 );
287 
288  if (napv==6)
289  ssV[i][component] << ( (BC.BadFibers>>1)&0x1 ) << " "
290  << ( (BC.BadFibers>>2)&0x1 );
291  ssV[i][component] << " \t "
292  << ( (BC.BadApvs)&0x1 ) << " "
293  << ( (BC.BadApvs>>1)&0x1 ) << " ";
294  if (napv==4)
295  ssV[i][component] << "x x " << ( (BC.BadApvs>>2)&0x1 ) << " "
296  << ( (BC.BadApvs>>3)&0x1 );
297  if (napv==6)
298  ssV[i][component] << ( (BC.BadApvs>>2)&0x1 ) << " "
299  << ( (BC.BadApvs>>3)&0x1 ) << " "
300  << ( (BC.BadApvs>>4)&0x1 ) << " "
301  << ( (BC.BadApvs>>5)&0x1 ) << " ";
302 
303  if (BC.BadApvs){
304  NBadComponent[i][0][2]+= ( (BC.BadApvs>>5)&0x1 )+ ( (BC.BadApvs>>4)&0x1 ) + ( (BC.BadApvs>>3)&0x1 ) +
305  ( (BC.BadApvs>>2)&0x1 )+ ( (BC.BadApvs>>1)&0x1 ) + ( (BC.BadApvs)&0x1 );
306  NBadComponent[i][component][2]+= ( (BC.BadApvs>>5)&0x1 )+ ( (BC.BadApvs>>4)&0x1 ) + ( (BC.BadApvs>>3)&0x1 ) +
307  ( (BC.BadApvs>>2)&0x1 )+ ( (BC.BadApvs>>1)&0x1 ) + ( (BC.BadApvs)&0x1 );
308  tkMap->fillc(BC.detid,0xff0000);
309  }
310  if (BC.BadFibers){
311  NBadComponent[i][0][1]+= ( (BC.BadFibers>>2)&0x1 )+ ( (BC.BadFibers>>1)&0x1 ) + ( (BC.BadFibers)&0x1 );
312  NBadComponent[i][component][1]+= ( (BC.BadFibers>>2)&0x1 )+ ( (BC.BadFibers>>1)&0x1 ) + ( (BC.BadFibers)&0x1 );
313  tkMap->fillc(BC.detid,0x0000ff);
314  }
315  if (BC.BadModule){
316  NBadComponent[i][0][0]++;
317  NBadComponent[i][component][0]++;
318  tkMap->fillc(BC.detid,0x0);
319  }
320 }
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:42
EventNumber_t event() const
Definition: EventID.h:44
int i
Definition: DBlmapReader.cc:9
unsigned int layer() const
layer id
Definition: TOBDetId.h:39
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:59
#define NULL
Definition: scimark2.h:8
Registry::const_iterator RegistryIterator
unsigned int side() const
positive or negative id
Definition: TECDetId.h:47
void saveAsCanvas(std::string filename, std::string options="", std::string mode="RECREATE")
Definition: TkHistoMap.cc:202
void analyze(const edm::Event &, const edm::EventSetup &)
void save(std::string filename)
Definition: TkHistoMap.cc:41
const std::vector< uint32_t > & getAllDetIds() const
void fill(uint32_t &detid, float value)
Definition: TkHistoMap.cc:130
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:632
int j
Definition: DBlmapReader.cc:9
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
void fillc(int idmod, int RGBcode)
Definition: TrackerMap.h:48
std::stringstream ssV[4][19]
int k[5][pyjets_maxn]
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
TimeValue_t value() const
Definition: Timestamp.cc:72
unsigned int side() const
positive or negative id
Definition: TIDDetId.h:45
const T & get() const
Definition: EventSetup.h:55
unsigned int wheel() const
wheel id
Definition: TECDetId.h:52
unsigned int layer() const
layer id
Definition: TIBDetId.h:41
edm::EventID id() const
Definition: EventBase.h:56
double a
Definition: hdecay.h:121
std::pair< ContainerIterator, ContainerIterator > Range
void print(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap")
Definition: TrackerMap.cc:2210
tuple filename
Definition: lut2db_cfg.py:20
SiStripDetInfoFileReader * reader
SiStripQualityStatistics(const edm::ParameterSet &)
std::string fullPath() const
Definition: FileInPath.cc:171
edm::Timestamp time() const
Definition: EventBase.h:57
void fill(int layer, int ring, int nmod, float x)
Definition: TrackerMap.cc:2549
unsigned int wheel() const
wheel id
Definition: TIDDetId.h:50