00001 #include "DQMOffline/CalibTracker/plugins/SiStripQualityHotStripIdentifierRoot.h"
00002
00003 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00004
00005 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
00006 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
00007 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
00008 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00009 #include "DataFormats/TrackReco/interface/Track.h"
00010 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00011
00012 #include <iostream>
00013 #include <fstream>
00014 #include <sstream>
00015
00016
00017 #include "CalibTracker/SiStripQuality/interface/SiStripHotStripAlgorithmFromClusterOccupancy.h"
00018 #include "CalibTracker/SiStripQuality/interface/SiStripBadAPVAlgorithmFromClusterOccupancy.h"
00019 #include "CalibTracker/SiStripQuality/interface/SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy.h"
00020
00021
00022 SiStripQualityHotStripIdentifierRoot::SiStripQualityHotStripIdentifierRoot(const edm::ParameterSet& iConfig) : ConditionDBWriter<SiStripBadStrip>(iConfig),
00023 m_cacheID_(0),
00024 dataLabel_(iConfig.getUntrackedParameter<std::string>("dataLabel","")),
00025 UseInputDB_(iConfig.getUntrackedParameter<bool>("UseInputDB",false)),
00026 conf_(iConfig),
00027 fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"))),
00028 _tracker(nullptr),
00029 tTopo(nullptr),
00030 filename(iConfig.getUntrackedParameter<std::string>("rootFilename","CondDB_TKCC_20X_v3_hlt_50822.root")),
00031 dirpath(iConfig.getUntrackedParameter<std::string>("rootDirPath","")),
00032 TotNumberOfEvents(0),
00033 calibrationthreshold(iConfig.getUntrackedParameter<uint32_t>("CalibrationThreshold",10000))
00034 {
00035 reader = new SiStripDetInfoFileReader(fp_.fullPath());
00036
00037 dqmStore_ = edm::Service<DQMStore>().operator->();
00038 dqmStore_->setVerbose(iConfig.getUntrackedParameter<uint32_t>("verbosity",0));
00039
00040 if(filename!=""){
00041 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " before opening file " << filename.c_str();
00042 dqmStore_->open(filename.c_str(), false);
00043 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " after opening file ";
00044 }
00045 }
00046
00047
00048 SiStripQualityHotStripIdentifierRoot::~SiStripQualityHotStripIdentifierRoot(){
00049 }
00050
00051 SiStripBadStrip* SiStripQualityHotStripIdentifierRoot::getNewObject(){
00052
00053 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<"SiStripQualityHotStripIdentifierRoot::getNewObject called"<<std::endl;
00054
00055 SiStripBadStrip* obj=new SiStripBadStrip();
00056
00057 edm::ParameterSet parameters=conf_.getParameter<edm::ParameterSet>("AlgoParameters");
00058 std::string AlgoName = parameters.getParameter<std::string>("AlgoName");
00059
00060 bookHistos();
00061
00062 if (TotNumberOfEvents>=calibrationthreshold)
00063 {
00064 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] Total number of events is " << TotNumberOfEvents << ". Calibration is launched." <<std::endl;
00065
00066 if (AlgoName=="SiStripHotStripAlgorithmFromClusterOccupancy")
00067 {
00068
00069 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call to SiStripHotStripAlgorithmFromClusterOccupancy"<<std::endl;
00070
00071 theIdentifier= new SiStripHotStripAlgorithmFromClusterOccupancy(conf_, tTopo);
00072 theIdentifier->setProbabilityThreshold(parameters.getUntrackedParameter<double>("ProbabilityThreshold",1.E-7));
00073 theIdentifier->setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries",100));
00074 theIdentifier->setMinNumEntriesPerStrip(parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip",5));
00075 theIdentifier->setOccupancyThreshold(parameters.getUntrackedParameter<double>("OccupancyThreshold",1.E-5));
00076 theIdentifier->setNumberOfEvents(TotNumberOfEvents);
00077 theIdentifier->setOutputFileName(conf_.getUntrackedParameter<std::string>("OccupancyRootFile","Occupancy.root"),conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile",false));
00078 theIdentifier->setTrackerGeometry(_tracker);
00079
00080 SiStripQuality* qobj = new SiStripQuality();
00081 theIdentifier->extractBadStrips(qobj,ClusterPositionHistoMap,SiStripQuality_);
00082
00083
00084
00085 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"<<std::endl;
00086
00087 std::stringstream ss;
00088
00089 SiStripBadStrip::RegistryIterator rIter=qobj->getRegistryVectorBegin();
00090 SiStripBadStrip::RegistryIterator rIterEnd=qobj->getRegistryVectorEnd();
00091 for(;rIter!=rIterEnd;++rIter){
00092 SiStripBadStrip::Range range(qobj->getDataVectorBegin()+rIter->ibegin,qobj->getDataVectorBegin()+rIter->iend);
00093 if ( ! obj->put(rIter->detid,range) )
00094 edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
00095 }
00096 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
00097 }
00098 else if (AlgoName=="SiStripBadAPVAlgorithmFromClusterOccupancy")
00099 {
00100
00101 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call to SiStripBadAPVAlgorithmFromClusterOccupancy"<<std::endl;
00102
00103 theIdentifier2 = new SiStripBadAPVAlgorithmFromClusterOccupancy(conf_, tTopo);
00104 theIdentifier2->setLowOccupancyThreshold(parameters.getUntrackedParameter<double>("LowOccupancyThreshold",5));
00105 theIdentifier2->setHighOccupancyThreshold(parameters.getUntrackedParameter<double>("HighOccupancyThreshold",10));
00106 theIdentifier2->setAbsoluteLowThreshold(parameters.getUntrackedParameter<double>("AbsoluteLowThreshold",0));
00107 theIdentifier2->setNumberIterations(parameters.getUntrackedParameter<uint32_t>("NumberIterations",2));
00108 theIdentifier2->setAbsoluteOccupancyThreshold(parameters.getUntrackedParameter<double>("OccupancyThreshold",1.E-5));
00109 theIdentifier2->setNumberOfEvents(TotNumberOfEvents);
00110 theIdentifier2->setMinNumOfEvents();
00111 theIdentifier2->setOutputFileName(conf_.getUntrackedParameter<std::string>("OccupancyRootFile","Occupancy.root"),conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile",false));
00112 theIdentifier2->setTrackerGeometry(_tracker);
00113
00114 SiStripQuality* qobj = new SiStripQuality();
00115 theIdentifier2->extractBadAPVs(qobj,ClusterPositionHistoMap,SiStripQuality_);
00116
00117
00118
00119 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"<<std::endl;
00120
00121 std::stringstream ss;
00122
00123 SiStripBadStrip::RegistryIterator rIter=qobj->getRegistryVectorBegin();
00124 SiStripBadStrip::RegistryIterator rIterEnd=qobj->getRegistryVectorEnd();
00125 for(;rIter!=rIterEnd;++rIter){
00126 SiStripBadStrip::Range range(qobj->getDataVectorBegin()+rIter->ibegin,qobj->getDataVectorBegin()+rIter->iend);
00127 if ( ! obj->put(rIter->detid,range) )
00128 edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
00129 }
00130 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
00131
00132
00133 }
00134 else if (AlgoName=="SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy")
00135 {
00136
00137 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call to SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy"<<std::endl;
00138
00139 theIdentifier3= new SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy(conf_, tTopo);
00140 theIdentifier3->setProbabilityThreshold(parameters.getUntrackedParameter<double>("ProbabilityThreshold",1.E-7));
00141 theIdentifier3->setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries",100));
00142 theIdentifier3->setMinNumEntriesPerStrip(parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip",5));
00143 theIdentifier3->setNumberOfEvents(TotNumberOfEvents);
00144 theIdentifier3->setMinNumOfEvents();
00145 theIdentifier3->setOutputFileName(conf_.getUntrackedParameter<std::string>("OccupancyRootFile","Occupancy.root"),conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile",false),conf_.getUntrackedParameter<std::string>("DQMHistoOutputFile","DQMHistos.root"),conf_.getUntrackedParameter<bool>("WriteDQMHistoOutputFile",false));
00146 theIdentifier3->setTrackerGeometry(_tracker);
00147 theIdentifier3->setLowOccupancyThreshold(parameters.getUntrackedParameter<double>("LowOccupancyThreshold",5));
00148 theIdentifier3->setHighOccupancyThreshold(parameters.getUntrackedParameter<double>("HighOccupancyThreshold",10));
00149 theIdentifier3->setAbsoluteLowThreshold(parameters.getUntrackedParameter<double>("AbsoluteLowThreshold",0));
00150 theIdentifier3->setNumberIterations(parameters.getUntrackedParameter<uint32_t>("NumberIterations",2));
00151 theIdentifier3->setAbsoluteOccupancyThreshold(parameters.getUntrackedParameter<double>("OccupancyThreshold",1.E-5));
00152
00153 SiStripQuality* qobj = new SiStripQuality();
00154 theIdentifier3->extractBadAPVSandStrips(qobj,ClusterPositionHistoMap,SiStripQuality_);
00155
00156
00157
00158 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"<<std::endl;
00159
00160 std::stringstream ss;
00161
00162 SiStripBadStrip::RegistryIterator rIter=qobj->getRegistryVectorBegin();
00163 SiStripBadStrip::RegistryIterator rIterEnd=qobj->getRegistryVectorEnd();
00164 for(;rIter!=rIterEnd;++rIter){
00165 SiStripBadStrip::Range range(qobj->getDataVectorBegin()+rIter->ibegin,qobj->getDataVectorBegin()+rIter->iend);
00166 if ( ! obj->put(rIter->detid,range) )
00167 edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
00168 }
00169 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
00170 }
00171 else
00172 {
00173 edm::LogError("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call for a unknow HotStrip identification algoritm"<<std::endl;
00174
00175 std::vector<uint32_t> a;
00176 SiStripBadStrip::Range range(a.begin(),a.end());
00177 if ( ! obj->put(0xFFFFFFFF,range) )
00178 edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
00179 }
00180 }
00181 else
00182 {
00183 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] Total number of events is " << TotNumberOfEvents << ", wich is below the threshold (" << calibrationthreshold << "). Calibration will NOT be launched." <<std::endl;
00184 setDoStore(false);
00185 }
00186
00187 return obj;
00188 }
00189
00190 void SiStripQualityHotStripIdentifierRoot::algoBeginRun(const edm::Run& iRun,const edm::EventSetup& iSetup){
00191
00192 edm::ESHandle<TrackerTopology> tTopoHandle;
00193 iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
00194 tTopo = tTopoHandle.product();
00195
00196 iSetup.get<TrackerDigiGeometryRecord> ().get (theTrackerGeom);
00197 _tracker=&(* theTrackerGeom);
00198
00199 if(UseInputDB_){
00200 unsigned long long cacheID = iSetup.get<SiStripQualityRcd>().cacheIdentifier();
00201
00202 if (m_cacheID_ == cacheID)
00203 return;
00204
00205 m_cacheID_ = cacheID;
00206
00207 iSetup.get<SiStripQualityRcd>().get(dataLabel_,SiStripQuality_);
00208 }
00209 }
00210
00211 void SiStripQualityHotStripIdentifierRoot::algoEndJob(){
00212
00213 ClusterPositionHistoMap.clear();
00214 }
00215
00216
00217 void SiStripQualityHotStripIdentifierRoot::bookHistos(){
00218 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::bookHistos] " << dirpath << std::endl;
00219 std::vector<MonitorElement*> MEs = dqmStore_->getAllContents(dirpath);
00220
00221
00222 edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::bookHistos] vector size " << MEs.size()<< std::endl;
00223
00224 std::vector<MonitorElement*>::const_iterator iter=MEs.begin();
00225 std::vector<MonitorElement*>::const_iterator iterEnd=MEs.end();
00226
00227 edm::ParameterSet parameters=conf_.getParameter<edm::ParameterSet>("AlgoParameters");
00228 bool gotNentries=true;
00229 if( parameters.getUntrackedParameter<uint32_t>("NumberOfEvents",0)==0 && parameters.getUntrackedParameter<double>("OccupancyThreshold",0)!=0)
00230 gotNentries=false;
00231 edm::LogInfo("SiStripQualityHotStripIdentifierRoot")<< "[SiStripQualityHotStripIdentifierRoot::bookHistos] gotNentries flag " << gotNentries
00232 << " number of " << parameters.getUntrackedParameter<uint32_t>("NumberOfEvents",0)
00233 << " occup " << parameters.getUntrackedParameter<double>("OccupancyThreshold",0)
00234 << " OccupancyHisto" << parameters.getUntrackedParameter<std::string>("OccupancyHisto") << std::endl;
00235
00236 for (; iter!=iterEnd;++iter) {
00237 std::string me_name = (*iter)->getName();
00238
00239 if (!gotNentries && strstr(me_name.c_str(),"TotalNumberOfCluster__T")!=NULL && strstr(me_name.c_str(),"Profile")==NULL ){
00240
00241 TotNumberOfEvents = ((TH1F*)(*iter)->getTH1F())->GetEntries();
00242 edm::LogInfo("SiStripQualityHotStripIdentifierRoot")<< "Total Number of Events: " << TotNumberOfEvents << std::endl;
00243
00244 gotNentries=true;
00245 edm::LogInfo("SiStripQualityHotStripIdentifierRoot")<< "[SiStripQualityHotStripIdentifierRoot::bookHistos] gotNentries flag " << gotNentries << std::endl;
00246 }
00247
00248 if (strstr(me_name.c_str(),(parameters.getUntrackedParameter<std::string>("OccupancyHisto")).c_str())==NULL)
00249 continue;
00250
00251 unsigned int detid=0;
00252 char title[128];
00253 sprintf(title,"%s",me_name.c_str());
00254 char *ptr=strtok(title,"__");
00255 int c=0;
00256 while (ptr!=NULL){
00257 if (c==2){
00258 detid=atol(ptr);
00259 break;
00260 }
00261 ptr=strtok(NULL,"_");
00262 c++;
00263 }
00264 LogDebug("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::bookHistos] detid " << detid<< std::endl;
00265
00266 ClusterPositionHistoMap[detid]=boost::shared_ptr<TH1F>(new TH1F(*(*iter)->getTH1F()));
00267
00268 }
00269
00270 }
00271