CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/CondFormats/SiPixelObjects/src/SiPixelQuality.cc

Go to the documentation of this file.
00001 // SiPixelQuality.cc
00002 //
00003 // class implementation to hold a list of disabled pixel modules
00004 //
00005 // M. Eads
00006 // Apr 2008
00007 
00008 #include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h"
00009 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameReverter.h"
00010 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h"
00011 #include "DataFormats/Common/interface/Handle.h"
00012 #include "FWCore/Framework/interface/ESHandle.h"
00013 #include "FWCore/Framework/interface/ESWatcher.h"
00014 #include "CondFormats/DataRecord/interface/SiPixelFedCablingMapRcd.h"
00015 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h"
00016 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h"
00017 #include "CondFormats/SiPixelObjects/interface/PixelROC.h"
00018 #include "CondFormats/SiPixelObjects/interface/LocalPixel.h"
00019 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00020 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00021 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00022 
00023 
00024 #include <algorithm>
00025 #include <iostream>
00026 
00027 
00028 using namespace sipixelobjects;
00029 
00030 
00032       //  errortype "whole" = int 0 in DB //
00033       //  errortype "tbmA" = int 1 in DB  //
00034       //  errortype "tbmB" = int 2 in DB  //
00035       //  errortype "none" = int 3 in DB  //
00037     
00039       //each bad roc correspond to a bit to 1: num=  //
00040       // 0 <-> all good rocs                         //
00041       // 1 <-> only roc 0 bad                        //
00042       // 2<-> only roc 1 bad                         //
00043       // 3<->  roc 0 and 1 bad                       //
00044       // 4 <-> only roc 2 bad                        //
00045       //  ...                                        //
00047 
00048 
00049 // add a list of modules to the vector of disabled modules
00050 void SiPixelQuality::addDisabledModule(std::vector<SiPixelQuality::disabledModuleType> & idVector) {
00051   theDisabledModules.insert(theDisabledModules.end(),
00052                             idVector.begin(),
00053                             idVector.end());
00054 
00055 } 
00056 
00057 void SiPixelQuality::add(const SiStripDetVOff* Voff) {
00058   
00059   //Get vector of Voff dets
00060   std::vector<uint32_t> vdets;
00061   Voff->getDetIds(vdets);
00062 
00063   std::vector<uint32_t>::const_iterator iter=vdets.begin();
00064   std::vector<uint32_t>::const_iterator iterEnd=vdets.end();
00065 
00066   for(;iter!=iterEnd;++iter){
00067     SiPixelQuality::disabledModuleType BadModule;  
00068     BadModule.DetID = *iter;
00069     BadModule.errorType = 0;
00070     BadModule.BadRocs = 65535; //NOTE: here all module is bad - no difference for half modules
00071     if(IsModuleUsable(BadModule.DetID))
00072       addDisabledModule(BadModule);
00073     
00074   }
00075 }
00076 
00077 // bool SiPixelQuality::removeDisabledModule(const uint32_t & detid){
00078 //   std::vector<disabledModuleType>::const_iterator iter = std::lower_bound(theDisabledModules.begin(),theDisabledModules.end(),detid,SiPixelQuality::BadComponentStrictWeakOrdering());
00079 //   if (iter != theDisabledModules.end() && iter->DetID==detid){
00080 //     theDisabledModules.erase(iter);
00081 //     return true;
00082 //   }
00083 //   return false;
00084 // }
00085 
00086 // ask if module is OK
00087 bool SiPixelQuality::IsModuleUsable(const uint32_t& detid) const {
00088    if(IsFedBad(detid))
00089      return true;
00090    std::vector<SiPixelQuality::disabledModuleType>disabledModules = theDisabledModules;
00091    std::sort(disabledModules.begin(),disabledModules.end(),SiPixelQuality::BadComponentStrictWeakOrdering());
00092    std::vector<disabledModuleType>::const_iterator iter = std::lower_bound(disabledModules.begin(),disabledModules.end(),detid,SiPixelQuality::BadComponentStrictWeakOrdering());
00093    if (iter != disabledModules.end() && iter->DetID==detid && iter->errorType ==0)
00094     return false;
00095   return true;
00096 }
00097 
00098 int SiPixelQuality::BadModuleNumber() {
00099   std::vector<SiPixelQuality::disabledModuleType>disabledModules = theDisabledModules;
00100   //does not distinguish between partially dead or not 
00101   return disabledModules.size();
00102 }
00103 
00104 //ask if module is bad
00105  bool SiPixelQuality::IsModuleBad(const uint32_t & detid) const {
00106    if(IsFedBad(detid))
00107      return true;
00108    std::vector<SiPixelQuality::disabledModuleType>disabledModules = theDisabledModules;
00109    std::sort(disabledModules.begin(),disabledModules.end(),SiPixelQuality::BadComponentStrictWeakOrdering());
00110    std::vector<disabledModuleType>::const_iterator iter = std::lower_bound(disabledModules.begin(),disabledModules.end(),detid,SiPixelQuality::BadComponentStrictWeakOrdering());
00111    if (iter != disabledModules.end() && iter->DetID==detid && iter->errorType == 0) //errorType 0 corresponds to "whole" dead module
00112       return true;
00113    return false;
00114 }
00115 
00116 //ask if roc is bad
00117 bool SiPixelQuality::IsRocBad(const uint32_t& detid, const short& rocNb) const {
00118   if(IsModuleBad(detid))
00119     return true;
00120    std::vector<SiPixelQuality::disabledModuleType>disabledModules = theDisabledModules;
00121    std::sort(disabledModules.begin(),disabledModules.end(),SiPixelQuality::BadComponentStrictWeakOrdering());
00122    std::vector<disabledModuleType>::const_iterator iter = std::lower_bound(disabledModules.begin(),disabledModules.end(),detid,SiPixelQuality::BadComponentStrictWeakOrdering());
00123    if (iter != disabledModules.end() && iter->DetID == detid){
00124      return ((iter->BadRocs >> rocNb)&0x1);}
00125   return false;
00126 }
00127 
00128 bool SiPixelQuality::IsAreaBad(uint32_t detid, sipixelobjects::GlobalPixel global, const edm::EventSetup& es, const SiPixelFedCabling* map ) const {
00129  
00130   SiPixelFrameReverter reverter(es,map);
00131   int rocfromarea = -1;  
00132   rocfromarea = reverter.findRocInDet(detid, global);
00133 
00134   return SiPixelQuality::IsRocBad(detid, rocfromarea);
00135   return false;
00136 }
00137 
00138 //ask for bad ROCS
00139 
00140 
00141 short SiPixelQuality::getBadRocs(const uint32_t& detid) const{
00142   std::vector<SiPixelQuality::disabledModuleType>disabledModules = theDisabledModules;
00143   std::sort(disabledModules.begin(),disabledModules.end(),SiPixelQuality::BadComponentStrictWeakOrdering());
00144   std::vector<disabledModuleType>::const_iterator iter = std::lower_bound(disabledModules.begin(),disabledModules.end(),detid,SiPixelQuality::BadComponentStrictWeakOrdering());
00145   if (iter != disabledModules.end() && iter->DetID==detid)
00146     return iter->BadRocs;
00147   return 0;
00148 }
00149 
00150 const std::vector<LocalPoint> SiPixelQuality::getBadRocPositions(const uint32_t & detid, const TrackerGeometry& theTracker, const SiPixelFedCabling* map) const{
00151   std::vector<LocalPoint> badrocpositions (0);
00152   std::pair<uint8_t, uint8_t> coord(1,1);
00153    for(unsigned int i = 0; i < 16; i++){
00154      if (IsRocBad(detid, i) == true){
00155     std::vector<CablingPathToDetUnit> path = map->pathToDetUnit(detid);
00156     typedef  std::vector<CablingPathToDetUnit>::const_iterator IT;
00157        for  (IT it = path.begin(); it != path.end(); ++it) {
00158           const PixelROC * myroc = map->findItem(*it);
00159           if( myroc->idInDetUnit() == i) {
00160               LocalPixel::RocRowCol  local = { 39, 25};   //corresponding to center of ROC row, col
00161               GlobalPixel global = myroc->toGlobal( LocalPixel(local) );
00162               //       edm::ESHandle<TrackerGeometry> geom;
00163               //     es.get<TrackerDigiGeometryRecord>().get( geom );
00164               //    const TrackerGeometry& theTracker(*geom);
00165               const PixelGeomDetUnit * theGeomDet = dynamic_cast<const PixelGeomDetUnit*> (theTracker.idToDet(detid) );
00166 
00167               PixelTopology const * topology = &(theGeomDet->specificTopology());
00168 
00169               MeasurementPoint thepoint(global.row, global.col);
00170               LocalPoint localpoint = topology->localPosition(thepoint);
00171               badrocpositions.push_back(localpoint);
00172          break;
00173           }
00174        }
00175      }
00176    }
00177   return badrocpositions;
00178 }
00179 
00180 
00181 bool SiPixelQuality::IsFedBad(const uint32_t & detid) const{
00182   return false;
00183 }
00184 
00185 
00186