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