CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/CalibTracker/SiStripQuality/plugins/SiStripQualityStatistics.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiStripQualityStatistics
00004 // Class:      SiStripQualityStatistics
00005 // 
00013 //
00014 // Original Author:  Domenico GIORDANO
00015 //         Created:  Wed Oct  3 12:11:10 CEST 2007
00016 // $Id: SiStripQualityStatistics.cc,v 1.15 2009/11/30 11:23:27 giordano Exp $
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   saveTkHistoMap_(iConfig.getUntrackedParameter<bool>("SaveTkHistoMap",true)),
00040   tkMap(0),tkMapFullIOVs(0)
00041 {  
00042   reader = new SiStripDetInfoFileReader(fp_.fullPath());
00043 
00044   tkMapFullIOVs=new TrackerMap( "BadComponents" );
00045   tkhisto=0;
00046   if (TkMapFileName_!=""){
00047     tkhisto   =new TkHistoMap("BadComp","BadComp",-1.); //here the baseline (the value of the empty,not assigned bins) is put to -1 (default is zero)
00048   }
00049 }
00050 
00051 void SiStripQualityStatistics::endJob(){
00052 
00053   std::string filename=TkMapFileName_;
00054   if (filename!=""){
00055     tkMapFullIOVs->save(false,0,0,filename.c_str());
00056     filename.erase(filename.begin()+filename.find("."),filename.end());
00057     tkMapFullIOVs->print(false,0,0,filename.c_str());
00058   
00059     if(saveTkHistoMap_){
00060       tkhisto->save(filename+".root");
00061       tkhisto->saveAsCanvas(filename+"_Canvas.root","E");
00062     }
00063   }
00064 }
00065 
00066 void SiStripQualityStatistics::analyze( const edm::Event& e, const edm::EventSetup& iSetup){
00067 
00068   unsigned long long cacheID = iSetup.get<SiStripQualityRcd>().cacheIdentifier();
00069 
00070   std::stringstream ss;
00071 
00072   if (m_cacheID_ == cacheID) 
00073     return;
00074 
00075   m_cacheID_ = cacheID; 
00076 
00077   edm::ESHandle<SiStripQuality> SiStripQuality_;
00078   iSetup.get<SiStripQualityRcd>().get(dataLabel_,SiStripQuality_);
00079     
00080   for(int i=0;i<4;++i){
00081     NTkBadComponent[i]=0;
00082     for(int j=0;j<19;++j){
00083       ssV[i][j].str("");
00084       for(int k=0;k<4;++k)
00085         NBadComponent[i][j][k]=0;
00086     }
00087   }
00088 
00089   if (tkMap)
00090     delete tkMap;
00091   tkMap=new TrackerMap( "BadComponents" );
00092 
00093 
00094   ss.str(""); 
00095   std::vector<uint32_t> detids=reader->getAllDetIds();
00096   std::vector<uint32_t>::const_iterator idet=detids.begin();
00097   for(;idet!=detids.end();++idet){
00098     ss << "detid " << (*idet) << " IsModuleUsable " << SiStripQuality_->IsModuleUsable((*idet)) << "\n";
00099     if (SiStripQuality_->IsModuleUsable((*idet)))
00100       tkMap->fillc(*idet,0x00ff00);
00101   }
00102   LogDebug("SiStripQualityStatistics") << ss.str() << std::endl;
00103 
00104 
00105   std::vector<SiStripQuality::BadComponent> BC = SiStripQuality_->getBadComponentList();
00106   
00107   for (size_t i=0;i<BC.size();++i){
00108     
00109     //&&&&&&&&&&&&&
00110     //Full Tk
00111     //&&&&&&&&&&&&&
00112 
00113     if (BC[i].BadModule) 
00114       NTkBadComponent[0]++;
00115     if (BC[i].BadFibers) 
00116       NTkBadComponent[1]+= ( (BC[i].BadFibers>>2)&0x1 )+ ( (BC[i].BadFibers>>1)&0x1 ) + ( (BC[i].BadFibers)&0x1 );
00117     if (BC[i].BadApvs)
00118       NTkBadComponent[2]+= ( (BC[i].BadApvs>>5)&0x1 )+ ( (BC[i].BadApvs>>4)&0x1 ) + ( (BC[i].BadApvs>>3)&0x1 ) + 
00119         ( (BC[i].BadApvs>>2)&0x1 )+ ( (BC[i].BadApvs>>1)&0x1 ) + ( (BC[i].BadApvs)&0x1 );
00120 
00121     //&&&&&&&&&&&&&&&&&
00122     //Single SubSyste
00123     //&&&&&&&&&&&&&&&&&
00124 
00125     int component;
00126     SiStripDetId a(BC[i].detid);
00127     if ( a.subdetId() == SiStripDetId::TIB ){
00128       //&&&&&&&&&&&&&&&&&
00129       //TIB
00130       //&&&&&&&&&&&&&&&&&
00131       
00132       component=TIBDetId(BC[i].detid).layer();
00133       SetBadComponents(0, component, BC[i]);         
00134 
00135     } else if ( a.subdetId() == SiStripDetId::TID ) {
00136       //&&&&&&&&&&&&&&&&&
00137       //TID
00138       //&&&&&&&&&&&&&&&&&
00139 
00140       component=TIDDetId(BC[i].detid).side()==2?TIDDetId(BC[i].detid).wheel():TIDDetId(BC[i].detid).wheel()+3;
00141       SetBadComponents(1, component, BC[i]);         
00142 
00143     } else if ( a.subdetId() == SiStripDetId::TOB ) {
00144       //&&&&&&&&&&&&&&&&&
00145       //TOB
00146       //&&&&&&&&&&&&&&&&&
00147 
00148       component=TOBDetId(BC[i].detid).layer();
00149       SetBadComponents(2, component, BC[i]);         
00150 
00151     } else if ( a.subdetId() == SiStripDetId::TEC ) {
00152       //&&&&&&&&&&&&&&&&&
00153       //TEC
00154       //&&&&&&&&&&&&&&&&&
00155 
00156       component=TECDetId(BC[i].detid).side()==2?TECDetId(BC[i].detid).wheel():TECDetId(BC[i].detid).wheel()+9;
00157       SetBadComponents(3, component, BC[i]);         
00158 
00159     }    
00160   }
00161 
00162   //&&&&&&&&&&&&&&&&&&
00163   // Single Strip Info
00164   //&&&&&&&&&&&&&&&&&&
00165   float percentage=0;
00166 
00167   SiStripQuality::RegistryIterator rbegin = SiStripQuality_->getRegistryVectorBegin();
00168   SiStripQuality::RegistryIterator rend   = SiStripQuality_->getRegistryVectorEnd();
00169   
00170   for (SiStripBadStrip::RegistryIterator rp=rbegin; rp != rend; ++rp) {
00171     uint32_t detid=rp->detid;
00172 
00173     int subdet=-999; int component=-999;
00174     SiStripDetId a(detid);
00175     if ( a.subdetId() == 3 ){
00176       subdet=0;
00177       component=TIBDetId(detid).layer();
00178     } else if ( a.subdetId() == 4 ) {
00179       subdet=1;
00180       component=TIDDetId(detid).side()==2?TIDDetId(detid).wheel():TIDDetId(detid).wheel()+3;
00181     } else if ( a.subdetId() == 5 ) {
00182       subdet=2;
00183       component=TOBDetId(detid).layer();
00184     } else if ( a.subdetId() == 6 ) {
00185       subdet=3;
00186       component=TECDetId(detid).side()==2?TECDetId(detid).wheel():TECDetId(detid).wheel()+9;
00187     } 
00188 
00189     SiStripQuality::Range sqrange = SiStripQuality::Range( SiStripQuality_->getDataVectorBegin()+rp->ibegin , SiStripQuality_->getDataVectorBegin()+rp->iend );
00190         
00191     percentage=0;
00192     for(int it=0;it<sqrange.second-sqrange.first;it++){
00193       unsigned int range=SiStripQuality_->decode( *(sqrange.first+it) ).range;
00194       NTkBadComponent[3]+=range;
00195       NBadComponent[subdet][0][3]+=range;
00196       NBadComponent[subdet][component][3]+=range;
00197       percentage+=range;
00198     }
00199     if(percentage!=0)
00200       percentage/=128.*reader->getNumberOfApvsAndStripLength(detid).first;
00201     if(percentage>1)
00202       edm::LogError("SiStripQualityStatistics") <<  "PROBLEM detid " << detid << " value " << percentage<< std::endl;
00203 
00204     //------- Global Statistics on percentage of bad components along the IOVs ------//
00205     tkMapFullIOVs->fill(detid,percentage);
00206     if(tkhisto!=NULL)
00207       tkhisto->fill(detid,percentage);
00208   }
00209   
00210  
00211   //&&&&&&&&&&&&&&&&&&
00212   // printout
00213   //&&&&&&&&&&&&&&&&&&
00214 
00215   ss.str("");
00216   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";
00217   ss << "\n-----------------\nGlobal Info\n-----------------";
00218   ss << "\nBadComponent \t   Modules \tFibers \tApvs\tStrips\n----------------------------------------------------------------";
00219   ss << "\nTracker:\t\t"<<NTkBadComponent[0]<<"\t"<<NTkBadComponent[1]<<"\t"<<NTkBadComponent[2]<<"\t"<<NTkBadComponent[3];
00220   ss<< "\n";
00221   ss << "\nTIB:\t\t\t"<<NBadComponent[0][0][0]<<"\t"<<NBadComponent[0][0][1]<<"\t"<<NBadComponent[0][0][2]<<"\t"<<NBadComponent[0][0][3];
00222   ss << "\nTID:\t\t\t"<<NBadComponent[1][0][0]<<"\t"<<NBadComponent[1][0][1]<<"\t"<<NBadComponent[1][0][2]<<"\t"<<NBadComponent[1][0][3];
00223   ss << "\nTOB:\t\t\t"<<NBadComponent[2][0][0]<<"\t"<<NBadComponent[2][0][1]<<"\t"<<NBadComponent[2][0][2]<<"\t"<<NBadComponent[2][0][3];
00224   ss << "\nTEC:\t\t\t"<<NBadComponent[3][0][0]<<"\t"<<NBadComponent[3][0][1]<<"\t"<<NBadComponent[3][0][2]<<"\t"<<NBadComponent[3][0][3];
00225   ss << "\n";
00226 
00227   for (int i=1;i<5;++i)
00228     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];
00229   ss << "\n";
00230   for (int i=1;i<4;++i)
00231     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];
00232   for (int i=4;i<7;++i)
00233     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];
00234   ss << "\n";
00235   for (int i=1;i<7;++i)
00236     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];
00237   ss << "\n";
00238   for (int i=1;i<10;++i)
00239     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];
00240   for (int i=10;i<19;++i)
00241     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];
00242   ss<< "\n";
00243 
00244   ss << "\n----------------------------------------------------------------\n\t\t   Detid  \tModules Fibers Apvs\n----------------------------------------------------------------";
00245   for (int i=1;i<5;++i)
00246     ss << "\nTIB Layer " << i << " :" << ssV[0][i].str();
00247   ss << "\n";
00248   for (int i=1;i<4;++i)
00249     ss << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
00250   for (int i=4;i<7;++i)
00251     ss << "\nTID- Disk " << i-3 << " :" << ssV[1][i].str();
00252   ss << "\n";
00253   for (int i=1;i<7;++i)
00254     ss << "\nTOB Layer " << i << " :" << ssV[2][i].str();
00255   ss << "\n";
00256   for (int i=1;i<10;++i)
00257     ss << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
00258   for (int i=10;i<19;++i)
00259     ss << "\nTEC- Disk " << i-9 << " :" << ssV[3][i].str();
00260 
00261 
00262   edm::LogInfo("SiStripQualityStatistics") << ss.str() << std::endl;
00263 
00264   std::string filetype=TkMapFileName_,filename=TkMapFileName_;
00265   std::stringstream sRun; sRun.str("");
00266   sRun << "_Run_"  << std::setw(6) << std::setfill('0')<< e.id().run() << std::setw(0) ;
00267     
00268   if (filename!=""){
00269     filename.insert(filename.find("."),sRun.str());
00270     tkMap->save(true,0,0,filename.c_str());
00271     filename.erase(filename.begin()+filename.find("."),filename.end());
00272     tkMap->print(true,0,0,filename.c_str());
00273   }
00274 }
00275 
00276 
00277 void SiStripQualityStatistics::SetBadComponents(int i, int component,SiStripQuality::BadComponent& BC){
00278 
00279   int napv=reader->getNumberOfApvsAndStripLength(BC.detid).first;
00280 
00281   ssV[i][component] << "\n\t\t " 
00282                     << BC.detid 
00283                     << " \t " << BC.BadModule << " \t " 
00284                     << ( (BC.BadFibers)&0x1 ) << " ";
00285   if (napv==4)
00286     ssV[i][component] << "x " <<( (BC.BadFibers>>1)&0x1 );
00287   
00288   if (napv==6)
00289     ssV[i][component] << ( (BC.BadFibers>>1)&0x1 ) << " "
00290                       << ( (BC.BadFibers>>2)&0x1 );
00291   ssV[i][component] << " \t " 
00292                     << ( (BC.BadApvs)&0x1 ) << " " 
00293                     << ( (BC.BadApvs>>1)&0x1 ) << " ";
00294   if (napv==4) 
00295     ssV[i][component] << "x x " << ( (BC.BadApvs>>2)&0x1 ) << " " 
00296                       << ( (BC.BadApvs>>3)&0x1 );
00297   if (napv==6) 
00298     ssV[i][component] << ( (BC.BadApvs>>2)&0x1 ) << " " 
00299                       << ( (BC.BadApvs>>3)&0x1 ) << " " 
00300                       << ( (BC.BadApvs>>4)&0x1 ) << " " 
00301                       << ( (BC.BadApvs>>5)&0x1 ) << " "; 
00302 
00303   if (BC.BadApvs){
00304     NBadComponent[i][0][2]+= ( (BC.BadApvs>>5)&0x1 )+ ( (BC.BadApvs>>4)&0x1 ) + ( (BC.BadApvs>>3)&0x1 ) + 
00305       ( (BC.BadApvs>>2)&0x1 )+ ( (BC.BadApvs>>1)&0x1 ) + ( (BC.BadApvs)&0x1 );
00306     NBadComponent[i][component][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     tkMap->fillc(BC.detid,0xff0000);
00309   }
00310   if (BC.BadFibers){ 
00311     NBadComponent[i][0][1]+= ( (BC.BadFibers>>2)&0x1 )+ ( (BC.BadFibers>>1)&0x1 ) + ( (BC.BadFibers)&0x1 );
00312     NBadComponent[i][component][1]+= ( (BC.BadFibers>>2)&0x1 )+ ( (BC.BadFibers>>1)&0x1 ) + ( (BC.BadFibers)&0x1 );
00313     tkMap->fillc(BC.detid,0x0000ff);
00314   }   
00315   if (BC.BadModule){
00316     NBadComponent[i][0][0]++;
00317     NBadComponent[i][component][0]++;
00318     tkMap->fillc(BC.detid,0x0);
00319   }
00320 }