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