00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
00020
00021 #include "CalibTracker/SiStripQuality/plugins/SiStripQualityStatistics.h"
00022
00023 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00024 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00025 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00026 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00027
00028 #include <iostream>
00029 #include <iomanip>
00030 #include <stdio.h>
00031 #include <sys/time.h>
00032
00033
00034 SiStripQualityStatistics::SiStripQualityStatistics( const edm::ParameterSet& iConfig ):
00035 m_cacheID_(0),
00036 dataLabel_(iConfig.getUntrackedParameter<std::string>("dataLabel","")),
00037 TkMapFileName_(iConfig.getUntrackedParameter<std::string>("TkMapFileName","")),
00038 fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"))),
00039 tkMap(0)
00040 {
00041 reader = new SiStripDetInfoFileReader(fp_.fullPath());
00042 }
00043
00044 void SiStripQualityStatistics::analyze( const edm::Event& e, const edm::EventSetup& iSetup){
00045
00046 unsigned long long cacheID = iSetup.get<SiStripQualityRcd>().cacheIdentifier();
00047
00048 std::stringstream ss;
00049
00050 if (m_cacheID_ == cacheID)
00051 return;
00052
00053 m_cacheID_ = cacheID;
00054
00055 edm::ESHandle<SiStripQuality> SiStripQuality_;
00056 iSetup.get<SiStripQualityRcd>().get(dataLabel_,SiStripQuality_);
00057
00058 for(int i=0;i<4;++i){
00059 NTkBadComponent[i]=0;
00060 for(int j=0;j<19;++j){
00061 ssV[i][j].str("");
00062 for(int k=0;k<4;++k)
00063 NBadComponent[i][j][k]=0;
00064 }
00065 }
00066
00067 if (tkMap)
00068 delete tkMap;
00069 tkMap=new TrackerMap( "BadComponents" );
00070
00071
00072 ss.str("");
00073 std::vector<uint32_t> detids=reader->getAllDetIds();
00074 std::vector<uint32_t>::const_iterator idet=detids.begin();
00075 for(;idet!=detids.end();++idet){
00076 ss << "detid " << (*idet) << " IsModuleUsable " << SiStripQuality_->IsModuleUsable((*idet)) << "\n";
00077 if (SiStripQuality_->IsModuleUsable((*idet)))
00078 tkMap->fillc(*idet,0x00ff00);
00079 }
00080 LogDebug("SiStripQualityStatistics") << ss.str() << std::endl;
00081
00082
00083 std::vector<SiStripQuality::BadComponent> BC = SiStripQuality_->getBadComponentList();
00084
00085 for (size_t i=0;i<BC.size();++i){
00086
00087
00088
00089
00090
00091 if (BC[i].BadModule)
00092 NTkBadComponent[0]++;
00093 if (BC[i].BadFibers)
00094 NTkBadComponent[1]+= ( (BC[i].BadFibers>>2)&0x1 )+ ( (BC[i].BadFibers>>1)&0x1 ) + ( (BC[i].BadFibers)&0x1 );
00095 if (BC[i].BadApvs)
00096 NTkBadComponent[2]+= ( (BC[i].BadApvs>>5)&0x1 )+ ( (BC[i].BadApvs>>4)&0x1 ) + ( (BC[i].BadApvs>>3)&0x1 ) +
00097 ( (BC[i].BadApvs>>2)&0x1 )+ ( (BC[i].BadApvs>>1)&0x1 ) + ( (BC[i].BadApvs)&0x1 );
00098
00099
00100
00101
00102
00103 int component;
00104 SiStripDetId a(BC[i].detid);
00105 if ( a.subdetId() == SiStripDetId::TIB ){
00106
00107
00108
00109
00110 component=TIBDetId(BC[i].detid).layer();
00111 SetBadComponents(0, component, BC[i]);
00112
00113 } else if ( a.subdetId() == SiStripDetId::TID ) {
00114
00115
00116
00117
00118 component=TIDDetId(BC[i].detid).side()==2?TIDDetId(BC[i].detid).wheel():TIDDetId(BC[i].detid).wheel()+3;
00119 SetBadComponents(1, component, BC[i]);
00120
00121 } else if ( a.subdetId() == SiStripDetId::TOB ) {
00122
00123
00124
00125
00126 component=TOBDetId(BC[i].detid).layer();
00127 SetBadComponents(2, component, BC[i]);
00128
00129 } else if ( a.subdetId() == SiStripDetId::TEC ) {
00130
00131
00132
00133
00134 component=TECDetId(BC[i].detid).side()==2?TECDetId(BC[i].detid).wheel():TECDetId(BC[i].detid).wheel()+9;
00135 SetBadComponents(3, component, BC[i]);
00136
00137 }
00138 }
00139
00140
00141
00142
00143
00144 SiStripQuality::RegistryIterator rbegin = SiStripQuality_->getRegistryVectorBegin();
00145 SiStripQuality::RegistryIterator rend = SiStripQuality_->getRegistryVectorEnd();
00146
00147 for (SiStripBadStrip::RegistryIterator rp=rbegin; rp != rend; ++rp) {
00148 uint32_t detid=rp->detid;
00149
00150 int subdet,component;
00151 SiStripDetId a(detid);
00152 if ( a.subdetId() == 3 ){
00153 subdet=0;
00154 component=TIBDetId(detid).layer();
00155 } else if ( a.subdetId() == 4 ) {
00156 subdet=1;
00157 component=TIDDetId(detid).side()==2?TIDDetId(detid).wheel():TIDDetId(detid).wheel()+3;
00158 } else if ( a.subdetId() == 5 ) {
00159 subdet=2;
00160 component=TOBDetId(detid).layer();
00161 } else if ( a.subdetId() == 6 ) {
00162 subdet=3;
00163 component=TECDetId(detid).side()==2?TECDetId(detid).wheel():TECDetId(detid).wheel()+9;
00164 }
00165
00166 SiStripQuality::Range sqrange = SiStripQuality::Range( SiStripQuality_->getDataVectorBegin()+rp->ibegin , SiStripQuality_->getDataVectorBegin()+rp->iend );
00167
00168 for(int it=0;it<sqrange.second-sqrange.first;it++){
00169 unsigned int range=SiStripQuality_->decode( *(sqrange.first+it) ).range;
00170 NTkBadComponent[3]+=range;
00171 NBadComponent[subdet][0][3]+=range;
00172 NBadComponent[subdet][component][3]+=range;
00173 }
00174 }
00175
00176
00177
00178
00179
00180
00181 ss.str("");
00182 ss << "\n-----------------\nNew IOV starting from run " << e.id().run() << "\n-----------------\n";
00183 ss << "\n-----------------\nGlobal Info\n-----------------";
00184 ss << "\nBadComponent \t Modules \tFibers \tApvs\tStrips\n----------------------------------------------------------------";
00185 ss << "\nTracker:\t\t"<<NTkBadComponent[0]<<"\t"<<NTkBadComponent[1]<<"\t"<<NTkBadComponent[2]<<"\t"<<NTkBadComponent[3];
00186 ss<< "\n";
00187 ss << "\nTIB:\t\t\t"<<NBadComponent[0][0][0]<<"\t"<<NBadComponent[0][0][1]<<"\t"<<NBadComponent[0][0][2]<<"\t"<<NBadComponent[0][0][3];
00188 ss << "\nTID:\t\t\t"<<NBadComponent[1][0][0]<<"\t"<<NBadComponent[1][0][1]<<"\t"<<NBadComponent[1][0][2]<<"\t"<<NBadComponent[1][0][3];
00189 ss << "\nTOB:\t\t\t"<<NBadComponent[2][0][0]<<"\t"<<NBadComponent[2][0][1]<<"\t"<<NBadComponent[2][0][2]<<"\t"<<NBadComponent[2][0][3];
00190 ss << "\nTEC:\t\t\t"<<NBadComponent[3][0][0]<<"\t"<<NBadComponent[3][0][1]<<"\t"<<NBadComponent[3][0][2]<<"\t"<<NBadComponent[3][0][3];
00191 ss << "\n";
00192
00193 for (int i=1;i<5;++i)
00194 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];
00195 ss << "\n";
00196 for (int i=1;i<4;++i)
00197 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];
00198 for (int i=4;i<7;++i)
00199 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];
00200 ss << "\n";
00201 for (int i=1;i<7;++i)
00202 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];
00203 ss << "\n";
00204 for (int i=1;i<10;++i)
00205 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];
00206 for (int i=10;i<19;++i)
00207 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];
00208 ss<< "\n";
00209
00210 ss << "\n----------------------------------------------------------------\n\t\t Detid \tModules Fibers Apvs\n----------------------------------------------------------------";
00211 for (int i=1;i<5;++i)
00212 ss << "\nTIB Layer " << i << " :" << ssV[0][i].str();
00213 ss << "\n";
00214 for (int i=1;i<4;++i)
00215 ss << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
00216 for (int i=4;i<7;++i)
00217 ss << "\nTID- Disk " << i-3 << " :" << ssV[1][i].str();
00218 ss << "\n";
00219 for (int i=1;i<7;++i)
00220 ss << "\nTOB Layer " << i << " :" << ssV[2][i].str();
00221 ss << "\n";
00222 for (int i=1;i<10;++i)
00223 ss << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
00224 for (int i=10;i<19;++i)
00225 ss << "\nTEC- Disk " << i-9 << " :" << ssV[3][i].str();
00226
00227
00228 edm::LogInfo("SiStripQualityStatistics") << ss.str() << std::endl;
00229
00230 std::string filetype=TkMapFileName_,filename=TkMapFileName_;
00231 std::stringstream sRun; sRun.str("");
00232 sRun << "_Run_" << std::setw(6) << std::setfill('0')<< e.id().run() << std::setw(0) ;
00233
00234 if (filename!=""){
00235 filename.insert(filename.find("."),sRun.str());
00236 tkMap->save(true,0,0,filename.c_str());
00237 filename.erase(filename.begin()+filename.find("."),filename.end());
00238 tkMap->print(true,0,0,filename.c_str());
00239 }
00240 }
00241
00242
00243 void SiStripQualityStatistics::SetBadComponents(int i, int component,SiStripQuality::BadComponent& BC){
00244
00245 int napv=reader->getNumberOfApvsAndStripLength(BC.detid).first;
00246
00247 ssV[i][component] << "\n\t\t "
00248 << BC.detid
00249 << " \t " << BC.BadModule << " \t "
00250 << ( (BC.BadFibers)&0x1 ) << " ";
00251 if (napv==4)
00252 ssV[i][component] << "x " <<( (BC.BadFibers>>1)&0x1 );
00253
00254 if (napv==6)
00255 ssV[i][component] << ( (BC.BadFibers>>1)&0x1 ) << " "
00256 << ( (BC.BadFibers>>2)&0x1 );
00257 ssV[i][component] << " \t "
00258 << ( (BC.BadApvs)&0x1 ) << " "
00259 << ( (BC.BadApvs>>1)&0x1 ) << " ";
00260 if (napv==4)
00261 ssV[i][component] << "x x " << ( (BC.BadApvs>>2)&0x1 ) << " "
00262 << ( (BC.BadApvs>>3)&0x1 );
00263 if (napv==6)
00264 ssV[i][component] << ( (BC.BadApvs>>2)&0x1 ) << " "
00265 << ( (BC.BadApvs>>3)&0x1 ) << " "
00266 << ( (BC.BadApvs>>4)&0x1 ) << " "
00267 << ( (BC.BadApvs>>5)&0x1 ) << " ";
00268
00269 if (BC.BadApvs){
00270 NBadComponent[i][0][2]+= ( (BC.BadApvs>>5)&0x1 )+ ( (BC.BadApvs>>4)&0x1 ) + ( (BC.BadApvs>>3)&0x1 ) +
00271 ( (BC.BadApvs>>2)&0x1 )+ ( (BC.BadApvs>>1)&0x1 ) + ( (BC.BadApvs)&0x1 );
00272 NBadComponent[i][component][2]+= ( (BC.BadApvs>>5)&0x1 )+ ( (BC.BadApvs>>4)&0x1 ) + ( (BC.BadApvs>>3)&0x1 ) +
00273 ( (BC.BadApvs>>2)&0x1 )+ ( (BC.BadApvs>>1)&0x1 ) + ( (BC.BadApvs)&0x1 );
00274 tkMap->fillc(BC.detid,0xff0000);
00275 }
00276 if (BC.BadFibers){
00277 NBadComponent[i][0][1]+= ( (BC.BadFibers>>2)&0x1 )+ ( (BC.BadFibers>>1)&0x1 ) + ( (BC.BadFibers)&0x1 );
00278 NBadComponent[i][component][1]+= ( (BC.BadFibers>>2)&0x1 )+ ( (BC.BadFibers>>1)&0x1 ) + ( (BC.BadFibers)&0x1 );
00279 tkMap->fillc(BC.detid,0x0000ff);
00280 }
00281 if (BC.BadModule){
00282 NBadComponent[i][0][0]++;
00283 NBadComponent[i][component][0]++;
00284 tkMap->fillc(BC.detid,0x0);
00285 }
00286 }