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
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
00107 uint32_t startDet=DetId(DetId::Tracker,subDet).rawId();
00108 uint32_t stopDet=DetId(DetId::Tracker,subDet+1).rawId();
00109
00110 std::vector<uint32_t>::const_iterator iter=lower_bound(DetIds.begin(),DetIds.end(),startDet);
00111 std::vector<uint32_t>::const_iterator iterEnd=lower_bound(DetIds.begin(),DetIds.end(),stopDet);
00112
00113 bool resp;
00114 for ( ;iter!=iterEnd;++iter){
00115
00116 resp=false;
00117 if (iBadComponent->getParameter<std::string>("SubDet")=="TIB")
00118 resp=isTIBDetector(*iter,
00119 iBadComponent->getParameter<uint32_t>("layer"),
00120 iBadComponent->getParameter<uint32_t>("bkw_frw"),
00121 iBadComponent->getParameter<uint32_t>("int_ext"),
00122 iBadComponent->getParameter<uint32_t>("ster"),
00123 iBadComponent->getParameter<uint32_t>("string_"),
00124 iBadComponent->getParameter<uint32_t>("detid")
00125 );
00126 else if (iBadComponent->getParameter<std::string>("SubDet")=="TID")
00127 resp=isTIDDetector(*iter,
00128 iBadComponent->getParameter<uint32_t>("side"),
00129 iBadComponent->getParameter<uint32_t>("wheel"),
00130 iBadComponent->getParameter<uint32_t>("ring"),
00131 iBadComponent->getParameter<uint32_t>("ster"),
00132 iBadComponent->getParameter<uint32_t>("detid")
00133 );
00134 else if (iBadComponent->getParameter<std::string>("SubDet")=="TOB")
00135 resp=isTOBDetector(*iter,
00136 iBadComponent->getParameter<uint32_t>("layer"),
00137 iBadComponent->getParameter<uint32_t>("bkw_frw"),
00138 iBadComponent->getParameter<uint32_t>("rod"),
00139 iBadComponent->getParameter<uint32_t>("ster"),
00140 iBadComponent->getParameter<uint32_t>("detid")
00141 );
00142 else if (iBadComponent->getParameter<std::string>("SubDet")=="TEC")
00143 resp=isTECDetector(*iter,
00144 iBadComponent->getParameter<uint32_t>("side"),
00145 iBadComponent->getParameter<uint32_t>("wheel"),
00146 iBadComponent->getParameter<uint32_t>("petal_bkw_frw"),
00147 iBadComponent->getParameter<uint32_t>("petal"),
00148 iBadComponent->getParameter<uint32_t>("ring"),
00149 iBadComponent->getParameter<uint32_t>("ster"),
00150 iBadComponent->getParameter<uint32_t>("detid")
00151 );
00152
00153 if(resp)
00154 list.push_back(*iter);
00155 }
00156 }
00157 if (printdebug_)
00158 edm::LogInfo("SiStripBadModuleGenerator") << ss.str();
00159 }
00160
00161
00162 bool SiStripBadModuleGenerator::isTIBDetector(const uint32_t & therawid,
00163 uint32_t requested_layer,
00164 uint32_t requested_bkw_frw,
00165 uint32_t requested_int_ext,
00166 uint32_t requested_string,
00167 uint32_t requested_ster,
00168 uint32_t requested_detid) const{
00169 TIBDetId potentialDet = TIBDetId(therawid);
00170 if( potentialDet.subDetector() == SiStripDetId::TIB ){
00171 if(
00172 ( (potentialDet.layerNumber()==requested_layer) || requested_layer==0 )
00173 &&
00174 ( (potentialDet.isZPlusSide() && requested_bkw_frw==2) || (!potentialDet.isZPlusSide() && requested_bkw_frw==1) || requested_bkw_frw==0)
00175 &&
00176 ( (potentialDet.isInternalString() && requested_int_ext==1) || (!potentialDet.isInternalString() && requested_int_ext==2) || requested_int_ext==0 )
00177 &&
00178 ( (potentialDet.isStereo() && requested_ster==1) || (potentialDet.isRPhi() && requested_ster==2) || requested_ster==0 )
00179 &&
00180 ( (potentialDet.stringNumber()==requested_string) || requested_string==0 )
00181 &&
00182 ( (potentialDet.rawId()==requested_detid) || requested_detid==0 )
00183 )
00184 return 1;
00185 }
00186 return 0;
00187 }
00188
00189 bool SiStripBadModuleGenerator::isTOBDetector(const uint32_t & therawid,
00190 uint32_t requested_layer,
00191 uint32_t requested_bkw_frw,
00192 uint32_t requested_rod,
00193 uint32_t requested_ster,
00194 uint32_t requested_detid) const{
00195 TOBDetId potentialDet = TOBDetId(therawid);
00196 if( potentialDet.subDetector() == SiStripDetId::TOB ){
00197 if(
00198 ( (potentialDet.layerNumber()==requested_layer) || requested_layer==0 )
00199 &&
00200 ( (potentialDet.isZPlusSide() && requested_bkw_frw==2) || (!potentialDet.isZPlusSide() && requested_bkw_frw==1) || requested_bkw_frw==0)
00201 &&
00202 ( (potentialDet.isStereo() && requested_ster==1) || (potentialDet.isRPhi() && requested_ster==2) || requested_ster==0 )
00203 &&
00204 ( (potentialDet.rodNumber()==requested_rod) || requested_rod==0 )
00205 &&
00206 ( (potentialDet.rawId()==requested_detid) || requested_detid==0 )
00207 )
00208 return 1;
00209 }
00210 return 0;
00211 }
00212
00213
00214 bool SiStripBadModuleGenerator::isTIDDetector(const uint32_t & therawid,
00215 uint32_t requested_side,
00216 uint32_t requested_wheel,
00217 uint32_t requested_ring,
00218 uint32_t requested_ster,
00219 uint32_t requested_detid) const{
00220 TIDDetId potentialDet = TIDDetId(therawid);
00221 if( potentialDet.subDetector() == SiStripDetId::TID ){
00222 if(
00223 ( (potentialDet.diskNumber()==requested_wheel) || requested_wheel==0 )
00224 &&
00225 ( (potentialDet.isZPlusSide() && requested_side==2) || (!potentialDet.isZPlusSide() && requested_side==1) || requested_side==0)
00226 &&
00227 ( (potentialDet.isStereo() && requested_ster==1) || (potentialDet.isRPhi() && requested_ster==2) || requested_ster==0 )
00228 &&
00229 ( (potentialDet.ringNumber()==requested_ring) || requested_ring==0 )
00230 &&
00231 ( (potentialDet.rawId()==requested_detid) || requested_detid==0 )
00232 )
00233 return 1;
00234 }
00235 return 0;
00236 }
00237
00238
00239 bool SiStripBadModuleGenerator::isTECDetector(const uint32_t & therawid,
00240 uint32_t requested_side,
00241 uint32_t requested_wheel,
00242 uint32_t requested_petal_bkw_frw,
00243 uint32_t requested_petal,
00244 uint32_t requested_ring,
00245 uint32_t requested_ster,
00246 uint32_t requested_detid) const{
00247 TECDetId potentialDet = TECDetId(therawid);
00248 if( potentialDet.subDetector() == SiStripDetId::TEC ){
00249 if(
00250 ( (potentialDet.wheelNumber()==requested_wheel) || requested_wheel==0 )
00251 &&
00252 ( (potentialDet.isZPlusSide() && requested_side==2) || (!potentialDet.isZPlusSide() && requested_side==1) || requested_side==0)
00253 &&
00254 ( (potentialDet.isStereo() && requested_ster==1) || (!potentialDet.isStereo() && requested_ster==2) || requested_ster==0 )
00255 &&
00256 ( (potentialDet.isFrontPetal() && requested_petal_bkw_frw==2) || (!potentialDet.isFrontPetal() && requested_petal_bkw_frw==2) || requested_petal_bkw_frw==0 )
00257 &&
00258 ( (potentialDet.petalNumber()==requested_petal) || requested_petal==0 )
00259 &&
00260 ( (potentialDet.ringNumber()==requested_ring) || requested_ring==0 )
00261 &&
00262 ( (potentialDet.rawId()==requested_detid) || requested_detid==0 )
00263 )
00264 return 1;
00265 }
00266 return 0;
00267 }
00268