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