CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/CalibTracker/SiStripESProducers/src/SiStripBadModuleGenerator.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripESProducers/interface/SiStripBadModuleGenerator.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include <boost/cstdint.hpp>
00004 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00005 #include "FWCore/ParameterSet/interface/FileInPath.h"
00006 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00007 
00008 #include "DataFormats/SiStripDetId/interface/SiStripSubStructure.h"
00009 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00010 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00011 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00012 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00013 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00014 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00015 
00016 SiStripBadModuleGenerator::SiStripBadModuleGenerator(const edm::ParameterSet& iConfig,const edm::ActivityRegistry& aReg):
00017   SiStripCondObjBuilderBase<SiStripBadStrip>::SiStripCondObjBuilderBase(iConfig)
00018 {
00019   edm::LogInfo("SiStripBadModuleGenerator") <<  "[SiStripBadModuleGenerator::SiStripBadModuleGenerator]";
00020 }
00021 
00022 
00023 SiStripBadModuleGenerator::~SiStripBadModuleGenerator() { 
00024   edm::LogInfo("SiStripBadModuleGenerator") <<  "[SiStripBadModuleGenerator::~SiStripBadModuleGenerator]";
00025 }
00026 
00027 
00028 void SiStripBadModuleGenerator::createObject(){
00029     
00030   SiStripQuality* obj  = new SiStripQuality();
00031 
00032   edm::FileInPath fp_           = _pset.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"));
00033   printdebug_             = _pset.getUntrackedParameter<bool>("printDebug",false);
00034   BadComponentList_            =  _pset.getUntrackedParameter<Parameters>("BadComponentList");
00035 
00036 
00037   SiStripDetInfoFileReader reader(fp_.fullPath());   
00038   const std::vector<uint32_t>& DetIds= reader.getAllDetIds();
00039   std::vector<uint32_t> selDetIds;
00040   selectDetectors(DetIds,selDetIds);
00041 
00042   edm::LogInfo("SiStripQualityConfigurableFakeESSource")<<"[produce] number of selected dets to be removed " << selDetIds.size() <<std::endl;
00043 
00044   std::stringstream ss;  
00045   std::vector<uint32_t>::const_iterator iter=selDetIds.begin();
00046   std::vector<uint32_t>::const_iterator iterEnd=selDetIds.end();
00047   for(;iter!=iterEnd;++iter){
00048     
00049     SiStripQuality::InputVector theSiStripVector;
00050     
00051     unsigned short firstBadStrip=0, NconsecutiveBadStrips=reader.getNumberOfApvsAndStripLength(*iter).first * 128;
00052     unsigned int theBadStripRange;
00053     
00054     theBadStripRange = obj->encode(firstBadStrip,NconsecutiveBadStrips);
00055     
00056     if (printdebug_)
00057       ss << "detid " << *iter << " \t"
00058          << " firstBadStrip " << firstBadStrip << "\t "
00059          << " NconsecutiveBadStrips " << NconsecutiveBadStrips << "\t "
00060          << " packed integer " << std::hex << theBadStripRange  << std::dec
00061          << std::endl;      
00062     
00063     theSiStripVector.push_back(theBadStripRange);
00064     
00065     SiStripBadStrip::Range range(theSiStripVector.begin(),theSiStripVector.end());
00066     if ( ! obj->put(*iter,range) )
00067       edm::LogError("SiStripQualityConfigurableFakeESSource")<<"[produce] detid already exists"<<std::endl;
00068   }
00069   if (printdebug_)
00070     edm::LogInfo("SiStripQualityConfigurableFakeESSource") << ss.str();
00071   
00072   obj->cleanUp();
00073   //obj->fillBadComponents();
00074 
00075   std::stringstream ss1;
00076   if (printdebug_){
00077     for (std::vector<SiStripQuality::BadComponent>::const_iterator iter=obj->getBadComponentList().begin();iter!=obj->getBadComponentList().end();++iter)
00078       ss1 << "bad module " << iter->detid << " " << iter->BadModule <<  "\n";
00079     edm::LogInfo("SiStripQualityConfigurableFakeESSource") << ss1.str();
00080   }
00081 
00082   obj_ = new SiStripBadStrip( *(dynamic_cast<SiStripBadStrip*> (obj)));
00083   delete obj;
00084 }
00085 
00086 
00087 void SiStripBadModuleGenerator::selectDetectors(const std::vector<uint32_t>& DetIds, std::vector<uint32_t>& list){
00088 
00089   SiStripSubStructure siStripSubStructure;
00090   std::stringstream ss;
00091 
00092   for(Parameters::iterator iBadComponent = BadComponentList_.begin(); iBadComponent != BadComponentList_.end(); ++iBadComponent ) {
00093     
00094     if (printdebug_)
00095       ss << "Bad SubDet " << iBadComponent->getParameter<std::string>("SubDet") << " \t";
00096 
00097     SiStripDetId::SubDetector subDet=SiStripDetId::UNKNOWN;
00098     if (iBadComponent->getParameter<std::string>("SubDet")=="TIB")
00099       subDet=SiStripDetId::TIB;
00100     else if (iBadComponent->getParameter<std::string>("SubDet")=="TID")
00101       subDet=SiStripDetId::TID;
00102     else if (iBadComponent->getParameter<std::string>("SubDet")=="TOB")
00103       subDet=SiStripDetId::TOB;
00104     else if (iBadComponent->getParameter<std::string>("SubDet")=="TEC")
00105       subDet=SiStripDetId::TEC;
00106     std::vector<uint32_t> genericBadDetIds( iBadComponent->getUntrackedParameter<std::vector<uint32_t> >("detidList", std::vector<uint32_t>()) );
00107     
00108     bool anySubDet = true;
00109     if( genericBadDetIds.empty() ) anySubDet = false;
00110 
00111     std::cout << "genericBadDetIds.size() = " << genericBadDetIds.size() << std::endl;
00112 
00113     uint32_t startDet=DetId(DetId::Tracker,subDet).rawId();
00114     uint32_t stopDet=DetId(DetId::Tracker,subDet+1).rawId();
00115 
00116     if( anySubDet ) {
00117       startDet=DetId(DetId::Tracker,SiStripDetId::TIB).rawId();
00118       stopDet=DetId(DetId::Tracker,SiStripDetId::TEC+1).rawId();      
00119     }
00120 
00121     std::vector<uint32_t>::const_iterator iter=lower_bound(DetIds.begin(),DetIds.end(),startDet);
00122     std::vector<uint32_t>::const_iterator iterEnd=lower_bound(DetIds.begin(),DetIds.end(),stopDet);
00123 
00124     bool resp;
00125     for ( ;iter!=iterEnd;++iter){
00126 
00127       resp=false;
00128       if (iBadComponent->getParameter<std::string>("SubDet")=="TIB")
00129         resp=isTIBDetector(*iter,
00130                            iBadComponent->getParameter<uint32_t>("layer"),
00131                            iBadComponent->getParameter<uint32_t>("bkw_frw"),
00132                            iBadComponent->getParameter<uint32_t>("int_ext"),
00133                            iBadComponent->getParameter<uint32_t>("ster"),
00134                            iBadComponent->getParameter<uint32_t>("string_"),
00135                            iBadComponent->getParameter<uint32_t>("detid")
00136                            );
00137       else if (iBadComponent->getParameter<std::string>("SubDet")=="TID")
00138         resp=isTIDDetector(*iter,
00139                            iBadComponent->getParameter<uint32_t>("side"),
00140                            iBadComponent->getParameter<uint32_t>("wheel"),
00141                            iBadComponent->getParameter<uint32_t>("ring"),
00142                            iBadComponent->getParameter<uint32_t>("ster"),
00143                            iBadComponent->getParameter<uint32_t>("detid")
00144                            );
00145       else if (iBadComponent->getParameter<std::string>("SubDet")=="TOB")
00146         resp=isTOBDetector(*iter,
00147                            iBadComponent->getParameter<uint32_t>("layer"),
00148                            iBadComponent->getParameter<uint32_t>("bkw_frw"),
00149                            iBadComponent->getParameter<uint32_t>("rod"),
00150                            iBadComponent->getParameter<uint32_t>("ster"),
00151                            iBadComponent->getParameter<uint32_t>("detid")
00152                            );
00153       else if (iBadComponent->getParameter<std::string>("SubDet")=="TEC")
00154         resp=isTECDetector(*iter,
00155                            iBadComponent->getParameter<uint32_t>("side"),
00156                            iBadComponent->getParameter<uint32_t>("wheel"),
00157                            iBadComponent->getParameter<uint32_t>("petal_bkw_frw"),
00158                            iBadComponent->getParameter<uint32_t>("petal"),
00159                            iBadComponent->getParameter<uint32_t>("ring"),
00160                            iBadComponent->getParameter<uint32_t>("ster"),
00161                            iBadComponent->getParameter<uint32_t>("detid")
00162                            );
00163       if( anySubDet ) {
00164         std::cout << "AnySubDet" << *iter << std::endl;
00165         if( std::find(genericBadDetIds.begin(), genericBadDetIds.end(), *iter) == genericBadDetIds.end() ) resp = false;
00166         else resp = true;
00167       }
00168    
00169       if(resp)
00170         list.push_back(*iter);      
00171     }
00172   }
00173   if (printdebug_)
00174     edm::LogInfo("SiStripBadModuleGenerator") << ss.str();
00175 }
00176 
00177 
00178 bool SiStripBadModuleGenerator::isTIBDetector(const uint32_t & therawid,
00179                                                            uint32_t requested_layer,
00180                                                            uint32_t requested_bkw_frw,
00181                                                            uint32_t requested_int_ext,
00182                                                            uint32_t requested_string,
00183                                                            uint32_t requested_ster,
00184                                                            uint32_t requested_detid) const{
00185   TIBDetId potentialDet = TIBDetId(therawid); // build TIBDetId, at this point is just DetId, but do not want to cast twice
00186   if( potentialDet.subDetector() ==  SiStripDetId::TIB ){ // check if subdetector field is a TIB, both tested numbers are int
00187     if( // check if TIB is from the ones requested
00188        (    (potentialDet.layerNumber()==requested_layer) || requested_layer==0 )  // take everything if default value is 0
00189        &&
00190        ( (potentialDet.isZPlusSide() && requested_bkw_frw==2) || (!potentialDet.isZPlusSide() && requested_bkw_frw==1) || requested_bkw_frw==0)
00191        &&
00192        ( (potentialDet.isInternalString() && requested_int_ext==1) || (!potentialDet.isInternalString() && requested_int_ext==2) || requested_int_ext==0 )
00193        && 
00194        ( (potentialDet.isStereo() && requested_ster==1) || (potentialDet.isRPhi() && requested_ster==2) || requested_ster==0 )
00195        && 
00196        ( (potentialDet.stringNumber()==requested_string) || requested_string==0 )
00197        &&
00198        ( (potentialDet.rawId()==requested_detid) || requested_detid==0 )
00199        )
00200       return 1;
00201   }
00202   return 0;
00203 }
00204 
00205 bool SiStripBadModuleGenerator::isTOBDetector(const uint32_t & therawid,
00206                                                            uint32_t requested_layer,
00207                                                            uint32_t requested_bkw_frw,
00208                                                            uint32_t requested_rod,
00209                                                            uint32_t requested_ster,
00210                                                            uint32_t requested_detid) const{
00211   TOBDetId potentialDet = TOBDetId(therawid); // build TOBDetId, at this point is just DetId, but do not want to cast twice
00212   if( potentialDet.subDetector() ==  SiStripDetId::TOB ){ // check if subdetector field is a TOB, both tested numbers are int
00213     if( // check if TOB is from the ones requested
00214        (    (potentialDet.layerNumber()==requested_layer) || requested_layer==0 )  // take everything if default value is 0
00215        &&
00216        ( (potentialDet.isZPlusSide() && requested_bkw_frw==2) || (!potentialDet.isZPlusSide() && requested_bkw_frw==1) || requested_bkw_frw==0)
00217        &&
00218        ( (potentialDet.isStereo() && requested_ster==1) || (potentialDet.isRPhi() && requested_ster==2) || requested_ster==0 )
00219        && 
00220        ( (potentialDet.rodNumber()==requested_rod) || requested_rod==0 )
00221        &&
00222        ( (potentialDet.rawId()==requested_detid) || requested_detid==0 )   
00223        )
00224       return 1;
00225   }
00226   return 0;
00227 }
00228 
00229 
00230 bool SiStripBadModuleGenerator::isTIDDetector(const uint32_t & therawid,
00231                                                            uint32_t requested_side,
00232                                                            uint32_t requested_wheel,
00233                                                            uint32_t requested_ring,
00234                                                            uint32_t requested_ster,
00235                                                            uint32_t requested_detid) const{
00236   TIDDetId potentialDet = TIDDetId(therawid); // build TIDDetId, at this point is just DetId, but do not want to cast twice
00237   if( potentialDet.subDetector() ==  SiStripDetId::TID ){ // check if subdetector field is a TID, both tested numbers are int 
00238     if( // check if TID is from the ones requested 
00239      (    (potentialDet.diskNumber()==requested_wheel) || requested_wheel==0 )  // take everything if default value is 0 
00240      &&
00241      ( (potentialDet.isZPlusSide() && requested_side==2) || (!potentialDet.isZPlusSide() && requested_side==1) || requested_side==0)
00242      &&
00243      ( (potentialDet.isStereo() && requested_ster==1) || (potentialDet.isRPhi() && requested_ster==2) || requested_ster==0 )
00244      &&
00245      ( (potentialDet.ringNumber()==requested_ring) || requested_ring==0 )
00246      &&
00247      ( (potentialDet.rawId()==requested_detid) || requested_detid==0 )
00248      )
00249      return 1;
00250      }
00251   return 0;
00252 }
00253   
00254 
00255 bool SiStripBadModuleGenerator::isTECDetector(const uint32_t & therawid,
00256                                                            uint32_t requested_side,
00257                                                            uint32_t requested_wheel,
00258                                                            uint32_t requested_petal_bkw_frw,
00259                                                            uint32_t requested_petal,                    
00260                                                            uint32_t requested_ring,
00261                                                            uint32_t requested_ster,
00262                                                            uint32_t requested_detid) const{
00263   TECDetId potentialDet = TECDetId(therawid); // build TECDetId, at this point is just DetId, but do not want to cast twice
00264   if( potentialDet.subDetector() ==  SiStripDetId::TEC ){ // check if subdetector field is a TEC, both tested numbers are int 
00265     if( // check if TEC is from the ones requested 
00266        (    (potentialDet.wheelNumber()==requested_wheel) || requested_wheel==0 )  // take everything if default value is 0 
00267        &&
00268        ( (potentialDet.isZPlusSide() && requested_side==2) || (!potentialDet.isZPlusSide() && requested_side==1) || requested_side==0)
00269        &&
00270        ( (potentialDet.isStereo() && requested_ster==1) || (!potentialDet.isStereo() && requested_ster==2) || requested_ster==0 )
00271        &&
00272        ( (potentialDet.isFrontPetal() && requested_petal_bkw_frw==2) || (!potentialDet.isFrontPetal() && requested_petal_bkw_frw==2) || requested_petal_bkw_frw==0 )
00273        &&
00274        ( (potentialDet.petalNumber()==requested_petal) || requested_petal==0 )
00275        &&
00276        ( (potentialDet.ringNumber()==requested_ring) || requested_ring==0 )
00277        &&
00278        ( (potentialDet.rawId()==requested_detid) || requested_detid==0 )
00279        )
00280       return 1;
00281   }
00282   return 0;
00283 }
00284